|
@@ -6,16 +6,16 @@ import com.qmth.sop.business.bean.params.DingAddParam;
|
|
|
import com.qmth.sop.business.bean.result.CanChooseSopResult;
|
|
|
import com.qmth.sop.business.entity.TBDingAdd;
|
|
|
import com.qmth.sop.business.mapper.TBDingAddMapper;
|
|
|
-import com.qmth.sop.business.service.TBCrmDetailService;
|
|
|
import com.qmth.sop.business.service.TBDingAddService;
|
|
|
-import com.qmth.sop.business.service.TBUserArchivesAllocationService;
|
|
|
import com.qmth.sop.business.service.TBUserArchivesService;
|
|
|
+import com.qmth.sop.common.contant.SystemConstant;
|
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
@@ -32,12 +32,6 @@ public class TBDingAddServiceImpl extends ServiceImpl<TBDingAddMapper, TBDingAdd
|
|
|
@Resource
|
|
|
private TBUserArchivesService tbUserArchivesService;
|
|
|
|
|
|
- @Resource
|
|
|
- private TBUserArchivesAllocationService tbUserArchivesAllocationService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private TBCrmDetailService tbCrmDetailService;
|
|
|
-
|
|
|
@Override
|
|
|
public CanChooseSopResult findCanChooseSopResultList(Long serviceId, Long userId) {
|
|
|
CanChooseSopResult result = new CanChooseSopResult();
|
|
@@ -61,21 +55,49 @@ public class TBDingAddServiceImpl extends ServiceImpl<TBDingAddMapper, TBDingAdd
|
|
|
BigDecimal addHours = dingAddParam.getAddHours();
|
|
|
|
|
|
boolean isCoordinator = tbUserArchivesService.containsRegionCoordinator(userId);
|
|
|
- if (!isCoordinator && Objects.isNull(sopNo)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("非区域协调员必须选择SOP");
|
|
|
+ List<TBDingAdd> dbDingAddList = this.list(
|
|
|
+ new QueryWrapper<TBDingAdd>().lambda().eq(TBDingAdd::getServiceId, serviceId).eq(TBDingAdd::getUserId, userId));
|
|
|
+
|
|
|
+ QueryWrapper<TBDingAdd> removeQuery = new QueryWrapper<>();
|
|
|
+ removeQuery.lambda().eq(TBDingAdd::getServiceId, serviceId).eq(TBDingAdd::getUserId, userId);
|
|
|
+
|
|
|
+ if (isCoordinator) {
|
|
|
+ // 区协追加
|
|
|
+ // 如果有曾经作为工程师的追加记录,则不允许提交
|
|
|
+ if (dbDingAddList.stream().anyMatch(e -> Objects.nonNull(e.getSopNo()))) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该用户曾有过工程师的追加记录,无法作为区协追加");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 工程师追加
|
|
|
+ // 工程师追加必须选择SOP
|
|
|
+ if (Objects.isNull(sopNo)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("工程师必须选择SOP");
|
|
|
+ }
|
|
|
+ // 如果有曾经作为区协的追加记录,则不允许提交
|
|
|
+ if (dbDingAddList.stream().anyMatch(e -> Objects.isNull(e.getSopNo()))) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该用户曾有过区协的追加记录,无法作为工程师追加");
|
|
|
+ }
|
|
|
+ removeQuery.lambda().eq(TBDingAdd::getSopNo, sopNo);
|
|
|
}
|
|
|
|
|
|
+ // 清除掉之前的追加记录
|
|
|
+ this.remove(removeQuery);
|
|
|
+ // 追加
|
|
|
TBDingAdd dingAdd = new TBDingAdd();
|
|
|
dingAdd.setServiceId(serviceId);
|
|
|
dingAdd.setUserId(userId);
|
|
|
- if (Objects.nonNull(sopNo)) {
|
|
|
+ if (Objects.nonNull(sopNo) && !isCoordinator) {
|
|
|
dingAdd.setSopNo(sopNo);
|
|
|
}
|
|
|
- dingAdd.setAddDays(addDays);
|
|
|
- dingAdd.setAddHours(addHours);
|
|
|
+ if (SystemConstant.effectBigDecimal(addDays)) {
|
|
|
+ dingAdd.setAddDays(addDays);
|
|
|
+ } else {
|
|
|
+ dingAdd.setAddHours(addHours);
|
|
|
+ }
|
|
|
dingAdd.insertInfo(requestUserId);
|
|
|
-
|
|
|
- this.remove(new QueryWrapper<TBDingAdd>().lambda().eq(TBDingAdd::getServiceId, serviceId).eq(TBDingAdd::getUserId, userId));
|
|
|
- this.save(dingAdd);
|
|
|
+ if (SystemConstant.effectBigDecimal(addDays) || SystemConstant.effectBigDecimal(addHours)) {
|
|
|
+ // 追加日或工时有效才追加 否则视为删除追加操作
|
|
|
+ this.save(dingAdd);
|
|
|
+ }
|
|
|
}
|
|
|
}
|