|
|
@@ -1,9 +1,11 @@
|
|
|
package com.dk.mdm.service.mst;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.dk.common.exception.BaseBusinessException;
|
|
|
import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
import com.dk.common.infrastructure.constant.Constant;
|
|
|
import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
+import com.dk.common.infrastructure.xxl.XxlJobUtils;
|
|
|
import com.dk.common.model.pojo.PageList;
|
|
|
import com.dk.common.model.vo.core.StaffEntity;
|
|
|
import com.dk.common.response.ResponseCodeEnum;
|
|
|
@@ -24,16 +26,21 @@ import com.dk.common.model.response.mst.StaffResponse;
|
|
|
import com.dk.mdm.model.vo.mst.CusFollowVO;
|
|
|
import com.dk.mdm.model.vo.mst.MeasureReceiptVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
+import com.xxl.job.core.context.XxlJobHelper;
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
-@Transactional
|
|
|
public class CusFollowService extends BaseService<CusFollow> {
|
|
|
|
|
|
@Override
|
|
|
@@ -76,7 +83,10 @@ public class CusFollowService extends BaseService<CusFollow> {
|
|
|
|
|
|
@Autowired
|
|
|
private MeasureRoomMapper measureRoomMapper;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private FollowPlanMapper followPlanMapper;
|
|
|
+ @Autowired
|
|
|
+ private XxlJobUtils xxlJobUtils;
|
|
|
|
|
|
@Autowired
|
|
|
private MeasureReceiptConvert measureReceiptConvert;
|
|
|
@@ -115,7 +125,7 @@ public class CusFollowService extends BaseService<CusFollow> {
|
|
|
public ResponseResultVO<CusFollowResponse> selectById(CusFollowQuery cusFollowQuery) {
|
|
|
CusFollowResponse cusFollowResponse = cusFollowMapper.selectByCond(cusFollowQuery).get(0);
|
|
|
|
|
|
- if (cusFollowResponse.getFollowId() != null && cusFollowResponse.getMeasureStatus()!=null &&cusFollowResponse.getMeasureStatus().equals(Constant.BasicDataConstant.MEASURE_STATUS_1.getValue())) {
|
|
|
+ if (cusFollowResponse.getFollowId() != null && cusFollowResponse.getMeasureStatus() != null && cusFollowResponse.getMeasureStatus().equals(Constant.BasicDataConstant.MEASURE_STATUS_1.getValue())) {
|
|
|
//已量尺
|
|
|
MeasureReceipt measureReceipts = measureReceiptMapper.selectByFollowId(new MeasureReceipt().setFollowId(cusFollowQuery.getFollowId()));
|
|
|
cusFollowResponse.setMeasureReceipt(measureReceipts);
|
|
|
@@ -271,15 +281,9 @@ public class CusFollowService extends BaseService<CusFollow> {
|
|
|
}});
|
|
|
customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
//新建客户或编辑客户
|
|
|
customerMapper.insert(customer);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
// 约量尺
|
|
|
if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(cusFollow.getFollowStatus())) {
|
|
|
// 量尺状态:待量尺
|
|
|
@@ -289,65 +293,220 @@ public class CusFollowService extends BaseService<CusFollow> {
|
|
|
cusFollow.setFollowData("无");
|
|
|
}
|
|
|
super.insert(cusFollow);
|
|
|
-
|
|
|
-
|
|
|
//设计师
|
|
|
StaffResponse designStaff = null;
|
|
|
if (cusFollow.getDesignStaff() != null) {
|
|
|
-
|
|
|
designStaff = staffMapper.selectById(cusFollow.getDesignStaff());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- // 约尺 同意邀约 有设计师 设计师绑定企微
|
|
|
- boolean pushFlag = Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(cusFollow.getFollowStatus()) &&
|
|
|
- Constant.BasicDataConstant.FOLLOW_INVITE_RESULT.getValue().equals(cusFollow.getInviteResult()) &&
|
|
|
- designStaff != null;
|
|
|
-
|
|
|
- if (cusFollow.getNextFollowTime() != null || pushFlag) {
|
|
|
+ // 只要有跟进日期
|
|
|
+ if (cusFollow.getNextFollowTime() != null) {
|
|
|
// 保存跟进信息
|
|
|
- // saveToXxlJob(cusFollow);
|
|
|
+ saveToXxlJob(cusFollow);
|
|
|
}
|
|
|
|
|
|
return ResponseResultUtil.success();
|
|
|
}
|
|
|
|
|
|
|
|
|
-/**
|
|
|
- * @desc : 保存跟进信息到xxl job
|
|
|
- * @author : 于继渤海
|
|
|
- * @date : 2022-05-27 09:53
|
|
|
- */
|
|
|
-// @Transactional(rollbackFor = {Exception.class})
|
|
|
-// public void saveToXxlJob(CusFollow cusFollow) {
|
|
|
-//
|
|
|
-// Long nextId = followPlanMapper.getNextId();
|
|
|
-//
|
|
|
-//
|
|
|
-// // 约量尺 && 接受邀约
|
|
|
-//// 预约量尺,邀约结果接受,通知设计师提醒时间是(服务时间);邀约结果拒绝,通知创建者提醒时间是(提醒时间)
|
|
|
-// if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(follow.getFollowStatus()) &&
|
|
|
-// Constant.BasicDataConstant.FOLLOW_INVITE_RESULT.getValue().equals(follow.getInviteResult())) {
|
|
|
-// follow.setNextFollowTime(follow.getInviteTime()).setFollowUser(follow.getDesignUser());
|
|
|
-// }
|
|
|
-//
|
|
|
-// int id = xxlJobUtils.create(Math.toIntExact(
|
|
|
-// (follow.getNextFollowTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - System.currentTimeMillis()) / 1000
|
|
|
-// ), nextId, Constant.XxlJobInfo.FOLLOW.getValue());
|
|
|
-//
|
|
|
-//
|
|
|
-// // 生成主键
|
|
|
-// followPlanMapper.insert(
|
|
|
-// new FollowPlan().setPlanId(nextId).setCustomerId(follow.getCustomerId())
|
|
|
-// .setPlanType(Constant.IntegerConstant.PLAN_TYPE_FOLLOW.getValue())
|
|
|
-// .setFollowId(follow.getFollowId())
|
|
|
-// .setFollowUser(follow.getFollowUser())
|
|
|
-// .setNextFollowPlan(follow.getNextFollowPlan())
|
|
|
-// .setNextFollowTime(follow.getNextFollowTime())
|
|
|
-// .setXxlJobId(id)
|
|
|
-// .setCpId(follow.getCpId())
|
|
|
-// );
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * @desc : 客户跟进提醒回调
|
|
|
+ * @author : 姜永辉
|
|
|
+ * @date : 2022-06-29 14:22
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ @XxlJob("customer-reminder")
|
|
|
+ public ResponseResultVO customerReminder() {
|
|
|
+ log.info("@XxlJob(\"customer-reminder\")");
|
|
|
+ log.info("followPlan id: {}", XxlJobHelper.getJobParam());
|
|
|
+ FollowPlan followPlan = followPlanMapper.selectById(Long.valueOf(XxlJobHelper.getJobParam()));
|
|
|
+ if (followPlan != null) {
|
|
|
+ CusFollow follow = cusFollowMapper.selectById(followPlan.getFollowId());
|
|
|
+
|
|
|
+ if (follow != null) {
|
|
|
+ FollowPlan plan = new FollowPlan().setPlanId(followPlan.getPlanId());
|
|
|
+ try {
|
|
|
+ //发消息
|
|
|
+ String msg = sendFollowMessage(follow, followPlan);
|
|
|
+ if (msg == null) {
|
|
|
+ plan.setCallStatus(Constant.IntegerConstant.CALL_STATUS_DONE.getValue() + "");
|
|
|
+ } else {
|
|
|
+ plan.setCallStatus(Constant.IntegerConstant.CALL_STATUS_ERROR.getValue() + "").setRemarks(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("客户跟进发送消息异常:{}", e.getMessage());
|
|
|
+ plan.setCallStatus(Constant.IntegerConstant.CALL_STATUS_ERROR.getValue() + "").setRemarks(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改状态
|
|
|
+ followPlanMapper.updateById(plan);
|
|
|
+
|
|
|
+ //删除任务
|
|
|
+ xxlJobUtils.delete(followPlan.getXxlJobId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 客户计划任务提醒回调
|
|
|
+ * @author : jyh
|
|
|
+ * @date : 2022-06-29 14:22
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ @XxlJob("plan-reminder")
|
|
|
+ public void planReminder() {
|
|
|
+ log.info("@XxlJob(\"plan-reminder\")");
|
|
|
+ log.info("followPlan id: {}", XxlJobHelper.getJobParam());
|
|
|
+ FollowPlan followPlan = followPlanMapper.selectById(Long.valueOf(XxlJobHelper.getJobParam()));
|
|
|
+ if (followPlan != null && followPlan.getFlgValid()) {
|
|
|
+ FollowPlan plan = new FollowPlan().setPlanId(followPlan.getPlanId());
|
|
|
+ try {
|
|
|
+ //发消息
|
|
|
+ String msg = sendFollowPlanMessage(followPlan);
|
|
|
+ if (msg == null) {
|
|
|
+ plan.setCallStatus(Constant.IntegerConstant.CALL_STATUS_DONE.getValue() + "");
|
|
|
+ } else {
|
|
|
+ plan.setCallStatus(Constant.IntegerConstant.CALL_STATUS_ERROR.getValue() + "").setRemarks(msg);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("跟进任务发送消息异常:{}", e.getMessage());
|
|
|
+ plan.setCallStatus(Constant.IntegerConstant.CALL_STATUS_ERROR.getValue() + "").setRemarks(e.getMessage());
|
|
|
+ }
|
|
|
+ //修改状态
|
|
|
+ followPlanMapper.updateById(plan);
|
|
|
+ //删除任务
|
|
|
+ xxlJobUtils.delete(followPlan.getXxlJobId());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 发送跟进消息
|
|
|
+ * @author : 姜永辉
|
|
|
+ * @date : 2022-05-27 09:34
|
|
|
+ */
|
|
|
+ public String sendFollowMessage(CusFollow follow, FollowPlan followPlan) {
|
|
|
+ log.info("sendFollowMessage:{}", JSONObject.toJSONString(follow));
|
|
|
+ // 跟进人
|
|
|
+ StaffResponse followStaff = staffMapper.selectById(followPlan.getFollowUser());
|
|
|
+ //查到跟进人
|
|
|
+ if (followStaff != null) {
|
|
|
+ log.info("sendFollowMessage:{}", JSONObject.toJSONString(followStaff));
|
|
|
+ Customer customer = customerMapper.selectById(new CustomerQuery().setCusId(follow.getCusId()));
|
|
|
+
|
|
|
+ if (customer != null) {
|
|
|
+ //设计师
|
|
|
+ StaffResponse designUser = null;
|
|
|
+ if (follow.getDesignStaff() != null) {
|
|
|
+ designUser = staffMapper.selectById(follow.getDesignStaff());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加跟进ID
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(customer));
|
|
|
+ jsonObject.put("followId", follow.getFollowId());
|
|
|
+
|
|
|
+
|
|
|
+ String loginType = null;
|
|
|
+ JSONObject list = null;
|
|
|
+ //跟进followId先查询跟进数据
|
|
|
+ CusFollow e = cusFollowMapper.selectById(follow.getFollowId());
|
|
|
+ if (e != null) {
|
|
|
+ if (Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue().equals(e.getFollowStatus()) ||
|
|
|
+ Constant.BasicDataConstant.FOLLOW_STATUS_5.getValue().equals(e.getFollowStatus())) {
|
|
|
+
|
|
|
+ JSONObject followJs = JSONObject.parseObject(JSONObject.toJSONString(e));
|
|
|
+ followJs.put("customerName", jsonObject.get("customerName"));
|
|
|
+ followJs.put("customerPhone", jsonObject.get("customerPhone"));
|
|
|
+ followJs.put("addressFull", jsonObject.get("addressFull"));
|
|
|
+
|
|
|
+ list = followJs;
|
|
|
+ loginType = "8";
|
|
|
+
|
|
|
+ } else if (Constant.BasicDataConstant.FOLLOW_STATUS_1.getValue().equals(e.getFollowStatus()) ||
|
|
|
+ Constant.BasicDataConstant.FOLLOW_STATUS_2.getValue().equals(e.getFollowStatus()) ||
|
|
|
+ Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(e.getFollowStatus())) {
|
|
|
+
|
|
|
+ list = jsonObject;
|
|
|
+ loginType = "1";
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ log.error("客户查询异常:为空{}", follow.getCusId());
|
|
|
+ return ResponseCodeEnum.SELECT_NULL.getMessage();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("跟进人异常:为空{}", followPlan.getFollowUser());
|
|
|
+ return ResponseCodeEnum.SELECT_NULL.getMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 发送跟进任务消息
|
|
|
+ * @author : 姜永辉
|
|
|
+ * @date : 2022-06-30 19:24
|
|
|
+ */
|
|
|
+ public String sendFollowPlanMessage(FollowPlan followPlan) {
|
|
|
+ log.info("sendFollowMessage:{}", JSONObject.toJSONString(followPlan));
|
|
|
+ // 跟进人
|
|
|
+ StaffResponse followStaff = staffMapper.selectById(followPlan.getFollowUser());
|
|
|
+
|
|
|
+ Customer customer = customerMapper.selectById(new CustomerQuery().setCusId(followPlan.getCusId()));
|
|
|
+
|
|
|
+ if (customer != null) {
|
|
|
+ // 小程序消息
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return ResponseCodeEnum.SELECT_NULL.getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 保存跟进信息到xxl job
|
|
|
+ * @author : 于继渤海
|
|
|
+ * @date : 2022-05-27 09:53
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public void saveToXxlJob(CusFollow cusFollow) {
|
|
|
+ //设置ID
|
|
|
+ Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.FOLLOWPLAN.getName(), true);
|
|
|
+ String nextId = uniqueNoteCode.get("outId").toString();
|
|
|
+ cusFollow.setFollowId(nextId);
|
|
|
+
|
|
|
+ // 约量尺 && 接受邀约
|
|
|
+// 预约量尺,邀约结果接受,通知设计师提醒时间是(服务时间);邀约结果拒绝,通知创建者提醒时间是(提醒时间)
|
|
|
+ if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(cusFollow.getFollowStatus()) &&
|
|
|
+ Constant.BasicDataConstant.FOLLOW_INVITE_RESULT.getValue().equals(cusFollow.getInviteResult())) {
|
|
|
+ cusFollow.setNextFollowTime(cusFollow.getInviteTime()).setFollowStaff(cusFollow.getDesignStaff());
|
|
|
+ }
|
|
|
+
|
|
|
+ int id = xxlJobUtils.create(Math.toIntExact(
|
|
|
+ (cusFollow.getNextFollowTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - System.currentTimeMillis()) / 1000
|
|
|
+ ), nextId, Constant.XxlJobInfo.FOLLOW.getValue());
|
|
|
+ // 生成主键
|
|
|
+ followPlanMapper.insert(
|
|
|
+ new FollowPlan().setPlanId(nextId).setCusId(cusFollow.getCusId())
|
|
|
+ .setPlanType(Constant.IntegerConstant.PLAN_TYPE_FOLLOW.getValue())
|
|
|
+ .setFollowId(cusFollow.getFollowId())
|
|
|
+ .setFollowUser(cusFollow.getFollowStaff())
|
|
|
+ .setNextFollowPlan(cusFollow.getNextFollowPlan())
|
|
|
+ .setNextFollowTime(cusFollow.getNextFollowTime())
|
|
|
+ .setXxlJobId(id)
|
|
|
+ .setCpId(cusFollow.getCpId())
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @desc : 新建量尺回执
|
|
|
@@ -422,8 +581,6 @@ public class CusFollowService extends BaseService<CusFollow> {
|
|
|
cusFollow.setMeasureStatus(Constant.BasicDataConstant.MEASURE_STATUS_1.getValue());
|
|
|
//修改跟进
|
|
|
super.updateByUuid(cusFollow);
|
|
|
-
|
|
|
-
|
|
|
return ResponseResultUtil.success();
|
|
|
}
|
|
|
|
|
|
@@ -494,7 +651,7 @@ public class CusFollowService extends BaseService<CusFollow> {
|
|
|
customerService.updateByUuid(customer);
|
|
|
} else {
|
|
|
//不是陌生接待
|
|
|
- if(!cusFollowVO.getFollowStatus().equals(Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue())){
|
|
|
+ if (!cusFollowVO.getFollowStatus().equals(Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue())) {
|
|
|
StaffEntity staff = authUtils.getStaff();
|
|
|
Customer customer = new Customer();
|
|
|
customer.setCusName(cusFollowVO.getCusName());
|