|
@@ -0,0 +1,326 @@
|
|
|
+package cn.cslg.pas.service.business;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.dto.business.PatentProjectDTO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.*;
|
|
|
+import cn.cslg.pas.common.model.request.GroupRequest;
|
|
|
+import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
+import cn.cslg.pas.common.model.request.StringRequest;
|
|
|
+import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.vo.business.EventCountVO;
|
|
|
+import cn.cslg.pas.common.vo.business.EventVO;
|
|
|
+import cn.cslg.pas.domain.business.AssoEventFile;
|
|
|
+import cn.cslg.pas.domain.business.PatentProject;
|
|
|
+import cn.cslg.pas.domain.business.ReportProject;
|
|
|
+import cn.cslg.pas.domain.business.SystemDict;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
+import cn.cslg.pas.factorys.businessFactory.Business;
|
|
|
+import cn.cslg.pas.factorys.reGroupFactory.QueryGroupFactory;
|
|
|
+import cn.cslg.pas.factorys.reGroupFactory.QueryGroupImp;
|
|
|
+import cn.cslg.pas.mapper.AssoProjectEventMapper;
|
|
|
+import cn.cslg.pas.mapper.EventMapper;
|
|
|
+import cn.cslg.pas.mapper.PatentProjectMapper;
|
|
|
+import cn.cslg.pas.mapper.ReportProjectMapper;
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
+import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
+import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ReportProjectService extends ServiceImpl<ReportProjectMapper,ReportProject> implements Business {
|
|
|
+ @Autowired
|
|
|
+ private EventMapper eventMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FormatQueryService formatQueryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AssoEventFileService assoEventFileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QueryGroupFactory queryGroupFactory;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PermissionService permissionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SystemDictService systemDictService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AssoProjectEventMapper assoProjectEventMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CacheUtils cacheUtils;
|
|
|
+ @Autowired
|
|
|
+ private LoginUtils loginUtils;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
|
+
|
|
|
+ List<String> sqls = formatQueryService.reSqls(queryRequest,"event");
|
|
|
+ //根据sql查询事件信息
|
|
|
+ List<EventVO> eventVOS = eventMapper.getEvent(sqls.get(0),sqls.get(1),sqls.get(2));
|
|
|
+
|
|
|
+ //查询总数
|
|
|
+ Long total = eventMapper.getEventCount(sqls.get(0));
|
|
|
+
|
|
|
+ //装载事件信息
|
|
|
+ this.loadEvent(eventVOS);
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(queryRequest.getCurrent());
|
|
|
+ records.setSize(queryRequest.getSize());
|
|
|
+ records.setData(eventVOS);
|
|
|
+ records.setTotal(total);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Integer addMessage(Object object, List<MultipartFile> files) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Object deleteMessage(List<Integer> ids) throws IOException {
|
|
|
+ //根据事件id删除事件和文件关联
|
|
|
+ LambdaQueryWrapper<AssoEventFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(AssoEventFile::getEventId, ids);
|
|
|
+ List<AssoEventFile> assoEventFiles = assoEventFileService.list(queryWrapper);
|
|
|
+ List<String> guids = assoEventFiles.stream().map(AssoEventFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ // 根据guid删除文件
|
|
|
+ if (guids.size() != 0) {
|
|
|
+ fileManagerService.deleteFileFromFMS(guids);
|
|
|
+ }
|
|
|
+ //删除事件和文件关联表
|
|
|
+ assoEventFiles.remove(queryWrapper);
|
|
|
+ //根据事件id删除事件
|
|
|
+ this.removeBatchByIds(ids);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新事件接口
|
|
|
+ *
|
|
|
+ * @param object
|
|
|
+ * @param files
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询事件分组信息
|
|
|
+ *
|
|
|
+ * @param groupRequest
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Object getGroup(GroupRequest groupRequest,String tableName) throws Exception {
|
|
|
+ StringRequest stringRequest =new StringRequest();
|
|
|
+ BeanUtils.copyProperties(groupRequest,stringRequest);
|
|
|
+ List<String> sqls = formatQueryService.reSqls(stringRequest,tableName);
|
|
|
+ //格式化 分组
|
|
|
+ GroupConfig groupConfig=null;
|
|
|
+ if (groupRequest.getGroupBy() != null) {
|
|
|
+ String json = CommonService.readJsonFile(tableName+".json");
|
|
|
+ List<GroupConfig> groupConfigs = JSON.parseArray(json, GroupConfig.class);
|
|
|
+ groupConfig = groupConfigs.stream().filter(item -> groupRequest.getGroupBy().equals(item.getField())).findFirst().orElse(null);
|
|
|
+ if (groupConfig == null) {
|
|
|
+ throw new XiaoShiException("未找到配置");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回分组数据
|
|
|
+ QueryGroupImp queryGroupImp = queryGroupFactory.getClass(groupConfig.getGroupClass());
|
|
|
+ ReGroupDataVO reGroupDataVO = queryGroupImp.getGroup(sqls, tableName, groupConfig.getSqlField());
|
|
|
+
|
|
|
+ //装载数据
|
|
|
+ GroupVO groupVO = new GroupVO();
|
|
|
+ groupVO.setField(groupRequest.getGroupBy());
|
|
|
+ groupVO.setValues(reGroupDataVO.getValues());
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(groupRequest.getCurrent());
|
|
|
+ records.setSize(groupRequest.getSize());
|
|
|
+ records.setData(groupVO);
|
|
|
+ records.setTotal(reGroupDataVO.getTotal());
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object addMessage(Object object) {
|
|
|
+ PatentProjectDTO patentProjectDTO =(PatentProjectDTO)object;
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object updateMessage(Object object) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载事件返回类
|
|
|
+ *
|
|
|
+ * @param eventVOs
|
|
|
+ */
|
|
|
+ private void loadEvent(List<EventVO> eventVOs) throws IOException {
|
|
|
+ List<String> createIds = new ArrayList<>();
|
|
|
+ List<Integer> clientIds = new ArrayList<>();
|
|
|
+ List<Integer> ids = new ArrayList<>();
|
|
|
+ List<EventCountVO> eventCountVOS = new ArrayList<>();
|
|
|
+ //获得所有文件的guid
|
|
|
+ eventVOs.forEach(
|
|
|
+ item -> {
|
|
|
+ if (item.getClientId() != null) {
|
|
|
+ clientIds.add(item.getClientId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.getCreateId() != null) {
|
|
|
+ createIds.add(item.getCreateId());
|
|
|
+ }
|
|
|
+ if (item.getId() != null) {
|
|
|
+ ids.add(item.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ List<Personnel> personnels = new ArrayList<>();
|
|
|
+ List<Client> clients = new ArrayList<>();
|
|
|
+ List<String> guids = new ArrayList<>();
|
|
|
+ List<SystemFile> systemFiles = new ArrayList<>();
|
|
|
+ List<AssoEventFile> assoEventFiles = new ArrayList<>();
|
|
|
+
|
|
|
+ if (ids.size() != 0) {
|
|
|
+ //根据事件id获得事件文件关联表
|
|
|
+ LambdaQueryWrapper<AssoEventFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(AssoEventFile::getEventId, ids);
|
|
|
+ assoEventFiles = assoEventFileService.list(queryWrapper);
|
|
|
+ guids = assoEventFiles.stream().map(AssoEventFile::getFileGuid).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ //根据事件id分组查询事件关联专题库或报告数量
|
|
|
+ eventCountVOS = assoProjectEventMapper.getEventProjectCount(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询创建人名称
|
|
|
+ if (createIds.size() != 0) {
|
|
|
+ String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询客户名称
|
|
|
+ if (clientIds.size() != 0) {
|
|
|
+ String res = permissionService.getClientByIdsFromPCS(clientIds);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ clients = JSONObject.parseArray(jsonObject.getString("data"), Client.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询文件
|
|
|
+ if (guids.size() != 0) {
|
|
|
+ String res = fileManagerService.getSystemFileFromFMS(guids);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ systemFiles = JSONObject.parseArray(jsonObject.getString("data"), SystemFile.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询关联报告或专题库
|
|
|
+
|
|
|
+ //查询应用场景
|
|
|
+ List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList("ENTERPRISE_APPLICATION_SCENARIO"));
|
|
|
+
|
|
|
+ //查询专题库数量
|
|
|
+
|
|
|
+ //装载信息
|
|
|
+ for (EventVO eventVO : eventVOs) {
|
|
|
+ //装载人员信息
|
|
|
+ Personnel personnel = personnels.stream().filter(item -> item.getId().equals(eventVO.getCreateId())).findFirst().orElse(null);
|
|
|
+ if (personnel != null) {
|
|
|
+ eventVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载客户信息
|
|
|
+ Client client = clients.stream().filter(item -> item.getId().equals(eventVO.getClientId())).findFirst().orElse(null);
|
|
|
+ if (client != null) {
|
|
|
+ eventVO.setClientName(client.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载场景
|
|
|
+ SystemDict systemDict = systemDictList.stream().filter(item -> item.getValue().equals(eventVO.getScenarioId().toString())).findFirst().orElse(null);
|
|
|
+ if (systemDict != null) {
|
|
|
+ eventVO.setScenarioName(systemDict.getLabel());
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载文件信息
|
|
|
+ List<AssoEventFile> assoEventFileTemp = assoEventFiles.stream().filter(item -> item.getEventId().equals(eventVO.getId())).collect(Collectors.toList());
|
|
|
+ if (assoEventFileTemp.size() != 0) {
|
|
|
+ List<String> guidTemp = assoEventFileTemp.stream().map(AssoEventFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ if (guidTemp.size() != 0) {
|
|
|
+ List<SystemFile> systemFileTemp = systemFiles.stream().filter(item -> guidTemp.contains(item.getGuid())).collect(Collectors.toList());
|
|
|
+ if (systemFileTemp.size() != 0) {
|
|
|
+ eventVO.setSystemFileList(systemFileTemp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //装载专题库或报告数量
|
|
|
+ if (eventCountVOS.size() != 0) {
|
|
|
+ //专题库数量
|
|
|
+ EventCountVO eventCountVO1 = eventCountVOS.stream().filter(item ->
|
|
|
+ item.getEventId().equals(eventVO.getId()) && item.getProjectType().equals(1)).findFirst().orElse(null);
|
|
|
+
|
|
|
+ //报告数量
|
|
|
+ EventCountVO eventCountVO2 = eventCountVOS.stream().filter(item ->
|
|
|
+ item.getEventId().equals(eventVO.getId()) && item.getProjectType().equals(2)).findFirst().orElse(null);
|
|
|
+
|
|
|
+ //设置专题库数量
|
|
|
+ if (eventCountVO1 != null) {
|
|
|
+ eventVO.setPatentProjectNum(eventCountVO1.getProjectCount());
|
|
|
+ } else {
|
|
|
+ eventVO.setPatentProjectNum(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置报告数量
|
|
|
+ if (eventCountVO2 != null) {
|
|
|
+ eventVO.setReportProjectNum(eventCountVO2.getProjectCount());
|
|
|
+ } else {
|
|
|
+ eventVO.setReportProjectNum(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ eventVO.setReportProjectNum(0);
|
|
|
+ eventVO.setPatentProjectNum(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|