| | |
| | | package com.highdatas.mdm.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.mapper.SysAssembleMapper; |
| | | import com.highdatas.mdm.mapper.TableInfoMapper; |
| | |
| | | import com.highdatas.mdm.pojo.kettle.DataSourceInfo; |
| | | import com.highdatas.mdm.pojo.kettle.UnBigDataDataSourceInfo; |
| | | import com.highdatas.mdm.service.*; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.ContentBuilder; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import lombok.Data; |
| | | import com.highdatas.mdm.util.RuleClient; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.ibatis.session.SqlSession; |
| | | import org.apache.regexp.RE; |
| | | import org.mybatis.spring.SqlSessionTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | |
| | | BigDataDataSourceInfo bigDataDataSourceInfo; |
| | | @Autowired |
| | | MasterDataService masterDataService; |
| | | |
| | | @Autowired |
| | | ITUserService userService; |
| | | @Autowired |
| | | RuleClient ruleClient; |
| | | @Autowired |
| | | IMasterModifiedService masterModifiedService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public Result run(String id, HttpSession session) { |
| | | public Result run(String id) { |
| | | if (StringUtils.isEmpty(id)) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | |
| | | if (assemble == null) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | assemble.setPreTime(new Date()); |
| | | assemble.setPreStatus(SysAssembleRunStatus.working); |
| | | assemble.updateById(); |
| | | |
| | | if (!assemble.getStatus().equals(SysAssembleStatus.working)) { |
| | | assemble.setPreStatus(SysAssembleRunStatus.fail); |
| | | assemble.setPreCnt(0); |
| | | assemble.setPreMsg("当前任务不在工作中,状态:" + assemble.getStatus()); |
| | | assemble.updateById(); |
| | | return Result.error(new CodeMsg(6009,"当前任务不在工作中,状态:" + assemble.getStatus())); |
| | | |
| | | } |
| | | |
| | | String flowId = assemble.getFlowId(); |
| | |
| | | if (flows != null) { |
| | | ActivitiStatus status = flows.getStatus(); |
| | | if (!status.equals(ActivitiStatus.close) && !status.equals(ActivitiStatus.open)) { |
| | | assemble.setPreStatus(SysAssembleRunStatus.fail); |
| | | assemble.setPreCnt(0); |
| | | assemble.setPreMsg("当前有流程正在运行,暂时无法汇集下次数据:" + status.toString()); |
| | | assemble.updateById(); |
| | | return Result.error(new CodeMsg(6009,"当前有流程正在运行,暂时无法汇集下次数据:" + status.toString())); |
| | | |
| | | } |
| | | } |
| | | } |
| | | assemble.setPreTime(new Date()); |
| | | assemble.setPreStatus(SysAssembleRunStatus.working); |
| | | assemble.updateById(); |
| | | |
| | | Boolean bigData = assemble.getBigdata(); |
| | | |
| | |
| | | } |
| | | |
| | | //5 check temp data |
| | | result = checkTempData(id, assemble.getCheckType(), assemble.getCheckFields()); |
| | | result = checkTempData(assemble); |
| | | |
| | | if (!result.getSuccess()) { |
| | | assemble.setPreStatus(SysAssembleRunStatus.fail); |
| | |
| | | } |
| | | |
| | | //7 record 链接 版本 |
| | | result = linkMaintain(assemble, session); |
| | | result = linkMaintain(assemble); |
| | | if (!result.getSuccess()) { |
| | | assemble.setPreStatus(SysAssembleRunStatus.fail); |
| | | assemble.setPreMsg("联接版本出现错误" ); |
| | |
| | | } |
| | | } |
| | | |
| | | private Result linkMaintain(SysAssemble assemble, HttpSession session) { |
| | | private Result linkMaintain(SysAssemble assemble) { |
| | | try{ |
| | | String menuId = assemble.getMenuId(); |
| | | MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("menu_id", menuId)); |
| | |
| | | //默认需要审批 |
| | | audit = true; |
| | | } |
| | | // 处理关联人 |
| | | |
| | | |
| | | if (audit) { |
| | | Flows flows = activitiService.start("process", session, maintain.getId(), ActivitiBusinessType.maintain); |
| | | String chargeId = menuMapping.getChargeId(); |
| | | TUser user = userService.selectById(chargeId); |
| | | if (user == null) { |
| | | return Result.error(new CodeMsg(6009, "找不到对应的负责人:" + chargeId)); |
| | | } |
| | | activitiService.setUser(user); |
| | | Flows flows = activitiService.start("process", null, maintain.getId(), ActivitiBusinessType.maintain); |
| | | assemble.setFlowId(flows.getId()).updateById(); |
| | | maintain.setFlowId(flows.getId()); |
| | | maintain.setDesp("启动汇集流程"); |
| | | maintain.updateById(); |
| | | masterModifiedService.dealAssemble(maintain.getId(), assemble.getUserId(), true); |
| | | }else { |
| | | //直接运行 |
| | | Flows flows = new Flows().setStatus(ActivitiStatus.open).setBusinessId(maintain.getId()).setId(DbUtils.getUUID()).setCreateTime(new Date()); |
| | |
| | | maintain.setFlowId(flows.getId()); |
| | | maintain.updateById(); |
| | | maintainService.dealFlow(maintain.getId(), ActivitiStatus.open); |
| | | masterModifiedService.dealAssemble(maintain.getId(), assemble.getUserId(), false); |
| | | } |
| | | return Result.success(null); |
| | | }catch (Exception e) { |
| | |
| | | PreparedStatement updatedPreparedStatement = conn.prepareStatement(updatedSql); |
| | | int updateCnt = updatedPreparedStatement.executeUpdate(); |
| | | cnt = updateCnt; |
| | | tableInfoMapper.insertMatintainDetailFromTemp(DbUtils.quotedStr(maintain.getId()), maintain.getTableName() + Constant.RECORD , DbUtils.quotedStr(Operate.update.toString())); |
| | | } |
| | | } |
| | | |
| | | tableInfoMapper.insertMatintainDetailFromTemp(DbUtils.quotedStr(maintain.getId()), maintain.getTableName() + Constant.RECORD , DbUtils.quotedStr(Operate.update.toString())); |
| | | |
| | | //tableInfoMapper.updateStdId( maintain.getTableName() + Constant.RECORD); |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private Result temp2record(SysAssemble assemble) { |
| | | Connection conn = null; |
| | | try { |
| | |
| | | String joinStr = getJoinFieldParse(unionCodeFields); |
| | | |
| | | // insert |
| | | |
| | | String insertFieldStr = fieldsFromTable.stream() |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.T1,s)) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | |
| | | return builder.toString(); |
| | | } |
| | | |
| | | private Result checkTempData(String s,SysAssembleCheckType checkType, String id) { |
| | | private Result checkTempData(SysAssemble assemble) { |
| | | //TODO |
| | | |
| | | SysAssembleCheckType checkType = assemble.getCheckType(); |
| | | if (checkType == null) { |
| | | return Result.error(new CodeMsg(6009,"规则校验类型为空")); |
| | | } |
| | | if (checkType.equals(SysAssembleCheckType.unlimited)) { |
| | | return Result.success(null); |
| | | } |
| | | |
| | | String menuId = assemble.getMenuId(); |
| | | MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("menu_id", menuId)); |
| | | String tableName = menuMapping.getTableName(); |
| | | String tempTableName = Constant.Temp + tableName; |
| | | HashMap<String,Boolean> fieldResultSet = ruleClient.execuImmeForCollect(tempTableName, assemble.getUserId()); |
| | | switch (checkType){ |
| | | case successAdd: |
| | | String unSuccessFields = fieldResultSet.keySet().stream().filter(s -> !fieldResultSet.get(s)).collect(Collectors.joining(Constant.COMMA)); |
| | | if (fieldResultSet.keySet().contains(false)) { |
| | | return Result.error(new CodeMsg(6009,"规则校验不通过 字段:" + unSuccessFields)); |
| | | } |
| | | break; |
| | | case partSuccessAdd: |
| | | String checkFields = assemble.getCheckFields(); |
| | | String[] split = checkFields.split(Constant.SEMICOLON); |
| | | for (String s : split) { |
| | | Boolean checked = fieldResultSet.get(s); |
| | | if (checked == null || !checked) { |
| | | return Result.error(new CodeMsg(6009,"规则校验不通过 字段:" + s)); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | |
| | | |
| | | |
| | | return Result.success(null); |
| | | } |
| | | |