diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/common/constants/TypeConstants.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/common/constants/TypeConstants.java index c1c16d2..1e4e857 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/common/constants/TypeConstants.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/common/constants/TypeConstants.java @@ -13,6 +13,9 @@ public class TypeConstants { /** 维修单号的开头字母 */ public static final String REPAIR_TASK_TYPE_LABEL = "W"; + /** 退役单号的开头字母 */ + public static final String SCRAP_TASK_TYPE_LABEL = "Y"; + /** 退料单号的开头字母 */ public static final String BACK_TASK_TYPE_LABEL = "T"; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/controller/ToBeScrapController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/controller/ToBeScrapController.java new file mode 100644 index 0000000..62e0cfd --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/controller/ToBeScrapController.java @@ -0,0 +1,62 @@ +package com.bonus.material.scrap.controller; + +import com.bonus.common.core.web.controller.BaseController; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.core.web.page.TableDataInfo; +import com.bonus.material.scrap.domain.ToBeScrap; +import com.bonus.material.scrap.service.ToBeScrapService; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@RestController +@RequestMapping("/deviceRetireApply") +public class ToBeScrapController extends BaseController { + + @Resource + private ToBeScrapService toBeScrapService; + + @PostMapping("/submitTask") + @ApiOperation(value = "新增退役任务申请") + public AjaxResult submitTask(@RequestBody ToBeScrap bean) { + return toBeScrapService.addScrapData(bean); + } + + @GetMapping("/list") + @ApiOperation(value = "获取报废申请列表") + public TableDataInfo getScrapApplyList(ToBeScrap bean) { + return getDataTable(toBeScrapService.getScrapApplyList(bean)); + } + + @PostMapping("/audit") + @ApiOperation(value = "审批退役任务明细") + public AjaxResult auditData(@RequestBody ToBeScrap bean) { + return toBeScrapService.auditData(bean); + } + + @GetMapping("/detail/{id}") + @ApiOperation(value = "获取报废详情明细") + public AjaxResult getScrapDetailsList(@PathVariable("id") Long id) { + ToBeScrap bean = new ToBeScrap(); + bean.setId(id); + return AjaxResult.success(toBeScrapService.getScrapDetailsList(bean)); + } + + @DeleteMapping("/deleteTask/{id}") + @ApiOperation(value = "删除退役任务") + public AjaxResult deleteChangeInfo(@PathVariable("id") Long id) { + return toBeScrapService.deleteChangeInfo(id); + } + + @GetMapping("/scrapItemList") + @ApiOperation(value = "获取在库的装备、工具列表") + public TableDataInfo getInStockList(ToBeScrap bean) { + startPage(); + List inStockList = toBeScrapService.getInStockList(bean); + return getDataTable(inStockList); + } + + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/domain/ToBeScrap.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/domain/ToBeScrap.java new file mode 100644 index 0000000..c59bdd8 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/domain/ToBeScrap.java @@ -0,0 +1,167 @@ +package com.bonus.material.scrap.domain; + +import com.bonus.common.biz.domain.BmFileInfo; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +@Data +public class ToBeScrap { + + /** + * 设备主键ID + */ + private Long id; + + /** + * 变更任务表主键 + */ + private Long changeId; + + /** + * 用作key + */ + private String keyId; + + /** + * 类型:工具,装备 + */ + private String type; + + /** + * 类型id + */ + private String typeId; + + /** + * 设备类型 1-装备,2-工具 + */ + private String devType; + + /** + * 类目 + */ + private String groupName; + + /** + * 名称 + */ + private String typeName; + + /** + * 规格型号 + */ + private String typeModelName; + + /** + * 管理类型:数量管理,编码管理 + */ + private String manageMode; + + /** + * 设备编码 + */ + private String devCode; + + /** + * 任务编码 + */ + private String code; + + /** + * 在库数量 + */ + private BigDecimal inStockNum; + + /** + * 报废数量 + */ + private BigDecimal scrapNum; + + /** + * 报废附件URL + */ + private String scrapUrl; + + /** + * 创建人昵称 + */ + private String createUser; + + /** + * 创建人ID + */ + private Long CreateBy; + + /** + * 是否报废 + */ + private String isScrap; + + /** + * 是否报废 + */ + private Integer isScrapFilter; + + /** + * 退役时间 + */ + private String scrapTime; + + /** + * 退役原因 + */ + private String reasonVal; + + /** + * 附件 + */ + private List bmFileInfos; + + /** + * 退役明细列表 + */ + private List toBeScrapList; + + /** + * 装备数 + */ + private BigDecimal equipmentNum; + + /** + * 工具数 + */ + private BigDecimal toolNum; + + /** + * 状态 + */ + private String status; + + /** + * 创建时间 + */ + private String createTime; + + /** + * 开始时间(查询条件) + */ + private String startTime; + + /** + * 结束时间(查询条件) + */ + private String endTime; + + /** + * 审批状态 + */ + private String reviewStatus; + + /** + * 操作类型 add新增 edit编辑 + */ + private String operationType; + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/mapper/ScrapMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/mapper/ScrapMapper.java new file mode 100644 index 0000000..9a5e84e --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/mapper/ScrapMapper.java @@ -0,0 +1,86 @@ +package com.bonus.material.scrap.mapper; + +import com.bonus.material.devchange.domain.CsDeviceInfo; +import com.bonus.material.repair.domain.ToBeRepair; +import com.bonus.material.scrap.domain.ToBeScrap; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface ScrapMapper { + + /** + * 获取申请编号 + * @param year 年 + * @param month 月 + * @param type 任务类型 + */ + int getMonthMaxOrderByDate(@Param("year") String year, @Param("month") String month, @Param("type") Integer type); + + /** + * 审批明细数据 + */ + int auditData(ToBeScrap toBeScrap); + + /** + * 查询待审批条数 + */ + int selectCountByChangeId(@Param("changeId") Long changeId); + + /** + * 删除任务 + */ + int deleteChangeInfo(@Param("id") Long id); + + /** + * 修改任务状态 + */ + int updateChangeStatus(@Param("changeId") Long changeId, @Param("reviewStatus") String reviewStatus); + + /** + * 新增工具生命周期数据 + */ + int addToolLifecycleByRepair(ToBeScrap beScrap); + + /** + * 更新装备信息 + */ + int updateMaDevInfo(ToBeScrap toBeScrap); + + /** + * 更新工具台账 + */ + int updateToolLifecycle(ToBeScrap toBeScrap); + + /** + * 新增退役任务 + */ + int addDeviceChangeApply(CsDeviceInfo deviceInfo); + + /** + * 新增退役任务明细 + */ + int addScrapChangeApplyDetails(ToBeScrap bean); + + /** + * 获取在库的装备、工具列表 + */ + List getInStockList(ToBeScrap bean); + + /** + * 获取报废申请列表 + */ + List getScrapApplyList(ToBeScrap bean); + + /** + * 获取报废详情明细 + */ + List getScrapDetailsList(ToBeScrap bean); + + /** + * 根据设备类型和编号查询 + */ + ToBeScrap selectByTypeIdAndCode(ToBeScrap toBeScrap); +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/service/ToBeScrapService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/service/ToBeScrapService.java new file mode 100644 index 0000000..3fd0b67 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/service/ToBeScrapService.java @@ -0,0 +1,40 @@ +package com.bonus.material.scrap.service; + +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.repair.domain.ToBeRepair; +import com.bonus.material.scrap.domain.ToBeScrap; + +import java.util.List; + +public interface ToBeScrapService { + + /** + * 删除任务 + */ + AjaxResult deleteChangeInfo(Long id); + + /** + * 审批任务明细 + */ + AjaxResult auditData(ToBeScrap bean); + + /** + * 新增报废退役任务 + */ + AjaxResult addScrapData(ToBeScrap bean); + + /** + * 获取在库的装备、工具列表 + */ + List getInStockList(ToBeScrap bean); + + /** + * 获取报废申请列表 + */ + List getScrapApplyList(ToBeScrap bean); + + /** + * 获取报废详情明细 + */ + List getScrapDetailsList(ToBeScrap bean); +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/service/impl/ToBeScrapServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/service/impl/ToBeScrapServiceImpl.java new file mode 100644 index 0000000..53c4e1d --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/scrap/service/impl/ToBeScrapServiceImpl.java @@ -0,0 +1,223 @@ +package com.bonus.material.scrap.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.bonus.common.core.constant.Constants; +import com.bonus.common.core.exception.ServiceException; +import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.common.constants.TypeConstants; +import com.bonus.material.common.enums.TypeEnums; +import com.bonus.material.devchange.domain.CsDeviceInfo; +import com.bonus.material.repair.domain.ToBeRepair; +import com.bonus.material.scrap.domain.ToBeScrap; +import com.bonus.material.scrap.mapper.ScrapMapper; +import com.bonus.material.scrap.service.ToBeScrapService; +import org.apache.commons.collections4.CollectionUtils; +import org.hibernate.validator.internal.util.StringHelper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +@Service +public class ToBeScrapServiceImpl implements ToBeScrapService { + + @Resource + private ScrapMapper scrapMapper; + + /** + * 删除任务 + */ + @Override + public AjaxResult deleteChangeInfo(Long id) { + if (Objects.isNull(id)) { + return AjaxResult.error("请求参数异常!"); + } + int deleted = scrapMapper.deleteChangeInfo(id); + return deleted > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败"); + } + + /** + * 审批退役任务明细 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult auditData(ToBeScrap bean) { + try { + if (Objects.isNull(bean)) { + return AjaxResult.error("请求参数异常!"); + } + if (CollectionUtils.isEmpty(bean.getToBeScrapList())) { + return AjaxResult.error("请选择要审批的数据"); + } + String username = SecurityUtils.getLoginUser().getSysUser().getNickName(); + Long userId = SecurityUtils.getLoginUser().getUserid(); + for (ToBeScrap toBeScrap : bean.getToBeScrapList()) { + if (StrUtil.isNotBlank(toBeScrap.getReviewStatus())) { + if (!StrUtil.equalsAny(toBeScrap.getReviewStatus(), "1", "2")) { + throw new ServiceException("审批状态异常"); + } + toBeScrap.setCreateUser(username); + int res = scrapMapper.auditData(toBeScrap); + if (res < 1) { + throw new ServiceException("数据审批失败"); + } + // 如果是审批通过,需要增加周期表数据以及更新台账信息 + if (Objects.equals("1", toBeScrap.getReviewStatus())) { + if (Objects.equals("工具", toBeScrap.getType())) { + // 根据typeId和code查询台账信息 + ToBeScrap bean1 = scrapMapper.selectByTypeIdAndCode(toBeScrap); + if (bean1 != null && bean1.getId() > 0){ + //1、添加周期表数据 + ToBeScrap bean2 = new ToBeScrap(); + bean2.setId(bean1.getId()); + bean2.setCreateBy(userId); + bean2.setCreateUser(username); + bean2.setCode(toBeScrap.getDevCode()); + bean2.setDevCode(toBeScrap.getDevCode()); + bean2.setScrapNum(toBeScrap.getScrapNum()); + bean2.setIsScrap("1"); + bean2.setIsScrapFilter(1); + int addedToolLifecycle = scrapMapper.addToolLifecycleByRepair(bean2); + if (addedToolLifecycle < 1) { + throw new ServiceException("添加工具周期表数据失败"); + } + // 2、更新工具台账表 + int updatedToolLifecycle = scrapMapper.updateToolLifecycle(bean2); + if (updatedToolLifecycle <= 0) { + throw new ServiceException("更新工具台账信息失败"); + } + } + } else if (Objects.equals("装备", toBeScrap.getType())) { + //更新台账信息 + toBeScrap.setCreateBy(userId); + toBeScrap.setIsScrapFilter(1); + int updateDevInfos = scrapMapper.updateMaDevInfo(toBeScrap); + if (updateDevInfos <= 0){ + throw new ServiceException("更新台账信息失败"); + } + } else { + throw new ServiceException("设备类型异常"); + } + } + } else { + throw new ServiceException("审批状态为空,请检查!"); + } + } + // 明细审核完成后,根据审批数量去修改外层任务状态 + int pendingReviewCount = scrapMapper.selectCountByChangeId(bean.getId()); + if (pendingReviewCount > 0) { + int res = scrapMapper.updateChangeStatus(bean.getId(), "1"); + if (res < 1) { + throw new ServiceException("更新任务状态失败"); + } + } else if (pendingReviewCount == 0) { + int res = scrapMapper.updateChangeStatus(bean.getId(), "2"); + if (res < 1) { + throw new ServiceException("更新任务状态失败"); + } + } + + return AjaxResult.success("审批成功"); + } catch (Exception e) { + System.err.println(e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error("审核失败"); + } + } + + /** + * 新增报废退役任务 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult addScrapData(ToBeScrap bean) { + try { + if (bean.getToBeScrapList().isEmpty()) { + return AjaxResult.error("请添加退役明细数据"); + } + if (Objects.isNull(bean.getOperationType()) || !StrUtil.equalsAny(bean.getOperationType(), "add", "edit")) { + return AjaxResult.error("操作类型异常!"); + } + // 如果是编辑操作,那么就直接把之前的任务删掉重新建立 + if (Objects.equals("edit", bean.getOperationType())) { + scrapMapper.deleteChangeInfo(bean.getId()); + } + String username = SecurityUtils.getLoginUser().getSysUser().getNickName(); + //1、创建退役任务单号 + int thisMonthMaxOrder = scrapMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TypeEnums.TM_TASK_RETIRE.getTaskTypeId()); + String code = genderTaskCode(thisMonthMaxOrder); + CsDeviceInfo deviceInfo = new CsDeviceInfo(); + deviceInfo.setType(String.valueOf(TypeEnums.TM_TASK_RETIRE.getTaskTypeId())); + deviceInfo.setCode(code); + deviceInfo.setReviewStatus(Constants.LOGIN_SUCCESS_STATUS); + deviceInfo.setCreateUser(username); + // 添加任务 + int num = scrapMapper.addDeviceChangeApply(deviceInfo); + if (num < 1) { + throw new ServiceException("添加任务失败"); + } + Long changeId = deviceInfo.getId(); + // 保存任务明细 + for (ToBeScrap toBeScrap : bean.getToBeScrapList()) { + toBeScrap.setChangeId(changeId); + toBeScrap.setCreateUser(username); + if (CollectionUtils.isNotEmpty(toBeScrap.getBmFileInfos())) { + toBeScrap.setScrapUrl(toBeScrap.getBmFileInfos().get(0).getFileUrl()); + } + int res = scrapMapper.addScrapChangeApplyDetails(toBeScrap); + if (res <= 0) { + throw new ServiceException("添加退役明细数据失败"); + } + } + return AjaxResult.success("任务提交成功!"); + } catch (Exception e) { + System.err.println(e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error("申请失败"); + } + } + + /** + * 生成退役任务编号 + * @param thisMonthMaxOrder 本月最大单号 + * @return 任务单号 + */ + private String genderTaskCode(int thisMonthMaxOrder) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + String result = format.replace("-", ""); + return TypeConstants.SCRAP_TASK_TYPE_LABEL + result + String.format("-%04d", thisMonthMaxOrder + 1); + } + + /** + * 获取在库的装备、工具列表 + */ + @Override + public List getInStockList(ToBeScrap bean) { + return scrapMapper.getInStockList(bean); + } + + /** + * 获取报废申请列表 + */ + @Override + public List getScrapApplyList(ToBeScrap bean) { + return scrapMapper.getScrapApplyList(bean); + } + + /** + * 获取报废详情明细 + */ + @Override + public List getScrapDetailsList(ToBeScrap bean) { + return scrapMapper.getScrapDetailsList(bean); + } +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/upOrDown/tool/entity/ToolEntity.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/upOrDown/tool/entity/ToolEntity.java index 7e2b585..b30d611 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/upOrDown/tool/entity/ToolEntity.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/upOrDown/tool/entity/ToolEntity.java @@ -3,6 +3,7 @@ package com.bonus.material.upOrDown.tool.entity; import com.bonus.common.core.annotation.Excel; import com.bonus.material.device.domain.vo.DevInfoPropertyVo; import lombok.Data; +import org.apache.ibatis.type.Alias; import java.math.BigDecimal; import java.time.LocalDate; @@ -14,7 +15,7 @@ import java.util.List; * @version 1.0 * Create by 2025/11/15 23:13 */ - +@Alias("ToolTwoEntity") @Data public class ToolEntity { /** diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/scrap/ScrapMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/scrap/ScrapMapper.xml new file mode 100644 index 0000000..70c519d --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/scrap/ScrapMapper.xml @@ -0,0 +1,312 @@ + + + + + + + + + + + + + insert into cs_device_change(type, code, review_status, create_user, create_time, del_flag) + values (3, #{code}, #{reviewStatus}, #{createUser}, NOW(), '0') + + + + insert into cs_device_change_details( + change_id, + dev_code, + dev_type_id, + dev_type, + num, + real_num, + reason_val, + reason_url, + is_scrap, + create_user, + review_status, + create_time + ) + values ( + #{changeId}, + #{devCode}, + #{typeId}, + #{devType}, + #{scrapNum}, + #{scrapNum}, + #{reasonVal}, + #{scrapUrl}, + 1, + #{createUser}, + '0', + NOW() + ) + + + + + + update cs_device_change_details + set review_status = #{reviewStatus}, + review_by = #{createUser}, + review_time = now() + where id = #{id} + + + + + + insert into tool_lifecycle( + ledger_id, + tool_code, + action_type, + change_num, + status_before, + status_after, + operator_id, + operator_name, + operate_time, + create_time + ) + values ( + #{id}, + #{devCode}, + '退役', + #{scrapNum}, + '在库', + '退役', + #{createBy}, + #{createUser}, + NOW(), + NOW() + ) + + + + update + tool_ledger + set + available_num = available_num - #{scrapNum}, + scrap_num = scrap_num + #{scrapNum}, + status = '3', + update_time = now() + where + id = #{id} + + + + update + ma_dev_info + set + ma_status = '99', + + update_by = #{createBy}, + + update_time = now() + where + type_id = #{typeId} and code = #{devCode} + + + + + + update cs_device_change set review_status = #{reviewStatus} where id = #{changeId} + + + + update cs_device_change set del_flag = '2' where id = #{id} + + \ No newline at end of file