新购验收--定义枚举、增加事务、去除TODO
This commit is contained in:
parent
f1a955262a
commit
d23f2765ae
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.bonus.material.purchase.config;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 阮世耀
|
||||||
|
* @version : 1.0
|
||||||
|
* @PackagePath: com.bonus.material.purchase.config
|
||||||
|
* @CreateTime: 2024-10-22 13:08
|
||||||
|
* @Description: 新购任务信息枚举
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum PurchaseTaskEnum {
|
||||||
|
|
||||||
|
PURCHASE_TASK_STATUS_NOTICE(55, 0, "待通知", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_WAIT_CHECK(56, 1,"待验收", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_CHECKED_OK(57, 2,"验收合格", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_CHECK_NO(58, 3,"验收未通过", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_ALL_IN(59, 4,"已全部入库", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_IN_CHECK(60, 5,"入库审核中", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_SERVICE_CENTRE_NO(61, 6,"综合服务中心未通过", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_IN_NO(62, 7,"入库审核未通过", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_SERVICE_CENTRE_CHECK(63, 8,"综合服务中心审核中", "purchase_task_status", 16),
|
||||||
|
PURCHASE_TASK_STATUS_PART_IN(64, 9,"部分已入库", "purchase_task_status", 16);
|
||||||
|
|
||||||
|
|
||||||
|
private final Integer taskStatusCode;
|
||||||
|
private final Integer taskStatusValue;
|
||||||
|
private final String taskStatusName;
|
||||||
|
private final String taskTypeValue;
|
||||||
|
private final Integer taskTypeId;
|
||||||
|
|
||||||
|
PurchaseTaskEnum(Integer taskStatusCode, Integer taskStatusValue, String taskStatusName, String taskTypeValue, Integer taskTypeId) {
|
||||||
|
this.taskStatusCode = taskStatusCode;
|
||||||
|
this.taskStatusValue = taskStatusValue;
|
||||||
|
this.taskStatusName = taskStatusName;
|
||||||
|
this.taskTypeValue = taskTypeValue;
|
||||||
|
this.taskTypeId = taskTypeId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -132,10 +132,10 @@ public class PurchaseCheckDetailsController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "上传文件")
|
@ApiOperation(value = "上传报告附件")
|
||||||
@PreventRepeatSubmit
|
@PreventRepeatSubmit
|
||||||
@RequiresPermissions("purchase:details:add")
|
@RequiresPermissions("purchase:details:add")
|
||||||
@SysLog(title = "上传文件", businessType = OperaType.INSERT, logType = 1,module = "物资新购->上传物资报告附件")
|
@SysLog(title = "上传报告附件", businessType = OperaType.INSERT, logType = 1,module = "物资新购->上传物资报告附件")
|
||||||
@PostMapping("/uploadFile")
|
@PostMapping("/uploadFile")
|
||||||
public AjaxResult uploadFile(@RequestBody @NotNull @Valid PurchaseCheckFileDto purchaseCheckFileDto) {
|
public AjaxResult uploadFile(@RequestBody @NotNull @Valid PurchaseCheckFileDto purchaseCheckFileDto) {
|
||||||
return purchaseCheckDetailsService.insertPurchaseCheckFile(purchaseCheckFileDto);
|
return purchaseCheckDetailsService.insertPurchaseCheckFile(purchaseCheckFileDto);
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,7 @@ import com.bonus.common.core.web.page.TableDataInfo;
|
||||||
/**
|
/**
|
||||||
* 新购验收任务Controller
|
* 新购验收任务Controller
|
||||||
*
|
*
|
||||||
* @author xsheng
|
* @author syruan
|
||||||
* @date 2024-10-16
|
|
||||||
*/
|
*/
|
||||||
@Api(tags = "新购验收任务接口")
|
@Api(tags = "新购验收任务接口")
|
||||||
@RestController
|
@RestController
|
||||||
|
|
@ -72,7 +71,7 @@ public class PurchaseCheckInfoController extends BaseController {
|
||||||
@ApiOperation(value = "新增新购验收任务")
|
@ApiOperation(value = "新增新购验收任务")
|
||||||
@PreventRepeatSubmit
|
@PreventRepeatSubmit
|
||||||
@RequiresPermissions("purchase:info:add")
|
@RequiresPermissions("purchase:info:add")
|
||||||
@SysLog(title = "新购验收任务", businessType = OperaType.INSERT, module = "仓储管理->新增新购验收任务")
|
@SysLog(title = "新购验收任务", businessType = OperaType.INSERT, module = "物资新购->新增新购验收任务")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Valid @NotNull @RequestBody PurchaseCheckDto purchaseCheckDto) {
|
public AjaxResult add(@Valid @NotNull @RequestBody PurchaseCheckDto purchaseCheckDto) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -88,7 +87,7 @@ public class PurchaseCheckInfoController extends BaseController {
|
||||||
@ApiOperation(value = "修改新购验收任务")
|
@ApiOperation(value = "修改新购验收任务")
|
||||||
@PreventRepeatSubmit
|
@PreventRepeatSubmit
|
||||||
@RequiresPermissions("purchase:info:edit")
|
@RequiresPermissions("purchase:info:edit")
|
||||||
@SysLog(title = "新购验收任务", businessType = OperaType.UPDATE, module = "仓储管理->修改新购验收任务")
|
@SysLog(title = "新购验收任务", businessType = OperaType.UPDATE, module = "物资新购->修改新购验收任务")
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody PurchaseCheckInfo purchaseCheckInfo) {
|
public AjaxResult edit(@RequestBody PurchaseCheckInfo purchaseCheckInfo) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -104,7 +103,7 @@ public class PurchaseCheckInfoController extends BaseController {
|
||||||
@ApiOperation(value = "删除新购验收任务")
|
@ApiOperation(value = "删除新购验收任务")
|
||||||
@PreventRepeatSubmit
|
@PreventRepeatSubmit
|
||||||
@RequiresPermissions("purchase:info:remove")
|
@RequiresPermissions("purchase:info:remove")
|
||||||
@SysLog(title = "新购验收任务", businessType = OperaType.DELETE, module = "仓储管理->删除新购验收任务")
|
@SysLog(title = "新购验收任务", businessType = OperaType.DELETE, module = "物资新购->删除新购验收任务")
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||||
return toAjax(purchaseCheckInfoService.deletePurchaseCheckInfoByIds(ids));
|
return toAjax(purchaseCheckInfoService.deletePurchaseCheckInfoByIds(ids));
|
||||||
|
|
@ -118,7 +117,7 @@ public class PurchaseCheckInfoController extends BaseController {
|
||||||
@ApiOperation(value = "导出新购验收任务列表")
|
@ApiOperation(value = "导出新购验收任务列表")
|
||||||
@PreventRepeatSubmit
|
@PreventRepeatSubmit
|
||||||
@RequiresPermissions("purchase:info:export")
|
@RequiresPermissions("purchase:info:export")
|
||||||
@SysLog(title = "新购验收任务", businessType = OperaType.EXPORT, module = "仓储管理->导出新购验收任务")
|
@SysLog(title = "新购验收任务", businessType = OperaType.EXPORT, module = "物资新购->导出新购验收任务")
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response, PurchaseCheckInfo purchaseCheckInfo) {
|
public void export(HttpServletResponse response, PurchaseCheckInfo purchaseCheckInfo) {
|
||||||
List<PurchaseCheckInfo> list = purchaseCheckInfoService.selectPurchaseCheckInfoList(purchaseCheckInfo);
|
List<PurchaseCheckInfo> list = purchaseCheckInfoService.selectPurchaseCheckInfoList(purchaseCheckInfo);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package com.bonus.material.purchase.service.impl;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -10,24 +9,27 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
|
||||||
import com.bonus.common.core.exception.ServiceException;
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
import com.bonus.common.core.utils.DateUtils;
|
import com.bonus.common.core.utils.DateUtils;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.material.purchase.config.PurchaseTaskEnum;
|
||||||
import com.bonus.material.purchase.domain.PurchaseCheckDetails;
|
import com.bonus.material.purchase.domain.PurchaseCheckDetails;
|
||||||
import com.bonus.material.purchase.dto.PurchaseCheckDto;
|
import com.bonus.material.purchase.dto.PurchaseCheckDto;
|
||||||
import com.bonus.material.purchase.mapper.PurchaseCheckDetailsMapper;
|
import com.bonus.material.purchase.mapper.PurchaseCheckDetailsMapper;
|
||||||
import com.bonus.material.task.domain.TmTask;
|
import com.bonus.material.task.domain.TmTask;
|
||||||
import com.bonus.material.task.mapper.TmTaskMapper;
|
import com.bonus.material.task.mapper.TmTaskMapper;
|
||||||
import org.apache.ibatis.reflection.ArrayUtil;
|
import com.mysql.cj.exceptions.DataTruncationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.bonus.material.purchase.mapper.PurchaseCheckInfoMapper;
|
import com.bonus.material.purchase.mapper.PurchaseCheckInfoMapper;
|
||||||
import com.bonus.material.purchase.domain.PurchaseCheckInfo;
|
import com.bonus.material.purchase.domain.PurchaseCheckInfo;
|
||||||
import com.bonus.material.purchase.service.IPurchaseCheckInfoService;
|
import com.bonus.material.purchase.service.IPurchaseCheckInfoService;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionStatus;
|
||||||
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新购验收任务Service业务层处理
|
* 新购验收任务Service业务层处理
|
||||||
|
|
@ -37,6 +39,11 @@ import javax.validation.constraints.NotNull;
|
||||||
@Service
|
@Service
|
||||||
public class PurchaseCheckInfoServiceImpl implements IPurchaseCheckInfoService {
|
public class PurchaseCheckInfoServiceImpl implements IPurchaseCheckInfoService {
|
||||||
|
|
||||||
|
public static final String TASK_TYPE_LABEL = "XG";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlatformTransactionManager transactionManager;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PurchaseCheckInfoMapper purchaseCheckInfoMapper;
|
private PurchaseCheckInfoMapper purchaseCheckInfoMapper;
|
||||||
|
|
||||||
|
|
@ -153,48 +160,68 @@ public class PurchaseCheckInfoServiceImpl implements IPurchaseCheckInfoService {
|
||||||
// 赋值创建时间
|
// 赋值创建时间
|
||||||
purchaseCheckInfo.getPurchaseCheckInfo().setCreateTime(DateUtils.getNowDate());
|
purchaseCheckInfo.getPurchaseCheckInfo().setCreateTime(DateUtils.getNowDate());
|
||||||
try {
|
try {
|
||||||
// TODO: 任务类型、XG 待完善,先定义死,后期修改至配置中心
|
// 开启事务
|
||||||
|
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
|
||||||
|
|
||||||
// 查询新购任务当月最大单号
|
// 查询新购任务当月最大单号
|
||||||
Integer thisMonthMaxOrder = tmTaskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), 16L);
|
Integer thisMonthMaxOrder = tmTaskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), Long.valueOf(PurchaseTaskEnum.PURCHASE_TASK_STATUS_NOTICE.getTaskTypeId()));
|
||||||
// 查询出的单号值,进行必要性校正
|
// 查询出的单号值,进行必要性校正
|
||||||
if (thisMonthMaxOrder == null || thisMonthMaxOrder == 0) {
|
thisMonthMaxOrder = Optional.ofNullable(thisMonthMaxOrder).orElse(0);
|
||||||
thisMonthMaxOrder = 1;
|
|
||||||
} else {
|
|
||||||
thisMonthMaxOrder = thisMonthMaxOrder + 1;
|
|
||||||
}
|
|
||||||
// 生成单号
|
// 生成单号
|
||||||
String taskCode = "XG" + DateUtils.getCurrentYear() + DateUtils.getCurrentMonth() + String.format("%06d", thisMonthMaxOrder);
|
TmTask tmTask = genderTaskCode(purchaseCheckInfo, thisMonthMaxOrder);
|
||||||
|
Long taskId;
|
||||||
// 先往tm_task任务表中创建任务
|
|
||||||
TmTask tmTask = new TmTask(null, 16L, 55L, taskCode, purchaseCheckInfo.getPurchaseCheckInfo().getCompanyId(), "1", thisMonthMaxOrder + 1);
|
|
||||||
Long taskId = 0L;
|
|
||||||
if (tmTaskMapper.insertTmTask(tmTask) > 0) {
|
if (tmTaskMapper.insertTmTask(tmTask) > 0) {
|
||||||
taskId = tmTask.getTaskId();
|
taskId = tmTask.getTaskId();
|
||||||
} else {
|
} else {
|
||||||
|
transactionManager.rollback(transactionStatus);
|
||||||
return AjaxResult.error("新增任务失败_task表插入0条");
|
return AjaxResult.error("新增任务失败_task表插入0条");
|
||||||
}
|
}
|
||||||
|
|
||||||
// tm_task 插入成功后,再往新购验收info表中插入数据
|
// tm_task 插入成功后,再往新购验收info表中插入数据
|
||||||
purchaseCheckInfo.getPurchaseCheckInfo().setTaskId(taskId);
|
purchaseCheckInfo.getPurchaseCheckInfo().setTaskId(taskId);
|
||||||
if (purchaseCheckInfoMapper.insertPurchaseCheckInfo(purchaseCheckInfo.getPurchaseCheckInfo()) > 0) {
|
if (purchaseCheckInfoMapper.insertPurchaseCheckInfo(purchaseCheckInfo.getPurchaseCheckInfo()) > 0) {
|
||||||
Long finalTaskId = taskId;
|
|
||||||
purchaseCheckInfo.getPurchaseCheckDetailsList().forEach(
|
purchaseCheckInfo.getPurchaseCheckDetailsList().forEach(
|
||||||
details -> {
|
details -> {
|
||||||
details.setTaskId(finalTaskId);
|
details.setTaskId(taskId);
|
||||||
details.setInputStatus("0");
|
details.setInputStatus("0");
|
||||||
});
|
});
|
||||||
// 批量插入详情数据
|
// 批量插入详情数据
|
||||||
boolean purchaseCheckDetailsListAddResult = purchaseCheckDetailsMapper.insertPurchaseCheckDetailsList(purchaseCheckInfo.getPurchaseCheckDetailsList()) > 0;
|
boolean purchaseCheckDetailsListAddResult = purchaseCheckDetailsMapper.insertPurchaseCheckDetailsList(purchaseCheckInfo.getPurchaseCheckDetailsList()) > 0;
|
||||||
return purchaseCheckDetailsListAddResult ? AjaxResult.success("新增任务成功") : AjaxResult.error("新增任务失败,详情表插入0条");
|
if (purchaseCheckDetailsListAddResult) {
|
||||||
|
transactionManager.commit(transactionStatus);
|
||||||
|
return AjaxResult.success("新增任务成功");
|
||||||
|
} else {
|
||||||
|
transactionManager.rollback(transactionStatus);
|
||||||
|
return AjaxResult.error("新增任务失败,详情表插入0条");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
transactionManager.rollback(transactionStatus);
|
||||||
return AjaxResult.error("新增任务失败,info表插入0条");
|
return AjaxResult.error("新增任务失败,info表插入0条");
|
||||||
}
|
}
|
||||||
|
} catch (DataAccessException e) {
|
||||||
|
return AjaxResult.error("数据库操作失败:" + e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return AjaxResult.error("新增任务失败:" + e.getMessage());
|
return AjaxResult.error("新增任务失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成任务编号并构造Tm_Task任务对象
|
||||||
|
* @param purchaseCheckInfo 新购验收任务数据
|
||||||
|
* @param thisMonthMaxOrder 当月最大单号
|
||||||
|
* @return 任务对象
|
||||||
|
*/
|
||||||
|
private static TmTask genderTaskCode(PurchaseCheckDto purchaseCheckInfo, Integer thisMonthMaxOrder) {
|
||||||
|
String taskCode = TASK_TYPE_LABEL + DateUtils.getCurrentYear() + DateUtils.getCurrentMonth() + String.format("%06d", thisMonthMaxOrder + 1);
|
||||||
|
|
||||||
|
// 构造函数创建任务对象
|
||||||
|
return new TmTask(null,
|
||||||
|
PurchaseTaskEnum.PURCHASE_TASK_STATUS_NOTICE.getTaskTypeId(),
|
||||||
|
PurchaseTaskEnum.PURCHASE_TASK_STATUS_NOTICE.getTaskStatusCode(),
|
||||||
|
taskCode, purchaseCheckInfo.getPurchaseCheckInfo().getCompanyId(), "1", thisMonthMaxOrder + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改新购验收任务
|
* 修改新购验收任务
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,12 @@ public class TmTask extends BaseEntity {
|
||||||
/** 任务类型(定义数据字典) */
|
/** 任务类型(定义数据字典) */
|
||||||
@Excel(name = "任务类型(定义数据字典)")
|
@Excel(name = "任务类型(定义数据字典)")
|
||||||
@ApiModelProperty(value = "任务类型(定义数据字典)")
|
@ApiModelProperty(value = "任务类型(定义数据字典)")
|
||||||
private Long taskType;
|
private Integer taskType;
|
||||||
|
|
||||||
/** 任务状态(定义数据字典) */
|
/** 任务状态(定义数据字典) */
|
||||||
@Excel(name = "任务状态(定义数据字典)")
|
@Excel(name = "任务状态(定义数据字典)")
|
||||||
@ApiModelProperty(value = "任务状态(定义数据字典)")
|
@ApiModelProperty(value = "任务状态(定义数据字典)")
|
||||||
private Long taskStatus;
|
private Integer taskStatus;
|
||||||
|
|
||||||
/** 编号 */
|
/** 编号 */
|
||||||
@Excel(name = "编号")
|
@Excel(name = "编号")
|
||||||
|
|
@ -49,10 +49,10 @@ public class TmTask extends BaseEntity {
|
||||||
@ApiModelProperty(value = "任务当月序号 例如:1 插入及查询时请携带任务类型")
|
@ApiModelProperty(value = "任务当月序号 例如:1 插入及查询时请携带任务类型")
|
||||||
private Integer monthOrder;
|
private Integer monthOrder;
|
||||||
|
|
||||||
public TmTask(Long taskId, Long taskType, Long taskStatus, String code, Long companyId, String status, Integer monthOrder) {
|
public TmTask(Long taskId, Integer taskType, Integer taskStatus, String code, Long companyId, String status, Integer monthOrder) {
|
||||||
this.taskId = taskId;
|
this.taskId = taskId;
|
||||||
this.taskType = taskType;
|
this.taskType = Math.toIntExact(taskType);
|
||||||
this.taskStatus = taskStatus;
|
this.taskStatus = Math.toIntExact(taskStatus);
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.companyId = companyId;
|
this.companyId = companyId;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue