|  |  | 
 |  |  | 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.pojoPr.PrDevice; | 
 |  |  | 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.validation.BindingResult; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | import java.io.IOException; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 组装任务计划 | 
 |  |  | 
 |  |  |     @PostMapping(path="save") | 
 |  |  |     @SsoPowerAop(power = "-1") | 
 |  |  |     @Log("保存组装任务计划") | 
 |  |  |     public BaseResponse<Boolean> save(@RequestBody @Valid PrAssemblyPlan plan, BindingResult bindingResult){ | 
 |  |  |         if (bindingResult != null && bindingResult.hasErrors()) { | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         int count; | 
 |  |  |         try { | 
 |  |  |             count = sv.save(plan); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("保存组装任务计划异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |     public BaseResponse<Boolean> save(@RequestBody @Valid PrAssemblyPlan plan){ | 
 |  |  |         int count = sv.save(plan); | 
 |  |  |         if (count <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("数据库存储失败"); | 
 |  |  |         } else { | 
 |  |  | 
 |  |  |     /** | 
 |  |  |      * 更新 | 
 |  |  |      * @param plan | 
 |  |  |      * @param bindingResult | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path="update") | 
 |  |  |     @SsoPowerAop(power = "-1") | 
 |  |  |     @Log("更新组装任务计划") | 
 |  |  |     public BaseResponse<Boolean> update(@RequestBody @Valid PrAssemblyPlan plan, BindingResult bindingResult){ | 
 |  |  |         int count; | 
 |  |  |         try { | 
 |  |  |             if (bindingResult != null && bindingResult.hasErrors()) { | 
 |  |  |                 return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             } | 
 |  |  |             count = sv.update(plan); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("更新组装任务计划异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |     public BaseResponse<Boolean> update(@RequestBody @Valid PrAssemblyPlan plan){ | 
 |  |  |         int count = sv.update(plan); | 
 |  |  |         if (count <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("数据库存储失败"); | 
 |  |  |         } else { | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @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 | 
 |  |  | 
 |  |  |     @SsoPowerAop(power = "-1") | 
 |  |  |     @Log("根据ID查询组装任务计划") | 
 |  |  |     public BaseResponse<PrAssemblyPlan> one(Long id){ | 
 |  |  |         try{ | 
 |  |  |             PrAssemblyPlan plan=sv.selectById(id); | 
 |  |  |             return BaseResponseUtils.buildSuccess(plan); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("根据ID查询组装任务计划异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |         PrAssemblyPlan plan=sv.selectById(id); | 
 |  |  |         return BaseResponseUtils.buildSuccess(plan); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  | 
 |  |  |     @SsoPowerAop(power = "-1") | 
 |  |  |     @Log("分页查询组装任务计划") | 
 |  |  |     public BaseResponse<QueryResultVo<List<PrAssemblyPlan>>> some(@RequestBody QueryVo vo){ | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<PrAssemblyPlan>> list = sv.selectSome(vo) ; | 
 |  |  |             return BaseResponseUtils.buildSuccess(list); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("分页查询组装任务计划异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |         QueryResultVo<List<PrAssemblyPlan>> list = sv.selectSome(vo) ; | 
 |  |  |         return BaseResponseUtils.buildSuccess(list); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 增加设备号 | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path="addEquip") | 
 |  |  |     @PostMapping(path="addDevice") | 
 |  |  |     @SsoPowerAop(power = "-1") | 
 |  |  |     @Log("增加设备号") | 
 |  |  |     public BaseResponse<Boolean> addEquip(@RequestBody QueryVo vo){ | 
 |  |  |     public BaseResponse<?> addDevice(@RequestBody QueryVo vo){ | 
 |  |  |         if(vo.addNum == null || vo.addNum <= 0 || vo.planId == null){ | 
 |  |  |             return BaseResponseUtils.buildFail("参数错误"); | 
 |  |  |         } | 
 |  |  |         try { | 
 |  |  |             int count = sv.addEquip(vo.planId,vo.addNum); | 
 |  |  |             if (count <= 0) { | 
 |  |  |                 return BaseResponseUtils.buildFail("数据库存储失败"); | 
 |  |  |             } else { | 
 |  |  |                 return BaseResponseUtils.buildSuccess(true); | 
 |  |  |             } | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("增加设备号异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         int count = sv.addDevice(vo.planId,vo.addNum); | 
 |  |  |         if (count <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("数据库存储失败"); | 
 |  |  |         } else { | 
 |  |  |             return BaseResponseUtils.buildSuccess(true); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PostMapping(path="someEquip") | 
 |  |  |     @PostMapping(path="someDevice") | 
 |  |  |     @SsoPowerAop(power = "-1") | 
 |  |  |     @Log("查询设备号") | 
 |  |  |     public BaseResponse<QueryResultVo<List<PrEquip>>> someEquip(@RequestBody QueryVo queryVo){ | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<PrEquip>> list = sv.selectSomeEquip(queryVo) ; | 
 |  |  |             return BaseResponseUtils.buildSuccess(list); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("分页查询组装任务计划异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |     @Log("分页查询设备号") | 
 |  |  |     public BaseResponse<QueryResultVo<List<PrDevice>>> someDevice(@RequestBody QueryVo queryVo){ | 
 |  |  |         QueryResultVo<List<PrDevice>> list = sv.selectSomeDevice(queryVo) ; | 
 |  |  |         return BaseResponseUtils.buildSuccess(list); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @GetMapping(path="exportEquip") | 
 |  |  |     @GetMapping(path="exportDevice") | 
 |  |  |     @SsoPowerAop(power = "-1") | 
 |  |  |     @Log("导出设备号") | 
 |  |  |     public void exportEquip(Long batchId, HttpServletResponse response){ | 
 |  |  |     public void exportDevice(Long batchId, HttpServletResponse response){ | 
 |  |  |         Date start = new Date() ; | 
 |  |  |         try{ | 
 |  |  |             List<Converter> list = new ArrayList<>(); | 
 |  |  |         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"); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("导出设备号异常", e); | 
 |  |  |         } | 
 |  |  |         List<PrDevice> deviceList = sv.selectDeviceByBatchId(batchId) ; | 
 |  |  |         // 使用并行流提高性能 | 
 |  |  |         deviceList.parallelStream().forEach(device -> { | 
 |  |  |             ExcelVo vo = new ExcelVo(); | 
 |  |  |             vo.deviceNo = device.deviceNo; | 
 |  |  |             try { | 
 |  |  |                 vo.qrCode = QrCodeUtil.genQrCode(vo.deviceNo); | 
 |  |  |             } 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"); | 
 |  |  |     } | 
 |  |  | } |