|
@@ -0,0 +1,110 @@
|
|
|
+package com.fjhx.customer.service.customer.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.enums.PushBusinessTypeEnum;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerLvDto;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerLvSelectDto;
|
|
|
+import com.fjhx.customer.entity.customer.po.Customer;
|
|
|
+import com.fjhx.customer.entity.customer.po.CustomerLv;
|
|
|
+import com.fjhx.customer.entity.customer.vo.CustomerLvVo;
|
|
|
+import com.fjhx.customer.entity.customer.vo.CustomerVo;
|
|
|
+import com.fjhx.customer.mapper.customer.CustomerLvMapper;
|
|
|
+import com.fjhx.customer.service.customer.CustomerLvService;
|
|
|
+import com.fjhx.customer.service.customer.CustomerService;
|
|
|
+import com.fjhx.socket.core.PushTypeEnum;
|
|
|
+import com.fjhx.socket.core.WebSocketPush;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.framework.mybatis.holder.TenantHolder;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 客户等级 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2024-04-02
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CustomerLvServiceImpl extends ServiceImpl<CustomerLvMapper, CustomerLv> implements CustomerLvService {
|
|
|
+ @Autowired
|
|
|
+ private CustomerService customerService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<CustomerLvVo> getPage(CustomerLvSelectDto dto) {
|
|
|
+ IWrapper<CustomerLv> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("cl", CustomerLv::getId);
|
|
|
+ Page<CustomerLvVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CustomerLvVo detail(Long id) {
|
|
|
+ CustomerLv CustomerLv = this.getById(id);
|
|
|
+ CustomerLvVo result = BeanUtil.toBean(CustomerLv, CustomerLvVo.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(CustomerLvDto customerLvDto) {
|
|
|
+ this.save(customerLvDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(CustomerLvDto customerLvDto) {
|
|
|
+ this.updateById(customerLvDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启动时和每天0点 自动将 超过指定时间没跟进的客户转入公海
|
|
|
+ */
|
|
|
+// @PostConstruct
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+ void customerAutoTransfer() {
|
|
|
+ TenantHolder.setIgnore(true);
|
|
|
+ List<CustomerVo> list = customerService.getList(IWrapper.<Customer>getWrapper()
|
|
|
+ .apply("DATEDIFF(now(),IFNULL(c.last_follow_time, NOW())) >cul.max_not_follow")
|
|
|
+ .isNotNull("cul.max_not_follow")
|
|
|
+ .isNotNull("c.user_id")
|
|
|
+ );
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (CustomerVo customerVo : list) {
|
|
|
+ customerService.update(q -> q
|
|
|
+ .eq(Customer::getId, customerVo.getId())
|
|
|
+ .set(Customer::getUserId, null)
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ );
|
|
|
+
|
|
|
+ JSONObject msg = new JSONObject();
|
|
|
+ msg.put("business_id", customerVo.getId());
|
|
|
+ WebSocketPush.byUser(PushTypeEnum.MESSAGE, customerVo.getUserId(),
|
|
|
+ String.format("您的客户【%s】因长时间未跟进,已自动转入公海!"),
|
|
|
+ PushBusinessTypeEnum.NEW_QUOTATION.getType(),
|
|
|
+ msg.toString());
|
|
|
+ }
|
|
|
+ TenantHolder.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|