|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.sop.business.bean.dto.DataPermissionDto;
|
|
|
import com.qmth.sop.business.bean.params.ServiceUnitParam;
|
|
|
import com.qmth.sop.business.bean.result.ReductionResult;
|
|
@@ -16,10 +17,9 @@ import com.qmth.sop.business.service.SysDingGroupService;
|
|
|
import com.qmth.sop.business.service.SysUserRoleService;
|
|
|
import com.qmth.sop.business.service.TBServiceService;
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
|
-import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.sop.common.enums.ProductTypeEnum;
|
|
|
-import com.qmth.sop.common.enums.RoleTypeEnum;
|
|
|
-import com.qmth.sop.common.enums.ServiceStatusEnum;
|
|
|
+import com.qmth.sop.common.enums.*;
|
|
|
+import com.qmth.sop.common.util.ResultUtil;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -51,45 +51,59 @@ public class TBServiceServiceImpl extends ServiceImpl<TBServiceMapper, TBService
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public Long edit(ServiceUnitParam serviceUnitParam, SysUser requestUser) {
|
|
|
- Long id = serviceUnitParam.getId();
|
|
|
- Long leaderId = serviceUnitParam.getServiceLeadId();
|
|
|
- Long startTime = serviceUnitParam.getStartTime();
|
|
|
- Long endTime = serviceUnitParam.getEndTime();
|
|
|
-
|
|
|
- Integer regionPeopleCount = serviceUnitParam.getRegionPeopleCount();
|
|
|
- Integer regionProjectCount = serviceUnitParam.getRegionProjectCount();
|
|
|
- ReductionResult reduction = this.reduction(regionPeopleCount, regionProjectCount);
|
|
|
-
|
|
|
- if (endTime < startTime) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("服务截止时间不能小于服务开始时间");
|
|
|
- }
|
|
|
+ try {
|
|
|
+ Long id = serviceUnitParam.getId();
|
|
|
+ Long leaderId = serviceUnitParam.getServiceLeadId();
|
|
|
+ Long startTime = serviceUnitParam.getStartTime();
|
|
|
+ Long endTime = serviceUnitParam.getEndTime();
|
|
|
+
|
|
|
+ Integer regionPeopleCount = serviceUnitParam.getRegionPeopleCount();
|
|
|
+ Integer regionProjectCount = serviceUnitParam.getRegionProjectCount();
|
|
|
+ ReductionResult reduction = this.reduction(regionPeopleCount, regionProjectCount);
|
|
|
+
|
|
|
+ if (endTime < startTime) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("服务截止时间不能小于服务开始时间");
|
|
|
+ }
|
|
|
|
|
|
- if (!sysUserRoleService.userContainsRoles(leaderId, RoleTypeEnum.BUSSINESS)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("不包含'业务线负责人'角色的用户不能充当服务单元的负责人");
|
|
|
- }
|
|
|
+ if (!sysUserRoleService.userContainsRoles(leaderId, RoleTypeEnum.BUSSINESS)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不包含'业务线负责人'角色的用户不能充当服务单元的负责人");
|
|
|
+ }
|
|
|
|
|
|
- TBService tbService = new TBService();
|
|
|
- tbService.setName(serviceUnitParam.getName());
|
|
|
- tbService.setType(serviceUnitParam.getType());
|
|
|
- tbService.setStartTime(serviceUnitParam.getStartTime());
|
|
|
- tbService.setEndTime(serviceUnitParam.getEndTime());
|
|
|
- tbService.setRegionPeopleCount(reduction.getMolecular());
|
|
|
- tbService.setRegionProjectCount(reduction.getDenominator());
|
|
|
- tbService.setServiceLeadId(serviceUnitParam.getServiceLeadId());
|
|
|
- if (Objects.isNull(id)) {
|
|
|
-
|
|
|
- tbService.setEnable(true);
|
|
|
- tbService.setStatus(ServiceStatusEnum.NEW);
|
|
|
- tbService.setCreateId(requestUser.getId());
|
|
|
- this.save(tbService);
|
|
|
- id = tbService.getId();
|
|
|
- } else {
|
|
|
-
|
|
|
- tbService.setId(id);
|
|
|
- tbService.setUpdateId(requestUser.getUpdateId());
|
|
|
- this.updateById(tbService);
|
|
|
+ TBService tbService = new TBService();
|
|
|
+ tbService.setName(serviceUnitParam.getName());
|
|
|
+ tbService.setType(serviceUnitParam.getType());
|
|
|
+ tbService.setStartTime(serviceUnitParam.getStartTime());
|
|
|
+ tbService.setEndTime(serviceUnitParam.getEndTime());
|
|
|
+ tbService.setRegionPeopleCount(reduction.getMolecular());
|
|
|
+ tbService.setRegionProjectCount(reduction.getDenominator());
|
|
|
+ tbService.setServiceLeadId(serviceUnitParam.getServiceLeadId());
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+
|
|
|
+ tbService.setEnable(true);
|
|
|
+ tbService.setStatus(ServiceStatusEnum.NEW);
|
|
|
+ tbService.setCreateId(requestUser.getId());
|
|
|
+ this.save(tbService);
|
|
|
+ id = tbService.getId();
|
|
|
+ } else {
|
|
|
+
|
|
|
+ tbService.setId(id);
|
|
|
+ tbService.setUpdateId(requestUser.getUpdateId());
|
|
|
+ this.updateById(tbService);
|
|
|
+ }
|
|
|
+ return id;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3).replaceAll("'", "");
|
|
|
+ throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
+ } else if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
- return id;
|
|
|
}
|
|
|
|
|
|
@Override
|