package org.jeecg.modules.arj.g.controller;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.jeecg.modules.arj.config.AjaxResult;
|
import org.jeecg.modules.arj.entity.Head;
|
import org.jeecg.modules.arj.g.entity.G18ChanTotal;
|
import org.jeecg.modules.arj.g.entity.G18Chanliangtongji;
|
import org.jeecg.modules.arj.g.service.G18ChanTotalService;
|
import org.jeecg.modules.arj.g.service.G18ChanliangtongjiService;
|
import org.jeecg.modules.arj.g.vo.G18ChanVo;
|
import org.jeecg.modules.arj.service.HeadService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 盖线产量统计 前端控制器
|
* </p>
|
*
|
* @author hyy
|
* @since 2023-05-12
|
*/
|
@Api(tags = "g18-盖线产量统计")
|
@RestController
|
@RequestMapping("/g/g18-chanliangtongji")
|
public class G18ChanliangtongjiController {
|
|
@Autowired
|
HeadService headService;
|
@Autowired
|
G18ChanliangtongjiService g18ChanliangtongjiService;
|
@Autowired
|
G18ChanTotalService g18ChanTotalService;
|
|
|
//新增和修改接口
|
@ApiOperation("新增数据")
|
@PostMapping("/add")
|
public AjaxResult save(@RequestBody G18ChanVo g18ChanVo) {
|
//新增或者更新
|
Head head = headService.insert(g18ChanVo.getHead());
|
if (g18ChanVo.getG18ChanliangtongjiList() != null) {
|
g18ChanVo.getG18ChanliangtongjiList().stream().forEach(item -> item.setHeadId(head.getId()));
|
g18ChanliangtongjiService.saveBatch(g18ChanVo.getG18ChanliangtongjiList());
|
}
|
if (g18ChanVo.getG18ChanTotal() != null) {
|
g18ChanVo.getG18ChanTotal().setHeadId(head.getId());
|
g18ChanTotalService.save(g18ChanVo.getG18ChanTotal());
|
}
|
return AjaxResult.success(head.getId());
|
}
|
|
|
//查询所有内容接口
|
@ApiOperation("获取最新数据")
|
@GetMapping("/list")
|
public AjaxResult findAll() {
|
Head head = headService.queryLast("g18");
|
G18ChanVo g18ChanVo = new G18ChanVo();
|
g18ChanVo.setHead(head);
|
g18ChanVo.setG18ChanliangtongjiList(g18ChanliangtongjiService.queryByHeadId(head.getId()));
|
|
g18ChanVo.setG18ChanTotal(g18ChanTotalService.queryByHeadId(head.getId()));
|
return AjaxResult.success(g18ChanVo); //返回查询到的所有数据
|
}
|
|
//根据id查询
|
@ApiOperation("通过ID查询单条数据")
|
@GetMapping("/id")
|
public AjaxResult findOne(String id) {
|
Head head = headService.queryById(id);
|
|
if (head == null) return AjaxResult.error("访问无数据");
|
|
G18ChanVo g18ChanVo = new G18ChanVo();
|
g18ChanVo.setHead(head);
|
|
g18ChanVo.setG18ChanTotal(g18ChanTotalService.queryByHeadId(id));
|
g18ChanVo.setG18ChanliangtongjiList(g18ChanliangtongjiService.queryByHeadId(id));
|
return AjaxResult.success(g18ChanVo); //返回查询到指定id的数据
|
}
|
|
//分页查询
|
@GetMapping("/page")
|
public IPage<G18Chanliangtongji> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
|
//此处没有写查询条件逻辑,因为太活了,所有不在模板中写了
|
IPage<G18Chanliangtongji> page = new Page<>(pageNum, pageSize); //新建一个page
|
QueryWrapper<G18Chanliangtongji> queryWrapper = new QueryWrapper<>(); //新建一个queryWrapper
|
|
queryWrapper.orderByDesc("id"); //通过id倒序显示
|
return g18ChanliangtongjiService.page(page, queryWrapper); //返回分页
|
}
|
|
//查询所有内容接口
|
@ApiOperation("获取最新数据")
|
@GetMapping("/last")
|
public AjaxResult find(String leixing) {
|
Head head = headService.queryLast("g18");
|
G18ChanVo g18ChanVo = new G18ChanVo();
|
g18ChanVo.setHead(head);
|
g18ChanVo.setG18ChanliangtongjiList(g18ChanliangtongjiService.queryByHeadId(head.getId()));
|
|
g18ChanVo.setG18ChanTotal(g18ChanTotalService.queryByHeadId(head.getId()));
|
return AjaxResult.success(g18ChanVo); //返回查询到的所有数据
|
}
|
}
|