分公司班组领料同步材料站

This commit is contained in:
mashuai 2025-08-03 16:25:20 +08:00
parent 16fe9fedbb
commit f165448650
5 changed files with 368 additions and 9 deletions

View File

@ -307,4 +307,46 @@ public interface MaterialLeaseInfoMapper {
* @return
*/
List<LeaseOutDetails> getInfoByQrcodeClz(BmQrcodeInfo bmQrcodeInfo);
/**
* 添加站点领料出库数据
* @param record
* @return
*/
int insertLeaseApplyDetails(LeaseOutDetails record);
/**
* 根据任务id查询领料任务信息
* @param taskId
* @return
*/
MaterialLeaseApplyInfo selectId(Long taskId);
/**
* 根据任务id查询领料任务详情信息
* @param info
* @return
*/
MaterialLeaseApplyDetails selectDetailsById(MaterialLeaseApplyInfo info);
/**
* 修改站点领料详情数据
* @param details
* @return
*/
int updateLeaseApplyDetails(@Param("record") MaterialLeaseApplyDetails details);
/**
* 根据工器具id查询工器具领料详情数据
* @param record
* @return
*/
LeaseOutDetails selectInfoByTypeId(LeaseOutDetails record);
/**
* 修改站点领料详情数据
* @param leaseOutDetails
* @return
*/
int updateLeaseOutDetails(@Param("record") LeaseOutDetails leaseOutDetails);
}

View File

