opt export history callling list

This commit is contained in:
Donghuang 2021-10-05 12:04:23 +08:00
parent e81fb93143
commit 13df0934e3
7 changed files with 298 additions and 69 deletions

View File

@ -160,6 +160,7 @@ public class CallingListServiceImpl
val exportBatchKey = idSeq.uuid();
val argMarkAsExport = form.copy(
new ReqCallingListHistoricalMarkAsExport());
argMarkAsExport.setTenantId(form.getTenantId());
argMarkAsExport.setExportBatchKey(exportBatchKey);
argMarkAsExport.setOperator(form.getAuthUser());
@ -167,6 +168,17 @@ public class CallingListServiceImpl
val rows = callingListHistoricalMapper.markAsExport(argMarkAsExport);
log.info("MarkCallingListHistoricalExportRows|{}", rows);
val rows1 = callingListHistoricalMapper.removeInCallingList(argMarkAsExport);
log.info("Remove in calling list [{}].", rows1);
val rows2 = callingListHistoricalMapper.removeCalled6Times(argMarkAsExport);
log.info("Remove called exceed 6 times [{}].", rows2);
int rows3 = callingListHistoricalMapper.removeCalledTwiceToday(argMarkAsExport);
log.info("Remove called twice today [{}].", rows3);
int rows4 = callingListHistoricalMapper.removeCalledIn4Hours(argMarkAsExport);
log.info("Remove called in 4 hours today [{}].", rows4);
val rows5 = callingListHistoricalMapper.removeAnswered(argMarkAsExport);
log.info("Remove answered [{}].", rows5);
mapper.insertHistorical(form.getAuthUser(),
exportBatchKey,
form.getDailyFrom().getSecondOfDay(),

View File

@ -48,6 +48,46 @@ public interface CallingListHistoricalMapper extends BaseMapper<Integer, Calling
*/
int markAsExport(@Param("arg") ReqCallingListHistoricalMarkAsExport arg);
/**
* 删除在拨打名单中
*
* @param arg arg
* @return update rows
*/
int removeInCallingList(@Param("arg") ReqCallingListHistoricalMarkAsExport arg);
/**
* 删除接通过
*
* @param arg arg
* @return update rows
*/
int removeAnswered(@Param("arg") ReqCallingListHistoricalMarkAsExport arg);
/**
* 删除拨打超过6次
*
* @param arg arg
* @return update rows
*/
int removeCalled6Times(@Param("arg") ReqCallingListHistoricalMarkAsExport arg);
/**
* 删除今日拨打超过1次
*
* @param arg arg
* @return update rows
*/
int removeCalledTwiceToday(@Param("arg") ReqCallingListHistoricalMarkAsExport arg);
/**
* 删除4小时内拨打过
*
* @param arg arg
* @return update rows
*/
int removeCalledIn4Hours(@Param("arg") ReqCallingListHistoricalMarkAsExport arg);
/**
* revert
*

View File

@ -121,68 +121,145 @@
</update>
<update id="markAsExport">
update <include refid="table" />
set export_batch_key = #{arg.exportBatchKey},
export_time = now(),
updated_by = #{arg.operator},
updated_time = now()
where tenant_id = #{arg.tenantId}
and campaign_id = #{arg.campaignId}
and put_in_date = #{arg.putInDate}
and last_dial_date = #{arg.lastDialDate}
and export_batch_key is null
and export_time is null
and active = 1
limit #{arg.limit}
</update>
<update id="removeInCallingList">
update <include refid="table" /> c
join br_calling_list c1
on c.tenant_id = c1.tenant_id
and c.phone = c1.phone
set c.active = 0,
c.note = 'IN Calling List',
c.updated_by = #{arg.operator},
c.updated_time = now()
where c.tenant_id = #{arg.tenantId}
and c.campaign_id = #{arg.campaignId}
and c.export_batch_key = #{arg.exportBatchKey}
and c.active = 1
</update>
<update id="removeAnswered">
update <include refid="table" /> c
join (
select c.id from <include refid="table" /> c
<!-- 过去接通过 -->
<![CDATA[
left join (select called_number
from br_call_detail_record
where start_stamp > date(subdate(now(), 21))
group by called_number
having count(answer_stamp) > 0) t1
]]>
on c.phone = t1.called_number
<!-- 过去累计拨打次数超过6 -->
<![CDATA[
left join (select called_number
from br_call_detail_record
where start_stamp > date(subdate(now(), 21))
group by called_number
having count(id) > 6) t2
]]>
on c.phone = t2.called_number
<!-- 今日拨打次数超过1 -->
<![CDATA[
left join (select called_number
from br_call_detail_record
where start_stamp > date(now())
group by called_number
having count(id) > 1) t3
]]>
on c.phone = t3.called_number
<!-- 4小时内拨打过 -->
<![CDATA[
left join (select called_number
from br_call_detail_record
where start_stamp > date(now())
group by called_number
having max(start_stamp) > now() - interval 4 hour) t4
]]>
on c.phone = t4.called_number
<!-- 在拨打名单中 -->
left join br_calling_list c1
on c.phone = c1.phone
<![CDATA[
select called_number
from br_call_detail_record rec
where start_stamp > date(now() - interval 21 day)
and tenant_id = #{arg.tenantId}
and answer_stamp is not null
group by called_number
having count(answer_stamp) > 0
]]>
) t1
on c.phone = t1.called_number
where c.campaign_id = #{arg.campaignId}
and c.put_in_date = #{arg.putInDate}
and c.last_dial_date = #{arg.lastDialDate}
and c.export_batch_key is null
and c.export_time is null
and c.active = 1
and t1.called_number is null
and t2.called_number is null
and t3.called_number is null
and t4.called_number is null
and c1.id is null
limit #{arg.limit}
) t
on c.id = t.id
set c.export_batch_key = #{arg.exportBatchKey},
set c.active = 0,
c.note = 'Answered',
c.updated_by = #{arg.operator},
c.export_time = now()
c.updated_time = now()
where c.tenant_id = #{arg.tenantId}
and c.campaign_id = #{arg.campaignId}
and c.export_batch_key = #{arg.exportBatchKey}
and c.active = 1
</update>
<update id="removeCalled6Times">
update <include refid="table" /> c
join (
<![CDATA[
select called_number
from br_call_detail_record rec
where start_stamp > date(now() - interval 21 day)
and tenant_id = #{arg.tenantId}
group by called_number
having count(start_stamp) > 6
]]>
) t1
on c.phone = t1.called_number
set c.active = 0,
c.note = 'Exceed 6 Times',
c.updated_by = #{arg.operator},
c.updated_time = now()
where c.tenant_id = #{arg.tenantId}
and c.campaign_id = #{arg.campaignId}
and c.export_batch_key = #{arg.exportBatchKey}
and c.active = 1
</update>
<update id="removeCalledTwiceToday">
update <include refid="table" /> c
join (
<![CDATA[
select called_number
from br_call_detail_record rec
where start_stamp > date(now())
and tenant_id = #{arg.tenantId}
group by called_number
having count(start_stamp) > 1
]]>
) t1
on c.phone = t1.called_number
set c.active = 0,
c.note = 'Exceed 1 Times Today',
c.updated_by = #{arg.operator},
c.updated_time = now()
where c.tenant_id = #{arg.tenantId}
and c.campaign_id = #{arg.campaignId}
and c.export_batch_key = #{arg.exportBatchKey}
and c.active = 1
</update>
<update id="removeCalledIn4Hours">
update <include refid="table" /> c
join (
<![CDATA[
select called_number
from br_call_detail_record rec
where start_stamp > now() - interval 4 hour
and tenant_id = #{arg.tenantId}
group by called_number
having count(start_stamp) > 0
]]>
) t1
on c.phone = t1.called_number
set c.active = 0,
c.note = 'Called In 4 Hours',
c.updated_by = #{arg.operator},
c.updated_time = now()
where c.tenant_id = #{arg.tenantId}
and c.campaign_id = #{arg.campaignId}
and c.export_batch_key = #{arg.exportBatchKey}
and c.active = 1
</update>
<update id="revert">

View File

@ -186,10 +186,9 @@
#{dailyTo} daily_to,
'OLD' type, 'OLD_DATA' note, #{operator}
from br_calling_list_historical p
left join br_calling_list c
on p.phone = c.phone
where export_batch_key = #{exportBatchKey}
and c.id is null
where p.export_batch_key = #{exportBatchKey}
and p.active = 1
</insert>
</mapper>

View File

@ -1,6 +1,9 @@
package com.pudonghot.yo.mapper;
import com.pudonghot.yo.model.request.ReqCallingListHistoricalMarkAsExport;
import lombok.SneakyThrows;
import lombok.val;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;
import lombok.extern.slf4j.Slf4j;
import org.junit.runner.RunWith;
@ -9,6 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Date;
/**
* @author Donghuang
* @date Sep 26, 2020 20:47:13
@ -42,4 +47,93 @@ public class CallingListHistoricalMapperTest {
val summary = mapper.updatePutInDate();
log.info("Update put in date [{}].", summary);
}
@Test
public void testMarkAsExport() {
val req = new ReqCallingListHistoricalMarkAsExport();
req.setTenantId(1);
req.setCampaignId(4);
req.setLastDialDate(parseDate("2021-03-31"));
req.setPutInDate(parseDate("2021-03-24"));
req.setExportBatchKey("TestDriver");
req.setOperator("donghuang");
req.setLimit(10);
val rows = mapper.markAsExport(req);
log.info("Mark as Export [{}].", rows);
}
@Test
public void testRemoveInCallingList() {
val req = new ReqCallingListHistoricalMarkAsExport();
req.setTenantId(1);
req.setCampaignId(4);
req.setLastDialDate(parseDate("2021-03-31"));
req.setPutInDate(parseDate("2021-03-24"));
req.setExportBatchKey("TestDriver");
req.setOperator("donghuang");
req.setLimit(20);
val rows = mapper.removeInCallingList(req);
log.info("Remove in calling list [{}].", rows);
}
@Test
public void testRemoveAnswered() {
val req = new ReqCallingListHistoricalMarkAsExport();
req.setTenantId(1);
req.setCampaignId(4);
req.setLastDialDate(parseDate("2021-03-31"));
req.setPutInDate(parseDate("2021-03-24"));
req.setExportBatchKey("TestDriver");
req.setOperator("donghuang");
req.setLimit(20);
val rows = mapper.removeAnswered(req);
log.info("Remove answered [{}].", rows);
}
@Test
public void testRemoveCalled6Times() {
val req = new ReqCallingListHistoricalMarkAsExport();
req.setTenantId(1);
req.setCampaignId(4);
req.setLastDialDate(parseDate("2021-03-31"));
req.setPutInDate(parseDate("2021-03-24"));
req.setExportBatchKey("TestDriver");
req.setOperator("donghuang");
req.setLimit(20);
val rows = mapper.removeCalled6Times(req);
log.info("Remove called 6 times [{}].", rows);
}
@Test
public void testRemoveCalled1Times() {
val req = new ReqCallingListHistoricalMarkAsExport();
req.setTenantId(1);
req.setCampaignId(4);
req.setLastDialDate(parseDate("2021-03-31"));
req.setPutInDate(parseDate("2021-03-24"));
req.setExportBatchKey("TestDriver");
req.setOperator("donghuang");
req.setLimit(20);
val rows = mapper.removeCalledTwiceToday(req);
log.info("Remove twice today [{}].", rows);
}
@Test
public void testRemoveCalledIn4Hours() {
val req = new ReqCallingListHistoricalMarkAsExport();
req.setTenantId(1);
req.setCampaignId(4);
req.setLastDialDate(parseDate("2021-03-31"));
req.setPutInDate(parseDate("2021-03-24"));
req.setExportBatchKey("TestDriver");
req.setOperator("donghuang");
req.setLimit(20);
val rows = mapper.removeCalledIn4Hours(req);
log.info("Remove called in 4 hours [{}].", rows);
}
@SneakyThrows
Date parseDate(String date) {
return DateUtils.parseDate(date, "yyyy-MM-dd");
}
}

View File

@ -1,14 +1,14 @@
package com.pudonghot.yo.mapper;
import lombok.val;
import org.junit.Test;
import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import com.pudonghot.yo.model.DailyTime;
import com.pudonghot.yo.model.domain.CallingList;
import com.pudonghot.yo.model.request.ReqCallingListRedial;
import lombok.val;
import org.junit.Test;
import lombok.extern.slf4j.Slf4j;
import org.junit.runner.RunWith;
import me.chyxion.tigon.mybatis.Search;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*/
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:spring/spring-*.xml")
@SpringBootTest(classes = TestDriver.class)
public class CallingListMapperTest {
@Autowired
private CallingListMapper mapper;
@ -47,4 +47,10 @@ public class CallingListMapperTest {
val result = mapper.redial(arg);
log.info("Redial: {}", result);
}
@Test
public void testInsertHis() {
val result = mapper.insertHistorical("donghuang", "TestDriver", 49200, 54000);
log.info("Test insert his [{}].", result);
}
}

View File

@ -2,9 +2,9 @@ package com.pudonghot.yo.model.request;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
/**
* @author Donghuang
@ -16,6 +16,7 @@ import java.util.Date;
public class ReqCallingListHistoricalMarkAsExport implements Serializable {
private static final long serialVersionUID = 1L;
private Integer tenantId;
private String operator;
private Integer campaignId;
private Date putInDate;