Commit 169aa510 authored by liucx's avatar liucx

沟通记录统计 --差运行时间优化

parent 08e8341c
package com.zfxftech.telmarket.common.pojo.dao.followAccount;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "communication_record_statistical_log")
public class CommunicationRecordStatisticalLog {
/**
* 唯一标记
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 产品类型 1私人订制,2跟投账户,3资管,4智能跟投
*/
@TableField(value = "productType")
private Integer productType;
/**
* 产品id
*/
@TableField(value = "productId")
private Long productId;
/**
* 客户id
*/
@TableField(value = "customerId")
private Long customerId;
/**
* 日统计次数
*/
@TableField(value = "dayConut")
private Integer dayConut;
/**
* 周统计次数
*/
@TableField(value = "weekConut")
private Integer weekConut;
/**
* 月沟通次数
*/
@TableField(value = "monthConut")
private Integer monthConut;
/**
* 总沟通次数
*/
@TableField(value = "totalConut")
private Integer totalConut;
}
\ No newline at end of file
package com.zfxftech.telmarket.common.pojo.dao.followAccount;
import lombok.Data;
@Data
public class CustomerCommunicationRecordTask {
private Integer count;
private Long productId;
private Long customerId;
private Integer productType;
}
\ No newline at end of file
package com.zfxftech.telmarket.mapper.followAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.CommunicationRecordStatisticalLog;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface CommunicationRecordStatisticalLogMapper extends BaseMapper<CommunicationRecordStatisticalLog> {
int deleteByPrimaryKey(Integer id);
int insertSelective(CommunicationRecordStatisticalLog record);
CommunicationRecordStatisticalLog selectByPrimaryKey(Integer id);
List<CommunicationRecordStatisticalLog> selectAll();
int updateByPrimaryKeySelective(CommunicationRecordStatisticalLog record);
CommunicationRecordStatisticalLog selectDistinct(@Param("customerId") long longValue, @Param("productId") long longValue1, @Param("productType") Integer productType);
}
\ No newline at end of file
......@@ -2,11 +2,12 @@ package com.zfxftech.telmarket.mapper.followAccount;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.CustomerCommunicationRecord;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.CustomerCommunicationRecordExample;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.CustomerCommunicationRecordTask;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
public interface CustomerCommunicationRecordMapper {
long countByExample(CustomerCommunicationRecordExample example);
......@@ -23,6 +24,8 @@ public interface CustomerCommunicationRecordMapper {
List<CustomerCommunicationRecord> selectList(Map<String, Object> pram);
List<CustomerCommunicationRecordTask> selectListTask(Map<String, Object> pram);
CustomerCommunicationRecord selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") CustomerCommunicationRecord record, @Param("example") CustomerCommunicationRecordExample example);
......
package com.zfxftech.telmarket.service.followAccount;
/**
* 沟通记录统计
*/
public interface CommunicationRecordStatisticalLogService {
/**
* 更新日数据
*/
void saveOrUpdateDay();
/**
* 更新总数据
*/
void totalommunication();
/**
* 更新月数据
*/
void saveOrUpdateMonth();
/**
* 更新周数据
*/
void saveOrUpdateWeek();
}
package com.zfxftech.telmarket.service.followAccount;
import com.zfxftech.telmarket.common.bean.CommonPage;
import com.zfxftech.telmarket.common.excepitonHandler.followAccount.FollowAccountRiskException;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.FollowAccount;
import com.zfxftech.telmarket.common.pojo.dto.followAccount.FollowAccountStockInputQueryDto;
import com.zfxftech.telmarket.common.pojo.request.followAccount.*;
import com.zfxftech.telmarket.common.pojo.vo.followAccount.*;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.CustomerCommunicationRecordTask;
import com.zfxftech.telmarket.common.pojo.request.followAccount.CustomerCommunicationRecordIdReq;
import com.zfxftech.telmarket.common.pojo.request.followAccount.CustomerCommunicationRecordQueryReq;
import com.zfxftech.telmarket.common.pojo.request.followAccount.CustomerCommunicationRecordReq;
import com.zfxftech.telmarket.common.pojo.vo.followAccount.CustomerCommunicationRecordQueryVo;
import java.util.Date;
import java.util.List;
/**
......@@ -19,6 +20,8 @@ public interface CustomerCommunicationRecordService {
CommonPage<CustomerCommunicationRecordQueryVo> queryCustomerCommunicationRecord(CustomerCommunicationRecordQueryReq req);
List<CustomerCommunicationRecordTask> queryCustomerCommunicationRecordTask(Date startTime , Date endTime);
CommonPage<CustomerCommunicationRecordQueryVo> queryCustomerCommunicationRecordByCustomerId(CustomerCommunicationRecordIdReq req);
}
package com.zfxftech.telmarket.service.followAccount.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.CommunicationRecordStatisticalLog;
import com.zfxftech.telmarket.common.pojo.dao.followAccount.CustomerCommunicationRecordTask;
import com.zfxftech.telmarket.common.util.DateUtil;
import com.zfxftech.telmarket.mapper.followAccount.CommunicationRecordStatisticalLogMapper;
import com.zfxftech.telmarket.service.followAccount.CommunicationRecordStatisticalLogService;
import com.zfxftech.telmarket.service.followAccount.CustomerCommunicationRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* Create time: 2022/1/24
*/
@Slf4j
@Service
public class CommunicationRecordStatisticalLogServiceImpl extends ServiceImpl<CommunicationRecordStatisticalLogMapper, CommunicationRecordStatisticalLog> implements CommunicationRecordStatisticalLogService {
@Resource
private CustomerCommunicationRecordService customerCommunicationRecordService;
@Override
public void saveOrUpdateDay() {
Date startTime = DateUtil.getToDayAndStartTime();
Date endTime = DateUtil.getToDayAndEndTime();
List<CustomerCommunicationRecordTask> list = customerCommunicationRecordService.queryCustomerCommunicationRecordTask(startTime, endTime);
if(ObjectUtils.isEmpty(list)){
return;
}
this.updateAndSave(list,"day");
}
private void updateAndSave( List<CustomerCommunicationRecordTask> list,String type){
for (CustomerCommunicationRecordTask customerCommunicationRecordTask : list) {
CommunicationRecordStatisticalLog distinct = getBaseMapper().selectDistinct(customerCommunicationRecordTask.getCustomerId().longValue(), customerCommunicationRecordTask.getProductId().longValue(), customerCommunicationRecordTask.getProductType());
if (ObjectUtils.isEmpty(distinct)) {
CommunicationRecordStatisticalLog communicationRecordStatisticalLog = new CommunicationRecordStatisticalLog();
communicationRecordStatisticalLog.setCustomerId(customerCommunicationRecordTask.getCustomerId().longValue());
communicationRecordStatisticalLog.setProductType(customerCommunicationRecordTask.getProductType());
communicationRecordStatisticalLog.setProductId(customerCommunicationRecordTask.getProductId().longValue());
distinct.setDayConut(customerCommunicationRecordTask.getCount());
saveOrUpdate(communicationRecordStatisticalLog);
}else {
if(type.equals("day")){
distinct.setDayConut(customerCommunicationRecordTask.getCount());
}
if(type.equals("week")){
distinct.setWeekConut(customerCommunicationRecordTask.getCount());
}
if(type.equals("month")){
distinct.setMonthConut(customerCommunicationRecordTask.getCount());
}
updateById(distinct);
}
}
}
@Override
public void totalommunication() {
//同步数据
List<CustomerCommunicationRecordTask> recordList = customerCommunicationRecordService.queryCustomerCommunicationRecordTask(null, null);
if (ObjectUtils.isEmpty(recordList)) {
return;
}
for (CustomerCommunicationRecordTask customerCommunicationRecord : recordList) {
CommunicationRecordStatisticalLog distinct = getBaseMapper().selectDistinct(customerCommunicationRecord.getCustomerId().longValue(), customerCommunicationRecord.getProductId().longValue(), customerCommunicationRecord.getProductType());
if (ObjectUtils.isEmpty(distinct)) {
CommunicationRecordStatisticalLog communicationRecordStatisticalLog = new CommunicationRecordStatisticalLog();
communicationRecordStatisticalLog.setCustomerId(customerCommunicationRecord.getCustomerId().longValue());
communicationRecordStatisticalLog.setProductType(customerCommunicationRecord.getProductType());
communicationRecordStatisticalLog.setProductId(customerCommunicationRecord.getProductId().longValue());
communicationRecordStatisticalLog.setTotalConut(customerCommunicationRecord.getCount());
saveOrUpdate(communicationRecordStatisticalLog);
}else {
distinct.setTotalConut(customerCommunicationRecord.getCount());
updateById(distinct);
}
}
}
@Override
public void saveOrUpdateMonth() {
Date startTime = DateUtil.getFirstDayOfMonthDate();
Date str= DateUtil.dateStrToDate( DateUtil.dateToStr(startTime,"yyyy-MM-dd 00:00:00"),"yyyy-MM-dd 00:00:00");
List<CustomerCommunicationRecordTask> list = customerCommunicationRecordService.queryCustomerCommunicationRecordTask(str, new Date());
if(ObjectUtils.isEmpty(list)){
return;
}
this.updateAndSave(list,"month");
}
@Override
public void saveOrUpdateWeek() {
Date startTime = DateUtil.getThisWeekMonday(new Date());
Date str= DateUtil.dateStrToDate( DateUtil.dateToStr(startTime,"yyyy-MM-dd 00:00:00"),"yyyy-MM-dd 00:00:00");
List<CustomerCommunicationRecordTask> list = customerCommunicationRecordService.queryCustomerCommunicationRecordTask(startTime, new Date());
if(ObjectUtils.isEmpty(list)){
return;
}
this.updateAndSave(list,"week");
}
}
package com.zfxftech.telmarket.task.communication;
import com.zfxftech.telmarket.common.bean.CommonResult;
import com.zfxftech.telmarket.service.followAccount.CommunicationRecordStatisticalLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Description TODO
* @Author Dell
* @Date 2021/11/30 13:16
*/
@Api(value = "定时任务相关接口", tags = {"定时任务相关接口"})
@RestController
@RequestMapping("/admin/timedTask/")
public class TimedTaskController {
private static Logger logger = LoggerFactory.getLogger(TimedTaskController.class);
@Autowired
private CommunicationRecordStatisticalLogService communicationRecordStatisticalLogService;
@ApiOperation(value = "日统计沟通记录次数", notes = "日统计沟通记录次数 ", httpMethod = "GET")
@GetMapping("/dayCommunication")
@Scheduled(cron = "0 0/1 * * * ?")
public CommonResult dayCommunicationCount() {
communicationRecordStatisticalLogService.saveOrUpdateDay();
return CommonResult.success("日统计沟通记录次数成功");
}
@ApiOperation(value = "周统计沟通记录次数", notes = "周统计沟通记录次数 ", httpMethod = "GET")
@GetMapping("/weekCommunication")
@Scheduled(cron = "0 0/1 * * * ?")
public CommonResult weekCommunicationCount() {
communicationRecordStatisticalLogService.saveOrUpdateWeek();
return CommonResult.success("日统计沟通记录次数成功");
}
@ApiOperation(value = "月统计沟通记录次数", notes = "月统计沟通记录次数 ", httpMethod = "GET")
@GetMapping("/mothCommunication")
@Scheduled(cron = "0 0/1 * * * ?")
public CommonResult monthCommunicationCount() {
communicationRecordStatisticalLogService.saveOrUpdateMonth();
return CommonResult.success("日统计沟通记录次数成功");
}
@ApiOperation(value = "总数据统计", notes = "总数据统计 ", httpMethod = "GET")
@Scheduled(cron = "0 0/1 * * * ?")
public CommonResult totalommunication() {
communicationRecordStatisticalLogService.totalommunication();
return CommonResult.success("日统计沟通记录次数成功");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zfxftech.telmarket.mapper.followAccount.CommunicationRecordStatisticalLogMapper">
<resultMap id="BaseResultMap" type="com.zfxftech.telmarket.common.pojo.dao.followAccount.CommunicationRecordStatisticalLog">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="productType" jdbcType="BIGINT" property="productType" />
<result column="productId" jdbcType="BIGINT" property="productId" />
<result column="customerId" jdbcType="BIGINT" property="customerId" />
<result column="dayConut" jdbcType="INTEGER" property="dayConut" />
<result column="weekConut" jdbcType="INTEGER" property="weekConut" />
<result column="monthConut" jdbcType="INTEGER" property="monthConut" />
<result column="totalConut" jdbcType="INTEGER" property="totalConut" />
</resultMap>
<sql id="Base_Column_List">
id, productType, productId, customerId, dayConut, weekConut, monthConut, totalConut
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from communication_record_statistical_log
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectDistinct" resultType="com.zfxftech.telmarket.common.pojo.dao.followAccount.CommunicationRecordStatisticalLog">
select
<include refid="Base_Column_List" />
from communication_record_statistical_log
where productType = #{productType} and productId = #{productId} and customerId = #{customerId} limit 1
</select>
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from communication_record_statistical_log
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from communication_record_statistical_log
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insertSelective" parameterType="com.zfxftech.telmarket.common.pojo.dao.followAccount.CommunicationRecordStatisticalLog">
insert into communication_record_statistical_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="productType != null">
productType,
</if>
<if test="productId != null">
productId,
</if>
<if test="customerId != null">
customerId,
</if>
<if test="dayConut != null">
dayConut,
</if>
<if test="weekConut != null">
weekConut,
</if>
<if test="monthConut != null">
monthConut,
</if>
<if test="totalConut != null">
totalConut,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="productType != null">
#{productType,jdbcType=INTEGER},
</if>
<if test="productId != null">
#{productId,jdbcType=BIGINT},
</if>
<if test="customerId != null">
#{customerId,jdbcType=BIGINT},
</if>
<if test="dayConut != null">
#{dayConut,jdbcType=INTEGER},
</if>
<if test="weekConut != null">
#{weekConut,jdbcType=INTEGER},
</if>
<if test="monthConut != null">
#{monthConut,jdbcType=INTEGER},
</if>
<if test="totalConut != null">
#{totalConut,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.zfxftech.telmarket.common.pojo.dao.followAccount.CommunicationRecordStatisticalLog">
update communication_record_statistical_log
<set>
<if test="productType != null">
productType = #{productType,jdbcType=INTEGER},
</if>
<if test="productId != null">
productId = #{productId,jdbcType=BIGINT},
</if>
<if test="customerId != null">
customerId = #{customerId,jdbcType=BIGINT},
</if>
<if test="dayConut != null">
dayConut = #{dayConut,jdbcType=INTEGER},
</if>
<if test="weekConut != null">
weekConut = #{weekConut,jdbcType=INTEGER},
</if>
<if test="monthConut != null">
monthConut = #{monthConut,jdbcType=INTEGER},
</if>
<if test="totalConut != null">
totalConut = #{totalConut,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
......@@ -418,4 +418,72 @@
</where>
order by c.CREATED_TIME desc
</select>
<select id="selectListTask" resultType="com.zfxftech.telmarket.common.pojo.dao.followAccount.CustomerCommunicationRecordTask" parameterType="java.util.Map">
select c.productId as productId ,c.productType as productType,c.customerId as customerId, count(id) as count from (
select cr.*,
p.analyst
from customer_communication_record as cr
left join product as p on cr.productId = p.id
where cr.productType = 1
union
select cr.*,
p.analyst
from customer_communication_record as cr
left join followaccount as p on cr.productId = p.id
where cr.productType = 2
union
select cr.*,
p.analyst
from customer_communication_record as cr
left join smart_product as p on cr.productId = p.id
where cr.productType = 4
union
select cr.*,
p.analyst
from customer_communication_record as cr
left join asset_product as p on cr.productId = p.id
where cr.productType = 3
) as c
<where>
<if test="companyId != null">
AND c.company_id = #{companyId}
</if>
<if test="analyst != null">
AND c.analyst = #{analyst}
</if>
<if test="productType != null">
AND c.productType = #{productType}
</if>
<if test="productId != null">
AND c.productId = #{productId}
</if>
<if test="customerName != null">
AND c.customerName like "%"#{customerName}"%"
</if>
<if test="adminUserName != null">
AND c.adminUserName like "%"#{adminUserName}"%"
</if>
<if test="productName != null">
AND c.productName like "%"#{productName}"%"
</if>
<if test="customerId != null">
AND c.customerId = #{customerId}
</if>
<if test="createUserId != null">
AND c.CREATED_BY = #{createUserId}
</if>
<if test="recordTimeStart != null">
AND c.recordTime <![CDATA[>=]]> #{recordTimeStart}
</if>
<if test="recordTimeEnd != null">
AND c.recordTime <![CDATA[<=]]> #{recordTimeEnd}
</if>
<if test="comments != null and comments!=''">
AND c.comments like "%"#{comments}"%"
</if>
</where>
GROUP BY c.productId,c.productType,c.customerId
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment