kimi
2020-03-24 b5636e416a2fe029f96aec6ddfd3489394925b15
src/main/java/com/highdatas/mdm/controller/MasterDataController.java
@@ -9,10 +9,7 @@
import com.highdatas.mdm.pojo.Operate;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.pojo.SysAssembleUpdateType;
import com.highdatas.mdm.service.IMaintainDetailService;
import com.highdatas.mdm.service.IMaintainService;
import com.highdatas.mdm.service.IMenuMappingService;
import com.highdatas.mdm.service.MasterDataService;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
import com.highdatas.mdm.util.DbUtils;
import org.apache.commons.lang3.StringUtils;
@@ -51,6 +48,9 @@
    @Autowired
    TableInfoMapper tableInfoMapper;
    @Autowired
    IMasterModifiedService masterModifiedService;
    @RequestMapping(value = "{tableName}/uploaded",  method = RequestMethod.GET)
    public Result get(@PathVariable String tableName, HttpServletRequest request) {
        String uploadTypeStr = request.getParameter("uploadType");
@@ -61,6 +61,8 @@
        uploadType = SysAssembleUpdateType.valueOf(uploadTypeStr);
        TUser user = (TUser) request.getSession().getAttribute(Constant.USER);
        Maintain maintain = masterDataService.uploadedData(tableName, uploadType, user.getUserId());
        // 处理关联人
        masterModifiedService.dealAssemble(maintain.getId(), user.getUserId(), true);
        JSONObject object = new JSONObject();
        object.fluentPut("maintainId",maintain.getId());
        object.fluentPut("version",maintain.getVersion());
@@ -98,7 +100,11 @@
            version = String.valueOf(nowVersion.getVersion());
        }else if(version.equalsIgnoreCase(Constant.MAX)){
            findMax = true;
            version = String.valueOf(maintainService.getMaxVersion(tableName).getVersion());
            Maintain maxVersion = maintainService.getMaxVersion(tableName);
            if (maxVersion == null)  {
                return Result.success(null);
            }
            version = String.valueOf(maxVersion.getVersion());
        }
        if (StringUtils.isEmpty(fields)) {
@@ -130,21 +136,28 @@
    }
    @RequestMapping(value = "{maintainId}/modify/{operateStr}", method = RequestMethod.POST)
    public Result modify(@RequestParam String datas, @PathVariable String maintainId, @PathVariable String operateStr, HttpServletRequest request) throws UnsupportedEncodingException {
    public Result modify(@RequestParam String datas, @PathVariable String maintainId, @PathVariable String operateStr,  @RequestParam String modify, HttpServletRequest request) throws UnsupportedEncodingException {
        Result result = null;
        Operate operate = Operate.parse(operateStr);
        Maintain maintain = maintainService.selectById(maintainId);
        List<String> modifyFields = null;
        if (!StringUtils.isEmpty(modify)) {
            String[] split = modify.split(Constant.SEMICOLON);
            modifyFields = Arrays.stream(split).collect(Collectors.toList());
        }
        TUser user = (TUser) request.getSession().getAttribute("user");
        switch (operate) {
            case delete:
                //datas is id;
                Integer deleteCount = tableInfoMapper.deleteRecordByMaintainId(maintain.getTableName() + Constant.RECORD, DbUtils.quotedStr(datas), DbUtils.quotedStr(maintainId));
                result = Result.success(deleteCount);
                break;
            case update:
                JSONObject jsonObject = JSONObject.parseObject(datas);
                String id = (String) jsonObject.get("id");
                masterModifiedService.updateModifiedUserById(maintainId, id, user.getUserId(), modifyFields);
                jsonObject.remove(Constant.ID);
                datas = jsonObject.toJSONString();
                String updateSegment = masterDataService.getUpdateSegment(maintain.getTableName(), maintain.getTableName() + Constant.RECORD, datas);
@@ -155,6 +168,9 @@
            case create:
                JSONObject createObject = JSONObject.parseObject(datas);
                String recordId = DbUtils.getUUID();
                masterModifiedService.updateModifiedUserById(maintainId, recordId, user.getUserId(), modifyFields);
                createObject.fluentPut(Constant.ID, recordId);
                createObject.fluentPut(Constant.STD_ID, DbUtils.getUUID());
                datas = createObject.toJSONString();
@@ -189,6 +205,11 @@
        Maintain maintain = maintainService.getMaxVersion(tableName);
        Maintain nowMaintain = maintainService.getNextMaintain(tableName, userId);
        List<String> modifyFields = null;
        if (!StringUtils.isEmpty(modify)) {
            String[] split = modify.split(Constant.SEMICOLON);
            modifyFields = Arrays.stream(split).collect(Collectors.toList());
        }
        Result result;
        if (operate.equals(Operate.delete)) {
@@ -209,16 +230,19 @@
        } else if (operate.equals(Operate.update)) {
            JSONObject jsonObject = JSONObject.parseObject(datas);
            Object id = jsonObject.get("id");
            String nowMaintainId = nowMaintain.getId();
            String tempId = tableInfoMapper.getTempIdByStdId(tableName + Constant.RECORD,DbUtils.quotedStr(id.toString()), DbUtils.quotedStr(nowMaintainId));
            if (StringUtils.isEmpty(tempId)) {
                result = masterDataService.selectById(tableName, id.toString());
            } else {
                masterModifiedService.updateModifiedUserById(nowMaintain.getId(), id.toString(), user.getUserId(), modifyFields);
                jsonObject.put(Constant.STD_ID, id);
                jsonObject.put(Constant.ID, tempId);
                return masterDataService.updateById(tableName + Constant.RECORD, JSON.toJSONString(jsonObject), tempId,false);
            }
        }
        //merge 2 temp
        String tableTempName = tableName + Constant.RECORD;
@@ -228,6 +252,7 @@
        if (dataId == null) {
            dataId = DbUtils.getUUID();
        }
        masterModifiedService.updateModifiedUserById(nowMaintain.getId(), dataId.toString(), user.getUserId(), modifyFields);
        object.put(Constant.STD_ID, dataId);
        object.put(Constant.ID, DbUtils.getUUID());
        datas = JSON.toJSONString(object);
@@ -308,4 +333,11 @@
            return masterDataService.delete(tableName, whereSegment);
        }
    }
    @RequestMapping(value = "{tableName}/getFieldVal/{field}",  method = RequestMethod.GET)
    public Result getFieldVal(@PathVariable String tableName, @PathVariable String field) {
        return masterDataService.getFieldValByTable(tableName,field);
    }
}