| | |
| | | import com.mzl.flower.dto.request.partner.*; |
| | | import com.mzl.flower.dto.response.partner.PartnerDTO; |
| | | import com.mzl.flower.entity.partner.Partner; |
| | | import com.mzl.flower.entity.supplier.Supplier; |
| | | import com.mzl.flower.entity.system.User; |
| | | import com.mzl.flower.mapper.partner.PartnerMapper; |
| | | import com.mzl.flower.mapper.system.UserMapper; |
| | | import com.mzl.flower.service.BaseService; |
| | | import com.mzl.flower.service.UploadService; |
| | | import com.mzl.flower.service.system.UserService; |
| | | import com.mzl.flower.utils.DateUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | |
| | | private final PartnerMapper partnerMapper; |
| | | |
| | | private final UserMapper userMapper; |
| | | |
| | | |
| | | private final WxMaService maService; |
| | | |
| | |
| | | @Resource |
| | | private BaseService baseService; |
| | | |
| | | public PartnerService(PartnerMapper partnerMapper, WxMaService maService, UploadService uploadService) { |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | |
| | | public PartnerService(PartnerMapper partnerMapper, UserMapper userMapper, WxMaService maService, UploadService uploadService) { |
| | | this.partnerMapper = partnerMapper; |
| | | this.userMapper = userMapper; |
| | | this.maService = maService; |
| | | this.uploadService = uploadService; |
| | | } |
| | |
| | | if(dto.getId()==null){ //注册 |
| | | if(checkExist(dto.getUserId())){ |
| | | throw new ValidationException("合伙人信息已登记"); |
| | | } |
| | | if(StringUtils.isNotBlank(dto.getContactTel()) && StringUtils.isNotBlank(dto.getUserId())){ |
| | | //验证手机号 |
| | | User user = userMapper.selectById(dto.getUserId()); |
| | | if(user==null){ |
| | | throw new ValidationException("合伙人账号信息不存在"); |
| | | } |
| | | if(userMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getTel, dto.getContactTel()) |
| | | .eq(User::getType, Constants.USER_TYPE.partner.name()) |
| | | .ne(User::getId, dto.getUserId()) |
| | | .eq(User::getDeleted, 0) |
| | | )>0){ |
| | | throw new ValidationException("手机号已被注册使用"); |
| | | } |
| | | user.setTel(dto.getContactTel()); |
| | | userMapper.updateById(user); |
| | | } |
| | | partner = new Partner(); |
| | | BeanUtils.copyProperties(dto, partner,"id"); |
| | |
| | | partner = partnerMapper.selectById(dto.getId()); |
| | | if(partner==null){ |
| | | throw new ValidationException("合伙人信息未登记"); |
| | | } |
| | | if(StringUtils.isNotBlank(dto.getContactTel()) && !partner.getContactTel().equals(dto.getContactTel())){ |
| | | //验证手机号 |
| | | User user = userMapper.selectById(partner.getUserId()); |
| | | if(user==null){ |
| | | throw new ValidationException("合伙人账号信息不存在"); |
| | | } |
| | | if(userMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getTel, dto.getContactTel()) |
| | | .eq(User::getType, Constants.USER_TYPE.partner.name()) |
| | | .ne(User::getId, partner.getUserId()) |
| | | .eq(User::getDeleted, 0) |
| | | )>0){ |
| | | throw new ValidationException("手机号已被注册使用"); |
| | | } |
| | | user.setTel(dto.getContactTel()); |
| | | partner.setContactTel(dto.getContactTel()); |
| | | userMapper.updateById(user); |
| | | } |
| | | BeanUtils.copyProperties(dto, partner,"id"); |
| | | partner.setIdCards(JSON.toJSONString(dto.getIdCards())); |
| | |
| | | if(StringUtils.isNotBlank(dto.getName())){ |
| | | partner.setName(dto.getName()); |
| | | } |
| | | if(StringUtils.isNotBlank(dto.getContactTel())){ |
| | | if(StringUtils.isNotBlank(dto.getContactTel()) && !partner.getContactTel().equals(dto.getContactTel())){ |
| | | //验证手机号 |
| | | User user = userMapper.selectById(partner.getUserId()); |
| | | if(user==null){ |
| | | throw new ValidationException("合伙人账号信息不存在"); |
| | | } |
| | | if(userMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getTel, dto.getContactTel()) |
| | | .eq(User::getType, Constants.USER_TYPE.partner.name()) |
| | | .ne(User::getId, partner.getUserId()) |
| | | .eq(User::getDeleted, 0) |
| | | )>0){ |
| | | throw new ValidationException("手机号已被注册使用"); |
| | | } |
| | | user.setTel(dto.getContactTel()); |
| | | partner.setContactTel(dto.getContactTel()); |
| | | userMapper.updateById(user); |
| | | } |
| | | partner.update(SecurityUtils.getUserId()); |
| | | partnerMapper.updateById(partner); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | public String generateCodeDTO(GenerateCodeDTO dto) { |
| | | try { |
| | |
| | | partner.update(SecurityUtils.getUserId()); |
| | | partnerMapper.updateById(partner); |
| | | } |
| | | |
| | | public void baseUpdate(UpdatePartnerBaseDTO dto) { |
| | | Partner partner = partnerMapper.selectById(dto.getId()); |
| | | if(partner==null){ |
| | | throw new ValidationException("合伙人信息未登记"); |
| | | } |
| | | BeanUtils.copyProperties(dto, partner,"id"); |
| | | partner.update(SecurityUtils.getUserId()); |
| | | partnerMapper.updateById(partner); |
| | | } |
| | | |
| | | @Transactional |
| | | public void phoneUpdate(UpdatePhoneDTO dto) { |
| | | Partner partner = partnerMapper.selectById(dto.getId()); |
| | | if(partner==null){ |
| | | throw new ValidationException("合伙人信息未登记"); |
| | | } |
| | | User user = userService.getUserById(partner.getUserId()); |
| | | if(user == null){ |
| | | throw new ValidationException("用户不存在"); |
| | | } |
| | | partner.setContactTel(dto.getUsername()); |
| | | partner.update(SecurityUtils.getUserId()); |
| | | partnerMapper.updateById(partner); |
| | | |
| | | user.setTel(dto.getUsername()); |
| | | user.setLoginName(dto.getUsername()); |
| | | user.update(SecurityUtils.getUserId()); |
| | | userMapper.updateById(user); |
| | | |
| | | } |
| | | } |