维修管理--公共方法抽取、常量引用
This commit is contained in:
parent
7a381a0de4
commit
7e4725c231
|
|
@ -93,7 +93,7 @@ public class RepairApplyRecord extends BaseEntity {
|
|||
|
||||
/** 类型(0不收费,1收费) */
|
||||
@Excel(name = "类型", readConverterExp = "0=不收费,1收费")
|
||||
private String partType;
|
||||
private Integer partType;
|
||||
|
||||
/** 配件名称 */
|
||||
@Excel(name = "配件名称")
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ import com.bonus.common.core.web.domain.BaseEntity;
|
|||
* @author xsheng
|
||||
* @date 2024-10-16
|
||||
*/
|
||||
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class RepairPartDetails extends BaseEntity {
|
||||
|
|
@ -55,7 +53,7 @@ public class RepairPartDetails extends BaseEntity {
|
|||
|
||||
/** 类型(0不收费,1收费) */
|
||||
@Excel(name = "类型", readConverterExp = "0=不收费,1收费")
|
||||
private String partType;
|
||||
private Integer partType;
|
||||
|
||||
/** 数据所属组织 */
|
||||
@Excel(name = "数据所属组织")
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public interface RepairMapper {
|
|||
/**
|
||||
* 新增维修费用
|
||||
*/
|
||||
int addRepairCost(@Param("bean") RepairApplyRecord bean, @Param("costs") BigDecimal costs,@Param("partType") String partType);
|
||||
int addRepairCost(@Param("bean") RepairApplyRecord bean, @Param("costs") BigDecimal costs, @Param("partType") String partType);
|
||||
|
||||
/**
|
||||
* 查询配件价格
|
||||
|
|
|
|||
|
|
@ -37,17 +37,11 @@ public class RepairServiceImpl implements RepairService {
|
|||
@Resource
|
||||
private TmTaskMapper taskMapper;
|
||||
|
||||
// 内部维修类型
|
||||
private final int inRepairType = 1;
|
||||
// 返厂维修类型
|
||||
private final int outRepairType = 2;
|
||||
// 报废维修类型
|
||||
private final int scrapRepairType = 3;
|
||||
// 1:内部维修 2:外部返厂维修 3:报废
|
||||
private final int inRepairType = 1, outRepairType = 2, scrapRepairType = 3;
|
||||
|
||||
// 维修管理方式--编码
|
||||
private final int manageTypeByCode = 0;
|
||||
// 维修管理方式--数量
|
||||
private final int manageTypeByNumber = 1;
|
||||
// 维修管理方式--0:编码管理 1:数量管理
|
||||
private final int manageTypeByCode = 0, manageTypeByNumber = 1;
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -113,7 +107,6 @@ public class RepairServiceImpl implements RepairService {
|
|||
List<RepairPartDetails> partList = bean.getPartList();
|
||||
BigDecimal sfCosts = new BigDecimal("0");
|
||||
|
||||
|
||||
// 收费配件
|
||||
String sfPart = "1";
|
||||
|
||||
|
|
@ -125,13 +118,13 @@ public class RepairServiceImpl implements RepairService {
|
|||
// 根据维修类型,更新维修数量、报废数量
|
||||
switch (bean.getRepairType()) {
|
||||
case inRepairType: {
|
||||
int repairNum = getNum(bean, details);
|
||||
int repairNum = verifyRepairNum(bean, details);
|
||||
// 更新维修数量、并修改维修人员
|
||||
repairMapper.updateRepairedNum(bean.getId(), repairNum, loginUser.getUserid(), loginUser.getUserid());
|
||||
break;
|
||||
}
|
||||
case outRepairType: {
|
||||
int repairNum = getNum(bean, details);
|
||||
int repairNum = verifyRepairNum(bean, details);
|
||||
// 更新维修数量、维修人员不变
|
||||
repairMapper.updateRepairedNumTwo(bean.getId(), repairNum, loginUser.getUserid());
|
||||
break;
|
||||
|
|
@ -209,13 +202,7 @@ public class RepairServiceImpl implements RepairService {
|
|||
}
|
||||
|
||||
// 配件费用计算
|
||||
for (RepairPartDetails partDetails : partList) {
|
||||
if (partDetails.getPartCost() != null) {
|
||||
BigDecimal partCost = partDetails.getPartCost();
|
||||
BigDecimal partNumber = new BigDecimal(partDetails.getPartNum());
|
||||
sfCosts = sfCosts.add(partCost.multiply(partNumber));
|
||||
}
|
||||
}
|
||||
sfCosts = countPartCosts(partList, sfCosts);
|
||||
|
||||
// 判断是否是收费配件
|
||||
if (sfPart.equals(sfCosts.toString())) {
|
||||
|
|
@ -229,7 +216,10 @@ public class RepairServiceImpl implements RepairService {
|
|||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
private static int getNum(RepairApplyRecord bean, RepairTaskDetails details) {
|
||||
/**
|
||||
* 校验维修数量
|
||||
*/
|
||||
private static int verifyRepairNum(RepairApplyRecord bean, RepairTaskDetails details) {
|
||||
int repairNum = details.getRepairedNum() + bean.getRepairNum();
|
||||
int num = repairNum + details.getScrapNum();
|
||||
if (num > details.getRepairNum()) {
|
||||
|
|
@ -303,7 +293,8 @@ public class RepairServiceImpl implements RepairService {
|
|||
break;
|
||||
}
|
||||
case scrapRepairType: {
|
||||
partList = bean.getCodeScrapRepairPartList();
|
||||
// 报废无需上传配件、直接初始化空集合
|
||||
partList = new ArrayList<>(0);
|
||||
// 更新报废数量
|
||||
repairMapper.updateScrapNum(bean.getId(), 1, loginUser.getUserid());
|
||||
break;
|
||||
|
|
@ -313,13 +304,11 @@ public class RepairServiceImpl implements RepairService {
|
|||
break;
|
||||
}
|
||||
|
||||
// 处理配件集合数据
|
||||
copeNumberManageInList(bean, partList, loginUser);
|
||||
|
||||
// 统一处理配件集合数据
|
||||
copeNumberManageInList(bean, partList, loginUser, bean.getManageType());
|
||||
|
||||
} else if (Objects.equals(manageTypeByNumber, bean.getManageType())) {
|
||||
// 物资管理方式--数量管理
|
||||
|
||||
if (bean.getId() == null) {
|
||||
throw new ServiceException("请完善参数,维修详情ID为空!");
|
||||
}
|
||||
|
|
@ -330,6 +319,7 @@ public class RepairServiceImpl implements RepairService {
|
|||
throw new ServiceException("此维修记录不存在,请检查后提交!");
|
||||
}
|
||||
|
||||
// 处理配件--数量管理--内部维修
|
||||
if (CollectionUtil.isNotEmpty(bean.getNumberInRepairPartList())) {
|
||||
partList = bean.getNumberInRepairPartList();
|
||||
|
||||
|
|
@ -342,14 +332,15 @@ public class RepairServiceImpl implements RepairService {
|
|||
throw new ServiceException("维修数量大于维修总量");
|
||||
}
|
||||
// ---------------校验维修数量-----------------
|
||||
|
||||
// 更新维修数量、并修改维修人员
|
||||
repairMapper.updateRepairedNum(bean.getId(), repairNum, loginUser.getUserid(), loginUser.getUserid());
|
||||
|
||||
copeNumberManageInList(bean, partList, loginUser);
|
||||
|
||||
// 处理配件集合数据
|
||||
copeNumberManageInList(bean, partList, loginUser, bean.getManageType());
|
||||
}
|
||||
|
||||
// 处理配件集合数据 -- 数量管理--外部返厂维修
|
||||
if (CollectionUtil.isNotEmpty(bean.getNumberOutRepairPartList())) {
|
||||
BigDecimal sfCosts = new BigDecimal("0");
|
||||
partList = bean.getNumberOutRepairPartList();
|
||||
|
||||
// ---------------校验维修数量-----------------
|
||||
|
|
@ -364,10 +355,37 @@ public class RepairServiceImpl implements RepairService {
|
|||
|
||||
// 更新维修数量、维修人员不变
|
||||
repairMapper.updateRepairedNumTwo(bean.getId(), repairNum, loginUser.getUserid());
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(bean.getNumberScrapRepairPartList())) {
|
||||
partList = bean.getNumberScrapRepairPartList();
|
||||
|
||||
// 数量管理--外部返厂维修
|
||||
RepairApplyRecord repairApplyRecord = new RepairApplyRecord();
|
||||
repairApplyRecord.setTaskId(bean.getTaskId());
|
||||
repairApplyRecord.setMaId(bean.getMaId());
|
||||
repairApplyRecord.setTypeId(bean.getTypeId());
|
||||
repairApplyRecord.setRepairType(outRepairType);
|
||||
repairApplyRecord.setPartName(partList.get(0).getPartName());
|
||||
repairApplyRecord.setPartType(partList.get(0).getPartType());
|
||||
repairApplyRecord.setRepairContent(partList.get(0).getRepairContent());
|
||||
if (partList.get(0).getSupplierId() == null) {
|
||||
throw new ServiceException("请选择返厂厂家");
|
||||
} else {
|
||||
repairApplyRecord.setSupplierId(partList.get(0).getSupplierId());
|
||||
}
|
||||
if (partList.get(0).getPartPrice() == null) {
|
||||
repairApplyRecord.setPartPrice(new BigDecimal(0));
|
||||
} else {
|
||||
repairApplyRecord.setPartPrice(partList.get(0).getPartPrice());
|
||||
}
|
||||
repairApplyRecord.setPartNum(partList.get(0).getPartNum());
|
||||
// 新增【维修记录表】
|
||||
repairMapper.addRecord(repairApplyRecord);
|
||||
|
||||
sfCosts = countPartCosts(partList, sfCosts);
|
||||
// TODO: 判断是否是收费配件,因数据存在多条,可能有些是免费配件 有些收费,所以这里用价格统一做处理,后续讨论
|
||||
// SQL: 新增【维修费用记录表】
|
||||
repairMapper.addRepairCost(repairApplyRecord, sfCosts, sfCosts.equals(new BigDecimal("0")) ? "0" : "1");
|
||||
}
|
||||
|
||||
if (CollectionUtil.isNotEmpty(bean.getNumberScrapRepairPartList())) {
|
||||
// -------------校验维修数量开始----------------
|
||||
// 统计历史已报废数量 + 本次报废数量 = 报废总数
|
||||
int scrapNum = details.getScrapNum() + bean.getScrapNum();
|
||||
|
|
@ -380,65 +398,145 @@ public class RepairServiceImpl implements RepairService {
|
|||
// -------------校验维修数量结束----------------
|
||||
|
||||
// 更新报废数量
|
||||
repairMapper.updateScrapNum(bean.getId(), 1, loginUser.getUserid());
|
||||
repairMapper.updateScrapNum(bean.getId(), scrapNum, loginUser.getUserid());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new ServiceException("请选择维修类型");
|
||||
throw new ServiceException("请选择正确的维修类型");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return AjaxResult.success("维修完成");
|
||||
}
|
||||
|
||||
private void copeNumberManageInList(RepairDeviceVO bean, List<RepairPartDetails> partList, LoginUser loginUser) {
|
||||
// 处理配件集合数据
|
||||
/**
|
||||
* 配件列表价格合计
|
||||
* @param partList 配件列表
|
||||
* @param sfCosts 配件价格合计
|
||||
* @return 配件合计后的价格
|
||||
*/
|
||||
private static BigDecimal countPartCosts(List<RepairPartDetails> partList, BigDecimal sfCosts) {
|
||||
for (RepairPartDetails partDetails : partList) {
|
||||
if (partDetails.getPartCost() != null) {
|
||||
BigDecimal partCost = partDetails.getPartCost();
|
||||
BigDecimal partNumber = new BigDecimal(partDetails.getPartNum());
|
||||
sfCosts = sfCosts.add(partCost.multiply(partNumber));
|
||||
}
|
||||
}
|
||||
return sfCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理配件集合数据
|
||||
* @param bean 维修申请单
|
||||
* @param partList 配件列表
|
||||
* @param loginUser 当前登录用户
|
||||
* @param manageType 管理方式:0编码管理 1数量管理
|
||||
*/
|
||||
private void copeNumberManageInList(RepairDeviceVO bean, List<RepairPartDetails> partList, LoginUser loginUser, Integer manageType) {
|
||||
if (CollectionUtil.isNotEmpty(partList)) {
|
||||
// 遍历配件列表,判断配件类型,收费还是不收费
|
||||
for (RepairPartDetails partDetails : partList) {
|
||||
// 维修记录表信息
|
||||
// 内部维修
|
||||
if (bean.getRepairType() == inRepairType) {
|
||||
// 遍历配件列表,判断配件类型,收费还是不收费
|
||||
for (RepairPartDetails partDetails : partList) {
|
||||
// 维修记录表信息
|
||||
RepairApplyRecord repairApplyRecord = new RepairApplyRecord();
|
||||
repairApplyRecord.setTaskId(bean.getTaskId());
|
||||
repairApplyRecord.setMaId(bean.getMaId());
|
||||
repairApplyRecord.setTypeId(bean.getTypeId());
|
||||
repairApplyRecord.setRepairType(bean.getRepairType());
|
||||
if (manageType == manageTypeByCode) {
|
||||
repairApplyRecord.setRepairNum(scrapRepairType != bean.getRepairType() ? 1 : 0);
|
||||
repairApplyRecord.setScrapNum(scrapRepairType == bean.getRepairType() ? 1 : 0);
|
||||
}
|
||||
if (manageType == manageTypeByNumber) {
|
||||
repairApplyRecord.setRepairNum(bean.getRepairNum());
|
||||
repairApplyRecord.setScrapNum(bean.getScrapNum());
|
||||
}
|
||||
repairApplyRecord.setCreateBy(loginUser.getUsername());
|
||||
repairApplyRecord.setStatus(0L);
|
||||
|
||||
if (partDetails.getPartId() != null) {
|
||||
// 有维修配件时,如果价格为空,设置为0
|
||||
if (partDetails.getPartCost() == null) {
|
||||
partDetails.setPartCost(new BigDecimal(0));
|
||||
}
|
||||
partDetails.setTaskId(bean.getTaskId());
|
||||
partDetails.setMaId(bean.getMaId());
|
||||
partDetails.setTypeId(bean.getTypeId());
|
||||
partDetails.setCreateBy(String.valueOf(loginUser.getUserid()));
|
||||
partDetails.setCompanyId(null);
|
||||
|
||||
// 根据 partId 找配件单价
|
||||
BigDecimal partPrice = repairMapper.selectPartPrice(partDetails.getPartId());
|
||||
// 设置配件费用
|
||||
partDetails.setPartCost(partPrice);
|
||||
// 添加【维修配件明细表】
|
||||
repairMapper.addPart(partDetails);
|
||||
|
||||
// 设置维修记录的配件费用
|
||||
repairApplyRecord.setPartPrice(partDetails.getPartCost());
|
||||
repairApplyRecord.setPartId(partDetails.getPartId() == null ? 0L : partDetails.getPartId());
|
||||
repairApplyRecord.setPartNum(partDetails.getPartNum());
|
||||
repairApplyRecord.setRepairContent(partDetails.getRepairContent());
|
||||
repairApplyRecord.setPartType(partDetails.getPartType());
|
||||
// 添加【维修记录表】
|
||||
repairMapper.addRecord(repairApplyRecord);
|
||||
} else {
|
||||
// 不选维修配件时, 只添加【维修记录表】
|
||||
repairMapper.addRecord(repairApplyRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 外部维修
|
||||
if (bean.getRepairType() == outRepairType) {
|
||||
BigDecimal sfCosts = new BigDecimal("0");
|
||||
partList = bean.getNumberOutRepairPartList();
|
||||
|
||||
// ---------------校验维修数量-----------------
|
||||
// 统计已维修数量 + 本次维修数量
|
||||
int repairNum = bean.getRepairedNum() + bean.getRepairNum();
|
||||
// 统计报废数量 + 维修合计数量
|
||||
int num = repairNum + bean.getScrapNum();
|
||||
if (num > bean.getRepairNum()) {
|
||||
throw new ServiceException("维修数量大于维修总量");
|
||||
}
|
||||
// ---------------校验维修数量-----------------
|
||||
|
||||
// 更新维修数量、维修人员不变
|
||||
repairMapper.updateRepairedNumTwo(bean.getId(), repairNum, loginUser.getUserid());
|
||||
|
||||
// 编码管理--外部返厂维修
|
||||
RepairApplyRecord repairApplyRecord = new RepairApplyRecord();
|
||||
repairApplyRecord.setTaskId(bean.getTaskId());
|
||||
repairApplyRecord.setMaId(bean.getMaId());
|
||||
repairApplyRecord.setTypeId(bean.getTypeId());
|
||||
repairApplyRecord.setRepairType(bean.getRepairType());
|
||||
repairApplyRecord.setRepairNum(scrapRepairType != bean.getRepairType() ? 1 : 0);
|
||||
repairApplyRecord.setScrapNum(scrapRepairType == bean.getRepairType() ? 1 : 0);
|
||||
repairApplyRecord.setCreateBy(loginUser.getUsername());
|
||||
repairApplyRecord.setStatus(0L);
|
||||
|
||||
if (partDetails.getPartId() != null) {
|
||||
// 有维修配件时,如果价格为空,设置为0
|
||||
if (partDetails.getPartCost() == null) {
|
||||
partDetails.setPartCost(new BigDecimal(0));
|
||||
}
|
||||
partDetails.setTaskId(bean.getTaskId());
|
||||
partDetails.setMaId(bean.getMaId());
|
||||
partDetails.setTypeId(bean.getTypeId());
|
||||
partDetails.setCreateBy(String.valueOf(loginUser.getUserid()));
|
||||
partDetails.setCompanyId(null);
|
||||
|
||||
// 根据 partId 找配件单价
|
||||
BigDecimal partPrice = repairMapper.selectPartPrice(partDetails.getPartId());
|
||||
// 设置配件费用
|
||||
partDetails.setPartCost(partPrice);
|
||||
// 添加【维修配件明细表】
|
||||
repairMapper.addPart(partDetails);
|
||||
|
||||
// 设置配件费用
|
||||
repairApplyRecord.setPartPrice(partDetails.getPartCost());
|
||||
repairApplyRecord.setPartId((long) partDetails.getPartId().intValue());
|
||||
repairApplyRecord.setPartNum(partDetails.getPartNum());
|
||||
repairApplyRecord.setRepairContent(partDetails.getRepairContent());
|
||||
repairApplyRecord.setPartType(partDetails.getPartType());
|
||||
// 添加【维修记录表】
|
||||
repairMapper.addRecord(repairApplyRecord);
|
||||
repairApplyRecord.setRepairType(outRepairType);
|
||||
repairApplyRecord.setPartName(partList.get(0).getPartName());
|
||||
repairApplyRecord.setPartType(partList.get(0).getPartType());
|
||||
repairApplyRecord.setRepairContent(partList.get(0).getRepairContent());
|
||||
if (partList.get(0).getSupplierId() == null) {
|
||||
throw new ServiceException("请选择返厂厂家");
|
||||
} else {
|
||||
// 不选维修配件时, 只添加【维修记录表】
|
||||
repairMapper.addRecord(repairApplyRecord);
|
||||
repairApplyRecord.setSupplierId(partList.get(0).getSupplierId());
|
||||
}
|
||||
if (partList.get(0).getPartPrice() == null) {
|
||||
repairApplyRecord.setPartPrice(new BigDecimal(0));
|
||||
} else {
|
||||
repairApplyRecord.setPartPrice(partList.get(0).getPartPrice());
|
||||
}
|
||||
repairApplyRecord.setPartNum(partList.get(0).getPartNum());
|
||||
// 新增【维修记录表】
|
||||
repairMapper.addRecord(repairApplyRecord);
|
||||
|
||||
// 配件费用计算
|
||||
sfCosts = countPartCosts(partList, sfCosts);
|
||||
|
||||
// TODO: 判断是否是收费配件,因数据存在多条,可能有些是免费配件 有些收费,所以这里用价格统一做处理,后续讨论
|
||||
// SQL: 新增【维修费用记录表】
|
||||
repairMapper.addRepairCost(repairApplyRecord, sfCosts, sfCosts.equals(new BigDecimal("0")) ? "0" : "1");
|
||||
}
|
||||
|
||||
} else {
|
||||
// 配件为空,添加【维修记录表】
|
||||
// 维修记录表信息
|
||||
|
|
@ -447,8 +545,8 @@ public class RepairServiceImpl implements RepairService {
|
|||
repairApplyRecord.setMaId(bean.getMaId());
|
||||
repairApplyRecord.setTypeId(bean.getTypeId());
|
||||
repairApplyRecord.setRepairType(bean.getRepairType());
|
||||
repairApplyRecord.setRepairNum(bean.getRepairType() != 3 ? 1 : 0);
|
||||
repairApplyRecord.setScrapNum(bean.getRepairType() == 3 ? 1 : 0);
|
||||
repairApplyRecord.setRepairNum(bean.getRepairType() != scrapRepairType ? 1 : 0);
|
||||
repairApplyRecord.setScrapNum(bean.getRepairType() == scrapRepairType ? 1 : 0);
|
||||
repairApplyRecord.setCreateBy(loginUser.getUsername());
|
||||
repairApplyRecord.setStatus(0L);
|
||||
// 不选维修配件时, 只添加【维修记录表】
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@
|
|||
</insert>
|
||||
|
||||
<insert id="addRepairCost">
|
||||
insert into repair_cost (task_id,repair_id,type_id,ma_id,repair_num,costs,part_type,status,company_id)
|
||||
values (#{bean.taskId},#{bean.id},#{bean.typeId},#{bean.maId},#{bean.repairNum},#{costs},#{partType},'0',#{bean.companyId});
|
||||
insert into repair_cost (task_id,repair_id,type_id,ma_id,repair_num,costs,part_type,status)
|
||||
values (#{bean.taskId},#{bean.id},#{bean.typeId},#{bean.maId},#{bean.repairNum},#{costs},#{partType},'0');
|
||||
</insert>
|
||||
|
||||
<update id="updateRepairedNum">
|
||||
|
|
|
|||
Loading…
Reference in New Issue