@ -1,23 +1,30 @@
package com.bonus.material.lease.service.impl;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import com.bonus.common.biz.constant.MaterialConstants;
import com.bonus.common.biz.domain.lease.LeaseApplyInfo;
import com.bonus.common.biz.enums.InputOutEnum;
import com.bonus.common.biz.enums.LeaseTaskStatusEnum;
import com.bonus.common.biz.enums.MaMachineStatusEnum;
import com.bonus.common.biz.enums.MaTypeManageTypeEnum;
import com.bonus.common.biz.enums.*;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.basic.domain.BmAgreementInfo;
import com.bonus.material.basic.domain.BmQrBoxInfo;
import com.bonus.material.basic.domain.BmUnit;
import com.bonus.material.basic.mapper.BmAgreementInfoMapper;
import com.bonus.material.basic.mapper.BmQrBoxMapper;
import com.bonus.material.clz.domain.BmTeam;
import com.bonus.material.clz.domain.lease.MaterialLeaseApplyDetails;
import com.bonus.material.clz.domain.lease.MaterialLeaseApplyInfo;
import com.bonus.material.clz.domain.vo.MaterialSltAgreementInfo;
import com.bonus.material.clz.mapper.BmTeamMapper;
import com.bonus.material.clz.mapper.MaterialLeaseInfoMapper;
import com.bonus.material.lease.domain.LeaseApplyDetails;
import com.bonus.material.lease.mapper.LeaseApplyDetailsMapper;
import com.bonus.material.lease.mapper.LeaseApplyInfoMapper;
@ -27,6 +34,7 @@ import com.bonus.material.ma.mapper.TypeMapper;
import com.bonus.material.settlement.domain.SltAgreementInfo;
import com.bonus.material.settlement.mapper.SltAgreementInfoMapper;
import com.bonus.material.task.domain.TmTask;
import com.bonus.material.task.domain.TmTaskAgreement;
import com.bonus.material.task.mapper.TmTaskAgreementMapper;
import com.bonus.material.task.mapper.TmTaskMapper;
import lombok.extern.slf4j.Slf4j;
@ -78,6 +86,12 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
@Resource
private BmQrBoxMapper bmQrBoxMapper;
@Resource
private BmTeamMapper bmTeamMapper;
@Resource
private MaterialLeaseInfoMapper materialLeaseInfoMapper;
/**
* 查询领料出库详细
*
@ -206,6 +220,135 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
}
}
}
// 7.将班组领料数据同步至材料站
//7.1 根据单位id判读是否为班组领料出库
BmUnit unit = tmTaskMapper.selectBmUnitById(record);
if (unit != null && unit.getTypeId() == 1731L) {
// 先根据taskId去tm_task中查询看数据是否存在
String createBy = SecurityUtils.getLoginUser().getSysUser().getNickName();
TmTask task = tmTaskMapper.selectTmTaskByPreTaskId(Long.parseLong(record.getTaskId()));
if (task == null) {
int thisMonthMaxOrder = tmTaskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TmTaskTypeEnum.TM_TASK_MATERIAL_LEASE.getTaskTypeId());
String taskCode = genderTaskCode(thisMonthMaxOrder);
TmTask tmTask = new TmTask();
tmTask = new TmTask(null, TmTaskTypeEnum.TM_TASK_MATERIAL_LEASE.getTaskTypeId(),
LeaseTaskStatusEnum.LEASE_TASK_FINISHED.getStatus(),
null, thisMonthMaxOrder + 1, taskCode);
tmTask.setCreateTime(DateUtils.getNowDate());
tmTask.setCreateBy(createBy);
tmTask.setPreTaskId(Long.parseLong(record.getTaskId()));
tmTaskMapper.insertTmTask(tmTask);
BmAgreementInfo bmAgreementInfo = new BmAgreementInfo();
bmAgreementInfo.setProjectId(Long.valueOf(record.getLeaseProjectId()));
bmAgreementInfo.setCreateTime(DateUtils.getNowDate());
bmAgreementInfo.setCreateBy(createBy);
bmAgreementInfo.setSignTime(DateUtils.getNowDate());
bmAgreementInfo.setAgreementCode(getAgreementCode());
// 先根据班组名称查询此班组是否存在
BmTeam tbTeam = new BmTeam();
tbTeam.setTeamName(record.getLeaseUnit());
tbTeam.setProjectId(record.getLeaseProjectId().toString());
// 班组类型固定传值
tbTeam.setTypeId(1731L);
BmTeam bmTeam = bmTeamMapper.selectByName(tbTeam);
if (bmTeam == null) {
// 新增班组
tbTeam.setCreateUser(SecurityUtils.getLoginUser().getUserid().toString());
int result = bmTeamMapper.insert(tbTeam);
if (result <= 0) {
return AjaxResult.error(HttpCodeEnum.UPDATE_TO_DATABASE.getCode(), HttpCodeEnum.UPDATE_TO_DATABASE.getMsg());
}
bmAgreementInfo.setUnitId(tbTeam.getId());
} else {
bmAgreementInfo.setUnitId(bmTeam.getId());
bmTeamMapper.update(tbTeam);
}
// 先根据班组和工程id查询若存在则直接返回不存在则新增
BmAgreementInfo info = bmAgreementInfoMapper.queryByTeamIdAndProjectIdCl(bmAgreementInfo);
if (info != null) {
record.setAgreementId(info.getAgreementId());
} else {
int count = bmAgreementInfoMapper.insertBmAgreementInfoClz(bmAgreementInfo);
if (count > 0) {
record.setAgreementId(bmAgreementInfo.getAgreementId());
} else {
return AjaxResult.error("新增bm_agreement_info表失败");
}
}
TmTaskAgreement tmTaskAgreement = new TmTaskAgreement(tmTask.getTaskId(), record.getAgreementId());
tmTaskAgreement.setCreateTime(DateUtils.getNowDate());
tmTaskAgreement.setCreateBy(createBy);
tmTaskAgreementMapper.insertTmTaskAgreement(tmTaskAgreement);
// 领料任务类型为2 数据同步
MaterialLeaseApplyInfo materialLeaseApplyInfo = new MaterialLeaseApplyInfo();
materialLeaseApplyInfo.setCode(taskCode);
materialLeaseApplyInfo.setTaskId(tmTask.getTaskId());
materialLeaseApplyInfo.setLeaseStyle("2");
materialLeaseApplyInfo.setTeamId(bmAgreementInfo.getUnitId().toString());
materialLeaseApplyInfo.setProjectId(record.getLeaseProjectId().toString());
int count = materialLeaseInfoMapper.insertLeaseApplyInfo(materialLeaseApplyInfo);
if (count > 0) {
return insertPurchaseCheckDetails(record, createBy, tmTask.getTaskId(), materialLeaseApplyInfo.getId());
} else {
return AjaxResult.error("新增任务失败,lease_apply_info表插入0条");
}
} else {
// 根据taskId查询领料任务
MaterialLeaseApplyInfo info = materialLeaseInfoMapper.selectId(task.getTaskId());
// 根据id查询clz_lease_apply_details表中数据是否存在
if (info != null) {
info.setTypeId(record.getTypeId().toString());
record.setParentId(info.getId());
record.setCreateTime(DateUtils.getNowDate());
record.setCreateBy(createBy);
record.setIsFinished(1);
MaterialLeaseApplyDetails details = materialLeaseInfoMapper.selectDetailsById(info);
if (details != null) {
// 走编辑
details.setOutNum(record.getOutNum());
details.setParentId(info.getId());
details.setTypeId(record.getTypeId());
int count = materialLeaseInfoMapper.updateLeaseApplyDetails(details);
if (count < 0) {
throw new Exception("更新clz_lease_apply_details表数据失败");
}
} else {
record.setPreNum(record.getOutNum());
record.setAlNum(record.getOutNum());
res = materialLeaseInfoMapper.insertLeaseApplyDetails(record);
if (res <= 0) {
throw new Exception("新增clz_lease_apply_details表数据失败");
}
}
// 根据类型查询clz_lease_out_details表数据是否存在
if (record.getMaId() != null) {
// 编码直接走新增
res = materialLeaseInfoMapper.insertLeaseOutDetails(record);
if (res <= 0) {
throw new Exception("新增clz_lease_out_details表数据失败");
}
res = insSltInfoClz(task.getTaskId(), record);
} else {
record.setTypeId(record.getTypeId());
// 数量先判断是否存在存在则进行数量追加否则新增
LeaseOutDetails leaseOutDetails = materialLeaseInfoMapper.selectInfoByTypeId(record);
if (leaseOutDetails != null) {
leaseOutDetails.setOutNum(record.getOutNum());
res = materialLeaseInfoMapper.updateLeaseOutDetails(leaseOutDetails);
if (res <= 0) {
throw new Exception("更新clz_lease_out_details表数据失败");
}
} else {
res = materialLeaseInfoMapper.insertLeaseOutDetails(record);
if (res <= 0) {
throw new Exception("新增clz_lease_out_details表数据失败");
}
}
res = insSltInfoClz(task.getTaskId(), record);
}
}
}
}
} else {
return AjaxResult.error("领料出库失败,机具库存不足");
}
@ -219,6 +362,87 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
return AjaxResult.success("出库成功");
}
/**
* 出库同步材料站
* @param record
* @param createBy
* @param taskId
* @param id
* @return
*/
private AjaxResult insertPurchaseCheckDetails(LeaseOutDetails record, String createBy, Long taskId, Long id) {
record.setCreateTime(DateUtils.getNowDate());
record.setCreateBy(createBy);
record.setParentId(id);
record.setIsFinished(1);
int res = materialLeaseInfoMapper.insertLeaseOutDetails(record);
if (res == 0) {
throw new RuntimeException("出库失败,插入结算记录失败");
}
record.setPreNum(record.getOutNum());
record.setAlNum(record.getOutNum());
res = materialLeaseInfoMapper.insertLeaseApplyDetails(record);
if (res == 0) {
throw new RuntimeException("出库失败,插入结算记录失败");
}
res = insSltInfoClz(taskId, record);
if (res == 0) {
throw new RuntimeException("出库失败,插入结算记录失败");
}
return AjaxResult.success("出库成功");
}
/**
* 插入结算记录
* @param taskId
* @param record
* @return
*/
private int insSltInfoClz(Long taskId, LeaseOutDetails record) {
int res = 0;
MaterialSltAgreementInfo sltAgreementInfo = materialLeaseInfoMapper.getSltAgreementInfo(record);
if (sltAgreementInfo != null) {
BigDecimal num = sltAgreementInfo.getNum();
BigDecimal outNum = record.getOutNum();
sltAgreementInfo.setNum(num.add(outNum));
res = materialLeaseInfoMapper.updSltInfo(sltAgreementInfo);
record.setAgreementId(sltAgreementInfo.getAgreementId());
} else {
String agreementId = tmTaskAgreementMapper.getAgreementId(taskId.toString());
Type maType = typeMapper.getMaType(record.getTypeId());
maType.setFinalPrice(maType.getLeasePrice());
res = materialLeaseInfoMapper.insSltInfo(record, agreementId, maType);
}
return res;
}
/**
* 生成任务编号
* @param thisMonthMaxOrder
* @return
*/
private static String genderTaskCode(Integer thisMonthMaxOrder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date nowDate = DateUtils.getNowDate();
String format = dateFormat.format(nowDate);
String result = format.replace("-", "");
return MaterialConstants.MATERIAL_LEASE_TASK_TYPE_LABEL + result + String.format("-%03d", thisMonthMaxOrder + 1);
}
/**
* 获取协议编号
*
* @return
*/
private String getAgreementCode() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date nowDate = DateUtils.getNowDate();
String format = dateFormat.format(nowDate);
String result = format.replace("-", "");
int num = bmAgreementInfoMapper.selectNumByMonthClz(nowDate);
return MaterialConstants.AGREEMENT_PREFIX + result + String.format("-%03d", num + 1);
}
/**
* app领料出库退回
*

View File

@ -3,6 +3,8 @@ package com.bonus.material.task.mapper;
import java.util.Date;
import java.util.List;
import com.bonus.common.biz.domain.lease.LeaseOutDetails;
import com.bonus.material.basic.domain.BmUnit;
import com.bonus.material.settlement.domain.SltAgreementInfo;
import com.bonus.material.task.domain.TmTask;
import org.apache.ibatis.annotations.Param;
@ -113,4 +115,18 @@ public interface TmTaskMapper {
* @return
*/
TmTask selectTaskByIdByCl(Long agreementId);
/**
* 根据协议id查询单位
* @param record
* @return
*/
BmUnit selectBmUnitById(LeaseOutDetails record);
/**
* 查询材料站领料数据
* @param parseLong
* @return
*/
TmTask selectTmTaskByPreTaskId(long parseLong);
}

