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 |  163 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 152 insertions(+), 11 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 a04589d..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);
@@ -472,6 +575,7 @@
         try {
             String[] split = fields.split(Constant.SEMICOLON);
             List<String> fieldNameList = Arrays.stream(split).map(s -> s.trim()).collect(Collectors.toList());
+            fields = fieldNameList.stream().collect(Collectors.joining(Constant.COMMA));
             ContentBuilder builder = new ContentBuilder(Constant.COMMA);
             Object parse = JSON.parse(values);
             List<String> ids = new ArrayList<>();
@@ -481,7 +585,7 @@
                 ids.add(id);
                 String sqlValues  = builder.toString();
                 mapper.insert(tableName, fields, sqlValues);
-                return Result.success(CodeMsg.INSERT_SUCCESS);
+                return Result.success(ids);
             } else if (parse instanceof JSONArray) {
                 JSONArray jsonArray = (JSONArray) parse;
                 int size = jsonArray.size();
@@ -582,6 +686,12 @@
     }
 
     @Override
+    public Result updateByStdId(String tableName, String fieldsSegment, String id, boolean total) {
+        String whereStr = DbUtils.combieOneSegment(Constant.STD_ID, id);
+        return update(tableName, fieldsSegment,whereStr, total);
+    }
+
+    @Override
     public Result update(String tableName, String fieldsSegment, boolean total) {
         String whereSegment = Constant.WHERE_DEFAULT;
         return update(tableName, fieldsSegment,whereSegment, total);
@@ -614,6 +724,31 @@
                 segment = new Segment(fieldName, String.valueOf(o));
             } else {
                 segment = new Segment(fieldName, o);
+            }
+            builder.append(segment.toString());
+        }
+        return builder.toString();
+    }
+
+    @Override
+    public String getUpdateSegment(String tableName, String alias, String fieldsSegment) {
+        ContentBuilder builder = new ContentBuilder(Constant.COMMA);
+        JSONObject jsonObject = JSONObject.parseObject(fieldsSegment);
+        List<TableSchemaResult> tableFieldResultList = mapper.getTableField(tableName);
+        for (TableSchemaResult tableSchemaResult : tableFieldResultList) {
+            String dbType = tableSchemaResult.getDbType();
+            String fieldName = tableSchemaResult.getFieldName();
+            Object o = jsonObject.get(fieldName);
+            if (o == null) {
+                continue;
+            }
+            String javaTypeStr = DbUtils.toSqlToJava(dbType);
+            Segment segment;
+            if ("string".equalsIgnoreCase(javaTypeStr.trim())) {
+
+                segment = new Segment(MessageFormat.format(Constant.Alias, alias, fieldName), String.valueOf(o));
+            } else {
+                segment = new Segment(MessageFormat.format(Constant.Alias, alias, fieldName), o);
             }
             builder.append(segment.toString());
         }
@@ -691,6 +826,12 @@
         String whereStr = DbUtils.combieOneSegment(Constant.ID, id);
         return  delete(tableName, whereStr);
     }
+
+    @Override
+    public Result deleteByStdId(String tableName, String id) {
+        String whereStr = DbUtils.combieOneSegment(Constant.STD_ID, id);
+        return  delete(tableName, whereStr);
+    }
     @Override
     public Result delete(String tableName, String whereSegment) {
         try {

--
Gitblit v1.8.0