Commit 8d568808 authored by Vu Duy Anh's avatar Vu Duy Anh

anhvd accept merge

parents 27be70ec 6070a547
package com.viettel.campaign.model.ccms_full;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "AGENT_STATUS_STAT")
@Getter
@Setter
public class AgentStatusStat {
@Id
@NotNull
@GeneratedValue(generator = "AGENT_STATUS_STAT_SEQ")
@SequenceGenerator(name = "AGENT_STATUS_STAT_SEQ", sequenceName = "AGENT_STATUS_STAT_SEQ", allocationSize = 1)
@Basic(optional = false)
@Column(name = "KZ_ACCOUNT_ID")
@NotNull
private String kzAccountId;
@Column(name = "KZ_USER_ID")
@NotNull
private String kzUserId;
@Column(name = "CURRENT_STATUS")
@NotNull
private String currentStatus;
@Column(name = "TIMESTAMP")
@NotNull
private String timestamp;
@Column(name = "PREVIOUS_STATUS")
private String previousStatus;
@Column(name = "PREVIOUS_STATUS_DURATION")
private Long previousStatusDuration;
@Column(name = "ID")
@NotNull
private Long id;
@Column(name = "CHANNEL")
@NotNull
private String channel;
}
package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.AgentStatusStat;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Repository
@Transactional(DataSourceQualify.CCMS_FULL)
public interface AgentStatusStatRepository extends JpaRepository<AgentStatusStat, Long> {
AgentStatusStat findByKzUserIdAndCurrentStatusNotIn(String kzUserId, List<String> currentStatus);
}
......@@ -18,7 +18,9 @@ public interface CampaignAgentRepository extends JpaRepository<CampaignAgent, Lo
@Query(value = "SELECT campaign_agent_seq.nextval FROM DUAL", nativeQuery = true)
Long getNextSeqId();
List<CampaignAgent> findByCampaignIdAndAgentId(Long campaignId, Long agentId);
CampaignAgent findByCampaignIdAndAgentId(Long campaignId, Long agentId);
List<CampaignAgent> findByAgentId(Long agentId);
@Modifying
@Query("delete from CampaignAgent c where c.campaignAgentId in (:p_campaign_agent_id)")
......
......@@ -21,13 +21,13 @@ public interface TimeRangeDialModeRepository extends JpaRepository<TimeRangeDial
List<TimeRangeDialMode> findTimeRangeDialModeByCampaignIdAndCompanySiteId(Long campaignId, Long companySiteId);
@Query(value = "SELECT * " +
"FROM (SELECT Z.* " +
" FROM TIME_ZONE_DIAL_MODE Z INNER JOIN CAMPAIGN C ON Z.CAMPAIGN_ID = C.CAMPAIGN_ID " +
" WHERE Z.COMPANY_SITE_ID = :companySiteId " +
" AND Z.CAMPAIGN_ID = :campaignId " +
" AND TO_DATE(START_TIME, 'YYYY/MM/DD') <= TO_DATE(SYSDATE, 'YYYY/MM/DD') " +
" AND TO_DATE((to_char(SYSDATE, 'YYYY/MM/DD') || ' ' || Z.HOUR || ':' || Z.MINUTE || ':00'), 'YYYY/MM/DD HH24:MI:SS') <= SYSDATE " +
" ORDER BY TO_DATE((to_char(SYSDATE, 'YYYY/MM/DD') || ' ' || Z.HOUR || ':' || Z.MINUTE || ':00'), 'YYYY/MM/DD HH24:MI:SS') DESC " +
"FROM (SELECT R.* " +
" FROM TIME_RANGE_DIAL_MODE R INNER JOIN CAMPAIGN C ON R.CAMPAIGN_ID = C.CAMPAIGN_ID" +
" WHERE R.COMPANY_SITE_ID = :companySiteId " +
" AND R.CAMPAIGN_ID = :campaignId " +
" AND C.START_TIME <= SYSDATE " +
" AND R.START_TIME <= SYSDATE " +
" ORDER BY R.START_TIME DESC " +
" ) WHERE ROWNUM = 1", nativeQuery = true)
TimeRangeDialMode findDialModeAtCurrent(@Param("companySiteId") Long companySiteId, @Param("campaignId") Long campaignId);
......
......@@ -21,14 +21,15 @@ public interface TimeZoneDialModeRepository extends JpaRepository<TimeZoneDialMo
List<TimeZoneDialMode> findTimeZoneDialModeByCampaignIdAndCompanySiteId(Long campaignId, Long companySiteId);
@Query(value = "SELECT * " +
"FROM (SELECT R.* " +
" FROM TIME_RANGE_DIAL_MODE R " +
" WHERE R.CAMPAIGN_ID = 11 " +
" AND R.COMPANY_SITE_ID = 662691 " +
" AND TO_DATE(R.START_TIME, 'YYYY/MM/DD HH24:MI:SS') <= TO_DATE(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') " +
" ORDER BY R.START_TIME DESC " +
"FROM (SELECT Z.* " +
" FROM TIME_ZONE_DIAL_MODE Z INNER JOIN CAMPAIGN C ON Z.CAMPAIGN_ID = C.CAMPAIGN_ID " +
" WHERE Z.COMPANY_SITE_ID = :companySiteId " +
" AND Z.CAMPAIGN_ID = :campaignId " +
" AND TO_CHAR(C.START_TIME, 'YYYY/MM/DD') <= TO_CHAR(SYSDATE, 'YYYY/MM/DD') " +
" AND TO_DATE((TO_CHAR(SYSDATE, 'YYYY/MM/DD') || ' ' || Z.HOUR || ':' || Z.MINUTE || ':00'), 'YYYY/MM/DD HH24:MI:SS') <= SYSDATE " +
" ORDER BY TO_DATE((TO_CHAR(SYSDATE, 'YYYY/MM/DD') || ' ' || Z.HOUR || ':' || Z.MINUTE || ':00'), 'YYYY/MM/DD HH24:MI:SS') DESC " +
" ) WHERE ROWNUM = 1", nativeQuery = true)
TimeZoneDialMode findDialModeAtCurrent(@Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId);
TimeZoneDialMode findDialModeAtCurrent(@Param("companySiteId") Long companySiteId, @Param("campaignId") Long campaignId);
void deleteAllByCampaignIdAndCompanySiteId(Long campaignId, Long companySiteId);
}
......@@ -6,5 +6,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface VSAUsersRepository extends JpaRepository<VSAUsers, Long> {
List<VSAUsers> findAllByCompanySiteId(Long companySiteId);
VSAUsers findByUserId(Long userId);
}
......@@ -460,6 +460,9 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
@Transactional(DataSourceQualify.CCMS_FULL)
public List<CampaignDTO> searchCampaignExecute(CampaignRequestDTO campaignRequestDto, Pageable pageable) {
List<CampaignDTO> result = new ArrayList<>();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = null;
StringBuilder expression = new StringBuilder()
.append(" SELECT C.CAMPAIGN_CODE, C.CAMPAIGN_NAME, C.CONTENT, C.START_TIME, C.END_TIME, C.STATUS, CA.STATUS AS AGENT_STATUS, C.CAMPAIGN_ID ")
.append(" FROM CAMPAIGN C INNER JOIN CAMPAIGN_AGENT CA ON C.CAMPAIGN_ID = CA.CAMPAIGN_ID ")
......@@ -506,12 +509,15 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
}
try {
Query query = entityManager.createNativeQuery(expression.toString());
session = sessionFactory.openSession();
session.beginTransaction();
SQLQuery query = session.createSQLQuery(expression.toString());
query.setParameter("pAgentId", Long.parseLong(campaignRequestDto.getAgentId()));
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode())) {
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode()) && !DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode().trim())) {
String[] lstCode = campaignRequestDto.getCampaignCode().split(",");
query.setParameter("pCampaignCode", lstCode);
query.setParameterList("pCampaignCode", lstCode);
}
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignName())) {
......@@ -557,9 +563,7 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
query.setMaxResults(pageable.getPageSize());
}
List<Object[]> data = query.getResultList();
//TimeZoneDialMode zoneDialMode = zoneDialModeRepository.findDialModeAtCurrent(Long.parseLong(campaignRequestDto.getCampaignId()), Long.parseLong(campaignRequestDto.getCompanySiteId()));
//TimeRangeDialMode rangeDialMode = rangeDialModeRepository.findDialModeAtCurrent(Long.parseLong(campaignRequestDto.getCampaignId()), Long.parseLong(campaignRequestDto.getCompanySiteId()));
List<Object[]> data = query.list();
for (Object[] obj : data) {
CampaignDTO item = new CampaignDTO();
......@@ -580,7 +584,11 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
return result;
} catch (Exception e) {
// e.printStackTrace();
e.printStackTrace();
} finally {
if (null != session) {
session.close();
}
}
return result;
......
......@@ -546,7 +546,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
sb.append(" select column_name columnName, null customizeFieldId, 1 isFix from user_tab_columns, dual");
sb.append(" where table_name = 'CUSTOMER'");
sb.append(" )");
sb.append(" select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)");
sb.append(" select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where campaign_id = :p_campaign_id and column_name is not null)");
sb.append(" union all");
sb.append(" select title columnName, customize_field_id customizeFieldId, 0 isFix from customize_fields, dual");
sb.append(" where function_code = 'CUSTOMER'");
......
......@@ -20,7 +20,9 @@ public interface CampaignExecuteService {
XSSFWorkbook exportInteractiveResult(CampaignRequestDTO dto) throws IOException;
ResultDTO searchCampaignExecute(CampaignRequestDTO requestDto, String xAuthToken);
ResultDTO searchCampaignExecute(CampaignRequestDTO requestDto);
ResultDTO checkExecuteCampaign(CampaignRequestDTO requestDto);
ResultDTO getExecuteCampaign(CampaignRequestDTO requestDto);
......@@ -34,6 +36,8 @@ public interface CampaignExecuteService {
ResultDTO getAgentLogout(CampaignRequestDTO dto);
ResultDTO getLogoutContactResult(ReceiveCustLogDTO dto);
ResultDTO updateContactCustResult(ContactCustResultDTO dto, UserSession userSession);
ResultDTO draftAtTen(ContactCustResultDTO dto, UserSession userSession);
......@@ -52,7 +56,7 @@ public interface CampaignExecuteService {
ResultDTO updateListContactQuestResult(ContactQuestResultDTO dto);
String getDialModeAtCurrent(Long campaignId, Long companySiteId);
String getDialModeAtCurrent(Long companySiteId, Long campaignId);
ResultDTO getContactCustResultById(Long contactCustResultId);
......
......@@ -79,6 +79,12 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
@Autowired
CustomerRepository customerRepository;
@Autowired
AgentStatusStatRepository agentStatusStatRepository;
@Autowired
VSAUsersRepository vsaUsersRepository;
public CampaignExecuteServiceImp() throws NoSuchAlgorithmException {
}
......@@ -255,31 +261,70 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
//</editor-fold: hungtt>
@Override
public ResultDTO searchCampaignExecute(CampaignRequestDTO requestDto, String xAuthToken) {
public ResultDTO searchCampaignExecute(CampaignRequestDTO requestDto) {
ResultDTO result = new ResultDTO();
Map data = new HashMap();
UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken);
String campaignSystemStatus = "";
String campaignExecuting = "";
Integer count = campaignExecuteRepository.searchCampaignExecute(requestDto, null).size();
try {
Integer count = campaignExecuteRepository.searchCampaignExecute(requestDto, null).size();
if (count > 0) {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setTotalRow(count);
List<CampaignDTO> campaignList = campaignExecuteRepository.searchCampaignExecute(requestDto, SQLBuilder.buildPageable(requestDto));
result.setListData(campaignList);
Agents agents = agentsRepository.findByAgentId(requestDto.getAgentId());
if (agents.getCampaignSystemStatus() != null && agents.getCampaignSystemStatus().equalsIgnoreCase("AVAILABLE")) {
campaignSystemStatus = "1";
for (CampaignDTO item : campaignList) {
if (item.getStatus() == 2 && item.getAgentStatus() == 1) {
campaignExecuting = item.getCampaignId().toString();
break;
}
}
}
data.put("campaignSystemStatus", campaignSystemStatus);
data.put("campaignExecuting", campaignExecuting);
result.setData(data);
} else {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
data.put("dialModeManual", campaignSystemStatus);
data.put("campaignExecuting", campaignExecuting);
result.setData(data);
}
} catch (Exception e) {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
}
if (count > 0) {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setTotalRow(count);
result.setListData(campaignExecuteRepository.searchCampaignExecute(requestDto, SQLBuilder.buildPageable(requestDto)));
return result;
}
Agents agents = agentsRepository.findByAgentId(requestDto.getAgentId());
//TimeZoneDialMode zoneDialMode = zoneDialModeRepository.findDialModeAtCurrent(Long.parseLong(requestDto.getCampaignId()), Long.parseLong(requestDto.getCompanySiteId()));
//TimeRangeDialMode rangeDialMode = rangeDialModeRepository.findDialModeAtCurrent(Long.parseLong(requestDto.getCampaignId()), Long.parseLong(requestDto.getCompanySiteId()));
@Override
public ResultDTO checkExecuteCampaign(CampaignRequestDTO requestDto) {
ResultDTO result = new ResultDTO();
if (agents.getUserStatus() != null && agents.getCampaignSystemStatus() != null) {
if (agents.getUserStatus().equalsIgnoreCase("CALLOUT") && agents.getCampaignSystemStatus().equalsIgnoreCase("AVAILABLE")) {
//if (zoneDialMode != null && zoneDialMode.getDialMode().equals(0) || rangeDialMode != null && rangeDialMode.getDialMode().equals(0))
data.put("dialModeManual", "1");
}
try {
String dialMode = getDialModeAtCurrent(Long.parseLong(requestDto.getCompanySiteId()), Long.parseLong(requestDto.getCampaignId()));
VSAUsers vsa = vsaUsersRepository.findByUserId(Long.parseLong(requestDto.getAgentId()));
AgentStatusStat ass = agentStatusStatRepository.findByKzUserIdAndCurrentStatusNotIn(vsa.getUserKazooId(), Arrays.asList("logged_out", "campaign"));
if (ass != null) {
result.setErrorCode("02");
result.setDescription("campaign-agents-err-callout");
} else if (dialMode.equalsIgnoreCase("-1")) {
result.setErrorCode("03");
result.setDescription("campaign-agents-err-dial-mode");
} else {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
}
result.setData(data);
} else {
} catch (Exception e) {
// e.printStackTrace();
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
}
......@@ -290,9 +335,16 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
@Override
public ResultDTO getExecuteCampaign(CampaignRequestDTO requestDto) {
ResultDTO result = new ResultDTO();
String dialMode = getDialModeAtCurrent(Long.parseLong(requestDto.getCompanySiteId()), Long.parseLong(requestDto.getCampaignId()));
try {
if (requestDto.getType() == 2) {
List<CampaignAgent> ca = campaignAgentRepository.findByAgentId(Long.parseLong(requestDto.getAgentId()));
for (CampaignAgent item: ca) {
item.setStatus(0);
}
ca = campaignAgentRepository.saveAll(ca);
}
// update acd_full.agents table
Agents agents = agentsRepository.findByAgentId(requestDto.getAgentId());
agents.setAgentId(requestDto.getAgentId());
......@@ -302,11 +354,9 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
Agents a1 = agentsRepository.save(agents);
// update ccms_full.campaign_agent table
List<CampaignAgent> ca = campaignAgentRepository.findByCampaignIdAndAgentId(Long.parseLong(requestDto.getCampaignId()), Long.parseLong(requestDto.getAgentId()));
for (CampaignAgent item : ca) {
item.setStatus(1);
}
List<CampaignAgent> ca1 = campaignAgentRepository.saveAll(ca);
CampaignAgent ca = campaignAgentRepository.findByCampaignIdAndAgentId(Long.parseLong(requestDto.getCampaignId()), Long.parseLong(requestDto.getAgentId()));
ca.setStatus(1);
ca = campaignAgentRepository.save(ca);
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
......@@ -510,11 +560,31 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
try {
agentsRepository.updateAgentLogoutFromCampaign(dto.getAgentId(), "LOGOUT");
// update ccms_full.campaign_agent table
List<CampaignAgent> ca = campaignAgentRepository.findByCampaignIdAndAgentId(Long.parseLong(dto.getCampaignId()), Long.parseLong(dto.getAgentId()));
for (CampaignAgent item : ca) {
item.setStatus(1);
}
List<CampaignAgent> ca1 = campaignAgentRepository.saveAll(ca);
CampaignAgent ca = campaignAgentRepository.findByCampaignIdAndAgentId(Long.parseLong(dto.getCampaignId()), Long.parseLong(dto.getAgentId()));
ca.setStatus(0);
ca = campaignAgentRepository.save(ca);
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
// e.printStackTrace();
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
}
return result;
}
@Override
public ResultDTO getLogoutContactResult(ReceiveCustLogDTO dto) {
ResultDTO result = new ResultDTO();
try {
agentsRepository.updateAgentLogoutFromCampaign(dto.getAgentId().toString(), "AVAILABLE");
// update receive customer log
ReceiveCustLog rcl = custLogRepository.getOne(dto.getReceiveCustLogId());
rcl.setEndTime(new Date());
rcl = custLogRepository.save(rcl);
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
......@@ -808,15 +878,15 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
}
@Override
public String getDialModeAtCurrent(Long campaignId, Long companySiteId) {
public String getDialModeAtCurrent(Long companySiteId, Long campaignId) {
// 0: manual, 1- Preview, 2-Progressive, 3-Super Progressive, 4- Predictive
try {
TimeRangeDialMode lstTimeRange = rangeDialModeRepository.findDialModeAtCurrent(companySiteId, campaignId);
TimeZoneDialMode lstTimeZone = zoneDialModeRepository.findDialModeAtCurrent(companySiteId, campaignId);
if (lstTimeRange.getTimeRangeDialModeId() != null) {
if (lstTimeRange != null) {
return lstTimeRange.getDialMode().toString();
} else if (lstTimeZone.getTimeZoneDialModeId() != null) {
} else if (lstTimeZone != null) {
return lstTimeZone.getDialMode().toString();
}
} catch (Exception e) {
......
......@@ -34,9 +34,15 @@ public class CampaignExecuteController {
@PostMapping("/searchCampaignExecute")
@ResponseBody
public ResponseEntity<ResultDTO> searchCampaignExecute(@RequestBody CampaignRequestDTO requestDto, HttpServletRequest request) {
String xAuthToken = request.getHeader("X-Auth-Token");
ResultDTO result = campaignExecuteService.searchCampaignExecute(requestDto, xAuthToken);
public ResponseEntity<ResultDTO> searchCampaignExecute(@RequestBody CampaignRequestDTO requestDto) {
ResultDTO result = campaignExecuteService.searchCampaignExecute(requestDto);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/checkExecuteCampaign")
@ResponseBody
public ResponseEntity<ResultDTO> checkExecuteCampaign(@RequestBody CampaignRequestDTO requestDto) {
ResultDTO result = campaignExecuteService.checkExecuteCampaign(requestDto);
return new ResponseEntity<>(result, HttpStatus.OK);
}
......@@ -82,6 +88,13 @@ public class CampaignExecuteController {
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/getLogoutContactResult")
@ResponseBody
public ResponseEntity<ResultDTO> getLogoutContactResult(@RequestBody ReceiveCustLogDTO requestDto) {
ResultDTO result = campaignExecuteService.getLogoutContactResult(requestDto);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/searchInteractiveResult")
@ResponseBody
public ResponseEntity<ResultDTO> searchInteractiveResult(@RequestBody CampaignRequestDTO dto) throws Exception {
......
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