|
@@ -1,23 +1,43 @@
|
|
|
package com.jpsoft.enterprise.modules.base.controller;
|
|
package com.jpsoft.enterprise.modules.base.controller;
|
|
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
import com.github.pagehelper.Page;
|
|
|
|
|
+import com.jpsoft.enterprise.config.OSSConfig;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.base.entity.CompanyInfo;
|
|
|
import com.jpsoft.enterprise.modules.base.entity.PersonInfo;
|
|
import com.jpsoft.enterprise.modules.base.entity.PersonInfo;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.base.service.CompanyInfoService;
|
|
|
import com.jpsoft.enterprise.modules.base.service.PersonInfoService;
|
|
import com.jpsoft.enterprise.modules.base.service.PersonInfoService;
|
|
|
import com.jpsoft.enterprise.modules.common.dto.MessageResult;
|
|
import com.jpsoft.enterprise.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.enterprise.modules.common.dto.Sort;
|
|
import com.jpsoft.enterprise.modules.common.dto.Sort;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.common.utils.AESUtil;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.common.utils.OSSUtil;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.enterprise.modules.common.utils.PojoUtils;
|
|
import com.jpsoft.enterprise.modules.common.utils.PojoUtils;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.sys.entity.User;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.sys.service.DataDictionaryService;
|
|
|
|
|
+import com.jpsoft.enterprise.modules.sys.service.UserService;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 企业用户管理
|
|
|
|
|
+ * sz
|
|
|
|
|
+ */
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/base/personInfo")
|
|
@RequestMapping("/base/personInfo")
|
|
|
@Api(description = "personInfo")
|
|
@Api(description = "personInfo")
|
|
@@ -26,6 +46,14 @@ public class PersonInfoController {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private PersonInfoService personInfoService;
|
|
private PersonInfoService personInfoService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DataDictionaryService dataDictionaryService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UserService userService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
|
|
|
|
@ApiOperation(value="创建空记录")
|
|
@ApiOperation(value="创建空记录")
|
|
|
@GetMapping("create")
|
|
@GetMapping("create")
|
|
@@ -197,6 +225,11 @@ public class PersonInfoController {
|
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
public MessageResult<Map> pageList(
|
|
public MessageResult<Map> pageList(
|
|
|
String id,
|
|
String id,
|
|
|
|
|
+ @RequestParam(value="companyName",defaultValue="") String companyName,
|
|
|
|
|
+ @RequestParam(value="registerType",defaultValue="") String registerType,
|
|
|
|
|
+ @RequestParam(value="personName",defaultValue="") String personName,
|
|
|
|
|
+ @RequestParam(value="idCard",defaultValue="") String idCard,
|
|
|
|
|
+ @RequestParam(value="openId",defaultValue="") String openId,
|
|
|
@RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
@RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
@RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
@RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
@RequestAttribute String subject){
|
|
@RequestAttribute String subject){
|
|
@@ -209,17 +242,147 @@ public class PersonInfoController {
|
|
|
Map<String,Object> searchParams = new HashMap<>();
|
|
Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("id_","asc"));
|
|
|
|
|
|
|
+ sortList.add(new Sort("a.company_id","asc"));
|
|
|
|
|
+ sortList.add(new Sort("a.create_time","asc "));
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(id)) {
|
|
if (StringUtils.isNotEmpty(id)) {
|
|
|
searchParams.put("id","%" + id + "%");
|
|
searchParams.put("id","%" + id + "%");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(companyName)) {
|
|
|
|
|
+ searchParams.put("companyName","%" + companyName + "%");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotEmpty(registerType)) {
|
|
|
|
|
+ searchParams.put("registerType",registerType);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotEmpty(personName)) {
|
|
|
|
|
+ searchParams.put("personName","%" + personName + "%");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotEmpty(idCard)) {
|
|
|
|
|
+ searchParams.put("idCard","%" + idCard + "%");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotEmpty(openId)) {
|
|
|
|
|
+ searchParams.put("openId",openId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
|
+ for(PersonInfo pi : page.getResult()){
|
|
|
|
|
+ pi.setRegisterTypeName(dataDictionaryService.findNameByCatalogNameAndValue("注册用户类型",pi.getRegisterType()));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
msgResult.setResult(true);
|
|
msgResult.setResult(true);
|
|
|
msgResult.setData(PojoUtils.pageWrapper(page));
|
|
msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
|
|
|
|
return msgResult;
|
|
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){
|
|
|
|
|
+ User user = userService.get(subject);
|
|
|
|
|
+
|
|
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
|
|
+ int sheetIndex = 0;
|
|
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
|
|
+
|
|
|
|
|
+ int affectCount = 0;
|
|
|
|
|
+ int failCount = 0;
|
|
|
|
|
+ int validateColIndex = 10;
|
|
|
|
|
+
|
|
|
|
|
+ for(int rowIndex=1 ; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
|
|
+ try {
|
|
|
|
|
+ String sort = (String)poiUtils.getCellValue(sheetIndex,rowIndex,0).toString().replace(" ","");
|
|
|
|
|
+ String companyName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,1).toString().replace(" ","");
|
|
|
|
|
+ String registerType = (String)poiUtils.getCellValue(sheetIndex,rowIndex,2).toString().replace(" ","");
|
|
|
|
|
+ String userName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,3).toString().replace(" ","");
|
|
|
|
|
+ String personName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,4).toString().replace(" ","");
|
|
|
|
|
+ String idCard = (String)poiUtils.getCellValue(sheetIndex,rowIndex,5).toString().replace(" ","");
|
|
|
|
|
+ String phone = (String)poiUtils.getCellValue(sheetIndex,rowIndex,6).toString().replace(" ","");
|
|
|
|
|
+ String remark = (String)poiUtils.getCellValue(sheetIndex,rowIndex,7).toString().replace(" ","");
|
|
|
|
|
+
|
|
|
|
|
+ if(StringUtils.isEmpty(personName)){
|
|
|
|
|
+ break;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ PersonInfo pi = personInfoService.findByUserName(userName);
|
|
|
|
|
+ if(pi != null){
|
|
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("该用户已存在!");
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ CompanyInfo companyInfo = companyInfoService.findByName(companyName);
|
|
|
|
|
+
|
|
|
|
|
+ if (companyInfo == null) {
|
|
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("该企业不存在!");
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ PersonInfo personInfo = new PersonInfo();
|
|
|
|
|
+ personInfo.setId(UUID.randomUUID().toString());
|
|
|
|
|
+ personInfo.setCompanyId(companyInfo.getId());
|
|
|
|
|
+
|
|
|
|
|
+ personInfo.setRegisterType(dataDictionaryService.findValueByCatalogNameAndName("注册用户类型",registerType));
|
|
|
|
|
+
|
|
|
|
|
+ personInfo.setUserName(userName);
|
|
|
|
|
+ personInfo.setPersonName(personName);
|
|
|
|
|
+ personInfo.setPassword(AESUtil.encrypt("123456",AESUtil.MYSQL_ENC_KEY));
|
|
|
|
|
+ personInfo.setIdCard(idCard);
|
|
|
|
|
+ personInfo.setPhone(phone);
|
|
|
|
|
+ personInfo.setRemark(remark);
|
|
|
|
|
+
|
|
|
|
|
+ personInfo.setDelFlag(false);
|
|
|
|
|
+ personInfo.setCreateBy(subject);
|
|
|
|
|
+ personInfo.setCreateTime(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|