| | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.highdatas.mdm.entity.Flows; |
| | | import com.highdatas.mdm.entity.Maintain; |
| | | import com.highdatas.mdm.entity.MaintainField; |
| | | import com.highdatas.mdm.entity.SysField; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.mapper.MaintainFieldMapper; |
| | | import com.highdatas.mdm.pojo.ActivitiStatus; |
| | | import com.highdatas.mdm.pojo.Operate; |
| | | import com.highdatas.mdm.service.IFlowsService; |
| | | import com.highdatas.mdm.service.IMaintainFieldService; |
| | | import com.highdatas.mdm.service.IMaintainService; |
| | | import com.highdatas.mdm.service.ISysFieldService; |
| | | 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; |
| | |
| | | IFlowsService flowsService; |
| | | @Autowired |
| | | ISysFieldService fieldService; |
| | | |
| | | @Autowired |
| | | MaintainFieldMapper maintainFieldMapper; |
| | | |
| | | @Autowired |
| | | 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) { |
| | |
| | | maintainField.deleteById(); |
| | | } |
| | | else if (status.equals(ActivitiStatus.open)) { |
| | | |
| | | Integer orderNo = maintainField.getOrderNo(); |
| | | int preNo = orderNo - 1; |
| | | 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)); |
| | | } |
| | | |
| | | if (preMaintainField == null){ |
| | | return; |
| | | } |
| | | List<MasterAuthor> masterAuthors = masterAuthorService.selectList( |
| | | new EntityWrapper<MasterAuthor>() |
| | | .eq("maintain_auto", true) |
| | | .eq("table_name", maintainField.getTableName()) |
| | | .eq("maintain_field_id", preMaintainField.getId())); |
| | | |
| | | List<SysField> fieldList = fieldService.selectList(new EntityWrapper<SysField>().eq("maintain_field_id", maintainField.getId())); |
| | | |
| | | List<SysField> collect = fieldList.stream().filter(sysField -> Operate.delete.equals(sysField.getOperate())).collect(Collectors.toList()); |
| | | //delete |
| | | for (SysField field : collect) { |
| | | List<SysField> deleteList = fieldList.stream().filter(sysField -> Operate.delete.equals(sysField.getOperate())).collect(Collectors.toList()); |
| | | List<SysField> updateList = fieldList.stream().filter(sysField -> (Operate.update.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | List<SysField> createList = fieldList.stream().filter(sysField -> (Operate.create.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | |
| | | List<String> createFieldList = createList.stream().map(sysField -> sysField.getField()).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(); |
| | | |
| | | for (MasterAuthorDetail masterAuthorDetail : masterAuthorDetails) { |
| | | 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(masterAuthor.getId()).setId(DbUtils.getUUID()).insert(); |
| | | } |
| | | } |
| | | } |
| | | // |
| | | |
| | | |
| | | //delete |
| | | for (SysField field : deleteList) { |
| | | field.deleteById(); |
| | | } |
| | | //update |
| | | List<SysField> updateList = fieldList.stream().filter(sysField -> (Operate.update.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | for (SysField field : updateList) { |
| | | field.setOperate(null).updateById(); |
| | | } |
| | | List<SysField> createList = fieldList.stream().filter(sysField -> (Operate.create.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | for (SysField field : createList) { |
| | | for (SysField field : createList) { |
| | | String fieldType = field.getFieldType(); |
| | | if (StringUtils.isEmpty(fieldType)) { |
| | | fieldType = Constant.varchar; |
| | |
| | | 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); |
| | | |
| | | Set<String> keySet = resultMap.keySet(); |
| | | ArrayList<String> keys = new ArrayList<>(keySet); |
| | | Collections.sort(keys, new Comparator<String>() { |
| | | @Override |
| | | public int compare(String maintianFieldId1, String maintianFieldId2) { |
| | | MaintainField maintainField1 = selectById(maintianFieldId1); |
| | | MaintainField maintainField2 = selectById(maintianFieldId2); |
| | | if (maintainField1 == null) { |
| | | return 1; |
| | | } |
| | | if (maintainField2 == null){ |
| | | return -1; |
| | | } |
| | | |
| | | return maintainField1.getOrderNo().compareTo(maintainField2.getOrderNo()); |
| | | } |
| | | }); |
| | | |
| | | JSONArray array = new JSONArray(); |
| | | for (String s : keySet) { |
| | | for (String s : keys) { |
| | | List<Maintain> list = resultMap.get(s); |
| | | Maintain max = list.stream().max(new Comparator<Maintain>() { |
| | | @Override |
| | |
| | | JSONObject object = new JSONObject(); |
| | | object.fluentPut("maintainFieldId", s); |
| | | object.fluentPut("version", MessageFormat.format(Constant.extent, min.getVersion(), max.getVersion())); |
| | | object.fluentPut("list", list); |
| | | |
| | | array.add(object); |
| | | } |
| | | 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) && !id.equalsIgnoreCase(Constant.All)){ |
| | | return null; |
| | | }else { |
| | | 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")); |
| | | 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()); |