CustomFieldService.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. package cn.cslg.pas.service.business;
  2. import cn.cslg.pas.common.dto.AllFieldOrderDTO;
  3. import cn.cslg.pas.common.dto.business.CustomFieldDTO;
  4. import cn.cslg.pas.common.dto.business.UpdateCustomFieldDTO;
  5. import cn.cslg.pas.common.dto.es.EsCustomFieldDTO;
  6. import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
  7. import cn.cslg.pas.common.dto.es.QueryEsCustomFieldDTO;
  8. import cn.cslg.pas.common.model.cronModel.Personnel;
  9. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  10. import cn.cslg.pas.common.model.cronModel.Records;
  11. import cn.cslg.pas.common.model.request.GroupRequest;
  12. import cn.cslg.pas.common.model.request.QueryRequest;
  13. import cn.cslg.pas.common.utils.*;
  14. import cn.cslg.pas.common.vo.FieldValueVO;
  15. import cn.cslg.pas.common.vo.PatentWithIdVO;
  16. import cn.cslg.pas.common.vo.UploadParamsVO;
  17. import cn.cslg.pas.common.vo.business.AllCustomFieldVO;
  18. import cn.cslg.pas.common.vo.business.CustomFieldVO;
  19. import cn.cslg.pas.common.vo.business.ProductVO;
  20. import cn.cslg.pas.common.vo.es.QueryESCustomFieldVO;
  21. import cn.cslg.pas.domain.business.*;
  22. import cn.cslg.pas.exception.UnLoginException;
  23. import cn.cslg.pas.exception.XiaoShiException;
  24. import cn.cslg.pas.factorys.businessFactory.Business;
  25. import cn.cslg.pas.mapper.CustomFieldMapper;
  26. import cn.cslg.pas.service.AssoTaskFieldService;
  27. import cn.cslg.pas.service.business.es.EsCustomFieldService;
  28. import cn.cslg.pas.service.permissions.PermissionService;
  29. import cn.cslg.pas.service.query.FormatQueryService;
  30. import com.alibaba.fastjson.JSONObject;
  31. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  32. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  33. import org.springframework.beans.BeanUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.context.annotation.Lazy;
  36. import org.springframework.stereotype.Service;
  37. import org.springframework.util.CollectionUtils;
  38. import org.springframework.web.multipart.MultipartFile;
  39. import java.io.IOException;
  40. import java.util.ArrayList;
  41. import java.util.Arrays;
  42. import java.util.Comparator;
  43. import java.util.List;
  44. import java.util.stream.Collectors;
  45. /**
  46. * 自定义栏位Service层
  47. *
  48. * @Author xiexiang
  49. * @Date 2023/11/8
  50. */
  51. @Service
  52. public class CustomFieldService extends ServiceImpl<CustomFieldMapper, CustomField> implements Business {
  53. @Autowired
  54. private CacheUtils cacheUtils;
  55. @Autowired
  56. private LoginUtils loginUtils;
  57. @Autowired
  58. private FormatQueryService formatQueryService;
  59. @Autowired
  60. private CustomFieldMapper customFieldMapper;
  61. @Autowired
  62. private PermissionService permissionService;
  63. @Autowired
  64. private AssoProjectTreeNodeService assoProjectTreeNodeService;
  65. @Autowired
  66. private ProductCategoryService productCategoryService;
  67. @Autowired
  68. private ProductService productService;
  69. @Autowired
  70. private EsCustomFieldService esCustomFieldService;
  71. @Lazy
  72. @Autowired
  73. private CustomOptionService customOptionService;
  74. @Autowired
  75. private TreeNodeService treeNodeService;
  76. @Autowired
  77. private AssoTaskFieldService assoTaskFieldService;
  78. @Override
  79. public Object queryMessage(QueryRequest queryRequest) throws Exception {
  80. //根据专题库/报告id查询自定义栏位
  81. List<String> sqls = formatQueryService.reSqls(queryRequest, "customField");
  82. //根据sql查询自定义栏位信息
  83. List<CustomFieldVO> customFieldVOS = customFieldMapper.getCustomField(sqls.get(0), sqls.get(1), sqls.get(2));
  84. //查询总数
  85. Long total = customFieldMapper.getCustomFieldCount(sqls.get(0));
  86. //装载自定义栏位信息
  87. this.loadCustomField(customFieldVOS);
  88. //装载返回信息
  89. Records records = new Records();
  90. records.setCurrent(queryRequest.getCurrent());
  91. records.setSize(queryRequest.getSize());
  92. records.setData(customFieldVOS);
  93. records.setTotal(total);
  94. return records;
  95. }
  96. @Override
  97. public Object addMessage(Object object, List<MultipartFile> files) {
  98. return null;
  99. }
  100. @Override
  101. public Object deleteMessage(List<Integer> ids) throws IOException {
  102. if (ids == null || ids.size() == 0) {
  103. throw new XiaoShiException("ids不能为空");
  104. }
  105. this.removeBatchByIds(ids);
  106. //TODO 删除缓存中保存的栏位信息
  107. //TODO 删除与专题库的关联关系
  108. return ids;
  109. }
  110. @Override
  111. public Object updateMessage(Object object, List<MultipartFile> files) {
  112. return null;
  113. }
  114. @Override
  115. public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
  116. return null;
  117. }
  118. @Override
  119. public Object addMessage(Object object) {
  120. if (object == null) {
  121. throw new XiaoShiException("参数不能为空");
  122. }
  123. //object to customFieldDTO
  124. CustomFieldDTO customFieldDTO = (CustomFieldDTO) object;
  125. //非空校验
  126. if (customFieldDTO.getProjectId().equals(null)) {
  127. throw new XiaoShiException("专题库/报告id不能为空!");
  128. }
  129. if (customFieldDTO.getName().equals(null) || customFieldDTO.getName().equals("")) {
  130. throw new XiaoShiException("自定义栏位名称不能为空!");
  131. }
  132. if (customFieldDTO.getType().equals(null)) {
  133. throw new XiaoShiException("自定义栏位类型不能为空!");
  134. }
  135. String name = customFieldDTO.getName();
  136. Integer projectId = customFieldDTO.getProjectId();
  137. //检查名称是否规范
  138. customFieldDTO.setName(name.trim());
  139. //同一个专题库/报告id下名称不能重复
  140. LambdaQueryWrapper<CustomField> queryWrapper = new LambdaQueryWrapper<>();
  141. queryWrapper.eq(CustomField::getName, name);
  142. queryWrapper.eq(CustomField::getProjectId, projectId);
  143. List<CustomField> customFields = this.list(queryWrapper);
  144. if (customFields != null && customFields.size() != 0) {
  145. throw new XiaoShiException("名称不能重复");
  146. }
  147. //获取登录人信息
  148. PersonnelVO personnelVO = new PersonnelVO();
  149. try {
  150. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  151. } catch (Exception e) {
  152. throw new UnLoginException("未登录");
  153. }
  154. CustomField customField = new CustomField();
  155. BeanUtils.copyProperties(customFieldDTO, customField);
  156. customField.setCreateId(personnelVO.getId());
  157. customField.insert();
  158. //TODO 删除缓存中保存的栏位信息
  159. return customField.getId();
  160. }
  161. @Override
  162. public Object updateMessage(Object object) {
  163. if (object == null) {
  164. throw new XiaoShiException("参数不能为空");
  165. }
  166. //object to updateCustomFieldDTO
  167. UpdateCustomFieldDTO updateCustomFieldDTO = (UpdateCustomFieldDTO) object;
  168. //非空校验
  169. if (updateCustomFieldDTO.getProjectId().equals(null)) {
  170. throw new XiaoShiException("专题库/报告id不能为空!");
  171. }
  172. if (updateCustomFieldDTO.getName().equals(null) || updateCustomFieldDTO.getName().equals("")) {
  173. throw new XiaoShiException("自定义栏位名称不能为空!");
  174. }
  175. if (updateCustomFieldDTO.getType().equals(null)) {
  176. throw new XiaoShiException("自定义栏位类型不能为空!");
  177. }
  178. String name = updateCustomFieldDTO.getName();
  179. Integer projectId = updateCustomFieldDTO.getProjectId();
  180. CustomField customField = this.getById(updateCustomFieldDTO.getId());
  181. //检查名称是否规范
  182. updateCustomFieldDTO.setName(name.trim());
  183. //同一个专题库/报告id下名称不能重复
  184. LambdaQueryWrapper<CustomField> queryWrapper = new LambdaQueryWrapper<>();
  185. queryWrapper.eq(CustomField::getName, name);
  186. queryWrapper.eq(CustomField::getProjectId, projectId);
  187. List<CustomField> customFields = this.list(queryWrapper);
  188. if (!name.equals(customField.getName()) && customFields.size() != 0) {
  189. throw new XiaoShiException("名称重复");
  190. }
  191. //TODO 删除缓存中保存的栏位信息
  192. BeanUtils.copyProperties(updateCustomFieldDTO, customField);
  193. customField.updateById();
  194. return customField.getId();
  195. }
  196. /**
  197. * 装载自定义栏位
  198. *
  199. * @param customFieldVOS
  200. */
  201. private void loadCustomField(List<CustomFieldVO> customFieldVOS) throws IOException {
  202. List<String> createIds = new ArrayList<>();
  203. customFieldVOS.forEach(
  204. item -> {
  205. if (item.getCreateId() != null) {
  206. createIds.add(item.getCreateId());
  207. }
  208. }
  209. );
  210. List<Personnel> personnels = new ArrayList<>();
  211. //查询创建人名称
  212. if (createIds.size() != 0) {
  213. String res = permissionService.getPersonnelByIdsFromPCS(createIds);
  214. JSONObject jsonObject = JSONObject.parseObject(res);
  215. personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
  216. }
  217. for (CustomFieldVO customFieldVO : customFieldVOS) {
  218. //装载人员信息
  219. Personnel personnel = personnels.stream().filter(item -> item.getId().equals(customFieldVO.getCreateId())).findFirst().orElse(null);
  220. if (personnel != null) {
  221. customFieldVO.setCreateName(personnel.getPersonnelName());
  222. } else {
  223. throw new XiaoShiException("未获取到当前登陆人信息");
  224. }
  225. }
  226. }
  227. public List<AllCustomFieldVO> getAllProjectCustomField(Integer projectId) {
  228. Integer order = 0;
  229. List<AllCustomFieldVO> allCustomFieldVOS = cacheUtils.getPatentCustomField(projectId);
  230. if (CollectionUtils.isEmpty(allCustomFieldVOS)) {
  231. allCustomFieldVOS = new ArrayList<>();
  232. //根据 project获得栏位值
  233. List<CustomField> customFields = new ArrayList<>();
  234. LambdaQueryWrapper<CustomField> queryWrapper = new LambdaQueryWrapper<>();
  235. queryWrapper.eq(CustomField::getProjectId, projectId);
  236. customFields = this.list(queryWrapper);
  237. //
  238. LambdaQueryWrapper<AssoProjectTreeNode> assoQueryWrapper = new LambdaQueryWrapper<>();
  239. assoQueryWrapper.eq(AssoProjectTreeNode::getProjectId, projectId);
  240. List<AssoProjectTreeNode> projectTreeNodes = assoProjectTreeNodeService.list(assoQueryWrapper);
  241. for (CustomField item : customFields) {
  242. AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
  243. allCustomFieldVO.setId(item.getId());
  244. allCustomFieldVO.setName(item.getName());
  245. allCustomFieldVO.setType(item.getType());
  246. allCustomFieldVO.setSysOrder(order);
  247. allCustomFieldVOS.add(allCustomFieldVO);
  248. order += 1;
  249. }
  250. for (AssoProjectTreeNode item : projectTreeNodes) {
  251. //根据类型和id
  252. AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
  253. allCustomFieldVO.setId(item.getId());
  254. allCustomFieldVO.setType(item.getTreeType());
  255. allCustomFieldVO.setSysOrder(order);
  256. switch (item.getTreeType()) {
  257. case 7:
  258. Product product = productService.getById(item.getId());
  259. allCustomFieldVO.setName(product.getName());
  260. break;
  261. case 8:
  262. ProductCategory productCategory = productCategoryService.getById(item.getId());
  263. allCustomFieldVO.setName(productCategory.getName());
  264. break;
  265. case 9:
  266. //TODO 技术类别
  267. break;
  268. }
  269. allCustomFieldVOS.add(allCustomFieldVO);
  270. order += 1;
  271. }
  272. cacheUtils.addPatentCustomField(projectId, allCustomFieldVOS);
  273. }
  274. return allCustomFieldVOS;
  275. }
  276. /**
  277. * @param taskId
  278. * @return
  279. */
  280. public List<AllCustomFieldVO> getAllTaskCustomField(Integer taskId) {
  281. Integer order = 0;
  282. List<AllCustomFieldVO> allCustomFieldVOS = cacheUtils.getTaskCustomField(taskId);
  283. if (allCustomFieldVOS == null || allCustomFieldVOS.size() == 0) {
  284. allCustomFieldVOS = new ArrayList<>();
  285. //根据任务id查询
  286. List<AssoTaskField> assoTaskFields = new ArrayList<>();
  287. LambdaQueryWrapper<AssoTaskField> queryWrapper = new LambdaQueryWrapper<>();
  288. queryWrapper.eq(AssoTaskField::getTaskId, taskId);
  289. assoTaskFields = assoTaskFieldService.list(queryWrapper);
  290. //
  291. if (assoTaskFields != null) {
  292. //从自定义栏位表中获得自定义栏位id
  293. List<Integer> fieldIds = assoTaskFields.stream()
  294. .filter(item -> item.getFieldType().equals(0)
  295. || item.getFieldType().equals(1)
  296. || item.getFieldType().equals(2)
  297. || item.getFieldType().equals(3)
  298. || item.getFieldType().equals(4)
  299. || item.getFieldType().equals(5)
  300. || item.getFieldType().equals(6)).map(AssoTaskField::getFieldId).collect(Collectors.toList());
  301. if (fieldIds.size() != 0) {
  302. LambdaQueryWrapper<CustomField> queryCWrapper = new LambdaQueryWrapper<>();
  303. queryCWrapper.in(CustomField::getId, fieldIds);
  304. List<CustomField> customFields = this.list(queryCWrapper);
  305. for (CustomField item : customFields) {
  306. AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
  307. allCustomFieldVO.setId(item.getId());
  308. allCustomFieldVO.setName(item.getName());
  309. allCustomFieldVO.setType(item.getType());
  310. allCustomFieldVO.setSysOrder(order);
  311. allCustomFieldVOS.add(allCustomFieldVO);
  312. order += 1;
  313. }
  314. }
  315. //从关联表中获得产品id
  316. List<Integer> productIds = assoTaskFields.stream()
  317. .filter(item -> item.getFieldId().equals(7))
  318. .map(AssoTaskField::getFieldId).collect(Collectors.toList());
  319. if (productIds != null && productIds.size() != 0) {
  320. LambdaQueryWrapper<Product> productLambdaQueryWrapper = new LambdaQueryWrapper<>();
  321. List<Product> products = productService.list(productLambdaQueryWrapper);
  322. for (Product item : products) {
  323. AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
  324. allCustomFieldVO.setId(item.getId());
  325. allCustomFieldVO.setName(item.getName());
  326. allCustomFieldVO.setType(7);
  327. allCustomFieldVO.setSysOrder(order);
  328. allCustomFieldVOS.add(allCustomFieldVO);
  329. order += 1;
  330. }
  331. }
  332. List<Integer> productCategoryIds = assoTaskFields.stream()
  333. .filter(item -> item.getFieldId().equals(8))
  334. .map(AssoTaskField::getFieldId).collect(Collectors.toList());
  335. if (productCategoryIds != null && productCategoryIds.size() != 0) {
  336. LambdaQueryWrapper<ProductCategory> LambdaQueryWrapper = new LambdaQueryWrapper<>();
  337. List<ProductCategory> productCategories = productCategoryService.list(LambdaQueryWrapper);
  338. for (ProductCategory item : productCategories) {
  339. AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
  340. allCustomFieldVO.setId(item.getId());
  341. allCustomFieldVO.setName(item.getName());
  342. allCustomFieldVO.setType(8);
  343. allCustomFieldVO.setSysOrder(order);
  344. allCustomFieldVOS.add(allCustomFieldVO);
  345. order += 1;
  346. }
  347. }
  348. //TODO 技术类别
  349. // List<Integer> technicalIds = assoTaskFields.stream()
  350. // .filter(item -> item.getFieldId().equals(9))
  351. // .map(AssoTaskField::getFieldId).collect(Collectors.toList());
  352. }
  353. cacheUtils.addTaskCustomField(taskId, allCustomFieldVOS);
  354. }
  355. allCustomFieldVOS = allCustomFieldVOS.stream().sorted(Comparator.comparing(AllCustomFieldVO::getSysOrder)).collect(Collectors.toList());
  356. return allCustomFieldVOS;
  357. }
  358. /**
  359. * 查询栏位选项
  360. *
  361. * @param queryEsCustomFieldDTO
  362. * @return
  363. * @throws Exception
  364. */
  365. public Records getCustomFieldValues(QueryEsCustomFieldDTO queryEsCustomFieldDTO) throws Exception {
  366. List<FieldValueVO> fieldValueVOS = new ArrayList<>();
  367. Integer type = queryEsCustomFieldDTO.getFieldType();
  368. EsCustomFieldDTO esCustomFieldDTO = new EsCustomFieldDTO();
  369. esCustomFieldDTO.setFieldId(queryEsCustomFieldDTO.getFieldId());
  370. esCustomFieldDTO.setProjectId((queryEsCustomFieldDTO.getProjectId()));
  371. esCustomFieldDTO.setTaskId(queryEsCustomFieldDTO.getTaskId());
  372. esCustomFieldDTO.setPatentNo(queryEsCustomFieldDTO.getPatentNo());
  373. esCustomFieldDTO.setFieldType(queryEsCustomFieldDTO.getFieldType());
  374. PatentWithIdVO patentVO = esCustomFieldService.getEsCustomField(esCustomFieldDTO);
  375. if (patentVO != null) {
  376. List<String> value = patentVO.getPatent().getESCustomField().getFieldValue();
  377. switch (type) {
  378. case 0:
  379. case 1:
  380. case 2:
  381. value.forEach(item -> {
  382. FieldValueVO fieldValueVO = new FieldValueVO();
  383. fieldValueVO.setValue(item);
  384. fieldValueVOS.add(fieldValueVO);
  385. });
  386. break;
  387. case 3:
  388. case 4:
  389. case 5:
  390. if (value != null && value.size() > 0) {
  391. List<Integer> ids = FormatUtil.StringTOIntegerList(value);
  392. LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
  393. queryWrapper.in(CustomOption::getId, ids);
  394. List<CustomOption> customOptions = customOptionService.list(queryWrapper);
  395. customOptions.forEach(item -> {
  396. FieldValueVO fieldValueVO = new FieldValueVO();
  397. fieldValueVO.setValueId(item.getId());
  398. fieldValueVO.setValue(item.getName());
  399. fieldValueVOS.add(fieldValueVO);
  400. });
  401. }
  402. break;
  403. case 6:
  404. case 7:
  405. case 8:
  406. case 9:
  407. if (value != null && value.size() > 0) {
  408. List<Integer> ids = FormatUtil.StringTOIntegerList(value);
  409. LambdaQueryWrapper<TreeNode> queryWrapper = new LambdaQueryWrapper<>();
  410. queryWrapper.in(TreeNode::getId, ids);
  411. List<TreeNode> treeNodes = treeNodeService.list(queryWrapper);
  412. treeNodes.forEach(item -> {
  413. FieldValueVO fieldValueVO = new FieldValueVO();
  414. fieldValueVO.setValueId(item.getId());
  415. fieldValueVO.setValue(item.getName());
  416. fieldValueVO.setPath(item.getPath());
  417. fieldValueVOS.add(fieldValueVO);
  418. });
  419. }
  420. break;
  421. }
  422. }
  423. Records records = new Records();
  424. records.setData(fieldValueVOS);
  425. return records;
  426. }
  427. public Records addAllPatentCustomFieldOrder(AllFieldOrderDTO allFieldOrderDTO) {
  428. Integer projectId = allFieldOrderDTO.getProjectId();
  429. List<AllCustomFieldVO> allCustomFieldVOS = allFieldOrderDTO.getAllCustomFieldVOs();
  430. if (allFieldOrderDTO.getTaskId() != null) {
  431. cacheUtils.addTaskCustomField(allFieldOrderDTO.getTaskId(), allCustomFieldVOS);
  432. } else {
  433. cacheUtils.addPatentCustomField(projectId, allCustomFieldVOS);
  434. }
  435. Records records = new Records();
  436. records.setData(allCustomFieldVOS);
  437. return records;
  438. }
  439. /**
  440. * 根据名称获得标引栏位以及标引值
  441. *
  442. * @param name
  443. * @param projectId
  444. */
  445. public List<EsCustomFieldValueDTO> getCustomFieldByValueName(String name, Integer projectId) {
  446. List<EsCustomFieldValueDTO> esCustomFieldDTOS = new ArrayList<>();
  447. //根据名称获得标引栏位以及标引值
  448. LambdaQueryWrapper<CustomField> queryWrapper = new LambdaQueryWrapper<>();
  449. queryWrapper.in(CustomField::getType, Arrays.asList(4, 5, 6))
  450. .eq(CustomField::getProjectId, projectId);
  451. List<CustomField> customFields = this.list(queryWrapper);
  452. List<Integer> ids = customFields.stream().map(CustomField::getId).collect(Collectors.toList());
  453. if (ids.size() == 0) {
  454. return esCustomFieldDTOS;
  455. }
  456. //从option 查询名称相同的选项
  457. LambdaQueryWrapper<CustomOption> optionWrapper = new LambdaQueryWrapper<>();
  458. optionWrapper.eq(CustomOption::getName, name)
  459. .in(CustomOption::getCustomFieldId, ids);
  460. List<CustomOption> options = customOptionService.list(optionWrapper);
  461. // 从 treeNode 查询名称相同的节点
  462. LambdaQueryWrapper<TreeNode> treeNodeWrapper = new LambdaQueryWrapper<>();
  463. treeNodeWrapper.eq(TreeNode::getName, name)
  464. .eq(TreeNode::getType, 4)
  465. .in(TreeNode::getTypeId, ids);
  466. List<TreeNode> treeNodes = treeNodeService.list(treeNodeWrapper);
  467. if (options != null && options.size() != 0) {
  468. options.forEach(item -> {
  469. EsCustomFieldValueDTO esCustomFieldDTO = esCustomFieldDTOS.stream()
  470. .filter(i -> i.getFieldId()
  471. .equals(item.getCustomFieldId()))
  472. .findFirst().orElse(null);
  473. if (esCustomFieldDTO == null) {
  474. esCustomFieldDTO.setFieldId(item.getCustomFieldId().toString());
  475. List<String> values = new ArrayList<>();
  476. values.add(item.getId().toString());
  477. esCustomFieldDTO.setFieldValue(values);
  478. } else {
  479. esCustomFieldDTO.getFieldValue().add(item.getId().toString());
  480. }
  481. });
  482. }
  483. if (treeNodes != null && treeNodes.size() != 0) {
  484. treeNodes.forEach(item -> {
  485. EsCustomFieldValueDTO esCustomFieldDTO = esCustomFieldDTOS.stream()
  486. .filter(i -> i.getFieldId()
  487. .equals(item.getTypeId()))
  488. .findFirst().orElse(null);
  489. if (esCustomFieldDTO == null) {
  490. esCustomFieldDTO.setFieldId(item.getTypeId().toString());
  491. List<String> values = new ArrayList<>();
  492. values.add(item.getId().toString());
  493. esCustomFieldDTO.setFieldValue(values);
  494. } else {
  495. esCustomFieldDTO.getFieldValue().add(item.getId().toString());
  496. }
  497. });
  498. }
  499. return esCustomFieldDTOS;
  500. }
  501. public List<EsCustomFieldDTO> getCustomFieldDTOs(List<UploadParamsVO.Field> customerFieldList, Integer projectId, Integer taskId) {
  502. List<EsCustomFieldDTO> esCustomFieldDTOS = new ArrayList<>();
  503. for (UploadParamsVO.Field field : customerFieldList) {
  504. String key = field.getKey();
  505. List<String> fields = StringUtils.changeStringToString(key, ":");
  506. if (fields.size() == 2) {
  507. String name = fields.get(0);
  508. Integer fieldId = null;
  509. List<String> value = field.getFieldList();
  510. Integer type = Integer.parseInt(fields.get(1));
  511. List<String> select = field.getFieldList();
  512. if (StringUtils.isNull(select)) {
  513. return esCustomFieldDTOS;
  514. }
  515. switch (type) {
  516. case 0:
  517. ;
  518. case 1:
  519. ;
  520. case 2:
  521. ;
  522. case 3:
  523. fieldId = this.GetIdByName(name, projectId, type);
  524. break;
  525. case 4:
  526. case 5:
  527. fieldId = this.GetIdByName(name, projectId, type);
  528. value = customOptionService.getIdsByNames(value, fieldId);
  529. break;
  530. case 6:
  531. //TODO 根据名称和类型查询
  532. fieldId = this.GetIdByName(name, projectId, type);
  533. value =treeNodeService.getIdByNames(value,fieldId,type);
  534. ;
  535. }
  536. EsCustomFieldDTO esCustomFieldDTO = new EsCustomFieldDTO();
  537. esCustomFieldDTO.setFieldType(type);
  538. esCustomFieldDTO.setFieldId(fieldId.toString());
  539. esCustomFieldDTO.setFieldValue(value);
  540. esCustomFieldDTO.setProjectId(projectId);
  541. esCustomFieldDTO.setTaskId(taskId);
  542. esCustomFieldDTOS.add(esCustomFieldDTO);
  543. }
  544. }
  545. return esCustomFieldDTOS;
  546. }
  547. /**
  548. * 根据名称获得自定义字段id
  549. *
  550. * @param name
  551. * @param projectId
  552. * @param type
  553. * @return
  554. */
  555. public Integer GetIdByName(String name, Integer projectId, Integer type) {
  556. LambdaQueryWrapper<CustomField> queryWrapper = new LambdaQueryWrapper<>();
  557. queryWrapper.eq(CustomField::getName, name)
  558. .eq(CustomField::getProjectId, projectId)
  559. .eq(CustomField::getType, type);
  560. CustomField customField = this.getOne(queryWrapper);
  561. if (customField != null) {
  562. return customField.getId();
  563. }
  564. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  565. CustomField customField1 = new CustomField();
  566. customField1.setName(name);
  567. customField1.setProjectId(projectId);
  568. customField1.setType(type);
  569. customField1.setCreateId(personnelVO.getId());
  570. customField1.insert();
  571. return customField1.getId();
  572. }
  573. }