Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

yeshijie 6 years ago
parent
commit
b31b28be27

+ 3 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -414,6 +414,9 @@ public class BaseRequestMapping {
    public static class BasePopulation extends Basic {
        public static final String PREFIX  = "/basePopulation";
        public static final String CHECK_POPULATION_IS_EXIST  = "/checkBasePopulationIsExist";
        public static final String POPULATION_BATCH_IMPORT  = "/basePopulationBatchImport";
        public static final String POPULATION_BATCH_ERROR_DOENLOAD  = "/basePopulationBatchErrorDownLoad";
    }
    /**

+ 3 - 3
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/saas/SaasTypeDictVO.java

@ -13,7 +13,7 @@ import io.swagger.annotations.ApiModelProperty;
public class SaasTypeDictVO extends UuidIdentityVOWithOperator {
    @ApiModelProperty(value = "Saas类型编码", example = "familyDoctor")
    private String code;
    private Integer code;
    @ApiModelProperty(value = "Saas类型名称", example = "家医型")
    private String name;
@ -21,11 +21,11 @@ public class SaasTypeDictVO extends UuidIdentityVOWithOperator {
    @ApiModelProperty(value = "状态(effective-生效中,invalid-已失效)", example = "effective")
    private SaasTypeDictDO.Status status;
    public String getCode() {
    public Integer getCode() {
        return code;
    }
    public void setCode(String code) {
    public void setCode(Integer code) {
        this.code = code;
    }

+ 27 - 0
svr/svr-base/pom.xml

@ -141,6 +141,33 @@
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <!--   poi xml导入导出工具 start-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.yihu.ehr</groupId>
                    <artifactId>commons-util</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-collections4</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
        </dependency>
        <!-- xlsx  依赖这个包 -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
        </dependency>
        <!--   poi xml导入导出工具 end -->
    </dependencies>
    <build>

+ 66 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/excel/AExcelReader.java

@ -0,0 +1,66 @@
package com.yihu.jw.base.endpoint.common.excel;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class AExcelReader {
    protected List errorLs = new ArrayList<>();
    protected List correctLs = new ArrayList<>();
    protected Map<String, Set> repeat = new HashMap<>();
    public abstract void read(Workbook rwb) throws Exception;
    public void read(MultipartFile file) throws Exception {
        read(ExcelUtils.getWorkBook(file));
    }
    public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            str = str.replaceAll("\\u00A0" ," ");
            //去除字符串中的空格、回车、换行符、制表符
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
    protected String getCellCont(Sheet sheet, int row, int col){
        Cell cell = sheet.getRow(row).getCell(col);
        return ExcelUtils.getCellValue(cell);
    }
    public List getErrorLs() {
        return errorLs;
    }
    public void setErrorLs(List errorLs) {
        this.errorLs = errorLs;
    }
    public List getCorrectLs() {
        return correctLs;
    }
    public void setCorrectLs(List correctLs) {
        this.correctLs = correctLs;
    }
    public Map<String, Set> getRepeat() {
        return repeat;
    }
    public void setRepeat(Map<String, Set> repeat) {
        this.repeat = repeat;
    }
}

+ 71 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/excel/AExcelWriter.java

@ -0,0 +1,71 @@
package com.yihu.jw.base.endpoint.common.excel;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.*;
import java.io.File;
import java.util.List;
public abstract class AExcelWriter {
    public abstract void write(Workbook wwb, List ls, File file) throws Exception;
//    public void write(OutputStream os, List ls) throws Exception{
//        write(Workbook.createWorkbook(os), ls);
//    };
    public void write( File file, List ls) throws Exception{
        write(ExcelUtils.getWorkBook(file),ls,file);
    };
    //添加单元格内容
    public void addCell(Sheet ws, int row, int column, String data )  {
        Row row1 = ws.getRow(row) ;
        row1 = row1==null? ws.createRow(row) : row1;
        Cell cell = row1.createCell(column);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(data);
    }
    //添加单元格内容
    public  void addCell(Sheet ws, int row, int column, String data , String memo)  {
        Row row1 = ws.getRow(row) ;
        row1 = row1==null? ws.createRow(row) : row1;
        Cell cell = row1.createCell(column);
        cell.setCellValue(data);
    }
    //添加单元格内容
    public void addCell(Workbook wb,Sheet ws, int row, int column, String data, String memo)  {
        //1.得到一个POI的工具类
        CreationHelper factory = wb.getCreationHelper();
        //2 得到一个换图的对象
        Drawing drawing = ws.createDrawingPatriarch();
        //3. ClientAnchor是附属在WorkSheet上的一个对象,  其固定在一个单元格的左上角和右下角.
        ClientAnchor anchor = factory.createClientAnchor();
        //4  获取行
        Row row1 = ws.getRow(row) ;
        row1 = row1==null? ws.createRow(row) : row1;
        Cell cell = row1.createCell(column);
        cell.setCellValue(data);
        //5 设置注释
        anchor.setCol1(cell.getColumnIndex());
        anchor.setCol2(cell.getColumnIndex() + 2);
        anchor.setRow1(row1.getRowNum());
        anchor.setRow2(row1.getRowNum() + 3);
        if(!StringUtils.isEmpty(memo)){
            Comment comment0 = drawing.createCellComment(anchor);
            RichTextString richTextString = factory.createRichTextString(memo);
            comment0.setString(richTextString);
            cell.setCellComment(comment0);
        }
    }
}

+ 546 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/excel/ExcelUtils.java

@ -0,0 +1,546 @@
package com.yihu.jw.base.endpoint.common.excel;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * excel 工具类
 *
 * @author HZY
 * @vsrsion 1.0
 * Created at 2017/3/2.
 */
public class ExcelUtils extends AExcelWriter {
    private static Logger logger = LoggerFactory.getLogger(ExcelUtils.class);
    private final static String xls = "xls";
    private final static String xlsx = "xlsx";
    /**
     * 总行数
     */
    private int totalRows = 0;
    /**
     * 总列数
     */
    private int totalCells = 0;
    public int getTotalRows() {
        return totalRows;
    }
    public int getTotalCells() {
        return totalCells;
    }
    /**
     * 创建Excel文档
     *
     * @return
     */
    public static HSSFWorkbook createWorkBook() {
        return new HSSFWorkbook();
    }
    /**
     * 创建sheet
     *
     * @param wb
     * @param sheetName
     * @return
     */
    public static HSSFSheet createSheet(HSSFWorkbook wb, String sheetName) {
        return wb.createSheet(sheetName);
    }
    /**
     * 创建一行多列
     *
     * @param sheet
     * @param rowNum
     * @param columnNum
     * @param cellStyle
     * @return
     */
    public static HSSFRow createRow(HSSFSheet sheet, int rowNum, int columnNum, HSSFCellStyle cellStyle) {
        HSSFRow row = sheet.createRow(rowNum);
        if (columnNum > 0) {
            for (int i = 0; i < columnNum; i++) {
                HSSFCell cell = row.createCell(i);
                if (cellStyle != null) {
                    cell.setCellStyle(cellStyle);
                }
            }
        }
        return row;
    }
    /**
     * 创建多行多列
     *
     * @param sheet`
     * @param rowNum
     * @param rowCount
     * @param columnNum
     * @param cellStyle
     * @return
     */
    public static boolean createRows(HSSFSheet sheet, int rowNum, int rowCount, int columnNum, HSSFCellStyle cellStyle) {
        for (int i = 0; i < rowCount; i++) {
            HSSFRow row = sheet.createRow(rowNum + i);
            if (columnNum > 0) {
                for (int j = 0; j < columnNum; j++) {
                    HSSFCell cell = row.createCell(j);
                    if (cellStyle != null) {
                        cell.setCellStyle(cellStyle);
                    }
                }
            }
        }
        return true;
    }
    /**
     * 合并单元格
     *
     * @param sheet
     * @param firstRow
     * @param lastRow
     * @param firstCol
     * @param lastCol
     * @return
     */
    public static int mergeRegion(HSSFSheet sheet, int firstRow, int lastRow, int firstCol, int lastCol) {
        int num = sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
        return num;
    }
    /**
     * 创建单元格样式
     *
     * @param wb
     * @param align
     * @param bold
     * @param border
     * @param backColor
     * @return
     */
    public static HSSFCellStyle createCellStyle(HSSFWorkbook wb, short align, boolean bold, boolean border, short backColor) {
        HSSFCellStyle style = wb.createCellStyle();
        //字体
        HSSFFont font = wb.createFont();
        font.setBold(bold);
        font.setFontName("宋体");
        font.setFontHeight((short) 220);
        style.setFont(font);
        //设置对齐
//        style.setAlignment(align);
//        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        if (border) {
            // 设置边框
//            style.setBottomBorderColor(HSSFColor.BLACK.index);
//            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
//            style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        }
        if (backColor > 0) {
            style.setFillBackgroundColor((short) backColor);
        }
        return style;
    }
    /* **************************************** Excel 读取 *************************************************************** */
    /**
     * 读取Excel内容
     *
     * @param is       Excel文件流
     * @param fileName excel文件名,包括后缀
     * @return
     * @throws IOException
     */
    public static List<Map<Object, Object>> readExcel(InputStream is, String fileName) throws IOException {
        List<Map<Object, Object>> list = null;
        boolean isExcel2007 = isExcel2007(fileName);
        if (isExcel2007) {
            list = readExcel2007(is);
        } else {
            list = readExcel2003(is);
        }
        return list;
    }
    /**
     *  读取Excel2003内容
     * @param is  Excel文件流
     * @return
     * @throws IOException
     */
    public static List<Map<Object, Object>> readExcel2003(InputStream is) throws IOException {
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
        Map<Object, Object> student = null;
        List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
        // 循环工作表Sheet
        for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
            HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
            if (hssfSheet == null) {
                continue;
            }
            //获取表头字段
            HSSFRow columnName = hssfSheet.getRow(0);
            // 循环行Row
            for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                HSSFRow hssfRow = hssfSheet.getRow(rowNum);
                if (hssfRow != null) {
                    student = setCellVal(columnName, hssfRow);
                    list.add(student);
                }
            }
        }
        return list;
    }
    /**
     * 获取Excel单元格的值
     * @param hssfCell  单元格对象
     * @return
     */
    @SuppressWarnings("static-access")
    public static Object getExcelValue(HSSFCell hssfCell) {
        if(hssfCell==null){
            return null;
        }else  if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
            // 返回布尔类型的值
            return hssfCell.getBooleanCellValue();
        } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
            // 返回数值类型的值
            return (int)hssfCell.getNumericCellValue();
        } else {
            // 返回字符串类型的值
            return hssfCell.getStringCellValue();
        }
    }
    /**
     * 获取Excel2007的内容
     * @param is    输入流
     * @return
     */
    public static List<Map<Object, Object>> readExcel2007(InputStream is) {
        XSSFWorkbook hssfWorkbook = null;
        List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
        try {
            hssfWorkbook = new XSSFWorkbook(is);
            Map<Object, Object> result = null;
            // 循环工作表Sheet
            for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
                XSSFSheet xssfSheet = hssfWorkbook.getSheetAt(numSheet);
                if (xssfSheet == null) {
                    continue;
                }
                //获取表头字段
                XSSFRow columnName = xssfSheet.getRow(0);
                // 循环行Row
                for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
                    XSSFRow hssfRow = xssfSheet.getRow(rowNum);
                    if (hssfRow != null) {
                        result = setCellVal(columnName, hssfRow);
                        list.add(result);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
    @SuppressWarnings("static-access")
    public static Object getExcelValue(XSSFCell xssfCell) {
        if(xssfCell==null){
            return null;
        }else if (xssfCell.getCellType() == xssfCell.CELL_TYPE_BOOLEAN) {
            // 返回布尔类型的值
            return xssfCell.getBooleanCellValue();
        } else if (xssfCell.getCellType() == xssfCell.CELL_TYPE_NUMERIC) {
            // 返回数值类型的值
            return (int)xssfCell.getNumericCellValue();
        } else {
            // 返回字符串类型的值
            return xssfCell.getStringCellValue();
        }
    }
    public static Map<Object, Object> setCellVal(XSSFRow names, XSSFRow values) {
        Map<Object, Object> map = new HashMap<>();
        Object name = null;
        Object value = null;
        for (int i = 0; i < names.getLastCellNum(); i++) {
            name = getExcelValue(names.getCell(i));
            value = getExcelValue(values.getCell(i));
            map.put(name, value);
        }
        return map;
    }
    public static Map<Object, Object> setCellVal(HSSFRow names, HSSFRow values) {
        Map<Object, Object> map = new HashMap<>();
        Object name = null;
        Object value = null;
        for (int i = 0; i < names.getLastCellNum(); i++) {
            name = getExcelValue(names.getCell(i));
            value = getExcelValue(values.getCell(i));
            map.put(name, value);
        }
        return map;
    }
    public static boolean isExcel2007(String filePath) {
        return filePath.matches("^.+\\.(?i)(xlsx)$");
    }
    /* ********************************  重写poi,2018-05-16 by hzy   ******************************************* */
    /**
     * 获取excel对象
     * @param file
     * @return
     */
    public static Workbook getWorkBook(MultipartFile file) {
        //获得文件名
        String fileName = file.getOriginalFilename();
        //创建Workbook工作薄对象,表示整个excel
        Workbook workbook = null;
        try {
            //获取excel文件的io流
            InputStream is = file.getInputStream();
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
            if(fileName.toLowerCase().endsWith(xls)){
                //2003
                workbook = new HSSFWorkbook(is);
            }else if(fileName.toLowerCase().endsWith(xlsx)){
                //2007
                workbook = new XSSFWorkbook(is);
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info(e.getMessage());
        }
        return workbook;
    }
    /**
     * 获取Excel的内容
     * @param file    上传的文件
     * @return
     */
    public static List<Map<Object, Object>> readExcel (File file) {
        Workbook workBook = null;
        List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
        try {
            workBook = getWorkBook(file);
            Map<Object, Object> result = null;
            // 循环工作表Sheet
            for (int numSheet = 0; numSheet < workBook.getNumberOfSheets(); numSheet++) {
                Sheet sheet = workBook.getSheetAt(numSheet);
                if (sheet == null) {
                    continue;
                }
                //获取表头字段
                Row columnName = sheet.getRow(0);
                // 循环行Row
                for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
                    Row hssfRow = sheet.getRow(rowNum);
                    if (hssfRow != null) {
                        result = setCellVal(columnName, hssfRow);
                        list.add(result);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    /**
     * 设置单元格值
     * @param names
     * @param values
     * @return
     */
    public static Map<Object, Object> setCellVal(Row names, Row values) {
        Map<Object, Object> map = new HashMap<>();
        Object name = null;
        Object value = null;
        for (int i = 0; i < names.getLastCellNum(); i++) {
            name = getCellValue(names.getCell(i));
            value = getCellValue(values.getCell(i));
            map.put(name, value);
        }
        return map;
    }
    /**
     * 获取excel对象
     * @param file
     * @return
     */
    public static Workbook getWorkBook(File file) throws IOException {
        //创建Workbook工作薄对象,表示整个excel
        Workbook workbook = null;
        FileOutputStream fileOut = null;
        try {
            //获得文件名
            String fileName = file.getName();
            //创建excel文件的out流
             fileOut = new FileOutputStream(file);
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
            if(fileName.toLowerCase().endsWith(xls)){
                //2003
                workbook = new HSSFWorkbook();
            }else if(fileName.toLowerCase().endsWith(xlsx)){
                //2007
                workbook = new XSSFWorkbook();
            }
            workbook.write(fileOut);
        } catch (IOException e) {
            e.printStackTrace();
            logger.info(e.getMessage());
        }finally {
            if (fileOut!=null){
                fileOut.flush();
                fileOut.close();
            }
        }
        return workbook;
    }
    /**
     * 获取excel对象
     * @param is
     * @return
     */
    public static Workbook getWorkBook(String fileName,InputStream is) {
        //创建Workbook工作薄对象,表示整个excel
        Workbook workbook = null;
        try {
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
            if(fileName.toLowerCase().endsWith(xls)){
                //2003
                workbook = new HSSFWorkbook(is);
            }else if(fileName.toLowerCase().endsWith(xlsx)){
                //2007
                workbook = new XSSFWorkbook(is);
            }
        } catch (IOException e) {
            logger.info(e.getMessage());
        }
        return workbook;
    }
    /**
     *   获取单元格值
     * @param cell     excel单元格对象
     * @return
     */
    public static String getCellValue(Cell cell){
        String cellValue = "";
        if(cell == null){
            return cellValue;
        }
        //把数字当成String来读,避免出现1读成1.0的情况
        if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
            cell.setCellType(Cell.CELL_TYPE_STRING);
        }
        //判断数据的类型
        switch (cell.getCellType()){
            case Cell.CELL_TYPE_NUMERIC: //数字
                cellValue = String.valueOf(cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_STRING: //字符串
                cellValue = String.valueOf(cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN: //Boolean
                cellValue = String.valueOf(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA: //公式
                cellValue = String.valueOf(cell.getCellFormula());
                break;
            case Cell.CELL_TYPE_BLANK: //空值
                cellValue = "";
                break;
            case Cell.CELL_TYPE_ERROR: //故障
                cellValue = "非法字符";
                break;
            default:
                cellValue = "未知类型";
                break;
        }
        return cellValue;
    }
    public void addCell(Sheet ws, int row, int column, String data )  {
        Row row1 = ws.createRow(row);
        Cell cell = row1.createCell(column);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(data);
    }
    //添加单元格内容
    public static void addCellData(Sheet sheet, int column, int row, String data){
        Row sheetRow = sheet.getRow(row);
        if(sheetRow==null){
            sheetRow = sheet.createRow(row);
        }
        Cell cell= sheetRow.createCell(column);
        cell.setCellValue(data);
    }
    //添加单元格内容带样式
    public static void addCellData(Sheet sheet, int column, int row, String data, CellStyle cellStyle){
        Row sheetRow = sheet.getRow(row);
        if(sheetRow==null){
            sheetRow = sheet.createRow(row);
        }
        Cell cell= sheetRow.createCell(column);
        cell.setCellValue(data);
        cell.setCellStyle(cellStyle);
    }
    @Override
    public void write(Workbook wwb, List ls, File file) throws Exception {
    }
}

+ 224 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/populationBatchImport/PopulationMsg.java

@ -0,0 +1,224 @@
package com.yihu.jw.base.endpoint.common.populationBatchImport;
import com.yihu.jw.util.excel.ExcelUtil;
import com.yihu.jw.util.excel.Validation;
import com.yihu.jw.util.excel.annotation.Location;
import com.yihu.jw.util.excel.annotation.Row;
import com.yihu.jw.util.excel.annotation.Title;
import com.yihu.jw.util.excel.annotation.ValidRepeat;
import javax.persistence.Column;
import java.util.Date;
import java.util.Map;
import java.util.Set;
/**
 *  基础人口信息列表-excel实体类
 *
 * @author zdm
 * @vsrsion 1.0
 * Created at 2018/10/15.
 */
@Row(start = 1)
@Title(names= "{'租户名称', '时间','常住人口', '户籍人口', '糖尿病人数', '高血压人数', '任务数'}")
public class PopulationMsg extends ExcelUtil implements Validation {
    @Location(x=0)
    @ValidRepeat
    String saasName;
    @Location(x=1)
    @ValidRepeat
    String year;
    @Location(x=2)
    @ValidRepeat
    Integer populationNum;
    @Location(x=3)
    @ValidRepeat
    Integer regisPopulationNum;
    @Location(x=4)
    @ValidRepeat
    Integer dmNum;
    @Location(x=5)
    @ValidRepeat
    Integer hbpNum;
    @Location(x=6)
    @ValidRepeat
    Integer taskNum;
    private String  saasId;
    //租户创建时间
    private Date saasCreateTime;
    //所属省代码
    private String  provinceCode;
    //省份名称
    private String  provinceName;
    //城市编码
    private String  cityCode;
    //城市名称
    private String  cityName;
    //所属区代码
    private String  districtCode;
    //区名
    private String  districtName;
    //慢病人数
    private Integer ncdNum;
    @Override
    public int validate(Map<String, Set> repeatMap) {
        int rs = 1;
        if(!repeatMap.get("saasName").add(saasName+year)){
            rs = 0;
            addErrorMsg("saasName", "已添加"+year+saasName+"的基础人口信息,请直接修改即可");
        }
        if(populationNum<0){
            rs = 0;
            addErrorMsg("populationNum", "常住人口数不能小于0!");
        }
        if(regisPopulationNum<0){
            rs = 0;
            addErrorMsg("regisPopulationNum", "户籍人口数不能小于0!");
        }
        if(dmNum<0){
            rs = 0;
            addErrorMsg("dmNum", "糖尿病人口不能小于0!");
        }
        if(hbpNum<0){
            rs = 0;
            addErrorMsg("hbpNum", "高血压人口不能小于0!");
        }
        if(taskNum<0){
            rs = 0;
            addErrorMsg("taskNum", "任务数不能小于0!");
        }
        return rs;
    }
    public String getSaasName() {
        return saasName;
    }
    public void setSaasName(String saasName) {
        this.saasName = saasName;
    }
    public String getYear() {
        return year;
    }
    public void setYear(String year) {
        this.year = year;
    }
    public Integer getPopulationNum() {
        return populationNum;
    }
    public void setPopulationNum(Integer populationNum) {
        this.populationNum = populationNum;
    }
    public Integer getRegisPopulationNum() {
        return regisPopulationNum;
    }
    public void setRegisPopulationNum(Integer regisPopulationNum) {
        this.regisPopulationNum = regisPopulationNum;
    }
    public Integer getDmNum() {
        return dmNum;
    }
    public void setDmNum(Integer dmNum) {
        this.dmNum = dmNum;
    }
    public Integer getHbpNum() {
        return hbpNum;
    }
    public void setHbpNum(Integer hbpNum) {
        this.hbpNum = hbpNum;
    }
    public Integer getTaskNum() {
        return taskNum;
    }
    public void setTaskNum(Integer taskNum) {
        this.taskNum = taskNum;
    }
    public Date getSaasCreateTime() {
        return saasCreateTime;
    }
    public void setSaasCreateTime(Date saasCreateTime) {
        this.saasCreateTime = saasCreateTime;
    }
    public String getProvinceCode() {
        return provinceCode;
    }
    public void setProvinceCode(String provinceCode) {
        this.provinceCode = provinceCode;
    }
    public String getProvinceName() {
        return provinceName;
    }
    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }
    public String getCityCode() {
        return cityCode;
    }
    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }
    public String getCityName() {
        return cityName;
    }
    public void setCityName(String cityName) {
        this.cityName = cityName;
    }
    public String getDistrictCode() {
        return districtCode;
    }
    public void setDistrictCode(String districtCode) {
        this.districtCode = districtCode;
    }
    public String getDistrictName() {
        return districtName;
    }
    public void setDistrictName(String districtName) {
        this.districtName = districtName;
    }
    public Integer getNcdNum() {
        return ncdNum;
    }
    public void setNcdNum(Integer ncdNum) {
        this.ncdNum = ncdNum;
    }
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
}

+ 64 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/populationBatchImport/PopulationMsgReader.java

@ -0,0 +1,64 @@
package com.yihu.jw.base.endpoint.common.populationBatchImport;
import com.yihu.jw.base.endpoint.common.excel.AExcelReader;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.*;
/**
 * 基础人口信息列表-excel解析类
 *
 * @author zdm
 * @vsrsion 1.0
 * Created at 2018/10/15.
 */
public class PopulationMsgReader extends AExcelReader {
    @Override
    public void read(Workbook rwb) throws Exception {
        try {
            Iterator<Sheet> sheets = rwb.sheetIterator();
            int j = 0, rows;
            PopulationMsg populationMsg;
            getRepeat().put("saasName", new HashSet<>());
            getRepeat().put("year", new HashSet<>());
            getRepeat().put("populationNum", new HashSet<>());
            getRepeat().put("regisPopulationNum", new HashSet<>());
            getRepeat().put("dmNum", new HashSet<>());
            getRepeat().put("hbpNum", new HashSet<>());
            getRepeat().put("taskNum", new HashSet<>());
            while (sheets.hasNext()){
                Sheet sheet = sheets.next();
                if ((rows = sheet.getLastRowNum()) == 0) {
                    continue;
                }
                for (int i = 1; i <= rows; i++) {
                    populationMsg = new PopulationMsg();
                    populationMsg.setSaasName(replaceBlank(getCellCont(sheet, i, 0)));
                    populationMsg.setYear(replaceBlank(getCellCont(sheet, i, 1)));
                    populationMsg.setPopulationNum(null == getCellCont(sheet, i, 2) ? 0 : Integer.valueOf(getCellCont(sheet, i, 2).trim()));
                    populationMsg.setRegisPopulationNum(null == getCellCont(sheet, i, 3) ? 0 : Integer.valueOf(getCellCont(sheet, i, 3).trim()));
                    populationMsg.setDmNum(null == getCellCont(sheet, i, 4) ? 0 : Integer.valueOf(getCellCont(sheet, i, 4).trim()));
                    populationMsg.setHbpNum(null == getCellCont(sheet, i, 5) ? 0 : Integer.valueOf(getCellCont(sheet, i, 5).trim()));
                    populationMsg.setTaskNum(null == getCellCont(sheet, i, 6) ? 0 : Integer.valueOf(getCellCont(sheet, i, 6).trim()));
                    int rs = populationMsg.validate(repeat);
                    if (rs == 0) {
                        errorLs.add(populationMsg);
                    } else if (rs == 1) {
                        correctLs.add(populationMsg);
                    }
                }
                j++;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            if (rwb != null) {
                rwb.close();
            }
        }
    }
}

+ 110 - 5
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/population/BasePopulationEndpoint.java

@ -1,5 +1,7 @@
package com.yihu.jw.base.endpoint.population;
import com.yihu.jw.base.endpoint.common.excel.AExcelReader;
import com.yihu.jw.base.endpoint.common.populationBatchImport.*;
import com.yihu.jw.base.service.area.BaseCityService;
import com.yihu.jw.base.service.area.BaseProvinceService;
import com.yihu.jw.base.service.area.BaseTownService;
@ -8,6 +10,7 @@ import com.yihu.jw.base.service.saas.SaasService;
import com.yihu.jw.entity.base.area.BaseTownDO;
import com.yihu.jw.entity.base.population.BasePopulationDO;
import com.yihu.jw.entity.base.saas.SaasDO;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.jw.restmodel.base.population.BasePopulationVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
@ -21,19 +24,22 @@ import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;
/**
 * 基础人口基数信息控制器
 *
 * @version <pre>
 *                                                       Author	Version		Date		Changes
 *                                                       litaohong 	1.0  		2018年09月26日 	update
 *           Author	Version		Date		Changes
 *           litaohong 	1.0  		2018年09月26日 	update
 *
 *                                                       </pre>
 *           </pre>
 * @since 1.
 */
@RestController
@ -51,6 +57,7 @@ public class BasePopulationEndpoint extends EnvelopRestEndpoint {
    private BaseProvinceService baseProvinceService;
    @Autowired
    private BaseCityService baseCityService;
    static final String parentFile = "population";
    @PostMapping(value = BaseRequestMapping.BasePopulation.CREATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ -253,5 +260,103 @@ public class BasePopulationEndpoint extends EnvelopRestEndpoint {
        return (null != basePopulationDOList && basePopulationDOList.size() > 0) ? true : false;
    }
    @PostMapping(value = BaseRequestMapping.BasePopulation.POPULATION_BATCH_IMPORT)
    @Transactional(rollbackFor = Exception.class)
    @ApiOperation(value = "基础人口信息列表导入")
    public Envelop importData(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestPart(value = "file") MultipartFile file,
            HttpServletRequest request) throws IOException, ManageException {
        try {
            request.setCharacterEncoding("UTF-8");
            AExcelReader excelReader = new PopulationMsgReader();
            excelReader.read(file);
            //验证未通过
            List<PopulationMsg> errorLs = excelReader.getErrorLs();
            List<PopulationMsg> correctLs = excelReader.getCorrectLs();
            //获取所有租户+年份的基础人口信息
            Set<String> populationNameAndYear =new HashSet<String>( basePopulationService.getFacilityCodeByServerType());
            PopulationMsg model;
            List saveLs = new ArrayList<>();
            if (correctLs.size() > 0) {
                for (int i = 0; i < correctLs.size(); i++) {
                    model = correctLs.get(i);
                    Map<Boolean,PopulationMsg> map=validate(model,populationNameAndYear);
                    if (null==map.get(true)) {
                        errorLs.add(model);
                    } else {
                        saveLs.add(model);
                    }
                }
                Map<String, Object> result = basePopulationService.batchInsertPopulation(saveLs);
                result.put("errorLs",errorLs);
                return success("导入成功!", result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return failed("导入异常,请检查导入文件格式"+e.getMessage());
        }
        return failed("导入失败");
    }
    private Map<Boolean,PopulationMsg> validate(PopulationMsg model, Set<String> populationNameAndYear) throws Exception{
        Map<Boolean,PopulationMsg> msgMap =new HashMap<>();
        Boolean rs = true;
        //验证租户是否存在
        SaasDO saasDO = saasService.findByName(model.getSaasName());
        String nameAndYear=model.getSaasName()+model.getYear();
        //验证租户+年份的人口基数是否存在
        if (populationNameAndYear.contains(nameAndYear)) {
            model.addErrorMsg("saasName", "已添加"+model.getYear()+model.getSaasName()+"的基础人口信息,请直接修改即可!");
            rs = false;
        }
        if (null==saasDO) {
            model.addErrorMsg("saasName", "租户不存在,请核对!");
            rs = false;
        }else {
            model.setSaasId(saasDO.getId());
            model.setSaasCreateTime(saasDO.getCreateTime());
            String areaCode = saasDO.getAreaNumber();
            String filters = "province?" + areaCode + " g1;city?" + areaCode + " g1;code?" + areaCode + " g1;";
            List<BaseTownDO> baseTowns = baseTownService.search(filters);
            BaseTownDO baseTownDO = (null != baseTowns && baseTowns.size() > 0 ? baseTowns.get(0) : null);
            if (null != baseTownDO) {
                if (baseTownDO.getCode().equals(areaCode)) {
                    model.setProvinceCode(baseTownDO.getProvince());
                    model.setProvinceName(baseProvinceService.getNameByCode(baseTownDO.getProvince()));
                    //市编码
                    model.setCityCode(baseTownDO.getCity());
                    model.setCityName(baseCityService.getNameByCode(baseTownDO.getCity()));
                    //区县编码
                    model.setDistrictCode(areaCode);
                    model.setDistrictName(baseTownDO.getName());
                } else if (baseTownDO.getCity().equals(areaCode)) {
                    model.setProvinceCode(baseTownDO.getProvince());
                    model.setProvinceName(baseProvinceService.getNameByCode(baseTownDO.getProvince()));
                    //市编码
                    model.setCityCode(areaCode);
                    model.setCityName(baseCityService.getNameByCode(areaCode));
                    //区县编码
                    model.setDistrictCode("");
                    model.setDistrictName("");
                } else if (baseTownDO.getProvince().equals(areaCode)) {
                    //省编码
                    model.setProvinceCode(areaCode);
                    model.setProvinceName(baseProvinceService.getNameByCode(areaCode));
                    //市编码
                    model.setCityCode("");
                    model.setCityName("");
                    //区县编码
                    model.setDistrictCode("");
                    model.setDistrictName("");
                }
            }
        }
        msgMap.put(rs,model);
        return msgMap;
    }
}

+ 71 - 3
svr/svr-base/src/main/java/com/yihu/jw/base/service/population/BasePopulationService.java

@ -1,19 +1,29 @@
package com.yihu.jw.base.service.population;
import com.yihu.jw.base.dao.population.BasePopulationDao;
import com.yihu.jw.base.endpoint.common.populationBatchImport.PopulationMsg;
import com.yihu.jw.entity.base.population.BasePopulationDO;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 基础人口基数信息服务service
 *
 * @version <pre>
 *          Author	Version		Date		Changes
 *          litaohong    1.0  2018年09月26日 update
 *                            Author	Version		Date		Changes
 *                            litaohong    1.0  2018年09月26日 update
 *
 *          </pre>
 *                            </pre>
 * @since 1.
 */
@Service
@ -24,4 +34,62 @@ public class BasePopulationService extends BaseJpaService<BasePopulationDO, Base
    public BasePopulationDO findById(String id) {
        return basePopulationDao.findOne(id);
    }
    /**
     * 批量导入基础人口信息的集合
     *
     * @param populations 基础人口信息
     */
    public Map<String, Object> batchInsertPopulation(List<PopulationMsg> populations) throws ManageException {
        Map<String, Object> result = new HashMap<>();
        //批量存储的集合
        int correctCount = 0;
        List<BasePopulationDO> corrects = new ArrayList<>();
        BasePopulationDO basePopulationDO;
        //批量存储
        for (PopulationMsg populationMsg : populations) {
            basePopulationDO = new BasePopulationDO();
            basePopulationDO.setId(getCode());
            basePopulationDO.setSaasId(populationMsg.getSaasId());
            basePopulationDO.setSaasName(populationMsg.getSaasName());
            basePopulationDO.setSaasCreateTime(populationMsg.getSaasCreateTime());
            basePopulationDO.setYear(populationMsg.getYear());
            basePopulationDO.setProvinceCode(populationMsg.getProvinceCode());
            basePopulationDO.setProvinceName(populationMsg.getProvinceName());
            basePopulationDO.setCityCode(populationMsg.getCityCode());
            basePopulationDO.setCityName(populationMsg.getCityName());
            basePopulationDO.setDistrictCode(populationMsg.getDistrictCode());
            basePopulationDO.setDistrictName(populationMsg.getDistrictName());
            basePopulationDO.setRegisPopulationNum(populationMsg.getRegisPopulationNum());
            basePopulationDO.setPopulationNum(populationMsg.getPopulationNum());
            //糖尿病人数
            basePopulationDO.setDmNum(populationMsg.getDmNum());
            //高血压人数
            basePopulationDO.setHbpNum(populationMsg.getHbpNum());
            basePopulationDO.setTaskNum(populationMsg.getTaskNum());
            //慢病人数
            basePopulationDO.setNcdNum(populationMsg.getHbpNum() + populationMsg.getDmNum());
            corrects.add(basePopulationDO);
            if (corrects.size() > 100) {
                basePopulationDao.save(corrects);
                correctCount += corrects.size();
                corrects.clear();
            }
        }
        if (!corrects.isEmpty()) {
            basePopulationDao.save(corrects);
            correctCount += corrects.size();
        }
        result.put("correctCount", correctCount);
        return result;
    }
    public List<String> getFacilityCodeByServerType() {
        Session s = currentSession();
        String hql = "SELECT concat(p.saas_name,p.year)  FROM  base_population p ";
        Query query = s.createSQLQuery(hql);
        return query.list();
    }
}

+ 4 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/saas/SaasService.java

@ -292,4 +292,8 @@ public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
        return saasDao.findById(id);
    }
    public SaasDO findByName(String name){
        return saasDao.findByName(name);
    }
}