package org.jeecg.modules.arj.controller;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; //导包
|
import com.baomidou.mybatisplus.core.metadata.IPage; //导包
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; //导包
|
import org.jeecg.modules.arj.config.AjaxResult;
|
import org.jeecg.modules.arj.entity.Head;
|
import org.jeecg.modules.arj.service.HeadService;
|
import org.jeecg.modules.arj.vo.BianxkVo;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.jeecg.modules.arj.service.BianxkService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*; //导包
|
|
import javax.annotation.Resource; //导包
|
import java.util.HashMap;
|
import java.util.List; //导包
|
|
/*其中com.terra.arj.service就等于 com.example.demo.service,BianxkService就等于SpiderdataSpiderxrmmwService*/
|
import org.jeecg.modules.arj.entity.Bianxk;
|
/*其中com.terra.arj.entity就等于com.example.demo.entity,Bianxk就等于SpiderdataSpiderxrmmw,一种Java的模板引擎语法*/
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
/**
|
* <p>
|
* 边线库 前端控制器
|
* </p>
|
*
|
* @author hyy
|
* @since 2023-02-20
|
*/
|
@Api(tags = "A0-边线库接口")
|
@RestController
|
@RequestMapping("/bianxk")
|
public class BianxkController {
|
|
@Resource
|
private BianxkService bianxkService;
|
|
@Autowired
|
private HeadService headService;
|
|
//新增和修改接口
|
@ApiOperation("增加数据")
|
@PostMapping("/add")
|
public AjaxResult add(@RequestBody BianxkVo bianxkVo) {
|
//新增或者更新
|
Head h = headService.insert(bianxkVo.getHead());
|
|
if (bianxkVo.getBainxkVoList() != null) {
|
bianxkVo.getBainxkVoList().stream().forEach(item -> item.setHeadId(h.getId()));
|
bianxkService.saveBatch(bianxkVo.getBainxkVoList());
|
}
|
|
return AjaxResult.success(h.getId());
|
|
}
|
@ApiOperation("编辑数据")
|
@PostMapping("/edit")
|
public AjaxResult edit(@RequestBody BianxkVo bianxkVo) {
|
//新增或者更新
|
|
Head h2 = bianxkVo.getHead();
|
h2.setId("");
|
Head hh = headService.insert(h2);
|
if (bianxkVo.getBainxkVoList() != null) {
|
|
bianxkVo.getBainxkVoList().stream().forEach(item -> item.setHeadId(hh.getId()));
|
bianxkService.saveOrUpdateBatch(bianxkVo.getBainxkVoList());
|
}
|
|
return AjaxResult.success(hh.getId());
|
|
}
|
//删除接口
|
@DeleteMapping("/{id}")
|
public boolean delete(@PathVariable Integer id) {
|
return bianxkService.removeById(id);
|
}
|
|
@ApiOperation("通过ID查询单条数据")
|
@GetMapping("/id")
|
public AjaxResult queryById(String id) {
|
BianxkVo hanjiVo = new BianxkVo();
|
Head head = headService.queryById(id);
|
|
if (head == null) return AjaxResult.error("访问无数据");
|
hanjiVo.setHead(head);
|
|
|
hanjiVo.setBainxkVoList(bianxkService.queryByHeadId(head.getId()));
|
|
return AjaxResult.success(hanjiVo);
|
}
|
//查询所有内容接口
|
@GetMapping("/list")
|
public List<Bianxk> findAll() {
|
return bianxkService.list();
|
}
|
|
//根据id查询
|
@GetMapping("/{id}")
|
public Bianxk findOne(@PathVariable Integer id) {
|
return bianxkService.getById(id);
|
}
|
|
//分页查询
|
@GetMapping("/page")
|
public IPage<Bianxk> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
|
//此处没有写查询条件逻辑,因为太活了,所有不在模板中写了
|
IPage<Bianxk> page = new Page<>(pageNum, pageSize); //新建一个page
|
QueryWrapper<Bianxk> queryWrapper = new QueryWrapper<>(); //新建一个queryWrapper
|
|
queryWrapper.orderByDesc("id"); //通过id倒序显示
|
return bianxkService.page(page, queryWrapper); //返回分页
|
}
|
/**
|
* 获取最新数据
|
*
|
* @return 实例对象
|
*/
|
@ApiOperation("获取最新数据")
|
@PostMapping("/last")
|
public AjaxResult getlastRecord(@RequestBody String leixing) {
|
JSONObject j = JSONObject.parseObject(leixing);
|
HashMap<String, String > myMap = new HashMap<String, String>(){{
|
put("0","一");
|
put("2","二");
|
put("3","三");
|
put("4","四");
|
put("5","五");
|
put("6","六");
|
put("7","七");
|
put("8","八");
|
put("9","九");
|
}};
|
|
Head head = headService.queryLeixingChanxian("A0",myMap.get(j.getString("leixing")));
|
if (head == null) return AjaxResult.error("访问无数据");
|
BianxkVo hanjiVo = new BianxkVo();
|
hanjiVo.setHead(head);
|
|
hanjiVo.setBainxkVoList(bianxkService.queryByHeadId(head.getId()));
|
return AjaxResult.success(hanjiVo);
|
}
|
|
|
|
}
|