维修拆分
This commit is contained in:
parent
8243be6781
commit
13cddfef9a
|
|
@ -17,5 +17,10 @@ public class TaskTypeConstants {
|
|||
*/
|
||||
public static final String WX = "WX";
|
||||
|
||||
/**
|
||||
* 维修审核任务
|
||||
*/
|
||||
public static final String WS = "WS";
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ public enum TaskTypeEnum {
|
|||
*维修任务
|
||||
*/
|
||||
MAINTENANCE_TASK(41, "维修任务"),
|
||||
/**
|
||||
* 维修审核任务
|
||||
*/
|
||||
REPAIR_AUDIT_TASK(45, "维修审核任务"),
|
||||
/**
|
||||
* 报废任务
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ public class RepairTaskDetails {
|
|||
private String keyword;
|
||||
private String typeId;
|
||||
private String repairRemark;
|
||||
|
||||
private String remark;
|
||||
private Long companyId;
|
||||
/**
|
||||
* 任务创建人
|
||||
|
|
@ -91,4 +93,13 @@ public class RepairTaskDetails {
|
|||
@ApiModelProperty(value = "任务创建人")
|
||||
private Long createBy;
|
||||
|
||||
@ApiModelProperty(value = "退料id")
|
||||
private Long backId;
|
||||
|
||||
@ApiModelProperty(value = "维修拆分层级")
|
||||
private String level;
|
||||
|
||||
@ApiModelProperty(value = "维修拆分父级id")
|
||||
private Long parentId;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,4 +163,18 @@ public interface RepairMapper {
|
|||
int addRepairCost(@Param("bean") RepairApplyRecord bean, @Param("costs") BigDecimal costs,@Param("partType") String partType);
|
||||
|
||||
BigDecimal selectPartPrice(Long partId);
|
||||
|
||||
/**
|
||||
* 修改维修状态
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
int updateStatus(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 新增维修记录
|
||||
* @param repairTaskDetail
|
||||
* @return
|
||||
*/
|
||||
int insertRepaired(RepairTaskDetails repairTaskDetail);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.sgzb.base.service.impl;
|
||||
|
||||
import com.bonus.sgzb.app.mapper.BackReceiveMapper;
|
||||
import com.bonus.sgzb.base.api.domain.BackApplyInfo;
|
||||
import com.bonus.sgzb.base.api.domain.FileInfo;
|
||||
import com.bonus.sgzb.base.domain.RepairApplyRecord;
|
||||
import com.bonus.sgzb.base.domain.RepairPartDetails;
|
||||
|
|
@ -9,8 +10,12 @@ import com.bonus.sgzb.base.domain.RepairTaskDetails;
|
|||
import com.bonus.sgzb.base.domain.vo.DictVo;
|
||||
import com.bonus.sgzb.base.mapper.RepairMapper;
|
||||
import com.bonus.sgzb.base.service.RepairService;
|
||||
import com.bonus.sgzb.common.core.constant.TaskTypeConstants;
|
||||
import com.bonus.sgzb.common.core.enums.TaskStatusEnum;
|
||||
import com.bonus.sgzb.common.core.enums.TaskTypeEnum;
|
||||
import com.bonus.sgzb.common.core.exception.ServiceException;
|
||||
import com.bonus.sgzb.common.core.utils.DateUtils;
|
||||
import com.bonus.sgzb.common.core.utils.StringUtils;
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
||||
import com.bonus.sgzb.material.domain.TmTask;
|
||||
|
|
@ -20,10 +25,13 @@ import com.bonus.sgzb.system.api.model.LoginUser;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -264,29 +272,209 @@ public class RepairServiceImpl implements RepairService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult endRepairTask(List<RepairTask> taskList) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
// 1.查询选择任务是否还有未完成维修的数据
|
||||
for (RepairTask task : taskList) {
|
||||
int i = mapper.getUnFinish(task);
|
||||
if (i > 0) {
|
||||
throw new ServiceException("选中的数据中包含维修未完成的,请完成维修再进行提交审核");
|
||||
// 查询选择的任务中是否存在未维修的单子,进行不能提交审核提醒
|
||||
List<RepairTaskDetails> detailsList = mapper.getDetailsListByTaskId(task);
|
||||
if (!CollectionUtils.isEmpty(detailsList)) {
|
||||
int repairedNum = 0;
|
||||
int scrapNum = 0;
|
||||
String taskCode = "";
|
||||
for (RepairTaskDetails repairTaskDetails : detailsList) {
|
||||
repairedNum = repairedNum + repairTaskDetails.getRepairedNum();
|
||||
scrapNum = scrapNum + repairTaskDetails.getScrapNum();
|
||||
taskCode = repairTaskDetails.getCode();
|
||||
}
|
||||
if (repairedNum + scrapNum == 0) {
|
||||
return AjaxResult.error("维修单号" + taskCode + "还未进行维修,请先维修后再提交审核!");
|
||||
}
|
||||
}
|
||||
}
|
||||
int i = mapper.updateTaskStatus(taskList, loginUser.getUserid());
|
||||
if (i == 0) {
|
||||
return AjaxResult.error("修改外层任务状态失败");
|
||||
}
|
||||
for (RepairTask task : taskList) {
|
||||
// 维修拆分标志
|
||||
boolean isWxFlag = false;
|
||||
// 维修拆分数据集合
|
||||
List<RepairTaskDetails> repairTaskDetails = new ArrayList<>();
|
||||
task.setCreateBy(loginUser.getUserid());
|
||||
Long agreementId = mapper.getAgreementId(task);
|
||||
//生成维修审核单号
|
||||
String code = genWsCodeRule(TaskTypeEnum.REPAIR_AUDIT_TASK.getCode());
|
||||
List<RepairTaskDetails> detailsList = mapper.getDetailsListByTaskId(task);
|
||||
task.setRepairCode(code);
|
||||
mapper.addTask(task);
|
||||
for (RepairTaskDetails details : detailsList) {
|
||||
// 将待修状态改为已维修
|
||||
i = mapper.updateStatus(details.getId());
|
||||
if (i == 0) {
|
||||
throw new ServiceException("待修状态修改失败");
|
||||
}
|
||||
if (StringUtils.isNotBlank(details.getMaId())) {
|
||||
if ("0".equals(details.getStatus())) {
|
||||
isWxFlag = true;
|
||||
details.setLevel((StringUtils.isNotBlank(details.getLevel())) ? String.valueOf(Integer.parseInt(details.getLevel()) + 1) : "1");
|
||||
details.setParentId(details.getId());
|
||||
repairTaskDetails.add(details);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
int repairNum = details.getRepairNum();
|
||||
int repairedNum = details.getRepairedNum();
|
||||
int scrapNum = details.getScrapNum();
|
||||
if (repairedNum + scrapNum < repairNum) {
|
||||
isWxFlag = true;
|
||||
RepairTaskDetails taskDetails = new RepairTaskDetails();
|
||||
taskDetails.setRepairNum(repairNum - repairedNum - scrapNum);
|
||||
taskDetails.setTypeId(details.getTypeId());
|
||||
taskDetails.setLevel((StringUtils.isNotBlank(details.getLevel())) ? String.valueOf(Integer.parseInt(details.getLevel()) + 1) : "1");
|
||||
taskDetails.setParentId(details.getId());
|
||||
taskDetails.setBackId(details.getBackId());
|
||||
taskDetails.setCreateBy(details.getCreateBy());
|
||||
repairTaskDetails.add(taskDetails);
|
||||
}
|
||||
}
|
||||
details.setCreateBy(loginUser.getUserid());
|
||||
details.setTaskId(task.getTaskId());
|
||||
mapper.addAuditDetails(details);
|
||||
details.setRepairNum(details.getRepairedNum() + details.getScrapNum());
|
||||
// 如果合格数和报废数都为0,则未进行维修,不插入审核表
|
||||
if (details.getRepairedNum() == 0 &&
|
||||
details.getScrapNum() == 0) {
|
||||
continue;
|
||||
}
|
||||
i = mapper.addAuditDetails(details);
|
||||
if (i == 0) {
|
||||
throw new ServiceException("维修审核添加失败");
|
||||
}
|
||||
}
|
||||
task.setAgreementId(agreementId);
|
||||
mapper.createAgreementTask(task);
|
||||
// 进行维修拆分
|
||||
if (isWxFlag) {
|
||||
// 插入任务表
|
||||
Long newTaskId = insertTt(SecurityUtils.getUsername());
|
||||
// 插入协议任务表
|
||||
int res = insertTta(newTaskId, agreementId);
|
||||
if (res <= 0) {
|
||||
throw new ServiceException("协议任务表插入失败");
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(repairTaskDetails)) {
|
||||
for (RepairTaskDetails repairTaskDetail : repairTaskDetails) {
|
||||
repairTaskDetail.setTaskId(String.valueOf(newTaskId));
|
||||
repairTaskDetail.setStatus("0");
|
||||
i = mapper.insertRepaired(repairTaskDetail);
|
||||
if (i == 0) {
|
||||
throw new ServiceException("维修拆分插入失败");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new ServiceException("维修拆分数据组装错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入协议任务表
|
||||
* @param newTaskId
|
||||
* @param agreementId
|
||||
* @return
|
||||
*/
|
||||
private int insertTta(Long newTaskId, Long agreementId) {
|
||||
int res;
|
||||
RepairTask task = new RepairTask();
|
||||
task.setTaskId(newTaskId.toString());
|
||||
task.setAgreementId(agreementId);
|
||||
task.setCreateBy(SecurityUtils.getUserId());
|
||||
res = mapper.createAgreementTask(task);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成维修任务单号
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
private Long insertTt(String username) {
|
||||
int newTask;
|
||||
//生成单号
|
||||
String code = genWxCodeRule(TaskTypeEnum.MAINTENANCE_TASK.getCode());
|
||||
BackApplyInfo applyInfo = new BackApplyInfo();
|
||||
applyInfo.setTaskType(TaskTypeEnum.MAINTENANCE_TASK.getCode());
|
||||
applyInfo.setTaskStatus(TaskStatusEnum.REPAIRPENDING.getCode());
|
||||
applyInfo.setCode(code);
|
||||
//创建人
|
||||
applyInfo.setCreateBy(username);
|
||||
newTask = backReceiveMapper.insertTt(applyInfo);
|
||||
if (newTask > 0 && applyInfo.getTaskId() > 0) {
|
||||
newTask = applyInfo.getTaskId();
|
||||
}
|
||||
return (long) newTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成维修任务单号
|
||||
* @param taskType
|
||||
* @return
|
||||
*/
|
||||
private String genWxCodeRule(Integer taskType) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
Date nowDate = DateUtils.getNowDate();
|
||||
String format = dateFormat.format(nowDate);
|
||||
Integer taskNum = backReceiveMapper.selectTaskNumByMonthWx(nowDate, taskType);
|
||||
|
||||
String taskNumStr = "";
|
||||
if (taskNum != null) {
|
||||
// 将字符串转换为整数
|
||||
// int num = Integer.parseInt(taskNum);
|
||||
// 执行加一操作
|
||||
taskNum++;
|
||||
// 将结果转换回字符串格式,并确保结果是四位数,不足四位则在前面补0
|
||||
taskNumStr = String.format("%04d", taskNum);
|
||||
} else {
|
||||
taskNumStr = "0001";
|
||||
}
|
||||
String code = "";
|
||||
if (TaskTypeEnum.MAINTENANCE_TASK.getCode().equals(taskType)) {
|
||||
code = TaskTypeConstants.WX;
|
||||
}
|
||||
code = code + format + "-" + taskNumStr;
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成维修审核任务单号
|
||||
* @param taskType
|
||||
* @return
|
||||
*/
|
||||
private String genWsCodeRule(Integer taskType) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
Date nowDate = DateUtils.getNowDate();
|
||||
String format = dateFormat.format(nowDate);
|
||||
Integer taskNum = backReceiveMapper.selectTaskNumByMonthWx(nowDate, taskType);
|
||||
|
||||
String taskNumStr = "";
|
||||
if (taskNum != null) {
|
||||
// 将字符串转换为整数
|
||||
// int num = Integer.parseInt(taskNum);
|
||||
// 执行加一操作
|
||||
taskNum++;
|
||||
// 将结果转换回字符串格式,并确保结果是四位数,不足四位则在前面补0
|
||||
taskNumStr = String.format("%04d", taskNum);
|
||||
} else {
|
||||
taskNumStr = "0001";
|
||||
}
|
||||
String code = "";
|
||||
if (TaskTypeEnum.REPAIR_AUDIT_TASK.getCode().equals(taskType)) {
|
||||
code = TaskTypeConstants.WS;
|
||||
}
|
||||
code = code + format + "-" + taskNumStr;
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictVo> getDicSelect(String value) {
|
||||
return mapper.getDicSelect(value);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,95 @@
|
|||
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>
|
||||
<insert id="insertRepaired">
|
||||
insert into repair_apply_details
|
||||
(
|
||||
<if test="taskId != null">
|
||||
task_id,
|
||||
</if>
|
||||
<if test="maId != null">
|
||||
ma_id,
|
||||
</if>
|
||||
<if test="typeId != null">
|
||||
type_id,
|
||||
</if>
|
||||
<if test="repairNum != null">
|
||||
repair_num,
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status,
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
create_by,
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
update_by,
|
||||
</if>
|
||||
update_time,
|
||||
<if test="remark != null and remark != ''">
|
||||
remark,
|
||||
</if>
|
||||
<if test="companyId != null">
|
||||
company_id,
|
||||
</if>
|
||||
<if test="backId != null">
|
||||
back_id,
|
||||
</if>
|
||||
<if test="level != null and level != ''">
|
||||
level,
|
||||
</if>
|
||||
<if test="parentId != null">
|
||||
parent_id,
|
||||
</if>
|
||||
<if test="repairRemark != null and repairRemark != ''">
|
||||
repair_remark,
|
||||
</if>
|
||||
create_time
|
||||
)
|
||||
values (
|
||||
<if test="taskId != null">
|
||||
#{taskId},
|
||||
</if>
|
||||
<if test="maId != null">
|
||||
#{maId},
|
||||
</if>
|
||||
<if test="typeId != null">
|
||||
#{typeId},
|
||||
</if>
|
||||
<if test="repairNum != null">
|
||||
#{repairNum},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
#{status},
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
#{createBy},
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
#{createBy},
|
||||
</if>
|
||||
NOW(),
|
||||
<if test="remark != null and remark != ''">
|
||||
#{remark},
|
||||
</if>
|
||||
<if test="companyId != null">
|
||||
#{companyId},
|
||||
</if>
|
||||
<if test="backId != null">
|
||||
#{backId},
|
||||
</if>
|
||||
<if test="level != null and level != ''">
|
||||
#{level},
|
||||
</if>
|
||||
<if test="parentId != null">
|
||||
#{parentId},
|
||||
</if>
|
||||
<if test="repairRemark != null and repairRemark != ''">
|
||||
#{repairRemark},
|
||||
</if>
|
||||
NOW()
|
||||
)
|
||||
</insert>
|
||||
<update id="updateRepairedNum">
|
||||
update repair_apply_details
|
||||
set repaired_num = #{repairNum},
|
||||
|
|
@ -68,6 +157,15 @@
|
|||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateStatus">
|
||||
update
|
||||
repair_apply_details
|
||||
set
|
||||
status = '1'
|
||||
where
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="getRepairTaskList" resultType="com.bonus.sgzb.base.domain.RepairTask">
|
||||
SELECT
|
||||
rd.task_id,
|
||||
|
|
@ -264,15 +362,22 @@
|
|||
where s1.value = #{value} and s2.status = 0
|
||||
</select>
|
||||
<select id="getDetailsListByTaskId" resultType="com.bonus.sgzb.base.domain.RepairTaskDetails">
|
||||
select id,
|
||||
ma_id as maId,
|
||||
type_id as typeId,
|
||||
repair_num as repairNum,
|
||||
repaired_num as repairedNum,
|
||||
scrap_num as scrapNum,
|
||||
company_id as companyId
|
||||
from repair_apply_details
|
||||
where task_id = #{taskId}
|
||||
select rad.id as id,
|
||||
rad.ma_id as maId,
|
||||
rad.type_id as typeId,
|
||||
rad.repair_num as repairNum,
|
||||
rad.repaired_num as repairedNum,
|
||||
rad.scrap_num as scrapNum,
|
||||
tt.task_id as taskId,
|
||||
rad.back_id as backId,
|
||||
rad.status as status,
|
||||
rad.level as level,
|
||||
tt.code as code,
|
||||
rad.company_id as companyId,
|
||||
rad.create_by as createBy
|
||||
from repair_apply_details rad
|
||||
left join tm_task tt on rad.task_id = tt.task_id
|
||||
where rad.task_id = #{taskId}
|
||||
</select>
|
||||
<select id="selectPartPrice" resultType="java.math.BigDecimal">
|
||||
select ifnull(buy_price,0) from ma_part_type where pa_id = #{partId}
|
||||
|
|
|
|||
Loading…
Reference in New Issue