kimi
2020-05-18 c8aee7b9bfd79cfd741d7e5692520f4f51a31a86
src/main/java/com/highdatas/mdm/controller/MasterDataController.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.highdatas.mdm.entity.Character;
import com.highdatas.mdm.entity.*;
import com.highdatas.mdm.mapper.TableInfoMapper;
import com.highdatas.mdm.pojo.CodeMsg;
@@ -12,8 +13,11 @@
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
import com.highdatas.mdm.util.DbUtils;
import com.highdatas.mdm.util.NoticeClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@@ -30,6 +34,7 @@
 */
@RestController
@Slf4j
@RequestMapping("/master")
public class MasterDataController {
    @Autowired
@@ -51,6 +56,10 @@
    IMasterModifiedService masterModifiedService;
    @Autowired
    IMasterAuthorService masterAuthorService;
    @Autowired
    ISysMenuService menuService;
    @Autowired
    NoticeClient noticeClient;
    @RequestMapping(value = "{tableName}/uploaded",  method = RequestMethod.GET)
    public Result get(@PathVariable String tableName, HttpServletRequest request) {
@@ -58,12 +67,19 @@
        SysAssembleUpdateType uploadType;
        if (StringUtils.isEmpty(uploadTypeStr)) {
            uploadType = SysAssembleUpdateType.Increment;
        }else {
            uploadType = SysAssembleUpdateType.valueOf(uploadTypeStr);
        }
        uploadType = SysAssembleUpdateType.valueOf(uploadTypeStr);
        TUser user = (TUser) request.getSession().getAttribute(Constant.USER);
        TUser user = DbUtils.getUser(request);
        Maintain maintain = masterDataService.uploadedData(tableName, uploadType, user.getUserId());
        // 处理关联人
        masterModifiedService.dealAssemble(maintain.getId(), user.getUserId(), true);
        //masterModifiedService.dealAssemble(maintain.getId(), user.getUserId(), true);
        //添加 std_id 索引
        String recordTableName = tableName + Constant.RECORD;
        masterDataService.createIdx(recordTableName);
        JSONObject object = new JSONObject();
        object.fluentPut("maintainId",maintain.getId());
        object.fluentPut("version",maintain.getVersion());
@@ -78,7 +94,12 @@
    @RequestMapping(value = "{tableName}/all/{pageNo}",  method = RequestMethod.GET)
    public Result getByPage(@PathVariable String tableName, @PathVariable Integer pageNo, HttpServletRequest request) throws UnsupportedEncodingException {
        TUser user = DbUtils.getUser(request);
        String uuid = DbUtils.getUUID();
        Date start = new Date();
        Character character = DbUtils.getCharacter(request);
        Date end = new Date();
        log.info(MessageFormat.format("master tag:{0} MASTER-- form userID selct user:{1} ms",uuid, (end.getTime() - start.getTime())));
        String pageSizeStr = request.getParameter("pageSize");
        String whereSegment = request.getParameter(Constant.WHERE_SEGMENT);
        String fields = request.getParameter(Constant.FIELDS);
@@ -113,21 +134,28 @@
            return null;
        }
        //ADD Filter
        String filter = masterAuthorService.getFilter(user.getUserId(), maintainFromVersion.getId());
        whereSegment = DbUtils.StrJoin(whereSegment, Constant.AND, filter);
        start = new Date();
        log.info(MessageFormat.format("master tag:{0} MASTER-- select maintain:{1} ms",uuid, (start.getTime() - end.getTime())));
        String filter = masterAuthorService.getFilter(character, maintainFromVersion.getId(), uuid);
        if (!StringUtils.isEmpty(filter)) {
            whereSegment = DbUtils.StrJoin(whereSegment, Constant.AND, filter);
        }
        end = new Date();
        log.info(MessageFormat.format("master tag:{0}  MASTER-- select filter:{1} ms",uuid, (end.getTime() - start.getTime())));
        if (StringUtils.isEmpty(fields)) {
            if (StringUtils.isEmpty(pageSizeStr)) {
                return masterDataService.selectListByPageByVersion(user, tableName, whereSegment,pageNo,version, findMax);
                return masterDataService.selectListByPageByVersion(character, tableName, whereSegment,pageNo,version, findMax,uuid);
            }
            return masterDataService.selectListByPageByVersion(user, tableName, null, whereSegment,pageNo, Integer.valueOf(pageSizeStr),version,findMax);
            return masterDataService.selectListByPageByVersion(character, tableName, null, whereSegment,pageNo, Integer.valueOf(pageSizeStr),version,findMax, uuid);
        }else {
            String[] split = fields.split(Constant.COMMA_TRIM);
            List<String> fieldList = Arrays.stream(split).collect(Collectors.toList());
            if (StringUtils.isEmpty(pageSizeStr)) {
                return masterDataService.selectListByPageByVersion(user, tableName, fieldList, whereSegment,pageNo, null,version, findMax);
                return masterDataService.selectListByPageByVersion(character, tableName, fieldList, whereSegment,pageNo, null,version, findMax, uuid);
            }
            return masterDataService.selectListByPageByVersion(user, tableName, fieldList, whereSegment,pageNo, Integer.valueOf(pageSizeStr), findMax);
            return masterDataService.selectListByPageByVersion(character, tableName, fieldList, whereSegment,pageNo, Integer.valueOf(pageSizeStr), findMax, uuid);
        }
    }
@@ -155,7 +183,7 @@
            String[] split = modify.split(Constant.SEMICOLON);
            modifyFields = Arrays.stream(split).collect(Collectors.toList());
        }
        TUser user = (TUser) request.getSession().getAttribute("user");
        TUser user = DbUtils.getUser(request);
        switch (operate) {
            case delete:
@@ -207,10 +235,11 @@
    @RequestMapping(value = "{tableName}/{operateStr}", method = RequestMethod.POST)
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Result insert(@PathVariable String tableName,@PathVariable String operateStr, @RequestParam String datas, @RequestParam String modify, HttpServletRequest request) {
        String fields = request.getParameter("fields");
        Operate operate = Operate.parse(operateStr);
        TUser user = (TUser) request.getSession().getAttribute("user");
        TUser user = DbUtils.getUser(request);
        String userId = user.getUserId();
        Maintain maintain = maintainService.getMaxVersion(tableName);
        Maintain nowMaintain = maintainService.getNextMaintain(tableName, userId);
@@ -275,6 +304,7 @@
        List<String> ids = (List<String>) result.getData();
        nowMaintain.insertOrUpdate();
        for (String id : ids) {
            MaintainDetail maintainDetail = new MaintainDetail();
            maintainDetail.setId(DbUtils.getUUID());
@@ -290,7 +320,23 @@
        Maintain firstVersionMaintain = maintainService.getMaintainFromVersion(tableName, Constant.VERSION_Default);
        MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("table_name", firstVersionMaintain.getTableName()));
        String menuId = menuMapping.getMenuId();
        SysMenu menu = menuService.selectById(menuId);
        if (menu != null) {
            LinkedHashSet<String> parentIdSet = new LinkedHashSet<>();
            parentIdSet.add(menuId);
            LinkedHashSet<String> byParentId = menuService.getByParentId(parentIdSet);
            if (byParentId == null) {
                noticeClient.EditMasterData(menu, null, user.getUserId(), operate);
            } else {
                if (!byParentId.isEmpty()) {
                    List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId);
                    SysMenu parentMenu = sysMenus.get(0);
                    noticeClient.EditMasterData(menu, parentMenu, user.getUserId(),operate);
                }
            }
        }
        SysOperateLog operateLog = new SysOperateLog();
        operateLog.setChargeId(user.getUserId()).setId(DbUtils.getUUID())
                .setMaintainId(nowMaintain.getId())