package org.jeecg.modules.arj.controller; import com.alibaba.fastjson.JSONObject; 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.mapper.HeadMapper; import org.jeecg.modules.arj.service.*; import org.jeecg.modules.arj.vo.FanbianVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @Api(tags = "A3翻边滚筋封口接口") @RestController @RequestMapping("/fanbianVo") public class FanbianVoController { @Autowired private HeadService headService; @Autowired private HeadMapper headMapper; @Autowired private FanbianRdService fanbianRdService; @Autowired private FanbianZhiliangRdService fanbianZhiliangRdService; @Autowired private FanbianZhiliangRd2Service fanbianZhiliangRd2Service; @Autowired private FeipinYintieService feipinYintieService; @Autowired private FanbianClService fanbianClService; @Autowired private FeipinFanbianService feipinFanbianService; @Autowired private FanbianClFwService fanbianClFwService ; /** * 通过ID查询单条数据 * * @param id 主键 * @return 实例对象 */ @ApiOperation("通过ID查询单条数据") @GetMapping("/id") public AjaxResult queryById(String id) { FanbianVo hanjiVo = new FanbianVo(); Head head = headService.queryById(id); if (head == null) return AjaxResult.error("访问无数据"); hanjiVo.setHead(head); hanjiVo.setFanbianClList(fanbianClService.queryByHeadId(head.getId())); hanjiVo.setFanbianRdList(fanbianRdService.queryByHeadId(head.getId())); hanjiVo.setFeipinYintie(feipinYintieService.queryByHeadId(head.getId())); hanjiVo.setFanbianZhiliangRdList(fanbianZhiliangRdService.queryByHeadId(head.getId())); hanjiVo.setFanbianZhiliangRd2List(fanbianZhiliangRd2Service.queryByHeadId(head.getId())); hanjiVo.setFeipinFanbian(feipinFanbianService.queryByHeadId(head.getId())); hanjiVo.setFanbianClFw(fanbianClFwService.queryByHeadId(head.getId())); return AjaxResult.success(hanjiVo); } /** * 获取最新数据 * * @return 实例对象 */ @ApiOperation("获取最新数据") @PostMapping("/last") public AjaxResult getlastRecord(@RequestBody String leixing){ // Head head = headService.queryLast(leixing==null?"A3":leixing); JSONObject j = JSONObject.parseObject(leixing); HashMap myMap = new HashMap(){{ put("0","一"); put("2","二"); put("3","三"); put("4","四"); put("5","五"); put("6","六"); put("7","七"); put("8","八"); put("9","九"); }}; Head head = headService.queryLeixingChanxian("A3",myMap.get(j.getString("leixing"))); FanbianVo hanjiVo = new FanbianVo(); if( head == null ) return AjaxResult.error("访问无数据"); hanjiVo.setHead(head); hanjiVo.setFanbianClList(fanbianClService.queryByHeadId(head.getId())); hanjiVo.setFanbianRdList(fanbianRdService.queryByHeadId(head.getId())); hanjiVo.setFeipinYintie(feipinYintieService.queryByHeadId(head.getId())); hanjiVo.setFanbianZhiliangRdList(fanbianZhiliangRdService.queryByHeadId(head.getId())); hanjiVo.setFanbianZhiliangRd2List(fanbianZhiliangRd2Service.queryByHeadId(head.getId())); hanjiVo.setFeipinFanbian(feipinFanbianService.queryByHeadId(head.getId())); hanjiVo.setFanbianClFw(fanbianClFwService.queryByHeadId(head.getId())); return AjaxResult.success(hanjiVo); } @PostMapping("/page") public AjaxResult findPage( @RequestParam(defaultValue = "1") Integer pageNum , @RequestParam(defaultValue = "10") Integer pageSize) { List headList = headMapper.queryPage2((pageNum - 1) * pageSize, pageSize); IPage iPage = new Page(); List records = new ArrayList<>(); for (Head h : headList) { FanbianVo fanbianVo = new FanbianVo(); Head head = headService.queryById(h.getId()); if( head == null ) return AjaxResult.error("访问无数据"); fanbianVo.setHead(head); fanbianVo.setFanbianClList(fanbianClService.queryByHeadId(head.getId())); fanbianVo.setFanbianRdList(fanbianRdService.queryByHeadId(head.getId())); fanbianVo.setFeipinYintie(feipinYintieService.queryByHeadId(head.getId())); fanbianVo.setFanbianZhiliangRdList(fanbianZhiliangRdService.queryByHeadId(head.getId())); fanbianVo.setFanbianZhiliangRd2List(fanbianZhiliangRd2Service.queryByHeadId(head.getId())); fanbianVo.setFeipinFanbian(feipinFanbianService.queryByHeadId(head.getId())); fanbianVo.setFanbianClFw(fanbianClFwService.queryByHeadId(head.getId())); records.add(fanbianVo); } int n = headMapper.queryCount(); iPage.setPages(n % pageSize == 0 ? n / pageSize : n / pageSize + 1); iPage.setRecords(records); iPage.setTotal(headMapper.queryCount()); iPage.setSize(pageSize); iPage.setCurrent(pageNum); return AjaxResult.success(iPage); } /** * 新增数据 * * @param fanbianVo 实例对象 * @return 实例对象 */ @ApiOperation("新增数据") @PostMapping public AjaxResult add( @RequestBody FanbianVo fanbianVo){ Head h = headService.insert(fanbianVo.getHead()); extracted(fanbianVo, h); return AjaxResult.success(h.getId()); } @ApiOperation("更新数据") @PostMapping("/edit") public AjaxResult edit( @RequestBody FanbianVo fanbianVo){ Head h2 = fanbianVo.getHead(); h2.setId(""); Head hh = headService.insert(h2); extracted(fanbianVo, hh); return AjaxResult.success(hh.getId()); } private void extracted(@RequestBody FanbianVo fanbianVo, Head h) { if(fanbianVo.getFeipinYintie() != null) { fanbianVo.getFeipinYintie().setHeadId(h.getId()); feipinYintieService.saveOrUpdate(fanbianVo.getFeipinYintie()); } if(fanbianVo.getFeipinFanbian() != null) { fanbianVo.getFeipinFanbian().setHeadId(h.getId()); feipinFanbianService.saveOrUpdate(fanbianVo.getFeipinFanbian()); } if(fanbianVo.getFanbianClList() != null) { fanbianVo.getFanbianClList().stream().forEach(item -> item.setHeadId(h.getId())); fanbianClService.saveOrUpdateBatch(fanbianVo.getFanbianClList()); } if(fanbianVo.getFanbianRdList() != null) { fanbianVo.getFanbianRdList().stream().forEach(item -> item.setHeadId(h.getId())); fanbianRdService.saveOrUpdateBatch(fanbianVo.getFanbianRdList()); } if(fanbianVo.getFanbianZhiliangRdList() != null) { fanbianVo.getFanbianZhiliangRdList().stream().forEach(item -> item.setHeadId(h.getId())); fanbianZhiliangRdService.saveOrUpdateBatch(fanbianVo.getFanbianZhiliangRdList()); } if(fanbianVo.getFanbianZhiliangRd2List() != null) { fanbianVo.getFanbianZhiliangRd2List().stream().forEach(item -> item.setHeadId(h.getId())); fanbianZhiliangRd2Service.saveOrUpdateBatch(fanbianVo.getFanbianZhiliangRd2List()); } if(fanbianVo.getFanbianClFw() != null) { fanbianVo.getFanbianClFw().setHeadId(h.getId()); fanbianClFwService.saveOrUpdate(fanbianVo.getFanbianClFw()); } } /** * 更新数据 * * @param head 实例对象 * @return 实例对象 */ @ApiOperation("更新数据") @PutMapping public AjaxResult edit(Head head){ return AjaxResult.success(headService.update(head)); } /** * 通过主键删除数据 * * @param id 主键 * @return 是否成功 */ @ApiOperation("通过主键删除数据") @DeleteMapping public AjaxResult deleteById(String id){ return AjaxResult.success(headService.deleteById(id)); } }