|
|
@@ -1,19 +1,32 @@
|
|
|
package com.jpsoft.employment.modules.base.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.employment.config.OSSConfig;
|
|
|
import com.jpsoft.employment.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.employment.modules.common.utils.DES3;
|
|
|
+import com.jpsoft.employment.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.employment.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.employment.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.employment.modules.common.dto.Sort;
|
|
|
import com.jpsoft.employment.modules.base.entity.PersonInfo;
|
|
|
import com.jpsoft.employment.modules.base.service.PersonInfoService;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -24,6 +37,12 @@ public class PersonInfoController {
|
|
|
|
|
|
@Autowired
|
|
|
private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+ @Value("${jwt.secret}")
|
|
|
+ private String jwtSecret;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
|
|
|
|
|
@ApiOperation(value="创建空记录")
|
|
|
@@ -49,6 +68,9 @@ public class PersonInfoController {
|
|
|
personInfo.setDelFlag(false);
|
|
|
personInfo.setCreateBy(subject);
|
|
|
personInfo.setCreateTime(new Date());
|
|
|
+ DES3 des3 = new DES3();
|
|
|
+ personInfo.setPassword(des3.encrypt(jwtSecret,"123456"));
|
|
|
+ personInfo.setStatus("0");
|
|
|
|
|
|
int affectCount = personInfoService.insert(personInfo);
|
|
|
|
|
|
@@ -195,7 +217,7 @@ public class PersonInfoController {
|
|
|
@ApiOperation(value="列表")
|
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
public MessageResult<Map> pageList(
|
|
|
- String id,
|
|
|
+ String realName,
|
|
|
@RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
@RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
HttpServletRequest request){
|
|
|
@@ -209,13 +231,12 @@ public class PersonInfoController {
|
|
|
Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("id_","asc"));
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(id)) {
|
|
|
- searchParams.put("id","%" + id + "%");
|
|
|
+ if (StringUtils.isNotEmpty(realName)) {
|
|
|
+ searchParams.put("realName","%" + realName + "%");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
|
|
|
|
|
@@ -224,4 +245,193 @@ public class PersonInfoController {
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="导入人员")
|
|
|
+ @PostMapping("importXls")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
+ })
|
|
|
+ public MessageResult<String> importXls(MultipartFile uploadFile, @RequestAttribute String subject){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ int sheetIndex = 0;
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
+
|
|
|
+ String[] colNames = new String[]{"用户名","真实姓名","联系电话","身份证号","年龄","性别"};
|
|
|
+ Map<String,Integer> headerMap = new HashMap<>();
|
|
|
+
|
|
|
+ Row headerRow = sheet1.getRow(0);
|
|
|
+
|
|
|
+ for (int i=0;i<colNames.length;i++) {
|
|
|
+ String colName = colNames[i];
|
|
|
+
|
|
|
+ for (int j = 0; j < headerRow.getLastCellNum(); j++) {
|
|
|
+ String title = headerRow.getCell(j).getStringCellValue();
|
|
|
+
|
|
|
+ if (title.indexOf(colName)!=-1){
|
|
|
+ headerMap.put(colName, j);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 4;
|
|
|
+
|
|
|
+ int count = sheet1.getLastRowNum();
|
|
|
+
|
|
|
+ for(int rowIndex=1 ; rowIndex<=count; rowIndex++){
|
|
|
+ try {
|
|
|
+
|
|
|
+ String userName = "";
|
|
|
+
|
|
|
+ if(headerMap.containsKey("用户名")) {
|
|
|
+ userName = poiUtils.getCellValue(sheetIndex, rowIndex, headerMap.get("用户名")).toString().replace(" ", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ String realName = "";
|
|
|
+
|
|
|
+ if(headerMap.containsKey("真实姓名")) {
|
|
|
+ realName = poiUtils.getCellValue(sheetIndex, rowIndex, headerMap.get("真实姓名")).toString().replace(" ", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ String phone = "";
|
|
|
+
|
|
|
+ if(headerMap.containsKey("联系电话")) {
|
|
|
+ phone = poiUtils.getCellValue(sheetIndex, rowIndex, headerMap.get("联系电话")).toString().replace(" ", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ String idCard = "";
|
|
|
+
|
|
|
+ if(headerMap.containsKey("身份证号")){
|
|
|
+ idCard = poiUtils.getCellValue(sheetIndex,rowIndex,headerMap.get("身份证号")).toString().replace(" ","");
|
|
|
+ }
|
|
|
+
|
|
|
+ String age = "";
|
|
|
+
|
|
|
+ if(headerMap.containsKey("年龄")){
|
|
|
+ age = poiUtils.getCellValue(sheetIndex,rowIndex,headerMap.get("年龄")).toString().replace(" ","");
|
|
|
+ }
|
|
|
+
|
|
|
+ String gender = "";
|
|
|
+
|
|
|
+ if(headerMap.containsKey("性别")){
|
|
|
+ gender = poiUtils.getCellValue(sheetIndex,rowIndex,headerMap.get("性别")).toString().replace(" ","");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(userName)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写用户名!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(realName)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写真实姓名!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(phone)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写联系电话!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(idCard)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写身份证号!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(age)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写年龄!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(gender)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写性别!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+// String platform = "";
|
|
|
+//
|
|
|
+// if(StringUtils.isEmpty(platform)){
|
|
|
+// sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("填写的平台在系统中不存在!");
|
|
|
+// failCount++;
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+
|
|
|
+ //用户身份
|
|
|
+ PersonInfo personInfo = new PersonInfo();
|
|
|
+ personInfo.setId(UUID.randomUUID().toString());
|
|
|
+ personInfo.setPhone(phone);
|
|
|
+ personInfo.setUserName(userName);
|
|
|
+ personInfo.setRealName(realName);
|
|
|
+ personInfo.setIdCard(idCard);
|
|
|
+ personInfo.setAge(Integer.parseInt(age));
|
|
|
+
|
|
|
+ if("男".equals(gender)){
|
|
|
+ personInfo.setGender("0");
|
|
|
+ }
|
|
|
+ else if("女".equals(gender)){
|
|
|
+ personInfo.setGender("1");
|
|
|
+ }
|
|
|
+ personInfo.setStatus("0");
|
|
|
+ personInfo.setCreateBy(subject);
|
|
|
+ personInfo.setCreateTime(new Date());
|
|
|
+ personInfo.setDelFlag(false);
|
|
|
+
|
|
|
+ //保存新用户
|
|
|
+ personInfoService.insert(personInfo);
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+ catch(Exception innerEx){
|
|
|
+ logger.error(innerEx.getMessage(),innerEx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (failCount>0){
|
|
|
+ //有导入失败的记录
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
+
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(sheetIndex,validateColIndex,1 + affectCount + failCount);
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
|
|
|
+
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|