Commit dda0a5ff by zhouhaibao

[+]质检查询逻辑优化

1 parent 6b4d2bb5
...@@ -62,4 +62,8 @@ public class CustomerOrderTemp { ...@@ -62,4 +62,8 @@ public class CustomerOrderTemp {
@Column(name = "order_transaction_amount") @Column(name = "order_transaction_amount")
private BigDecimal orderTransactionAmount; // 推荐使用 BigDecimal 处理金额 private BigDecimal orderTransactionAmount; // 推荐使用 BigDecimal 处理金额
@Column(name = "is_anxin_package")
private Integer isAnxinPackage;
} }
\ No newline at end of file \ No newline at end of file
...@@ -82,30 +82,17 @@ public class ConversationBatchService { ...@@ -82,30 +82,17 @@ public class ConversationBatchService {
RpcPagination<ConversationBatchRequestDTO> req) { RpcPagination<ConversationBatchRequestDTO> req) {
PageHelper.startPage(req.getPageNum(), req.getPageSize()); PageHelper.startPage(req.getPageNum(), req.getPageSize());
Page<ConversationBatchDTO> res = conversationBatchMapper.page(req.getCondition()); Page<ConversationBatchDTO> res = conversationBatchMapper.page(req.getCondition());
List<String> phones=conversationBatchMapper.findAllFinishPhone("安心");
//成交订单手机号
List<String> allPhones=conversationBatchMapper.findAllOrderPhone();
if(CollectionUtils.isNotEmpty(res)){ if(CollectionUtils.isNotEmpty(res)){
List<Integer> collected = res.stream().map(ConversationBatchDTO::getMerchantId) List<Integer> collected = res.stream().filter(index->index.getMerchantId()!=null).map(ConversationBatchDTO::getMerchantId)
.collect(Collectors.toList()); .collect(Collectors.toList());
if(CollectionUtils.isEmpty(collected)) {
return res;
}
ListMerchantRequest listMerchantRequest = new ListMerchantRequest(); ListMerchantRequest listMerchantRequest = new ListMerchantRequest();
String merchantNos = org.apache.commons.lang3.StringUtils.join(collected, ","); String merchantNos = org.apache.commons.lang3.StringUtils.join(collected, ",");
listMerchantRequest.setMerchantNoStrSet(merchantNos); listMerchantRequest.setMerchantNoStrSet(merchantNos);
List<MerchantRopResponse> merchantListByCondition = merchantService.findMerchantListByCondition( List<MerchantRopResponse> merchantListByCondition = merchantService.findMerchantListByCondition(
listMerchantRequest); listMerchantRequest);
for (ConversationBatchDTO extBatchById : res) {
if(CollectionUtils.isNotEmpty(phones)){
String phoneNumber = extBatchById.getPhoneNumber();
if(phones.contains(phoneNumber)){
extBatchById.setFinishFlag(true);
}
}
if(CollectionUtils.isNotEmpty(allPhones)){
String phoneNumber = extBatchById.getPhoneNumber();
if(allPhones.contains(phoneNumber)){
extBatchById.setOrderFinishFlag(true);
}
}
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(merchantListByCondition)) { if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(merchantListByCondition)) {
for (ConversationBatchDTO merchantDTO : res) { for (ConversationBatchDTO merchantDTO : res) {
List<MerchantRopResponse> merchantRopResponses = merchantListByCondition.stream() List<MerchantRopResponse> merchantRopResponses = merchantListByCondition.stream()
...@@ -117,7 +104,6 @@ public class ConversationBatchService { ...@@ -117,7 +104,6 @@ public class ConversationBatchService {
} }
} }
} }
}
return res; return res;
} }
...@@ -323,7 +309,7 @@ public class ConversationBatchService { ...@@ -323,7 +309,7 @@ public class ConversationBatchService {
*/ */
public List<ConversationBatchDTO> findExtBatchByIds(List<Integer> collect) { public List<ConversationBatchDTO> findExtBatchByIds(List<Integer> collect) {
List<ConversationBatchDTO> extBatchByIds = conversationBatchMapper.findExtBatchByIds(collect); List<ConversationBatchDTO> extBatchByIds = conversationBatchMapper.findExtBatchByIds(collect);
// 安心包成交订单手机号 /* // 安心包成交订单手机号
List<String> axPhones=conversationBatchMapper.findAllFinishPhone("安心"); List<String> axPhones=conversationBatchMapper.findAllFinishPhone("安心");
//成交订单手机号 //成交订单手机号
...@@ -342,7 +328,7 @@ public class ConversationBatchService { ...@@ -342,7 +328,7 @@ public class ConversationBatchService {
} }
} }
} }
} }*/
return extBatchByIds; return extBatchByIds;
} }
......
...@@ -5,8 +5,10 @@ import cn.com.glsx.dj.mindworkplate.model.CustomerOrderTemp; ...@@ -5,8 +5,10 @@ import cn.com.glsx.dj.mindworkplate.model.CustomerOrderTemp;
import cn.com.glsx.dj.smartcarlife.dto.GoodsOrderDTO; import cn.com.glsx.dj.smartcarlife.dto.GoodsOrderDTO;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable; import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
...@@ -55,6 +57,14 @@ public class CustomerOrderTempService { ...@@ -55,6 +57,14 @@ public class CustomerOrderTempService {
CustomerOrderTemp customerOrderTemp=customerOrderTempMapper.searchByOrderCode(orderCode); CustomerOrderTemp customerOrderTemp=customerOrderTempMapper.searchByOrderCode(orderCode);
if(customerOrderTemp!=null){ if(customerOrderTemp!=null){
log.info("订单详情{}", JSONObject.toJSONString(customerOrderTemp)); log.info("订单详情{}", JSONObject.toJSONString(customerOrderTemp));
boolean isAnxin = Arrays.asList(
customerOrderTemp.getUpgradeGoodsName(),
customerOrderTemp.getUpgradeGoodsAlias(),
customerOrderTemp.getPackageName()
).stream()
.filter(Objects::nonNull) // 先过滤 null
.anyMatch(s -> s.contains("安心"));
customerOrderTemp.setIsAnxinPackage(isAnxin ? 1 : 0);
if(newcustomerOrderTemp==null){ if(newcustomerOrderTemp==null){
customerOrderTempMapper.insert(customerOrderTemp); customerOrderTempMapper.insert(customerOrderTemp);
customerOrderTemp.setUpdateTime(new Date()); customerOrderTemp.setUpdateTime(new Date());
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
<result column="defence_result_flag" property="defence" jdbcType="INTEGER"/> <result column="defence_result_flag" property="defence" jdbcType="INTEGER"/>
<result column="axbOpenFlag" property="axbOpenFlag" jdbcType="BOOLEAN"/> <result column="axbOpenFlag" property="axbOpenFlag" jdbcType="BOOLEAN"/>
<result column="isOrderFinishFlag" property="orderFinishFlag" jdbcType="BOOLEAN"/> <result column="isOrderFinishFlag" property="orderFinishFlag" jdbcType="BOOLEAN"/>
<result column="isFinishFlag" property="finishFlag" jdbcType="BOOLEAN"/>
<result column="employeeName" property="employeeName" jdbcType="VARCHAR"/> <result column="employeeName" property="employeeName" jdbcType="VARCHAR"/>
<result column="merchant_id" property="merchantId" jdbcType="INTEGER"/> <result column="merchant_id" property="merchantId" jdbcType="INTEGER"/>
<result column="reception_start_time" property="receptionStartTime" jdbcType="TIMESTAMP"/> <result column="reception_start_time" property="receptionStartTime" jdbcType="TIMESTAMP"/>
...@@ -68,13 +69,24 @@ ...@@ -68,13 +69,24 @@
parameterType="cn.com.glsx.dj.mindworkplate.dto.ConversationBatchRequestDTO" parameterType="cn.com.glsx.dj.mindworkplate.dto.ConversationBatchRequestDTO"
resultMap="DTOResultMap"> resultMap="DTOResultMap">
select cb.*,re.customer_name,re.phone_number,re.car_brand,re.car_model,re.reception_status,re.bussiness_type,ind.customer_type,ind.avg_defence as def_score, select cb.*,re.customer_name,re.phone_number,re.car_brand,re.car_model,re.reception_status,re.bussiness_type,ind.customer_type,ind.avg_defence as def_score,
ibr.defence_result_flag, ibr.defence_task_id,if(t3.Is_mentioned=1,true,false) as axbOpenFlag, re.merchant_id, re.reception_start_time,ibr.check_history_flag as checkHistoryFlag ibr.defence_result_flag, ibr.defence_task_id,if(t3.Is_mentioned=1,true,false) as axbOpenFlag, re.merchant_id, re.reception_start_time,ibr.check_history_flag as checkHistoryFlag,
COALESCE(orders.has_anxin, 0) AS isFinishFlag, -- 安心包是否成交 → isFinishFlag
COALESCE(orders.has_completed, 0) AS isOrderFinishFlag -- 订单是否成交 → isOrderFinishFlag
from from
inspection_conversation_batch cb inspection_conversation_batch cb
left join reception_customer_info re on cb.task_id = re.id left join reception_customer_info re on cb.task_id = re.id
left join inspection_defence ind on ind.batch_id = cb.id and ind.deleted_flag = 'N' left join inspection_defence ind on ind.batch_id = cb.id and ind.deleted_flag = 'N'
left join inspection_badge_recordings ibr on ibr.id = cb.record_id and ibr.deleted_flag = 'N' left join inspection_badge_recordings ibr on ibr.id = cb.record_id and ibr.deleted_flag = 'N'
left join recording_batch_model_call_axb t3 on cb.id=t3.batch_id left join recording_batch_model_call_axb t3 on cb.id=t3.batch_id
LEFT JOIN (
SELECT
phone,
1 AS has_completed, -- 因为 WHERE 已限定 order_status IN (4,6)
MAX(is_anxin_package) AS has_anxin
FROM dj_smartcarlife.customer_order_temp
WHERE order_status IN (4, 6)
GROUP BY phone
) orders ON re.phone_number = orders.phone
<where> <where>
cb.deleted_flag = 'N' cb.deleted_flag = 'N'
<if test="id != null"> <if test="id != null">
...@@ -214,11 +226,23 @@ ...@@ -214,11 +226,23 @@
<select id="findExtBatchByIds" <select id="findExtBatchByIds"
resultType="cn.com.glsx.dj.mindworkplate.dto.ConversationBatchDTO"> resultType="cn.com.glsx.dj.mindworkplate.dto.ConversationBatchDTO">
select t1.conversation_id as conversationId,t2.customer_name as customerName,t2.phone_number as phoneNumber,t2.reception_status,t1.start_time,t1.file_url,t1.duration, select t1.conversation_id as conversationId,t2.customer_name as customerName,t2.phone_number as phoneNumber,t2.reception_status,t1.start_time,t1.file_url,t1.duration,
if(t3.Is_mentioned=1,true,false) as axbOpenFlag,if(t4.Is_mentioned=1,true,false) as dtcOpenFlag if(t3.Is_mentioned=1,true,false) as axbOpenFlag,if(t4.Is_mentioned=1,true,false) as dtcOpenFlag,
-- 👇 关键:按你的 Java 字段命名
COALESCE(orders.has_anxin, 0) AS isFinishFlag, -- 安心包是否成交 → isFinishFlag
COALESCE(orders.has_completed, 0) AS isOrderFinishFlag -- 订单是否成交 → isOrderFinishFlag
from inspection_conversation_batch t1 from inspection_conversation_batch t1
left join reception_customer_info t2 on t1.task_id = t2.id left join reception_customer_info t2 on t1.task_id = t2.id
left join recording_batch_model_call_axb t3 on t1.id=t3.batch_id left join recording_batch_model_call_axb t3 on t1.id=t3.batch_id
left join recording_batch_model_call_dtc t4 on t1.id=t4.batch_id left join recording_batch_model_call_dtc t4 on t1.id=t4.batch_id
LEFT JOIN (
SELECT
phone,
1 AS has_completed, -- 因为 WHERE 已限定 order_status IN (4,6)
MAX(is_anxin_package) AS has_anxin -- 👈 关键:取最大值(0/1),只要有一个1就是1
FROM dj_smartcarlife.customer_order_temp
WHERE order_status IN (4, 6) and scene_type=0
GROUP BY phone
) orders ON t2.phone_number = orders.phone
<where> <where>
<if test="ids != null and ids.size>0"> <if test="ids != null and ids.size>0">
t1.conversation_id in t1.conversation_id in
......
...@@ -386,57 +386,36 @@ ...@@ -386,57 +386,36 @@
<select id="findPhoneListByRecMerchantNo" resultType="cn.com.glsx.dj.mindworkplate.dto.EmployeeSearch"> <select id="findPhoneListByRecMerchantNo" resultType="cn.com.glsx.dj.mindworkplate.dto.EmployeeSearch">
select distinct t2.badge_id as badgeId,date_format(t2.recording_start_time,'%Y-%m-%d') as audioTime from reception_customer_info t1 select distinct t2.badge_id as badgeId,date_format(t2.recording_start_time,'%Y-%m-%d') as audioTime from reception_customer_info t1
left join inspection_badge_recordings t2 on t1.id=t2.reception_id left join inspection_badge_recordings t2 on t1.id=t2.reception_id
where 1=1
<!-- 条件1:安心包是否成交(is_anxin_package = 1) -->
<if test="condition.orderAxbTransactionFlag != null"> <if test="condition.orderAxbTransactionFlag != null">
left join (select AND EXISTS (
distinct dclgoc.customer_phone SELECT 1
from dj_car_life_goods_order dclgo FROM dj_smartcarlife.customer_order_temp cot
left join dj_car_life_goods_sub_order dclgso WHERE cot.phone = t1.phone_number
on dclgo.order_code = dclgso.order_code and dclgso.deleted_flag = 'N' AND cot.scene_type = #{bussinessType}
left join dj_car_life_goods_order_customer dclgoc AND cot.order_status IN (4, 6)
on dclgoc.order_code = dclgo.order_code and dclgoc.deleted_flag = 'N' AND cot.is_anxin_package = 1
left join dj_car_life_pay_order dclpo on dclpo.order_code = dclgo.order_code and dclpo.deleted_flag = 'N' <if test="condition.orderTransactionAmount != null">
where dclgo.deleted_flag = 'N' and dclgo.scene_type = #{bussinessType} AND cot.order_transaction_amount > #{condition.orderTransactionAmount}
and dclgo.status in (4, 6) and upgrade_flag = 'Y' and (upgrade_goods_name like concat('%', '安心包','%')
or upgrade_goods_alias like concat('%', '安心','%')
or package_name like concat('%', '安心','%') )
<if test="condition.orderTransactionAmount != null ">
and dclgo.total_price> #{condition.orderTransactionAmount}
</if> </if>
) t3 on t3.customer_phone = t1.phone_number )
</if> </if>
<!-- 条件2:是否有成交订单(不关心是否安心包) -->
<if test="condition.orderTransactionFlag != null"> <if test="condition.orderTransactionFlag != null">
left join (select AND EXISTS (
distinct dclgoc.customer_phone SELECT 1
from dj_car_life_goods_order dclgo FROM dj_smartcarlife.customer_order_temp cot
left join dj_car_life_goods_sub_order dclgso WHERE cot.phone = t1.phone_number
on dclgo.order_code = dclgso.order_code and dclgso.deleted_flag = 'N' AND cot.scene_type = #{bussinessType}
left join dj_car_life_goods_order_customer dclgoc AND cot.order_status IN (4, 6)
on dclgoc.order_code = dclgo.order_code and dclgoc.deleted_flag = 'N'
left join dj_car_life_pay_order dclpo on dclpo.order_code = dclgo.order_code and dclpo.deleted_flag = 'N'
where dclgo.deleted_flag = 'N' and dclgo.scene_type= #{bussinessType}
and dclgo.status in (4, 6) and upgrade_flag = 'Y'
<if test="condition.orderTransactionAmount != null ">
and dclgo.total_price> #{condition.orderTransactionAmount}
</if>
) t4 on t4.customer_phone = t1.phone_number
</if>
<if test="condition.orderTransactionAmount != null"> <if test="condition.orderTransactionAmount != null">
left join (select AND cot.order_transaction_amount > #{condition.orderTransactionAmount}
distinct dclgoc.customer_phone
from dj_car_life_goods_order dclgo
left join dj_car_life_goods_sub_order dclgso
on dclgo.order_code = dclgso.order_code and dclgso.deleted_flag = 'N'
left join dj_car_life_goods_order_customer dclgoc
on dclgoc.order_code = dclgo.order_code and dclgoc.deleted_flag = 'N'
left join dj_car_life_pay_order dclpo on dclpo.order_code = dclgo.order_code and dclpo.deleted_flag = 'N'
where dclgo.deleted_flag = 'N' and dclgo.scene_type = #{bussinessType}
and dclgo.status in (4, 6) and upgrade_flag = 'Y'
<if test="condition.orderTransactionAmount != null ">
and dclgo.total_price> #{condition.orderTransactionAmount}
</if> </if>
) t5 on t5.customer_phone = t1.phone_number )
</if> </if>
where 1=1
<if test="recMerchantNo != null and recMerchantNo.size>0"> <if test="recMerchantNo != null and recMerchantNo.size>0">
and t1.merchant_id in and t1.merchant_id in
<foreach close=")" collection="recMerchantNo" item="item" open="(" separator=","> <foreach close=")" collection="recMerchantNo" item="item" open="(" separator=",">
...@@ -480,22 +459,6 @@ ...@@ -480,22 +459,6 @@
<if test="condition.enterpriseCustomerFlag != null and condition.enterpriseCustomerFlag ==1 "> <if test="condition.enterpriseCustomerFlag != null and condition.enterpriseCustomerFlag ==1 ">
and t1.customer_name like concat('%','公司','%') and t1.customer_name like concat('%','公司','%')
</if> </if>
<if test="condition.orderAxbTransactionFlag != null and condition.orderAxbTransactionFlag==1 ">
and t3.customer_phone is not null
</if>
<if test="condition.orderAxbTransactionFlag!=null and condition.orderAxbTransactionFlag==0 ">
and t3.customer_phone is null
</if>
<if test="condition.orderTransactionFlag!=null and condition.orderTransactionFlag==1 ">
and t4.customer_phone is not null
</if>
<if test="condition.orderTransactionFlag!=null and condition.orderTransactionFlag==0 ">
and t4.customer_phone is null
</if>
<if test="condition.orderTransactionAmount!=null">
and t5.customer_phone is not null
</if>
and t2.badge_id is not null and t2.badge_id is not null
</select> </select>
......
...@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,16 +25,33 @@ public class ConversationBatchServiceTest extends BaseServiceTest { ...@@ -24,16 +25,33 @@ public class ConversationBatchServiceTest extends BaseServiceTest {
public void conversationBatchPage() { public void conversationBatchPage() {
RpcPagination<ConversationBatchRequestDTO> req=new RpcPagination<>(); RpcPagination<ConversationBatchRequestDTO> req=new RpcPagination<>();
req.setPageSize(1); req.setPageSize(1);
req.setPageSize(200); req.setPageSize(9987);
ConversationBatchRequestDTO conversationBatchRequestDTO=new ConversationBatchRequestDTO(); ConversationBatchRequestDTO conversationBatchRequestDTO=new ConversationBatchRequestDTO();
// conversationBatchRequestDTO.setConversationDateId(40); // conversationBatchRequestDTO.setConversationDateId(40);
req.setCondition(conversationBatchRequestDTO); req.setCondition(conversationBatchRequestDTO);
Page<ConversationBatchDTO> res = conversationBatchService Page<ConversationBatchDTO> res = conversationBatchService
.conversationBatchPage(req); .conversationBatchPage(req);
System.out.println(JSONObject.toJSONString( res.stream().filter(index->index.isOrderFinishFlag()&& index.isFinishFlag()).collect(
Collectors.toList())));
}
@Test
public void findBatchByPhone() {
List<ConversationBatchDTO> res = conversationBatchService
.findBatchByPhone("13700000001");
System.out.println(res); System.out.println(res);
} }
@Test @Test
public void findExtBatchByIds() {
List<ConversationBatchDTO> res = conversationBatchService
.findExtBatchByIds(Arrays.asList(41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87));
System.out.println(JSONObject.toJSONString( res));
}
@Test
public void conversationDetailPage() { public void conversationDetailPage() {
Page<ConversationDetailDTO> res = conversationBatchService Page<ConversationDetailDTO> res = conversationBatchService
.conversationDetailPage(RpcPagination.copyPage(ConversationDetailRequestDTO.builder() .conversationDetailPage(RpcPagination.copyPage(ConversationDetailRequestDTO.builder()
......
...@@ -75,7 +75,6 @@ public class EmployeeBadgeServiceTest extends BaseServiceTest{ ...@@ -75,7 +75,6 @@ public class EmployeeBadgeServiceTest extends BaseServiceTest{
rpcPagination.setPageSize(10); rpcPagination.setPageSize(10);
EmployeeBadgeDTO employeeBadgeDTO=new EmployeeBadgeDTO(); EmployeeBadgeDTO employeeBadgeDTO=new EmployeeBadgeDTO();
employeeBadgeDTO.setOrderTransactionAmount(new BigDecimal(10)); employeeBadgeDTO.setOrderTransactionAmount(new BigDecimal(10));
employeeBadgeDTO.setOrderAxbTransactionFlag(1);
employeeBadgeDTO.setOrderTransactionFlag(1); employeeBadgeDTO.setOrderTransactionFlag(1);
employeeBadgeDTO.setBussinessType(1); employeeBadgeDTO.setBussinessType(1);
rpcPagination.setCondition(employeeBadgeDTO); rpcPagination.setCondition(employeeBadgeDTO);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!