Commit b18de655 authored by Phạm Duy Phi's avatar Phạm Duy Phi
parents c6eb58cf 7e1d0f89
......@@ -201,6 +201,17 @@
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
<version>9.0.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<dependencyManagement>
......
......@@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
......@@ -26,9 +28,6 @@ import java.util.concurrent.ScheduledFuture;
@Configuration
public class JobConfig implements SchedulingConfigurer {
@Autowired
private ApParamService apParamService;
TaskScheduler taskScheduler;
private ScheduledFuture<?> job1;
private ScheduledFuture<?> job2;
......@@ -38,18 +37,18 @@ public class JobConfig implements SchedulingConfigurer {
return new CampaignJob();
}
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(10);
threadPoolTaskScheduler.setThreadNamePrefix("scheduler-thread");
threadPoolTaskScheduler.initialize();
job1(threadPoolTaskScheduler);
job2(threadPoolTaskScheduler);
this.taskScheduler = threadPoolTaskScheduler;
taskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
}
// @Override
// public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
//
// ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
// threadPoolTaskScheduler.setPoolSize(10);
// threadPoolTaskScheduler.setThreadNamePrefix("scheduler-thread");
// threadPoolTaskScheduler.initialize();
// job1(threadPoolTaskScheduler);
// job2(threadPoolTaskScheduler);
// this.taskScheduler = threadPoolTaskScheduler;
// taskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
// }
private void job1(TaskScheduler scheduler) {
job1 = scheduler.schedule(() -> {
......@@ -82,8 +81,17 @@ public class JobConfig implements SchedulingConfigurer {
// @Override
// public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
//// scheduledTaskRegistrar.addTriggerTask(() -> campaignJob().process2(), (TriggerContext triggerContext) -> yourService.getCron());
// }
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(10);
threadPoolTaskScheduler.setThreadNamePrefix("scheduler-thread");
threadPoolTaskScheduler.initialize();
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
// scheduledTaskRegistrar.addTriggerTask(() -> campaignJob().process(), (TriggerContext triggerContext) -> yourService.getCron());
scheduledTaskRegistrar.addTriggerTask(() -> campaignJob().process(), triggerContext -> {
CronTrigger trigger = new CronTrigger("0/5 * * * * ?");
return trigger.nextExecutionTime(triggerContext);
});
}
}
package com.viettel.campaign.model;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* @author hanv_itsol
* @project campaign
*/
@Entity
@Table(name = "PROCESS_CONFIG")
@Data
public class ProcessConfig implements Serializable {
@Id
@NotNull
@Column(name = "CONFIG_ID")
private Long configId;
@Column(name = "CONFIG_NAME")
private String configName;
@Column(name = "CONFIG_CODE")
private String configCode;
@Column(name = "CONFIG_VALUE")
private String configValue;
@Column(name = "LAST_PROCESS")
private Date lastProcess;
@Column(name = "COMPANY_SITE_ID")
private Long siteId;
}
......@@ -8,9 +8,21 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Repository
public interface CampaignRepository extends JpaRepository<Campaign, Long>, CampaignRepositoryCustom {
List<Campaign> findAllByCompanySiteId(Long companyId);
List<Campaign> findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(Long siteId, Date startTime, List<Long> status);
List<Campaign> findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(Long siteId, Date endTime, List<Long> status);
@Query("SELECT COUNT(c.campaignId) " +
" FROM Campaign c JOIN CampaignCustomer cc ON c.campaignId = cc.campaignId " +
" WHERE cc.companySiteId = :pCompanySiteId " +
......
......@@ -13,4 +13,6 @@ public interface CampaignRepositoryCustom {
ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO);
String getMaxCampaignIndex();
ResultDTO checkAllowStatusToPrepare (Long campaignId);
}
package com.viettel.campaign.repository;
import com.viettel.campaign.model.ProcessConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author hanv_itsol
* @project campaign
*/
@Repository
public interface ProcessConfigRepository extends JpaRepository<ProcessConfig, Long> {
List<ProcessConfig> findAllByConfigCode(String configCode);
}
......@@ -192,7 +192,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) {
sqlStr.append(" AND UPPER(a.CAMPAIGN_NAME) LIKE :p_name");
}
if (requestDto.getStatus() != null && requestDto.getStatus() > 0) {
if (requestDto.getStatus() != null && requestDto.getStatus() >= 0) {
sqlStr.append(" AND a.STATUS = :p_status");
}
if (!DataUtil.isNullOrEmpty(requestDto.getFromDateFr())) {
......@@ -245,7 +245,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
query.setParameter("p_company_site_id", requestDto.getCompanySiteId());
if (requestDto.getStatus() != null && requestDto.getStatus() > 0) {
if (requestDto.getStatus() != null && requestDto.getStatus() >= 0) {
query.setParameter("p_status", requestDto.getStatus());
}
if (!DataUtil.isNullOrEmpty(requestDto.getFromDateFr())) {
......@@ -287,6 +287,14 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
query.addScalar("numOfJoinedCus", new LongType());
query.addScalar("numOfNotJoinedCus", new LongType());
query.addScalar("numOfLockCus", new LongType());
query.addScalar("companySiteId", new LongType());
query.addScalar("content", new StringType());
query.addScalar("maxRecall", new IntegerType());
query.addScalar("recallType", new IntegerType());
query.addScalar("recallDuration", new IntegerType());
query.addScalar("currentTimeMode", new LongType());
query.addScalar("wrapupTimeConnect", new LongType());
query.addScalar("wrapupTimeDisconnect", new LongType());
query.setResultTransformer(Transformers.aliasToBean(CampaignDTO.class));
int count = 0;
......@@ -407,4 +415,36 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
return null;
}
@Override
public ResultDTO checkAllowStatusToPrepare(Long campaignId) {
logger.info("Start check allow campaign status to prepare::");
ResultDTO result = new ResultDTO();
if(DataUtil.isNullOrZero(campaignId)) {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
return result;
}
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
try {
StringBuilder sqlStr = new StringBuilder();
sqlStr.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "check-allow-campaign-status-to-prepare"));
SQLQuery query = session.createSQLQuery(sqlStr.toString());
query.setParameter("p_campaignId", campaignId);
List<Object[]> list = query.list();
if(list.size() > 0) {
result.setData(list.get(0));
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
}
}catch (Exception ex) {
logger.error(ex.getMessage(), ex);
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
}finally {
session.close();
}
return result;
}
}
package com.viettel.campaign.service;
import com.viettel.campaign.model.Campaign;
import com.viettel.campaign.web.dto.CampaignDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
public interface CampaignService {
......@@ -13,6 +17,14 @@ public interface CampaignService {
ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO);
List<Campaign> findAllCondition(Long companySiteId);
List<Campaign> findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(Long siteId, Date startTime, List<Long> status);
List<Campaign> findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(Long siteId, Date startTime, List<Long> status);
Campaign updateProcess(Campaign c);
ResultDTO findByCampaignId(Long campaignId);
ResultDTO addNewCampaign(CampaignDTO campaignDTO);
......@@ -22,4 +34,6 @@ public interface CampaignService {
ResultDTO findCampaignById(Long campaignId);
ResultDTO changeCampaignStatus(CampaignDTO dto);
ResultDTO checkAllowStatusToPrepare(Long campaignId);
}
package com.viettel.campaign.service;
import com.viettel.campaign.model.ProcessConfig;
import com.viettel.campaign.repository.ProcessConfigRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author hanv_itsol
* @project campaign
*/
@Service
@Transactional
public class ProcessConfigService {
@Autowired
private ProcessConfigRepository processConfigRepository;
@Transactional(readOnly = true)
public List<ProcessConfig> findAll(){
return processConfigRepository.findAll();
}
@Transactional(readOnly = true)
public List<ProcessConfig> findAllByCode(String configCode){
return processConfigRepository.findAllByConfigCode(configCode);
}
public void update(ProcessConfig pc){
processConfigRepository.save(pc);
}
}
......@@ -21,6 +21,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
......@@ -58,6 +63,26 @@ public class CampaignServiceImpl implements CampaignService {
return campaignRepository.findByCampaignCode(requestDTO);
}
@Override
public List<Campaign> findAllCondition(Long companySiteId) {
return campaignRepository.findAllByCompanySiteId(companySiteId);
}
@Override
public List<Campaign> findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(Long siteId, Date startTime, List<Long> status) {
return campaignRepository.findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(siteId, startTime, status);
}
@Override
public List<Campaign> findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(Long siteId, Date endTime, List<Long> status) {
return campaignRepository.findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(siteId, endTime, status);
}
@Override
public Campaign updateProcess(Campaign c) {
return campaignRepository.save(c);
}
@Override
public ResultDTO findByCampaignId(Long campaignId) {
ResultDTO result = new ResultDTO();
......@@ -179,6 +204,14 @@ public class CampaignServiceImpl implements CampaignService {
userActionLog.setObjectId(entity.getCampaignId());
if (dto.getStatus().equals((short) -1)) {
userActionLog.setActionType((short) 2);
}
else if(dto.getStatus().equals((short) 4)) {
userActionLog.setActionType((short) 7);
}
else if(dto.getStatus().equals((short) 3)) {
userActionLog.setActionType((short) 4);
}
else if(dto.getStatus().equals((short) 2)) {
} else if (dto.getStatus().equals((short) 5)) {
userActionLog.setActionType((short) 7);
} else if (dto.getStatus().equals((short) 4)) {
......@@ -203,12 +236,17 @@ public class CampaignServiceImpl implements CampaignService {
return result;
}
@Override
public ResultDTO checkAllowStatusToPrepare(Long campaignId) {
return campaignRepository.checkAllowStatusToPrepare(campaignId);
}
private String generateCampaignCode(String campaignType, Short chanel) {
int year = Calendar.getInstance().get(Calendar.YEAR);
String maxIndexStr = campaignRepository.getMaxCampaignIndex();
if (maxIndexStr != null) {
Long maxIndex = Long.valueOf(maxIndexStr) + 1;
String result = campaignType + "_" + String.valueOf(chanel) + "_" + String.valueOf(year) + "_" + maxIndex.toString();
String result = campaignType + "_" + chanel + "_" + year + "_" + maxIndex.toString();
return result;
}
return null;
......
package com.viettel.campaign.utils;
import com.cronutils.model.definition.CronDefinition;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.model.time.ExecutionTime;
import com.cronutils.parser.CronParser;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.quartz.CronExpression;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Optional;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicReference;
import static com.cronutils.model.CronType.QUARTZ;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
/**
* @author anhvd_itsol
*/
@Slf4j
public final class DateTimeUtil {
public static final long DAY_IN_MILLIS = 86400000L;
public static interface DateTimeProvider { long now(); }
......@@ -84,4 +98,26 @@ public final class DateTimeUtil {
/**
*
*/
public static boolean isRun(String cron, Date lastCheck){
boolean isOk = false;
String format="dd-MMM-YYYY hh:mm:ss";
// String cronExpression="* * 12 ? * FRI *";
SimpleDateFormat sdf = new SimpleDateFormat(format);
CronExpression expression = null;
try {
expression = new CronExpression(cron);
} catch (ParseException e) {
e.printStackTrace();
}
Date currentDate = new Date();
assert expression != null;
Date lastDate = expression.getNextValidTimeAfter(lastCheck);
long interval = lastDate.getTime() - currentDate.getTime();
if(interval <= 0){
isOk = true;
}
return isOk;
}
}
......@@ -117,4 +117,9 @@ public class CampaignController {
dto.setSessionId(request.getSession().getId());
return campaignService.changeCampaignStatus(dto);
}
@RequestMapping(value = "/check-allow-status-to-prepare", method = RequestMethod.GET)
public ResultDTO checkAllowStatusToPrepare(@RequestParam("campaignId") Long campaignId) {
return campaignService.checkAllowStatusToPrepare(campaignId);
}
}
WITH COUNT_LIST AS (SELECT (SELECT COUNT(1) FROM CAMPAIGN_CUSTOMER WHERE CAMPAIGN_ID = :p_campaignId) countCamp,
(SELECT COUNT(1) FROM CAMPAIGN_AGENT WHERE CAMPAIGN_ID = :p_campaignId) countAgent,
(select COUNT(1)
FROM SCENARIO s
INNER JOIN SCENARIO_QUESTION sq ON s.SCENARIO_ID = sq.SCENARIO_ID
INNER JOIN SCENARIO_ANSWER sa ON sq.SCENARIO_QUESTION_ID = sa.SCENARIO_QUESTION_ID
WHERE s.CAMPAIGN_ID = :p_campaignId) countScenario
FROM DUAL)
SELECT c.countCamp countCamp,
c.countAgent countAgent,
c.countScenario countScenario,
CASE
WHEN (c.countCamp IS NOT NULL AND c.countAgent IS NOT NULL AND c.countScenario IS NOT NULL) THEN '00'
ELSE '01' END as code
FROM COUNT_LIST c
......@@ -12,7 +12,15 @@ SELECT
a.CUSTOMER_NUMBER cusNum,
b.SLKHThamgiaCD numOfJoinedCus,
c.SLKHChuaTuongTac numOfNotJoinedCus,
d.SLKHDoNotCall_Khoa numOfLockCus
d.SLKHDoNotCall_Khoa numOfLockCus,
a.COMPANY_SITE_ID companySiteId,
a.CONTENT content,
a.MAX_RECALL maxRecall,
a.RECALL_TYPE recallType,
a.RECALL_DURATION recallDuration,
a.CURRENT_TIME_MODE currentTimeMode,
a.WRAPUP_TIME_CONNECT wrapupTimeConnect,
a.WRAPUP_TIME_DISCONNECT wrapupTimeDisconnect
FROM CAMPAIGN a
LEFT JOIN (SELECT campaign_id, COUNT (*) AS SLKHThamgiaCD
FROM campaign_customer cc INNER JOIN CUSTOMER cus ON cc.CUSTOMER_ID = cus.CUSTOMER_ID
......
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