diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/controller/BackApplyInfoController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/controller/BackApplyInfoController.java index 505ec15e..eddec7ad 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/controller/BackApplyInfoController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/controller/BackApplyInfoController.java @@ -41,7 +41,7 @@ public class BackApplyInfoController extends BaseController { * 查询退料任务列表 */ @ApiOperation(value = "查询退料任务列表") - //@RequiresPermissions("back:info:list") + @RequiresPermissions("back:info:list") @GetMapping("/list") public TableDataInfo list(BackApplyInfo backApplyInfo) { startPage(); @@ -65,6 +65,7 @@ public class BackApplyInfoController extends BaseController { @SysLog(title = "退料任务", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出退料任务") @PostMapping("/export") public void export(HttpServletResponse response, BackApplyInfo backApplyInfo) { + backApplyInfo.setIsExport(true); List list = backApplyInfoService.selectBackApplyInfoList(backApplyInfo); ExcelUtil util = new ExcelUtil(BackApplyInfo.class); util.exportExcel(response, list, "退料任务数据"); @@ -74,7 +75,7 @@ public class BackApplyInfoController extends BaseController { * 获取退料任务详细信息 */ @ApiOperation(value = "获取退料任务详细信息") - //@RequiresPermissions("back:info:query") + @RequiresPermissions("back:info:query") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(backApplyInfoService.selectBackApplyInfoById(id)); @@ -112,12 +113,28 @@ public class BackApplyInfoController extends BaseController { } } + /** + * 退料申请提交 + */ + @ApiOperation(value = "退料申请提交") + //@PreventRepeatSubmit + //@RequiresPermissions("back:info:submit") + @SysLog(title = "退料任务", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->退料申请提交") + @PostMapping("/submitBackApply") + public AjaxResult submitBackApply(@RequestBody BackApplyInfo backApplyInfo) { + try { + return backApplyInfoService.submitBackApply(backApplyInfo); + } catch (Exception e) { + return error("系统错误, " + e.getMessage()); + } + } + /** * 删除退料任务 */ @ApiOperation(value = "删除退料任务") - //@PreventRepeatSubmit - //@RequiresPermissions("back:info:remove") + @PreventRepeatSubmit + @RequiresPermissions("back:info:remove") @SysLog(title = "退料任务", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除退料任务") @DeleteMapping("/{id}") public AjaxResult remove(@PathVariable Long id) { diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyDetails.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyDetails.java index cb0844c4..15902720 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyDetails.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyDetails.java @@ -82,6 +82,12 @@ public class BackApplyDetails extends BaseEntity { @ApiModelProperty(value = "机具外观判断") private String apDetection; + @ApiModelProperty(value = "退料状态") + private String backStatus; + + @ApiModelProperty(value = "是否完成 (0:未完成退料,可以撤回 1:已完成退料,不能撤回)") + private Integer isFinished; + /** 数据所属组织 */ @ApiModelProperty(value = "数据所属组织") private Long companyId; diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyInfo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyInfo.java index 5225d9f3..09f4a213 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyInfo.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/domain/BackApplyInfo.java @@ -21,6 +21,8 @@ import com.bonus.common.core.web.domain.BaseEntity; public class BackApplyInfo { private static final long serialVersionUID = 1L; + private Boolean isExport; + /** ID */ private Long id; @@ -57,7 +59,6 @@ public class BackApplyInfo { private String typeName; /** 任务ID */ - @Excel(name = "任务ID") @ApiModelProperty(value = "任务ID") private Long taskId; @@ -66,29 +67,30 @@ public class BackApplyInfo { @ApiModelProperty(value = "退料人") private String backPerson; + /** + * 退料数量 + */ + private Integer backNum; + /** 联系方式 */ @Excel(name = "退料人电话") @ApiModelProperty(value = "联系方式") private String phone; /** 机具公司审批人 */ - @Excel(name = "机具公司审批人") @ApiModelProperty(value = "机具公司审批人") private Long directAuditBy; /** 机具公司审批时间 */ @ApiModelProperty(value = "机具公司审批时间") @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "机具公司审批时间", width = 30, dateFormat = "yyyy-MM-dd") private Date directAuditTime; /** 机具公司审批备注 */ - @Excel(name = "机具公司审批备注") @ApiModelProperty(value = "机具公司审批备注") private String directAuditRemark; /** 数据所属组织 */ - @Excel(name = "数据所属组织") @ApiModelProperty(value = "数据所属组织") private Long companyId; @@ -124,6 +126,13 @@ public class BackApplyInfo { @Excel(name = "备注") private String remark; + @ApiModelProperty(value = "机具id") + private Long maId; + + /** 任务ID */ + @ApiModelProperty(value = "任务ID") + private Long parentId; + /** 直转id */ @ApiModelProperty(value = "直转id") private Long directId; diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java index b47379f7..b63bdfe6 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java @@ -6,6 +6,7 @@ import java.util.List; import com.bonus.material.back.domain.BackApplyDetails; import com.bonus.material.back.domain.BackApplyInfo; import com.bonus.material.back.domain.vo.MaCodeVo; +import com.bonus.material.settlement.domain.SltAgreementInfo; import org.apache.ibatis.annotations.Param; /** @@ -155,4 +156,88 @@ public interface BackApplyInfoMapper { */ int deleteCheckDetails(Long id); + /** + * 查询详情 + * @param id + * @return + */ + List selectBackDetails(Long id); + + /** + * 更新任务状态 + * @param backApplyInfo + * @return + */ + int updateTaskStatus(BackApplyInfo backApplyInfo); + + /** + * 更新退料单 + * @param backApplyInfo + * @return + */ + int updateBack(BackApplyInfo backApplyInfo); + + /** + * 更新详情 + * @param backApplyInfo + * @return + */ + int updateBackDetails(BackApplyInfo backApplyInfo); + + /** + * 更新机具退料详情 + * @param backApplyInfo + * @return + */ + int updateCheckDetails(BackApplyInfo backApplyInfo); + + /** + * 查询维修列表 + * @param backApplyInfo + * @return + */ + List getWxList(BackApplyInfo backApplyInfo); + + /** + * 查询维修单号 + * @param nowDate + * @return + */ + Integer selectTaskNumByMonthWx(@Param("date") Date nowDate); + + /** + * 新增维修单 + * @param wx + * @return + */ + int insertRad(BackApplyInfo wx); + + /** + * 查询结算信息 + * @param bean + * @return + */ + List getStlInfo(BackApplyInfo bean); + + /** + * 更新结算信息 + * @param info + * @param record + */ + void updateStlInfo(@Param("info") SltAgreementInfo info, @Param("record") BackApplyInfo record); + + /** + * 更新结算信息2 + * @param info + * @param record + * @param backNum + */ + void updateStlInfoTwo(@Param("info") SltAgreementInfo info,@Param("record") BackApplyInfo record, @Param("backNum") Integer backNum); + + /** + * 新增结算信息 + * @param info + * @param many + */ + void insStlInfoTwo(@Param("info")SltAgreementInfo info, @Param("many")Integer many); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/IBackApplyInfoService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/IBackApplyInfoService.java index d8cea68c..c63fa3e6 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/IBackApplyInfoService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/IBackApplyInfoService.java @@ -67,4 +67,11 @@ public interface IBackApplyInfoService { * @return */ AjaxResult getMachineById(BackApplyInfo dto); + + /** + * 提交退料申请 + * @param backApplyInfo + * @return + */ + AjaxResult submitBackApply(BackApplyInfo backApplyInfo); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java index 4345593f..61633f0b 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java @@ -18,6 +18,7 @@ import com.bonus.material.back.domain.vo.BackApplyRequestVo; import com.bonus.material.back.domain.vo.MaCodeVo; import com.bonus.material.basic.domain.BmFileInfo; import com.bonus.material.basic.mapper.BmFileInfoMapper; +import com.bonus.material.settlement.domain.SltAgreementInfo; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import com.bonus.material.back.mapper.BackApplyInfoMapper; @@ -167,7 +168,31 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { */ @Override public List selectBackApplyInfoList(BackApplyInfo backApplyInfo) { - return backApplyInfoMapper.selectBackApplyInfoList(backApplyInfo); + List list = backApplyInfoMapper.selectBackApplyInfoList(backApplyInfo); + // 如果列表为空,直接返回空列表 + if (CollectionUtils.isEmpty(list)) { + return new ArrayList<>(); + } + // 如果需要导出 + if (backApplyInfo.getIsExport()) { + for (BackApplyInfo applyInfo : list) { + applyInfo.setPrintStatus("0".equals(applyInfo.getPrintStatus()) ? "未打印" : "已打印"); + switch (applyInfo.getStatus()) { + case "0": + applyInfo.setStatus("退料未完成"); + break; + case "1": + applyInfo.setStatus("维修驳回"); + break; + case "2": + applyInfo.setStatus("退料已完成"); + break; + default: + break; + } + } + } + return list; } /** @@ -186,6 +211,14 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { if (StringUtils.isNotBlank(dto.getBackApplyInfo().getPhone()) && !PhoneUtil.isMobile(dto.getBackApplyInfo().getPhone())) { return AjaxResult.error("手机号格式不正确,请重新填写!"); } + //对提交的退料详情树木进行校验 + for (BackApplyDetails backApplyDetails : dto.getBackApplyDetailsList()) { + if (backApplyDetails.getNum() != null && backApplyDetails.getPreNum() != null) { + if (backApplyDetails.getNum() < backApplyDetails.getPreNum()) { + return AjaxResult.error("退料数量不能大于预退数量,请重新填写!"); + } + } + } //生成退料单号 String code = getString(); if (StringUtils.isBlank(code)) { @@ -271,13 +304,14 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { * @return */ private int saveMaCodeBmFileInfo(BackApplyDetails details, Long id, int result) { + // 设置公共字段 + setCommonFields(details, id); if (CollectionUtils.isNotEmpty(details.getMaCodeList())) { for (MaCodeDto maCodeDto : details.getMaCodeList()) { + // 设置每个 MaCodeDto 的独立属性 details.setMaId(maCodeDto.getMaId()); - details.setParentId(id); - details.setCreateBy(SecurityUtils.getUsername()); - details.setCreateTime(DateUtils.getNowDate()); - details.setStatus("0"); + details.setPreNum(1); + // 插入 CheckDetails result += backApplyInfoMapper.insertCheckDetails(details); if (CollectionUtils.isNotEmpty(maCodeDto.getBmFileInfos())) { for (BmFileInfo bmFileInfo : maCodeDto.getBmFileInfos()) { @@ -290,10 +324,29 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { } } } + } else { + // 如果 MaCodeList 为空,只插入 CheckDetails + result += backApplyInfoMapper.insertCheckDetails(details); } return result; } + /** + * 设置公共字段 + * @param details + * @param id + */ + private void setCommonFields(BackApplyDetails details, Long id) { + details.setParentId(id); + details.setCreateBy(SecurityUtils.getUsername()); + details.setCreateTime(DateUtils.getNowDate()); + details.setStatus("0"); + // 默认为 0,表示未完成 + details.setIsFinished(0); + // 默认返回状态 1 + details.setBackStatus("1"); + } + /** * 生成退料单号 * @return @@ -325,6 +378,17 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { */ @Override public AjaxResult updateBackApplyInfo(BackApplyRequestVo dto) { + if (dto == null || dto.getBackApplyInfo() == null || CollectionUtils.isEmpty(dto.getBackApplyDetailsList())) { + return AjaxResult.error("参数为空,请重新选择后上传!"); + } + //对提交的退料详情树木进行校验 + for (BackApplyDetails backApplyDetails : dto.getBackApplyDetailsList()) { + if (backApplyDetails.getNum() != null && backApplyDetails.getPreNum() != null) { + if (backApplyDetails.getNum() < backApplyDetails.getPreNum()) { + return AjaxResult.error("退料数量不能大于预退数量,请重新填写!"); + } + } + } try { //针对修改,先删除,后添加 //对传入的手机号进行校验 @@ -483,4 +547,183 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { return AjaxResult.success(backApplyInfoMapper.getMachineById(dto)); } + /** + * 提交退料申请 + * @param backApplyInfo + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult submitBackApply(BackApplyInfo backApplyInfo) { + // 根据传入的id查询退料申请信息 + List applyInfoList = backApplyInfoMapper.selectBackDetails(backApplyInfo.getId()); + // 设置更新信息 + backApplyInfo.setUpdateBy(SecurityUtils.getUsername()); + backApplyInfo.setUpdateTime(DateUtils.getNowDate()); + backApplyInfo.setTaskStatus(2); + // 更新任务表及退料申请表状态 + int result = updateTaskAndBackInfo(backApplyInfo); + if (result > 0 && CollectionUtils.isNotEmpty(applyInfoList)) { + for (BackApplyInfo applyInfo : applyInfoList) { + // 查询待维修的机具设备 + backApplyInfo.setTypeId(applyInfo.getTypeId()); + List wxList = backApplyInfoMapper.getWxList(backApplyInfo); + if (CollectionUtils.isNotEmpty(wxList)) { + // 插入任务表 + Long newTaskId = insertTt(SecurityUtils.getUsername()); + // 插入协议任务表 + result += insertTta(newTaskId, wxList); + // 插入维修记录表 + result += insertRad(newTaskId, wxList); + // 更新结算表 + int res = updateSlt4Bean(backApplyInfo, applyInfo); + // 检查机具是否领料 + if (res == 0) { + throw new RuntimeException("该机具未被领料使用"); + } + // 完成退料部分,更新 back_check_details + finishBackCheckDetails(backApplyInfo); + } + } + // 如果所有操作都成功 + if (result > 0) { + return AjaxResult.success(); + } + } + // 操作失败,返回错误 + return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg()); + } + + /** + * 更新任务表及退料申请表状态 + * @param backApplyInfo + * @return + */ + private int updateTaskAndBackInfo(BackApplyInfo backApplyInfo) { + int result = backApplyInfoMapper.updateTaskStatus(backApplyInfo); + result += backApplyInfoMapper.updateBack(backApplyInfo); + result += backApplyInfoMapper.updateBackDetails(backApplyInfo); + return result; + } + + /** + * 更新结算表 + * @param record + * @param bean + * @return + */ + private int updateSlt4Bean(BackApplyInfo record, BackApplyInfo bean) { + List infoList = backApplyInfoMapper.getStlInfo(bean); + if (infoList.size() > 0) { + Integer backNum = bean.getBackNum(); + for (SltAgreementInfo info : infoList) { + Integer num = info.getBackNum(); + if (backNum.equals(num)) { + backApplyInfoMapper.updateStlInfo(info, record); + break; + } else if (backNum > num) { + backNum = backNum - num; + backApplyInfoMapper.updateStlInfo(info, record); + } else { + Integer many = num - backNum; + backApplyInfoMapper.updateStlInfoTwo(info, record, backNum); + backApplyInfoMapper.insStlInfoTwo(info, many); + break; + } + } + } else { + return 0; + } + return 1; + } + + /** + * 完成退料申请 + * @param backApplyInfo + */ + private void finishBackCheckDetails(BackApplyInfo backApplyInfo) { + backApplyInfoMapper.updateCheckDetails(backApplyInfo); + } + + /** + * 插入维修记录表 + * @param taskId + * @param wxList + * @return + */ + private int insertRad(Long taskId, List wxList) { + int result = 0; + if (wxList != null) { + for (BackApplyInfo wx : wxList) { + wx.setTaskId(taskId); + wx.setStatus("0"); + result = backApplyInfoMapper.insertRad(wx); + } + } + return result; + } + + /** + * 插入协议任务表 + * @param taskId + * @param list + * @return + */ + private int insertTta(Long taskId, List list) { + int res; + String agreementId = String.valueOf(list.get(0).getAgreementId()); + BackApplyInfo backApplyInfo = new BackApplyInfo(); + backApplyInfo.setAgreementId(Long.parseLong(agreementId)); + backApplyInfo.setTaskId(taskId); + backApplyInfo.setCreateBy(SecurityUtils.getUsername()); + res = backApplyInfoMapper.insertTaskAgreement(backApplyInfo); + return res; + } + + /** + * 插入任务表 + * @param createBy + * @return + */ + private Long insertTt(String createBy) { + Long newTask = null; + // 生成维修单号 + String code = genCodeRule(); + BackApplyInfo applyInfo = new BackApplyInfo(); + applyInfo.setTaskType(4); // 设置任务类型 + applyInfo.setCode(code); // 设置单号 + applyInfo.setCreateBy(createBy); // 设置创建者 + applyInfo.setTaskStatus(0); + // 插入任务 + int taskId = backApplyInfoMapper.insertTmTask(applyInfo); + // 如果插入成功且返回的 taskId 大于 0 + if (taskId > 0 && applyInfo.getTaskId() > 0) { + newTask = applyInfo.getTaskId(); + } + return newTask; + } + + /** + * 生成维修单号 + * @return + */ + private String genCodeRule() { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + Integer taskNum = backApplyInfoMapper.selectTaskNumByMonthWx(nowDate); + String taskNumStr = ""; + if (taskNum != null) { + // 将字符串转换为整数 +// int num = Integer.parseInt(taskNum); + // 执行加一操作 + taskNum++; + // 将结果转换回字符串格式,并确保结果是四位数,不足四位则在前面补0 + taskNumStr = String.format("%02d", taskNum); + } else { + taskNumStr = "01"; + } + return "WX" + format + "-" + taskNumStr; + } + } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java index e4d6e183..ffd2f25d 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java @@ -45,6 +45,8 @@ public class SltAgreementInfo extends BaseEntity { @ApiModelProperty(value = "领料数量") private Long num; + private Integer backNum; + /** 领料时间 */ @ApiModelProperty(value = "领料时间") @JsonFormat(pattern = "yyyy-MM-dd") diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml index be833193..74f3cd86 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml @@ -30,6 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + insert into back_apply_info @@ -335,6 +408,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" back_num, ma_id, status, + back_status, + is_finished, create_by, create_time, remark, @@ -347,6 +422,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{preNum}, #{maId}, #{status}, + #{backStatus}, + #{isFinished}, #{createBy}, #{createTime}, #{remark}, @@ -355,6 +432,70 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + insert into repair_apply_details + ( + + task_id, + + + ma_id, + + + type_id, + + + repair_num, + + + status, + + + create_by, + + + remark, + + + company_id, + + + back_id, + + create_time + ) + values ( + + #{taskId}, + + + #{maId}, + + + #{typeId}, + + + #{backNum}, + + + #{status}, + + + #{createBy}, + + + #{remark}, + + + #{companyId}, + + + #{id}, + + NOW() + ) + + update back_apply_info @@ -375,6 +516,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + update tm_task set task_status = #{taskStatus} where task_id = #{taskId} + + + + update back_apply_info set status = #{taskStatus} where id = #{id} + + + + update back_apply_details set status = #{taskStatus} where parent_id = #{id} + + + + update back_check_details set is_finished = '1', update_time = now() where parent_id = #{id} and type_id = #{typeId} and (is_finished is null or is_finished != 1) + + + + update slt_agreement_info + set end_time = now(), + update_time = now(), + back_id = #{record.id}, + status = '1' + where id = #{info.id} + + + + update slt_agreement_info + set num = #{backNum}, + end_time = now(), + update_time = now(), + back_id = #{record.id}, + status = '1' + where id = #{info.id} + + + + insert into slt_agreement_info (agreement_id,type_id,ma_id,num,start_time,status,lease_id,lease_price,buy_price,is_slt,company_id,lease_type,create_time) + values (#{info.agreementId},#{info.typeId},#{info.maId},#{many},#{info.startTime},#{info.status},#{info.leaseId},#{info.leasePrice},#{info.buyPrice},'0',#{info.companyId},#{info.leaseType},now()); + delete from back_apply_info where id = #{id}