View File

@ -284,6 +284,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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>
<insert id="insertLeaseApplyDetails">
insert into clz_lease_apply_details
(parent_id, type_id, pre_num, al_num, `status`, create_by, create_time, update_by,
update_time, remark, company_id)
values (#{parentId}, #{typeId}, #{preNum},#{alNum}, #{status}, #{createBy},NOW(), #{updateBy}, NOW(),
#{remark}, #{companyId})
</insert>
<update id="updateLeaseApplyInfo">
update clz_lease_apply_info
<trim prefix="SET" suffixOverrides=",">
@ -333,6 +341,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
<update id="updateLeaseApplyDetails">
UPDATE
clz_lease_apply_details
SET
pre_num = pre_num + #{record.outNum},
al_num = al_num + #{record.outNum},
update_time = now()
WHERE
parent_id = #{record.parentId} and type_id = #{record.typeId}
</update>
<update id="updateLeaseOutDetails">
UPDATE
clz_lease_out_details
SET
out_num = out_num + #{record.outNum},
update_time = now()
WHERE
parent_id = #{record.parentId} and type_id = #{record.typeId}
</update>
<delete id="deleteLeaseApplyDetailsByParentIds">
delete from clz_lease_apply_details where parent_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
@ -986,16 +1015,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mt.type_name AS typeName,
mt2.type_name AS materialType
FROM
clz_lease_out_details lod
LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id
clz_slt_agreement_info sai
LEFT JOIN ma_machine mm ON sai.ma_id = mm.ma_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
AND mt2.del_flag = '0'
LEFT JOIN clz_slt_agreement_info sai on lod.type_id = sai.type_id
and sai.ma_id = lod.ma_id
LEFT JOIN clz_bm_agreement_info ba ON sai.agreement_id = ba.agreement_id
WHERE
sai.status = '0'
@ -1119,4 +1146,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and mt.type_id = #{typeId}
</if>
</select>
<select id="selectId" resultType="com.bonus.material.clz.domain.lease.MaterialLeaseApplyInfo">
SELECT
id as id,
task_id as taskId
FROM
clz_lease_apply_info
WHERE
task_id = #{taskId}
</select>
<select id="selectDetailsById" resultType="com.bonus.material.clz.domain.lease.MaterialLeaseApplyDetails">
SELECT
id as id,
parent_id as parentId,
type_id as typeId,
pre_num as num
FROM
clz_lease_apply_details
WHERE
parent_id = #{id}
and type_id = #{typeId}
</select>
<select id="selectInfoByTypeId" resultType="com.bonus.common.biz.domain.lease.LeaseOutDetails">
SELECT
id as id,
parent_id as parentId,
type_id as typeId,
out_num as outNum
FROM
clz_lease_out_details
WHERE
parent_id = #{id}
and type_id = #{typeId}
</select>
</mapper>

View File

@ -188,4 +188,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and agreement_id = #{agreementId}
</if>
</select>
<select id="selectBmUnitById" resultType="com.bonus.material.basic.domain.BmUnit">
SELECT
unit_id as unitId,
type_id as typeId,
unit_name as unitName
FROM
bm_unit
WHERE
unit_id = #{leaseUnitId}
</select>
<select id="selectTmTaskByPreTaskId" parameterType="Long" resultMap="TmTaskResult">
<include refid="selectTmTaskVo"/>
where task_type = '22' and pre_task_id = #{taskId}
</select>
</mapper>