| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package com.zhongzheng.service.impl;
- import cn.hutool.core.lang.Validator;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.http.HttpStatus;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
- import com.baomidou.mybatisplus.core.toolkit.StringUtils;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.zhongzheng.common.filter.CustomException;
- import com.zhongzheng.common.model.TableDataInfo;
- import com.zhongzheng.common.util.DateUtils;
- import com.zhongzheng.common.util.ServletUtils;
- import com.zhongzheng.domian.SysCompany;
- import com.zhongzheng.domian.SysCustomerSea;
- import com.zhongzheng.domian.SysPerson;
- import com.zhongzheng.mapper.SysCompanyMapper;
- import com.zhongzheng.mapper.SysCustomerSeaMapper;
- import com.zhongzheng.mapper.SysPersonMapper;
- import com.zhongzheng.service.ISysCompanyService;
- import com.zhongzheng.service.ISysCustomerSeaService;
- import com.zhongzheng.service.ISysPersonService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * 菜单 业务层处理
- *
- * @author zhongzheng
- */
- @Service
- public class SysPersonServiceImpl extends ServiceImpl<SysPersonMapper, SysPerson> implements ISysPersonService {
- public static final String PREMISSION_STRING = "perms[\"{0}\"]";
- @Autowired
- private SysPersonMapper personMapper;
- @Autowired
- private ISysCustomerSeaService sysCustomerSeaService;
- @Autowired
- private ISysCompanyService sysCompanyService;
- private SysCustomerSeaMapper customerSeaMapper;
- private boolean checkIdCardUnique(SysPerson entity) {
- if(entity.getIdCard()==null){
- return true;
- }
- SysPerson info = getOne(new LambdaUpdateWrapper<SysPerson>().eq(SysPerson::getIdCard,entity.getIdCard())
- .eq(SysPerson::getStatus,1)
- .eq(SysPerson::getCompanyId,entity.getCompanyId()));
- if (Validator.isNotNull(info)) {
- if(Validator.isNotEmpty(entity.getPersonId())){
- if(entity.getPersonId().longValue() != info.getPersonId().longValue()){
- return true;
- }
- }else{
- return true;
- }
- }
- return false;
- }
- private boolean checkPhoneUnique(SysPerson entity) {
- if(entity.getPhone()==null){
- return true;
- }
- SysPerson info = getOne(new LambdaUpdateWrapper<SysPerson>().eq(SysPerson::getPhone,entity.getPhone())
- .eq(SysPerson::getStatus,1)
- .eq(SysPerson::getCompanyId,entity.getCompanyId()));
- if (Validator.isNotNull(info)) {
- if(Validator.isNotEmpty(entity.getPersonId())){
- if(entity.getPersonId().longValue() != info.getPersonId().longValue()){
- return true;
- }
- }else{
- return true;
- }
- }
- return false;
- }
- @Override
- public TableDataInfo<SysPerson> selectPersonList(SysPerson entity) {
- if (ObjectUtil.isEmpty(entity.getPageSize()) || entity.getPageSize() < 1) {
- entity.setPageSize(-1);
- entity.setPageNum(1);
- }
- TableDataInfo<SysPerson> info = new TableDataInfo<>();
- LambdaQueryWrapper<SysPerson> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ObjectUtils.isNotNull(entity.getStatus()), SysPerson::getStatus, 1);
- queryWrapper.eq(ObjectUtils.isNotNull(entity.getCompanyId()), SysPerson::getCompanyId, entity.getCompanyId());
- queryWrapper.eq(ObjectUtils.isNotNull(entity.getPersonName()), SysPerson::getPersonName, entity.getPersonName());
- Page<SysPerson> page = page(new Page<>(entity.getPageNum(), entity.getPageSize()),queryWrapper );
- info.setRows(page.getRecords());
- info.setTotal(page.getTotal());
- info.setCode(HttpStatus.HTTP_OK);
- info.setMsg("查询成功");
- return info;
- }
- @Override
- public SysPerson selectPersonById(Integer id) {
- return personMapper.selectById(id);
- }
- @Override
- public long insertPerson(SysPerson entity) {
- if (checkIdCardUnique(entity)) {
- throw new CustomException("身份证重复了");
- }
- if (checkPhoneUnique(entity)) {
- throw new CustomException("手机号重复了");
- }
- entity.setCreateTime(DateUtils.getNowTime());
- personMapper.insert(entity);
- return entity.getPersonId();
- }
- @Override
- public int updatePerson(SysPerson entity) {
- if (checkIdCardUnique(entity)) {
- throw new CustomException("身份证重复了");
- }
- if (checkPhoneUnique(entity)) {
- throw new CustomException("手机号重复了");
- }
- return personMapper.updateById(entity);
- }
- @Override
- public boolean deletePersonById(long id) {
- SysPerson entity = new SysPerson();
- entity.setPersonId(id);
- entity.setStatus(-1);
- entity.setUpdateTime(DateUtils.getNowTime());
- return personMapper.updateById(entity) > 0;
- }
- }
|