|
@@ -1,10 +1,30 @@
|
|
package com.qmth.sop.business.service.impl;
|
|
package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.qmth.sop.business.bean.params.DingAddParam;
|
|
|
|
+import com.qmth.sop.business.bean.result.CanChooseSopResult;
|
|
|
|
+import com.qmth.sop.business.entity.SysUser;
|
|
|
|
+import com.qmth.sop.business.entity.TBCrmDetail;
|
|
import com.qmth.sop.business.entity.TBDingAdd;
|
|
import com.qmth.sop.business.entity.TBDingAdd;
|
|
|
|
+import com.qmth.sop.business.entity.TBUserArchivesAllocation;
|
|
import com.qmth.sop.business.mapper.TBDingAddMapper;
|
|
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.TBDingAddService;
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import com.qmth.sop.business.service.TBUserArchivesAllocationService;
|
|
|
|
+import com.qmth.sop.business.service.TBUserArchivesService;
|
|
|
|
+import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.sop.common.enums.SopRoleTypeEnum;
|
|
|
|
+import com.qmth.sop.common.util.ServletUtil;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.springframework.stereotype.Service;
|
|
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;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -17,4 +37,69 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
public class TBDingAddServiceImpl extends ServiceImpl<TBDingAddMapper, TBDingAdd> implements TBDingAddService {
|
|
public class TBDingAddServiceImpl extends ServiceImpl<TBDingAddMapper, TBDingAdd> implements TBDingAddService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private TBUserArchivesService tbUserArchivesService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private TBUserArchivesAllocationService tbUserArchivesAllocationService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private TBCrmDetailService tbCrmDetailService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public CanChooseSopResult findCanChooseSopResultList(Long serviceId) {
|
|
|
|
+ CanChooseSopResult result = new CanChooseSopResult();
|
|
|
|
+ SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+ boolean containsRegionCoordinator = tbUserArchivesService.containsRegionCoordinator(requestUser.getId());
|
|
|
|
+ if (containsRegionCoordinator) {
|
|
|
|
+ result.setNeedChoose(false);
|
|
|
|
+ } else {
|
|
|
|
+ result.setNeedChoose(true);
|
|
|
|
+ List<Long> crmDetailIdList = tbUserArchivesAllocationService.list(
|
|
|
|
+ new QueryWrapper<TBUserArchivesAllocation>().lambda().select(TBUserArchivesAllocation::getCrmDetailId)
|
|
|
|
+ .eq(TBUserArchivesAllocation::getServiceId, serviceId)
|
|
|
|
+ .eq(TBUserArchivesAllocation::getUserId, requestUser.getId()).ne(TBUserArchivesAllocation::getSopRoleType, SopRoleTypeEnum.REGION_COORDINATOR)).stream()
|
|
|
|
+ .map(TBUserArchivesAllocation::getCrmDetailId).distinct().collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(crmDetailIdList)) {
|
|
|
|
+ List<String> sopNoList = tbCrmDetailService.listByIds(crmDetailIdList).stream().map(TBCrmDetail::getSopNo).distinct().collect(Collectors.toList());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(sopNoList)) {
|
|
|
|
+ result.setSopNoList(sopNoList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public void dingAddSubmit(DingAddParam dingAddParam, Long requestUserId) {
|
|
|
|
+ Long userId = dingAddParam.getUserId();
|
|
|
|
+ Long serviceId = dingAddParam.getServiceId();
|
|
|
|
+ String sopNo = dingAddParam.getSopNo();
|
|
|
|
+ BigDecimal addDays = dingAddParam.getAddDays();
|
|
|
|
+ BigDecimal addHours = dingAddParam.getAddHours();
|
|
|
|
+ if ((Objects.isNull(addDays) && Objects.isNull(addHours)) || (Objects.nonNull(addDays) && Objects.nonNull(
|
|
|
|
+ addHours))) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("追加天数和追加小时数必填且只能选填一个");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ boolean isCoordinator = tbUserArchivesService.containsRegionCoordinator(userId);
|
|
|
|
+ if (!isCoordinator && Objects.isNull(sopNo)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("非区域协调员必须选择SOP");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TBDingAdd dingAdd = new TBDingAdd();
|
|
|
|
+ dingAdd.setServiceId(serviceId);
|
|
|
|
+ dingAdd.setUserId(userId);
|
|
|
|
+ if (Objects.nonNull(sopNo)) {
|
|
|
|
+ dingAdd.setSopNo(sopNo);
|
|
|
|
+ }
|
|
|
|
+ dingAdd.setAddDays(addDays);
|
|
|
|
+ dingAdd.setAddHours(addHours);
|
|
|
|
+ dingAdd.insertInfo(requestUserId);
|
|
|
|
+
|
|
|
|
+ this.remove(new QueryWrapper<TBDingAdd>().lambda().eq(TBDingAdd::getServiceId, serviceId).eq(TBDingAdd::getUserId, userId));
|
|
|
|
+ this.save(dingAdd);
|
|
|
|
+ }
|
|
}
|
|
}
|