123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- package com.jpsoft.smart.modules.base.controller;
- import com.github.pagehelper.Page;
- import com.jpsoft.smart.modules.common.utils.PojoUtils;
- import com.jpsoft.smart.modules.common.dto.Sort;
- import com.jpsoft.smart.modules.common.dto.MessageResult;
- import com.jpsoft.smart.modules.base.entity.PersonInfo;
- import com.jpsoft.smart.modules.base.service.PersonInfoService;
- import com.jpsoft.smart.modules.sys.entity.User;
- import com.jpsoft.smart.modules.sys.service.UserService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- 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.*;
- @RestController
- @RequestMapping("/base/personInfo")
- @Api(description = "personInfo")
- public class PersonInfoController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- private PersonInfoService personInfoService;
- @Autowired
- private UserService userService;
- @ApiOperation(value="保存信息")
- @PostMapping("save")
- public MessageResult<PersonInfo> save(@RequestBody PersonInfo personInfo,@RequestAttribute String subject){
- User user = userService.get(subject);
- MessageResult<PersonInfo> msgResult = new MessageResult<>();
- try {
- int affectCount = 0;
- if(personInfo.getId() != null) {
- personInfo.setCompanyId(user.getCompanyId());
- personInfo.setDelFlag(false);
- personInfo.setCreateBy(subject);
- personInfo.setCreateTime(new Date());
- affectCount = personInfoService.insert(personInfo);
- }else{
- personInfo.setUpdateBy(subject);
- personInfo.setUpdateTime(new Date());
- affectCount = personInfoService.update(personInfo);
- }
- if (affectCount > 0) {
- msgResult.setResult(true);
- msgResult.setData(personInfo);
- }else{
- msgResult.setResult(false);
- msgResult.setMessage("数据库保存失败");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- @ApiOperation(value="获取详情信息")
- @GetMapping("detail/{id}")
- public MessageResult<PersonInfo> detail(@PathVariable("id") String id){
- MessageResult<PersonInfo> msgResult = new MessageResult<>();
- try {
- PersonInfo personInfo = personInfoService.get(id);
- if (personInfo != null) {
- msgResult.setResult(true);
- msgResult.setData(personInfo);
- } else {
- msgResult.setResult(false);
- msgResult.setMessage("数据库不存在该记录!");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- @ApiOperation(value="删除")
- @PostMapping("delete/{id}")
- public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
- MessageResult<Integer> msgResult = new MessageResult<>();
- try {
- PersonInfo personInfo = personInfoService.get(id);
- personInfo.setDelFlag(true);
- personInfo.setUpdateBy(subject);
- personInfo.setUpdateTime(new Date());
- int affectCount = personInfoService.update(personInfo);
- if (affectCount > 0) {
- msgResult.setResult(true);
- msgResult.setData(affectCount);
- } else {
- msgResult.setResult(false);
- msgResult.setMessage("删除失败");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- @ApiOperation(value="批量删除")
- @PostMapping("batchDelete")
- public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
- MessageResult<Integer> msgResult = new MessageResult<>();
- try {
- int affectCount = 0;
- for (String id : idList) {
- PersonInfo personInfo = personInfoService.get(id);
- personInfo.setDelFlag(true);
- personInfo.setUpdateBy(subject);
- personInfo.setUpdateTime(new Date());
- affectCount += personInfoService.update(personInfo);
- }
- if (affectCount > 0) {
- msgResult.setResult(true);
- msgResult.setData(affectCount);
- } else {
- msgResult.setResult(false);
- msgResult.setMessage("删除失败");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- @ApiOperation(value="列表")
- @RequestMapping(value = "pageList",method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "name",value = "姓名", required = false, paramType = "form",dataType = "String"),
- @ApiImplicitParam(name = "position1",value = "一级位置", required = false, paramType = "form",dataType = "String"),
- @ApiImplicitParam(name = "position2",value = "二级位置", required = false, paramType = "form",dataType = "String"),
- @ApiImplicitParam(name = "position3",value = "三级位置", required = false, paramType = "form",dataType = "String"),
- @ApiImplicitParam(name = "position4",value = "四级位置", required = false, paramType = "form",dataType = "String"),
- @ApiImplicitParam(name = "position5",value = "五级位置", required = false, paramType = "form",dataType = "String")
- })
- public MessageResult<Map> pageList(
- @RequestParam(value="name",defaultValue="") String name,
- @RequestParam(value="position1",defaultValue="") String position1,
- @RequestParam(value="position2",defaultValue="") String position2,
- @RequestParam(value="position3",defaultValue="") String position3,
- @RequestParam(value="position4",defaultValue="") String position4,
- @RequestParam(value="position5",defaultValue="") String position5,
- @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
- @RequestParam(value="pageSize",defaultValue="20") int pageSize,
- @RequestAttribute String subject){
- //当前用户ID
- System.out.println(subject);
- MessageResult<Map> msgResult = new MessageResult<>();
- Map<String,Object> searchParams = new HashMap<>();
- List<Sort> sortList = new ArrayList<>();
- sortList.add(new Sort("id_","asc"));
- if (StringUtils.isNotEmpty(name)) {
- searchParams.put("name","%" + name + "%");
- }
- if (StringUtils.isNotEmpty(position1)) {
- searchParams.put("position1",position1);
- }
- if (StringUtils.isNotEmpty(position2)) {
- searchParams.put("position2",position2);
- }
- if (StringUtils.isNotEmpty(position3)) {
- searchParams.put("position3",position3);
- }
- if (StringUtils.isNotEmpty(position4)) {
- searchParams.put("position4",position4);
- }
- if (StringUtils.isNotEmpty(position5)) {
- searchParams.put("position5",position5);
- }
- Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
- msgResult.setResult(true);
- msgResult.setData(PojoUtils.pageWrapper(page));
- return msgResult;
- }
- @ApiOperation(value="人脸授权")
- @PostMapping("EnabledFace")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
- })
- public MessageResult<PersonInfo> EnabledFace(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
- MessageResult<PersonInfo> msgResult = new MessageResult<>();
- try {
- PersonInfo personInfo = personInfoService.get(id);
- if(personInfo.getFaceEnabled()){
- personInfo.setFaceEnabled(false);
- }else{
- personInfo.setFaceEnabled(true);
- }
- personInfo.setUpdateBy(subject);
- personInfo.setUpdateTime(new Date());
- int affectCount = personInfoService.update(personInfo);
- if (affectCount > 0) {
- msgResult.setResult(true);
- msgResult.setData(personInfo);
- }else{
- msgResult.setResult(false);
- msgResult.setMessage("数据库保存失败");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- @ApiOperation(value="刷卡授权")
- @PostMapping("EnabledCard")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
- })
- public MessageResult<PersonInfo> EnabledCard(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
- MessageResult<PersonInfo> msgResult = new MessageResult<>();
- try {
- PersonInfo personInfo = personInfoService.get(id);
- if(personInfo.getCardEnabled()){
- personInfo.setCardEnabled(false);
- }else{
- personInfo.setCardEnabled(true);
- }
- personInfo.setUpdateBy(subject);
- personInfo.setUpdateTime(new Date());
- int affectCount = personInfoService.update(personInfo);
- if (affectCount > 0) {
- msgResult.setResult(true);
- msgResult.setData(personInfo);
- }else{
- msgResult.setResult(false);
- msgResult.setMessage("数据库保存失败");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- @ApiOperation(value="手机授权")
- @PostMapping("EnabledApp")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
- })
- public MessageResult<PersonInfo> EnabledApp(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
- MessageResult<PersonInfo> msgResult = new MessageResult<>();
- try {
- PersonInfo personInfo = personInfoService.get(id);
- if(personInfo.getAppEnabled()){
- personInfo.setAppEnabled(false);
- }else{
- personInfo.setAppEnabled(true);
- }
- personInfo.setUpdateBy(subject);
- personInfo.setUpdateTime(new Date());
- int affectCount = personInfoService.update(personInfo);
- if (affectCount > 0) {
- msgResult.setResult(true);
- msgResult.setData(personInfo);
- }else{
- msgResult.setResult(false);
- msgResult.setMessage("数据库保存失败");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- @ApiOperation(value="访客授权")
- @PostMapping("EnabledGuest")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
- })
- public MessageResult<PersonInfo> EnabledGuest(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
- MessageResult<PersonInfo> msgResult = new MessageResult<>();
- try {
- PersonInfo personInfo = personInfoService.get(id);
- if(personInfo.getGuestEnabled()){
- personInfo.setGuestEnabled(false);
- }else{
- personInfo.setGuestEnabled(true);
- }
- personInfo.setUpdateBy(subject);
- personInfo.setUpdateTime(new Date());
- int affectCount = personInfoService.update(personInfo);
- if (affectCount > 0) {
- msgResult.setResult(true);
- msgResult.setData(personInfo);
- }else{
- msgResult.setResult(false);
- msgResult.setMessage("数据库保存失败");
- }
- }
- catch(Exception ex){
- logger.error(ex.getMessage(),ex);
- msgResult.setResult(false);
- msgResult.setMessage(ex.getMessage());
- }
- return msgResult;
- }
- // @ApiOperation(value="导入企业人员")
- // @PostMapping("importXls")
- // @ApiImplicitParams({
- // @ApiImplicitParam(name = "companyId",value = "企业ID", required = true, paramType = "form",dataType = "String"),
- // @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
- // })
- // public MessageResult<String> importXls(@RequestParam(value="companyId",defaultValue="") String companyId,
- // MultipartFile uploadFile,
- // @RequestAttribute String subject){
- // User user = userService.get(subject);
- //
- // MessageResult<String> msgResult = new MessageResult<>();
- // PersonInfo personInfo = new PersonInfo();
- //
- // try {
- // POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
- // int sheetIndex = 0;
- // Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
- //
- // int affectCount = 0;
- // int failCount = 0;
- // int validateColIndex = 7;
- //
- // for(int rowIndex=1 ; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
- // try {
- // String name = (String)poiUtils.getCellValue(sheetIndex,rowIndex,1);
- // String cardType = (String)poiUtils.getCellValue(sheetIndex,rowIndex,2);
- // String cardNo = (String)poiUtils.getCellValue(sheetIndex,rowIndex,3);
- // String sex = (String)poiUtils.getCellValue(sheetIndex,rowIndex,4);
- //// String age = array[5].toString();
- // String jobName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,5);
- // String healthStatus = (String)poiUtils.getCellValue(sheetIndex,rowIndex,6);
- //
- // if(StringUtils.isEmpty(name)){
- // break;
- // }
- //
- // Map<String, Object> searchParams = new HashMap<>();
- // searchParams.put("companyId", company.getId());
- // searchParams.put("cardNo", cardNo);
- // searchParams.put("delFlag", false);
- //
- // List<Sort> sortList = new ArrayList<>();
- // Page<CompanyMember> page = companyMemberService.pageSearch(searchParams, 1, 100, sortList);
- //
- // if (page.size() > 0) {
- // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证已导入!");
- // failCount++;
- // continue;
- // } else {
- // companyMember.setId(UUID.randomUUID().toString());
- // if (StringUtils.isNotEmpty(company.getId())) companyMember.setCompanyId(company.getId());
- // if (StringUtils.isNotEmpty(name)) companyMember.setName(name);
- //
- // CheckIdCard cic = null;
- //
- // if(StringUtils.isEmpty(cardNo)){
- // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证不能为空!");
- // failCount++;
- // continue;
- // }
- // else{
- // cardNo = cardNo.trim().toUpperCase();
- // }
- //
- // for(DataDictionary dd : ddList){
- // if(dd.getName().equals(cardType)) {
- // companyMember.setCardType(dd.getValue());
- // break;
- // }
- // }
- //
- // if (StringUtils.isEmpty(companyMember.getCardType())){
- // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("证件类型未选择!");
- // failCount++;
- // continue;
- // }
- //
- // if (cardType.contains("身份证")) {
- // cic = new CheckIdCard(cardNo);
- //
- // if (!cic.validate()){
- // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证验证失败!");
- // failCount++;
- //
- // continue;
- // }
- // }
- //
- // companyMember.setCardNo(cardNo);
- //
- // List<Jobs> jobsList = jobsService.findByName(jobsName);
- //
- // if (jobsList.size() > 0) {
- // companyMember.setJobsId(jobsList.get(0).getId());
- // }
- //
- // if (StringUtils.isNotEmpty(healthStatus)) companyMember.setHealthStatus(healthStatus);
- //
- // companyMember.setStatus("0");
- // companyMember.setDelFlag(false);
- // companyMember.setCreateBy(principal.getName());
- // companyMember.setCreateTime(new Date());
- //
- // if (companyMemberService.insert(companyMember) > 0) {
- // affectCount++;
- // }
- // }
- // }
- // catch(Exception innerEx){
- // logger.error(innerEx.getMessage(),innerEx);
- // }
- // }
- //
- // if (failCount>0){
- // //有导入失败的记录
- // msgResult.setResult(false);
- // msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
- //
- // //todo 只保留错误数据的sheet
- // int rowIndex = 1;
- //
- // while(rowIndex<= sheet1.getLastRowNum()){
- // Cell cell = sheet1.getRow(rowIndex).getCell(validateColIndex);
- //
- // if (cell==null || StringUtils.isEmpty(cell.getStringCellValue())){
- // sheet1.removeRow(sheet1.getRow(rowIndex));
- //
- // if (rowIndex<sheet1.getLastRowNum()) {
- // sheet1.shiftRows(rowIndex + 1, sheet1.getLastRowNum(), -1); //删除后下面行上移,则不需要移动rowIndex
- // }
- // }
- // else {
- // rowIndex++;
- // }
- // }
- //
- // //todo 将wb保存到oss
- // ByteArrayOutputStream output = new ByteArrayOutputStream();
- // poiUtils.getWorkbook().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;
- // }
- }
|