|
@@ -1,12 +1,13 @@
|
|
|
package cn.cslg.pas.service.business;
|
|
|
|
|
|
-import cn.cslg.pas.common.dto.business.CustomOptionDTO;
|
|
|
-import cn.cslg.pas.common.dto.business.UpdateCustomOptionDTO;
|
|
|
+import cn.cslg.pas.common.dto.business.*;
|
|
|
import cn.cslg.pas.common.model.cronModel.Personnel;
|
|
|
import cn.cslg.pas.common.model.cronModel.PersonnelVO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.Records;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
import cn.cslg.pas.common.vo.business.CustomOptionVO;
|
|
|
+import cn.cslg.pas.domain.business.CustomField;
|
|
|
import cn.cslg.pas.domain.business.CustomOption;
|
|
|
import cn.cslg.pas.exception.UnLoginException;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
@@ -18,12 +19,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
+ * 自定义选项的Service层
|
|
|
* @Author xiexiang
|
|
|
* @Date 2023/11/8
|
|
|
*/
|
|
@@ -38,6 +41,17 @@ public class CustomOptionService extends ServiceImpl<CustomOptionMapper, CustomO
|
|
|
@Autowired
|
|
|
private PermissionService permissionService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CustomFieldService customFieldService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TreeNodeService treeNodeService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增自定义选项
|
|
|
+ * @param customOptionDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Integer addCustomOption(CustomOptionDTO customOptionDTO) {
|
|
|
if (customOptionDTO.getName().equals(null)) {
|
|
|
throw new XiaoShiException("选项值不能为空!");
|
|
@@ -46,30 +60,52 @@ public class CustomOptionService extends ServiceImpl<CustomOptionMapper, CustomO
|
|
|
throw new XiaoShiException("所属自定义栏位不能为空!");
|
|
|
}
|
|
|
String name = customOptionDTO.getName();
|
|
|
- //检查名称是否规范
|
|
|
- customOptionDTO.setName(name.trim());
|
|
|
- //同一个自定义栏位下值选项不能重复
|
|
|
- LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(CustomOption::getName, name);
|
|
|
- queryWrapper.eq(CustomOption::getCustomFieldId, customOptionDTO.getCustomFieldId());
|
|
|
- List<CustomOption> customOptions = this.list(queryWrapper);
|
|
|
- if (customOptions != null && customOptions.size() != 0) {
|
|
|
- throw new XiaoShiException("名称不能重复");
|
|
|
- }
|
|
|
- //获取登录人信息
|
|
|
- PersonnelVO personnelVO = new PersonnelVO();
|
|
|
- try {
|
|
|
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
- } catch (Exception e) {
|
|
|
- throw new UnLoginException("未登录");
|
|
|
+ //所属自定义栏位的id
|
|
|
+ Integer customFieldId = customOptionDTO.getCustomFieldId();
|
|
|
+ //查询自定义栏位的类型,如果为树,则调用架构部分
|
|
|
+ CustomField customField = customFieldService.getById(customFieldId);
|
|
|
+ Integer customFieldType = customField.getType();
|
|
|
+ if (customFieldType.equals(6)) {
|
|
|
+ TreeNodeDTO treeNodeDTO = new TreeNodeDTO();
|
|
|
+ treeNodeDTO.setName(name);
|
|
|
+ //自定义树 设置为4
|
|
|
+ treeNodeDTO.setType(4);
|
|
|
+ treeNodeDTO.setParentId(customOptionDTO.getParentId());
|
|
|
+ treeNodeDTO.setTypeId(customOptionDTO.getCustomFieldId());
|
|
|
+ List<MultipartFile> files = new ArrayList<>();
|
|
|
+ Integer id = (Integer) treeNodeService.addMessage(treeNodeDTO, files);
|
|
|
+ return id;
|
|
|
+ } else {
|
|
|
+ //检查名称是否规范
|
|
|
+ customOptionDTO.setName(name.trim());
|
|
|
+ //同一个自定义栏位下值选项不能重复
|
|
|
+ LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(CustomOption::getName, name);
|
|
|
+ queryWrapper.eq(CustomOption::getCustomFieldId, customOptionDTO.getCustomFieldId());
|
|
|
+ List<CustomOption> customOptions = this.list(queryWrapper);
|
|
|
+ if (customOptions != null && customOptions.size() != 0) {
|
|
|
+ throw new XiaoShiException("名称不能重复");
|
|
|
+ }
|
|
|
+ //获取登录人信息
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
+ try {
|
|
|
+ personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new UnLoginException("未登录");
|
|
|
+ }
|
|
|
+ CustomOption customOption = new CustomOption();
|
|
|
+ BeanUtils.copyProperties(customOptionDTO, customOption);
|
|
|
+ customOption.setCreateId(personnelVO.getId());
|
|
|
+ customOption.insert();
|
|
|
+ return customOption.getId();
|
|
|
}
|
|
|
- CustomOption customOption = new CustomOption();
|
|
|
- BeanUtils.copyProperties(customOptionDTO, customOption);
|
|
|
- customOption.setCreateId(personnelVO.getId());
|
|
|
- customOption.insert();
|
|
|
- return customOption.getId();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新自定义选项
|
|
|
+ * @param updateCustomOptionDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Integer updateCustomOption(UpdateCustomOptionDTO updateCustomOptionDTO) {
|
|
|
if (updateCustomOptionDTO.getName().equals(null)) {
|
|
|
throw new XiaoShiException("选项值不能为空!");
|
|
@@ -77,67 +113,116 @@ public class CustomOptionService extends ServiceImpl<CustomOptionMapper, CustomO
|
|
|
if (updateCustomOptionDTO.getCustomFieldId().equals(null)) {
|
|
|
throw new XiaoShiException("所属自定义栏位不能为空!");
|
|
|
}
|
|
|
+ Integer id = null;
|
|
|
String name = updateCustomOptionDTO.getName();
|
|
|
- CustomOption customOption = this.getById(updateCustomOptionDTO.getId());
|
|
|
- //检查名称是否规范
|
|
|
- updateCustomOptionDTO.setName(name.trim());
|
|
|
- //同一个自定义栏位下值选项不能重复
|
|
|
- LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(CustomOption::getName, name);
|
|
|
- queryWrapper.eq(CustomOption::getCustomFieldId, updateCustomOptionDTO.getCustomFieldId());
|
|
|
- List<CustomOption> customOptions = this.list(queryWrapper);
|
|
|
- if (!name.equals(customOption.getName()) && customOptions.size() != 0) {
|
|
|
- throw new XiaoShiException("名称重复");
|
|
|
+ //所属自定义栏位的id
|
|
|
+ Integer customFieldId = updateCustomOptionDTO.getCustomFieldId();
|
|
|
+ //查询自定义栏位的类型,如果为树,则调用架构部分
|
|
|
+ CustomField customField = customFieldService.getById(customFieldId);
|
|
|
+ Integer customFieldType = customField.getType();
|
|
|
+ if (customFieldType.equals(6)) {
|
|
|
+ UpdateTreeNodeDTO updateTreeNodeDTO = new UpdateTreeNodeDTO();
|
|
|
+ BeanUtils.copyProperties(updateCustomOptionDTO, updateTreeNodeDTO);
|
|
|
+ List<MultipartFile> files = new ArrayList<>();
|
|
|
+ id = (Integer) treeNodeService.updateMessage(updateTreeNodeDTO, files);
|
|
|
+ } else {
|
|
|
+ CustomOption customOption = this.getById(updateCustomOptionDTO.getId());
|
|
|
+ //检查名称是否规范
|
|
|
+ updateCustomOptionDTO.setName(name.trim());
|
|
|
+ //同一个自定义栏位下值选项不能重复
|
|
|
+ LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(CustomOption::getName, name);
|
|
|
+ queryWrapper.eq(CustomOption::getCustomFieldId, updateCustomOptionDTO.getCustomFieldId());
|
|
|
+ List<CustomOption> customOptions = this.list(queryWrapper);
|
|
|
+ if (!name.equals(customOption.getName()) && customOptions.size() != 0) {
|
|
|
+ throw new XiaoShiException("名称重复");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(updateCustomOptionDTO, customOption);
|
|
|
+ customOption.updateById();
|
|
|
+ id = customOption.getId();
|
|
|
}
|
|
|
- BeanUtils.copyProperties(updateCustomOptionDTO, customOption);
|
|
|
- customOption.updateById();
|
|
|
- return customOption.getId();
|
|
|
+ return id;
|
|
|
}
|
|
|
|
|
|
- public List<CustomOptionVO> getCustomOption(Integer customFieldId) throws IOException {
|
|
|
- List<CustomOptionVO> customOptionVOS = new ArrayList<>();
|
|
|
- if (!customFieldId.equals(null) && customFieldId != 0) {
|
|
|
- List<String> createIds = new ArrayList<>();
|
|
|
- LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(CustomOption::getCustomFieldId, customFieldId);
|
|
|
- List<CustomOption> customOptions = this.list(queryWrapper);
|
|
|
- customOptions.forEach(
|
|
|
- item -> {
|
|
|
- if (item.getCreateId() != null) {
|
|
|
- createIds.add(item.getCreateId());
|
|
|
+ /**
|
|
|
+ * 查询自定义选项
|
|
|
+ * @param getCustomOptionDTO
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Records getCustomOption(GetCustomOptionDTO getCustomOptionDTO) throws Exception {
|
|
|
+ Integer customFieldId = getCustomOptionDTO.getCustomFieldId();
|
|
|
+ Records records = new Records();
|
|
|
+ CustomField customField = customFieldService.getById(customFieldId);
|
|
|
+ Integer customFieldType = customField.getType();
|
|
|
+ if (customFieldType.equals(6)) {
|
|
|
+ QueryTreeNodeDTO queryTreeNodeDTO = new QueryTreeNodeDTO();
|
|
|
+ queryTreeNodeDTO.setName(getCustomOptionDTO.getName());
|
|
|
+ queryTreeNodeDTO.setType(4);
|
|
|
+ queryTreeNodeDTO.setTypeId(customFieldId);
|
|
|
+ records = treeNodeService.queryMessage(queryTreeNodeDTO);
|
|
|
+ } else {
|
|
|
+ List<CustomOptionVO> customOptionVOS = new ArrayList<>();
|
|
|
+ if (!customFieldId.equals(null) && customFieldId != 0) {
|
|
|
+ List<String> createIds = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(CustomOption::getCustomFieldId, customFieldId);
|
|
|
+ List<CustomOption> customOptions = this.list(queryWrapper);
|
|
|
+ customOptions.forEach(
|
|
|
+ item -> {
|
|
|
+ if (item.getCreateId() != null) {
|
|
|
+ createIds.add(item.getCreateId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ List<Personnel> personnels = new ArrayList<>();
|
|
|
+ //查询创建人名称
|
|
|
+ if (createIds.size() != 0) {
|
|
|
+ String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
+ }
|
|
|
+ if (customOptions != null && customOptions.size() != 0) {
|
|
|
+ for (CustomOption customOption : customOptions) {
|
|
|
+ CustomOptionVO customOptionVO = new CustomOptionVO();
|
|
|
+ BeanUtils.copyProperties(customOption, customOptionVO);
|
|
|
+ //装载人员信息
|
|
|
+ Personnel personnel = personnels.stream().filter(item -> item.getId().equals(customOptionVO.getCreateId())).findFirst().orElse(null);
|
|
|
+ if (personnel != null) {
|
|
|
+ customOptionVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ customOptionVOS.add(customOptionVO);
|
|
|
+ } else {
|
|
|
+ throw new XiaoShiException("未获取到创建人信息");
|
|
|
}
|
|
|
- }
|
|
|
- );
|
|
|
- List<Personnel> personnels = new ArrayList<>();
|
|
|
- //查询创建人名称
|
|
|
- if (createIds.size() != 0) {
|
|
|
- String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
- personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
- }
|
|
|
- if (customOptions != null && customOptions.size() != 0) {
|
|
|
- for (CustomOption customOption : customOptions) {
|
|
|
- CustomOptionVO customOptionVO = new CustomOptionVO();
|
|
|
- BeanUtils.copyProperties(customOption, customOptionVO);
|
|
|
- //装载人员信息
|
|
|
- Personnel personnel = personnels.stream().filter(item -> item.getId().equals(customOptionVO.getCreateId())).findFirst().orElse(null);
|
|
|
- if (personnel != null) {
|
|
|
- customOptionVO.setCreateName(personnel.getPersonnelName());
|
|
|
- customOptionVOS.add(customOptionVO);
|
|
|
- } else {
|
|
|
- throw new XiaoShiException("未获取到创建人信息");
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ throw new XiaoShiException("错误参数");
|
|
|
}
|
|
|
- } else {
|
|
|
- throw new XiaoShiException("错误参数");
|
|
|
+ records.setData(customOptionVOS);
|
|
|
}
|
|
|
- return customOptionVOS;
|
|
|
+ return records;
|
|
|
}
|
|
|
|
|
|
- public void deleteCustomOption(List<Integer> ids){
|
|
|
- if (ids != null && ids.size() > 0) {
|
|
|
- this.removeBatchByIds(ids);
|
|
|
+ /**
|
|
|
+ * 删除自定义选项
|
|
|
+ * @param customOptionDeleteDTOS
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public void deleteCustomOption(List<CustomOptionDeleteDTO> customOptionDeleteDTOS) throws IOException {
|
|
|
+ if (customOptionDeleteDTOS != null && customOptionDeleteDTOS.size() > 0) {
|
|
|
+ for (CustomOptionDeleteDTO customOptionDeleteDTO : customOptionDeleteDTOS) {
|
|
|
+ Integer customFieldId = customOptionDeleteDTO.getCustomFieldId();
|
|
|
+ CustomField customField = customFieldService.getById(customFieldId);
|
|
|
+ Integer customFieldType = customField.getType();
|
|
|
+ List<Integer> deleteIds = new ArrayList<>();
|
|
|
+ deleteIds.add(customOptionDeleteDTO.getId());
|
|
|
+ if (customFieldType.equals(6)) {
|
|
|
+ treeNodeService.deleteMessage(deleteIds);
|
|
|
+ } else {
|
|
|
+ this.removeBatchByIds(deleteIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
throw new XiaoShiException("参数错误");
|
|
|
}
|