|  |  |  | 
|---|
|  |  |  | 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") | 
|---|
|  |  |  | @SsoPowerAop(power = "-1") | 
|---|
|  |  |  | @Log("增加设备号") | 
|---|
|  |  |  | public BaseResponse<Boolean> addEquip(@RequestBody QueryVo vo){ | 
|---|
|  |  |  | public BaseResponse<?> addEquip(@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.addEquip(vo.planId,vo.addNum); | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(path="someEquip") | 
|---|
|  |  |  | @SsoPowerAop(power = "-1") | 
|---|
|  |  |  | @Log("查询设备号") | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryResultVo<List<PrEquip>> list = sv.selectSomeEquip(queryVo) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping(path="exportEquip") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Log("导出设备号") | 
|---|
|  |  |  | public void exportEquip(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<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"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|