|
@@ -1,22 +1,35 @@
|
|
|
package cn.cslg.pas.service.business;
|
|
|
|
|
|
-import cn.cslg.pas.common.model.request.MapRequest;
|
|
|
-import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
-import cn.cslg.pas.common.model.request.StringRequest;
|
|
|
+import cn.cslg.pas.common.dto.business.EventDTO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.GroupConfig;
|
|
|
+import cn.cslg.pas.common.model.cronModel.GroupVO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.SqlObject;
|
|
|
+import cn.cslg.pas.common.model.request.*;
|
|
|
+
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
|
+import cn.cslg.pas.domain.business.AssoEventFile;
|
|
|
import cn.cslg.pas.domain.business.Event;
|
|
|
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.EventMapper;
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+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.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
@@ -25,6 +38,13 @@ public class EventService extends ServiceImpl<EventMapper, Event> implements Bu
|
|
|
private EventMapper eventMapper;
|
|
|
@Autowired
|
|
|
private FormatQueryService formatQueryService;
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
+ @Autowired
|
|
|
+ private AssoEventFileService assoEventFileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QueryGroupFactory queryGroupFactory;
|
|
|
public String getEvent(String sql){
|
|
|
eventMapper.getEvent(sql);
|
|
|
return "";
|
|
@@ -35,7 +55,6 @@ public class EventService extends ServiceImpl<EventMapper, Event> implements Bu
|
|
|
StringRequest stringRequest =null;
|
|
|
if(queryRequest instanceof MapRequest){
|
|
|
|
|
|
-
|
|
|
}
|
|
|
else {
|
|
|
stringRequest =(StringRequest)queryRequest;
|
|
@@ -65,20 +84,147 @@ public class EventService extends ServiceImpl<EventMapper, Event> implements Bu
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object addMessage(Object object, List<MultipartFile> files) {
|
|
|
+ public Integer addMessage(Object object, List<MultipartFile> files) {
|
|
|
+ EventDTO eventDTO =(EventDTO)object;
|
|
|
+ //检查事件格式 TODO
|
|
|
+ //根据名称查询是否重复
|
|
|
+ eventDTO.setName(eventDTO.getName().trim());
|
|
|
+ String name = eventDTO.getName();
|
|
|
+ LambdaQueryWrapper<Event> queryWrapper =new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Event::getName,name);
|
|
|
+ List<Event> events =this.list(queryWrapper);
|
|
|
+ if(events==null||events.size()==0){
|
|
|
return null;
|
|
|
}
|
|
|
+ Event event =new Event();
|
|
|
+ BeanUtils.copyProperties(eventDTO,event);
|
|
|
+ event.insert();
|
|
|
+ if (files != null && files.size() != 0)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ List<String> guids = fileManagerService.uploadFileGetGuid(files);
|
|
|
+ List<AssoEventFile> assoEventFiles =new ArrayList<>();
|
|
|
+ guids.forEach(item->{
|
|
|
+ AssoEventFile assoEventFile =new AssoEventFile();
|
|
|
+ assoEventFile.setEventId(event.getId());
|
|
|
+ assoEventFile.setFileGuid(item);
|
|
|
+ assoEventFile.setCreateId(1);
|
|
|
+ assoEventFiles.add(assoEventFile);
|
|
|
+ });
|
|
|
+ if(assoEventFiles!=null&&assoEventFiles.size()!=0){
|
|
|
+ assoEventFileService.saveBatch(assoEventFiles);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return event.getId();
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Object deleteMessage(List<Integer> ids) {
|
|
|
- return null;
|
|
|
+ //根据事件id删除事件
|
|
|
+ this.removeBatchByIds(ids);
|
|
|
+ //根据事件id删除事件和文件关联
|
|
|
+ LambdaQueryWrapper<AssoEventFile> queryWrapper =new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(AssoEventFile::getId,ids);
|
|
|
+ List<AssoEventFile> assoEventFiles =assoEventFileService.list(queryWrapper);
|
|
|
+ List<String> guids =assoEventFiles.stream().map(AssoEventFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ //TODO 根据guid删除文件
|
|
|
+ //删除事件和文件关联表
|
|
|
+ assoEventFiles.remove(queryWrapper);
|
|
|
+ return ids;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
|
- return null;
|
|
|
+ EventDTO eventDTO =(EventDTO)object;
|
|
|
+ //检查事件格式 TODO
|
|
|
+ //根据名称查询是否重复
|
|
|
+ eventDTO.setName(eventDTO.getName().trim());
|
|
|
+ String name = eventDTO.getName();
|
|
|
+ LambdaQueryWrapper<Event> queryWrapper =new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Event::getName,name);
|
|
|
+ List<Event> events =this.list(queryWrapper);
|
|
|
+ if(events==null||events.size()==0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Event event =new Event();
|
|
|
+ BeanUtils.copyProperties(eventDTO,event);
|
|
|
+ event.insert();
|
|
|
+ if (files != null && files.size() != 0)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ List<String> guids = fileManagerService.uploadFileGetGuid(files);
|
|
|
+ List<AssoEventFile> assoEventFiles =new ArrayList<>();
|
|
|
+ guids.forEach(item->{
|
|
|
+ AssoEventFile assoEventFile =new AssoEventFile();
|
|
|
+ assoEventFile.setEventId(event.getId());
|
|
|
+ assoEventFile.setFileGuid(item);
|
|
|
+ assoEventFile.setCreateId(1);
|
|
|
+ assoEventFiles.add(assoEventFile);
|
|
|
+ });
|
|
|
+ if(assoEventFiles!=null&&assoEventFiles.size()!=0){
|
|
|
+ assoEventFileService.saveBatch(assoEventFiles);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return event.getId();
|
|
|
}
|
|
|
|
|
|
- ;
|
|
|
+ public GroupVO getGroup(GroupRequest groupRequest) throws Exception {
|
|
|
+ //合成检索式
|
|
|
+ StringGroupRequest stringGroupRequest =null;
|
|
|
+ if(groupRequest instanceof MapGroupRequest){
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ stringGroupRequest =(StringGroupRequest)groupRequest;
|
|
|
+ }
|
|
|
+ String condition =stringGroupRequest.getSearchQuery();
|
|
|
+
|
|
|
+ //将检索式转换为二叉树
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
+
|
|
|
+ //格式化检索式
|
|
|
+ String sql = formatQueryService.ToString((operateNode) tree);
|
|
|
+
|
|
|
+ //格式化 分组
|
|
|
+ String json = CommonService.readJsonFile("event_group.json");
|
|
|
+ List<GroupConfig> groupConfigs = JSON.parseArray(json,GroupConfig.class);
|
|
|
+ GroupConfig groupConfig = groupConfigs.stream().filter(item->item.getField().equals(groupRequest.getGroupBy())).findFirst().orElse(null);
|
|
|
+ if(groupConfig!=null){
|
|
|
+ sql+=" group by "+groupConfig.getSqlField()+" ";
|
|
|
+ }
|
|
|
+
|
|
|
+ //格式化排序
|
|
|
+ if(groupRequest.getOrderDTOList()!=null&&groupRequest.getOrderDTOList().size()!=0) {
|
|
|
+ String orderSql = formatQueryService.orderToString(groupRequest.getOrderDTOList());
|
|
|
+ sql+=orderSql;
|
|
|
+ }
|
|
|
+
|
|
|
+ //格式化 分页信息
|
|
|
+ if(groupRequest.getSize()!=null&&groupRequest.getCurrent()!=null) {
|
|
|
+ Long size =groupRequest.getSize();
|
|
|
+ Long current =groupRequest.getCurrent();
|
|
|
+ String page= " limit "+((current-1)*size)+","+size;
|
|
|
+ sql +=page;
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回分组数据
|
|
|
+ QueryGroupImp queryGroupImp = queryGroupFactory.getClass(groupConfig.getGroupClass());
|
|
|
+ List<String> strs = queryGroupImp.getGroup(sql,"event",groupConfig.getSqlField());
|
|
|
+
|
|
|
+ //装载数据
|
|
|
+ GroupVO groupVO =new GroupVO();
|
|
|
+ groupVO.setField(groupRequest.getGroupBy());
|
|
|
+ groupVO.setValues(strs);
|
|
|
+ return groupVO;
|
|
|
+ }
|
|
|
|
|
|
}
|