Commit 1714bdb0 by 刘泽志

机构字典设置功能

parent 9bae4a21
...@@ -275,6 +275,14 @@ public class DataImportController { ...@@ -275,6 +275,14 @@ public class DataImportController {
@ApiOperation("一键导入正式库") @ApiOperation("一键导入正式库")
public AjaxResult syncDb(@RequestBody TemplateVO vo) { public AjaxResult syncDb(@RequestBody TemplateVO vo) {
final DataTemplate template = dataTemplateService.getById(vo.getId()); final DataTemplate template = dataTemplateService.getById(vo.getId());
if (template == null) {
return AjaxResult.error("没有对应的模板");
}
final long count = excelDataService.count(Wrappers.lambdaQuery(ExcelData.class).eq(ExcelData::getTemplateId, template.getId())
.eq(ExcelData::getType, "1"));
if (count < 1) {
return AjaxResult.error("请先上传导入数据");
}
try { try {
DataSourceService.switchDb(template.getDataSourceId()); DataSourceService.switchDb(template.getDataSourceId());
String insertSql = "INSERT INTO {} SELECT * FROM {} WHERE YEAROOFDATARECORD = '{}年'"; String insertSql = "INSERT INTO {} SELECT * FROM {} WHERE YEAROOFDATARECORD = '{}年'";
......
...@@ -11,12 +11,10 @@ import com.tbyf.his.web.dataImport.core.DiConfig; ...@@ -11,12 +11,10 @@ import com.tbyf.his.web.dataImport.core.DiConfig;
import com.tbyf.his.web.dataImport.domain.param.UploadExcelParam; import com.tbyf.his.web.dataImport.domain.param.UploadExcelParam;
import com.tbyf.his.web.dataImport.domain.vo.AreaDict; import com.tbyf.his.web.dataImport.domain.vo.AreaDict;
import com.tbyf.his.web.dataImport.domain.vo.VerifyVO; import com.tbyf.his.web.dataImport.domain.vo.VerifyVO;
import com.tbyf.his.web.dataImport.entity.DataDict;
import com.tbyf.his.web.dataImport.entity.DataTemplate; import com.tbyf.his.web.dataImport.entity.DataTemplate;
import com.tbyf.his.web.dataImport.entity.ExcelData; import com.tbyf.his.web.dataImport.entity.ExcelData;
import com.tbyf.his.web.dataImport.service.DataFieldService; import com.tbyf.his.web.dataImport.service.*;
import com.tbyf.his.web.dataImport.service.DataSourceService;
import com.tbyf.his.web.dataImport.service.DataTemplateService;
import com.tbyf.his.web.dataImport.service.ExcelDataService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows; import lombok.SneakyThrows;
...@@ -25,7 +23,6 @@ import org.apache.poi.ss.usermodel.*; ...@@ -25,7 +23,6 @@ import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -34,10 +31,8 @@ import java.io.ByteArrayInputStream; ...@@ -34,10 +31,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
/** /**
* @author lzz * @author lzz
...@@ -61,6 +56,9 @@ public class ExcelDataController { ...@@ -61,6 +56,9 @@ public class ExcelDataController {
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired
private DataDictService dataDictService;
@IgnoreWebSecurity @IgnoreWebSecurity
@GetMapping("/download/template") @GetMapping("/download/template")
@ApiOperation("模板下载") @ApiOperation("模板下载")
...@@ -140,7 +138,7 @@ public class ExcelDataController { ...@@ -140,7 +138,7 @@ public class ExcelDataController {
@IgnoreWebSecurity @IgnoreWebSecurity
@GetMapping("/queryArea") @GetMapping("/queryArea")
@ApiOperation("获取机构数据") @ApiOperation("获取机构数据")
public AjaxResult queryArea(@RequestParam String name, @RequestParam String year) { public AjaxResult queryArea(@RequestParam String name, @RequestParam String year, @RequestParam String type) {
ExcelData excelData = excelDataService.getOne(Wrappers.lambdaQuery(ExcelData.class) ExcelData excelData = excelDataService.getOne(Wrappers.lambdaQuery(ExcelData.class)
.eq(ExcelData::getOrgName, name) .eq(ExcelData::getOrgName, name)
.eq(ExcelData::getYear, year) .eq(ExcelData::getYear, year)
...@@ -148,6 +146,8 @@ public class ExcelDataController { ...@@ -148,6 +146,8 @@ public class ExcelDataController {
if (excelData == null) { if (excelData == null) {
return AjaxResult.error("请先上传数据并分析"); return AjaxResult.error("请先上传数据并分析");
} }
final List<DataDict> areaList = dataDictService.list(Wrappers.lambdaQuery(DataDict.class)
.eq(DataDict::getType, "area"));
DataTemplate template = dataTemplateService.getById(excelData.getTemplateId()); DataTemplate template = dataTemplateService.getById(excelData.getTemplateId());
String sql = "SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME,MAILING_ADDRESS,AREA_NUMBER_CODE FROM {} WHERE YEAROOFDATARECORD='{}年'"; String sql = "SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME,MAILING_ADDRESS,AREA_NUMBER_CODE FROM {} WHERE YEAROOFDATARECORD='{}年'";
try { try {
...@@ -156,6 +156,21 @@ public class ExcelDataController { ...@@ -156,6 +156,21 @@ public class ExcelDataController {
StrFormatter.format(sql, template.getOrgName(), template.getTableName() + "_TEMP", template.getYear()), StrFormatter.format(sql, template.getOrgName(), template.getTableName() + "_TEMP", template.getYear()),
new BeanPropertyRowMapper<>(AreaDict.class)); new BeanPropertyRowMapper<>(AreaDict.class));
DataSourceService.switchDefault(); DataSourceService.switchDefault();
// 错误数据筛选
if (StringUtils.equals(type, "0")) {
areaDictList = areaDictList.stream()
.filter(area -> {
if (StringUtils.isBlank(area.getAREA_NUMBER_CODE())) {
return true;
}
if (StringUtils.isBlank(area.getORG_NAME())) {
return true;
}
final Optional<DataDict> first = areaList.stream().filter(item -> StringUtils.equals(item.getValue(), area.getAREA_NUMBER_CODE())).findFirst();
return !first.map(dataDict -> area.getORG_NAME().startsWith(dataDict.getLabel())).orElse(true);
})
.collect(Collectors.toList());
}
return AjaxResult.success(areaDictList); return AjaxResult.success(areaDictList);
} finally { } finally {
DataSourceService.switchDefault(); DataSourceService.switchDefault();
......
package com.tbyf.his.web.dataImport.service.impl; package com.tbyf.his.web.dataImport.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tbyf.his.adapter.task.StringColumnRowMapper; import com.tbyf.his.adapter.task.StringColumnRowMapper;
import com.tbyf.his.common.annotation.DataSource; import com.tbyf.his.common.annotation.DataSource;
...@@ -11,15 +12,16 @@ import com.tbyf.his.web.dataImport.DataImportUtils; ...@@ -11,15 +12,16 @@ import com.tbyf.his.web.dataImport.DataImportUtils;
import com.tbyf.his.web.dataImport.core.*; import com.tbyf.his.web.dataImport.core.*;
import com.tbyf.his.web.dataImport.domain.vo.ExcelVO; import com.tbyf.his.web.dataImport.domain.vo.ExcelVO;
import com.tbyf.his.web.dataImport.domain.vo.VerifyVO; import com.tbyf.his.web.dataImport.domain.vo.VerifyVO;
import com.tbyf.his.web.dataImport.entity.DataDict;
import com.tbyf.his.web.dataImport.entity.DataRule; import com.tbyf.his.web.dataImport.entity.DataRule;
import com.tbyf.his.web.dataImport.entity.DataTemplate; import com.tbyf.his.web.dataImport.entity.DataTemplate;
import com.tbyf.his.web.dataImport.entity.ExcelData; import com.tbyf.his.web.dataImport.entity.ExcelData;
import com.tbyf.his.web.dataImport.mapper.ExcelDataMapper; import com.tbyf.his.web.dataImport.mapper.ExcelDataMapper;
import com.tbyf.his.web.dataImport.service.DataDictService;
import com.tbyf.his.web.dataImport.service.DataSourceService; import com.tbyf.his.web.dataImport.service.DataSourceService;
import com.tbyf.his.web.dataImport.service.DataTemplateService; import com.tbyf.his.web.dataImport.service.DataTemplateService;
import com.tbyf.his.web.dataImport.service.ExcelDataService; import com.tbyf.his.web.dataImport.service.ExcelDataService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.statement.select.Select;
import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.Zip64Mode; import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
...@@ -29,7 +31,6 @@ import org.apache.poi.util.IOUtils; ...@@ -29,7 +31,6 @@ import org.apache.poi.util.IOUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -58,6 +59,9 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData ...@@ -58,6 +59,9 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired
private DataDictService dataDictService;
@Override @Override
public void analyzeExport(ExcelData excelData, HttpServletResponse response) { public void analyzeExport(ExcelData excelData, HttpServletResponse response) {
// 查询出所有字段配置 // 查询出所有字段配置
...@@ -218,10 +222,12 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData ...@@ -218,10 +222,12 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
Map<String, List<ExcelVO>> areaMap = list.stream().collect(Collectors.groupingBy(ExcelVO::getAreaCode)); Map<String, List<ExcelVO>> areaMap = list.stream().collect(Collectors.groupingBy(ExcelVO::getAreaCode));
try (ZipArchiveOutputStream zous = new ZipArchiveOutputStream(response.getOutputStream())) { try (ZipArchiveOutputStream zous = new ZipArchiveOutputStream(response.getOutputStream())) {
zous.setUseZip64(Zip64Mode.AsNeeded); zous.setUseZip64(Zip64Mode.AsNeeded);
areaMap.forEach((code,excelList)->{ areaMap.forEach((code,excelList)-> {
String fileName = code + ".xlsx"; final DataDict one = dataDictService.getOne(Wrappers.lambdaQuery(DataDict.class)
.eq(DataDict::getType, "area").eq(DataDict::getValue, code), false);
String fileName = one == null ? code + ".xlsx" : one.getLabel() + ".xlsx";
ExcelUtil<ExcelVO> util = new ExcelUtil<>(ExcelVO.class); ExcelUtil<ExcelVO> util = new ExcelUtil<>(ExcelVO.class);
util.init(excelList,"异常数据分析","", Excel.Type.EXPORT); util.init(excelList, "异常数据分析", "", Excel.Type.EXPORT);
util.writeSheet(); util.writeSheet();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment