|
@@ -1,6 +1,8 @@
|
|
|
package cn.iocoder.yudao.module.pms.service.iotprojectinfo;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
|
@@ -9,15 +11,19 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotprojectinfo.vo.IotProject
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojectinfo.vo.IotProjectInfoSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojectinfo.IotProjectInfoDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotprojectinfo.IotProjectInfoMapper;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
+import cn.iocoder.yudao.module.system.service.dict.DictDataService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_PROJECT_INFO_NOT_EXISTS;
|
|
@@ -37,11 +43,16 @@ public class IotProjectInfoServiceImpl implements IotProjectInfoService {
|
|
|
private DeptMapper deptMapper;
|
|
|
@Resource
|
|
|
private AdminUserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private DictDataService dictDataService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Long createIotProjectInfo(IotProjectInfoSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
IotProjectInfoDO iotProjectInfo = BeanUtils.toBean(createReqVO, IotProjectInfoDO.class);
|
|
|
+ // 校验 项目信息中的 施工区域 如果施工区域值在 数据字典 dictType 中不存在 则新增到数据字典
|
|
|
+ saveDictData(createReqVO.getDictType(), createReqVO.getLocation());
|
|
|
iotProjectInfoMapper.insert(iotProjectInfo);
|
|
|
// 返回
|
|
|
return iotProjectInfo.getId();
|
|
@@ -51,11 +62,60 @@ public class IotProjectInfoServiceImpl implements IotProjectInfoService {
|
|
|
public void updateIotProjectInfo(IotProjectInfoSaveReqVO updateReqVO) {
|
|
|
// 校验存在
|
|
|
validateIotProjectInfoExists(updateReqVO.getId());
|
|
|
+ // 校验 项目信息中的 施工区域 如果施工区域值在 数据字典 dictType 中不存在 则新增到数据字典
|
|
|
+ saveDictData(updateReqVO.getDictType(), updateReqVO.getLocation());
|
|
|
// 更新
|
|
|
IotProjectInfoDO updateObj = BeanUtils.toBean(updateReqVO, IotProjectInfoDO.class);
|
|
|
iotProjectInfoMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验 项目信息中的 施工区域 如果施工区域值在 数据字典 dictType 中不存在 则新增到数据字典
|
|
|
+ * @param dictType label
|
|
|
+ */
|
|
|
+ public void saveDictData(String dictType, String label) {
|
|
|
+ if (StrUtil.isNotBlank(dictType)) {
|
|
|
+ AtomicBoolean existFlag = new AtomicBoolean(false);
|
|
|
+ List<DictDataDO> dictDatas = dictDataService.getDictDataListByDictType(dictType);
|
|
|
+ if (CollUtil.isNotEmpty(dictDatas)) {
|
|
|
+ Set<Integer> dataValues = new HashSet<>();
|
|
|
+ // 数据字典数据的排序字段
|
|
|
+ Set<Integer> dataSorts = new HashSet<>();
|
|
|
+ dictDatas.forEach(data -> {
|
|
|
+ if (data.getValue().matches("-?\\d+")) {
|
|
|
+ dataValues.add(Integer.valueOf(data.getValue()));
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNotEmpty(data.getSort())) {
|
|
|
+ dataSorts.add(data.getSort());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(label) && label.equals(data.getLabel())) {
|
|
|
+ // 现在数据字典集合中已经包含了当前项目的 施工区域
|
|
|
+ existFlag.set(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!existFlag.get()) {
|
|
|
+ DictDataSaveReqVO reqVO = new DictDataSaveReqVO();
|
|
|
+ // 找出集合中最大的整数
|
|
|
+ if (CollUtil.isNotEmpty(dataValues)) {
|
|
|
+ Optional<Integer> maxValue = dataValues.stream()
|
|
|
+ .max(Comparator.naturalOrder());
|
|
|
+ reqVO.setValue(String.valueOf(maxValue.get()+1));
|
|
|
+ }
|
|
|
+ // 设置 数据字典值 的排序值
|
|
|
+ if (CollUtil.isNotEmpty(dataSorts)) {
|
|
|
+ Optional<Integer> maxSort = dataSorts.stream()
|
|
|
+ .max(Comparator.naturalOrder());
|
|
|
+ reqVO.setSort(maxSort.get()+1);
|
|
|
+ }
|
|
|
+ // 现在数据字典集合中未包含了当前项目的 施工区域 新增到数据字典
|
|
|
+ reqVO.setDictType(dictType);
|
|
|
+ reqVO.setLabel(label);
|
|
|
+ dictDataService.createDictData(reqVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void deleteIotProjectInfo(Long id) {
|
|
|
// 校验存在
|