diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/lease/LeaseOutDetails.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/lease/LeaseOutDetails.java index c75d26f5..dd36e9be 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/lease/LeaseOutDetails.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/lease/LeaseOutDetails.java @@ -166,4 +166,7 @@ public class LeaseOutDetails extends BaseEntity { @ApiModelProperty(value = "来源") private Integer source; + @ApiModelProperty(value = "领料方式 0材料领料 1工器具领料 2数据同步") + private String leaseStyle; + } 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 22c9c4c9..568b5f20 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 @@ -206,4 +206,10 @@ public class BackApplyInfo implements Serializable { @ApiModelProperty(value = "材料员确认备注") private String confirmRemark; + + @ApiModelProperty(value="工程id") + private Long projectId; + + @ApiModelProperty(value = "退料方式(1 直退,2 数据同步)") + private String backStyle; } 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 1e4485f7..aeaed0d0 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 @@ -12,6 +12,7 @@ import com.bonus.material.back.domain.MaCodeDto; import com.bonus.material.back.domain.vo.BackApplyInfoVo; import com.bonus.material.back.domain.vo.BackApplyVo; import com.bonus.material.back.domain.vo.MaCodeVo; +import com.bonus.material.clz.domain.back.MaterialBackApplyDetails; import com.bonus.material.settlement.domain.SltAgreementInfo; import org.apache.ibatis.annotations.Param; @@ -247,7 +248,7 @@ public interface BackApplyInfoMapper { * @return */ int deleteDetails(BackApplyInfo backApplyInfo); - + /** * 查询机具 * @param dto @@ -428,6 +429,34 @@ public interface BackApplyInfoMapper { */ List selectBackApplyDetailsList(BackApplyDetails backApplyDetails); + /** + * 根据单位和工程id查询项目部关联协议id + * @param backApplyInfo + * @return + */ + BackApplyInfo selectInfo(BackApplyInfo backApplyInfo); + + /** + * 根据任务id查询协议信息 + * @param info + * @return + */ + SltAgreementInfo getStlInfoByTaskId(SltAgreementInfo info); + + /** + * 查询拆分退料任务单 + * @param backApplyDetails + * @return + */ + List selectClzList(MaterialBackApplyDetails backApplyDetails); + + /** + * 查询项目退料任务单 + * @param details + * @return + */ + List selectXmList(BackApplyDetails details); + List getMachineByOne(BackApplyInfo dto); List getMachineByTwo(BackApplyInfo dto); @@ -439,4 +468,11 @@ public interface BackApplyInfoMapper { List getMachineByTwoMaCode(BackApplyInfo dto); List getMachineByThreeMaCode(BackApplyInfo dto); + + /** + * 查询是否存在班组数据 + * @param bean + * @return + */ + List getTbList(BackApplyInfo bean); } 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 80c77d8c..a117d35f 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 @@ -977,12 +977,12 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { } else { return AjaxResult.error("退料物资为空,无法进行提交"); } - // 判断是否为班组退料,将退料同步材料站 + // 判断是否为班组退料,将退料同步材料站以及项目部 boolean isClz = false; - /*BmUnit unit = taskMapper.selectBmUnitInfo(backApplyInfo); + BmUnit unit = taskMapper.selectBmUnitInfo(backApplyInfo); if (unit != null && unit.getTypeId() == 1731L) { isClz = true; - }*/ + } // 设置更新信息, backApplyInfo.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); backApplyInfo.setUpdateTime(DateUtils.getNowDate()); @@ -1006,6 +1006,7 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { bmAgreementInfo.setUnitId(backApplyInfo.getUnitId()); bmAgreementInfo.setProjectId(backApplyInfo.getProId()); BmAgreementInfo info = bmAgreementInfoMapper.queryByTeamIdAndProjectIdCl(bmAgreementInfo); + BackApplyInfo backApplyInfo4 = new BackApplyInfo(); if (isClz) { int thisMonthMaxOrder = taskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TmTaskTypeEnum.TM_TASK_MATERIAL_BACK.getTaskTypeId()); String code = genderClzTaskCode(thisMonthMaxOrder); @@ -1049,6 +1050,45 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { } } } + // 材料站对分公司建立退料任务 + int backMonthMaxOrder = taskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TmTaskTypeEnum.TM_TASK_BACK.getTaskTypeId()); + String backCode = genderTaskCode(backMonthMaxOrder); + TmTask newTask = new TmTask(null, TmTaskTypeEnum.TM_TASK_BACK.getTaskTypeId(), + BackTaskStatusEnum.BACK_TASK_IN_FINISHED.getStatus(), + null,backMonthMaxOrder + 1, backCode); + newTask.setCreateTime(DateUtils.getNowDate()); + newTask.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + backApplyInfo4.setCode(backCode); + backApplyInfo4.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + backApplyInfo4.setCreateTime(DateUtils.getNowDate()); + // 保存退料信息到 tm_task 表中 + result += taskMapper.insertTmTask(newTask); + if (result > 0) { + // 根据单位和工程id查询项目部关联协议id + BackApplyInfo backApplyInfo3 = backApplyInfoMapper.selectInfo(backApplyInfo); + if (backApplyInfo3 != null) { + TmTaskAgreement tmTaskAgreement = new TmTaskAgreement(newTask.getTaskId(), backApplyInfo3.getAgreementId()); + tmTaskAgreement.setCreateTime(DateUtils.getNowDate()); + tmTaskAgreement.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + taskAgreementMapper.insertTmTaskAgreement(tmTaskAgreement); + } + backApplyInfo4.setTaskId(newTask.getTaskId()); + BackApplyInfo backApplyInfo2 = backApplyInfoMapper.selectBackApplyInfoById(backApplyInfo.getId()); + if (backApplyInfo2 != null) { + backApplyInfo4.setBackPerson(StringUtils.isNotBlank(backApplyInfo2.getBackPerson()) ? backApplyInfo2.getBackPerson() : ""); + backApplyInfo4.setPhone(StringUtils.isNotBlank(backApplyInfo2.getPhone()) ? backApplyInfo2.getPhone() : ""); + backApplyInfo4.setBackStyle("2"); + } + result += backApplyInfoMapper.insertBackApplyInfo(backApplyInfo4); + } + // 保存退料详情 + if (CollectionUtils.isNotEmpty(applyDetails)) { + for (BackApplyDetails applyDetail : applyDetails) { + // 保存退料详情 + applyDetail.setAuditNum(applyDetail.getPreNum()); + result += backApplyInfoMapper.insertBackApplyDetails(applyDetail); + } + } } for (String typeId : typeIdList) { // 查询待维修的机具设备 @@ -1060,11 +1100,13 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { // 更新结算表 List allList = backApplyInfoMapper.selectBackDetails(backApplyInfo); if (CollectionUtils.isNotEmpty(allList)) { - int res = updateSlt4Bean(backApplyInfo, allList); + int res = updateSlt4Bean(isClz,backApplyInfo, allList); // 检查机具是否领料 if (res == 0) { throw new RuntimeException("该机具未被领料使用"); } + List clzList = new ArrayList<>(); + List xmList = new ArrayList<>(); if (isClz) { for (BackApplyInfo applyInfo : allList) { applyInfo.setAgreementId(info.getAgreementId()); @@ -1078,11 +1120,29 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { details.setMaId(applyInfo.getMaId() != null ? applyInfo.getMaId() : null); details.setIsFinished(1); result += materialBackInfoMapper.insertCheckDetails(details); + // 查询材料站同步数据 + clzList = backApplyInfoMapper.selectClzList(details); + BackApplyDetails backApplyDetails = new BackApplyDetails(); + backApplyDetails.setParentId(backApplyInfo4.getId()); + backApplyDetails.setTypeId(Long.parseLong(typeId)); + backApplyDetails.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + backApplyDetails.setCreateTime(DateUtils.getNowDate()); + backApplyDetails.setPreNum(applyInfo.getBackNum()); + backApplyDetails.setMaId(applyInfo.getMaId() != null ? applyInfo.getMaId() : null); + backApplyDetails.setStatus("0"); + backApplyDetails.setIsFinished(1); + result += backApplyInfoMapper.insertCheckDetails(backApplyDetails); + // 查询项目部同步数据 + xmList = backApplyInfoMapper.selectXmList(backApplyDetails); } - res = updateSlt4BeanClz(materialBackApplyInfo, allList); + res = updateSlt4BeanClz(materialBackApplyInfo, clzList); if (res == 0) { throw new RuntimeException("同步材料站结算出错"); } + res = updateSlt4BeanXm(backApplyInfo4, xmList); + if (res == 0) { + throw new RuntimeException("同步项目部结算出错"); + } } } // 完成退料部分,更新 back_check_details @@ -1098,6 +1158,39 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg()); } + /** + * 结算处理 + * @param record + * @param allList + * @return + */ + private int updateSlt4BeanXm(BackApplyInfo record, List allList) { + for (BackApplyInfo bean : allList) { + List infoList = backApplyInfoMapper.getStlInfo(bean); + if (infoList.size() > 0) { + BigDecimal backNum = bean.getBackNum(); + for (SltAgreementInfo info : infoList) { + BigDecimal num = info.getBackNum(); + if (backNum.compareTo(num) == 0) { + backApplyInfoMapper.updateStlInfo(info, record); + break; + } else if (backNum.compareTo(num) > 0) { + backNum = backNum.subtract(num); + backApplyInfoMapper.updateStlInfo(info, record); + } else { + BigDecimal many = num.subtract(backNum); + backApplyInfoMapper.updateStlInfoTwo(info, record, backNum); + backApplyInfoMapper.insStlInfoTwo(info, many); + break; + } + } + } else { + return 0; + } + } + return 1; + } + /** * 生成材料站退料任务单号 * @param thisMonthMaxOrder @@ -2103,28 +2196,53 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { * @param allList * @return */ - private int updateSlt4Bean(BackApplyInfo record, List allList) { + private int updateSlt4Bean(Boolean isClz ,BackApplyInfo record, List allList) { for (BackApplyInfo bean : allList) { List infoList = backApplyInfoMapper.getStlInfo(bean); - if (infoList.size() > 0) { - BigDecimal backNum = bean.getBackNum(); - for (SltAgreementInfo info : infoList) { - BigDecimal num = info.getBackNum(); - if (backNum.compareTo(num) == 0) { - backApplyInfoMapper.updateStlInfo(info, record); - break; - } else if (backNum.compareTo(num) > 0) { - backNum = backNum.subtract(num); - backApplyInfoMapper.updateStlInfo(info, record); - } else { - BigDecimal many = num.subtract(backNum); - backApplyInfoMapper.updateStlInfoTwo(info, record, backNum); - backApplyInfoMapper.insStlInfoTwo(info, many); - break; + // 查询是否存在班组数据 + List tbList = backApplyInfoMapper.getTbList(bean); + if (CollectionUtils.isEmpty(infoList)) { + return 0; + } + BigDecimal backNum = bean.getBackNum(); + // 遍历每个typeId + for (SltAgreementInfo info : infoList) { + // 获取前端要退数量 + BigDecimal num = info.getBackNum(); + if (backNum.compareTo(num) == 0) { + backApplyInfoMapper.updateStlInfo(info, record); + break; + } else if (backNum.compareTo(num) > 0) { + backNum = backNum.subtract(num); + backApplyInfoMapper.updateStlInfo(info, record); + } else { + BigDecimal many = num.subtract(backNum); + backApplyInfoMapper.updateStlInfoTwo(info, record, backNum); + backApplyInfoMapper.insStlInfoTwo(info, many); + break; + } + } + // 非班组退料才同步班组分公司数据 + if (!isClz) { + BigDecimal tbBackNum = bean.getBackNum(); + if (CollectionUtils.isNotEmpty(tbList)) { + for (SltAgreementInfo info : tbList) { + // 获取前端要退数量 + BigDecimal num = info.getBackNum(); + if (tbBackNum.compareTo(num) == 0) { + backApplyInfoMapper.updateStlInfo(info, record); + break; + } else if (tbBackNum.compareTo(num) > 0) { + tbBackNum = tbBackNum.subtract(num); + backApplyInfoMapper.updateStlInfo(info, record); + } else { + BigDecimal many = num.subtract(tbBackNum); + backApplyInfoMapper.updateStlInfoTwo(info, record, tbBackNum); + backApplyInfoMapper.insStlInfoTwo(info, many); + break; + } } } - } else { - return 0; } } return 1; diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java index e7677995..32861c05 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java @@ -1557,17 +1557,6 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService { record.setOutType(leaseMaCodeDto.getOutType()); record.setTypeId(Long.parseLong(leaseMaCodeDto.getTypeId())); int res = materialLeaseInfoMapper.insertLeaseOutDetails(record); - /*// 更新 (ma_machine 设备表)的状态 - if (res > 0) { - machineMapper.updateMaMachineStatus(record, MaMachineStatusEnum.IN_USE.getStatus()); - } - if (res > 0) { - // 普通机具减少 (ma_type 设备规格表)的库存数量 - res = typeMapper.updateMaTypeStockNum(record); - if (res == 0) { - return AjaxResult.error("更新ma_type表数据失败"); - } - }*/ if (res > 0) { res = insSltInfo(taskId, record); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java index 5b92f230..b748eda8 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java @@ -452,6 +452,7 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService { String agreementId = tmTaskAgreementMapper.getAgreementId(taskId.toString()); Type maType = typeMapper.getMaType(record.getTypeId()); maType.setFinalPrice(maType.getLeasePrice()); + record.setLeaseStyle("2"); res = materialLeaseInfoMapper.insSltInfo(record, agreementId, maType); } return res; 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 22b529f6..944da680 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 @@ -237,4 +237,9 @@ public class SltAgreementInfo extends BaseEntity { //结算费用 private BigDecimal totalCostAll; + + @ApiModelProperty(value = "领料方式 0材料领料 1工器具领料 2数据同步") + private String leaseStyle; + + private String source; } 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 7e01f7db..be70ecdb 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 @@ -76,7 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" JOIN ma_type_repair mtr ON mtr.type_id = bad.type_id AND mtr.user_id = #{userId} WHERE - 1=1 + bai.back_style = '1' and bu.unit_id = #{unitId} @@ -135,7 +135,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND mt2.del_flag = '0' LEFT JOIN bm_agreement_info ba ON sai.agreement_id = ba.agreement_id WHERE - mm.ma_status = '2' + sai.`status` = '0' + AND mm.ma_status = '2' AND ba.unit_id = #{unitId} AND ba.project_id = #{proId} @@ -146,7 +147,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mm.ma_code like concat('%', #{keyWord}, '%') ) - GROUP BY mm.ma_code + GROUP BY mm.ma_id + + + + + + + + + + diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml index e5744c6d..923a3e66 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml @@ -543,7 +543,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" back_id AS backId, lease_price AS leasePrice, buy_price AS buyPrice, - company_id AS companyId + company_id AS companyId, + lease_style AS leaseStyle FROM clz_slt_agreement_info WHERE diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml index fdd5665d..36618fc7 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml @@ -280,8 +280,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - insert into clz_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,publish_task) - values (#{agreementId},#{record.typeId},#{record.maId},#{record.outNum},now(),0,#{record.parentId},#{ma.finalPrice},#{ma.buyPrice},'0',#{record.companyId},#{record.leaseType},now(),#{record.publishTask}); + insert into clz_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,publish_task, lease_style) + values (#{agreementId},#{record.typeId},#{record.maId},#{record.outNum},now(),0,#{record.parentId},#{ma.finalPrice},#{ma.buyPrice},'0',#{record.companyId},#{record.leaseType},now(),#{record.publishTask}, #{record.leaseStyle}); @@ -929,8 +929,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND publish_task = #{publishTask} - AND - DATE(start_time) = CURDATE();