doc/create_table_customer_user.sql
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,10 @@ drop table if exists customer_user; create table customer_user ( id bigint auto_increment primary key, customer_id bigint not null default 0 comment '客æ·id', user_id bigint not null default 0 comment 'ç¨æ·id', create_time datetime null comment 'å½å ¥æ¶é´', tenant_id bigint not null default 0 comment 'ç§æ·id' ); src/main/java/com/ruoyi/basic/controller/CustomerController.java
@@ -121,4 +121,23 @@ } /** * åé å®¢æ· */ @Log(title = "å®¢æ·æ¡£æ¡", businessType = BusinessType.OTHER) @PostMapping("/assignCustomer") public AjaxResult assignCustomer(@RequestBody CustomerDto customer) { customerService.assignCustomer(customer); return AjaxResult.success(); } /** * åæ¶å®¢æ· */ @Log(title = "å®¢æ·æ¡£æ¡", businessType = BusinessType.OTHER) @PostMapping("/recycleCustomer") public AjaxResult recycleCustomer(@RequestBody CustomerDto customer) { customerService.recycleCustomer(customer); return AjaxResult.success(); } } src/main/java/com/ruoyi/basic/dto/CustomerDto.java
@@ -24,5 +24,4 @@ private String usageUserName; private String togetherUserNames; } src/main/java/com/ruoyi/basic/pojo/Customer.java
@@ -129,4 +129,9 @@ @Schema(description = "使ç¨ç¶æ") private Long usageStatus; @ApiModelProperty(value = "ç±»å 0 ç§æµ·å®¢æ· 1 å ¬æµ·å®¢æ·") private Integer type; @ApiModelProperty(value = "æ¯å¦è¢«åé ï¼0-æªåé ï¼1-å·²åé ") private Integer isAssigned; } src/main/java/com/ruoyi/basic/pojo/CustomerFollowUp.java
@@ -39,6 +39,8 @@ */ private Long customerPrivatePoolId; private Long customerId; /** * è·è¿æ¹å¼ */ src/main/java/com/ruoyi/basic/pojo/CustomerReturnVisit.java
@@ -38,6 +38,8 @@ */ private Integer customerPrivatePoolId; private Long customerId; /** * æéå¼å ³ (0:å ³é, 1:å¼å¯) */ src/main/java/com/ruoyi/basic/pojo/CustomerUser.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,43 @@ package com.ruoyi.basic.pojo; import com.baomidou.mybatisplus.annotation.*; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.time.LocalDateTime; @TableName(value = "customer") @Data public class CustomerUser implements Serializable { private static final long serialVersionUID = 1L; /** * åºå· */ @TableId(type = IdType.AUTO) private Long id; /** * 客æ·id */ private Long customerId; /** * ç¨æ·id */ private Long userId; /** * ç§æ·id */ @TableField(fill = FieldFill.INSERT) private Long tenantId; /** * å½å ¥æ¶é´ */ @ApiModelProperty(value = "å建æ¶é´") @TableField(fill = FieldFill.INSERT) private LocalDateTime createTime; } src/main/java/com/ruoyi/basic/service/ICustomerService.java
@@ -6,6 +6,7 @@ import com.ruoyi.basic.dto.CustomerDto; import com.ruoyi.basic.dto.CustomerPrivatePoolDto; import com.ruoyi.basic.pojo.Customer; import com.ruoyi.basic.vo.CustomerVo; import com.ruoyi.framework.web.domain.AjaxResult; import org.springframework.web.multipart.MultipartFile; @@ -33,7 +34,7 @@ * @param id å®¢æ·æ¡£æ¡ä¸»é® * @return 客æ·è¯¦æ DTO */ Customer selectCustomerDetailById(Long id); CustomerVo selectCustomerDetailById(Long id); /** * æ¥è¯¢å®¢æ·æ¡£æ¡å表 @@ -80,4 +81,8 @@ AjaxResult importData(MultipartFile file); IPage<CustomerDto> selectCustomerList(Page<CustomerDto> page, CustomerDto customer); void assignCustomer(CustomerDto customer); void recycleCustomer(CustomerDto customer); } src/main/java/com/ruoyi/basic/service/impl/CustomerReturnVisitServiceImpl.java
@@ -75,7 +75,7 @@ throw new ServiceException("客æ·IDä¸è½ä¸ºç©º"); } LambdaQueryWrapper<CustomerReturnVisit> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(CustomerReturnVisit::getCustomerPrivatePoolId, customerId); queryWrapper.eq(CustomerReturnVisit::getCustomerId, customerId); CustomerReturnVisit returnVisit = baseMapper.selectOne(queryWrapper); if (returnVisit == null) { @@ -94,7 +94,7 @@ throw new ServiceException("客æ·IDä¸è½ä¸ºç©º"); } LambdaQueryWrapper<CustomerReturnVisit> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(CustomerReturnVisit::getCustomerPrivatePoolId, customerId); queryWrapper.eq(CustomerReturnVisit::getCustomerId, customerId); List<CustomerReturnVisit> returnVisits = baseMapper.selectList(queryWrapper); for (CustomerReturnVisit returnVisit : returnVisits) { @@ -124,7 +124,7 @@ if (returnVisit == null) { throw new ServiceException("å访æéæ°æ®ä¸è½ä¸ºç©º"); } if (returnVisit.getCustomerPrivatePoolId() == null) { if (returnVisit.getCustomerId() == null) { throw new ServiceException("客æ·IDä¸è½ä¸ºç©º"); } if (returnVisit.getReminderTime() == null) { src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -8,16 +8,20 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.basic.dto.CustomerDto; import com.ruoyi.basic.dto.CustomerFollowUpDto; import com.ruoyi.basic.mapper.CustomerMapper; import com.ruoyi.basic.mapper.CustomerPrivatePoolMapper; import com.ruoyi.basic.pojo.Customer; import com.ruoyi.basic.pojo.CustomerFollowUp; import com.ruoyi.basic.pojo.CustomerFollowUpFile; import com.ruoyi.basic.pojo.CustomerPrivatePool; import com.ruoyi.basic.service.CustomerFollowUpService; import com.ruoyi.basic.service.CustomerReturnVisitService; import com.ruoyi.basic.service.ICustomerService; import com.ruoyi.basic.vo.CustomerVo; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.security.LoginUser; import com.ruoyi.framework.web.domain.AjaxResult; @@ -30,6 +34,9 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.*; import java.util.stream.Collectors; @@ -70,8 +77,35 @@ * @return 客æ·è¯¦æ DTO */ @Override public Customer selectCustomerDetailById(Long id) { return this.getById( id); public CustomerVo selectCustomerDetailById(Long id) { CustomerVo customerVo = new CustomerVo(); BeanUtils.copyProperties(this.getById(id), customerVo); // æ¥è¯¢è·è¿è®°å½ List<CustomerFollowUp> followUpList = customerFollowUpService.list( new LambdaQueryWrapper<CustomerFollowUp>() .eq(CustomerFollowUp::getCustomerId, id) .orderByDesc(CustomerFollowUp::getFollowUpTime) ); if (!com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(followUpList)) { List<CustomerFollowUpDto> followUpDtoList = followUpList.stream().map(followUp -> { CustomerFollowUpDto followUpDto = new CustomerFollowUpDto(); BeanUtils.copyProperties(followUp, followUpDto); // æ¥è¯¢éä»¶ List<CustomerFollowUpFile> fileList = customerFollowUpFileService.list( new LambdaQueryWrapper<CustomerFollowUpFile>() .eq(CustomerFollowUpFile::getFollowUpId, followUp.getId()) ); followUpDto.setFileList(fileList); return followUpDto; }).collect(Collectors.toList()); customerVo.setFollowUpList(followUpDtoList); } return customerVo; } /** @@ -172,15 +206,22 @@ if (!salesLedgers.isEmpty()) { throw new RuntimeException("å®¢æ·æ¡£æ¡ä¸æéå®ååï¼è¯·å å é¤éå®åå"); } List<CustomerPrivatePool> customerPrivatePools = customerPrivatePoolMapper.selectList(new QueryWrapper<CustomerPrivatePool>().lambda().in(CustomerPrivatePool::getCustomerId, idList)); if (!customerPrivatePools.isEmpty()) { throw new RuntimeException("å®¢æ·æ¡£æ¡ä¸æå®¢æ·ç§æµ·ï¼è¯·å æ¶åç§æµ·æ°æ®"); // æ¥è¯¢æ¯å¦æå·²åé çå ¬æµ·å®¢æ· List<Customer> assignedPools = customerMapper.selectList( new QueryWrapper<Customer>().lambda() .in(Customer::getId, idList) .eq(Customer::getType, 1). eq(Customer::getIsAssigned, 1) // å ¬æµ·å®¢æ· ); if (!assignedPools.isEmpty()) { throw new RuntimeException("å®¢æ·æ¡£æ¡ä¸æå·²åé çå ¬æµ·å®¢æ·ï¼è¯·å æ¶å"); } // å é¤å®¢æ·çåæ¶ä¹éè¦å é¤å¯¹åºç客æ·è·éãéä»¶åå访æé for (Long id : ids) { customerFollowUpService.deleteByCustomerId(id); customerReturnVisitService.deleteByCustomerId(id); } customerMapper.delete(new QueryWrapper<Customer>().lambda().in(Customer::getId, idList)); return customerMapper.deleteBatchIds(idList); } @@ -230,6 +271,30 @@ ).collect(Collectors.toList()); } // åé å ¬æµ·å®¢æ·ç»ç§æµ· @Override public void assignCustomer(CustomerDto customerDto) { Customer customer = customerMapper.selectById(customerDto.getId()); if (customer.getType() == 1 && customer.getIsAssigned() == 0) { // å ¬æµ·ä¸å¯åé customer.setIsAssigned(1); customer.setUsageStatus(1L); customer.setUsageUser(customerDto.getUsageUser()); customerMapper.updateById(customer); } } // åæ¶ç§æµ·å®¢æ·å°å ¬æµ· @Override public void recycleCustomer(CustomerDto customerDto) { Customer customer = customerMapper.selectById(customerDto.getId()); if (customer.getType() == 1 && customer.getIsAssigned() == 1) { // å ¬æµ·ä¸å·²åé customer.setIsAssigned(0); customer.setUsageStatus(0L); customer.setUsageUser(null); customerMapper.updateById(customer); } } /** * ä¸å线å½å转驼峰å½å */ src/main/java/com/ruoyi/basic/task/ReturnVisitReminderTask.java
@@ -72,7 +72,7 @@ } try { unipushService.sendReturnVisitReminder(returnVisitId, client.getCid(), returnVisit.getContent(), returnVisit.getCustomerPrivatePoolId()); unipushService.sendReturnVisitReminder(returnVisitId, client.getCid(), returnVisit.getContent(), returnVisit.getCustomerId()); CustomerReturnVisit updateObj = new CustomerReturnVisit(); updateObj.setId(returnVisitId); updateObj.setIsCompleted(1); src/main/java/com/ruoyi/basic/vo/CustomerVo.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,14 @@ package com.ruoyi.basic.vo; import com.ruoyi.basic.dto.CustomerFollowUpDto; import com.ruoyi.basic.pojo.Customer; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.List; @Data public class CustomerVo extends Customer { @ApiModelProperty(value = "è·è¿è®°å½") private List<CustomerFollowUpDto> followUpList; } src/main/java/com/ruoyi/project/system/service/impl/UnipushService.java
@@ -136,7 +136,7 @@ /** * åéå访æé */ public void sendReturnVisitReminder(Long returnVisitId, String cid, String content, Integer customerId) { public void sendReturnVisitReminder(Long returnVisitId, String cid, String content, Long customerId) { String targetPath = "pages/cooperativeOffice/customerManage/detail?customerId=" + customerId; sendRoutingPush(returnVisitId, cid, "客æ·å访æé", content, targetPath, false); } src/main/resources/mapper/basic/CustomerMapper.xml
@@ -12,10 +12,10 @@ u.user_name usage_user_name, ( select group_concat(u2.user_name separator ', ') from customer_private_pool cpp2 left join sys_user u2 on cpp2.bound_id = u2.user_id where cpp2.customer_id = c.id and cpp2.delete_flag = 0 and cpp2.bound_id != c.usage_user from customer_user cu left join sys_user u2 on cu.user_id = u2.user_id where cu.customer_id = c.id and cu.user_id != c.usage_user ) as together_user_names from customer c left join sys_user u on c.usage_user = u.user_id @@ -26,6 +26,14 @@ <if test="c.customerType != null and c.customerType != ''"> and customer_type = #{c.customerType} </if> <!-- ç§æµ·æ¥è¯¢ï¼type = 0ï¼ç§æµ·å®¢æ·ï¼æè type = 1ï¼å ¬æµ·å®¢æ·ï¼ä¸å·²è¢«åé --> <if test="c.type != null and c.type == 0"> and type = #{c.type} or (type = 1 and is_assigned = 1) </if> <!-- å ¬æµ·æ¥è¯¢ï¼type = 1ï¼å ¬æµ·å®¢æ·ï¼--> <if test="c.type != null and c.type == 1"> and type = #{c.type} </if> </where> </select>