|
@@ -0,0 +1,354 @@
|
|
|
+package com.zkqy.business.service.impl;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import com.zkqy.business.domain.vo.DataAcquisitionInformationVo;
|
|
|
+import com.zkqy.business.domain.vo.DataAcquisitionInformationVoTwo;
|
|
|
+import com.zkqy.common.core.domain.AjaxResult;
|
|
|
+import com.zkqy.common.core.domain.entity.DataSource;
|
|
|
+import com.zkqy.common.core.domain.entity.SysTenant;
|
|
|
+import com.zkqy.common.core.domain.entity.SysUser;
|
|
|
+import com.zkqy.common.core.domain.model.LoginUser;
|
|
|
+import com.zkqy.common.utils.DateUtils;
|
|
|
+import com.zkqy.common.utils.SecurityUtils;
|
|
|
+import com.zkqy.common.utils.bpm.XmlDataParserUtils;
|
|
|
+import com.zkqy.execution.produce.dispersed.entity.CommonEntity;
|
|
|
+import com.zkqy.execution.produce.dispersed.entity.runbpm.BpmRunNodeVo;
|
|
|
+import com.zkqy.execution.produce.dispersed.mapper.CommonMapper;
|
|
|
+import com.zkqy.execution.produce.dispersed.runbpm.PreExecutionToolClass;
|
|
|
+import com.zkqy.execution.produce.dispersed.service.impl.CommonServiceImpl;
|
|
|
+import com.zkqy.framework.security.context.AuthenticationContextHolder;
|
|
|
+import com.zkqy.framework.security.context.ThreadLocalUtil;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.springframework.aop.framework.AopContext;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.authentication.AuthenticationManager;
|
|
|
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
+import org.springframework.security.core.userdetails.UserDetails;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.zkqy.business.mapper.DataAcquisitionInformationMapper;
|
|
|
+import com.zkqy.business.domain.DataAcquisitionInformation;
|
|
|
+import com.zkqy.business.service.IDataAcquisitionInformationService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.sound.sampled.Port;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 数据采集信息Service业务层处理
|
|
|
+ *
|
|
|
+ * @author zkqy
|
|
|
+ * @date 2024-03-22
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DataAcquisitionInformationServiceImpl implements IDataAcquisitionInformationService
|
|
|
+{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataAcquisitionInformationMapper dataAcquisitionInformationMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonServiceImpl commonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonMapper commonMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PreExecutionToolClass ipreExecutionToolClass;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AuthenticationManager authenticationManager;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询数据采集信息
|
|
|
+ *
|
|
|
+ * @param id 数据采集信息主键
|
|
|
+ * @return 数据采集信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public DataAcquisitionInformation selectDataAcquisitionInformationById(Long id)
|
|
|
+ {
|
|
|
+ return dataAcquisitionInformationMapper.selectDataAcquisitionInformationById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DataAcquisitionInformation selectDataAcquisitionInformationByTaskId(String taskId) {
|
|
|
+ return dataAcquisitionInformationMapper.selectDataAcquisitionInformationByTaskId(taskId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询数据采集信息列表
|
|
|
+ *
|
|
|
+ * @param dataAcquisitionInformation 数据采集信息
|
|
|
+ * @return 数据采集信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<DataAcquisitionInformation> selectDataAcquisitionInformationList(DataAcquisitionInformation dataAcquisitionInformation)
|
|
|
+ {
|
|
|
+ return dataAcquisitionInformationMapper.selectDataAcquisitionInformationList(dataAcquisitionInformation);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增数据采集信息
|
|
|
+ *
|
|
|
+ * @param dataAcquisitionInformation 数据采集信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertDataAcquisitionInformation(DataAcquisitionInformation dataAcquisitionInformation)
|
|
|
+ {
|
|
|
+ dataAcquisitionInformation.setCreateTime(DateUtils.getNowDate());
|
|
|
+ dataAcquisitionInformation.setCreateById(SecurityUtils.getUserId());
|
|
|
+ dataAcquisitionInformation.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ return dataAcquisitionInformationMapper.insertDataAcquisitionInformation(dataAcquisitionInformation);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改数据采集信息
|
|
|
+ *
|
|
|
+ * @param dataAcquisitionInformation 数据采集信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateDataAcquisitionInformation(DataAcquisitionInformation dataAcquisitionInformation)
|
|
|
+ {
|
|
|
+ dataAcquisitionInformation.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ dataAcquisitionInformation.setUpdateById(SecurityUtils.getUserId());
|
|
|
+ dataAcquisitionInformation.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ return dataAcquisitionInformationMapper.updateDataAcquisitionInformation(dataAcquisitionInformation);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除数据采集信息
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的数据采集信息主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteDataAcquisitionInformationByIds(Long[] ids)
|
|
|
+ {
|
|
|
+ return dataAcquisitionInformationMapper.deleteDataAcquisitionInformationByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据采集信息信息
|
|
|
+ * @param id 数据采集信息主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteDataAcquisitionInformationById(Long id)
|
|
|
+ {
|
|
|
+ return dataAcquisitionInformationMapper.deleteDataAcquisitionInformationById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult updateOrAddDataAcquisitionInformation(DataAcquisitionInformationVo dataAcquisitionInformationVo) {
|
|
|
+ //1、没有数采信息就是入
|
|
|
+ DataAcquisitionInformation dataAcquisitionInformation = this.selectDataAcquisitionInformationByTaskId(dataAcquisitionInformationVo.getTaskId());
|
|
|
+ if(dataAcquisitionInformation!=null){//有数采数据就更新
|
|
|
+ dataAcquisitionInformationMapper.updateDataAcquisitionInformationByTaskId(dataAcquisitionInformationVo);
|
|
|
+ //修改库存表信息
|
|
|
+ CommonEntity common = this.updateAndAdd(dataAcquisitionInformationVo,false);
|
|
|
+ int edit = commonService.edit(common);
|
|
|
+ if(edit>0){
|
|
|
+ return AjaxResult.success("刷新库存信息成功");
|
|
|
+ }
|
|
|
+ return AjaxResult.success("网络出现问题,刷新数据失败");
|
|
|
+ }else {
|
|
|
+ this.insertDataAcquisitionInformation(dataAcquisitionInformationVo);
|
|
|
+ //新增库存信息
|
|
|
+ CommonEntity common = this.updateAndAdd(dataAcquisitionInformationVo,true);
|
|
|
+ int insert = commonService.batchInsert(common);
|
|
|
+ if(insert>0){
|
|
|
+ return AjaxResult.success("插入库存信息成功");
|
|
|
+ }
|
|
|
+ return AjaxResult.success("网络出现问题,刷新数据失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult updateOrAddDataAcquisitionInformation2(DataAcquisitionInformationVoTwo dITwo) {
|
|
|
+ DataAcquisitionInformationServiceImpl impl = (DataAcquisitionInformationServiceImpl)AopContext.currentProxy();;
|
|
|
+ //1、先查询计划表信息
|
|
|
+ HashMap hashMap=new HashMap();
|
|
|
+ hashMap.put("task_id",dITwo.getTaskId());
|
|
|
+ //考虑到一个问题,这个接口如果匿名访问的话势必从登录用户中拿不到所谓的数据源头信息
|
|
|
+ //处理没有登录的情况下sql不能拼接的问题
|
|
|
+ HashMap hashMapSource=new HashMap();
|
|
|
+ hashMapSource.put("databaseType","mysql");
|
|
|
+ hashMapSource.put("dbName","jiaoyu");
|
|
|
+
|
|
|
+ LoginUser userDetails=new LoginUser();
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ SysTenant sysTenant=new SysTenant();
|
|
|
+ sysTenant.setTenantId(181L);
|
|
|
+ sysTenant.setTenantName("jiaoyu");
|
|
|
+ sysTenant.setTenantCode("jiaoyu01");
|
|
|
+ DataSource dataSource = new DataSource();
|
|
|
+ dataSource.setDatabaseName("jiaoyu");
|
|
|
+ dataSource.setDatabaseType("mysql");
|
|
|
+ sysTenant.setDataSource(dataSource);
|
|
|
+ sysUser.setTenant(sysTenant);
|
|
|
+ userDetails.setUser(sysUser);
|
|
|
+ userDetails.setUserId(282L);
|
|
|
+ userDetails.setTenantId(181L);
|
|
|
+
|
|
|
+ // 创建一个Authentication对象
|
|
|
+ Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, Collections.emptyList());
|
|
|
+ // 将Authentication对象设置到SecurityContext中
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
+ SecurityUtils.getUserId();
|
|
|
+ SecurityUtils.getLoginUser();
|
|
|
+
|
|
|
+ ThreadLocalUtil.setThreadLocalValue(hashMapSource);
|
|
|
+ List<CommonEntity> scheduleTable = commonMapper.selectList("schedule_table", hashMap);
|
|
|
+ if(scheduleTable.size()>0){
|
|
|
+ //有个计划--得到投产数量
|
|
|
+ String productQuantity = scheduleTable.get(0).getResultMap().get("productQuantity").toString();
|
|
|
+ //如果不合格数量==入库数量
|
|
|
+ Integer total= Integer.parseInt(dITwo.getUnqualified())+Integer.parseInt(dITwo.getInStock());
|
|
|
+ //正常更新数据采集信息And库存信息
|
|
|
+ DataAcquisitionInformation dataAcquisitionInformation = this.selectDataAcquisitionInformationByTaskId(dITwo.getTaskId());
|
|
|
+ //先转换一个更新要用的Vo
|
|
|
+ DataAcquisitionInformationVo dataAcquisitionInformationVo = new DataAcquisitionInformationVo();
|
|
|
+ dataAcquisitionInformationVo.setInventoryQuantity(dITwo.getInStock());//入库数量
|
|
|
+ dataAcquisitionInformationVo.setStockNumber(dITwo.getTaskId());//计划编号--当入库项目
|
|
|
+ dataAcquisitionInformationVo.setProductName(scheduleTable.get(0).getResultMap().get("taskName").toString());//任务名称
|
|
|
+ BeanUtils.copyProperties(dITwo,dataAcquisitionInformationVo);
|
|
|
+ //证明有数据采集信息
|
|
|
+ int i;
|
|
|
+ if(dataAcquisitionInformation!=null){
|
|
|
+ i = dataAcquisitionInformationMapper.updateDataAcquisitionInformationByTaskId(dataAcquisitionInformationVo);
|
|
|
+ if(Integer.parseInt(dITwo.getInStock())>0){
|
|
|
+ //通用的修改方法
|
|
|
+ CommonEntity common = impl.updateAndAdd(dataAcquisitionInformationVo,false);
|
|
|
+ //每次更新或者插入的时候就看看、质检不合格数量+入库数量是否等于计划数量
|
|
|
+ if(productQuantity.equals(total.toString())){
|
|
|
+ //执行关闭流程方法
|
|
|
+ impl.executeProcess(scheduleTable,dITwo);
|
|
|
+ }
|
|
|
+ return commonService.editNoUserInfo(common)>0?AjaxResult.success("数采数据推送成功"):AjaxResult.success("网络出现问题请稍后再试,刷新数据失败");
|
|
|
+ }
|
|
|
+ //没有数据采集信息
|
|
|
+ }else {
|
|
|
+ i = dataAcquisitionInformationMapper.insertDataAcquisitionInformation(dataAcquisitionInformationVo);
|
|
|
+ if(Integer.parseInt(dITwo.getInStock())>0){
|
|
|
+ //通用的新增
|
|
|
+ CommonEntity common = impl.updateAndAdd(dataAcquisitionInformationVo,true);
|
|
|
+ //每次更新或者插入的时候就看看、质检不合格数量+入库数量是否等于计划数量
|
|
|
+ if(productQuantity.equals(total)){
|
|
|
+ impl.executeProcess(scheduleTable,dITwo);
|
|
|
+ }
|
|
|
+ return commonService.batchInsertNoUserInfo(common)>0?AjaxResult.success("数采数据推送成功"):AjaxResult.success("网络出现问题请稍后再试,刷新数据失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ThreadLocalUtil.removeThreadLocalValue();
|
|
|
+ return i>0?AjaxResult.success("数采数据推送成功"):AjaxResult.success("网络出现问题请稍后再试");
|
|
|
+ }else {
|
|
|
+ return AjaxResult.success("未有此计划的采集数据信息请核对数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public AjaxResult executeProcess(List<CommonEntity> scheduleTable,DataAcquisitionInformationVoTwo dITwo) {
|
|
|
+ //1、先查询计划表信息
|
|
|
+// HashMap hashMap = new HashMap();
|
|
|
+// hashMap.put("task_id", dITwo.getTaskId());
|
|
|
+ //根据任务id查询流程信息 1、方案一:直接改流程的执行状态(①入库节点②共同结束脚本也要走) 2、方案二:模拟入库节点结束后,后边的自动结束
|
|
|
+ //根据计划id查询流程执行日志信息 bpm_execute_process
|
|
|
+ HashMap executeProcess = new HashMap();
|
|
|
+ executeProcess.put("task_plan_key", scheduleTable.get(0).getResultMap().get("id").toString());
|
|
|
+ List<CommonEntity> bpmExecuteProcess = commonMapper.selectList("bpm_execute_process", executeProcess);
|
|
|
+ if (bpmExecuteProcess.size() > 0) {
|
|
|
+ //当前节点
|
|
|
+ String taskNodeKey = bpmExecuteProcess.get(0).getResultMap().get("taskNodeKey").toString();
|
|
|
+ //下一个任务节点
|
|
|
+ String taskNodeNextKey = bpmExecuteProcess.get(0).getResultMap().get("taskNodeNextKey").toString();
|
|
|
+ //流程图xml文件
|
|
|
+ String taskProcessXmlContent = bpmExecuteProcess.get(0).getResultMap().get("taskProcessXmlContent").toString();
|
|
|
+ //流程任务执行别名
|
|
|
+ String task_key = bpmExecuteProcess.get(0).getResultMap().get("taskKey").toString();
|
|
|
+ //查询脚本key
|
|
|
+ String taskScriptKey = "";
|
|
|
+ HashMap hashMap1 = new HashMap();
|
|
|
+ hashMap1.put("task_process_key", task_key);
|
|
|
+ hashMap1.put("task_node_key", taskNodeKey);
|
|
|
+ List<CommonEntity> bpmExecuteNodeForm = commonMapper.selectList("bpm_execute_node_form", hashMap1);
|
|
|
+ if (bpmExecuteNodeForm.size() > 0) {
|
|
|
+ taskScriptKey = bpmExecuteNodeForm.get(0).getResultMap().get("taskScriptKey").toString();
|
|
|
+ } else {
|
|
|
+ AjaxResult.success("未找到关联的节点脚本");
|
|
|
+ }
|
|
|
+ //查询节点类型
|
|
|
+ HashMap hashMap2 = new HashMap();
|
|
|
+ hashMap2.put("task_process_key", task_key);
|
|
|
+ hashMap2.put("task_node_key", taskNodeKey);
|
|
|
+ String taskType = "";
|
|
|
+ List<CommonEntity> bpmExecuteNode = commonMapper.selectList("bpm_execute_node", hashMap2);
|
|
|
+ if (bpmExecuteNode.size() > 0) {
|
|
|
+ taskType = bpmExecuteNode.get(0).getResultMap().get("taskNodeType").toString();
|
|
|
+ } else {
|
|
|
+ AjaxResult.success("未找到节点的类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据准备齐全开始构造执行流程
|
|
|
+ BpmRunNodeVo bpmRunNodeVo = new BpmRunNodeVo();
|
|
|
+ bpmRunNodeVo.setTaskProcessXmlContent(taskProcessXmlContent);//流程文件
|
|
|
+ bpmRunNodeVo.setTaskProcessKey(task_key);//流程任务执行的别名
|
|
|
+ bpmRunNodeVo.setTaskNodeKey(taskNodeNextKey);//下一个节点--就是当前要执行的节点
|
|
|
+ String nextNodeKey = XmlDataParserUtils.getNextNodeKey(taskProcessXmlContent, taskNodeNextKey);
|
|
|
+ bpmRunNodeVo.setNextNodeKey(nextNodeKey);//下一个任务节点
|
|
|
+ bpmRunNodeVo.setImplementationName(taskScriptKey);//脚本key
|
|
|
+ bpmRunNodeVo.setTableName("");//表名
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
+ stringObjectHashMap.put("taskPlanKey", dITwo.getTaskId());
|
|
|
+ bpmRunNodeVo.setFormDataMap(stringObjectHashMap);//表名
|
|
|
+ bpmRunNodeVo.setTaskNodeType(taskType);
|
|
|
+ //执行流程
|
|
|
+ ipreExecutionToolClass.executionNode(bpmRunNodeVo);
|
|
|
+ return AjaxResult.success("流程执行成功");
|
|
|
+ }else {
|
|
|
+ return AjaxResult.success("未有此流程执行信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ public CommonEntity updateAndAdd( DataAcquisitionInformationVo dataAcquisitionInformationVo,boolean flag){
|
|
|
+ //修改库存表信息
|
|
|
+ CommonEntity commonEntity= getCommonEntity();
|
|
|
+ HashMap basicMap=new HashMap();
|
|
|
+ basicMap.put("tableName","inventory");
|
|
|
+ commonEntity.setBasicMap(basicMap);
|
|
|
+ HashMap conditions=new HashMap();
|
|
|
+ conditions.put("stock_number",dataAcquisitionInformationVo.getStockNumber());
|
|
|
+ commonEntity.setConditionMap(conditions);
|
|
|
+ if(flag){
|
|
|
+ //构造要添加的数据;
|
|
|
+ HashMap<String,String> mapRs=new HashMap();
|
|
|
+ mapRs.put("stock_number",dataAcquisitionInformationVo.getStockNumber());
|
|
|
+ mapRs.put("product_name",dataAcquisitionInformationVo.getProductName());
|
|
|
+ mapRs.put("inventory_quantity",dataAcquisitionInformationVo.getInventoryQuantity());
|
|
|
+ List<Map<String,String>> mapList=new ArrayList<>();
|
|
|
+ mapList.add(mapRs);
|
|
|
+ commonEntity.setAddListMap(mapList);
|
|
|
+ }else {
|
|
|
+ //构造要添加的数据;
|
|
|
+ HashMap<String,Object> mapRs=new HashMap();
|
|
|
+ mapRs.put("stock_number",dataAcquisitionInformationVo.getStockNumber());
|
|
|
+ mapRs.put("product_name",dataAcquisitionInformationVo.getProductName());
|
|
|
+ mapRs.put("inventory_quantity",dataAcquisitionInformationVo.getInventoryQuantity());
|
|
|
+ commonEntity.setCommMap(mapRs);
|
|
|
+ }
|
|
|
+ return commonEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private static CommonEntity getCommonEntity() {
|
|
|
+ return new CommonEntity();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|