| | |
| | | @Override |
| | | @Async |
| | | public void dealFlow(String maintainId, ActivitiStatus status) { |
| | | Maintain maintain = maintainService.selectById(maintainId); |
| | | if (maintain == null) { |
| | | return; |
| | | } |
| | | String tableName = maintain.getTableName(); |
| | | String recordTableName = tableName + Constant.RECORD; |
| | | List<Map<String,String>> modifiedList = masterModifiedMapper.selectByMaintainId(recordTableName, DbUtils.quotedStr(maintainId)); |
| | | switch (status) { |
| | | case open: |
| | | for (Map<String, String> masterModifiedMap : modifiedList) { |
| | | String preJson = masterModifiedMap.get(pre_record); |
| | | JSONObject jsonObject = JSONObject.parseObject(preJson); |
| | | if (jsonObject == null){ |
| | | continue; |
| | | } |
| | | Set<String> keySet = jsonObject.keySet(); |
| | | HashMap<String, String> userMap = new HashMap<>(); |
| | | for (String field : keySet) { |
| | | String userId = jsonObject.getString(field); |
| | | if (userMap.containsKey(userId)) { |
| | | String preFieldStr = userMap.get(userId); |
| | | field = preFieldStr + Constant.SEMICOLON + field; |
| | | } |
| | | userMap.put(userId, field); |
| | | } |
| | | List<TableSchemaResult> tableField = tableInfoMapper.getTableField(master_modified); |
| | | List<String> existsFieldList = tableField.stream().map(TableSchemaResult::getFieldName).collect(Collectors.toList()); |
| | | Set<String> userIdList = userMap.keySet(); |
| | | |
| | | if (!existsFieldList.containsAll(userIdList)) { |
| | | //新增之前不存在的用户 |
| | | List<String> unExistsUserList = userIdList.stream().filter(s -> !existsFieldList.contains(s)).collect(Collectors.toList()); |
| | | for (String s : unExistsUserList) { |
| | | //新增字段 |
| | | maintainFieldMapper.addCloumn(master_modified, s, Constant.Text); |
| | | } |
| | | } |
| | | masterModifiedMap.putAll(userMap); |
| | | updateById(masterModifiedMap); |
| | | } |
| | | break; |
| | | case close: |
| | | List<String> unUserIdList = new ArrayList<>(); |
| | | unUserIdList.add(Constant.ID); |
| | | unUserIdList.add(master_id); |
| | | unUserIdList.add(table_name); |
| | | unUserIdList.add(pre_record); |
| | | for (Map<String, String> masterModifiedMap : modifiedList) { |
| | | //todo 反更新 perjson 获取当前表所有可更改的用户 之后待修改 先从本地user表中拿 |
| | | Set<String> keySet = masterModifiedMap.keySet(); |
| | | List<String> userIdList = keySet.stream().filter(s -> !unUserIdList.contains(s)).collect(Collectors.toList()); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | for (String s : userIdList) { |
| | | String fields = masterModifiedMap.get(s); |
| | | if (StringUtils.isEmpty(fields)) { |
| | | try { |
| | | Maintain maintain = maintainService.selectById(maintainId); |
| | | if (maintain == null) { |
| | | return; |
| | | } |
| | | String tableName = maintain.getTableName(); |
| | | String recordTableName = tableName + Constant.RECORD; |
| | | List<Map<String,String>> modifiedList = masterModifiedMapper.selectByMaintainId(recordTableName, DbUtils.quotedStr(maintainId)); |
| | | switch (status) { |
| | | case open: |
| | | for (Map<String, String> masterModifiedMap : modifiedList) { |
| | | String preJson = masterModifiedMap.get(pre_record); |
| | | JSONObject jsonObject = JSONObject.parseObject(preJson); |
| | | if (jsonObject == null){ |
| | | continue; |
| | | } |
| | | String[] split = fields.split(Constant.SEMICOLON); |
| | | for (String field : split) { |
| | | jsonObject.fluentPut(field, s); |
| | | Set<String> keySet = jsonObject.keySet(); |
| | | HashMap<String, String> userMap = new HashMap<>(); |
| | | for (String field : keySet) { |
| | | String userId = jsonObject.getString(field); |
| | | if (userMap.containsKey(userId)) { |
| | | String preFieldStr = userMap.get(userId); |
| | | field = preFieldStr + Constant.SEMICOLON + field; |
| | | } |
| | | userMap.put(userId, field); |
| | | } |
| | | List<TableSchemaResult> tableField = tableInfoMapper.getTableField(master_modified); |
| | | List<String> existsFieldList = tableField.stream().map(TableSchemaResult::getFieldName).collect(Collectors.toList()); |
| | | Set<String> userIdList = userMap.keySet(); |
| | | |
| | | if (!existsFieldList.containsAll(userIdList)) { |
| | | //新增之前不存在的用户 |
| | | List<String> unExistsUserList = userIdList.stream().filter(s -> !existsFieldList.contains(s)).collect(Collectors.toList()); |
| | | for (String s : unExistsUserList) { |
| | | //新增字段 |
| | | maintainFieldMapper.addCloumn(master_modified, s, Constant.Text); |
| | | } |
| | | } |
| | | masterModifiedMap.putAll(userMap); |
| | | updateById(masterModifiedMap); |
| | | } |
| | | masterModifiedMap.put(pre_record, jsonObject.toJSONString()); |
| | | updateById(masterModifiedMap); |
| | | } |
| | | break; |
| | | break; |
| | | case close: |
| | | List<String> unUserIdList = new ArrayList<>(); |
| | | unUserIdList.add(Constant.ID); |
| | | unUserIdList.add(master_id); |
| | | unUserIdList.add(table_name); |
| | | unUserIdList.add(pre_record); |
| | | for (Map<String, String> masterModifiedMap : modifiedList) { |
| | | //todo 反更新 perjson 获取当前表所有可更改的用户 之后待修改 先从本地user表中拿 |
| | | Set<String> keySet = masterModifiedMap.keySet(); |
| | | List<String> userIdList = keySet.stream().filter(s -> !unUserIdList.contains(s)).collect(Collectors.toList()); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | for (String s : userIdList) { |
| | | String fields = masterModifiedMap.get(s); |
| | | if (StringUtils.isEmpty(fields)) { |
| | | continue; |
| | | } |
| | | String[] split = fields.split(Constant.SEMICOLON); |
| | | for (String field : split) { |
| | | jsonObject.fluentPut(field, s); |
| | | } |
| | | } |
| | | masterModifiedMap.put(pre_record, jsonObject.toJSONString()); |
| | | updateById(masterModifiedMap); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |