123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- package com.yihu.hos.system.service;
- import com.yihu.hos.common.constants.Constants;
- import com.yihu.hos.core.file.FileUtil;
- import com.yihu.hos.services.ServiceFlowEventService;
- import com.yihu.hos.system.dao.FlowClassDao;
- import com.yihu.hos.system.dao.FlowTempDao;
- import com.yihu.hos.system.dao.intf.IFlowClassDao;
- import com.yihu.hos.system.dao.intf.IFlowDao;
- import com.yihu.hos.system.dao.intf.IFlowTempDao;
- import com.yihu.hos.system.model.SystemServiceFlow;
- import com.yihu.hos.system.model.SystemServiceFlowClass;
- import com.yihu.hos.system.model.SystemServiceFlowTemp;
- import com.yihu.hos.system.service.intf.IFlowManage;
- import com.yihu.hos.web.framework.model.DictItem;
- import com.yihu.hos.web.framework.model.DictionaryResult;
- import com.yihu.hos.web.framework.model.Result;
- 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 javax.annotation.Resource;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- /**
- * 系统流程管理业务类
- *
- * @author HZY
- * @vsrsion 1.0
- * Created at 2016/8/19.
- */
- @Service("flowManager")
- public class FlowManager implements IFlowManage {
- public static final String BEAN_ID = "flowManager";
- @Resource(name = "flowDao")
- private IFlowDao flowDao;
- @Resource(name = FlowClassDao.BEAN_ID)
- private IFlowClassDao flowClassDao;
- @Resource(name = FlowTempDao.BEAN_ID)
- private IFlowTempDao flowTempDao;
- @Autowired
- ServiceFlowEventService serviceFlowEventService;
- @Override
- public Result getFlowList(Map<String, Object> params) throws Exception {
- return flowDao.getFlowList(params);
- }
- @Override
- public SystemServiceFlow getFlowById(Integer id) throws Exception {
- return flowDao.getEntity(SystemServiceFlow.class, id);
- }
- @Transactional
- public Result addFlow(SystemServiceFlow obj) throws Exception {
- obj.setCreateDate(new Date());
- flowDao.saveEntity(obj);
- if (Constants.CLASS.equals(obj.getFileType())){
- List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
- for (SystemServiceFlowClass flowClass:flowClassList){
- flowClass.setFlowId(obj.getId());
- flowDao.saveEntity(flowClass);
- //发送消息到MQ对列
- sendUpdateMessage(obj.getCode(), flowClass, Constants.FLOW_OP_ADD);
- }
- }else if (Constants.JAVA.equals(obj.getFileType())){
- List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
- for (SystemServiceFlowTemp flowTemp:flowTempList){
- flowTemp.setFlowId(obj.getId());
- flowDao.saveEntity(flowTemp);
- }
- }
- return Result.success("保存成功");
- }
- @Transactional
- public Result updateFlow(SystemServiceFlow obj) throws Exception {
- SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, obj.getId());
- flow.setCode(obj.getCode());
- flow.setName(obj.getName());
- flow.setPath(obj.getPath());
- flow.setChart(obj.getChart());
- flow.setValid(obj.getValid());
- flow.setFileType(obj.getFileType());
- if (Constants.JAVA.equals(flow.getFileType())){
- List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
- boolean succ = flowTempDao.deleteFlowTempByFlowId(obj.getId());
- if (succ){
- for (SystemServiceFlowTemp flowTemp:flowTempList){
- flowTempDao.saveEntity(flowTemp);
- }
- }
- }else if (Constants.CLASS.equals(flow.getFileType())){
- List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
- List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
- for (SystemServiceFlowClass flowClass:flowClassList){
- if (flowClass.getId()!=null) {
- classIds.remove(flowClass.getId());
- flowClassDao.updateEntity(flowClass);
- sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
- }else {
- flowClassDao.saveEntity(flowClass);
- sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
- }
- }
- //删除判断
- if (classIds !=null && classIds.size()>0){
- for (Integer id:classIds){
- SystemServiceFlowClass flowClass = getFlowClassById(id);
- flowClassDao.deleteEntity(flowClass);
- sendDeleteMessage(flow.getCode(), flowClass);
- }
- }
- }
- flowDao.updateEntity(flow);
- return Result.success("更新成功");
- }
- @Transactional
- public Result deleteFlow(Integer id) throws Exception {
- SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, id);
- List<SystemServiceFlowClass> flowClassList = flowClassDao.getFlowClassByFlowId(id);
- for (SystemServiceFlowClass flowClass:flowClassList){
- flowClassDao.deleteEntity(flowClass);
- //发送消息到MQ对列
- sendDeleteMessage(flow.getCode(), flowClass);
- }
- boolean succ = flowTempDao.deleteFlowTempByFlowId(id);
- flowDao.deleteEntity(flow);
- return Result.success("删除成功");
- }
- /* =================================== flowClass 部分================================================*/
- @Override
- public Result getFlowClassList(Map<String, Object> params) throws Exception {
- return null;
- }
- @Override
- public List<SystemServiceFlowClass> getFlowClassByFlowId(Integer flowId) throws Exception {
- return flowClassDao.getFlowClassByFlowId(flowId);
- }
- public SystemServiceFlowClass getFlowClassById(Integer id) throws Exception {
- return flowClassDao.getEntity(SystemServiceFlowClass.class,id);
- }
- @Transactional
- public Result addFlowClass(SystemServiceFlowClass obj) throws Exception {
- flowDao.saveEntity(obj);
- return Result.success("保存成功");
- }
- @Transactional
- public Result updateFlowClass(SystemServiceFlowClass obj) throws Exception {
- return null;
- }
- @Transactional
- public boolean deleteFlowClassByFlowId(Integer flowId) {
- boolean succ =flowClassDao.deleteFlowClassByFlowId(flowId);
- return succ;
- }
- @Override
- public List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer id) throws Exception {
- return flowTempDao.getFlowTempByFlowId(id);
- }
- @Override
- public String uploadFile(MultipartFile file, String baseSavePath) {
- String fileName = file.getOriginalFilename();
- boolean succ = false;
- try {
- succ = FileUtil.writeFile(baseSavePath +"/"+ fileName, file.getBytes(), "utf-8");
- if (succ){
- return fileName;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 发送MQ消息-更新路由
- * @param flowCode 服务流程Code标识
- * @param flowClass
- * @param operate
- */
- public void sendUpdateMessage(String flowCode,SystemServiceFlowClass flowClass,String operate){
- //发送消息到MQ对列
- if ("1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_ROUTE.equals(flowClass.getType())) {
- //route
- switch (operate){
- case "add" : serviceFlowEventService.routeDefineAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
- case "delete" : serviceFlowEventService.routeDefineDelete(flowCode, flowClass.getPackageName(), flowClass.getClassName()); break;
- case "update" : serviceFlowEventService.routeDefineChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
- default : break;
- }
- } else if ( "1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
- //processor
- switch (operate){
- case "add" : serviceFlowEventService.processorAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
- case "delete" : serviceFlowEventService.processorDataDeleted(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
- case "update" : serviceFlowEventService.processorDataChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
- default : break;
- }
- }
- }
- /**
- * 发送MQ消息-删除路由
- * @param flowCode 服务流程Code标识
- * @param flowClass
- */
- public void sendDeleteMessage(String flowCode,SystemServiceFlowClass flowClass){
- //发送消息到MQ对列
- if ( Constants.FLOW_TYPE_ROUTE.equals(flowClass.getType())) {
- //route
- serviceFlowEventService.routeDefineDelete(flowCode, flowClass.getPackageName(), flowClass.getClassName());
- } else if (Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
- //processor
- serviceFlowEventService.processorDataDeleted(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath());
- }
- }
- /**
- * 获取流程列表
- * @param type 流程的文件类型
- * @return
- * @throws Exception
- */
- @Override
- public DictionaryResult getFlowList(String type) throws Exception {
- List<SystemServiceFlow> flowList = flowDao.getFlowList(type);
- DictionaryResult re = new DictionaryResult("FLOW_LIST");
- if(flowList!=null&&flowList.size()>0)
- {
- List<DictItem> dictList = new ArrayList<>();
- for(SystemServiceFlow item:flowList){
- DictItem dict = new DictItem();
- dict.setCode(item.getId().toString());
- dict.setValue(item.getName());
- dict.setExtend("");
- dictList.add(dict);
- }
- re.setDetailModelList(dictList);
- }
- return re;
- }
- }
|