WorkerIdentityServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.chuanghai.attendance.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.chuanghai.attendance.common.exception.BizCodeEnume;
  5. import com.chuanghai.attendance.common.exception.RRException;
  6. import com.chuanghai.attendance.common.utils.CommonResult;
  7. import com.chuanghai.attendance.dao.WorkerIdentityDao;
  8. import com.chuanghai.attendance.entity.WorkerIdentity;
  9. import com.chuanghai.attendance.service.WorkerIdentityService;
  10. import com.chuanghai.attendance.utils.excel.ExcelImportXLSXUtil;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.util.StringUtils;
  13. import org.springframework.web.multipart.MultipartFile;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. /**
  17. * @Author: binguo
  18. * @Date: 2022/9/20 星期二 17:16
  19. * @Description: com.chuanghai.attendance.service.impl
  20. * @Version: 1.0
  21. */
  22. @Service("workerIdentityService")
  23. public class WorkerIdentityServiceImpl extends ServiceImpl<WorkerIdentityDao, WorkerIdentity> implements WorkerIdentityService {
  24. @Override
  25. public CommonResult importWorkExcel(MultipartFile file) throws Exception {
  26. //导入数据前先删除原先的数据
  27. deleteIdCard();
  28. List<WorkerIdentity> workerIdList = new ArrayList<>();
  29. List<String[]> list = ExcelImportXLSXUtil.readerExcel(file.getInputStream(), "员工身份", 4);
  30. if(list == null){
  31. return CommonResult.fail("-1","缺少员工身份页数据!");
  32. }
  33. Integer count = 0;
  34. for (String[] strings : list) {
  35. count++;
  36. if (count < 2) {
  37. continue;
  38. }
  39. WorkerIdentity workerIdentity = new WorkerIdentity();
  40. workerIdentity.setWorkNum(strings[0]);
  41. workerIdentity.setWorkName(strings[1]);
  42. workerIdentity.setIdCard(strings[2]);
  43. workerIdentity.setUserId(strings[3]);
  44. // WorkerIdentity queryByIdCard = queryByIdCard(strings[2],strings[1]);
  45. // if (queryByIdCard == null) {
  46. // }
  47. workerIdList.add(workerIdentity);
  48. }
  49. if (workerIdList.size() > 0 ) {
  50. boolean d = this.saveBatch(workerIdList, workerIdList.size());
  51. return d ? CommonResult.ok() : CommonResult.fail("-1","缺少员工身份页数据!");
  52. }else {
  53. return CommonResult.ok();
  54. }
  55. }
  56. public void deleteIdCard() {
  57. List<WorkerIdentity> list = this.list();
  58. List<Integer> idList = new ArrayList<>();
  59. list.forEach(workerIdentity -> {
  60. idList.add(workerIdentity.getId()) ;
  61. });
  62. this.removeByIds(idList);
  63. }
  64. @Override
  65. public String queryByuserId(String userId, String workNum, String workName) {
  66. QueryWrapper<WorkerIdentity> wrapper = new QueryWrapper<>();
  67. wrapper.eq("user_id",userId);
  68. // System.out.println(userId);
  69. WorkerIdentity one = this.getOne(wrapper);
  70. if (one == null) {
  71. if (StringUtils.hasText(workNum)) {
  72. QueryWrapper<WorkerIdentity> wrapper1 = new QueryWrapper<>();
  73. wrapper1.eq("work_num",workNum);
  74. one = this.getOne(wrapper1);
  75. }
  76. }
  77. if (one == null) {
  78. throw new RRException(BizCodeEnume.DATA_IS_NOT_EXIST, "用户 "+workName+" userId不存在");
  79. }
  80. String idCard = one.getIdCard();
  81. return idCard;
  82. }
  83. @Override
  84. public List<WorkerIdentity> queryByuserIds(List<String> userIds, List<String> workNums) {
  85. QueryWrapper<WorkerIdentity> wrapper = new QueryWrapper<>();
  86. wrapper.in("user_id", userIds).or().in("work_num", workNums);
  87. List<WorkerIdentity> list = this.list(wrapper);
  88. if (list.size() == 0) {
  89. // throw new RRException(BizCodeEnume.DATA_IS_NOT_EXIST, userId + "userId workNum不存在");
  90. }
  91. return list;
  92. }
  93. public WorkerIdentity queryByIdCard(String idCard,String workName) {
  94. QueryWrapper<WorkerIdentity> wrapper = new QueryWrapper<>();
  95. wrapper.eq("id_card", idCard);
  96. WorkerIdentity workerIdentity;
  97. try {
  98. workerIdentity = this.getOne(wrapper);
  99. }catch (Exception e){
  100. throw new RRException(BizCodeEnume.DATA_IS_EXIST, "员工 " +workName+ " 身份证信息重复");
  101. }
  102. return workerIdentity;
  103. }
  104. }