| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.highdatas.mdm.entity.Character; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.mapper.TableInfoMapper; |
| | | import com.highdatas.mdm.pojo.*; |
| | | import com.highdatas.mdm.service.*; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.ContentBuilder; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import com.highdatas.mdm.util.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.mybatis.spring.SqlSessionTemplate; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.sql.DataSource; |
| | | import java.sql.Connection; |
| | | import java.sql.SQLException; |
| | | import java.text.MessageFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author kimi |
| | | * @description |
| | |
| | | */ |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class MasterDataServiceImpl implements MasterDataService { |
| | | @Autowired |
| | | IMenuMappingService menuMappingService; |
| | |
| | | IMaintainDetailService maintainDetailService; |
| | | @Autowired |
| | | IFlowsService flowsService; |
| | | @Autowired |
| | | RedisClient redisClient; |
| | | @Autowired |
| | | IMaintainFieldService maintainFieldService; |
| | | @Autowired |
| | | IMasterAuthorService masterAuthorService; |
| | | @Autowired |
| | | SqlSessionFactory sqlSessionFactory; |
| | | @Resource |
| | | protected SqlSessionTemplate sqlSessionTemplate; |
| | | protected DataSource dataSource; |
| | | @Autowired |
| | | AntianaphylaxisClient antianaphylaxisClient; |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据表名和id获取数据 |
| | | * @param tableName 表名 |
| | | * @param id 数据id |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectById(String tableName, String id) { |
| | | try{ |
| | |
| | | return Result.error(CodeMsg.SELECT_ERROR); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据用户和表名获取数据 |
| | | * @param tableName 表名 |
| | | * @param character 用户 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectList(String tableName) { |
| | | return selectList(tableName, null,null, (maintainService.getNowVersion(tableName).getVersion())); |
| | | public Result selectList(Character character, String tableName) { |
| | | return selectList(character, tableName, null,null, (maintainService.getNowVersion(tableName).getVersion())); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据用户和表名,筛选条件获取数据 |
| | | * @param tableName 表名 |
| | | * @param whereSegment 筛选条件 |
| | | * @param character 用户 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectList(String tableName, String whereSegment) { |
| | | return selectList(tableName, whereSegment, (maintainService.getNowVersion(tableName).getVersion())); |
| | | public Result selectList(Character character, String tableName, String whereSegment) { |
| | | return selectList(character,tableName, whereSegment, (maintainService.getNowVersion(tableName).getVersion())); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据用户和表名,筛选条件,数据版本获取数据 |
| | | * @param tableName 表名 |
| | | * @param whereSegment 筛选条件 |
| | | * @param version 数据版本 |
| | | * @param character 用户 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectList(String tableName, String whereSegment, String version) { |
| | | return selectList(tableName, null, whereSegment, version); |
| | | public Result selectList(Character character,String tableName, String whereSegment, String version) { |
| | | return selectList(character, tableName, null, whereSegment, version); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据用户,字段,表名,筛选条件获取数据 |
| | | * @param tableName 表名 |
| | | * @param whereSegment 筛选条件 |
| | | * @param fieldList 字段 |
| | | * @param character 用户 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectList(String tableName, List<String> fieldList, String whereSegment) { |
| | | return selectList(tableName, fieldList, whereSegment, maintainService.getNowVersion(tableName).getVersion()); |
| | | public Result selectList(Character character, String tableName, List<String> fieldList, String whereSegment) { |
| | | return selectList(character, tableName, fieldList, whereSegment, maintainService.getNowVersion(tableName).getVersion()); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据用户,字段,表名,筛选条件,数据版本获取数据 |
| | | * @param tableName 表名 |
| | | * @param whereSegment 筛选条件 |
| | | * @param fieldList 字段 |
| | | * @param version 数据版本 |
| | | * @param character 用户 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectList(String tableName,List<String> fieldList, String whereSegment, String version) { |
| | | public Result selectList(Character character, String tableName,List<String> fieldList, String whereSegment, String version) { |
| | | try{ |
| | | JSONObject object = new JSONObject(); |
| | | |
| | | //TODO only add version |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | String fields; |
| | | if (fieldList == null || fieldList.size() == 0) { |
| | | fields = getFields(tableName); |
| | | fields = getFields(character, tableName, maintainFromVersion); |
| | | } else { |
| | | fields = fieldList.stream().collect(Collectors.joining(Constant.COMMA)); |
| | | } |
| | | //std |
| | | List<Map<String, Object>> select = mapper.select(tableName, fields, whereSegment); |
| | | //TODO only add version |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | |
| | | List<Map<String, Object>> maps = maintainService.selectVersionOperatorByType(tableName, maintainFromVersion.getId(), Operate.create); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据用户,字段,表名获取数据 |
| | | * @param tableName 表名 |
| | | * @param fieldList 字段 |
| | | * @param character 用户 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectList(String tableName, List<String> fields) { |
| | | return selectList(tableName,fields,Constant.WHERE_DEFAULT,(maintainService.getNowVersion(tableName).getVersion())); |
| | | public Result selectList(Character character, String tableName, List<String> fields) { |
| | | return selectList(character, tableName,fields,Constant.WHERE_DEFAULT,(maintainService.getNowVersion(tableName).getVersion())); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据表名,筛选条件获取数据条数 |
| | | * @param tableName 表名 |
| | | * @param whereSegment 筛选条件 |
| | | * @return: 数据条数 |
| | | * |
| | | */ |
| | | public Long getCount(String tableName, String whereSegment) { |
| | | try{ |
| | | if (StringUtils.isEmpty(whereSegment)) { |
| | |
| | | return null; |
| | | } |
| | | } |
| | | public Long getCountByVersion (String maintainId, String tableName,String tableTempName,Integer fromOrderNo, Integer toOrderNo, String whereSegment) { |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据条数 |
| | | * @param maintainId 数据版本 |
| | | * @param tableName 表名 |
| | | * @param tableTempName 临时表名 |
| | | * @param whereSegment 筛选条件 |
| | | * @param fieldList 字段 |
| | | * @param version 数据版本 |
| | | * @param character 用户 |
| | | * @param fromOrderNo 从哪个版本开始往前推 |
| | | * @param toOrderNo 到哪个版本结束往前推 |
| | | * @return: 数据条数 |
| | | * |
| | | */ |
| | | @Override |
| | | public Long getCountByVersion (Character character, String maintainId, String tableName,String tableTempName,Integer fromOrderNo, Integer toOrderNo, String whereSegment) { |
| | | try{ |
| | | String fields = getFields(tableName); |
| | | String Hfields = getFields(tableName, Constant.H); |
| | | String tempFields = getTempFields(tableName); |
| | | String A1fields = getFields(tableName, Constant.A1); |
| | | String A2fields = getFields(tableName, Constant.A2); |
| | | String tempHFields = getTempFields(tableName, Constant.H); |
| | | Maintain maintain = maintainService.selectById(maintainId); |
| | | String fields = getFields(character,tableName, maintain); |
| | | String tempFields = getTempFields(character, tableName, Constant.A1, maintain); |
| | | String A1fields = getFields(character, tableName, Constant.A1, maintain); |
| | | |
| | | if (StringUtils.isEmpty(whereSegment)) { |
| | | whereSegment = Constant.WHERE_DEFAULT; |
| | | } |
| | | Long count = mapper.getCountByVersion(tableName, tableTempName, fields, tempFields, Hfields, A1fields,A2fields,tempHFields, fromOrderNo, toOrderNo, DbUtils.quotedStr(maintainId), whereSegment); |
| | | Long count; |
| | | if (StringUtils.isEmpty(fields)) { |
| | | return 0L; |
| | | } |
| | | count = mapper.getCountByVersion(tableName, tableTempName, fields, tempFields, A1fields,fromOrderNo, toOrderNo, whereSegment); |
| | | return count; |
| | | } |
| | | catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取最大版本的数据条数 |
| | | * @param maintainId 数据版本 |
| | | * @param tableName 表名 |
| | | * @param tableTempName 临时表名 |
| | | * @param whereSegment 筛选条件 |
| | | * @param fieldList 字段 |
| | | * @param version 数据版本 |
| | | * @param character 用户 |
| | | * @return: 数据条数 |
| | | * |
| | | */ |
| | | public Long getCountByMaxVersion (Character character, String maintainId, String tableName,String tableTempName,Integer fromOrderNo, String whereSegment) { |
| | | try{ |
| | | Maintain maintain = maintainService.selectById(maintainId); |
| | | |
| | | String fields = getFields(character, tableName, maintain); |
| | | |
| | | String tempFields = getTempFields(character, tableName, Constant.A1, maintain); |
| | | String A1fields = getFields(character, tableName, Constant.A1, maintain); |
| | | |
| | | if (StringUtils.isEmpty(whereSegment)) { |
| | | whereSegment = Constant.WHERE_DEFAULT; |
| | | } |
| | | |
| | | Long count = mapper.getCountByMaxVersion(tableName, tableTempName, fields, tempFields, A1fields, fromOrderNo, whereSegment); |
| | | return count; |
| | | } |
| | | catch (Exception e) { |
| | |
| | | } |
| | | } |
| | | |
| | | public Long getCountByMaxVersion (String maintainId, String tableName,String tableTempName,Integer fromOrderNo, Integer toOrderNo, String whereSegment) { |
| | | try{ |
| | | String fields = getFields(tableName); |
| | | String Hfields = getFields(tableName, Constant.H); |
| | | String tempFields = getTempFields(tableName); |
| | | String A1fields = getFields(tableName, Constant.A1); |
| | | String A2fields = getFields(tableName, Constant.A2); |
| | | String tempHFields = getTempFields(tableName, Constant.H); |
| | | if (StringUtils.isEmpty(whereSegment)) { |
| | | whereSegment = Constant.WHERE_DEFAULT; |
| | | } |
| | | Long count = mapper.getCountByMaxVersion(tableName, tableTempName, fields, tempFields, Hfields, A1fields,A2fields,tempHFields, fromOrderNo, toOrderNo, DbUtils.quotedStr(maintainId), whereSegment); |
| | | return count; |
| | | } |
| | | catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据表名获取字段sql |
| | | * @param tableName 表名 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getFields(String tableName) { |
| | | return getFields(tableName, null); |
| | | return getFields(tableName, Constant.EMPTY_Str); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本获取字段sql |
| | | * @param tableName 表名 |
| | | * @param character 用户 |
| | | * @param maintain 版本 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getFields(Character character, String tableName, Maintain maintain) { |
| | | |
| | | return getFields(character, tableName, null, maintain); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本获取字段sql |
| | | * @param tableName 表名 |
| | | * @param character 用户 |
| | | * @param maintain 版本 |
| | | * @param uuid 请求唯一标识,log中查询时间使用 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getFields(Character character, String tableName, Maintain maintain, String uuid) { |
| | | |
| | | return getFields(character, tableName, null, maintain, uuid); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本组装 casewhen 字段sql |
| | | * @param tableName 表名 |
| | | |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | private String getCaseWhenFields(String tableName) { |
| | | List<TableSchemaResult> tableField = mapper.getTableField(tableName); |
| | | ContentBuilder contentBuilder = new ContentBuilder(Constant.COMMA); |
| | |
| | | } |
| | | return contentBuilder.toString(); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据表名 ,获取字段sql并添加别名 |
| | | * @param tableName 表名 |
| | | * @param alias 别名 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getFields(String tableName, String alias) { |
| | | List<TableSchemaResult> tableField = mapper.getTableField(tableName); |
| | |
| | | } |
| | | return contentBuilder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本获取字段sql,并添加别名 |
| | | * @param tableName 表名 |
| | | * @param character 用户 |
| | | * @param maintain 版本 |
| | | * @param alias 别名 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getTempFields(String tableName) { |
| | | return getTempFields(tableName, null); |
| | | public String getFields(Character character, String tableName, String alias, Maintain maintain) { |
| | | return getFields(character, tableName, alias, maintain, null); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本获取字段sql,并添加别名 |
| | | * @param tableName 表名 |
| | | * @param character 用户 |
| | | * @param maintain 版本 |
| | | * @param alias 别名 |
| | | * @param uuid 请求唯一标识,log中查询时间使用 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getTempFields(String tableName, String alias) { |
| | | public String getFields(Character character, String tableName, String alias, Maintain maintain, String uuid) { |
| | | List<SysField> fields; |
| | | if (character == null) { |
| | | fields = fieldService.getFieldByMaintain(maintain.getId()); |
| | | }else { |
| | | fields = masterAuthorService.getField(character, maintain.getId(), uuid); |
| | | } |
| | | ContentBuilder contentBuilder = new ContentBuilder(Constant.COMMA); |
| | | if (fields == null) { |
| | | return Constant.EMPTY_Str; |
| | | } |
| | | if (!fields.contains(Constant.ID)) { |
| | | fields.add(new SysField().setField(Constant.ID)); |
| | | } |
| | | |
| | | for (SysField field : fields) { |
| | | String fieldName = field.getField(); |
| | | if (fieldName.equalsIgnoreCase(Constant.DEAL)) { |
| | | //DEAL 不给看 |
| | | continue; |
| | | } |
| | | if (StringUtils.isEmpty(alias)) { |
| | | contentBuilder.append(fieldName); |
| | | } else { |
| | | contentBuilder.append(MessageFormat.format(Constant.Alias,alias,fieldName)); |
| | | } |
| | | |
| | | } |
| | | |
| | | return contentBuilder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本获取临时表字段sql,并添加别名 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param maintain 版本 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getTempFields(Character character, String tableName, Maintain maintain) { |
| | | return getTempFields(character, tableName, null, maintain); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本获取临时表字段sql,并添加别名 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getTempFields(Character character, String tableName) { |
| | | return getTempFields(character, tableName, Constant.EMPTY_Str); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户获取临时表字段sql,并添加自定义别名 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param alias 别名 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public String getTempFields(Character character, String tableName, String alias) { |
| | | List<TableSchemaResult> tableField = mapper.getTableField(tableName); |
| | | |
| | | ContentBuilder contentBuilder = new ContentBuilder(Constant.COMMA); |
| | | for (TableSchemaResult tableSchemaResult : tableField) { |
| | | String fieldName = tableSchemaResult.getFieldName(); |
| | |
| | | } |
| | | return contentBuilder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 根据表名 用户, 版本获取临时表字段sql,并添加自定义别名 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param maintain 版本 |
| | | * @param alias 别名 |
| | | * @return: 字段sql |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, Integer pageNo, Integer pageSize, boolean findMax) { |
| | | return selectListByPageByVersion(tableName,Constant.WHERE_DEFAULT,pageNo,pageSize, findMax); |
| | | public String getTempFields(Character character, String tableName, String alias, Maintain maintain) { |
| | | List<SysField> fields; |
| | | if (character == null) { |
| | | fields = fieldService.getFieldByMaintain(maintain.getId()); |
| | | }else { |
| | | fields = masterAuthorService.getField(character, maintain.getId()); |
| | | } |
| | | if (fields == null) { |
| | | return Constant.EMPTY_Str; |
| | | } |
| | | ContentBuilder contentBuilder = new ContentBuilder(Constant.COMMA); |
| | | if (!fields.contains(Constant.ID)) { |
| | | fields.add(new SysField().setField(Constant.ID)); |
| | | } |
| | | List<String> joinFieldList = getJoinFieldList(); |
| | | |
| | | for (SysField field : fields) { |
| | | String fieldName = field.getField(); |
| | | if (fieldName.equalsIgnoreCase(Constant.ID)) { |
| | | if (StringUtils.isEmpty(alias)) { |
| | | contentBuilder.append(MessageFormat.format("{0} as id", Constant.STD_ID)); |
| | | } else { |
| | | if (joinFieldList.contains(fieldName)) { |
| | | contentBuilder.append(MessageFormat.format("{0}.{1} as id", alias, Constant.STD_ID)); |
| | | } else { |
| | | contentBuilder.append(MessageFormat.format("{0} as id", Constant.STD_ID)); |
| | | } |
| | | |
| | | } |
| | | continue; |
| | | } |
| | | if (StringUtils.isEmpty(alias)) { |
| | | contentBuilder.append(fieldName); |
| | | } else { |
| | | if (joinFieldList.contains(fieldName)) { |
| | | contentBuilder.append(MessageFormat.format(Constant.Alias,alias,fieldName)); |
| | | } else { |
| | | contentBuilder.append(fieldName); |
| | | } |
| | | } |
| | | } |
| | | return contentBuilder.toString(); |
| | | } |
| | | |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, String whereSegment, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(tableName,null, whereSegment,pageNo, null, String.valueOf(maintainService.getNowVersion(tableName).getVersion()), findMax); |
| | | private List<String> getJoinFieldList() { |
| | | List<TableSchemaResult> fieldList = new ArrayList<>(); |
| | | List<TableSchemaResult> maintainList = mapper.getTableField("maintain"); |
| | | if (maintainList != null) { |
| | | fieldList.addAll(maintainList); |
| | | } |
| | | List<TableSchemaResult> flows = mapper.getTableField("flows"); |
| | | if (flows != null) { |
| | | fieldList.addAll(flows); |
| | | } |
| | | List<TableSchemaResult> maintain_detail = mapper.getTableField("maintain_detail"); |
| | | if (maintain_detail != null) { |
| | | fieldList.addAll(maintain_detail); |
| | | } |
| | | return fieldList.stream().map(tableSchemaResult -> tableSchemaResult.getFieldName()).collect(Collectors.toList()); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param pageNo 页数 |
| | | * @param pageSize 每页数据量 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, Integer pageNo, Integer pageSize, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName,Constant.WHERE_DEFAULT,pageNo,pageSize, findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param pageSize 每页数据量 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, String whereSegment, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName,null, whereSegment,pageNo, null, String.valueOf(maintainService.getNowVersion(tableName).getVersion()), findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param pageNo 页数 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @param uuid 请求唯一标识,log中查询时间使用 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, Integer pageNo, String version, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName,null,Constant.WHERE_DEFAULT,pageNo, null, version, findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param pageNo 页数 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName,null,Constant.WHERE_DEFAULT,pageNo, null, String.valueOf(maintainService.getNowVersion(tableName).getVersion()), findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param pageSize 每页数据量 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, String whereSegment, Integer pageNo, Integer pageSize, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName,null,whereSegment,pageNo,pageSize, findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param fieldList 筛选字段 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param pageSize 每页数据量 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, List<String> fieldList, String whereSegment, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName,null,whereSegment,pageNo, null, findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param fieldList 字段列表 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, List<String> fieldList, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName,null,Constant.WHERE_DEFAULT,pageNo, findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, String whereSegment, Integer pageNo, String version, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName, null,whereSegment, pageNo, null,version, findMax); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @param uuid 日志使用 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, String whereSegment, Integer pageNo, String version, boolean findMax, String uuid) { |
| | | return selectListByPageByVersion(character, tableName, null,whereSegment, pageNo, null,version, findMax, uuid); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> selectListByVersion(Character character, String tableName, List<String> fieldList, String whereSegment, String version, boolean findMax) { |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | Maintain nowVersionMaintain = maintainService.getNowVersion(tableName); |
| | | boolean isMax = maintainService.checkdMaxVersion(maintainFromVersion.getId()); |
| | | boolean isNow = maintainService.checkNowVersion(maintainFromVersion.getId()); |
| | | boolean isFirst = maintainService.checkFirstVersion(maintainFromVersion.getId()); |
| | | |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, Integer pageNo, String version, boolean findMax) { |
| | | return selectListByPageByVersion(tableName,null,Constant.WHERE_DEFAULT,pageNo, null, version, findMax); |
| | | } |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(tableName,null,Constant.WHERE_DEFAULT,pageNo, null, String.valueOf(maintainService.getNowVersion(tableName).getVersion()), findMax); |
| | | } |
| | | Integer fromVersionOrderNo = maintainFromVersion.getOrderNo(); |
| | | Integer nowVersionOrderNo = 0; |
| | | if (nowVersionMaintain != null) { |
| | | nowVersionOrderNo = nowVersionMaintain.getOrderNo(); |
| | | } |
| | | |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, String whereSegment, Integer pageNo, Integer pageSize, boolean findMax) { |
| | | return selectListByPageByVersion(tableName,null,whereSegment,pageNo,pageSize, findMax); |
| | | } |
| | | String tableTempName = tableName + Constant.RECORD; |
| | | List<Map<String, Object>> result = null; |
| | | |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, List<String> fieldList, String whereSegment, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(tableName,null,whereSegment,pageNo, null, findMax); |
| | | } |
| | | String fields; |
| | | String tempFields; |
| | | String A1Fields; |
| | | |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, List<String> fieldList, Integer pageNo, boolean findMax) { |
| | | return selectListByPageByVersion(tableName,null,Constant.WHERE_DEFAULT,pageNo, findMax); |
| | | } |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, String whereSegment, Integer pageNo, String version, boolean findMax) { |
| | | return selectListByPageByVersion(tableName, null,whereSegment, pageNo, null,version, findMax); |
| | | } |
| | | |
| | | if (fieldList == null || fieldList.size() == 0) { |
| | | fields = getFields(character, tableName, maintainFromVersion); |
| | | A1Fields = getFields(character, tableName, Constant.A1, maintainFromVersion); |
| | | tempFields = getTempFields(character, tableName, Constant.A1, maintainFromVersion); |
| | | } else { |
| | | fields = fieldList.stream().collect(Collectors.joining(Constant.COMMA)); |
| | | A1Fields = fieldList.stream() |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.A1, s)) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | | tempFields = fieldList.stream() |
| | | .map(s -> |
| | | s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format("{0} as id",Constant.STD_ID): s) |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.A1, s)) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | } |
| | | if (isNow && !findMax){ |
| | | result = mapper.selectByPage(tableName, fields, whereSegment, null); |
| | | } |
| | | else if (isMax && findMax) { |
| | | ContentBuilder builder = new ContentBuilder(Constant.COMMA); |
| | | if (nowVersionMaintain == null) { |
| | | builder.append(DbUtils.quotedStr(maintainFromVersion.getId())); |
| | | }else { |
| | | List<String> maintainIds = maintainService.getCompareVersionMaintains(nowVersionMaintain, maintainFromVersion); |
| | | long con = maintainIds.stream().map(s -> builder.append(DbUtils.quotedStr(s))).count(); |
| | | } |
| | | |
| | | result = mapper.selectByPageByMaxVersion(tableName,tableTempName,fields, A1Fields, tempFields, nowVersionOrderNo, whereSegment, null); |
| | | |
| | | }else { |
| | | result = mapper.selectByPageByVersion(tableName,tableTempName,fields, A1Fields, tempFields, nowVersionOrderNo, fromVersionOrderNo, whereSegment, null); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据sql语句 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据sql语句 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, String version, boolean findMax) { |
| | | public String selectByVersionSql(Character character, String tableName, List<String> fieldList, String whereSegment, String version, boolean findMax) { |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | Maintain nowVersionMaintain = maintainService.getNowVersion(tableName); |
| | | boolean isMax = maintainService.checkdMaxVersion(maintainFromVersion.getId()); |
| | | boolean isNow = maintainService.checkNowVersion(maintainFromVersion.getId()); |
| | | boolean isFirst = maintainService.checkFirstVersion(maintainFromVersion.getId()); |
| | | |
| | | Integer fromVersionOrderNo = maintainFromVersion.getOrderNo(); |
| | | Integer nowVersionOrderNo = 0; |
| | | if (nowVersionMaintain != null) { |
| | | nowVersionOrderNo = nowVersionMaintain.getOrderNo(); |
| | | } |
| | | |
| | | String tableTempName = tableName + Constant.RECORD; |
| | | String result = null; |
| | | |
| | | String fields; |
| | | String tempFields; |
| | | String Hfields; |
| | | String A1fields; |
| | | String A2fields; |
| | | |
| | | String tempHfields; |
| | | if (fieldList == null || fieldList.size() == 0) { |
| | | fields = getFields(null, tableName, maintainFromVersion); |
| | | Hfields = getFields(null, tableName,Constant.H, maintainFromVersion); |
| | | A1fields = getFields(null, tableName,Constant.A1, maintainFromVersion); |
| | | A2fields = getFields(null, tableName,Constant.A2, maintainFromVersion); |
| | | tempFields = getTempFields(null, tableName, maintainFromVersion); |
| | | tempHfields = getTempFields(null, tableName, Constant.H, maintainFromVersion); |
| | | } else { |
| | | fields = fieldList.stream().collect(Collectors.joining(Constant.COMMA)); |
| | | Hfields = fieldList.stream().map(s -> MessageFormat.format(Constant.Alias,Constant.H, s)).collect(Collectors.joining(Constant.COMMA)); |
| | | A1fields = fieldList.stream().map(s -> MessageFormat.format(Constant.Alias,Constant.A1, s)).collect(Collectors.joining(Constant.COMMA)); |
| | | A2fields = fieldList.stream().map(s -> MessageFormat.format(Constant.Alias,Constant.A2, s)).collect(Collectors.joining(Constant.COMMA)); |
| | | tempFields = fieldList.stream() |
| | | .map(s -> |
| | | s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format("{0} as id",Constant.STD_ID): s) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | tempHfields = fieldList.stream() |
| | | .map(s -> |
| | | s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format("{0} as id",Constant.STD_ID): s) |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.H,s)) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | } |
| | | MyBatisSql ibatisSql = new MyBatisSql(); |
| | | Map<String, Object> parameterMap = new HashMap<>(); |
| | | if (isNow && !findMax){ |
| | | parameterMap.put("tableName", tableName); |
| | | parameterMap.put("fields", fields); |
| | | parameterMap.put("where", whereSegment); |
| | | parameterMap.put("limit", null); |
| | | result = DbUtils.getMyBatisSql("selectByPage", parameterMap, sqlSessionFactory).getSql(); |
| | | } |
| | | else if (isMax && findMax) { |
| | | ContentBuilder builder = new ContentBuilder(Constant.COMMA); |
| | | if (nowVersionMaintain == null) { |
| | | builder.append(DbUtils.quotedStr(maintainFromVersion.getId())); |
| | | }else { |
| | | List<String> maintainIds = maintainService.getCompareVersionMaintains(nowVersionMaintain, maintainFromVersion); |
| | | long con = maintainIds.stream().map(s -> builder.append(DbUtils.quotedStr(s))).count(); |
| | | } |
| | | parameterMap.put("tableName", tableName); |
| | | parameterMap.put("tableTempName", tableTempName); |
| | | parameterMap.put("fields", fields); |
| | | parameterMap.put("tempFields", tempFields); |
| | | parameterMap.put("Hfields", Hfields); |
| | | parameterMap.put("A1fields", A1fields); |
| | | parameterMap.put("A2fields", A2fields); |
| | | parameterMap.put("tempHFields", tempHfields); |
| | | parameterMap.put("fromOrderNo", fromVersionOrderNo); |
| | | parameterMap.put("toOrderNo", nowVersionOrderNo); |
| | | parameterMap.put("maintainId", DbUtils.quotedStr(maintainFromVersion.getId())); |
| | | parameterMap.put("where", whereSegment); |
| | | parameterMap.put("limit", null); |
| | | result = DbUtils.getMyBatisSql("selectByPageByMaxVersion", parameterMap, sqlSessionFactory).getSql(); |
| | | |
| | | }else { |
| | | parameterMap.put("tableName", tableName); |
| | | parameterMap.put("tableTempName", tableTempName); |
| | | parameterMap.put("fields", fields); |
| | | parameterMap.put("tempFields", tempFields); |
| | | parameterMap.put("Hfields", Hfields); |
| | | parameterMap.put("A1fields", A1fields); |
| | | parameterMap.put("A2fields", A2fields); |
| | | parameterMap.put("tempHFields", tempHfields); |
| | | parameterMap.put("fromOrderNo", fromVersionOrderNo); |
| | | parameterMap.put("toOrderNo", nowVersionOrderNo); |
| | | parameterMap.put("maintainId", DbUtils.quotedStr(maintainFromVersion.getId())); |
| | | parameterMap.put("where", whereSegment); |
| | | parameterMap.put("limit", null); |
| | | result = DbUtils.getMyBatisSql("selectByPageByVersion", parameterMap, sqlSessionFactory).getSql(); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据量 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据量 |
| | | * |
| | | */ |
| | | @Override |
| | | public Long getCountByVersion(Character character, String tableName, String whereSegment, String version, boolean findMax) { |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | Maintain nowVersionMaintain = maintainService.getNowVersion(tableName); |
| | | boolean isMax = maintainService.checkdMaxVersion(maintainFromVersion.getId()); |
| | |
| | | |
| | | Long count; |
| | | |
| | | if (isNow && !findMax){ |
| | | if (isNow && !findMax){ |
| | | count = getCount(tableName, whereSegment); |
| | | } |
| | | else if (isMax && findMax) { |
| | | if (isFirst && nowVersionMaintain == null) { |
| | | nowVersionOrderNo = nowVersionOrderNo - 1; |
| | | } |
| | | |
| | | count = getCountByMaxVersion(character, maintainFromVersion.getId(), tableName, tableTempName, nowVersionOrderNo, whereSegment); |
| | | }else { |
| | | count = getCountByVersion(character, maintainFromVersion.getId(), tableName, tableTempName, nowVersionOrderNo, fromVersionOrderNo, whereSegment); |
| | | } |
| | | return count; |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param pageSize 每页条数 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, String version, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName, fieldList, whereSegment, pageNo, pageSize, version, findMax, null); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param fieldList 字段列表 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param pageSize 每页条数 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, String version, boolean findMax, String uuid) { |
| | | return selectListByPageByVersion(character, tableName, fieldList, whereSegment, pageNo, pageSize, version, findMax, uuid, null); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 根据条件获取数据 |
| | | * @param tableName 临时表名 |
| | | * @param character 用户 |
| | | * @param whereSegment 筛选条件 |
| | | * @param pageNo 页数 |
| | | * @param pageSize 每页条数 |
| | | * @param version 版本号 |
| | | * @param findMax 是否查询的最大版本的数据 |
| | | * @param uuid 供日志使用 |
| | | * @param page 已经计算好的分页对象 |
| | | * @return: 数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName, List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, String version, boolean findMax, String uuid, Page page) { |
| | | String fieldStr = ""; |
| | | if (fieldList == null || fieldList.isEmpty()) { |
| | | fieldStr = ""; |
| | | } else { |
| | | fieldList.stream().collect(Collectors.joining(Constant.UnderLine)); |
| | | } |
| | | String key; |
| | | if (page == null) { |
| | | key = DbUtils.StrJoinLink(Constant.UnderLine, character.getId(), tableName, whereSegment, String.valueOf(pageNo), String.valueOf(pageSize), version, String.valueOf(findMax)); |
| | | |
| | | } else { |
| | | key = DbUtils.StrJoinLink(Constant.UnderLine, character.getId(), tableName, whereSegment, String.valueOf(pageNo), String.valueOf(pageSize), version, String.valueOf(findMax), page.getLimitSQL()); |
| | | } |
| | | |
| | | if (!findMax) { |
| | | Object redisValObj = redisClient.getRedisValObj(key); |
| | | if (redisValObj != null) { |
| | | JSONObject object = (JSONObject) redisValObj; |
| | | Result result = JSONObject.parseObject(object.toJSONString(), Result.class); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | Maintain nowVersionMaintain = maintainService.getNowVersion(tableName); |
| | | boolean isMax = maintainService.checkdMaxVersion(maintainFromVersion.getId()); |
| | | boolean isNow = maintainService.checkNowVersion(maintainFromVersion.getId()); |
| | | boolean isFirst = maintainService.checkFirstVersion(maintainFromVersion.getId()); |
| | | |
| | | Integer fromVersionOrderNo = maintainFromVersion.getOrderNo(); |
| | | Integer nowVersionOrderNo = 0; |
| | | if (nowVersionMaintain != null) { |
| | | nowVersionOrderNo = nowVersionMaintain.getOrderNo(); |
| | | } |
| | | |
| | | String tableTempName = tableName + Constant.RECORD; |
| | | |
| | | Long count; |
| | | Date startDate = new Date(); |
| | | if (isNow && !findMax){ |
| | | count = getCount(tableName, whereSegment); |
| | | } |
| | | else if (isMax && findMax) { |
| | | if (isFirst && nowVersionMaintain == null) { |
| | | nowVersionOrderNo = nowVersionOrderNo - 1; |
| | | } |
| | | count = getCountByMaxVersion(maintainFromVersion.getId(), tableName, tableTempName, fromVersionOrderNo, nowVersionOrderNo, whereSegment); |
| | | }else { |
| | | count = getCountByVersion(maintainFromVersion.getId(), tableName, tableTempName, nowVersionOrderNo, fromVersionOrderNo, whereSegment); |
| | | } |
| | | |
| | | count = getCountByMaxVersion(character, maintainFromVersion.getId(), tableName, tableTempName, nowVersionOrderNo, whereSegment); |
| | | }else { |
| | | count = getCountByVersion(character, maintainFromVersion.getId(), tableName, tableTempName, nowVersionOrderNo, fromVersionOrderNo, whereSegment); |
| | | } |
| | | Date endDate = new Date(); |
| | | log.info(MessageFormat.format("master tag:{0} MASTER-- select count:{1} ms",uuid, (endDate.getTime() - startDate.getTime()))); |
| | | |
| | | if (page != null && count != null) { |
| | | page.setRecordCount(count.intValue()); |
| | | } |
| | | if (count == null || count == 0) { |
| | | return Result.success(null); |
| | | } |
| | | //mapper.selectByPageByVersion(tableName, tableTempName, fieldList, whereSegment,); |
| | | Page page = new Page(count); |
| | | if (pageSize != null && pageSize.compareTo(1) != -1) { |
| | | page.setPageSize(pageSize); |
| | | } |
| | | List<Map<String, Object>> result = null; |
| | | if (page.getPageCount() < pageNo) { |
| | | return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); |
| | | |
| | | if (page == null) { |
| | | page = new Page(count); |
| | | if (pageSize != null && pageSize.compareTo(1) != -1) { |
| | | page.setPageSize(pageSize); |
| | | } |
| | | |
| | | if (page.getPageCount() < pageNo) { |
| | | return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); |
| | | } |
| | | page.setPageNo(pageNo); |
| | | } |
| | | page.setPageNo(pageNo); |
| | | |
| | | String limitSQL = page.getLimitSQL(); |
| | | String fields; |
| | | String tempFields; |
| | | String Hfields; |
| | | String A1fields; |
| | | String A2fields; |
| | | |
| | | String tempHfields; |
| | | String A1Fields; |
| | | |
| | | if (fieldList == null || fieldList.size() == 0) { |
| | | fields = getFields(tableName); |
| | | Hfields = getFields(tableName,Constant.H); |
| | | A1fields = getFields(tableName,Constant.A1); |
| | | A2fields = getFields(tableName,Constant.A2); |
| | | tempFields = getTempFields(tableName); |
| | | tempHfields = getTempFields(tableName, Constant.H); |
| | | } else { |
| | | fields = fieldList.stream().collect(Collectors.joining(Constant.COMMA)); |
| | | Hfields = fieldList.stream().map(s -> MessageFormat.format(Constant.Alias,Constant.H, s)).collect(Collectors.joining(Constant.COMMA)); |
| | | A1fields = fieldList.stream().map(s -> MessageFormat.format(Constant.Alias,Constant.A1, s)).collect(Collectors.joining(Constant.COMMA)); |
| | | A2fields = fieldList.stream().map(s -> MessageFormat.format(Constant.Alias,Constant.A2, s)).collect(Collectors.joining(Constant.COMMA)); |
| | | tempFields = fieldList.stream() |
| | | fields = getFields(character, tableName, maintainFromVersion, uuid); |
| | | A1Fields = getFields(character, tableName, Constant.A1, maintainFromVersion, uuid); |
| | | List<String> fieldStrList = DbUtils.split(fields, Constant.COMMA); |
| | | tempFields = fieldStrList.stream() |
| | | .map(s -> |
| | | s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format("{} as id",Constant.STD_ID): s) |
| | | s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format("{0} as id",Constant.STD_ID): s) |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.A1, s)) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | tempHfields = fieldList.stream() |
| | | } else { |
| | | if (!fieldList.contains(Constant.ID)) { |
| | | fieldList.add(Constant.ID); |
| | | } |
| | | fields = fieldList.stream().collect(Collectors.joining(Constant.COMMA)); |
| | | A1Fields = fieldList.stream() |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.A1, s)) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | | tempFields = fieldList.stream() |
| | | .map(s -> |
| | | s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format("{} as id",Constant.STD_ID): s) |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.H,s)) |
| | | s.equalsIgnoreCase(Constant.ID) ? MessageFormat.format("{0} as id",Constant.STD_ID): s) |
| | | .map(s -> MessageFormat.format(Constant.Alias,Constant.A1, s)) |
| | | .collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | } |
| | | startDate = new Date(); |
| | | log.info(MessageFormat.format("master tag:{0} MASTER-- select field :{1} ms",uuid, (startDate.getTime() - endDate.getTime()))); |
| | | |
| | | |
| | | if (isNow && !findMax){ |
| | | result = mapper.selectByPage(tableName, fields, whereSegment, page.getLimitSQL()); |
| | | } |
| | |
| | | long con = maintainIds.stream().map(s -> builder.append(DbUtils.quotedStr(s))).count(); |
| | | } |
| | | |
| | | result = mapper.selectByPageByMaxVersion(tableName,tableTempName,fields,tempFields, Hfields, A1fields, A2fields, tempHfields, fromVersionOrderNo, nowVersionOrderNo, DbUtils.quotedStr(maintainFromVersion.getId()), whereSegment, limitSQL); |
| | | result = mapper.selectByPageByMaxVersion(tableName,tableTempName,fields, A1Fields, tempFields, nowVersionOrderNo, whereSegment, limitSQL); |
| | | |
| | | }else { |
| | | result = mapper.selectByPageByVersion(tableName,tableTempName,fields,tempFields, Hfields, A1fields, A2fields, tempHfields, nowVersionOrderNo, fromVersionOrderNo, DbUtils.quotedStr(maintainFromVersion.getId()), whereSegment, limitSQL); |
| | | result = mapper.selectByPageByVersion(tableName,tableTempName,fields, A1Fields, tempFields, nowVersionOrderNo, fromVersionOrderNo, whereSegment, limitSQL); |
| | | } |
| | | endDate = new Date(); |
| | | log.info(MessageFormat.format("master tag:{0} MASTER-- select dataMap :{1} ms",uuid, (endDate.getTime() - startDate.getTime()))); |
| | | |
| | | EntityWrapper<SysField> sysFieldEntityWrapper = new EntityWrapper<>(); |
| | | sysFieldEntityWrapper.eq("table_name", tableName); |
| | | List<SysField> sysFields = fieldService.selectList(sysFieldEntityWrapper); |
| | | List<SysField> sysFields = masterAuthorService.getField(character, maintainFromVersion.getId()); |
| | | if (isMax) { |
| | | sysFields.add(new SysField().setAlias("数据状态").setField("operate").setVisible(true).setFormat("operate_")); |
| | | sysFields.add(new SysField().setAlias("审批状态").setField("status").setVisible(true).setFormat("status_")); |
| | |
| | | JSONObject resultobject = new JSONObject(); |
| | | |
| | | JSONObject object = new JSONObject(); |
| | | |
| | | Map<String, AntianaphylaxisResult> helpfulField = antianaphylaxisClient.getHelpfulField(fields, tableName); |
| | | antianaphylaxisClient.fixMasterData(result,helpfulField); |
| | | startDate = new Date(); |
| | | log.info(MessageFormat.format("master tag:{0} MASTER-- antianaphy dataMap :{1} ms",uuid, (startDate.getTime() - endDate.getTime()))); |
| | | |
| | | object.fluentPut("total", page.getRecordCount()); |
| | | object.fluentPut("size", page.getPageSize()); |
| | |
| | | resultobject.fluentPut("grid",object); |
| | | resultobject.fluentPut("fields",sysFields); |
| | | resultobject.fluentPut("maintainId", maintainFromVersion.getId()); |
| | | |
| | | |
| | | redisClient.putRedisValObj(key, Result.success(resultobject)); |
| | | |
| | | return Result.success(resultobject); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 上传数据后的操作 |
| | | * @param tableName 临时表名 |
| | | * @param uploadType 更新类型 |
| | | * @param userId 用户id |
| | | * @return: 生成后的版本 |
| | | * |
| | | */ |
| | | @Override |
| | | public Maintain uploadedData(String tableName, SysAssembleUpdateType uploadType, String userId) { |
| | | return uploadedData(tableName, uploadType, userId, true); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 上传数据后的操作 |
| | | * @param tableName 临时表名 |
| | | * @param uploadType 更新类型 |
| | | * @param bigVersion 是否生成大版本 |
| | | * @param userId 用户id |
| | | * @return: 生成后的版本 |
| | | * |
| | | */ |
| | | @Override |
| | | public Maintain uploadedData(String tableName, SysAssembleUpdateType uploadType, String userId, boolean bigVersion) { |
| | | MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("table_name",tableName)); |
| | | SysOperateLog operateLog = new SysOperateLog(); |
| | | |
| | |
| | | |
| | | maxVersion.deleteById(); |
| | | }else { |
| | | biggerVersion = DbUtils.versionAddBig(mVersion); |
| | | if (bigVersion) { |
| | | biggerVersion = DbUtils.versionAddBig(mVersion); |
| | | }else { |
| | | biggerVersion = DbUtils.versionAddSub(mVersion); |
| | | } |
| | | |
| | | maintain.setOrderNo(DbUtils.getOrderNoAdd(maxVersion.getOrderNo())); |
| | | } |
| | | } |
| | |
| | | maintain.setTableName(tableName); |
| | | maintain.setCreateTime(new Date()); |
| | | |
| | | Connection connection = sqlSessionTemplate.getConnection(); |
| | | Connection connection = null; |
| | | try { |
| | | connection = dataSource.getConnection(); |
| | | connection.setAutoCommit(false); |
| | | mapper.insertMatintainDetailFromTemp(DbUtils.quotedStr(maintain.getId()), maintain.getTableName() + Constant.RECORD , DbUtils.quotedStr(Operate.create.toString())); |
| | | connection.commit(); |
| | | mapper.updateStdId( maintain.getTableName() + Constant.RECORD); |
| | | connection.commit(); |
| | | Integer aLong = mapper.tempDeal(maintain.getTableName() + Constant.RECORD, DbUtils.quotedStr(maintain.getId())); |
| | | connection.commit(); |
| | | if (aLong == null) { |
| | | maintain.setDesp("上传数据"); |
| | | }else { |
| | | maintain.setDesp(MessageFormat.format("上传数据{0}条", aLong)); |
| | | } |
| | | maintain.setDesp(MessageFormat.format("上传数据{0}条", aLong)); |
| | | |
| | | if (uploadType.equals(SysAssembleUpdateType.All)) { |
| | | List<TableSchemaResult> tableField = mapper.getTableField(tableName); |
| | |
| | | .map(s -> s.equalsIgnoreCase(Constant.STD_ID) ? MessageFormat.format(Constant.FieldAsAlias, Constant.ID, Constant.STD_ID) : s).collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | mapper.insertRecordFromStandrad(maintain.getTableName(), maintain.getTableName() + Constant.RECORD, collect); |
| | | connection.commit(); |
| | | mapper.insertMatintainDetailFromStandrad(DbUtils.quotedStr(maintain.getId()), maintain.getTableName() + Constant.RECORD); |
| | | connection.commit(); |
| | | Integer standradCnt = mapper.tempDeal(maintain.getTableName() + Constant.RECORD, DbUtils.quotedStr(maintain.getId())); |
| | | connection.commit(); |
| | | |
| | | if (standradCnt != null) { |
| | | maintain.setDesp(maintain.getDesp() + MessageFormat.format("删除原数据{0}条", standradCnt)); |
| | | }else { |
| | | maintain.setDesp(maintain.getDesp() + "删除原数据"); |
| | | } |
| | | maintain.setDesp(maintain.getDesp() + MessageFormat.format("删除原数据{0}条", standradCnt)); |
| | | |
| | | } |
| | | |
| | | operateLog.setCreateTime(new Date()) |
| | |
| | | .setId(DbUtils.getUUID()) |
| | | .setMaintainId(menuMapping.getId()) |
| | | .setOperate("open") |
| | | .setDesp(MessageFormat.format("上传数据{0}条", aLong)); |
| | | .setDesp("批量上传数据"); |
| | | |
| | | maintain.insert(); |
| | | connection.commit(); |
| | |
| | | catch (Exception e) { |
| | | e.printStackTrace(); |
| | | |
| | | |
| | | } |
| | | finally { |
| | | }finally { |
| | | if (connection != null) { |
| | | try { |
| | | connection.commit(); |
| | | connection.close(); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return maintain; |
| | | } |
| | | |
| | | |
| | | |
| | | //bak |
| | | @Deprecated |
| | | public Result selectListByPage(String tableName, List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, String version) { |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | long changeCount = maintainService.countVersionOperatorByType(tableName + Constant.RECORD, whereSegment, maintainFromVersion.getId(), Operate.create); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName,List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, boolean findMax) { |
| | | return selectListByPageByVersion(tableName, fieldList, whereSegment,pageNo,pageSize,String.valueOf(maintainService.getNowVersion(tableName).getVersion()), findMax); |
| | | public Result selectListByPageByVersion(Character character, String tableName,List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, boolean findMax, String uuid) { |
| | | return selectListByPageByVersion(character, tableName, fieldList, whereSegment,pageNo,pageSize,String.valueOf(maintainService.getNowVersion(tableName).getVersion()), findMax, uuid); |
| | | } |
| | | @Override |
| | | public Result selectListByPageByVersion(Character character, String tableName,List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, boolean findMax) { |
| | | return selectListByPageByVersion(character, tableName, fieldList, whereSegment,pageNo,pageSize,String.valueOf(maintainService.getNowVersion(tableName).getVersion()), findMax); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | public Result insert(String tableName, String json) { |
| | | try { |
| | | List<TableSchemaResult> tableFieldList = mapper.getTableField(tableName); |
| | | List<String> fieldNameList = tableFieldList.stream().map(TableSchemaResult::getFieldName).collect(Collectors.toList()); |
| | | String fields = tableFieldList.stream().map(TableSchemaResult::getFieldName).collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | JSONObject dataObject = JSON.parseObject(json); |
| | | Set<String> keySet = dataObject.keySet(); |
| | | List<String> fieldNameList = new ArrayList<>(keySet); |
| | | // List<SysField> fieldByTable = fieldService.getFieldByTable(tableName); |
| | | // List<String> fieldNameList = fieldByTable.stream().map(sysField -> sysField.getField()).collect(Collectors.toList()); |
| | | String fields = keySet.stream().collect(Collectors.joining(Constant.COMMA)); |
| | | ContentBuilder builder = new ContentBuilder(Constant.COMMA); |
| | | Object parse = JSON.parse(json); |
| | | List<String> ids = new ArrayList<>(); |
| | |
| | | return Result.error(CodeMsg.DELETE_ERROR); |
| | | } |
| | | } |
| | | /** |
| | | * |
| | | * @description: 获取表中distinct后的值 |
| | | * @param tableName 临时表名 |
| | | * @param field 字段名 |
| | | * @return: 去重后的数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Set<String> getFieldValByTable(String tableName, String field) { |
| | | //查缓存 |
| | | String key = DbUtils.getFieldRedisKey(tableName,field); |
| | | List<Object> redisList = redisClient.getRedisList(key); |
| | | if (redisList != null) { |
| | | HashSet<String> strings = new HashSet<>(); |
| | | for (Object o : redisList) { |
| | | strings.add(o.toString()); |
| | | } |
| | | return strings; |
| | | } |
| | | // 读数据库 |
| | | String tempTableName = tableName + Constant.RECORD; |
| | | // List<Map<String, Object>> maps = mapper.selectByPage(tableName, MessageFormat.format(Constant.DISTINCT, field), Constant.WHERE_DEFAULT, null); |
| | | |
| | | List<Map<String, Object>> maps = mapper.selectDistinct(tempTableName, field, Constant.WHERE_DEFAULT); |
| | | |
| | | if (maps.size() == 0) { |
| | | return null; |
| | | } |
| | | Set<String> result = maps.stream() |
| | | .filter(one -> one != null) |
| | | .map(one -> one.get(field)) |
| | | .filter(o -> o != null) |
| | | .map(o -> o.toString()).collect(Collectors.toSet()); |
| | | redisClient.putRedisList(key, new ArrayList(result)); |
| | | return result; |
| | | } |
| | | /** |
| | | * |
| | | * @description: 获取表中distinct后的值 |
| | | * @param maintainFieldId 字段版本id |
| | | * @param tableName 表名 |
| | | * @param field 字段名 |
| | | * @return: 去重后的数据 |
| | | * |
| | | */ |
| | | @Override |
| | | public Set<String> getFieldValByMaintainField(String maintainFieldId, String field, String tableName) { |
| | | //查缓存 |
| | | MaintainField maintainField = maintainFieldService.selectById(maintainFieldId); |
| | | |
| | | |
| | | // 读数据库 |
| | | List<Maintain> list = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName); |
| | | Maintain max = list.stream().max(new Comparator<Maintain>() { |
| | | @Override |
| | | public int compare(Maintain o1, Maintain o2) { |
| | | return o1.getOrderNo() - o2.getOrderNo(); |
| | | } |
| | | }).get(); |
| | | Maintain min = list.stream().min(new Comparator<Maintain>() { |
| | | @Override |
| | | public int compare(Maintain o1, Maintain o2) { |
| | | return o1.getOrderNo() - o2.getOrderNo(); |
| | | } |
| | | }).get(); |
| | | ArrayList<String> fieldList = new ArrayList<>(); |
| | | fieldList.add(field); |
| | | fieldList.add(Constant.ID); |
| | | // where |
| | | |
| | | List<Map<String, Object>> maps = selectListByVersion(null, tableName, fieldList, Constant.WHERE_DEFAULT, max.getVersion(), false); |
| | | String tempTableName = tableName + Constant.RECORD; |
| | | List<Map<String, Object>> tempVals = mapper.getOneTempFieldDataByMaintainExtent(DbUtils.quotedStr(tableName), tempTableName, field, min.getOrderNo(), max.getOrderNo()); |
| | | maps.addAll(tempVals); |
| | | if (maps.size() == 0) { |
| | | return null; |
| | | } |
| | | Set<String> result = maps.stream() |
| | | .filter(one -> one != null) |
| | | .map(one -> one.get(field)) |
| | | .filter(o -> o != null) |
| | | .map(o -> o.toString()).collect(Collectors.toSet()); |
| | | String val = result.stream().collect(Collectors.joining(Constant.SEMICOLON)); |
| | | |
| | | return result; |
| | | } |
| | | /** |
| | | * |
| | | * @description: 创建索引 |
| | | * @param recordTableName 记录表名称 |
| | | * @return: |
| | | * |
| | | */ |
| | | @Override |
| | | public void createIdx(String recordTableName) { |
| | | String idxName = MessageFormat.format(Constant.IDX_TEMPLATE, recordTableName, Constant.STD_ID); |
| | | |
| | | List<Map<String, Object>> maps = mapper.selectIdxByTableName(DbUtils.quotedStr(recordTableName)); |
| | | long existsIdx = maps.stream().filter(stringObjectMap -> stringObjectMap.get("index_name") != null) |
| | | .map(stringObjectMap -> stringObjectMap.get("index_name").toString()) |
| | | .filter(s -> idxName.equalsIgnoreCase(s)).count(); |
| | | if (existsIdx == 0) { |
| | | |
| | | mapper.createIdx(recordTableName, idxName, Constant.STD_ID + Constant.COMMA + Constant.DEAL); |
| | | } |
| | | } |
| | | } |