kimi
2020-03-31 74472c9d22dddcb41383794caf0011043b20f817
src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
@@ -6,6 +6,7 @@
import com.highdatas.mdm.controller.MasterAuthorController;
import com.highdatas.mdm.entity.*;
import com.highdatas.mdm.mapper.MasterAuthorMapper;
import com.highdatas.mdm.pojo.ActivitiStatus;
import com.highdatas.mdm.pojo.MasterAuthorType;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
@@ -42,6 +43,8 @@
    IMaintainFieldService maintainFieldService;
    @Autowired
    IMaintainService maintainService;
    @Autowired
    IFlowsService flowsService;
    @Override
    public HashMap<String, MasterAuthor> merageRoleAuthor(List<String> roleIds) {
@@ -82,17 +85,29 @@
    }
    @Override
    public List<SysField> getField(String userId, String maintainFieldId, String maintainId) {
        if (maintainFieldId.equalsIgnoreCase(Constant.All)) {
    public List<SysField> getField(String userId, String maintainId) {
        Maintain maintain = maintainService.selectById(maintainId);
        if (maintain == null){
            return new ArrayList<>();
        }
        boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName());
        if (isAll) {
            List<SysField> total = fieldService.getFieldByMaintain(maintainId);
            return total;
        }
        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(this.characterId, userId).eq("maintain_field_id", maintainFieldId));
        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
        if (maintainField == null){
            return new ArrayList<>();
        }
        String maintainFieldId = maintainField.getId();
        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("maintain_field_id", maintainFieldId));
        if (masterAuthors.size() == 0) {
            //user 获取role
            List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId));
            List<String> roleIds = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList());
            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(this.characterId, roleIds).eq("maintain_field_id", maintainFieldId));
            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds).eq("maintain_field_id", maintainFieldId));
        }
        if (masterAuthors.isEmpty()) {
            return null;
@@ -103,18 +118,35 @@
        if (codes.isEmpty()) {
            return null;
        }
        Wrapper<SysField> wrapper = new EntityWrapper<SysField>().in(Constant.FIELD, codes);
        Wrapper<SysField> wrapper = new EntityWrapper<SysField>().in(Constant.FIELD, codes).eq("table_name", maintain.getTableName());
        if (maintainFieldId.equalsIgnoreCase(Constant.Default)) {
        if (!maintainFieldId.equalsIgnoreCase(Constant.Default)) {
            wrapper.eq("maintain_field_id", maintainFieldId);
        }else {
            wrapper.isNull("maintain_field_id");
        }
        wrapper.orderBy("order_no");
        List<SysField> fieldList = fieldService.selectList(wrapper);
        return fieldList;
    }
    private boolean checkUnFilterAuthor(String userId, String tableName) {
        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("table_name", tableName));
        long isAll = masterAuthors.stream().filter(masterAuthor -> masterAuthor.getMaintainFieldId().equalsIgnoreCase(Constant.All)).count();
        if (isAll > 0) {
            return true;
        }
        if (!masterAuthors.isEmpty()) {
            return false;
        }
        Set<String> roleByUser = DbUtils.getRoleByUser(userId);
        isAll = selectCount(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleByUser).eq("table_name", tableName).eq("maintain_field_id", Constant.All_UPCASE));
        if (isAll > 0) {
            return true;
        }
        return false;
    }
    @Override
@@ -123,13 +155,11 @@
        if (maintain == null) {
            return false;
        }
        int checked = selectCount(new EntityWrapper<MasterAuthor>()
                .eq(Constant.TYPE, MasterAuthorType.user)
                .eq(MasterAuthorController.character_id, userId)
                .eq("table_name", maintain.getTableName())
                .eq("maintain_field_id", Constant.All));
        if(checked > 0) {
        int checked = 0;
        boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName());
        if (isAll){
            return true;
        }
        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
        if (maintainField == null) {
@@ -159,17 +189,25 @@
    @Override
    public String getFilter(String userId, String maintainId) {
        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
        if (maintainField)
        if (maintainFieldId.equalsIgnoreCase(Constant.All)) {
        Maintain maintain = maintainService.selectById(maintainId);
        if (maintain == null){
            return Constant.WHERE_DEFAULTUN;
        }
        boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName());
        if (isAll) {
            return Constant.WHERE_DEFAULT;
        }
        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(this.characterId, userId).eq("maintain_field_id", maintainFieldId));
        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
        String maintainFieldId = maintainField.getId();
        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>()
                .eq("table_name", maintain.getTableName())
                .eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("maintain_field_id", maintainFieldId));
        if (masterAuthors.size() == 0) {
            //user 获取role
            List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId));
            List<String> roleIds = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList());
            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(this.characterId, roleIds).eq("maintain_field_id", maintainFieldId));
            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq("table_name", maintain.getTableName()).eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds).eq("maintain_field_id", maintainFieldId));
        }
        if (masterAuthors.isEmpty()){
            return Constant.WHERE_DEFAULTUN;
@@ -190,8 +228,11 @@
            }
            Boolean preAll = segmentAllMap.get(field);
            if (preAll && segmentMap.containsKey(field)) {
                segmentMap.remove(field);
            if (preAll) {
                if (segmentMap.containsKey(field)) {
                    segmentMap.remove(field);
                }
                continue;
            }
            String val = detail.getVal();
@@ -205,13 +246,29 @@
            String val = vals.stream()
                    .filter(s -> !StringUtils.isEmpty(s))
                    .map(s -> DbUtils.quotedStr(s)).collect(Collectors.joining(Constant.COMMA));
            String format = MessageFormat.format(Constant.MYSQL_UUID, code, val);
            String format = MessageFormat.format(Constant.InSql, code, val);
            builder.append(format);
        }
        String filter = builder.toString();
        return filter;
    }
    @Override
    public Maintain getMaxVersionMaintain(String userId, String tableName) {
        List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no desc"));
        for (Maintain maintain : maintainList) {
            ActivitiStatus status = flowsService.getStatusByBusinessId(maintain.getId());
            if (!status.equals(ActivitiStatus.open)) {
                continue;
            }
            boolean b = checkMaintainAuthor(userId, maintain.getId());
            if (b) {
                return maintain;
            }
        }
        return null;
    }
    private MasterAuthor merage(MasterAuthor preMerageMasterAuthor, MasterAuthor masterAuthor) {
        // table name  masterField 一样 只有字段不同了
        List<MasterAuthorDetail> preFields = preMerageMasterAuthor.getFields();