|
@@ -4,23 +4,25 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.sop.business.bean.result.SysDingGroupResult;
|
|
|
-import com.qmth.sop.business.entity.SysDingGroup;
|
|
|
-import com.qmth.sop.business.entity.SysDingObj;
|
|
|
-import com.qmth.sop.business.entity.SysUser;
|
|
|
-import com.qmth.sop.business.entity.TBService;
|
|
|
+import com.qmth.sop.business.bean.result.SysDingGroupRoleResult;
|
|
|
+import com.qmth.sop.business.entity.*;
|
|
|
import com.qmth.sop.business.mapper.SysDingGroupMapper;
|
|
|
-import com.qmth.sop.business.service.SysDingGroupService;
|
|
|
-import com.qmth.sop.business.service.SysDingObjService;
|
|
|
-import com.qmth.sop.business.service.TBServiceService;
|
|
|
+import com.qmth.sop.business.service.*;
|
|
|
+import com.qmth.sop.common.base.BaseEntity;
|
|
|
+import com.qmth.sop.common.enums.DingObjTypeEnum;
|
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.sop.common.enums.ServiceStatusEnum;
|
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 考勤组表 服务实现.
|
|
@@ -38,6 +40,10 @@ public class SysDingGroupServiceImpl extends ServiceImpl<SysDingGroupMapper, Sys
|
|
|
SysDingObjService sysDingObjService;
|
|
|
@Resource
|
|
|
TBServiceService tbServiceService;
|
|
|
+ @Resource
|
|
|
+ SysSupplierService sysSupplierService;
|
|
|
+ @Resource
|
|
|
+ SysRoleService sysRoleService;
|
|
|
|
|
|
/**
|
|
|
* 查询列表
|
|
@@ -63,15 +69,72 @@ public class SysDingGroupServiceImpl extends ServiceImpl<SysDingGroupMapper, Sys
|
|
|
@Transactional
|
|
|
public void add(SysDingGroupResult sysDingGroup) {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- sysDingGroup.setCreateId(sysUser.getId());
|
|
|
- sysDingGroup.setCreateTime(System.currentTimeMillis());
|
|
|
- sysDingGroup.setEnable(true);
|
|
|
- this.saveOrUpdate(sysDingGroup);
|
|
|
- sysDingGroup.getDingObjs().forEach(e -> {
|
|
|
- e.setDingGroupId(sysDingGroup.getId());
|
|
|
- sysDingObjService.save(e);
|
|
|
- });
|
|
|
|
|
|
+ // 新增校验
|
|
|
+ Long serviceUnitId = sysDingGroup.getServiceId();
|
|
|
+ List<Long> supplierIdList = sysDingGroup.getSupplierIdList();
|
|
|
+ if (!CollectionUtils.isEmpty(supplierIdList)) {
|
|
|
+ List<SysDingGroupRoleResult> sysDingGroupRoleResultList = sysDingGroup.getDingObjs();
|
|
|
+ List<Long> roleIdList = sysDingGroupRoleResultList.stream()
|
|
|
+ .filter(e -> DingObjTypeEnum.DING.equals(e.getType()))
|
|
|
+ .map(SysDingObj::getRoleId).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (Long supplierId : supplierIdList) {
|
|
|
+ List<Long> sysDingGroupIdList = this.list(new QueryWrapper<SysDingGroup>().lambda()
|
|
|
+ .eq(SysDingGroup::getServiceId, serviceUnitId)
|
|
|
+ .eq(SysDingGroup::getSupplierId, supplierId))
|
|
|
+ .stream()
|
|
|
+ .map(BaseEntity::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(sysDingGroupIdList)) {
|
|
|
+ List<Long> dbRoleIdList = sysDingObjService.list(new QueryWrapper<SysDingObj>()
|
|
|
+ .lambda()
|
|
|
+ .in(SysDingObj::getDingGroupId, sysDingGroupIdList))
|
|
|
+ .stream()
|
|
|
+ .map(SysDingObj::getRoleId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ List<Long> alreadyRoleIdList = roleIdList.stream().filter(dbRoleIdList::contains).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(alreadyRoleIdList)) {
|
|
|
+ // 已存在的角色id集合
|
|
|
+ SysSupplier sysSupplier = sysSupplierService.getById(supplierId);
|
|
|
+ if (Objects.isNull(sysSupplier)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("供应商不存在");
|
|
|
+ }
|
|
|
+ TBService tbServiceUnit = tbServiceService.getById(serviceUnitId);
|
|
|
+ if (Objects.isNull(tbServiceUnit)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("服务单元不存在");
|
|
|
+ }
|
|
|
+ String supplierName = sysSupplier.getName();
|
|
|
+ String serviceUnitName = tbServiceUnit.getName();
|
|
|
+
|
|
|
+ String roleNames = sysRoleService.list(new QueryWrapper<SysRole>()
|
|
|
+ .lambda()
|
|
|
+ .in(SysRole::getId))
|
|
|
+ .stream()
|
|
|
+ .map(SysRole::getName)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ String error = String.format("新增失败,服务单元[%s],供应商[%s],使用考勤对象为[%s] 的考勤组设置已经存在", serviceUnitName, supplierName, roleNames);
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SysDingGroup sysDingGroupEntity = new SysDingGroup();
|
|
|
+ BeanUtils.copyProperties(sysDingGroup, sysDingGroupEntity);
|
|
|
+ sysDingGroupEntity.setSupplierId(supplierId);
|
|
|
+
|
|
|
+ sysDingGroupEntity.setCreateId(sysUser.getId());
|
|
|
+ sysDingGroupEntity.setCreateTime(System.currentTimeMillis());
|
|
|
+ sysDingGroupEntity.setEnable(true);
|
|
|
+ this.saveOrUpdate(sysDingGroupEntity);
|
|
|
+ sysDingGroup.getDingObjs().forEach(e -> {
|
|
|
+ e.setDingGroupId(sysDingGroupEntity.getId());
|
|
|
+ sysDingObjService.save(e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|