| | |
| | | import com.highdatas.mdm.service.*; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import com.highdatas.mdm.util.RedisClient; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | IMasterAuthorService masterAuthorService; |
| | | @Autowired |
| | | IMasterAuthorDetailService masterAuthorDetailService; |
| | | @Autowired |
| | | RedisClient redisClient; |
| | | /** |
| | | * |
| | | * @description: 获取下一版本信息 |
| | | * @param tableName 表名 |
| | | * @param userId 用户id |
| | | * @return: 字段版本对象 |
| | | * |
| | | */ |
| | | @Override |
| | | public MaintainField getNextMaintain(String tableName, String userId) { |
| | | MaintainField maintain = this.getMaxVersion(tableName); |
| | |
| | | } |
| | | return nowMaintain; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过字段版本获取对应的数据版本list |
| | | * @param tableName 表名 |
| | | * @return 数据版本列表 |
| | | * |
| | | */ |
| | | @Override |
| | | public List<Maintain> getMaintainByMaintainField(String maintainFieldId, String tableName) { |
| | | HashMap<String, List<Maintain>> resultMap = getMaintainFieldMapByTable(tableName); |
| | | if (resultMap == null) { |
| | | return null; |
| | | } |
| | | if (maintainFieldId == null) { |
| | | return null; |
| | | } |
| | | if (maintainFieldId.equalsIgnoreCase(Constant.All)) { |
| | | Collection<List<Maintain>> values = resultMap.values(); |
| | | HashSet<Maintain> maintains = new HashSet<>(); |
| | | for (List<Maintain> value : values) { |
| | | maintains.addAll(value); |
| | | } |
| | | |
| | | return new ArrayList<>(maintains); |
| | | } |
| | | return resultMap.get(maintainFieldId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean checkNowVersion(String maintainFieldId) { |
| | | MaintainField maintain = selectById(maintainFieldId); |
| | | MaintainField maxVersion = getNowVersion(maintain.getTableName()); |
| | | Integer compared = DbUtils.compareVersion(maxVersion, maintain); |
| | | if (compared != null && compared == 0) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean checkFirstVersion(String id) { |
| | | MaintainField maintain = selectById(id); |
| | | MaintainField order_no = selectOne(new EntityWrapper<MaintainField>().eq("table_name", maintain.getTableName()).orderBy("order_no")); |
| | | if (maintain.getId().equalsIgnoreCase(order_no.getId())) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public boolean checkdMaxVersion(String maintainFieldId) { |
| | | MaintainField maintain = selectById(maintainFieldId); |
| | | MaintainField maxVersion = getMaxVersion(maintain.getTableName()); |
| | | Integer compared = DbUtils.compareVersion(maxVersion, maintain); |
| | | if (compared == 0) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取最大的字段版本 |
| | | * @param tableName 表名 |
| | | * @return 字段版本对象 |
| | | * |
| | | */ |
| | | @Override |
| | | public MaintainField getMaxVersion(String tableName) { |
| | | Wrapper<MaintainField> versionWrapper = new EntityWrapper<MaintainField>().eq("table_name", tableName).orderBy("order_no desc"); |
| | |
| | | MaintainField maxVersion = this.selectOne(versionWrapper); |
| | | return maxVersion; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取未生效的最大版本 |
| | | * @param tableName 表名 |
| | | * @return 字段版本对象 |
| | | * |
| | | */ |
| | | @Override |
| | | public MaintainField getUnFlowMaxVersion(String tableName) { |
| | | Wrapper<MaintainField> versionWrapper = new EntityWrapper<MaintainField>().isNull("flow_id").eq("table_name", tableName).orderBy("order_no desc"); |
| | |
| | | MaintainField maxVersion = selectOne(versionWrapper); |
| | | return maxVersion; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取当前正在用的字段版本对象 |
| | | * @param tableName 表名 |
| | | * @return 字段版本对象 |
| | | * |
| | | */ |
| | | @Override |
| | | public MaintainField getNowVersion(String tableName) { |
| | | Wrapper<MaintainField> versionWrapper = new EntityWrapper<MaintainField>().eq("table_name", tableName).isNotNull("flow_id").orderBy("order_no desc"); |
| | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public MaintainField getMaintainFromVersion(String tableName, String verison) { |
| | | Wrapper<MaintainField> versionWrapper = new EntityWrapper<MaintainField>().eq("version", verison).eq("table_name", tableName); |
| | | MaintainField maxVersion = selectOne(versionWrapper); |
| | | return maxVersion; |
| | | } |
| | | /** |
| | | * |
| | | * @description: 流程完成后的处理 |
| | | * @param maintainId 字段版本 |
| | | * @param status 流程状态 |
| | | * |
| | | */ |
| | | |
| | | @Override |
| | | public void dealFlow(String maintainId, ActivitiStatus status) { |
| | |
| | | |
| | | Integer orderNo = maintainField.getOrderNo(); |
| | | int preNo = orderNo - 1; |
| | | if (preNo< 0) { |
| | | return; |
| | | MaintainField preMaintainField; |
| | | if (preNo < 0 ) { |
| | | preMaintainField = new MaintainField().setId(Constant.Default); |
| | | }else { |
| | | preMaintainField = selectOne(new EntityWrapper<MaintainField>() |
| | | .eq("table_name", maintainField.getTableName()) |
| | | .eq("order_no", preNo)); |
| | | } |
| | | MaintainField preMaintainField = selectOne(new EntityWrapper<MaintainField>() |
| | | .eq("table_name", maintainField.getTableName()) |
| | | .eq("order_no", preNo)); |
| | | |
| | | if (preMaintainField == null){ |
| | | return; |
| | | } |
| | |
| | | .eq("maintain_auto", true) |
| | | .eq("table_name", maintainField.getTableName()) |
| | | .eq("maintain_field_id", preMaintainField.getId())); |
| | | if (masterAuthors.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<SysField> fieldList = fieldService.selectList(new EntityWrapper<SysField>().eq("maintain_field_id", maintainField.getId())); |
| | | |
| | | List<SysField> deleteList = fieldList.stream().filter(sysField -> Operate.delete.equals(sysField.getOperate())).collect(Collectors.toList()); |
| | |
| | | |
| | | for (MasterAuthor masterAuthor : masterAuthors) { |
| | | Boolean fieldAuto = masterAuthor.getFieldAuto(); |
| | | |
| | | List<MasterAuthorDetail> masterAuthorDetails = masterAuthorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId())); |
| | | |
| | | masterAuthor.setMaintainFieldId(maintainField.getId()) |
| | | .setCreateTime(new Date()) |
| | | .setUpdateTime(null) |
| | | .setId(DbUtils.getUUID()) |
| | | .insert(); |
| | | List<MasterAuthorDetail> masterAuthorDetails = masterAuthorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, preMaintainField.getId())); |
| | | |
| | | for (MasterAuthorDetail masterAuthorDetail : masterAuthorDetails) { |
| | | masterAuthorDetail.setParentId(maintainField.getId()).setId(DbUtils.getUUID()).insert(); |
| | | long count = deleteList.stream().filter(sysField -> sysField.getField().equalsIgnoreCase(masterAuthorDetail.getField())).count(); |
| | | if (count > 0) { |
| | | continue; |
| | | } |
| | | masterAuthorDetail.setParentId(masterAuthor.getId()).setId(DbUtils.getUUID()).insert(); |
| | | } |
| | | |
| | | if (fieldAuto) { |
| | | for (String s : createFieldList) { |
| | | new MasterAuthorDetail().setField(s).setVal(Constant.z_AllVal).setAll(true).setParentId(maintainField.getId()).setId(DbUtils.getUUID()).insert(); |
| | | new MasterAuthorDetail().setField(s).setVal(Constant.z_AllVal).setAll(true).setParentId(masterAuthor.getId()).setId(DbUtils.getUUID()).insert(); |
| | | } |
| | | } |
| | | } |
| | |
| | | maintainFieldMapper.addCloumn(tableName, field.getField(), fieldTypeStr); |
| | | |
| | | field.setOperate(null).updateById(); |
| | | |
| | | redisClient.delByField(); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取未生效的版本数量 |
| | | * @param tableName 表名 |
| | | * @return 未生效版本数量 |
| | | * |
| | | */ |
| | | @Override |
| | | public int getUnFlowCount(String tableName, String userId) { |
| | | List<MaintainField> maintainFields = selectList(new EntityWrapper<MaintainField>().eq("table_name", tableName)); |
| | |
| | | } |
| | | return cnt; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过表名获取字段版本,数据版本的map list |
| | | * @param tableName 表名 |
| | | * @return 字段版本,数据版本的map list |
| | | * |
| | | */ |
| | | @Override |
| | | public JSONArray getMaintainListByTable(String tableName) { |
| | | HashMap<String, List<Maintain>> resultMap = getMaintainFieldMapByTable(tableName); |
| | |
| | | } |
| | | return array; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过表名和字段版本获取数据版本list |
| | | * @param tableName 表名 |
| | | * @param id 字段版本id |
| | | * @return 数据版本list |
| | | * |
| | | */ |
| | | @Override |
| | | public List<Maintain> getMaintainListByMaintainField(String id, String tableName) { |
| | | MaintainField maintainField = selectById(id); |
| | | if (maintainField == null) { |
| | | if (!id.equalsIgnoreCase(Constant.Default)){ |
| | | if (!id.equalsIgnoreCase(Constant.Default) && !id.equalsIgnoreCase(Constant.All)){ |
| | | return null; |
| | | }else { |
| | | maintainField = new MaintainField().setId(Constant.Default).setTableName(tableName); |
| | | maintainField = new MaintainField().setId(id).setTableName(tableName); |
| | | } |
| | | |
| | | } |
| | | |
| | | return getMaintainByMaintainField(maintainField.getId(), maintainField.getTableName()); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过表名获取字段版本,数据版本的map list |
| | | * @param tableName 表名 |
| | | * @return 字段版本,数据版本的map list |
| | | * |
| | | */ |
| | | private HashMap<String, List<Maintain>> getMaintainFieldMapByTable(String tableName) { |
| | | List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).isNotNull("flow_id").orderBy("order_no desc")); |
| | | HashMap<String, List<Maintain>> resultMap = new HashMap<>(); |
| | | for (Maintain maintain : maintainList) { |
| | | ActivitiStatus status = flowsService.getStatusByBusinessId(maintain.getId()); |
| | | if (!status.equals(ActivitiStatus.open)) { |
| | | if (!ActivitiStatus.open.equals(status)) { |
| | | continue; |
| | | } |
| | | MaintainField maintainFieldByMaintain = fieldService.getMaintainFieldByMaintain(maintain.getId()); |