diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairController.java index 45f1f471..5862a027 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairController.java @@ -11,6 +11,7 @@ import com.bonus.material.repair.domain.RepairPartDetails; import com.bonus.material.repair.domain.RepairTask; import com.bonus.material.repair.domain.RepairTaskDetails; import com.bonus.material.repair.domain.vo.RepairDeviceListVo; +import com.bonus.material.repair.domain.vo.RepairDeviceVO; import com.bonus.material.repair.service.RepairService; import com.bonus.system.api.domain.SysUser; import com.fasterxml.jackson.core.JsonProcessingException; @@ -68,19 +69,6 @@ public class RepairController extends BaseController { return AjaxResult.success(list); } - /** - * 导出维修任务列表--外层--壹级列表 - */ - @PostMapping("/export") - @RequiresPermissions("repair:manage:export") - @ApiOperation(value = "导出维修任务列表") - public void export(HttpServletResponse response, RepairTask bean) { - List list = service.exportRepairTaskList(bean); - ExcelUtil util = new ExcelUtil<>(RepairTask.class); - util.exportExcel(response, list, "维修任务列表"); - } - - /** * 获取维修任务物资设备列表--不分页 */ @@ -135,8 +123,8 @@ public class RepairController extends BaseController { */ @ApiOperation(value = "批量维修--批量--按照传参维修方式进行维修") @PostMapping("/batchRepairApply") - public AjaxResult batchRepairApply(@RequestBody List list) { - return service.fastRepairApply(list); + public AjaxResult batchRepairApply(@RequestBody List list) { + return service.batchRepairApply(list); } /** @@ -175,4 +163,17 @@ public class RepairController extends BaseController { return AjaxResult.success(list); } + /** + * 导出维修任务列表--外层--壹级列表 + */ + @PostMapping("/export") + @RequiresPermissions("repair:manage:export") + @ApiOperation(value = "导出维修任务列表") + public void export(HttpServletResponse response, RepairTask bean) { + List list = service.exportRepairTaskList(bean); + ExcelUtil util = new ExcelUtil<>(RepairTask.class); + util.exportExcel(response, list, "维修任务列表"); + } + + } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/RepairApplyRecord.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/RepairApplyRecord.java index 261b17d0..8061f653 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/RepairApplyRecord.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/RepairApplyRecord.java @@ -7,20 +7,22 @@ import java.util.List; import com.bonus.common.core.annotation.Excel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.ToString; import com.bonus.common.core.web.domain.BaseEntity; +import lombok.experimental.Accessors; /** * 维修记录对象 repair_apply_record * - * @author xsheng - * @date 2024-10-16 + * @author syruan */ - - +@EqualsAndHashCode(callSuper = false) @Data @ToString +@Accessors(chain = true) public class RepairApplyRecord extends BaseEntity { + private static final long serialVersionUID = 1L; /** $column.columnComment */ @@ -53,7 +55,7 @@ public class RepairApplyRecord extends BaseEntity { /** 维修方式(1内部2返厂3报废) */ @Excel(name = "维修方式", readConverterExp = "1=内部2返厂3报废") - private String repairType; + private Integer repairType; /** 数据所属组织 */ @Excel(name = "数据所属组织") diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/vo/RepairDeviceVO.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/vo/RepairDeviceVO.java index 18f32154..b67d30fe 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/vo/RepairDeviceVO.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/domain/vo/RepairDeviceVO.java @@ -1,6 +1,7 @@ package com.bonus.material.repair.domain.vo; import com.bonus.material.repair.domain.RepairPart; +import com.bonus.material.repair.domain.RepairPartDetails; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -24,12 +25,18 @@ public class RepairDeviceVO { @ApiModelProperty(value = "任务ID") private Long taskId; + @ApiModelProperty(value = "设备表主键id") + private Long maId; + @ApiModelProperty(value = "设备类型") private String typeName; @ApiModelProperty(value = "规格型号") private String type; + @ApiModelProperty(value = "规格型号ID") + private Long typeId; + @ApiModelProperty(value = "设备编码") private String code; @@ -42,54 +49,69 @@ public class RepairDeviceVO { @ApiModelProperty(value = "维修方式: 1内部 2外部返厂 3报废") private Integer repairType; + @ApiModelProperty(value = "维修人员") + private String repairer; + + @ApiModelProperty(value = "管理模式") + private Integer manageType; + @ApiModelProperty(value = "附件") private String fileUrl; + @ApiModelProperty(value = "维修数量") + private int repairNum; + + @ApiModelProperty(value = "维修合格数量") + private int repairedNum; + + @ApiModelProperty(value = "维修报废数量") + private int scrapNum; + @ApiModelProperty(value = "编码--内部维修配件集合") - private List codeInRepairPartList; + private List codeInRepairPartList; @ApiModelProperty(value = "编码--返厂维修配件集合") - private List codeOutRepairPartList; + private List codeOutRepairPartList; @ApiModelProperty(value = "编码--报废维修配件集合") - private List codeScrapRepairPartList; + private List codeScrapRepairPartList; @ApiModelProperty(value = "数量--内部维修配件集合") - private List numberInRepairPartList; + private List numberInRepairPartList; @ApiModelProperty(value = "数量--返厂维修配件集合") - private List numberOutRepairPartList; + private List numberOutRepairPartList; @ApiModelProperty(value = "数量--报废维修配件集合") - private List numberScrapRepairPartList; + private List numberScrapRepairPartList; // 手动覆盖 getter 方法,确保 List 始终被初始化 - public List getCodeInRepairPartList() { + public List getCodeInRepairPartList() { if (this.codeInRepairPartList == null) {this.codeInRepairPartList = new ArrayList<>();} return this.codeInRepairPartList; } - public List getCodeOutRepairPartList() { + public List getCodeOutRepairPartList() { if (this.codeOutRepairPartList == null) {this.codeOutRepairPartList = new ArrayList<>();} return this.codeOutRepairPartList; } - public List getCodeScrapRepairPartList() { + public List getCodeScrapRepairPartList() { if (this.codeScrapRepairPartList == null) {this.codeScrapRepairPartList = new ArrayList<>();} return this.codeScrapRepairPartList; } - public List getNumberInRepairPartList() { + public List getNumberInRepairPartList() { if (this.numberInRepairPartList == null) {this.numberInRepairPartList = new ArrayList<>();} return this.numberInRepairPartList; } - public List getNumberOutRepairPartList() { + public List getNumberOutRepairPartList() { if (this.numberOutRepairPartList == null) {this.numberOutRepairPartList = new ArrayList<>();} return this.numberOutRepairPartList; } - public List getNumberScrapRepairPartList() { + public List getNumberScrapRepairPartList() { if (this.numberScrapRepairPartList == null) {this.numberScrapRepairPartList = new ArrayList<>();} return this.numberScrapRepairPartList; } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/mapper/RepairMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/mapper/RepairMapper.java index 67ef5235..a9668836 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/mapper/RepairMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/mapper/RepairMapper.java @@ -108,7 +108,7 @@ public interface RepairMapper { * @param repairNum 维修数量 * @param userid 用户id */ - int updateRepairedNumTwo(@Param("id")Long id, @Param("repairNum")int repairNum, @Param("userId")Long userid); + int updateRepairedNumTwo(@Param("id") Long id, @Param("repairNum") int repairNum, @Param("userId") Long userid); /** * 查询是否存在未完成维修的 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/RepairService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/RepairService.java index 4608da83..ee87204d 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/RepairService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/RepairService.java @@ -6,6 +6,7 @@ import com.bonus.material.repair.domain.RepairApplyRecord; import com.bonus.material.repair.domain.RepairTask; import com.bonus.material.repair.domain.RepairTaskDetails; import com.bonus.material.repair.domain.vo.RepairDeviceListVo; +import com.bonus.material.repair.domain.vo.RepairDeviceVO; import com.bonus.system.api.domain.SysUser; import java.util.ArrayList; @@ -40,6 +41,8 @@ public interface RepairService { */ AjaxResult fastRepairApply(List list); + AjaxResult batchRepairApply(List repairDeviceVOList); + /** * 维修明细--批量审核--更新明细status */ diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java index c53c9450..805a0b83 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java @@ -7,10 +7,7 @@ import com.bonus.common.biz.enums.TmTaskTypeEnum; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.security.utils.SecurityUtils; -import com.bonus.material.repair.domain.RepairApplyRecord; -import com.bonus.material.repair.domain.RepairPartDetails; -import com.bonus.material.repair.domain.RepairTask; -import com.bonus.material.repair.domain.RepairTaskDetails; +import com.bonus.material.repair.domain.*; import com.bonus.material.repair.domain.vo.RepairDeviceListVo; import com.bonus.material.repair.domain.vo.RepairDeviceVO; import com.bonus.material.repair.mapper.RepairMapper; @@ -40,6 +37,17 @@ public class RepairServiceImpl implements RepairService { @Resource private TmTaskMapper taskMapper; + // 内部维修类型 + private final int inRepairType = 1; + // 返厂维修类型 + private final int outRepairType = 2; + // 报废维修类型 + private final int scrapRepairType = 3; + + // 维修管理方式--编码 + private final int manageTypeByCode = 0; + private final int manageTypeByNumber = 1; + @Override public List getRepairTaskList(RepairTask bean) { @@ -104,14 +112,9 @@ public class RepairServiceImpl implements RepairService { List partList = bean.getPartList(); BigDecimal sfCosts = new BigDecimal("0"); - // 内部维修类型 - String inRepairType = "1"; - // 返厂维修类型 - String outRepairType = "2"; + // 收费配件 String sfPart = "1"; - // 不收费配件 - String bsfPart = "0"; if (CollectionUtil.isNotEmpty(partList)) { bean.setRepairNum(partList.get(0).getRepairNum()); @@ -120,19 +123,19 @@ public class RepairServiceImpl implements RepairService { // 根据维修类型,更新维修数量、报废数量 switch (bean.getRepairType()) { - case "1": { + case inRepairType: { int repairNum = getNum(bean, details); // 更新维修数量、并修改维修人员 repairMapper.updateRepairedNum(bean.getId(), repairNum, Long.valueOf(bean.getRepairer()), loginUser.getUserid()); break; } - case "2": { + case outRepairType: { int repairNum = getNum(bean, details); // 更新维修数量、维修人员不变 repairMapper.updateRepairedNumTwo(bean.getId(), repairNum, loginUser.getUserid()); break; } - case "3": { + case scrapRepairType: { int scrapNum = details.getScrapNum() + bean.getScrapNum(); int num = scrapNum + details.getRepairedNum(); if (num > details.getRepairNum()) { @@ -149,7 +152,7 @@ public class RepairServiceImpl implements RepairService { // 判断配件列表是否为空 if (CollectionUtil.isNotEmpty(partList)) { // 内部维修 - if (inRepairType.equals(bean.getRepairType())) { + if (Objects.equals(inRepairType, bean.getRepairType())) { // 遍历配件列表,判断配件类型,收费还是不收费 for (RepairPartDetails partDetails : partList) { if (partDetails.getPartId() != null) { @@ -185,7 +188,7 @@ public class RepairServiceImpl implements RepairService { } // 返厂维修 - if (outRepairType.equals(bean.getRepairType())) { + if (outRepairType == bean.getRepairType()) { bean.setPartName(partList.get(0).getPartName()); bean.setPartType(partList.get(0).getPartType()); bean.setRepairContent(partList.get(0).getRepairContent()); @@ -256,7 +259,7 @@ public class RepairServiceImpl implements RepairService { repairRecord.setTypeId(Long.valueOf(bean.getTypeId())); repairRecord.setRepairNum(repairedNum); // 快捷维修,设置为内部维修 - repairRecord.setRepairType("1"); + repairRecord.setRepairType(inRepairType); repairRecord.setCreateBy(String.valueOf(loginUser.getUserid())); repairRecord.setCompanyId(bean.getCompanyId()); repairMapper.addRecord(repairRecord); @@ -268,6 +271,168 @@ public class RepairServiceImpl implements RepairService { return AjaxResult.success(); } + @Override + public AjaxResult batchRepairApply(@NotNull List repairDeviceVOList) { + // 准备业务逻辑数据 + LoginUser loginUser = SecurityUtils.getLoginUser(); + // 配件集合 + List partList = new ArrayList<>(); + + // 校验参数,过滤空数据 + repairDeviceVOList.removeIf(Objects::isNull); + + for (RepairDeviceVO bean : repairDeviceVOList) { + if (bean.getManageType() == null) { + throw new ServiceException("请选择物资管理方式"); + } + if (Objects.equals(manageTypeByCode, bean.getManageType())) { + // 物资管理方式--编码管理 + // 根据维修方式,更新维修数量、报废数量 + switch (bean.getRepairType()) { + case inRepairType: { + partList = bean.getCodeInRepairPartList(); + // 更新维修数量、并修改维修人员 + repairMapper.updateRepairedNum(bean.getId(), 1, Long.valueOf(bean.getRepairer()), loginUser.getUserid()); + break; + } + case outRepairType: { + partList = bean.getCodeOutRepairPartList(); + // 更新维修数量、维修人员不变 + repairMapper.updateRepairedNumTwo(bean.getId(), 1, loginUser.getUserid()); + break; + } + case scrapRepairType: { + partList = bean.getCodeScrapRepairPartList(); + // 更新报废数量 + repairMapper.updateScrapNum(bean.getId(), 1, loginUser.getUserid()); + break; + } + default: + System.err.println("请输入正确的维修类型:" + bean.getRepairType()); + break; + } + + // 处理配件集合数据 + if (CollectionUtil.isNotEmpty(partList)) { + // 遍历配件列表,判断配件类型,收费还是不收费 + for (RepairPartDetails partDetails : partList) { + // 维修记录表信息 + RepairApplyRecord repairApplyRecord = new RepairApplyRecord(); + repairApplyRecord.setTaskId(bean.getTaskId()); + repairApplyRecord.setMaId(bean.getMaId()); + repairApplyRecord.setTypeId(bean.getTypeId()); + repairApplyRecord.setRepairType(bean.getRepairType()); + repairApplyRecord.setRepairNum(scrapRepairType != bean.getRepairType() ? 1 : 0); + repairApplyRecord.setScrapNum(scrapRepairType == bean.getRepairType() ? 1 : 0); + repairApplyRecord.setCreateBy(loginUser.getUsername()); + repairApplyRecord.setStatus(0L); + + if (partDetails.getPartId() != null) { + // 有维修配件时,如果价格为空,设置为0 + if (partDetails.getPartCost() == null) { + partDetails.setPartCost(new BigDecimal(0)); + } + partDetails.setTaskId(bean.getTaskId()); + partDetails.setMaId(bean.getMaId()); + partDetails.setTypeId(bean.getTypeId()); + partDetails.setCreateBy(String.valueOf(loginUser.getUserid())); + partDetails.setCompanyId(null); + + // 根据 partId 找配件单价 + BigDecimal partPrice = repairMapper.selectPartPrice(partDetails.getPartId()); + // 设置配件费用 + partDetails.setPartCost(partPrice); + // 添加【维修配件明细表】 + repairMapper.addPart(partDetails); + + // 设置配件费用 + repairApplyRecord.setPartPrice(partDetails.getPartCost()); + repairApplyRecord.setPartId((long) partDetails.getPartId().intValue()); + repairApplyRecord.setPartNum(partDetails.getPartNum()); + repairApplyRecord.setRepairContent(partDetails.getRepairContent()); + repairApplyRecord.setPartType(partDetails.getPartType()); + // 添加【维修记录表】 + repairMapper.addRecord(repairApplyRecord); + } else { + // 不选维修配件时, 只添加【维修记录表】 + repairMapper.addRecord(repairApplyRecord); + } + } + } else { + // 配件为空,添加【维修记录表】 + // 维修记录表信息 + RepairApplyRecord repairApplyRecord = new RepairApplyRecord(); + repairApplyRecord.setTaskId(bean.getTaskId()); + repairApplyRecord.setMaId(bean.getMaId()); + repairApplyRecord.setTypeId(bean.getTypeId()); + repairApplyRecord.setRepairType(bean.getRepairType()); + repairApplyRecord.setRepairNum(bean.getRepairType() != 3 ? 1 : 0); + repairApplyRecord.setScrapNum(bean.getRepairType() == 3 ? 1 : 0); + repairApplyRecord.setCreateBy(loginUser.getUsername()); + repairApplyRecord.setStatus(0L); + // 不选维修配件时, 只添加【维修记录表】 + repairMapper.addRecord(repairApplyRecord); + } + + + } else if (Objects.equals(manageTypeByNumber, bean.getManageType())) { + // 物资管理方式--数量管理 + + if (bean.getId() == null) { + throw new ServiceException("请完善参数,维修详情ID为空!"); + } + // 获取维修详情表中的维修详情记录:待维修、已维修、报废的数量 + RepairTaskDetails details = repairMapper.getById(bean.getId()); + + if (details == null) { + throw new ServiceException("此维修记录不存在,请检查!"); + } + + // 根据维修方式,更新维修数量、报废数量 + switch (bean.getRepairType()) { + case inRepairType: { + partList = bean.getCodeInRepairPartList(); + // 更新维修数量、并修改维修人员 + repairMapper.updateRepairedNum(bean.getId(), 1, Long.valueOf(bean.getRepairer()), loginUser.getUserid()); + break; + } + case outRepairType: { + partList = bean.getCodeOutRepairPartList(); + // 更新维修数量、维修人员不变 + repairMapper.updateRepairedNumTwo(bean.getId(), 1, loginUser.getUserid()); + break; + } + case scrapRepairType: { + partList = bean.getCodeScrapRepairPartList(); + + // -------------校验维修数量---------------- + // 统计历史已报废数量 + 本次报废数量 = 报废总数 + int scrapNum = details.getScrapNum() + bean.getScrapNum(); + // 统计 报废总数 + 历史已维修数量, + int num = scrapNum + details.getRepairedNum(); + // 不能大与总的待维修数量 + if (num > details.getRepairNum()) { + throw new ServiceException("报废数量大于维修总量! 本次报废数量:" + bean.getScrapNum() + ",已报废数量:" + details.getScrapNum() + ",维修总量:" + details.getRepairNum()); + } + + // 更新报废数量 + repairMapper.updateScrapNum(bean.getId(), 1, loginUser.getUserid()); + break; + } + default: + System.err.println("请输入正确的维修类型:" + bean.getRepairType()); + break; + } + + } else { + throw new ServiceException("请选择维修类型"); + } + } + + + return AjaxResult.success("维修完成"); + } + @Override @Transactional(rollbackFor = Exception.class) public AjaxResult endRepairTask(@NotNull List taskList) {