PersonFieldService.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. package cn.cslg.pas.service.common;
  2. import cn.cslg.pas.common.core.base.PatentDictionary;
  3. import cn.cslg.pas.common.core.base.RedisConf;
  4. import cn.cslg.pas.common.dto.QueryFieldsDTO;
  5. import cn.cslg.pas.common.dto.patentCount.AddPatentCountDTO;
  6. import cn.cslg.pas.common.dto.patentCount.GetAllPatentCountDTO;
  7. import cn.cslg.pas.common.dto.patentCount.GetTabelColumDTO;
  8. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  9. import cn.cslg.pas.common.utils.*;
  10. import cn.cslg.pas.common.dto.AddSelfFieldDTO;
  11. import cn.cslg.pas.common.vo.QueryFiledVO;
  12. import cn.cslg.pas.common.vo.QueryFieldsVO;
  13. import cn.cslg.pas.common.vo.PersonSelfFieldVO;
  14. import cn.cslg.pas.common.vo.business.AllCustomFieldVO;
  15. import cn.cslg.pas.common.vo.patentCount.GetAllPatentCountVO;
  16. import cn.cslg.pas.domain.business.CustomField;
  17. import cn.cslg.pas.domain.business.ReportProject;
  18. import cn.cslg.pas.exception.UnLoginException;
  19. import cn.cslg.pas.exception.XiaoShiException;
  20. import cn.cslg.pas.service.business.CommonService;
  21. import cn.cslg.pas.service.business.CustomFieldService;
  22. import cn.cslg.pas.service.business.ReportProjectService;
  23. import cn.hutool.crypto.SecureUtil;
  24. import com.alibaba.fastjson.JSON;
  25. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.util.CollectionUtils;
  29. import java.util.ArrayList;
  30. import java.util.Comparator;
  31. import java.util.List;
  32. import java.util.stream.Collectors;
  33. @Service
  34. public class PersonFieldService {
  35. @Autowired
  36. private RedisUtil redisUtil;
  37. @Autowired
  38. private CacheUtils cacheUtils;
  39. @Autowired
  40. private LoginUtils loginUtils;
  41. @Autowired
  42. private CustomFieldService customFieldService;
  43. @Autowired
  44. private ReportProjectService reportProjectService;
  45. public List<PersonSelfFieldVO> getCustomField(String tableName, Integer projectId) {
  46. //根据登录人id和type查询
  47. PersonnelVO personnelVO = new PersonnelVO();
  48. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  49. String userId = personnelVO.getId();
  50. String key = "";
  51. if (projectId == null) {
  52. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
  53. } else {
  54. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + projectId);
  55. }
  56. String json = redisUtil.get(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key);
  57. //如果查到
  58. if (StringUtils.isNotEmpty(json)) {
  59. return JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
  60. }
  61. String fieldJson = "";
  62. //如果没查询到,则获取所有栏位添加到redis里
  63. try {
  64. fieldJson = CommonService.readJsonFile(tableName + ".json");
  65. } catch (Exception e) {
  66. throw new XiaoShiException("不存在此表");
  67. }
  68. List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
  69. if (fieldVOS == null) {
  70. throw new XiaoShiException("不存在此表");
  71. }
  72. fieldVOS = fieldVOS.stream().filter(item -> item.getIfShow().equals(true)).collect(Collectors.toList());
  73. if (fieldVOS == null || fieldVOS.size() == 0) {
  74. throw new XiaoShiException("表中无字段");
  75. }
  76. fieldVOS.forEach(item -> {
  77. item.setCreateType(1);
  78. });
  79. //当tableName是patent时
  80. if (PatentDictionary.NAME.equals(tableName)) {
  81. //获得所有自定义字段
  82. List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
  83. if (allCustomFieldVOS.size() != 0) {
  84. }
  85. }
  86. //装载顺序
  87. Integer order = 0;
  88. for (PersonSelfFieldVO item : fieldVOS) {
  89. item.setOrder(order);
  90. if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
  91. item.setIfHidden(true);
  92. } else {
  93. item.setIfHidden(false);
  94. }
  95. order++;
  96. }
  97. //保存到redis
  98. redisUtil.set(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
  99. return fieldVOS;
  100. }
  101. public List<PersonSelfFieldVO> setCustomField(AddSelfFieldDTO addSelfFieldDTO) {
  102. PersonnelVO personnelVO = new PersonnelVO();
  103. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  104. String userId = personnelVO.getId();
  105. String key = SecureUtil.md5(addSelfFieldDTO.getTableName() + RedisConf.SYMBOL_COLON + userId);
  106. String fieldJson = CommonService.readJsonFile(addSelfFieldDTO.getTableName() + ".json");
  107. List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
  108. fieldVOS = fieldVOS.stream().filter(item -> item.getIfShow().equals(true)).collect(Collectors.toList());
  109. for (PersonSelfFieldVO item : fieldVOS) {
  110. PersonSelfFieldVO temVO = addSelfFieldDTO.getValue().stream().filter(tem -> tem.getValue().equals(item.getValue())).findFirst().orElse(null);
  111. if (temVO == null) {
  112. item.setIfHidden(true);
  113. } else {
  114. item.setIfHidden(temVO.getIfHidden());
  115. }
  116. }
  117. Integer order = 0;
  118. for (PersonSelfFieldVO item : fieldVOS) {
  119. item.setOrder(order);
  120. order++;
  121. }
  122. redisUtil.set(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
  123. return fieldVOS;
  124. }
  125. /**
  126. * 获得查询的栏位
  127. *
  128. * @param queryFieldsDTOs
  129. * @return
  130. */
  131. public List<QueryFieldsVO> getQueryFields(List<QueryFieldsDTO> queryFieldsDTOs) {
  132. List<QueryFieldsVO> queryFieldsVOS = new ArrayList<>();
  133. queryFieldsDTOs.forEach(item -> {
  134. String json = null;
  135. try {
  136. json = CommonService.readJsonFile(item.getTableName() + ".json");
  137. } catch (Exception e) {
  138. }
  139. Boolean flag = true;
  140. if (json != null) {
  141. QueryFieldsVO queryFieldsVO = new QueryFieldsVO();
  142. queryFieldsVO.setTableName(item.getTableName());
  143. List<QueryFiledVO> queryConditions = JSON.parseArray(json, QueryFiledVO.class);
  144. //过滤出可查询的字段
  145. List<QueryFiledVO> queryFiledVOList = queryConditions.stream().filter(i -> flag.equals(i.getIfSearch()) || flag.equals(i.getIfGroup())).collect(Collectors.toList());
  146. if (!CollectionUtils.isEmpty(queryFiledVOList)) {
  147. queryFiledVOList.forEach(field -> {
  148. field.setGroup("nos");
  149. });
  150. }
  151. //当是专利的配置时
  152. if (item.getTableName().trim().equals(PatentDictionary.NAME) && item.getProjectId() != null) {
  153. //根据专题库id 查询所有自定义字段
  154. List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(item.getProjectId());
  155. //遍历装载
  156. List<QueryFiledVO> queryFiledVOS = new ArrayList<>();
  157. allCustomFieldVOS.forEach(i -> {
  158. QueryFiledVO queryFieldsVO1 = new QueryFiledVO();
  159. //装载名称
  160. queryFieldsVO1.setName(i.getName());
  161. //装载类型
  162. Integer type = i.getType();
  163. queryFieldsVO1.setFiledType(type);
  164. switch (type) {
  165. case 0:
  166. //装载组别
  167. queryFieldsVO1.setGroup("customField");
  168. queryFieldsVO1.setType("Integer");
  169. break;
  170. case 1:
  171. queryFieldsVO1.setGroup("customField");
  172. queryFieldsVO1.setType("DateTime");
  173. break;
  174. case 2:
  175. queryFieldsVO1.setGroup("customField");
  176. queryFieldsVO1.setType("String");
  177. break;
  178. case 4:
  179. case 5:
  180. queryFieldsVO1.setGroup("customField");
  181. queryFieldsVO1.setType("Array");
  182. break;
  183. case 6:
  184. queryFieldsVO1.setGroup("customField");
  185. queryFieldsVO1.setType("tree");
  186. break;
  187. case 7:
  188. queryFieldsVO1.setGroup("product");
  189. queryFieldsVO1.setType("tree");
  190. break;
  191. case 8:
  192. queryFieldsVO1.setGroup("productCategory");
  193. queryFieldsVO1.setType("tree");
  194. break;
  195. case 9:
  196. queryFieldsVO1.setGroup("technical");
  197. queryFieldsVO1.setType("tree");
  198. break;
  199. }
  200. //装载id
  201. queryFieldsVO1.setField(i.getId().toString());
  202. queryFieldsVO1.setIfSearch(true);
  203. queryFieldsVO1.setIfGroup(false);
  204. queryFiledVOS.add(queryFieldsVO1);
  205. });
  206. queryFiledVOList.addAll(queryFiledVOS);
  207. }
  208. queryFieldsVO.setConditionDTOList(queryFiledVOList);
  209. queryFieldsVOS.add(queryFieldsVO);
  210. }
  211. });
  212. return queryFieldsVOS;
  213. }
  214. /**
  215. * 查询表格显示栏位
  216. *
  217. * @param getTabelColumDTO
  218. * @return
  219. */
  220. public List<PersonSelfFieldVO> getTableColumns(GetTabelColumDTO getTabelColumDTO) {
  221. Integer projectId = getTabelColumDTO.getProjectId();
  222. Integer taskId = getTabelColumDTO.getTaskId();
  223. String tableName = getTabelColumDTO.getTableName();
  224. Integer productId = getTabelColumDTO.getProductId();
  225. //根据登录人id和type查询
  226. PersonnelVO personnelVO = new PersonnelVO();
  227. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  228. String userId = personnelVO.getId();
  229. String key = "";
  230. if (projectId == null) {
  231. if (productId != null) {
  232. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PRODUCT + RedisConf.SYMBOL_COLON + productId);
  233. } else {
  234. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
  235. }
  236. } else {
  237. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PROJECT + RedisConf.SYMBOL_COLON + projectId);
  238. }
  239. String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
  240. String json = redisUtil.get(redisKey);
  241. String fieldJson = "";
  242. //如果查到
  243. List<PersonSelfFieldVO> reFieldVos = new ArrayList<>();
  244. if (StringUtils.isNotEmpty(json)) {
  245. reFieldVos = JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
  246. }
  247. try {
  248. fieldJson = CommonService.readJsonFile(tableName + ".json");
  249. } catch (Exception e) {
  250. throw new XiaoShiException("不存在此表");
  251. }
  252. List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
  253. if (fieldVOS == null) {
  254. throw new XiaoShiException("不存在此表");
  255. }
  256. Boolean flag = true;
  257. fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfShow())).collect(Collectors.toList());
  258. if (fieldVOS == null || fieldVOS.size() == 0) {
  259. throw new XiaoShiException("表中无字段");
  260. }
  261. //当tableName是patent时
  262. if (PatentDictionary.NAME.equals(tableName) && projectId != null && projectId != 0) {
  263. //获得所有自定义字段
  264. List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
  265. AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
  266. allCustomFieldVO.setName("标签");
  267. allCustomFieldVO.setId(0);
  268. allCustomFieldVO.setType(10);
  269. allCustomFieldVOS.add(allCustomFieldVO);
  270. if (allCustomFieldVOS.size() != 0) {
  271. for (AllCustomFieldVO item : allCustomFieldVOS) {
  272. PersonSelfFieldVO personSelfFieldVO = new PersonSelfFieldVO();
  273. personSelfFieldVO.setIfHidden(true);
  274. personSelfFieldVO.setName(item.getName());
  275. personSelfFieldVO.setType(item.getType().toString());
  276. personSelfFieldVO.setValue(item.getId().toString());
  277. personSelfFieldVO.setIfPersonal(true);
  278. personSelfFieldVO.setIfSort(false);
  279. personSelfFieldVO.setDefaultHidden(true);
  280. fieldVOS.add(personSelfFieldVO);
  281. }
  282. }
  283. }
  284. //装载顺序
  285. for (PersonSelfFieldVO item : fieldVOS) {
  286. PersonSelfFieldVO personSelfFieldVO = reFieldVos.stream().filter(t -> t.getValue().equals(item.getValue()) && t.getType().equals(item.getType())).findFirst().orElse(null);
  287. if (personSelfFieldVO == null) {
  288. if (StringUtils.isNotEmpty(json)) {
  289. item.setIfHidden(true);
  290. } else {
  291. if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
  292. item.setIfHidden(true);
  293. } else {
  294. item.setIfHidden(false);
  295. }
  296. }
  297. reFieldVos.add(item);
  298. }
  299. }
  300. return reFieldVos;
  301. }
  302. /**
  303. * 获得表格导出栏位
  304. * @param getTabelColumDTO
  305. * @return
  306. */
  307. public List<PersonSelfFieldVO> getTableExportColumns(GetTabelColumDTO getTabelColumDTO) {
  308. Integer projectId = getTabelColumDTO.getProjectId();
  309. String tableName = getTabelColumDTO.getTableName();
  310. Integer productId = getTabelColumDTO.getProductId();
  311. //根据登录人id和type查询
  312. PersonnelVO personnelVO = new PersonnelVO();
  313. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  314. String userId = personnelVO.getId();
  315. String key = "";
  316. if (projectId == null) {
  317. if (productId != null) {
  318. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PRODUCT + RedisConf.SYMBOL_COLON + productId);
  319. } else {
  320. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
  321. }
  322. } else {
  323. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PROJECT + RedisConf.SYMBOL_COLON + projectId);
  324. }
  325. String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
  326. String json = redisUtil.get(redisKey);
  327. String fieldJson = "";
  328. //如果查到
  329. List<PersonSelfFieldVO> reFieldVos = new ArrayList<>();
  330. if (StringUtils.isNotEmpty(json)) {
  331. reFieldVos = JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
  332. }
  333. try {
  334. fieldJson = CommonService.readJsonFile(tableName + ".json");
  335. } catch (Exception e) {
  336. throw new XiaoShiException("不存在此表");
  337. }
  338. List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
  339. if (fieldVOS == null) {
  340. throw new XiaoShiException("不存在此表");
  341. }
  342. Boolean flag = true;
  343. fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIsExport())).collect(Collectors.toList());
  344. if (CollectionUtils.isEmpty(fieldVOS)) {
  345. throw new XiaoShiException("表中无字段");
  346. }
  347. //当tableName是patent时
  348. if (PatentDictionary.NAME.equals(tableName) && projectId != null && projectId != 0) {
  349. //获得所有自定义字段
  350. List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
  351. AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
  352. allCustomFieldVO.setName("标签");
  353. allCustomFieldVO.setId(0);
  354. allCustomFieldVO.setType(10);
  355. allCustomFieldVOS.add(allCustomFieldVO);
  356. if (!CollectionUtils.isEmpty(allCustomFieldVOS)) {
  357. for (AllCustomFieldVO item : allCustomFieldVOS) {
  358. PersonSelfFieldVO personSelfFieldVO = new PersonSelfFieldVO();
  359. personSelfFieldVO.setIfHidden(true);
  360. personSelfFieldVO.setName(item.getName());
  361. personSelfFieldVO.setType(item.getType().toString());
  362. personSelfFieldVO.setValue(item.getId().toString());
  363. personSelfFieldVO.setIfPersonal(true);
  364. personSelfFieldVO.setIfSort(false);
  365. personSelfFieldVO.setDefaultHidden(true);
  366. fieldVOS.add(personSelfFieldVO);
  367. }
  368. }
  369. }
  370. //装载顺序
  371. for (PersonSelfFieldVO item : fieldVOS) {
  372. PersonSelfFieldVO personSelfFieldVO = reFieldVos.stream().filter(t -> t.getValue().equals(item.getValue()) && t.getType().equals(item.getType())).findFirst().orElse(null);
  373. if (personSelfFieldVO == null) {
  374. if (StringUtils.isNotEmpty(json)) {
  375. item.setIfHidden(true);
  376. } else {
  377. if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
  378. item.setIfHidden(true);
  379. } else {
  380. item.setIfHidden(false);
  381. }
  382. }
  383. reFieldVos.add(item);
  384. }
  385. }
  386. return reFieldVos;
  387. }
  388. public List<PersonSelfFieldVO> setTableColumns(AddSelfFieldDTO addSelfFieldDTO) {
  389. PersonnelVO personnelVO = new PersonnelVO();
  390. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  391. String userId = personnelVO.getId();
  392. String tableName = addSelfFieldDTO.getTableName();
  393. Integer projectId = addSelfFieldDTO.getProjectId();
  394. Integer productId = addSelfFieldDTO.getProductId();
  395. List<PersonSelfFieldVO> personSelfFieldVOS = addSelfFieldDTO.getValue();
  396. personSelfFieldVOS = personSelfFieldVOS.stream().filter(item -> item.getIfHidden() != null && item.getIfHidden().equals(false)).collect(Collectors.toList());
  397. String key = "";
  398. if (projectId == null) {
  399. if (productId != null) {
  400. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PRODUCT + RedisConf.SYMBOL_COLON + productId);
  401. } else {
  402. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
  403. }
  404. } else {
  405. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PROJECT + RedisConf.SYMBOL_COLON + projectId);
  406. }
  407. String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
  408. redisUtil.set(redisKey, JsonUtils.objectToJson(personSelfFieldVOS));
  409. return personSelfFieldVOS;
  410. }
  411. /**
  412. * 查询所有的统计字段
  413. *
  414. * @param getAllPatentCountDTO
  415. * @return
  416. */
  417. public List<GetAllPatentCountVO> getAllCountColumns(GetAllPatentCountDTO getAllPatentCountDTO) {
  418. Integer taskId = getAllPatentCountDTO.getTaskId();
  419. Integer projectId = getAllPatentCountDTO.getProjectId();
  420. String fieldJson = "";
  421. //如果没查询到,则获取所有栏位添加到redis里
  422. try {
  423. fieldJson = CommonService.readJsonFile(PatentDictionary.NAME + ".json");
  424. } catch (Exception e) {
  425. throw new XiaoShiException("不存在此表");
  426. }
  427. Boolean flag = true;
  428. List<GetAllPatentCountVO> fieldVOS = JSON.parseArray(fieldJson, GetAllPatentCountVO.class);
  429. fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfStats())).collect(Collectors.toList());
  430. fieldVOS.forEach(item -> item.setFiledKind(-1));
  431. //当专题库id或者报告id不为null时
  432. if (taskId != null || projectId != null) {
  433. List<AllCustomFieldVO> allCustomFieldVOS = new ArrayList<>();
  434. if (taskId != null) {
  435. allCustomFieldVOS = customFieldService.getAllTaskCustomField(taskId);
  436. } else {
  437. allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
  438. }
  439. if (allCustomFieldVOS != null && allCustomFieldVOS.size() != 0) {
  440. //遍历查询出的自定义字段进行装载
  441. for (AllCustomFieldVO allCustomFieldVO : allCustomFieldVOS) {
  442. GetAllPatentCountVO getAllPatentCountVO = new GetAllPatentCountVO();
  443. //装载自定义字段的栏位值
  444. getAllPatentCountVO.setValue(allCustomFieldVO.getId().toString());
  445. //装载自定义栏位名
  446. getAllPatentCountVO.setName(allCustomFieldVO.getName());
  447. //装载栏位类型
  448. if (allCustomFieldVO.getType() <= 6) {
  449. getAllPatentCountVO.setFiledKind(0);
  450. switch (allCustomFieldVO.getType()) {
  451. case 0:
  452. getAllPatentCountVO.setType("Integer");
  453. break;
  454. case 1:
  455. getAllPatentCountVO.setType("DateTime");
  456. break;
  457. case 2:
  458. getAllPatentCountVO.setType("String");
  459. break;
  460. case 4:
  461. case 5:
  462. getAllPatentCountVO.setType("Array");
  463. break;
  464. case 6:
  465. getAllPatentCountVO.setType("tree");
  466. break;
  467. }
  468. } else {
  469. getAllPatentCountVO.setFiledKind(allCustomFieldVO.getType());
  470. getAllPatentCountVO.setType("tree");
  471. }
  472. fieldVOS.add(getAllPatentCountVO);
  473. }
  474. }
  475. }
  476. return fieldVOS;
  477. }
  478. /**
  479. * 查询显示的统计栏位
  480. *
  481. * @param getAllPatentCountDTO
  482. * @return
  483. */
  484. public List<GetAllPatentCountVO> getShowCountColumns(GetAllPatentCountDTO getAllPatentCountDTO) {
  485. Integer taskId = getAllPatentCountDTO.getTaskId();
  486. Integer projectId = getAllPatentCountDTO.getProjectId();
  487. //根据登录人id和type查询
  488. PersonnelVO personnelVO = new PersonnelVO();
  489. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  490. String userId = personnelVO.getId();
  491. String key = "";
  492. if (taskId != null) {
  493. key = SecureUtil.md5(RedisConf.TASK_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + taskId);
  494. } else {
  495. key = SecureUtil.md5(RedisConf.PROJECT_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + projectId);
  496. }
  497. String json = redisUtil.get(RedisConf.FIELD_COUNT + RedisConf.SYMBOL_COLON + key);
  498. //如果查到
  499. if (StringUtils.isNotEmpty(json)) {
  500. return JsonUtils.jsonToList(json, GetAllPatentCountVO.class);
  501. }
  502. String fieldJson = "";
  503. //如果没查询到,则获取所有栏位添加到redis里
  504. try {
  505. fieldJson = CommonService.readJsonFile(PatentDictionary.NAME + ".json");
  506. } catch (Exception e) {
  507. throw new XiaoShiException("不存在此表");
  508. }
  509. Boolean flag = true;
  510. //查询栏位
  511. LambdaQueryWrapper<CustomField> queryWrapper =new LambdaQueryWrapper<>();
  512. queryWrapper.eq(CustomField::getProjectId,projectId)
  513. .eq(CustomField::getName,"监控周期")
  514. .eq(CustomField::getType,4);
  515. CustomField customField =customFieldService.getOne(queryWrapper,false);
  516. List<GetAllPatentCountVO> fieldVOS =new ArrayList<>();
  517. if(customField!=null){
  518. GetAllPatentCountVO getAllPatentCountVO =new GetAllPatentCountVO();
  519. getAllPatentCountVO.setType("Array");
  520. getAllPatentCountVO.setValue(customField.getId().toString());
  521. getAllPatentCountVO.setName(customField.getName());
  522. getAllPatentCountVO.setFiledKind(0);
  523. fieldVOS.add(getAllPatentCountVO);
  524. }
  525. List<GetAllPatentCountVO> fieldVOS2 = JSON.parseArray(fieldJson, GetAllPatentCountVO.class);
  526. fieldVOS2 = fieldVOS2.stream().filter(item -> flag.equals(item.getIfStats()) && flag.equals(item.getDefaultShowStats())).collect(Collectors.toList());
  527. fieldVOS2.forEach(item -> item.setFiledKind(-1));
  528. fieldVOS.addAll(fieldVOS2);
  529. redisUtil.set(RedisConf.FIELD_COUNT + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
  530. return fieldVOS;
  531. }
  532. /**
  533. * 查询显示的统计栏位
  534. *
  535. * @param addPatentCountDTO
  536. * @return
  537. */
  538. public List<GetAllPatentCountVO> setShowCountColumns(AddPatentCountDTO addPatentCountDTO) {
  539. Integer taskId = addPatentCountDTO.getTaskId();
  540. Integer projectId = addPatentCountDTO.getProjectId();
  541. //根据登录人id和type查询
  542. PersonnelVO personnelVO = new PersonnelVO();
  543. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  544. String userId = personnelVO.getId();
  545. String key = "";
  546. if (taskId != null) {
  547. key = SecureUtil.md5(RedisConf.TASK_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + taskId);
  548. } else {
  549. key = SecureUtil.md5(RedisConf.PROJECT_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + projectId);
  550. }
  551. Boolean flag = true;
  552. List<GetAllPatentCountVO> fieldVOS = addPatentCountDTO.getValue();
  553. redisUtil.set(RedisConf.FIELD_COUNT + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
  554. return fieldVOS;
  555. }
  556. /**
  557. * 查询证据组合表头
  558. *
  559. * @param getTabelColumDTO
  560. * @return
  561. */
  562. public List<PersonSelfFieldVO> getEvidenceReasonTableColumns(GetTabelColumDTO getTabelColumDTO) {
  563. Integer projectId = getTabelColumDTO.getProjectId();
  564. String tableName = getTabelColumDTO.getTableName();
  565. if (tableName == null||tableName.equals("")) {
  566. tableName = "evidenceReason";
  567. }
  568. //根据登录人id和type查询
  569. PersonnelVO personnelVO = new PersonnelVO();
  570. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  571. String userId = personnelVO.getId();
  572. String key = "";
  573. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.EVIDENCE_REASON + RedisConf.SYMBOL_COLON + projectId);
  574. String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
  575. String json = redisUtil.get(redisKey);
  576. String fieldJson = "";
  577. //如果查到
  578. List<PersonSelfFieldVO> reFieldVos = new ArrayList<>();
  579. if (StringUtils.isNotEmpty(json)) {
  580. reFieldVos = JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
  581. }
  582. try {
  583. fieldJson = CommonService.readJsonFile(tableName + ".json");
  584. } catch (Exception e) {
  585. throw new XiaoShiException("不存在此表");
  586. }
  587. List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
  588. if (fieldVOS == null) {
  589. throw new XiaoShiException("不存在此表");
  590. }
  591. Boolean flag = true;
  592. LambdaQueryWrapper<ReportProject> queryWrapper =new LambdaQueryWrapper<>();
  593. queryWrapper.eq(ReportProject::getProjectId,projectId);
  594. ReportProject reportProject =reportProjectService.getOne(queryWrapper,false);
  595. if(reportProject.getIfSecondInvalid()!=null&&reportProject.getIfSecondInvalid())
  596. {
  597. fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfShow()) || item.getType().equals("second")).collect(Collectors.toList());
  598. }
  599. else {
  600. fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfShow())).collect(Collectors.toList());
  601. }
  602. if (fieldVOS == null || fieldVOS.size() == 0) {
  603. throw new XiaoShiException("表中无字段");
  604. }
  605. //装载顺序
  606. for (PersonSelfFieldVO item : fieldVOS) {
  607. if (StringUtils.isNotEmpty(json)) {
  608. PersonSelfFieldVO personSelfFieldVO = reFieldVos.stream().filter(t -> t.getValue().equals(item.getValue()) && t.getName().equals(item.getName())).findFirst().orElse(null);
  609. if (personSelfFieldVO == null) {
  610. item.setIfHidden(true);
  611. reFieldVos.add(item);
  612. }
  613. } else {
  614. if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
  615. item.setIfHidden(true);
  616. } else {
  617. item.setIfHidden(false);
  618. }
  619. reFieldVos.add(item);
  620. }
  621. }
  622. return reFieldVos;
  623. }
  624. public List<PersonSelfFieldVO> setEvidenceReasonTableColumns(AddSelfFieldDTO addSelfFieldDTO) {
  625. PersonnelVO personnelVO = new PersonnelVO();
  626. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  627. String userId = personnelVO.getId();
  628. String tableName = addSelfFieldDTO.getTableName();
  629. if (tableName == null||tableName.equals("")) {
  630. tableName = "evidenceReason";
  631. }
  632. Integer projectId = addSelfFieldDTO.getProjectId();
  633. List<PersonSelfFieldVO> personSelfFieldVOS = addSelfFieldDTO.getValue();
  634. personSelfFieldVOS = personSelfFieldVOS.stream().filter(item -> item.getIfHidden() != null && item.getIfHidden().equals(false)).collect(Collectors.toList());
  635. String key = "";
  636. key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.EVIDENCE_REASON + RedisConf.SYMBOL_COLON + projectId);
  637. String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
  638. redisUtil.set(redisKey, JsonUtils.objectToJson(personSelfFieldVOS));
  639. return personSelfFieldVOS;
  640. }
  641. }