This commit is contained in:
parent
717d1008b6
commit
54df56659f
|
|
@ -71,6 +71,11 @@ public class ToBeRepair {
|
||||||
*/
|
*/
|
||||||
private BigDecimal repairNum;
|
private BigDecimal repairNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退役数量
|
||||||
|
*/
|
||||||
|
private BigDecimal retirementNum;
|
||||||
|
|
||||||
private String repairUrl;
|
private String repairUrl;
|
||||||
private String scrapUrl;
|
private String scrapUrl;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
@ -48,46 +49,21 @@ public class RepairServiceImpl implements RepairService {
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public AjaxResult addRepairData(ToBeRepair bean) {
|
public AjaxResult addRepairData(ToBeRepair bean) {
|
||||||
try {
|
try {
|
||||||
if (bean.getToBeRepairList().size() <= 0) {
|
List<ToBeRepair> list = bean.getToBeRepairList();
|
||||||
|
if (list.size() <= 0) {
|
||||||
return AjaxResult.error("请添加维修数据");
|
return AjaxResult.error("请添加维修数据");
|
||||||
}
|
}
|
||||||
String username = SecurityUtils.getLoginUser().getSysUser().getNickName();
|
String username = getCurrentUsername();
|
||||||
//先创建任务--台账变更表
|
|
||||||
//1、创建维修单号
|
|
||||||
int thisMonthMaxOrder = mapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TypeEnums.TM_TASK_REPAIR.getTaskTypeId());
|
|
||||||
String code = genderTaskCode(thisMonthMaxOrder);
|
|
||||||
CsDeviceInfo deviceInfo = new CsDeviceInfo();
|
|
||||||
deviceInfo.setType("4");
|
|
||||||
deviceInfo.setCode(code);
|
|
||||||
deviceInfo.setReviewStatus("0");
|
|
||||||
deviceInfo.setCreateUser(username);
|
|
||||||
// 添加任务
|
|
||||||
int num = mapper.addDeviceChange(deviceInfo);
|
|
||||||
if (num < 1) {
|
|
||||||
throw new Exception("添加任务失败");
|
|
||||||
}
|
|
||||||
Long changeId = deviceInfo.getId();
|
|
||||||
for (ToBeRepair toBeRepair : bean.getToBeRepairList()) {
|
|
||||||
toBeRepair.setChangeId(changeId);
|
|
||||||
toBeRepair.setCreateUser(username);
|
|
||||||
if (!StringHelper.isNullOrEmptyString(toBeRepair.getIsScrap())) {
|
|
||||||
if (toBeRepair.getBmFileInfos()!=null && toBeRepair.getBmFileInfos().size() > 0) {
|
|
||||||
if ("0".equals(toBeRepair.getIsScrap())) {
|
|
||||||
toBeRepair.setRepairUrl(toBeRepair.getBmFileInfos().get(0).getFileUrl());
|
|
||||||
} else {
|
|
||||||
toBeRepair.setScrapUrl(toBeRepair.getBmFileInfos().get(0).getFileUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Exception("缺少合格状态数据");
|
|
||||||
}
|
|
||||||
int res = mapper.addRepairData(toBeRepair);
|
|
||||||
if (res <= 0) {
|
|
||||||
throw new Exception("添加设备详情失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return AjaxResult.success("申请成功");
|
|
||||||
|
|
||||||
|
// 1. 创建维修任务
|
||||||
|
Long changeId = createRepairTask(username);
|
||||||
|
|
||||||
|
// 2. 保存明细
|
||||||
|
for (ToBeRepair detail : list) {
|
||||||
|
processRepairDetail(detail, changeId, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
return AjaxResult.success("申请成功");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
|
@ -328,6 +304,101 @@ public class RepairServiceImpl implements RepairService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录用户昵称
|
||||||
|
*/
|
||||||
|
private String getCurrentUsername() {
|
||||||
|
return SecurityUtils.getLoginUser().getSysUser().getNickName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建维修任务
|
||||||
|
*/
|
||||||
|
private Long createRepairTask(String username) throws Exception {
|
||||||
|
int maxOrder = mapper.getMonthMaxOrderByDate(
|
||||||
|
DateUtils.getCurrentYear(),
|
||||||
|
DateUtils.getCurrentMonth(),
|
||||||
|
TypeEnums.TM_TASK_REPAIR.getTaskTypeId()
|
||||||
|
);
|
||||||
|
String code = genderTaskCode(maxOrder);
|
||||||
|
CsDeviceInfo deviceInfo = new CsDeviceInfo();
|
||||||
|
deviceInfo.setType("4");
|
||||||
|
deviceInfo.setCode(code);
|
||||||
|
deviceInfo.setReviewStatus("0");
|
||||||
|
deviceInfo.setCreateUser(username);
|
||||||
|
int result = mapper.addDeviceChange(deviceInfo);
|
||||||
|
if (result < 1) {
|
||||||
|
throw new Exception("添加任务失败");
|
||||||
|
}
|
||||||
|
return deviceInfo.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理维修明细
|
||||||
|
*/
|
||||||
|
private void processRepairDetail(ToBeRepair detail, Long changeId, String username) throws Exception {
|
||||||
|
detail.setChangeId(changeId);
|
||||||
|
detail.setCreateUser(username);
|
||||||
|
if (StringHelper.isNullOrEmptyString(detail.getIsScrap())) {
|
||||||
|
throw new Exception("缺少合格状态数据");
|
||||||
|
}
|
||||||
|
fillFileUrl(detail);
|
||||||
|
if ("1".equals(detail.getIsScrap()) && "数量管理".equals(detail.getManageMode())){
|
||||||
|
saveScrapAndQualified(detail);
|
||||||
|
} else {
|
||||||
|
insertDetail(detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理维修是否合格,选择了否,并且是数量管理的数据
|
||||||
|
*/
|
||||||
|
private void saveScrapAndQualified(ToBeRepair detail) throws Exception {
|
||||||
|
BigDecimal repairNum = detail.getRepairNum();
|
||||||
|
BigDecimal retirementNum = detail.getRetirementNum();
|
||||||
|
|
||||||
|
if (retirementNum == null || retirementNum.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
throw new Exception("退役数量不能为空或0");
|
||||||
|
}
|
||||||
|
// 1. 不合格记录
|
||||||
|
detail.setRepairNum(retirementNum);
|
||||||
|
insertDetail(detail);
|
||||||
|
// 2. 合格数量(如果有剩余)
|
||||||
|
if (repairNum != null && repairNum.compareTo(retirementNum) > 0) {
|
||||||
|
detail.setRepairNum(repairNum.subtract(retirementNum));
|
||||||
|
detail.setIsScrap("0");
|
||||||
|
detail.setReasonVal("");
|
||||||
|
detail.setRepairUrl("");
|
||||||
|
insertDetail(detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情数据新增
|
||||||
|
*/
|
||||||
|
private void insertDetail(ToBeRepair detail) throws Exception {
|
||||||
|
if (mapper.addRepairData(detail) <= 0) {
|
||||||
|
throw new Exception("添加设备详情失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理文件
|
||||||
|
*/
|
||||||
|
private void fillFileUrl(ToBeRepair detail) {
|
||||||
|
List<BmFileInfo> files = detail.getBmFileInfos();
|
||||||
|
if (files != null && !files.isEmpty()) {
|
||||||
|
String url = files.get(0).getFileUrl();
|
||||||
|
if ("0".equals(detail.getIsScrap())) {
|
||||||
|
detail.setRepairUrl(url);
|
||||||
|
} else {
|
||||||
|
detail.setScrapUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成任务编号
|
* 生成任务编号
|
||||||
* @param thisMonthMaxOrder
|
* @param thisMonthMaxOrder
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,12 @@
|
||||||
END manageMode,
|
END manageMode,
|
||||||
cdcd.dev_code as `code`,
|
cdcd.dev_code as `code`,
|
||||||
cdcd.num as repairNum,
|
cdcd.num as repairNum,
|
||||||
|
CASE cdcd.is_scrap
|
||||||
|
WHEN 0 THEN
|
||||||
|
0
|
||||||
|
WHEN 1 THEN
|
||||||
|
cdcd.num
|
||||||
|
END retirementNum,
|
||||||
cdcd.is_scrap as isScrap,
|
cdcd.is_scrap as isScrap,
|
||||||
CASE cdcd.review_status
|
CASE cdcd.review_status
|
||||||
WHEN 0 THEN
|
WHEN 0 THEN
|
||||||
|
|
@ -290,6 +296,12 @@
|
||||||
END manageMode,
|
END manageMode,
|
||||||
cdcd.dev_code as `code`,
|
cdcd.dev_code as `code`,
|
||||||
cdcd.num as repairNum,
|
cdcd.num as repairNum,
|
||||||
|
CASE cdcd.is_scrap
|
||||||
|
WHEN 0 THEN
|
||||||
|
0
|
||||||
|
WHEN 1 THEN
|
||||||
|
cdcd.num
|
||||||
|
END retirementNum,
|
||||||
cdcd.is_scrap as isScrap,
|
cdcd.is_scrap as isScrap,
|
||||||
CASE cdcd.review_status
|
CASE cdcd.review_status
|
||||||
WHEN 0 THEN
|
WHEN 0 THEN
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue