PersonInfoController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. package com.jpsoft.smart.modules.base.controller;
  2. import com.github.pagehelper.Page;
  3. import com.jpsoft.smart.modules.common.utils.PojoUtils;
  4. import com.jpsoft.smart.modules.common.dto.Sort;
  5. import com.jpsoft.smart.modules.common.dto.MessageResult;
  6. import com.jpsoft.smart.modules.base.entity.PersonInfo;
  7. import com.jpsoft.smart.modules.base.service.PersonInfoService;
  8. import com.jpsoft.smart.modules.sys.entity.User;
  9. import com.jpsoft.smart.modules.sys.service.UserService;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiImplicitParam;
  12. import io.swagger.annotations.ApiImplicitParams;
  13. import io.swagger.annotations.ApiOperation;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.servlet.http.HttpServletRequest;
  21. import java.io.ByteArrayInputStream;
  22. import java.io.ByteArrayOutputStream;
  23. import java.text.SimpleDateFormat;
  24. import java.util.*;
  25. @RestController
  26. @RequestMapping("/base/personInfo")
  27. @Api(description = "personInfo")
  28. public class PersonInfoController {
  29. private Logger logger = LoggerFactory.getLogger(getClass());
  30. @Autowired
  31. private PersonInfoService personInfoService;
  32. @Autowired
  33. private UserService userService;
  34. @ApiOperation(value="保存信息")
  35. @PostMapping("save")
  36. public MessageResult<PersonInfo> save(@RequestBody PersonInfo personInfo,@RequestAttribute String subject){
  37. User user = userService.get(subject);
  38. MessageResult<PersonInfo> msgResult = new MessageResult<>();
  39. try {
  40. int affectCount = 0;
  41. if(personInfo.getId() != null) {
  42. personInfo.setCompanyId(user.getCompanyId());
  43. personInfo.setDelFlag(false);
  44. personInfo.setCreateBy(subject);
  45. personInfo.setCreateTime(new Date());
  46. affectCount = personInfoService.insert(personInfo);
  47. }else{
  48. personInfo.setUpdateBy(subject);
  49. personInfo.setUpdateTime(new Date());
  50. affectCount = personInfoService.update(personInfo);
  51. }
  52. if (affectCount > 0) {
  53. msgResult.setResult(true);
  54. msgResult.setData(personInfo);
  55. }else{
  56. msgResult.setResult(false);
  57. msgResult.setMessage("数据库保存失败");
  58. }
  59. }
  60. catch(Exception ex){
  61. logger.error(ex.getMessage(),ex);
  62. msgResult.setResult(false);
  63. msgResult.setMessage(ex.getMessage());
  64. }
  65. return msgResult;
  66. }
  67. @ApiOperation(value="获取详情信息")
  68. @GetMapping("detail/{id}")
  69. public MessageResult<PersonInfo> detail(@PathVariable("id") String id){
  70. MessageResult<PersonInfo> msgResult = new MessageResult<>();
  71. try {
  72. PersonInfo personInfo = personInfoService.get(id);
  73. if (personInfo != null) {
  74. msgResult.setResult(true);
  75. msgResult.setData(personInfo);
  76. } else {
  77. msgResult.setResult(false);
  78. msgResult.setMessage("数据库不存在该记录!");
  79. }
  80. }
  81. catch(Exception ex){
  82. logger.error(ex.getMessage(),ex);
  83. msgResult.setResult(false);
  84. msgResult.setMessage(ex.getMessage());
  85. }
  86. return msgResult;
  87. }
  88. @ApiOperation(value="删除")
  89. @PostMapping("delete/{id}")
  90. public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
  91. MessageResult<Integer> msgResult = new MessageResult<>();
  92. try {
  93. PersonInfo personInfo = personInfoService.get(id);
  94. personInfo.setDelFlag(true);
  95. personInfo.setUpdateBy(subject);
  96. personInfo.setUpdateTime(new Date());
  97. int affectCount = personInfoService.update(personInfo);
  98. if (affectCount > 0) {
  99. msgResult.setResult(true);
  100. msgResult.setData(affectCount);
  101. } else {
  102. msgResult.setResult(false);
  103. msgResult.setMessage("删除失败");
  104. }
  105. }
  106. catch(Exception ex){
  107. logger.error(ex.getMessage(),ex);
  108. msgResult.setResult(false);
  109. msgResult.setMessage(ex.getMessage());
  110. }
  111. return msgResult;
  112. }
  113. @ApiOperation(value="批量删除")
  114. @PostMapping("batchDelete")
  115. public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
  116. MessageResult<Integer> msgResult = new MessageResult<>();
  117. try {
  118. int affectCount = 0;
  119. for (String id : idList) {
  120. PersonInfo personInfo = personInfoService.get(id);
  121. personInfo.setDelFlag(true);
  122. personInfo.setUpdateBy(subject);
  123. personInfo.setUpdateTime(new Date());
  124. affectCount += personInfoService.update(personInfo);
  125. }
  126. if (affectCount > 0) {
  127. msgResult.setResult(true);
  128. msgResult.setData(affectCount);
  129. } else {
  130. msgResult.setResult(false);
  131. msgResult.setMessage("删除失败");
  132. }
  133. }
  134. catch(Exception ex){
  135. logger.error(ex.getMessage(),ex);
  136. msgResult.setResult(false);
  137. msgResult.setMessage(ex.getMessage());
  138. }
  139. return msgResult;
  140. }
  141. @ApiOperation(value="列表")
  142. @RequestMapping(value = "pageList",method = RequestMethod.POST)
  143. @ApiImplicitParams({
  144. @ApiImplicitParam(name = "name",value = "姓名", required = false, paramType = "form",dataType = "String"),
  145. @ApiImplicitParam(name = "position1",value = "一级位置", required = false, paramType = "form",dataType = "String"),
  146. @ApiImplicitParam(name = "position2",value = "二级位置", required = false, paramType = "form",dataType = "String"),
  147. @ApiImplicitParam(name = "position3",value = "三级位置", required = false, paramType = "form",dataType = "String"),
  148. @ApiImplicitParam(name = "position4",value = "四级位置", required = false, paramType = "form",dataType = "String"),
  149. @ApiImplicitParam(name = "position5",value = "五级位置", required = false, paramType = "form",dataType = "String")
  150. })
  151. public MessageResult<Map> pageList(
  152. @RequestParam(value="name",defaultValue="") String name,
  153. @RequestParam(value="position1",defaultValue="") String position1,
  154. @RequestParam(value="position2",defaultValue="") String position2,
  155. @RequestParam(value="position3",defaultValue="") String position3,
  156. @RequestParam(value="position4",defaultValue="") String position4,
  157. @RequestParam(value="position5",defaultValue="") String position5,
  158. @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
  159. @RequestParam(value="pageSize",defaultValue="20") int pageSize,
  160. @RequestAttribute String subject){
  161. //当前用户ID
  162. System.out.println(subject);
  163. MessageResult<Map> msgResult = new MessageResult<>();
  164. Map<String,Object> searchParams = new HashMap<>();
  165. List<Sort> sortList = new ArrayList<>();
  166. sortList.add(new Sort("id_","asc"));
  167. if (StringUtils.isNotEmpty(name)) {
  168. searchParams.put("name","%" + name + "%");
  169. }
  170. if (StringUtils.isNotEmpty(position1)) {
  171. searchParams.put("position1",position1);
  172. }
  173. if (StringUtils.isNotEmpty(position2)) {
  174. searchParams.put("position2",position2);
  175. }
  176. if (StringUtils.isNotEmpty(position3)) {
  177. searchParams.put("position3",position3);
  178. }
  179. if (StringUtils.isNotEmpty(position4)) {
  180. searchParams.put("position4",position4);
  181. }
  182. if (StringUtils.isNotEmpty(position5)) {
  183. searchParams.put("position5",position5);
  184. }
  185. Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
  186. msgResult.setResult(true);
  187. msgResult.setData(PojoUtils.pageWrapper(page));
  188. return msgResult;
  189. }
  190. @ApiOperation(value="人脸授权")
  191. @PostMapping("EnabledFace")
  192. @ApiImplicitParams({
  193. @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
  194. })
  195. public MessageResult<PersonInfo> EnabledFace(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
  196. MessageResult<PersonInfo> msgResult = new MessageResult<>();
  197. try {
  198. PersonInfo personInfo = personInfoService.get(id);
  199. if(personInfo.getFaceEnabled()){
  200. personInfo.setFaceEnabled(false);
  201. }else{
  202. personInfo.setFaceEnabled(true);
  203. }
  204. personInfo.setUpdateBy(subject);
  205. personInfo.setUpdateTime(new Date());
  206. int affectCount = personInfoService.update(personInfo);
  207. if (affectCount > 0) {
  208. msgResult.setResult(true);
  209. msgResult.setData(personInfo);
  210. }else{
  211. msgResult.setResult(false);
  212. msgResult.setMessage("数据库保存失败");
  213. }
  214. }
  215. catch(Exception ex){
  216. logger.error(ex.getMessage(),ex);
  217. msgResult.setResult(false);
  218. msgResult.setMessage(ex.getMessage());
  219. }
  220. return msgResult;
  221. }
  222. @ApiOperation(value="刷卡授权")
  223. @PostMapping("EnabledCard")
  224. @ApiImplicitParams({
  225. @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
  226. })
  227. public MessageResult<PersonInfo> EnabledCard(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
  228. MessageResult<PersonInfo> msgResult = new MessageResult<>();
  229. try {
  230. PersonInfo personInfo = personInfoService.get(id);
  231. if(personInfo.getCardEnabled()){
  232. personInfo.setCardEnabled(false);
  233. }else{
  234. personInfo.setCardEnabled(true);
  235. }
  236. personInfo.setUpdateBy(subject);
  237. personInfo.setUpdateTime(new Date());
  238. int affectCount = personInfoService.update(personInfo);
  239. if (affectCount > 0) {
  240. msgResult.setResult(true);
  241. msgResult.setData(personInfo);
  242. }else{
  243. msgResult.setResult(false);
  244. msgResult.setMessage("数据库保存失败");
  245. }
  246. }
  247. catch(Exception ex){
  248. logger.error(ex.getMessage(),ex);
  249. msgResult.setResult(false);
  250. msgResult.setMessage(ex.getMessage());
  251. }
  252. return msgResult;
  253. }
  254. @ApiOperation(value="手机授权")
  255. @PostMapping("EnabledApp")
  256. @ApiImplicitParams({
  257. @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
  258. })
  259. public MessageResult<PersonInfo> EnabledApp(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
  260. MessageResult<PersonInfo> msgResult = new MessageResult<>();
  261. try {
  262. PersonInfo personInfo = personInfoService.get(id);
  263. if(personInfo.getAppEnabled()){
  264. personInfo.setAppEnabled(false);
  265. }else{
  266. personInfo.setAppEnabled(true);
  267. }
  268. personInfo.setUpdateBy(subject);
  269. personInfo.setUpdateTime(new Date());
  270. int affectCount = personInfoService.update(personInfo);
  271. if (affectCount > 0) {
  272. msgResult.setResult(true);
  273. msgResult.setData(personInfo);
  274. }else{
  275. msgResult.setResult(false);
  276. msgResult.setMessage("数据库保存失败");
  277. }
  278. }
  279. catch(Exception ex){
  280. logger.error(ex.getMessage(),ex);
  281. msgResult.setResult(false);
  282. msgResult.setMessage(ex.getMessage());
  283. }
  284. return msgResult;
  285. }
  286. @ApiOperation(value="访客授权")
  287. @PostMapping("EnabledGuest")
  288. @ApiImplicitParams({
  289. @ApiImplicitParam(name = "id",value = "人员编号", required = false, paramType = "form",dataType = "String")
  290. })
  291. public MessageResult<PersonInfo> EnabledGuest(@RequestParam(value="id",defaultValue="") String id,@RequestAttribute String subject){
  292. MessageResult<PersonInfo> msgResult = new MessageResult<>();
  293. try {
  294. PersonInfo personInfo = personInfoService.get(id);
  295. if(personInfo.getGuestEnabled()){
  296. personInfo.setGuestEnabled(false);
  297. }else{
  298. personInfo.setGuestEnabled(true);
  299. }
  300. personInfo.setUpdateBy(subject);
  301. personInfo.setUpdateTime(new Date());
  302. int affectCount = personInfoService.update(personInfo);
  303. if (affectCount > 0) {
  304. msgResult.setResult(true);
  305. msgResult.setData(personInfo);
  306. }else{
  307. msgResult.setResult(false);
  308. msgResult.setMessage("数据库保存失败");
  309. }
  310. }
  311. catch(Exception ex){
  312. logger.error(ex.getMessage(),ex);
  313. msgResult.setResult(false);
  314. msgResult.setMessage(ex.getMessage());
  315. }
  316. return msgResult;
  317. }
  318. // @ApiOperation(value="导入企业人员")
  319. // @PostMapping("importXls")
  320. // @ApiImplicitParams({
  321. // @ApiImplicitParam(name = "companyId",value = "企业ID", required = true, paramType = "form",dataType = "String"),
  322. // @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
  323. // })
  324. // public MessageResult<String> importXls(@RequestParam(value="companyId",defaultValue="") String companyId,
  325. // MultipartFile uploadFile,
  326. // @RequestAttribute String subject){
  327. // User user = userService.get(subject);
  328. //
  329. // MessageResult<String> msgResult = new MessageResult<>();
  330. // PersonInfo personInfo = new PersonInfo();
  331. //
  332. // try {
  333. // POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
  334. // int sheetIndex = 0;
  335. // Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
  336. //
  337. // int affectCount = 0;
  338. // int failCount = 0;
  339. // int validateColIndex = 7;
  340. //
  341. // for(int rowIndex=1 ; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
  342. // try {
  343. // String name = (String)poiUtils.getCellValue(sheetIndex,rowIndex,1);
  344. // String cardType = (String)poiUtils.getCellValue(sheetIndex,rowIndex,2);
  345. // String cardNo = (String)poiUtils.getCellValue(sheetIndex,rowIndex,3);
  346. // String sex = (String)poiUtils.getCellValue(sheetIndex,rowIndex,4);
  347. //// String age = array[5].toString();
  348. // String jobName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,5);
  349. // String healthStatus = (String)poiUtils.getCellValue(sheetIndex,rowIndex,6);
  350. //
  351. // if(StringUtils.isEmpty(name)){
  352. // break;
  353. // }
  354. //
  355. // Map<String, Object> searchParams = new HashMap<>();
  356. // searchParams.put("companyId", company.getId());
  357. // searchParams.put("cardNo", cardNo);
  358. // searchParams.put("delFlag", false);
  359. //
  360. // List<Sort> sortList = new ArrayList<>();
  361. // Page<CompanyMember> page = companyMemberService.pageSearch(searchParams, 1, 100, sortList);
  362. //
  363. // if (page.size() > 0) {
  364. // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证已导入!");
  365. // failCount++;
  366. // continue;
  367. // } else {
  368. // companyMember.setId(UUID.randomUUID().toString());
  369. // if (StringUtils.isNotEmpty(company.getId())) companyMember.setCompanyId(company.getId());
  370. // if (StringUtils.isNotEmpty(name)) companyMember.setName(name);
  371. //
  372. // CheckIdCard cic = null;
  373. //
  374. // if(StringUtils.isEmpty(cardNo)){
  375. // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证不能为空!");
  376. // failCount++;
  377. // continue;
  378. // }
  379. // else{
  380. // cardNo = cardNo.trim().toUpperCase();
  381. // }
  382. //
  383. // for(DataDictionary dd : ddList){
  384. // if(dd.getName().equals(cardType)) {
  385. // companyMember.setCardType(dd.getValue());
  386. // break;
  387. // }
  388. // }
  389. //
  390. // if (StringUtils.isEmpty(companyMember.getCardType())){
  391. // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("证件类型未选择!");
  392. // failCount++;
  393. // continue;
  394. // }
  395. //
  396. // if (cardType.contains("身份证")) {
  397. // cic = new CheckIdCard(cardNo);
  398. //
  399. // if (!cic.validate()){
  400. // sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证验证失败!");
  401. // failCount++;
  402. //
  403. // continue;
  404. // }
  405. // }
  406. //
  407. // companyMember.setCardNo(cardNo);
  408. //
  409. // List<Jobs> jobsList = jobsService.findByName(jobsName);
  410. //
  411. // if (jobsList.size() > 0) {
  412. // companyMember.setJobsId(jobsList.get(0).getId());
  413. // }
  414. //
  415. // if (StringUtils.isNotEmpty(healthStatus)) companyMember.setHealthStatus(healthStatus);
  416. //
  417. // companyMember.setStatus("0");
  418. // companyMember.setDelFlag(false);
  419. // companyMember.setCreateBy(principal.getName());
  420. // companyMember.setCreateTime(new Date());
  421. //
  422. // if (companyMemberService.insert(companyMember) > 0) {
  423. // affectCount++;
  424. // }
  425. // }
  426. // }
  427. // catch(Exception innerEx){
  428. // logger.error(innerEx.getMessage(),innerEx);
  429. // }
  430. // }
  431. //
  432. // if (failCount>0){
  433. // //有导入失败的记录
  434. // msgResult.setResult(false);
  435. // msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
  436. //
  437. // //todo 只保留错误数据的sheet
  438. // int rowIndex = 1;
  439. //
  440. // while(rowIndex<= sheet1.getLastRowNum()){
  441. // Cell cell = sheet1.getRow(rowIndex).getCell(validateColIndex);
  442. //
  443. // if (cell==null || StringUtils.isEmpty(cell.getStringCellValue())){
  444. // sheet1.removeRow(sheet1.getRow(rowIndex));
  445. //
  446. // if (rowIndex<sheet1.getLastRowNum()) {
  447. // sheet1.shiftRows(rowIndex + 1, sheet1.getLastRowNum(), -1); //删除后下面行上移,则不需要移动rowIndex
  448. // }
  449. // }
  450. // else {
  451. // rowIndex++;
  452. // }
  453. // }
  454. //
  455. // //todo 将wb保存到oss
  456. // ByteArrayOutputStream output = new ByteArrayOutputStream();
  457. // poiUtils.getWorkbook().write(output);
  458. //
  459. // byte[] buffer = output.toByteArray();
  460. // ByteArrayInputStream input = new ByteArrayInputStream(buffer);
  461. //
  462. // String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
  463. //
  464. // //todo 返回导入失败报表下载链接
  465. // msgResult.setData(downloadUrl);
  466. // }
  467. // else{
  468. // msgResult.setResult(true);
  469. // msgResult.setMessage("数据成功导入" + affectCount + "条");
  470. // }
  471. // }
  472. // catch(Exception ex){
  473. // logger.error(ex.getMessage(),ex);
  474. //
  475. // msgResult.setResult(false);
  476. // msgResult.setMessage(ex.getMessage());
  477. // }
  478. //
  479. // return msgResult;
  480. // }
  481. }