| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | |
| | | @Service |
| | | @Transactional |
| | |
| | | |
| | | @Resource |
| | | private BaseService baseService; |
| | | |
| | | private static final String CHARACTERS = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; |
| | | |
| | | private final Random random = new Random(); |
| | | |
| | | public CustomerService(CustomerMapper customerMapper, PartnerMapper partnerMapper) { |
| | | this.customerMapper = customerMapper; |
| | |
| | | |
| | | customer.create(SecurityUtils.getUserId()); |
| | | customer.setIsEnabled(true); |
| | | customer.setIntervialcode(generateCode()); |
| | | customer.setReintervialcode(dto.getRegesterCode()); |
| | | customer.setLevelId(Long.valueOf(Constants.DEFAULT_MEMBER_ID)); |
| | | customerMapper.insert(customer); |
| | | } else {//重新修改 |
| | |
| | | |
| | | private boolean checkExist(String userId) { |
| | | return customerMapper.selectCount(new LambdaQueryWrapper<Customer>().eq(Customer::getUserId, userId)) > 0; |
| | | } |
| | | |
| | | //验证邀请码是否有效 |
| | | public boolean checkCode(String code) { |
| | | return customerMapper.findCustomerByInvitationCode(code) == null; |
| | | } |
| | | |
| | | public Page<CustomerDTO> queryCustomer(QueryCustomerDTO dto, Page page) { |
| | |
| | | public void updateMemberInfo(Customer customer) { |
| | | customerMapper.updateById(customer); |
| | | } |
| | | |
| | | public void checkVipExpireTime() { |
| | | // 获取当天日期之前,且is_member=1的用户,设置为is_member=0并且将member_overtime设置为null |
| | | customerMapper.checkVipExpireTime(); |
| | | } |
| | | |
| | | //生成邀请码 |
| | | private String generateCode() { |
| | | StringBuilder sb = new StringBuilder(4); |
| | | for (int i = 0; i < 4; i++) { |
| | | sb.append(CHARACTERS.charAt(random.nextInt(CHARACTERS.length()))); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public void updateMemberInfoByUserId(Customer customer) { |
| | | if(null!= customer && StringUtils.isNotBlank(customer.getUserId())){ |
| | | Customer byUserId = getByUserId(customer.getUserId()); |
| | | if(null !=byUserId){ |
| | | byUserId.setName(customer.getName()); |
| | | byUserId.setCover(customer.getCover()); |
| | | customerMapper.updateById(byUserId); |
| | | }else{ |
| | | throw new ValidationException("用户不存在"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |