基础信息导入

This commit is contained in:
wans 2021-03-19 10:18:51 +08:00
parent 8166d7698f
commit a79bf7f9b7
5 changed files with 139 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package com.cm.population.controller.apis.basepopulationinfo;
import com.alibaba.excel.EasyExcel;
import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.component.SecurityComponent;
@ -15,10 +16,16 @@ import com.cm.common.result.SuccessResultList;
import com.cm.population.pojo.dtos.basepopulationinfo.BasePopulationInfoDTO;
import com.cm.population.pojo.vos.basepopulationinfo.BasePopulationInfoVO;
import com.cm.population.service.basepopulationinfo.IBasePopulationInfoService;
import com.cm.population.uploadexcellistener.populationbaseinfo.PopulationBaseInfoUploadListener;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -122,6 +129,36 @@ public class BasePopulationInfoController extends AbstractController {
return basePopulationInfoService.countBasePopulationInfo(params);
}
@ApiOperation(value = "人员基础信息模板下载", notes = "党费管理Excel模板下载接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("downloadtemplate")
public void downLoadTemplate(HttpServletResponse response) throws SearchException, IOException {
response.setContentType("application/vnd.ms-excel");
String fileName = URLEncoder.encode("人员基础信息Excel模板", "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
List<List<String>> listHeaders = new ArrayList<>();
String [] headers = {
"姓名","曾用名","性别","身份证号","出生日期","联系方式","籍贯","民族","宗教信仰","学历","政治面貌",
"婚姻情况","职业类别","职业","服务处所","户籍地(省)","市/直辖","区/县","详细地址","现住地(省)",
"市/直辖","区/县","详细地址"
};
List<List<String>> listHeader = new ArrayList<>();
for (String item : headers){
List<String> title = new ArrayList<>();
title.add(item);
listHeader.add(title);
}
EasyExcel.write(response.getOutputStream()).sheet("人员基础信息").head(listHeader).doWrite(new ArrayList());
}
@ApiOperation(value = "人员基础信息导入", notes = "人员基础信息导入接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("uploadtemplate")
public SuccessResultData uploadTemplate(@RequestParam(value = "file") MultipartFile file) throws SearchException, IOException {
EasyExcel.read(file.getInputStream(),new PopulationBaseInfoUploadListener(basePopulationInfoService)).sheet().doRead();
return new SuccessResultData("导入完成");
}
@ApiOperation(value = "当前用户id信息", notes = "当前用户id信息接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("getcurrentuseridinfo")

View File

@ -159,4 +159,10 @@ public interface IBasePopulationInfoService {
* @return
*/
BasePopulationInfoDTO getBasePopulationInfo(Map<String, Object> params) throws SearchException;
/**
* 人员基础信息导入保存
* @param dataObj
*/
void saveBasePopulationInfoImport(Map<String, Object> dataObj);
}

View File

@ -88,6 +88,20 @@ public class BasePopulationInfoServiceImpl extends AbstractService implements IB
return basePopulationInfoId;
}
@Override
public void saveBasePopulationInfoImport(Map<String, Object> dataObj) {
String idCardNumber = dataObj.get("idCardNumber").toString();
Map<String, Object> queryMap = getHashMap(4);
queryMap.put("idCardNumber",idCardNumber);
BasePopulationInfoDTO basePopulationInfo = basePopulationInfoDao.getBasePopulationInfo(queryMap);
if(basePopulationInfo == null){
String basePopulationInfoId = UUIDUtil.getUUID();
dataObj.put("basePopulationInfoId", basePopulationInfoId);
setSaveInfo(dataObj);
basePopulationInfoDao.saveBasePopulationInfo(dataObj);
}
}
@Override
public SuccessResult removeBasePopulationInfo(String ids) throws RemoveException {
removeBasePopulationInfoInfo(null, ids);

View File

@ -0,0 +1,55 @@
package com.cm.population.uploadexcellistener.populationbaseinfo;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.cm.common.utils.UUIDUtil;
import com.cm.population.service.basepopulationinfo.IBasePopulationInfoService;
import java.util.HashMap;
import java.util.Map;
/**
* @author xwangs
* @create 2021-03-18 17:26
* @description
*/
public class PopulationBaseInfoUploadListener extends AnalysisEventListener<Map<String, Object>> {
private static final int BATCH_COUNT = 3000;
private IBasePopulationInfoService service;
public PopulationBaseInfoUploadListener(IBasePopulationInfoService serviceObj){
this.service = serviceObj;
}
@Override
public void invoke(Map<String, Object> data, AnalysisContext context) {
Map<String, Object> dataObj = new HashMap<>(32);
dataObj.put("fullName",data.get(0));
dataObj.put("nameUsedBefore",data.get(1));
dataObj.put("gender",data.get(2));
dataObj.put("idCardNumber",data.get(3));
dataObj.put("birthDate",data.get(4));
dataObj.put("telephone",data.get(5));
dataObj.put("nativePlace",data.get(6));
dataObj.put("nation",data.get(7));
dataObj.put("religion",data.get(8));
dataObj.put("education",data.get(9));
dataObj.put("politicalStatus",data.get(10));
dataObj.put("maritalStatus",data.get(11));
dataObj.put("occupationCategory",data.get(12));
dataObj.put("occupation",data.get(13));
dataObj.put("serviceSpace",data.get(14));
dataObj.put("registeredResidence",data.get(15).toString() + data.get(16).toString() + data.get(17).toString());
dataObj.put("registeredResidenceAddr",data.get(18));
dataObj.put("currentResidence",data.get(19).toString() + data.get(20).toString() + data.get(21).toString());
dataObj.put("currentResidenceAddr",data.get(22));
service.saveBasePopulationInfoImport(dataObj);
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
}

View File

@ -23,6 +23,12 @@
<button type="button" id="search" class="layui-btn layui-btn-sm">
<i class="fa fa-lg fa-search"></i> 搜索
</button>
<button type="button" id="downloadTemplate" class="layui-btn layui-btn-sm">
<i class="fa fa-lg fa-download"></i> 下载模板
</button>
<button type="button" id="uploadTemplate" class="layui-btn layui-btn-sm">
<i class="fa fa-lg fa-upload"></i> 导入数据
</button>
</div>
<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
<!-- 表头按钮组 -->
@ -51,7 +57,7 @@
base: 'assets/layuiadmin/'
}).extend({
index: 'lib/index'
}).use(['index', 'table', 'laydate', 'common'], function() {
}).use(['index', 'table', 'laydate', 'common','upload'], function() {
var $ = layui.$;
var $win = $(window);
var table = layui.table;
@ -59,8 +65,22 @@
var laydate = layui.laydate;
var common = layui.common;
var resizeTimeout = null;
var upload = layui.upload;
var tableUrl = 'api/basepopulationinfo/listpagebasepopulationinfo';
var uploadInst = upload.render({
elem: '#uploadTemplate' //绑定元素
,url: 'api/basepopulationinfo/uploadtemplate' //上传接口
,exts: 'xlsx'
,done: function(res){
layer.msg(res.data);
reloadTable(1);
}
,error: function(){
console.log("erererer");
}
});
// 初始化表格
function initTable() {
table.render({
@ -228,6 +248,12 @@
$(document).on('click', '#search', function() {
reloadTable(1);
});
// 下载模板
$(document).on('click', '#downloadTemplate', function() {
window.open('api/basepopulationinfo/downloadtemplate');
});
// 事件 - 增删改
table.on('toolbar(dataTable)', function(obj) {
var layEvent = obj.event;