领料接口优化
This commit is contained in:
parent
4e3520aa3d
commit
ec9e196433
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import com.bonus.material.lease.domain.LeaseApplyDetails;
|
||||
import com.bonus.material.lease.domain.LeaseOutDetails;
|
||||
import com.bonus.material.ma.domain.Type;
|
||||
import com.bonus.material.settlement.domain.SltAgreementInfo;
|
||||
import com.bonus.material.task.domain.TmTask;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
|
@ -78,4 +79,39 @@ public interface LeaseOutDetailsMapper {
|
|||
Type selectByTypeId(@Param("record") LeaseOutDetails record);
|
||||
|
||||
int getCountOfCodeMachine(@Param("record") LeaseOutDetails record);
|
||||
|
||||
/** 插入领料出库详情表 -- 根据字段选择注入 */
|
||||
int insertSelective(LeaseOutDetails record);
|
||||
|
||||
/**
|
||||
* 减少 (ma_type 设备规格表)的库存数量
|
||||
*/
|
||||
int updateMaTypeStockNum(@Param("record") LeaseOutDetails leaseOutDetails);
|
||||
|
||||
/**
|
||||
* 修改机具设备(ma_machine表)的状态为:在用
|
||||
*/
|
||||
int updateMaMachineStatus(@Param("record") LeaseOutDetails leaseOutDetails);
|
||||
|
||||
SltAgreementInfo getSltAgreementInfo(LeaseOutDetails record);
|
||||
|
||||
int updSltInfo(SltAgreementInfo sltAgreementInfo);
|
||||
|
||||
String getAgreementId(String taskId);
|
||||
|
||||
Type getMaType(Long typeId);
|
||||
|
||||
String getProtocol(String agreementId);
|
||||
|
||||
int insSltInfo(@Param("record") LeaseOutDetails record, @Param("agreementId")String agreementId,@Param("ma") Type ma);
|
||||
|
||||
/**
|
||||
* 修改 (lease_apply_details 领料任务详细表)的已领数量
|
||||
*/
|
||||
int updateLeaseApplyDetailsOutNum(@Param("record") LeaseOutDetails leaseOutDetails);
|
||||
|
||||
LeaseApplyDetails getLeaseApplyDetails(@Param("record") LeaseOutDetails record);
|
||||
|
||||
int updateLeaseApplyDetails(@Param("record") LeaseOutDetails record);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,10 +73,10 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
|
|||
@Override
|
||||
public AjaxResult insertLeaseOutDetails(List<LeaseOutDetails> leaseOutDetailsList) {
|
||||
for (LeaseOutDetails bean : leaseOutDetailsList) {
|
||||
// AjaxResult ajaxResult = submitOut(bean);
|
||||
// if (ajaxResult.isError()) {
|
||||
// return ajaxResult;
|
||||
// }
|
||||
AjaxResult ajaxResult = submitOut(bean);
|
||||
if (ajaxResult.isError()) {
|
||||
return ajaxResult;
|
||||
}
|
||||
//leaseOutDetailsMapper.insertLeaseOutDetails(bean);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
|
|
@ -127,56 +127,56 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
|
|||
* @return 结果
|
||||
*/
|
||||
//@Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public AjaxResult submitOut(LeaseOutDetails record) {
|
||||
// int res = 0;
|
||||
// try {
|
||||
// // 1、判断是否重复提交
|
||||
// res = checkRepeatSubmit(record);
|
||||
// //record.setPreStoreNum(getStorageNum(record));
|
||||
// if (res > 0) {
|
||||
// if ((record.getManageType() == 1 || record.getManageType() == 2) && record.getInputNum() != null) {
|
||||
// record.setOutNum(record.getInputNum());
|
||||
// }
|
||||
// //2、判断成套机具出库库存是否足够
|
||||
// if (record.getManageType() == 2) {
|
||||
// res = checkStorageNumCt(record);
|
||||
// if (res == 0) {
|
||||
// throw new RuntimeException("出库失败,库存不足");
|
||||
// }
|
||||
// } else {
|
||||
// res = checkStorageNum(record);
|
||||
// }
|
||||
//
|
||||
// if (res > 0) {
|
||||
// // 3、插入出库记录,修改库存,修改机具状态
|
||||
// res = insertRecords(record);
|
||||
// if (res == 0) {
|
||||
// throw new RuntimeException("出库失败,更新设备规格库存数量时出错!");
|
||||
// }
|
||||
// // 4、修改任务状态(tm_task)
|
||||
// res = updateTaskStatus(record);
|
||||
// if (res == 0) {
|
||||
// throw new RuntimeException("出库失败,修改任务状态失败");
|
||||
// }
|
||||
// // 5、插入结算记录
|
||||
// String taskId = leaseOutDetailsMapper.getTaskId(record.getParentId());
|
||||
// res = insSltInfo(taskId, record);
|
||||
// if (res == 0) {
|
||||
// throw new RuntimeException("出库失败,插入结算记录失败");
|
||||
// }
|
||||
// //record.setPostStoreNum(getStorageNum(record));
|
||||
// } else {
|
||||
// return AjaxResult.error("领料出库失败,机具库存不足");
|
||||
// }
|
||||
// } else {
|
||||
// return AjaxResult.error("已领数量大于预领数量或该机具未在库");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// return AjaxResult.error("出库失败");
|
||||
// }
|
||||
// return AjaxResult.success("出库成功");
|
||||
// }
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult submitOut(LeaseOutDetails record) {
|
||||
int res = 0;
|
||||
try {
|
||||
// 1、判断是否重复提交
|
||||
res = checkRepeatSubmit(record);
|
||||
//record.setPreStoreNum(getStorageNum(record));
|
||||
if (res > 0) {
|
||||
if ((record.getManageType() == 1 || record.getManageType() == 2) && record.getInputNum() != null) {
|
||||
record.setOutNum(record.getInputNum());
|
||||
}
|
||||
//2、判断成套机具出库库存是否足够
|
||||
if (record.getManageType() == 2) {
|
||||
res = checkStorageNumCt(record);
|
||||
if (res == 0) {
|
||||
throw new RuntimeException("出库失败,库存不足");
|
||||
}
|
||||
} else {
|
||||
res = checkStorageNum(record);
|
||||
}
|
||||
|
||||
if (res > 0) {
|
||||
// 3、插入出库记录,修改库存,修改机具状态
|
||||
res = insertRecords(record);
|
||||
if (res == 0) {
|
||||
throw new RuntimeException("出库失败,更新设备规格库存数量时出错!");
|
||||
}
|
||||
// 4、修改任务状态(tm_task)
|
||||
res = updateTaskStatus(record);
|
||||
if (res == 0) {
|
||||
throw new RuntimeException("出库失败,修改任务状态失败");
|
||||
}
|
||||
// 5、插入结算记录
|
||||
String taskId = leaseOutDetailsMapper.getTaskId(record.getParentId());
|
||||
res = insSltInfo(taskId, record);
|
||||
if (res == 0) {
|
||||
throw new RuntimeException("出库失败,插入结算记录失败");
|
||||
}
|
||||
//record.setPostStoreNum(getStorageNum(record));
|
||||
} else {
|
||||
return AjaxResult.error("领料出库失败,机具库存不足");
|
||||
}
|
||||
} else {
|
||||
return AjaxResult.error("已领数量大于预领数量或该机具未在库");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("出库失败");
|
||||
}
|
||||
return AjaxResult.success("出库成功");
|
||||
}
|
||||
|
||||
private int checkRepeatSubmit(LeaseOutDetails record) {
|
||||
String maStatus = "15";
|
||||
|
|
@ -278,67 +278,67 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// private int insertRecords(LeaseOutDetails record) {
|
||||
// int res = 0;
|
||||
// // 首先更新领料任务详情表的领料数及状态(lease_apply_details)
|
||||
// res = leaseOutDetailsMapper.updateLeaseApplyDetailsOutNum(record);
|
||||
// LeaseApplyDetails leaseApplyDetails = leaseOutDetailsMapper.getLeaseApplyDetails(record);
|
||||
// if (leaseApplyDetails.getPreNum().equals(leaseApplyDetails.getAlNum()) || leaseApplyDetails.getAuditNum().equals(leaseApplyDetails.getAlNum())) {
|
||||
// leaseOutDetailsMapper.updateLeaseApplyDetails(record);
|
||||
// }
|
||||
// if (res > 0) {
|
||||
// // 插入领料出库明细表(lease_out_details)
|
||||
// res = leaseOutDetailsMapper.insertSelective(record);
|
||||
// if (res > 0) {
|
||||
// if (record.getManageType() == 2) {
|
||||
// // 成套机具减少 (ma_type 设备规格表)的库存数量
|
||||
// res = leaseOutDetailsMapper.updateMaTypeStockNum(record);
|
||||
// // 成套机具减少 (ma_type 设备规格表)配件的库存数量
|
||||
// List<TmTask> typeIds = leaseOutDetailsMapper.getMaTypeDetails(record);
|
||||
// typeIds.removeIf(item -> item == null);
|
||||
//// for (TmTask typeId : typeIds) {
|
||||
//// MachinePart machinePart = leaseOutDetailsMapper.getMachineParts(typeId);
|
||||
//// machinePart.setPartNum((typeId.getPartNum() * record.getOutNum()));
|
||||
//// typeId.setNum(machinePart.getNum() - machinePart.getPartNum());
|
||||
//// res = leaseOutDetailsMapper.updateMaTypeStockNumCt(typeId);
|
||||
//// }
|
||||
// } else {
|
||||
// // 普通机具减少 (ma_type 设备规格表)的库存数量
|
||||
// res = leaseOutDetailsMapper.updateMaTypeStockNum(record);
|
||||
// }
|
||||
// // 更新 (ma_machine 设备表)的状态
|
||||
// leaseOutDetailsMapper.updateMaMachineStatus(record);
|
||||
// }
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
// public int insSltInfo(String taskId, LeaseOutDetails record) {
|
||||
// int res = 0;
|
||||
// SltAgreementInfo sltAgreementInfo = leaseOutDetailsMapper.getSltAgreementInfo(record);
|
||||
// if (sltAgreementInfo != null) {
|
||||
// Long num = sltAgreementInfo.getNum();
|
||||
// Long outNum = record.getOutNum();
|
||||
// sltAgreementInfo.setNum(num + outNum);
|
||||
// res = leaseOutDetailsMapper.updSltInfo(sltAgreementInfo);
|
||||
// } else {
|
||||
// String agreementId = leaseOutDetailsMapper.getAgreementId(taskId);
|
||||
// String protocol = leaseOutDetailsMapper.getProtocol(agreementId);
|
||||
// Type ma = leaseOutDetailsMapper.getMaType(record.getTypeId());
|
||||
// if (StringUtils.isEmpty(protocol)) {
|
||||
// ma.setFinalPrice(ma.getLeasePrice());
|
||||
// } else {
|
||||
// if (MaterialConstants.INNER_PROTOCAL.equals(protocol)) {
|
||||
// ma.setFinalPrice(ma.getLeasePrice());
|
||||
// } else if (Constants.OUTER_PROTOCAL.equals(protocol)) {
|
||||
// ma.setFinalPrice(ma.getRentPrice());
|
||||
// } else {
|
||||
// ma.setFinalPrice(ma.getLeasePrice());
|
||||
// }
|
||||
// }
|
||||
// res = leaseOutDetailsMapper.insSltInfo(record, agreementId, ma);
|
||||
// }
|
||||
// return res;
|
||||
private int insertRecords(LeaseOutDetails record) {
|
||||
int res = 0;
|
||||
// 首先更新领料任务详情表的领料数及状态(lease_apply_details)
|
||||
res = leaseOutDetailsMapper.updateLeaseApplyDetailsOutNum(record);
|
||||
LeaseApplyDetails leaseApplyDetails = leaseOutDetailsMapper.getLeaseApplyDetails(record);
|
||||
if (leaseApplyDetails.getPreNum().equals(leaseApplyDetails.getAlNum()) || leaseApplyDetails.getAuditNum().equals(leaseApplyDetails.getAlNum())) {
|
||||
leaseOutDetailsMapper.updateLeaseApplyDetails(record);
|
||||
}
|
||||
if (res > 0) {
|
||||
// 插入领料出库明细表(lease_out_details)
|
||||
res = leaseOutDetailsMapper.insertSelective(record);
|
||||
if (res > 0) {
|
||||
if (record.getManageType() == 2) {
|
||||
// 成套机具减少 (ma_type 设备规格表)的库存数量
|
||||
res = leaseOutDetailsMapper.updateMaTypeStockNum(record);
|
||||
// 成套机具减少 (ma_type 设备规格表)配件的库存数量
|
||||
List<TmTask> typeIds = leaseOutDetailsMapper.getMaTypeDetails(record);
|
||||
typeIds.removeIf(item -> item == null);
|
||||
// for (TmTask typeId : typeIds) {
|
||||
// MachinePart machinePart = leaseOutDetailsMapper.getMachineParts(typeId);
|
||||
// machinePart.setPartNum((typeId.getPartNum() * record.getOutNum()));
|
||||
// typeId.setNum(machinePart.getNum() - machinePart.getPartNum());
|
||||
// res = leaseOutDetailsMapper.updateMaTypeStockNumCt(typeId);
|
||||
// }
|
||||
} else {
|
||||
// 普通机具减少 (ma_type 设备规格表)的库存数量
|
||||
res = leaseOutDetailsMapper.updateMaTypeStockNum(record);
|
||||
}
|
||||
// 更新 (ma_machine 设备表)的状态
|
||||
leaseOutDetailsMapper.updateMaMachineStatus(record);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int insSltInfo(String taskId, LeaseOutDetails record) {
|
||||
int res = 0;
|
||||
SltAgreementInfo sltAgreementInfo = leaseOutDetailsMapper.getSltAgreementInfo(record);
|
||||
if (sltAgreementInfo != null) {
|
||||
Long num = sltAgreementInfo.getNum();
|
||||
Long outNum = record.getOutNum();
|
||||
sltAgreementInfo.setNum(num + outNum);
|
||||
res = leaseOutDetailsMapper.updSltInfo(sltAgreementInfo);
|
||||
} else {
|
||||
String agreementId = leaseOutDetailsMapper.getAgreementId(taskId);
|
||||
String protocol = leaseOutDetailsMapper.getProtocol(agreementId);
|
||||
Type maType = leaseOutDetailsMapper.getMaType(record.getTypeId());
|
||||
if (StringUtils.isEmpty(protocol)) {
|
||||
maType.setFinalPrice(maType.getLeasePrice());
|
||||
} else {
|
||||
if (MaterialConstants.INNER_PROTOCAL.equals(protocol)) {
|
||||
maType.setFinalPrice(maType.getLeasePrice());
|
||||
} else if (MaterialConstants.OUTER_PROTOCAL.equals(protocol)) {
|
||||
maType.setFinalPrice(maType.getRentPrice());
|
||||
} else {
|
||||
maType.setFinalPrice(maType.getLeasePrice());
|
||||
}
|
||||
}
|
||||
res = leaseOutDetailsMapper.insSltInfo(record, agreementId, maType);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,6 +123,9 @@ public class Type extends BaseEntity {
|
|||
@ApiModelProperty(value = "丢失赔偿价")
|
||||
private BigDecimal payPrice;
|
||||
|
||||
@ApiModelProperty(value = "???价")
|
||||
private BigDecimal finalPrice;
|
||||
|
||||
/** 税率 */
|
||||
@ApiModelProperty(value = "税率")
|
||||
private BigDecimal taxRatio;
|
||||
|
|
|
|||
|
|
@ -182,4 +182,194 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and mt.`level` = 4
|
||||
and mt.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<insert id="insertSelective">
|
||||
insert into lease_out_details
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="parentId!= null">
|
||||
parent_id,
|
||||
</if>
|
||||
<if test="typeId!= null">
|
||||
type_id,
|
||||
</if>
|
||||
<if test="maId!= null">
|
||||
ma_id,
|
||||
</if>
|
||||
<if test="outNum!= null">
|
||||
out_num,
|
||||
</if>
|
||||
<if test="outType!= null">
|
||||
out_type,
|
||||
</if>
|
||||
<if test="createBy!= null">
|
||||
create_by,
|
||||
</if>
|
||||
<if test="updateBy!= null">
|
||||
update_by,
|
||||
</if>
|
||||
<if test="remark!= null">
|
||||
remark,
|
||||
</if>
|
||||
<if test="companyId!= null">
|
||||
company_id,
|
||||
</if>
|
||||
<if test="carCode!= null">
|
||||
car_code,
|
||||
</if>
|
||||
create_time,
|
||||
update_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="parentId!= null">
|
||||
#{parentId},
|
||||
</if>
|
||||
<if test="typeId!= null">
|
||||
#{typeId},
|
||||
</if>
|
||||
<if test="maId!= null">
|
||||
#{maId},
|
||||
</if>
|
||||
<if test="outNum!= null">
|
||||
#{outNum},
|
||||
</if>
|
||||
<if test="outType!= null">
|
||||
#{outType},
|
||||
</if>
|
||||
<if test="createBy!= null">
|
||||
#{createBy},
|
||||
</if>
|
||||
<if test="updateBy!= null">
|
||||
#{updateBy},
|
||||
</if>
|
||||
<if test="remark!= null">
|
||||
#{remark},
|
||||
</if>
|
||||
<if test="companyId!= null">
|
||||
#{companyId},
|
||||
</if>
|
||||
<if test="carCode!= null">
|
||||
#{carCode},
|
||||
</if>
|
||||
NOW(),
|
||||
NOW()
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateMaTypeStockNum">
|
||||
UPDATE
|
||||
ma_type
|
||||
SET
|
||||
num = num - #{record.outNum} ,update_time = NOW()
|
||||
WHERE
|
||||
type_id = #{record.typeId}
|
||||
</update>
|
||||
|
||||
<update id="updateMaMachineStatus">
|
||||
UPDATE
|
||||
ma_machine
|
||||
SET
|
||||
ma_status = '16',create_time = NOW()
|
||||
<where>
|
||||
type_id = #{record.typeId}
|
||||
<if test="record.maId != null and record.maId != ''">
|
||||
and ma_id = #{record.maId}
|
||||
</if>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<select id="getSltAgreementInfo" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
|
||||
SELECT
|
||||
id,
|
||||
agreement_id AS agreementId,
|
||||
type_id AS typeId,
|
||||
ma_id AS maId,
|
||||
num AS num,
|
||||
start_time AS startTime,
|
||||
end_time AS endTime,
|
||||
status AS status,
|
||||
lease_id AS leaseId,
|
||||
back_id AS backId,
|
||||
lease_price AS leasePrice,
|
||||
buy_price AS buyPrice,
|
||||
company_id AS companyId
|
||||
FROM
|
||||
slt_agreement_info
|
||||
WHERE
|
||||
lease_id = #{parentId}
|
||||
AND
|
||||
type_id = #{typeId}
|
||||
AND
|
||||
ma_id IS NULL
|
||||
AND
|
||||
status = '0'
|
||||
AND
|
||||
DATE(start_time) = CURDATE();
|
||||
</select>
|
||||
|
||||
<update id="updSltInfo">
|
||||
update slt_agreement_info
|
||||
set num = #{num},
|
||||
update_time = now()
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="getAgreementId" resultType="java.lang.String">
|
||||
select agreement_id
|
||||
from tm_task_agreement
|
||||
where task_id = #{taskId}
|
||||
</select>
|
||||
<select id="getMaType" resultType="com.bonus.material.ma.domain.Type">
|
||||
select lease_price as leasePrice,
|
||||
rent_price as rentPrice,
|
||||
buy_price as buyPrice,
|
||||
pay_price as payPrice,
|
||||
company_id as companyId
|
||||
from ma_type
|
||||
where type_id = #{typeId} and del_flag = 0
|
||||
</select>
|
||||
<select id="getProtocol" resultType="java.lang.String">
|
||||
select protocol
|
||||
from bm_agreement_info
|
||||
where agreement_id = #{agreementId}
|
||||
</select>
|
||||
|
||||
<insert id="insSltInfo">
|
||||
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 (#{agreementId},#{record.typeId},#{record.maId},#{record.outNum},now(),0,#{record.parentId},#{ma.finalPrice},#{ma.buyPrice},'0',#{record.companyId},#{record.leaseType},now());
|
||||
</insert>
|
||||
|
||||
<update id="updateLeaseApplyDetailsOutNum">
|
||||
UPDATE
|
||||
lease_apply_details
|
||||
SET
|
||||
al_num = IF(al_num IS NULL, #{record.outNum}, al_num + #{record.outNum}),
|
||||
<if test="record.updateBy != null and record.updateBy!= '' ">
|
||||
update_by = #{record.updateBy},
|
||||
</if>
|
||||
update_time = now(),
|
||||
status = '1'
|
||||
WHERE
|
||||
parennt_id = #{record.parentId} and type_id = #{record.typeId}
|
||||
</update>
|
||||
|
||||
<select id="getLeaseApplyDetails" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
|
||||
SELECT
|
||||
ifnull( pre_num, 0 ) AS preNum,
|
||||
ifnull( audit_num, 0 ) AS auditNum,
|
||||
ifnull( al_num, 0 ) AS alNum
|
||||
FROM
|
||||
lease_apply_details
|
||||
WHERE
|
||||
parennt_id = #{record.parentId}
|
||||
AND type_id = #{record.typeId}
|
||||
</select>
|
||||
|
||||
<update id="updateLeaseApplyDetails">
|
||||
UPDATE
|
||||
lease_apply_details
|
||||
SET
|
||||
status = '2'
|
||||
WHERE
|
||||
parennt_id = #{record.parentId} and type_id = #{record.typeId}
|
||||
</update>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue