kimi
2020-05-27 c007f0ca1785db093d48f4846cda82fe8e955765
src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java
@@ -15,10 +15,7 @@
import com.highdatas.mdm.mapper.TableInfoMapper;
import com.highdatas.mdm.pojo.CodeMsg;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.ActivitiService;
import com.highdatas.mdm.service.IMaintainService;
import com.highdatas.mdm.service.IMenuMappingService;
import com.highdatas.mdm.service.ISysMenuService;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
import com.highdatas.mdm.util.DbUtils;
import com.highdatas.mdm.util.WorkflowUtils;
@@ -27,6 +24,7 @@
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Map;
@@ -54,9 +52,20 @@
    @Autowired
    ISysMenuService menuService;
    @Autowired
    IMaintainFieldService maintainFieldService;
    @Autowired
    IMasterAuthorService masterAuthorService;
    public static final String key = "process";
    /**
     *
     * @description:  创建menumapping对象
     * @param json menu mapping josn数据
     * @param session 用户从session里获取
     * @return: menu mapping对象
     *
     */
    @Override
    public MenuMapping create(String json, HttpSession session) {
        JSONObject jsonObject = JSONObject.parseObject(json);
@@ -94,7 +103,7 @@
        //menuMapping.setMaintainFieldId(maintainId);
        return  create(menuMapping);
    }
    @Deprecated
    private Maintain createMaintain(String userId, JSONObject jsonObject, String flowsId) {
        Maintain maintain = new Maintain();
        maintain.setCreateTime(new Date());
@@ -116,7 +125,14 @@
        }
        return null;
    }
    /**
     *
     * @description:  保存menumapping对象
     * @param menuMapping menumapping 对象
     * @return: menu mapping对象
     *
     */
    @Override
    public MenuMapping create(MenuMapping menuMapping) {
        menuMapping.setCreateTime(new Date());
        menuMapping.setId(DbUtils.getUUID());
@@ -125,8 +141,21 @@
        String tableName = WorkflowUtils.toFirstChar(name.toLowerCase());
        tableName = Constant.MD + tableName;
        String tableByName = tableInfoMapper.selectTableByName(tableName);
        if (!StringUtils.isEmpty(tableByName)){
            tableName =  tableName + "_" +  DbUtils.getUUID(5);
            int sameCount = selectCount(new EntityWrapper<MenuMapping>().eq("table_name", tableName));
            if (sameCount > 0) {
                tableName =  tableName + "_" +  DbUtils.getUUID(5);
            }
        }
        int length = 0;
        try {
            length = tableName.getBytes("UTF-8").length;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if (length > 18) {
            tableName = Constant.MD + DbUtils.getUUID(10);
        }
        menuMapping.setTableName(tableName);
        boolean insert = this.insert(menuMapping);
@@ -135,7 +164,6 @@
        } else {
            return null;
        }
    }
    @Override
@@ -149,10 +177,26 @@
            e.printStackTrace();
            return false;
        }
        //only update no join
        //update menu name
        String menuId = menuMapping.getMenuId();
        SysMenu sysMenu = menuService.selectById(menuId);
        if (sysMenu == null) {
            return false;
        }
        sysMenu.setName(menuMapping.getName());
        sysMenu.updateById();
        return this.updateById(menuMapping);
    }
    /**
     *
     * @description:  通过主题获取menumapping
     * @param id 主题id
     * @param session 用户从session里获取
     * @return: menu mapping对象
     *
     */
    @Override
    public Result getMapping(HttpSession session, String id) {
        SysMenu sysMenu = menuService.selectById(id);
@@ -175,17 +219,84 @@
        if (menuMapping == null) {
            return Result.error(new CodeMsg(10008,"当前主题无版本数据"));
        }
        String tableName = menuMapping.getTableName();
        Maintain resultMaintain = maintainService.getNowVersion(tableName);
        String chargeId = menuMapping.getChargeId();
        TUser userByChargeId = DbUtils.getUserById(chargeId);
        TUser user = (TUser) session.getAttribute(Constant.USER);
        Maintain resultMaintain = masterAuthorService.getMaxVersionMaintain(user, tableName);
        Maintain nowVersion = maintainService.getNowVersion(tableName);
        if (resultMaintain != null) {
            if (nowVersion.getOrderNo().equals(resultMaintain.getOrderNo())) {
                mapping.put("maintainType", 0);
            }else {
                mapping.put("maintainType", 1);
            }
            mapping.put("version", resultMaintain.getVersion());
            mapping.put("maintainId", resultMaintain.getId());
        }
        if (userByChargeId != null) {
            mapping.put("userName", userByChargeId.getUserName());
        }
        if (nowVersion != null) {
            mapping.put("hasData", true);
        }else {
            mapping.put("hasData", false);
        }
        return Result.success(mapping);
    }
    /**
     *
     * @description:  通过表名获取主题
     * @param tableName 表名
     * @return: 主题对象
     *
     */
    @Override
    public SysMenu getMenuByTableName(String tableName) {
        MenuMapping menuMapping = selectOne(new EntityWrapper<MenuMapping>().eq("table_name", tableName).orderBy("create_time desc"));
        if (menuMapping == null) {
            return null;
        }
        String menuId = menuMapping.getMenuId();
        SysMenu sysMenu = menuService.selectById(menuId);
        return sysMenu;
    }
    /**
     *
     * @description:  通过主题获取menumapping
     * @param id 主题id
     * @param session 用户从session里获取
     * @return: menu mapping对象
     *
     */
    @Override
    public MenuMapping getMenuMappingByTableName(String tableName) {
        MenuMapping menuMapping = selectOne(new EntityWrapper<MenuMapping>().eq("table_name", tableName).orderBy("create_time desc"));
        if (menuMapping == null) {
            return null;
        }
        return menuMapping;
    }
    /**
     *
     * @description:  通过主题获取menumapping
     * @param menuId 主题id
     * @return: menumapping对象
     *
     */
    @Override
    public String getTableNameByMenu(String menuId) {
        MenuMapping menuMapping = selectOne(new EntityWrapper<MenuMapping>().eq("menu_id", menuId).orderBy("create_time desc"));
        if (menuMapping == null) {
            return null;
        }
        return menuMapping.getTableName();
    }
}