SysPersonServiceImpl.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.zhongzheng.service.impl;
  2. import cn.hutool.core.lang.Validator;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import cn.hutool.http.HttpStatus;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  9. import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.zhongzheng.common.filter.CustomException;
  13. import com.zhongzheng.common.model.TableDataInfo;
  14. import com.zhongzheng.common.util.DateUtils;
  15. import com.zhongzheng.common.util.ServletUtils;
  16. import com.zhongzheng.domian.SysCompany;
  17. import com.zhongzheng.domian.SysCustomerSea;
  18. import com.zhongzheng.domian.SysPerson;
  19. import com.zhongzheng.mapper.SysCompanyMapper;
  20. import com.zhongzheng.mapper.SysCustomerSeaMapper;
  21. import com.zhongzheng.mapper.SysPersonMapper;
  22. import com.zhongzheng.service.ISysCompanyService;
  23. import com.zhongzheng.service.ISysCustomerSeaService;
  24. import com.zhongzheng.service.ISysPersonService;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. /**
  28. * 菜单 业务层处理
  29. *
  30. * @author zhongzheng
  31. */
  32. @Service
  33. public class SysPersonServiceImpl extends ServiceImpl<SysPersonMapper, SysPerson> implements ISysPersonService {
  34. public static final String PREMISSION_STRING = "perms[\"{0}\"]";
  35. @Autowired
  36. private SysPersonMapper personMapper;
  37. @Autowired
  38. private ISysCustomerSeaService sysCustomerSeaService;
  39. @Autowired
  40. private ISysCompanyService sysCompanyService;
  41. private SysCustomerSeaMapper customerSeaMapper;
  42. private boolean checkIdCardUnique(SysPerson entity) {
  43. if(entity.getIdCard()==null){
  44. return true;
  45. }
  46. SysPerson info = getOne(new LambdaUpdateWrapper<SysPerson>().eq(SysPerson::getIdCard,entity.getIdCard())
  47. .eq(SysPerson::getStatus,1)
  48. .eq(SysPerson::getCompanyId,entity.getCompanyId()));
  49. if (Validator.isNotNull(info)) {
  50. if(Validator.isNotEmpty(entity.getPersonId())){
  51. if(entity.getPersonId().longValue() != info.getPersonId().longValue()){
  52. return true;
  53. }
  54. }else{
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. private boolean checkPhoneUnique(SysPerson entity) {
  61. if(entity.getPhone()==null){
  62. return true;
  63. }
  64. SysPerson info = getOne(new LambdaUpdateWrapper<SysPerson>().eq(SysPerson::getPhone,entity.getPhone())
  65. .eq(SysPerson::getStatus,1)
  66. .eq(SysPerson::getCompanyId,entity.getCompanyId()));
  67. if (Validator.isNotNull(info)) {
  68. if(Validator.isNotEmpty(entity.getPersonId())){
  69. if(entity.getPersonId().longValue() != info.getPersonId().longValue()){
  70. return true;
  71. }
  72. }else{
  73. return true;
  74. }
  75. }
  76. return false;
  77. }
  78. @Override
  79. public TableDataInfo<SysPerson> selectPersonList(SysPerson entity) {
  80. if (ObjectUtil.isEmpty(entity.getPageSize()) || entity.getPageSize() < 1) {
  81. entity.setPageSize(-1);
  82. entity.setPageNum(1);
  83. }
  84. TableDataInfo<SysPerson> info = new TableDataInfo<>();
  85. LambdaQueryWrapper<SysPerson> queryWrapper = new LambdaQueryWrapper<>();
  86. queryWrapper.eq(ObjectUtils.isNotNull(entity.getStatus()), SysPerson::getStatus, 1);
  87. queryWrapper.eq(ObjectUtils.isNotNull(entity.getCompanyId()), SysPerson::getCompanyId, entity.getCompanyId());
  88. queryWrapper.eq(ObjectUtils.isNotNull(entity.getPersonName()), SysPerson::getPersonName, entity.getPersonName());
  89. Page<SysPerson> page = page(new Page<>(entity.getPageNum(), entity.getPageSize()),queryWrapper );
  90. info.setRows(page.getRecords());
  91. info.setTotal(page.getTotal());
  92. info.setCode(HttpStatus.HTTP_OK);
  93. info.setMsg("查询成功");
  94. return info;
  95. }
  96. @Override
  97. public SysPerson selectPersonById(Integer id) {
  98. return personMapper.selectById(id);
  99. }
  100. @Override
  101. public long insertPerson(SysPerson entity) {
  102. if (checkIdCardUnique(entity)) {
  103. throw new CustomException("身份证重复了");
  104. }
  105. if (checkPhoneUnique(entity)) {
  106. throw new CustomException("手机号重复了");
  107. }
  108. entity.setCreateTime(DateUtils.getNowTime());
  109. personMapper.insert(entity);
  110. return entity.getPersonId();
  111. }
  112. @Override
  113. public int updatePerson(SysPerson entity) {
  114. if (checkIdCardUnique(entity)) {
  115. throw new CustomException("身份证重复了");
  116. }
  117. if (checkPhoneUnique(entity)) {
  118. throw new CustomException("手机号重复了");
  119. }
  120. return personMapper.updateById(entity);
  121. }
  122. @Override
  123. public boolean deletePersonById(long id) {
  124. SysPerson entity = new SysPerson();
  125. entity.setPersonId(id);
  126. entity.setStatus(-1);
  127. entity.setUpdateTime(DateUtils.getNowTime());
  128. return personMapper.updateById(entity) > 0;
  129. }
  130. }