| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.druid.sql.visitor.functions.Concat; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.CustomerLogMapper; |
| | | import com.doumee.dao.business.CustomerMapper; |
| | | import com.doumee.dao.business.model.Customer; |
| | | import com.doumee.dao.business.CustomerUserMapper; |
| | | import com.doumee.dao.business.MemberMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.web.reqeust.FreeCustomizationDTO; |
| | | import com.doumee.dao.web.reqeust.RenovationCalculatorDTO; |
| | | import com.doumee.dao.web.reqeust.TestTrimStyleDTO; |
| | | import com.doumee.service.business.CustomerLogService; |
| | | import com.doumee.service.business.CustomerService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.service.business.CustomerUserService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.checkerframework.checker.units.qual.C; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 客户信息表Service实现 |
| | |
| | | |
| | | @Autowired |
| | | private CustomerMapper customerMapper; |
| | | |
| | | @Autowired |
| | | private CustomerLogMapper customerLogMapper; |
| | | @Autowired |
| | | private CustomerUserMapper customerUserMapper; |
| | | |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | |
| | | @Override |
| | | public Long create(Customer customer) { |
| | |
| | | if (pageWrap.getModel().getAreaCode() != null) { |
| | | queryWrapper.lambda().eq(Customer::getAreaCode, pageWrap.getModel().getAreaCode()); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | queryWrapper.lambda().orderByDesc(Customer::getCreateDate ); |
| | | return PageData.from(customerMapper.selectPage(page, queryWrapper)); |
| | | } |
| | | |
| | |
| | | return customerMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public CustomerLog saveRenovationCalculator(RenovationCalculatorDTO renovationCalculatorDTO){ |
| | | if(Objects.isNull(renovationCalculatorDTO) |
| | | || Objects.isNull(renovationCalculatorDTO.getMemberId()) |
| | | || Objects.isNull(renovationCalculatorDTO.getHouseStatus()) |
| | | || Objects.isNull(renovationCalculatorDTO.getHouseType()) |
| | | || Objects.isNull(renovationCalculatorDTO.getBudget()) |
| | | || StringUtils.isEmpty(renovationCalculatorDTO.getArea()) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Member member = memberMapper.selectById(renovationCalculatorDTO.getMemberId()); |
| | | if(Objects.isNull(member)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到用户信息"); |
| | | } |
| | | if(StringUtils.isEmpty(member.getPhone())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未授权手机号"); |
| | | } |
| | | Customer customer = customerMapper.selectOne(new QueryWrapper<Customer>().lambda().eq(Customer::getPhone,member.getPhone()).eq(Customer::getIsdeleted, Constants.ZERO).last("limit 1")); |
| | | if(Objects.isNull(customer)){ |
| | | customer = new Customer(); |
| | | customer.setIsdeleted(Constants.ZERO); |
| | | customer.setPhone(member.getPhone()); |
| | | customer.setCreateDate(new Date()); |
| | | } else{ |
| | | customer.setEditDate(new Date()); |
| | | } |
| | | customer.setOpenid(member.getOpenid()); |
| | | customer.setMemberId(member.getId()); |
| | | |
| | | customerMapper.insertOrUpdate(customer); |
| | | |
| | | |
| | | public void saveRenovationCalculator(){ |
| | | |
| | | |
| | | |
| | | //存储 customerLog 数据 |
| | | CustomerLog customerLog = new CustomerLog(); |
| | | customerLog.setCreateDate(new Date()); |
| | | customerLog.setIsdeleted(Constants.ZERO); |
| | | customerLog.setType(Constants.TWO); |
| | | customerLog.setCrmStatus(Constants.ZERO); |
| | | customerLog.setName(StringUtils.isEmpty(member.getName())?member.getNickname():member.getName()); |
| | | customerLog.setPhone(customer.getPhone()); |
| | | customerLog.setBudget(renovationCalculatorDTO.getBudget().multiply(new BigDecimal(10000)).toString()); |
| | | customerLog.setHouseStatus(renovationCalculatorDTO.getHouseStatus()); |
| | | customerLog.setArea(renovationCalculatorDTO.getArea()); |
| | | customerLog.setHouseType(renovationCalculatorDTO.getHouseType()); |
| | | customerLog.setCostomerId(customer.getId().toString()); |
| | | customerLogMapper.insert(customerLog); |
| | | customerLog.setOpenid(member.getOpenid()); |
| | | return customerLog; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public CustomerLog saveFreeCustomizationApply(FreeCustomizationDTO freeCustomizationDTO){ |
| | | if(Objects.isNull(freeCustomizationDTO) |
| | | || Objects.isNull(freeCustomizationDTO.getMemberId()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getName()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getPhone()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getCityCode()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getCityName()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getProvinceName()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getProvinceCode()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getAreaCode()) |
| | | || StringUtils.isEmpty(freeCustomizationDTO.getAreaName()) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Member member = memberMapper.selectById(freeCustomizationDTO.getMemberId()); |
| | | if(Objects.isNull(member)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到用户信息"); |
| | | } |
| | | if(StringUtils.isEmpty(member.getPhone())){ |
| | | member.setPhone(freeCustomizationDTO.getPhone()); |
| | | memberMapper.updateById(member); |
| | | } |
| | | Customer customer = customerMapper.selectOne(new QueryWrapper<Customer>().lambda() |
| | | .eq(Customer::getPhone,freeCustomizationDTO.getPhone()).eq(Customer::getIsdeleted, Constants.ZERO).last("limit 1")); |
| | | if(Objects.isNull(customer)){ |
| | | customer = new Customer(); |
| | | customer.setPhone(freeCustomizationDTO.getPhone()); |
| | | customer.setCreateDate(new Date()); |
| | | customer.setIsdeleted(Constants.ZERO); |
| | | } else{ |
| | | customer.setEditDate(new Date()); |
| | | } |
| | | customer.setOpenid(member.getOpenid()); |
| | | customer.setMemberId(member.getId()); |
| | | customer.setName(freeCustomizationDTO.getName()); |
| | | customer.setProName(freeCustomizationDTO.getProvinceName()); |
| | | customer.setCityName(freeCustomizationDTO.getCityName()); |
| | | customer.setAreaName(freeCustomizationDTO.getAreaName()); |
| | | customer.setProvinceCode(freeCustomizationDTO.getProvinceCode()); |
| | | customer.setCityCode(freeCustomizationDTO.getCityCode()); |
| | | customer.setAreaCode(freeCustomizationDTO.getAreaCode()); |
| | | customerMapper.insertOrUpdate(customer); |
| | | |
| | | //存储 customerLog 数据 |
| | | CustomerLog customerLog = new CustomerLog(); |
| | | customerLog.setCreateDate(new Date()); |
| | | customerLog.setIsdeleted(Constants.ZERO); |
| | | customerLog.setType(Constants.ONE); |
| | | customerLog.setCrmStatus(Constants.ZERO); |
| | | customerLog.setPhone(customer.getPhone()); |
| | | customerLog.setCostomerId(customer.getId().toString()); |
| | | |
| | | customerLog.setProvinceName(freeCustomizationDTO.getProvinceName()); |
| | | customerLog.setCityName(freeCustomizationDTO.getCityName()); |
| | | customerLog.setAreaCode(freeCustomizationDTO.getAreaName()); |
| | | customerLog.setProvicneCode(freeCustomizationDTO.getProvinceCode()); |
| | | customerLog.setCityCode(freeCustomizationDTO.getCityCode()); |
| | | customerLog.setAreaCode(freeCustomizationDTO.getAreaCode()); |
| | | customerLog.setName(freeCustomizationDTO.getName()); |
| | | customerLog.setPhone(freeCustomizationDTO.getPhone()); |
| | | customerLog.setUsernames(freeCustomizationDTO.getUsername()); |
| | | if(org.apache.commons.lang3.StringUtils.isBlank(freeCustomizationDTO.getUsername())){ |
| | | //如果导购信息为空,查询该客户已绑定的导购信息,传递给CRM使用 |
| | | List<CustomerUser> userList = customerUserMapper.selectJoinList(CustomerUser.class, |
| | | new MPJLambdaWrapper<CustomerUser>() |
| | | .selectAs(Users::getIamUsername,CustomerUser::getUsername) |
| | | .leftJoin(Users.class, Users::getId,CustomerUser::getUserId) |
| | | .eq(CustomerUser::getIsdeleted,Constants.ZERO) |
| | | .eq(CustomerUser::getCustomerPhone,customerLog.getPhone()) |
| | | .groupBy(Users::getIamUsername)); |
| | | if(userList!=null && userList.size()>0){ |
| | | String names = ""; |
| | | for(CustomerUser cu : userList){ |
| | | if(!names.equals("")){ |
| | | names += ","; |
| | | } |
| | | names += cu.getUsername(); |
| | | } |
| | | if(!names.equals("")){ |
| | | customerLog.setUsernames(names); |
| | | } |
| | | } |
| | | } |
| | | customerLogMapper.insert(customerLog); |
| | | customerLog.setOpenid(member.getOpenid()); |
| | | return customerLog; |
| | | } |
| | | |
| | | @Override |
| | | public CustomerLog saveTestTrimStyle(TestTrimStyleDTO testTrimStyleDTO){ |
| | | if(Objects.isNull(testTrimStyleDTO) |
| | | || Objects.isNull(testTrimStyleDTO.getMemberId()) |
| | | |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getStyleInfo()) |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getAgeInfo()) |
| | | || Objects.isNull(testTrimStyleDTO.getSex()) |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getHouseType()) |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getAgeInfo()) |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getPhone()) |
| | | |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getCityCode()) |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getCityName()) |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getProvinceName()) |
| | | || StringUtils.isEmpty(testTrimStyleDTO.getProvinceCode()) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Member member = memberMapper.selectById(testTrimStyleDTO.getMemberId()); |
| | | if(Objects.isNull(member)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到用户信息"); |
| | | } |
| | | if(StringUtils.isEmpty(member.getPhone())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未授权手机号"); |
| | | } |
| | | Customer customer = customerMapper.selectOne(new QueryWrapper<Customer>().lambda() |
| | | .eq(Customer::getPhone,testTrimStyleDTO.getPhone()).eq(Customer::getIsdeleted, Constants.ZERO).last("limit 1")); |
| | | if(Objects.isNull(customer)){ |
| | | customer = new Customer(); |
| | | customer.setPhone(testTrimStyleDTO.getPhone()); |
| | | customer.setCreateDate(new Date()); |
| | | customer.setIsdeleted(Constants.ZERO); |
| | | } else{ |
| | | customer.setEditDate(new Date()); |
| | | } |
| | | customer.setOpenid(member.getOpenid()); |
| | | customer.setMemberId(member.getId()); |
| | | |
| | | customer.setProName(testTrimStyleDTO.getProvinceName()); |
| | | customer.setCityName(testTrimStyleDTO.getCityName()); |
| | | customer.setProvinceCode(testTrimStyleDTO.getProvinceCode()); |
| | | customer.setCityCode(testTrimStyleDTO.getCityCode()); |
| | | customerMapper.insertOrUpdate(customer); |
| | | |
| | | //存储 customerLog 数据 |
| | | CustomerLog customerLog = new CustomerLog(); |
| | | customerLog.setCreateDate(new Date()); |
| | | customerLog.setIsdeleted(Constants.ZERO); |
| | | customerLog.setType(Constants.ZERO); |
| | | customerLog.setCrmStatus(Constants.ZERO); |
| | | customerLog.setPhone(customer.getPhone()); |
| | | customerLog.setCostomerId(customer.getId().toString()); |
| | | |
| | | customerLog.setProvinceName(testTrimStyleDTO.getProvinceName()); |
| | | customerLog.setCityName(testTrimStyleDTO.getCityName()); |
| | | customerLog.setProvicneCode(testTrimStyleDTO.getProvinceCode()); |
| | | customerLog.setCityCode(testTrimStyleDTO.getCityCode()); |
| | | |
| | | customerLog.setAgeInfo(testTrimStyleDTO.getAgeInfo()); |
| | | customerLog.setHouseType(testTrimStyleDTO.getHouseType()); |
| | | customerLog.setStyleInfo(testTrimStyleDTO.getStyleInfo()); |
| | | customerLog.setSex(testTrimStyleDTO.getSex()); |
| | | customerLog.setAgeInfo(testTrimStyleDTO.getAgeInfo()); |
| | | customerLog.setPhone(testTrimStyleDTO.getPhone()); |
| | | customerLogMapper.insert(customerLog); |
| | | customerLog.setOpenid(member.getOpenid()); |
| | | return customerLog; |
| | | } |
| | | |
| | | |
| | | |
| | | |