| package com.dy.pmsProduct.taskPlan; | 
|   | 
| import com.alibaba.excel.converters.Converter; | 
| import com.dy.common.aop.SsoPowerAop; | 
| import com.dy.common.webUtil.BaseResponse; | 
| import com.dy.common.webUtil.BaseResponseUtils; | 
| import com.dy.common.webUtil.QueryResultVo; | 
| import com.dy.pmsGlobal.aop.Log; | 
| import com.dy.pmsGlobal.pojoPr.PrAssemblyPlan; | 
| import com.dy.pmsGlobal.pojoPr.PrEquip; | 
| import com.dy.pmsGlobal.util.QrCodeUtil; | 
| import com.google.zxing.WriterException; | 
| import jakarta.servlet.http.HttpServletResponse; | 
| import jakarta.validation.Valid; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.io.IOException; | 
| import java.util.ArrayList; | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 组装任务计划 | 
|  */ | 
| @Slf4j | 
| @RestController | 
| @RequestMapping(path="assembly") | 
| public class AssemblyPlanCtrl { | 
|     private static final String fileName = "设备号信息" ; | 
|     private static final String sheetName = "设备号信息" ; | 
|     private AssemblySv sv; | 
|     @Autowired | 
|     public void setAssemblySv(AssemblySv assemblySv) { | 
|         this.sv = assemblySv; | 
|     } | 
|   | 
|     @PostMapping(path="save") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("保存组装任务计划") | 
|     public BaseResponse<Boolean> save(@RequestBody @Valid PrAssemblyPlan plan){ | 
|         int count = sv.save(plan); | 
|         if (count <= 0) { | 
|             return BaseResponseUtils.buildFail("数据库存储失败"); | 
|         } else { | 
|             return BaseResponseUtils.buildSuccess(true); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 更新 | 
|      * @param plan | 
|      * @return | 
|      */ | 
|     @PostMapping(path="update") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("更新组装任务计划") | 
|     public BaseResponse<Boolean> update(@RequestBody @Valid PrAssemblyPlan plan){ | 
|         int count = sv.update(plan); | 
|         if (count <= 0) { | 
|             return BaseResponseUtils.buildFail("数据库存储失败"); | 
|         } else { | 
|             return BaseResponseUtils.buildSuccess(true); | 
|         } | 
|     } | 
|   | 
|     @PostMapping(path="updateStatus") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("更新任务计划状态") | 
|     public BaseResponse<Boolean> updateStatus(@RequestBody PrAssemblyPlan plan){ | 
|         int count = sv.updateStatus(plan); | 
|         if (count <= 0) { | 
|             return BaseResponseUtils.buildFail("数据库存储失败"); | 
|         } else { | 
|             return BaseResponseUtils.buildSuccess(true); | 
|         } | 
|     } | 
|     /** | 
|      * 根据ID查询 | 
|      * @return | 
|      */ | 
|     @GetMapping(path="one") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("根据ID查询组装任务计划") | 
|     public BaseResponse<PrAssemblyPlan> one(Long id){ | 
|         PrAssemblyPlan plan=sv.selectById(id); | 
|         return BaseResponseUtils.buildSuccess(plan); | 
|     } | 
|   | 
|     /** | 
|      * 分页查询 | 
|      * @param vo | 
|      * @return | 
|      */ | 
|     @PostMapping(path="some") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("分页查询组装任务计划") | 
|     public BaseResponse<QueryResultVo<List<PrAssemblyPlan>>> some(@RequestBody QueryVo vo){ | 
|         QueryResultVo<List<PrAssemblyPlan>> list = sv.selectSome(vo) ; | 
|         return BaseResponseUtils.buildSuccess(list); | 
|     } | 
|   | 
|     /** | 
|      * 增加设备号 | 
|      */ | 
|     @PostMapping(path="addEquip") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("增加设备号") | 
|     public BaseResponse<?> addEquip(@RequestBody QueryVo vo){ | 
|         if(vo.addNum == null || vo.addNum <= 0 || vo.planId == null){ | 
|             return BaseResponseUtils.buildFail("参数错误"); | 
|         } | 
|         int count = sv.addEquip(vo.planId,vo.addNum); | 
|         if (count <= 0) { | 
|             return BaseResponseUtils.buildFail("数据库存储失败"); | 
|         } else { | 
|             return BaseResponseUtils.buildSuccess(true); | 
|         } | 
|     } | 
|   | 
|     @PostMapping(path="someEquip") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("分页查询设备号") | 
|     public BaseResponse<QueryResultVo<List<PrEquip>>> someEquip(@RequestBody QueryVo queryVo){ | 
|         QueryResultVo<List<PrEquip>> list = sv.selectSomeEquip(queryVo) ; | 
|         return BaseResponseUtils.buildSuccess(list); | 
|     } | 
|   | 
|     @GetMapping(path="exportEquip") | 
|     @SsoPowerAop(power = "-1") | 
|     @Log("导出设备号") | 
|     public void exportEquip(Long batchId, HttpServletResponse response){ | 
|         Date start = new Date() ; | 
|         List<Converter> list = new ArrayList<>(); | 
|   | 
|         List<PrEquip> equipList = sv.selectEquipByBatchId(batchId) ; | 
|         // 使用并行流提高性能 | 
|         equipList.parallelStream().forEach(equip -> { | 
|             ExcelVo vo = new ExcelVo(); | 
|             vo.equipNo = equip.equipNo; | 
|             try { | 
|                 vo.qrCode = QrCodeUtil.genQrCode(vo.equipNo); | 
|             } catch (IOException | WriterException e) { | 
|                 e.printStackTrace(); | 
|             } | 
|             list.add(vo); | 
|         }); | 
|         log.info("导出设备号耗时:"+(new Date().getTime()-start.getTime())+"ms"); | 
|         QrCodeUtil.downloadExcel(response, fileName,sheetName,list); | 
|         log.info("导出设备号耗时:"+(new Date().getTime()-start.getTime())+"ms"); | 
|     } | 
| } |