|
@@ -0,0 +1,119 @@
|
|
|
+package com.fjhx.customer.service.customer.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerUserDto;
|
|
|
+import com.fjhx.customer.entity.customer.po.Customer;
|
|
|
+import com.fjhx.customer.entity.customer.po.CustomerUser;
|
|
|
+import com.fjhx.customer.mapper.customer.CustomerMapper;
|
|
|
+import com.fjhx.customer.service.customer.CustomerService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.customer.service.customer.CustomerUserService;
|
|
|
+import com.fjhx.customer.utils.code.CodeEnum;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fjhx.customer.entity.customer.vo.CustomerVo;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerSelectDto;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 客户表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-04-04
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
|
|
|
+ @Autowired
|
|
|
+ private CustomerUserService customerUserService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询客户的列表
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<CustomerVo> getPage(CustomerSelectDto dto) {
|
|
|
+ LambdaQueryWrapper<Customer> wrapper = Wrappers.<Customer>lambdaQuery();
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getSource()),Customer::getSource,dto.getSource());
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getStatus()),Customer::getStatus,dto.getStatus());
|
|
|
+ //客户状态(0:公海客户 1:私海客户)(业务员ID为null为公海客户,业务员ID不为null为私海客户)
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getType())){
|
|
|
+ wrapper.isNotNull(dto.getType().equals("1"),Customer::getUserId);
|
|
|
+ wrapper.isNull(dto.getType().equals("0"),Customer::getUserId);
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(Customer::getCreateTime);
|
|
|
+ Page<CustomerVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询客户的详情
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CustomerDto detail(Long id) {
|
|
|
+ //查询客户表的信息
|
|
|
+ Customer Customer = this.getById(id);
|
|
|
+ CustomerDto result = BeanUtil.toBean(Customer, CustomerDto.class);
|
|
|
+ //查询客户-联系人表的信息
|
|
|
+ List<CustomerUser> customerUserList = customerUserService.list(Wrappers.<CustomerUser>lambdaQuery()
|
|
|
+ .eq(CustomerUser::getCustomerId, result.getId()));
|
|
|
+ result.setCustomerUserList(customerUserList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加客户表的数据
|
|
|
+ * @param customerDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void add(CustomerDto customerDto) {
|
|
|
+ customerDto.setCode(CodeEnum.CUSTOMER.getCode());
|
|
|
+ this.save(customerDto);
|
|
|
+ saveCustomerUse(customerDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改客户表的数据
|
|
|
+ * @param customerDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void edit(CustomerDto customerDto) {
|
|
|
+ //修改客户表的信息
|
|
|
+ this.updateById(customerDto);
|
|
|
+ //删除客户-用户表的信息
|
|
|
+ customerUserService.remove(Wrappers.<CustomerUser>lambdaQuery().eq(CustomerUser::getCustomerId,customerDto.getId()));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除客户表的数据
|
|
|
+ * @param
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ //删除客户表的数据
|
|
|
+ this.removeById(id);
|
|
|
+ //删除客户-联系人表的数据
|
|
|
+ customerUserService.remove(Wrappers.<CustomerUser>lambdaQuery().eq(CustomerUser::getCustomerId,id));
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加客户用户表的信息
|
|
|
+ private void saveCustomerUse(CustomerDto customerDto){
|
|
|
+ List<CustomerUser> customerUserDtoList = customerDto.getCustomerUserList();
|
|
|
+ customerUserDtoList.forEach(customerUserDto -> customerUserDto.setCustomerId(customerDto.getId()));
|
|
|
+ customerUserService.saveBatch(customerUserDtoList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|