| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.mybatis.spring.SqlSessionTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.sql.DataSource; |
| | | import java.sql.Connection; |
| | | import java.sql.SQLException; |
| | | import java.text.MessageFormat; |
| | |
| | | IMaintainDetailService maintainDetailService; |
| | | @Autowired |
| | | IFlowsService flowsService; |
| | | |
| | | @Resource |
| | | protected SqlSessionTemplate sqlSessionTemplate; |
| | | protected DataSource dataSource; |
| | | |
| | | @Override |
| | | public Result selectById(String tableName, String id) { |
| | | try{ |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Long getCountByVersion (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(tableName, maintain); |
| | | String Hfields = getFields(tableName, Constant.H, maintain); |
| | | String tempFields = getTempFields(tableName, maintain); |
| | | String A1fields = getFields(tableName, Constant.A1, maintain); |
| | | String A2fields = getFields(tableName, Constant.A2, maintain); |
| | | String tempHFields = getTempFields(tableName, Constant.H, maintain); |
| | | if (StringUtils.isEmpty(whereSegment)) { |
| | | whereSegment = Constant.WHERE_DEFAULT; |
| | | } |
| | |
| | | |
| | | 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); |
| | | Maintain maintain = maintainService.selectById(maintainId); |
| | | |
| | | String fields = getFields(tableName, maintain); |
| | | String Hfields = getFields(tableName, Constant.H, maintain); |
| | | String tempFields = getTempFields(tableName, maintain); |
| | | String A1fields = getFields(tableName, Constant.A1, maintain); |
| | | String A2fields = getFields(tableName, Constant.A2, maintain); |
| | | String tempHFields = getTempFields(tableName, Constant.H, maintain); |
| | | if (StringUtils.isEmpty(whereSegment)) { |
| | | whereSegment = Constant.WHERE_DEFAULT; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public String getFields(String tableName) { |
| | | return getFields(tableName, null); |
| | | return getFields(tableName, Constant.EMPTY_Str); |
| | | } |
| | | |
| | | @Override |
| | | public String getFields(String tableName, Maintain maintain) { |
| | | |
| | | return getFields(tableName, null, maintain); |
| | | } |
| | | |
| | | private String getCaseWhenFields(String tableName) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getFields(String tableName, String alias, Maintain maintain) { |
| | | List<SysField> fields = fieldService.getFieldByMaintain(maintain.getId()); |
| | | ContentBuilder contentBuilder = new ContentBuilder(Constant.COMMA); |
| | | 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(); |
| | | } |
| | | |
| | | @Override |
| | | public String getTempFields(String tableName, Maintain maintain) { |
| | | return getTempFields(tableName, null, maintain); |
| | | } |
| | | |
| | | @Override |
| | | public String getTempFields(String tableName) { |
| | | return getTempFields(tableName, null); |
| | | return getTempFields(tableName, Constant.EMPTY_Str); |
| | | } |
| | | @Override |
| | | public String getTempFields(String tableName, String alias) { |
| | |
| | | ContentBuilder contentBuilder = new ContentBuilder(Constant.COMMA); |
| | | for (TableSchemaResult tableSchemaResult : tableField) { |
| | | String fieldName = tableSchemaResult.getFieldName(); |
| | | if (fieldName.equalsIgnoreCase(Constant.ID)) { |
| | | if (StringUtils.isEmpty(alias)) { |
| | | contentBuilder.append(MessageFormat.format("{0} as id", Constant.STD_ID)); |
| | | } else { |
| | | contentBuilder.append(MessageFormat.format("{0}.{1} as id", alias, Constant.STD_ID)); |
| | | } |
| | | continue; |
| | | } |
| | | if (StringUtils.isEmpty(alias)) { |
| | | contentBuilder.append(fieldName); |
| | | } else { |
| | | contentBuilder.append(MessageFormat.format(Constant.Alias,alias,fieldName)); |
| | | } |
| | | } |
| | | return contentBuilder.toString(); |
| | | } |
| | | |
| | | @Override |
| | | public String getTempFields(String tableName, String alias, Maintain maintain) { |
| | | List<SysField> fields = fieldService.getFieldByMaintain(maintain.getId()); |
| | | ContentBuilder contentBuilder = new ContentBuilder(Constant.COMMA); |
| | | if (!fields.contains(Constant.ID)) { |
| | | fields.add(new SysField().setField(Constant.ID)); |
| | | } |
| | | |
| | | 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)); |
| | |
| | | |
| | | @Override |
| | | public Result selectListByPageByVersion(String tableName, List<String> fieldList, String whereSegment, Integer pageNo, Integer pageSize, String version, boolean findMax) { |
| | | |
| | | Maintain maintainFromVersion = maintainService.getMaintainFromVersion(tableName, version); |
| | | Maintain nowVersionMaintain = maintainService.getNowVersion(tableName); |
| | | boolean isMax = maintainService.checkdMaxVersion(maintainFromVersion.getId()); |
| | |
| | | |
| | | String tempHfields; |
| | | 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); |
| | | fields = getFields(tableName, maintainFromVersion); |
| | | Hfields = getFields(tableName,Constant.H, maintainFromVersion); |
| | | A1fields = getFields(tableName,Constant.A1, maintainFromVersion); |
| | | A2fields = getFields(tableName,Constant.A2, maintainFromVersion); |
| | | tempFields = getTempFields(tableName, maintainFromVersion); |
| | | tempHfields = getTempFields(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)); |
| | |
| | | |
| | | EntityWrapper<SysField> sysFieldEntityWrapper = new EntityWrapper<>(); |
| | | sysFieldEntityWrapper.eq("table_name", tableName); |
| | | List<SysField> sysFields = fieldService.selectList(sysFieldEntityWrapper); |
| | | List<SysField> sysFields = fieldService.getFieldByMaintain(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_")); |
| | |
| | | |
| | | @Override |
| | | public Maintain uploadedData(String tableName, SysAssembleUpdateType uploadType, String userId) { |
| | | |
| | | MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("table_name",tableName)); |
| | | SysOperateLog operateLog = new SysOperateLog(); |
| | | |
| | |
| | | maintain.setTableName(tableName); |
| | | maintain.setCreateTime(new Date()); |
| | | |
| | | Connection connection = sqlSessionTemplate.getConnection(); |
| | | Connection connection; |
| | | 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 { |
| | | if (connection != null) { |
| | | try { |
| | | connection.commit(); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return maintain; |
| | | } |
| | | |
| | |
| | | |
| | | 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)); |
| | | List<SysField> fieldByTable = fieldService.getFieldByTable(tableName); |
| | | |
| | | List<String> fieldNameList = fieldByTable.stream().map(sysField -> sysField.getField()).collect(Collectors.toList()); |
| | | String fields = fieldByTable.stream().map(sysField -> sysField.getField()).collect(Collectors.joining(Constant.COMMA)); |
| | | |
| | | ContentBuilder builder = new ContentBuilder(Constant.COMMA); |
| | | Object parse = JSON.parse(json); |