From 2411eadd4ad4bef5c08c6ba2ea5898ea72136e29 Mon Sep 17 00:00:00 2001 From: kimi42345 <kimi42345@outlook.com> Date: 星期一, 02 三月 2020 11:13:35 +0800 Subject: [PATCH] add assebmle --- src/main/java/com/highdatas/mdm/service/impl/MasterDataServiceImpl.java | 123 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 113 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/highdatas/mdm/service/impl/MasterDataServiceImpl.java b/src/main/java/com/highdatas/mdm/service/impl/MasterDataServiceImpl.java index 855e7a2..18c90e4 100644 --- a/src/main/java/com/highdatas/mdm/service/impl/MasterDataServiceImpl.java +++ b/src/main/java/com/highdatas/mdm/service/impl/MasterDataServiceImpl.java @@ -4,23 +4,21 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.highdatas.mdm.entity.Flows; -import com.highdatas.mdm.entity.Maintain; -import com.highdatas.mdm.entity.SysField; -import com.highdatas.mdm.entity.TableSchemaResult; +import com.highdatas.mdm.entity.*; import com.highdatas.mdm.mapper.TableInfoMapper; import com.highdatas.mdm.pojo.*; -import com.highdatas.mdm.service.IFlowsService; -import com.highdatas.mdm.service.IMaintainService; -import com.highdatas.mdm.service.ISysFieldService; -import com.highdatas.mdm.service.MasterDataService; +import com.highdatas.mdm.service.*; import com.highdatas.mdm.util.Constant; import com.highdatas.mdm.util.ContentBuilder; import com.highdatas.mdm.util.DbUtils; import org.apache.commons.lang3.StringUtils; +import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.sql.Connection; +import java.sql.SQLException; import java.text.MessageFormat; import java.util.*; import java.util.stream.Collectors; @@ -34,14 +32,19 @@ @Service public class MasterDataServiceImpl implements MasterDataService { @Autowired + IMenuMappingService menuMappingService; + @Autowired TableInfoMapper mapper; @Autowired ISysFieldService fieldService; @Autowired IMaintainService maintainService; @Autowired + IMaintainDetailService maintainDetailService; + @Autowired IFlowsService flowsService; - + @Resource + protected SqlSessionTemplate sqlSessionTemplate; @Override public Result selectById(String tableName, String id) { try{ @@ -391,7 +394,107 @@ return Result.success(resultobject); } - //bak + @Override + public Maintain uploadedData(String tableName, SysAssembleUpdateType uploadType, String userId) { + MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("table_name",tableName)); + SysOperateLog operateLog = new SysOperateLog(); + + Maintain maxVersion = maintainService.getMaxVersion(tableName); + Maintain maintain = new Maintain(); + String biggerVersion = null; + if (maxVersion == null) { + biggerVersion = Constant.VERSION_Default; + maintain.setOrderNo(0); + operateLog.setOperate("鍒濆鍖栦富棰樻暟鎹�"); + } else { + operateLog.setOperate("鏇存柊涓婚"); + String flowId = maxVersion.getFlowId(); + String mVersion = maxVersion.getVersion(); + if (StringUtils.isEmpty(flowId)) { + biggerVersion = mVersion; + maintain.setOrderNo(maxVersion.getOrderNo()); + String tempName = maxVersion.getTableName() + Constant.RECORD; + + mapper.deleteTempByMaintainId(tempName, DbUtils.quotedStr(maxVersion.getId())); + maintainDetailService.delete(new EntityWrapper<MaintainDetail>().eq("parent_id", maxVersion.getId())); + + maxVersion.deleteById(); + }else { + biggerVersion = DbUtils.versionAddBig(mVersion); + maintain.setOrderNo(DbUtils.getOrderNoAdd(maxVersion.getOrderNo())); + } + } + + String uuid = DbUtils.getUUID(); + maintain.setId(uuid); + + maintain.setVersion(biggerVersion); + maintain.setChargeId(userId); + maintain.setTableName(tableName); + maintain.setCreateTime(new Date()); + + Connection connection = sqlSessionTemplate.getConnection(); + try { + mapper.insertMatintainDetailFromTemp(DbUtils.quotedStr(maintain.getId()), maintain.getTableName() + Constant.RECORD , DbUtils.quotedStr(Operate.create.toString())); + connection.commit(); + mapper.updateStdId( maintain.getTableName() + Constant.RECORD); + connection.commit(); + Integer aLong = mapper.tempDeal(maintain.getTableName() + Constant.RECORD, DbUtils.quotedStr(maintain.getId())); + connection.commit(); + if (aLong == null) { + maintain.setDesp("涓婁紶鏁版嵁"); + } + maintain.setDesp(MessageFormat.format("涓婁紶鏁版嵁{0}鏉�", aLong)); + + if (uploadType.equals(SysAssembleUpdateType.All)) { + List<TableSchemaResult> tableField = mapper.getTableField(tableName); + List<String> tableFieldList = tableField.stream().map(tableSchemaResult -> tableSchemaResult.getFieldName()).collect(Collectors.toList()); + tableFieldList.add(Constant.STD_ID); + String collect = tableFieldList.stream().map(s -> s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format(Constant.FieldAsAlias, Constant.MYSQL_UUID, Constant.ID) : s) + .map(s -> s.equalsIgnoreCase(Constant.STD_ID) ? MessageFormat.format(Constant.FieldAsAlias, Constant.ID, Constant.STD_ID) : s).collect(Collectors.joining(Constant.COMMA)); + + mapper.insertRecordFromStandrad(maintain.getTableName(), maintain.getTableName() + Constant.RECORD, collect); + connection.commit(); + mapper.insertMatintainDetailFromStandrad(DbUtils.quotedStr(maintain.getId()), maintain.getTableName() + Constant.RECORD); + connection.commit(); + Integer standradCnt = mapper.tempDeal(maintain.getTableName() + Constant.RECORD, DbUtils.quotedStr(maintain.getId())); + connection.commit(); + if (standradCnt != null) { + maintain.setDesp(maintain.getDesp() + MessageFormat.format("鍒犻櫎鍘熸暟鎹畕0}鏉�", standradCnt)); + }else { + maintain.setDesp(maintain.getDesp() + "鍒犻櫎鍘熸暟鎹�"); + } + maintain.setDesp(maintain.getDesp() + MessageFormat.format("鍒犻櫎鍘熸暟鎹畕0}鏉�", standradCnt)); + } + + operateLog.setCreateTime(new Date()) + .setMaintainId(maintain.getId()) + .setId(DbUtils.getUUID()) + .setMaintainId(menuMapping.getId()) + .setOperate("open") + .setDesp(MessageFormat.format("涓婁紶鏁版嵁{0}鏉�", aLong)); + + maintain.insert(); + connection.commit(); + } + catch (Exception e) { + e.printStackTrace(); + + + } + finally { + if (connection != null) { + try { + connection.commit(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + return maintain; + } + + //bak public Result selectListByPage(String tableName, List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, String version) { Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); long changeCount = maintainService.countVersionOperatorByType(tableName + Constant.RECORD, whereSegment, maintainFromVersion.getId(), Operate.create); -- Gitblit v1.8.0