123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- package cn.cslg.pas.service.common;
- import cn.cslg.pas.common.core.base.PatentDictionary;
- import cn.cslg.pas.common.core.base.RedisConf;
- import cn.cslg.pas.common.dto.QueryFieldsDTO;
- import cn.cslg.pas.common.dto.patentCount.AddPatentCountDTO;
- import cn.cslg.pas.common.dto.patentCount.GetAllPatentCountDTO;
- import cn.cslg.pas.common.dto.patentCount.GetTabelColumDTO;
- import cn.cslg.pas.common.model.cronModel.PersonnelVO;
- import cn.cslg.pas.common.utils.*;
- import cn.cslg.pas.common.dto.AddSelfFieldDTO;
- import cn.cslg.pas.common.vo.QueryFiledVO;
- import cn.cslg.pas.common.vo.QueryFieldsVO;
- import cn.cslg.pas.common.vo.PersonSelfFieldVO;
- import cn.cslg.pas.common.vo.business.AllCustomFieldVO;
- import cn.cslg.pas.common.vo.patentCount.GetAllPatentCountVO;
- import cn.cslg.pas.domain.business.CustomField;
- import cn.cslg.pas.domain.business.ReportProject;
- import cn.cslg.pas.exception.UnLoginException;
- import cn.cslg.pas.exception.XiaoShiException;
- import cn.cslg.pas.service.business.CommonService;
- import cn.cslg.pas.service.business.CustomFieldService;
- import cn.cslg.pas.service.business.ReportProjectService;
- import cn.hutool.crypto.SecureUtil;
- import com.alibaba.fastjson.JSON;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.List;
- import java.util.stream.Collectors;
- @Service
- public class PersonFieldService {
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private CacheUtils cacheUtils;
- @Autowired
- private LoginUtils loginUtils;
- @Autowired
- private CustomFieldService customFieldService;
- @Autowired
- private ReportProjectService reportProjectService;
- public List<PersonSelfFieldVO> getCustomField(String tableName, Integer projectId) {
- //根据登录人id和type查询
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String key = "";
- if (projectId == null) {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
- } else {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + projectId);
- }
- String json = redisUtil.get(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key);
- //如果查到
- if (StringUtils.isNotEmpty(json)) {
- return JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
- }
- String fieldJson = "";
- //如果没查询到,则获取所有栏位添加到redis里
- try {
- fieldJson = CommonService.readJsonFile(tableName + ".json");
- } catch (Exception e) {
- throw new XiaoShiException("不存在此表");
- }
- List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
- if (fieldVOS == null) {
- throw new XiaoShiException("不存在此表");
- }
- fieldVOS = fieldVOS.stream().filter(item -> item.getIfShow().equals(true)).collect(Collectors.toList());
- if (fieldVOS == null || fieldVOS.size() == 0) {
- throw new XiaoShiException("表中无字段");
- }
- fieldVOS.forEach(item -> {
- item.setCreateType(1);
- });
- //当tableName是patent时
- if (PatentDictionary.NAME.equals(tableName)) {
- //获得所有自定义字段
- List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
- if (allCustomFieldVOS.size() != 0) {
- }
- }
- //装载顺序
- Integer order = 0;
- for (PersonSelfFieldVO item : fieldVOS) {
- item.setOrder(order);
- if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
- item.setIfHidden(true);
- } else {
- item.setIfHidden(false);
- }
- order++;
- }
- //保存到redis
- redisUtil.set(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
- return fieldVOS;
- }
- public List<PersonSelfFieldVO> setCustomField(AddSelfFieldDTO addSelfFieldDTO) {
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String key = SecureUtil.md5(addSelfFieldDTO.getTableName() + RedisConf.SYMBOL_COLON + userId);
- String fieldJson = CommonService.readJsonFile(addSelfFieldDTO.getTableName() + ".json");
- List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
- fieldVOS = fieldVOS.stream().filter(item -> item.getIfShow().equals(true)).collect(Collectors.toList());
- for (PersonSelfFieldVO item : fieldVOS) {
- PersonSelfFieldVO temVO = addSelfFieldDTO.getValue().stream().filter(tem -> tem.getValue().equals(item.getValue())).findFirst().orElse(null);
- if (temVO == null) {
- item.setIfHidden(true);
- } else {
- item.setIfHidden(temVO.getIfHidden());
- }
- }
- Integer order = 0;
- for (PersonSelfFieldVO item : fieldVOS) {
- item.setOrder(order);
- order++;
- }
- redisUtil.set(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
- return fieldVOS;
- }
- /**
- * 获得查询的栏位
- *
- * @param queryFieldsDTOs
- * @return
- */
- public List<QueryFieldsVO> getQueryFields(List<QueryFieldsDTO> queryFieldsDTOs) {
- List<QueryFieldsVO> queryFieldsVOS = new ArrayList<>();
- queryFieldsDTOs.forEach(item -> {
- String json = null;
- try {
- json = CommonService.readJsonFile(item.getTableName() + ".json");
- } catch (Exception e) {
- }
- Boolean flag = true;
- if (json != null) {
- QueryFieldsVO queryFieldsVO = new QueryFieldsVO();
- queryFieldsVO.setTableName(item.getTableName());
- List<QueryFiledVO> queryConditions = JSON.parseArray(json, QueryFiledVO.class);
- //过滤出可查询的字段
- List<QueryFiledVO> queryFiledVOList = queryConditions.stream().filter(i -> flag.equals(i.getIfSearch()) || flag.equals(i.getIfGroup())).collect(Collectors.toList());
- if (!CollectionUtils.isEmpty(queryFiledVOList)) {
- queryFiledVOList.forEach(field -> {
- field.setGroup("nos");
- });
- }
- //当是专利的配置时
- if (item.getTableName().trim().equals(PatentDictionary.NAME) && item.getProjectId() != null) {
- //根据专题库id 查询所有自定义字段
- List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(item.getProjectId());
- //遍历装载
- List<QueryFiledVO> queryFiledVOS = new ArrayList<>();
- allCustomFieldVOS.forEach(i -> {
- QueryFiledVO queryFieldsVO1 = new QueryFiledVO();
- //装载名称
- queryFieldsVO1.setName(i.getName());
- //装载类型
- Integer type = i.getType();
- queryFieldsVO1.setFiledType(type);
- switch (type) {
- case 0:
- //装载组别
- queryFieldsVO1.setGroup("customField");
- queryFieldsVO1.setType("Integer");
- break;
- case 1:
- queryFieldsVO1.setGroup("customField");
- queryFieldsVO1.setType("DateTime");
- break;
- case 2:
- queryFieldsVO1.setGroup("customField");
- queryFieldsVO1.setType("String");
- break;
- case 4:
- case 5:
- queryFieldsVO1.setGroup("customField");
- queryFieldsVO1.setType("Array");
- break;
- case 6:
- queryFieldsVO1.setGroup("customField");
- queryFieldsVO1.setType("tree");
- break;
- case 7:
- queryFieldsVO1.setGroup("product");
- queryFieldsVO1.setType("tree");
- break;
- case 8:
- queryFieldsVO1.setGroup("productCategory");
- queryFieldsVO1.setType("tree");
- break;
- case 9:
- queryFieldsVO1.setGroup("technical");
- queryFieldsVO1.setType("tree");
- break;
- }
- //装载id
- queryFieldsVO1.setField(i.getId().toString());
- queryFieldsVO1.setIfSearch(true);
- queryFieldsVO1.setIfGroup(false);
- queryFiledVOS.add(queryFieldsVO1);
- });
- queryFiledVOList.addAll(queryFiledVOS);
- }
- queryFieldsVO.setConditionDTOList(queryFiledVOList);
- queryFieldsVOS.add(queryFieldsVO);
- }
- });
- return queryFieldsVOS;
- }
- /**
- * 查询表格显示栏位
- *
- * @param getTabelColumDTO
- * @return
- */
- public List<PersonSelfFieldVO> getTableColumns(GetTabelColumDTO getTabelColumDTO) {
- Integer projectId = getTabelColumDTO.getProjectId();
- Integer taskId = getTabelColumDTO.getTaskId();
- String tableName = getTabelColumDTO.getTableName();
- Integer productId = getTabelColumDTO.getProductId();
- //根据登录人id和type查询
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String key = "";
- if (projectId == null) {
- if (productId != null) {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PRODUCT + RedisConf.SYMBOL_COLON + productId);
- } else {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
- }
- } else {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PROJECT + RedisConf.SYMBOL_COLON + projectId);
- }
- String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
- String json = redisUtil.get(redisKey);
- String fieldJson = "";
- //如果查到
- List<PersonSelfFieldVO> reFieldVos = new ArrayList<>();
- if (StringUtils.isNotEmpty(json)) {
- reFieldVos = JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
- }
- try {
- fieldJson = CommonService.readJsonFile(tableName + ".json");
- } catch (Exception e) {
- throw new XiaoShiException("不存在此表");
- }
- List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
- if (fieldVOS == null) {
- throw new XiaoShiException("不存在此表");
- }
- Boolean flag = true;
- fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfShow())).collect(Collectors.toList());
- if (fieldVOS == null || fieldVOS.size() == 0) {
- throw new XiaoShiException("表中无字段");
- }
- //当tableName是patent时
- if (PatentDictionary.NAME.equals(tableName) && projectId != null && projectId != 0) {
- //获得所有自定义字段
- List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
- AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
- allCustomFieldVO.setName("标签");
- allCustomFieldVO.setId(0);
- allCustomFieldVO.setType(10);
- allCustomFieldVOS.add(allCustomFieldVO);
- if (allCustomFieldVOS.size() != 0) {
- for (AllCustomFieldVO item : allCustomFieldVOS) {
- PersonSelfFieldVO personSelfFieldVO = new PersonSelfFieldVO();
- personSelfFieldVO.setIfHidden(true);
- personSelfFieldVO.setName(item.getName());
- personSelfFieldVO.setType(item.getType().toString());
- personSelfFieldVO.setValue(item.getId().toString());
- personSelfFieldVO.setIfPersonal(true);
- personSelfFieldVO.setIfSort(false);
- personSelfFieldVO.setDefaultHidden(true);
- fieldVOS.add(personSelfFieldVO);
- }
- }
- }
- //装载顺序
- for (PersonSelfFieldVO item : fieldVOS) {
- PersonSelfFieldVO personSelfFieldVO = reFieldVos.stream().filter(t -> t.getValue().equals(item.getValue()) && t.getType().equals(item.getType())).findFirst().orElse(null);
- if (personSelfFieldVO == null) {
- if (StringUtils.isNotEmpty(json)) {
- item.setIfHidden(true);
- } else {
- if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
- item.setIfHidden(true);
- } else {
- item.setIfHidden(false);
- }
- }
- reFieldVos.add(item);
- }
- }
- return reFieldVos;
- }
- /**
- * 获得表格导出栏位
- * @param getTabelColumDTO
- * @return
- */
- public List<PersonSelfFieldVO> getTableExportColumns(GetTabelColumDTO getTabelColumDTO) {
- Integer projectId = getTabelColumDTO.getProjectId();
- String tableName = getTabelColumDTO.getTableName();
- Integer productId = getTabelColumDTO.getProductId();
- //根据登录人id和type查询
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String key = "";
- if (projectId == null) {
- if (productId != null) {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PRODUCT + RedisConf.SYMBOL_COLON + productId);
- } else {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
- }
- } else {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PROJECT + RedisConf.SYMBOL_COLON + projectId);
- }
- String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
- String json = redisUtil.get(redisKey);
- String fieldJson = "";
- //如果查到
- List<PersonSelfFieldVO> reFieldVos = new ArrayList<>();
- if (StringUtils.isNotEmpty(json)) {
- reFieldVos = JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
- }
- try {
- fieldJson = CommonService.readJsonFile(tableName + ".json");
- } catch (Exception e) {
- throw new XiaoShiException("不存在此表");
- }
- List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
- if (fieldVOS == null) {
- throw new XiaoShiException("不存在此表");
- }
- Boolean flag = true;
- fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIsExport())).collect(Collectors.toList());
- if (CollectionUtils.isEmpty(fieldVOS)) {
- throw new XiaoShiException("表中无字段");
- }
- //当tableName是patent时
- if (PatentDictionary.NAME.equals(tableName) && projectId != null && projectId != 0) {
- //获得所有自定义字段
- List<AllCustomFieldVO> allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
- AllCustomFieldVO allCustomFieldVO = new AllCustomFieldVO();
- allCustomFieldVO.setName("标签");
- allCustomFieldVO.setId(0);
- allCustomFieldVO.setType(10);
- allCustomFieldVOS.add(allCustomFieldVO);
- if (!CollectionUtils.isEmpty(allCustomFieldVOS)) {
- for (AllCustomFieldVO item : allCustomFieldVOS) {
- PersonSelfFieldVO personSelfFieldVO = new PersonSelfFieldVO();
- personSelfFieldVO.setIfHidden(true);
- personSelfFieldVO.setName(item.getName());
- personSelfFieldVO.setType(item.getType().toString());
- personSelfFieldVO.setValue(item.getId().toString());
- personSelfFieldVO.setIfPersonal(true);
- personSelfFieldVO.setIfSort(false);
- personSelfFieldVO.setDefaultHidden(true);
- fieldVOS.add(personSelfFieldVO);
- }
- }
- }
- //装载顺序
- for (PersonSelfFieldVO item : fieldVOS) {
- PersonSelfFieldVO personSelfFieldVO = reFieldVos.stream().filter(t -> t.getValue().equals(item.getValue()) && t.getType().equals(item.getType())).findFirst().orElse(null);
- if (personSelfFieldVO == null) {
- if (StringUtils.isNotEmpty(json)) {
- item.setIfHidden(true);
- } else {
- if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
- item.setIfHidden(true);
- } else {
- item.setIfHidden(false);
- }
- }
- reFieldVos.add(item);
- }
- }
- return reFieldVos;
- }
- public List<PersonSelfFieldVO> setTableColumns(AddSelfFieldDTO addSelfFieldDTO) {
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String tableName = addSelfFieldDTO.getTableName();
- Integer projectId = addSelfFieldDTO.getProjectId();
- Integer productId = addSelfFieldDTO.getProductId();
- List<PersonSelfFieldVO> personSelfFieldVOS = addSelfFieldDTO.getValue();
- personSelfFieldVOS = personSelfFieldVOS.stream().filter(item -> item.getIfHidden() != null && item.getIfHidden().equals(false)).collect(Collectors.toList());
- String key = "";
- if (projectId == null) {
- if (productId != null) {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PRODUCT + RedisConf.SYMBOL_COLON + productId);
- } else {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId);
- }
- } else {
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.PROJECT + RedisConf.SYMBOL_COLON + projectId);
- }
- String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
- redisUtil.set(redisKey, JsonUtils.objectToJson(personSelfFieldVOS));
- return personSelfFieldVOS;
- }
- /**
- * 查询所有的统计字段
- *
- * @param getAllPatentCountDTO
- * @return
- */
- public List<GetAllPatentCountVO> getAllCountColumns(GetAllPatentCountDTO getAllPatentCountDTO) {
- Integer taskId = getAllPatentCountDTO.getTaskId();
- Integer projectId = getAllPatentCountDTO.getProjectId();
- String fieldJson = "";
- //如果没查询到,则获取所有栏位添加到redis里
- try {
- fieldJson = CommonService.readJsonFile(PatentDictionary.NAME + ".json");
- } catch (Exception e) {
- throw new XiaoShiException("不存在此表");
- }
- Boolean flag = true;
- List<GetAllPatentCountVO> fieldVOS = JSON.parseArray(fieldJson, GetAllPatentCountVO.class);
- fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfStats())).collect(Collectors.toList());
- fieldVOS.forEach(item -> item.setFiledKind(-1));
- //当专题库id或者报告id不为null时
- if (taskId != null || projectId != null) {
- List<AllCustomFieldVO> allCustomFieldVOS = new ArrayList<>();
- if (taskId != null) {
- allCustomFieldVOS = customFieldService.getAllTaskCustomField(taskId);
- } else {
- allCustomFieldVOS = customFieldService.getAllProjectCustomField(projectId);
- }
- if (allCustomFieldVOS != null && allCustomFieldVOS.size() != 0) {
- //遍历查询出的自定义字段进行装载
- for (AllCustomFieldVO allCustomFieldVO : allCustomFieldVOS) {
- GetAllPatentCountVO getAllPatentCountVO = new GetAllPatentCountVO();
- //装载自定义字段的栏位值
- getAllPatentCountVO.setValue(allCustomFieldVO.getId().toString());
- //装载自定义栏位名
- getAllPatentCountVO.setName(allCustomFieldVO.getName());
- //装载栏位类型
- if (allCustomFieldVO.getType() <= 6) {
- getAllPatentCountVO.setFiledKind(0);
- switch (allCustomFieldVO.getType()) {
- case 0:
- getAllPatentCountVO.setType("Integer");
- break;
- case 1:
- getAllPatentCountVO.setType("DateTime");
- break;
- case 2:
- getAllPatentCountVO.setType("String");
- break;
- case 4:
- case 5:
- getAllPatentCountVO.setType("Array");
- break;
- case 6:
- getAllPatentCountVO.setType("tree");
- break;
- }
- } else {
- getAllPatentCountVO.setFiledKind(allCustomFieldVO.getType());
- getAllPatentCountVO.setType("tree");
- }
- fieldVOS.add(getAllPatentCountVO);
- }
- }
- }
- return fieldVOS;
- }
- /**
- * 查询显示的统计栏位
- *
- * @param getAllPatentCountDTO
- * @return
- */
- public List<GetAllPatentCountVO> getShowCountColumns(GetAllPatentCountDTO getAllPatentCountDTO) {
- Integer taskId = getAllPatentCountDTO.getTaskId();
- Integer projectId = getAllPatentCountDTO.getProjectId();
- //根据登录人id和type查询
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String key = "";
- if (taskId != null) {
- key = SecureUtil.md5(RedisConf.TASK_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + taskId);
- } else {
- key = SecureUtil.md5(RedisConf.PROJECT_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + projectId);
- }
- String json = redisUtil.get(RedisConf.FIELD_COUNT + RedisConf.SYMBOL_COLON + key);
- //如果查到
- if (StringUtils.isNotEmpty(json)) {
- return JsonUtils.jsonToList(json, GetAllPatentCountVO.class);
- }
- String fieldJson = "";
- //如果没查询到,则获取所有栏位添加到redis里
- try {
- fieldJson = CommonService.readJsonFile(PatentDictionary.NAME + ".json");
- } catch (Exception e) {
- throw new XiaoShiException("不存在此表");
- }
- Boolean flag = true;
- //查询栏位
- LambdaQueryWrapper<CustomField> queryWrapper =new LambdaQueryWrapper<>();
- queryWrapper.eq(CustomField::getProjectId,projectId)
- .eq(CustomField::getName,"监控周期")
- .eq(CustomField::getType,4);
- CustomField customField =customFieldService.getOne(queryWrapper,false);
- List<GetAllPatentCountVO> fieldVOS =new ArrayList<>();
- if(customField!=null){
- GetAllPatentCountVO getAllPatentCountVO =new GetAllPatentCountVO();
- getAllPatentCountVO.setType("Array");
- getAllPatentCountVO.setValue(customField.getId().toString());
- getAllPatentCountVO.setName(customField.getName());
- getAllPatentCountVO.setFiledKind(0);
- fieldVOS.add(getAllPatentCountVO);
- }
- List<GetAllPatentCountVO> fieldVOS2 = JSON.parseArray(fieldJson, GetAllPatentCountVO.class);
- fieldVOS2 = fieldVOS2.stream().filter(item -> flag.equals(item.getIfStats()) && flag.equals(item.getDefaultShowStats())).collect(Collectors.toList());
- fieldVOS2.forEach(item -> item.setFiledKind(-1));
- fieldVOS.addAll(fieldVOS2);
- redisUtil.set(RedisConf.FIELD_COUNT + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
- return fieldVOS;
- }
- /**
- * 查询显示的统计栏位
- *
- * @param addPatentCountDTO
- * @return
- */
- public List<GetAllPatentCountVO> setShowCountColumns(AddPatentCountDTO addPatentCountDTO) {
- Integer taskId = addPatentCountDTO.getTaskId();
- Integer projectId = addPatentCountDTO.getProjectId();
- //根据登录人id和type查询
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String key = "";
- if (taskId != null) {
- key = SecureUtil.md5(RedisConf.TASK_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + taskId);
- } else {
- key = SecureUtil.md5(RedisConf.PROJECT_FIELD_COUNT + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + projectId);
- }
- Boolean flag = true;
- List<GetAllPatentCountVO> fieldVOS = addPatentCountDTO.getValue();
- redisUtil.set(RedisConf.FIELD_COUNT + RedisConf.SYMBOL_COLON + key, JsonUtils.objectToJson(fieldVOS));
- return fieldVOS;
- }
- /**
- * 查询证据组合表头
- *
- * @param getTabelColumDTO
- * @return
- */
- public List<PersonSelfFieldVO> getEvidenceReasonTableColumns(GetTabelColumDTO getTabelColumDTO) {
- Integer projectId = getTabelColumDTO.getProjectId();
- String tableName = getTabelColumDTO.getTableName();
- if (tableName == null||tableName.equals("")) {
- tableName = "evidenceReason";
- }
- //根据登录人id和type查询
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String key = "";
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.EVIDENCE_REASON + RedisConf.SYMBOL_COLON + projectId);
- String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
- String json = redisUtil.get(redisKey);
- String fieldJson = "";
- //如果查到
- List<PersonSelfFieldVO> reFieldVos = new ArrayList<>();
- if (StringUtils.isNotEmpty(json)) {
- reFieldVos = JsonUtils.jsonToList(json, PersonSelfFieldVO.class);
- }
- try {
- fieldJson = CommonService.readJsonFile(tableName + ".json");
- } catch (Exception e) {
- throw new XiaoShiException("不存在此表");
- }
- List<PersonSelfFieldVO> fieldVOS = JSON.parseArray(fieldJson, PersonSelfFieldVO.class);
- if (fieldVOS == null) {
- throw new XiaoShiException("不存在此表");
- }
- Boolean flag = true;
- LambdaQueryWrapper<ReportProject> queryWrapper =new LambdaQueryWrapper<>();
- queryWrapper.eq(ReportProject::getProjectId,projectId);
- ReportProject reportProject =reportProjectService.getOne(queryWrapper,false);
- if(reportProject.getIfSecondInvalid()!=null&&reportProject.getIfSecondInvalid())
- {
- fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfShow()) || item.getType().equals("second")).collect(Collectors.toList());
- }
- else {
- fieldVOS = fieldVOS.stream().filter(item -> flag.equals(item.getIfShow())).collect(Collectors.toList());
- }
- if (fieldVOS == null || fieldVOS.size() == 0) {
- throw new XiaoShiException("表中无字段");
- }
- //装载顺序
- for (PersonSelfFieldVO item : fieldVOS) {
- if (StringUtils.isNotEmpty(json)) {
- PersonSelfFieldVO personSelfFieldVO = reFieldVos.stream().filter(t -> t.getValue().equals(item.getValue()) && t.getName().equals(item.getName())).findFirst().orElse(null);
- if (personSelfFieldVO == null) {
- item.setIfHidden(true);
- reFieldVos.add(item);
- }
- } else {
- if (item.getDefaultHidden() != null && item.getDefaultHidden().equals(true)) {
- item.setIfHidden(true);
- } else {
- item.setIfHidden(false);
- }
- reFieldVos.add(item);
- }
- }
- return reFieldVos;
- }
- public List<PersonSelfFieldVO> setEvidenceReasonTableColumns(AddSelfFieldDTO addSelfFieldDTO) {
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String userId = personnelVO.getId();
- String tableName = addSelfFieldDTO.getTableName();
- if (tableName == null||tableName.equals("")) {
- tableName = "evidenceReason";
- }
- Integer projectId = addSelfFieldDTO.getProjectId();
- List<PersonSelfFieldVO> personSelfFieldVOS = addSelfFieldDTO.getValue();
- personSelfFieldVOS = personSelfFieldVOS.stream().filter(item -> item.getIfHidden() != null && item.getIfHidden().equals(false)).collect(Collectors.toList());
- String key = "";
- key = SecureUtil.md5(tableName + RedisConf.SYMBOL_COLON + userId + RedisConf.SYMBOL_COLON + RedisConf.EVIDENCE_REASON + RedisConf.SYMBOL_COLON + projectId);
- String redisKey = RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key;
- redisUtil.set(redisKey, JsonUtils.objectToJson(personSelfFieldVOS));
- return personSelfFieldVOS;
- }
- }
|