Commit b918a41e authored by Phạm Duy Phi's avatar Phạm Duy Phi

phipd commit

parent eccfdb95
...@@ -19,5 +19,7 @@ public interface AgentsService { ...@@ -19,5 +19,7 @@ public interface AgentsService {
ResultDTO searchCampaignAgentByName(int page, int pageSize, Long companySiteId, String userName, String fullName); ResultDTO searchCampaignAgentByName(int page, int pageSize, Long companySiteId, String userName, String fullName);
ResultDTO searchCampaignAgentSelectByName(int page, int pageSize, Long companySiteId, Long campaignId, String userName, String fullName);
ResultDTO createMultipleCampaignAgent(CampaignAgentRequestDTO campaignAgentRequestDTO); ResultDTO createMultipleCampaignAgent(CampaignAgentRequestDTO campaignAgentRequestDTO);
} }
...@@ -88,13 +88,18 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -88,13 +88,18 @@ public class AgentsServiceImpl implements AgentsService {
sb.append(" a.FULL_NAME fullName,"); sb.append(" a.FULL_NAME fullName,");
sb.append(" a.COMPANY_SITE_ID companySiteId,"); sb.append(" a.COMPANY_SITE_ID companySiteId,");
sb.append(" b.FILTER_TYPE filterType,"); sb.append(" b.FILTER_TYPE filterType,");
sb.append(" b.CAMPAIGN_AGENT_ID campaignAgentId"); sb.append(" b.CAMPAIGN_AGENT_ID campaignAgentId,");
sb.append(" d.ROLE_CODE roleCode");
sb.append(" FROM VSA_USERS a"); sb.append(" FROM VSA_USERS a");
sb.append(" LEFT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID"); sb.append(" LEFT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID");
sb.append(" INNER JOIN USER_ROLE c on a.USER_ID = c.USER_ID");
sb.append(" INNER JOIN ROLE d on c.ROLE_ID = d.ROLE_ID");
sb.append(" WHERE 1 = 1"); sb.append(" WHERE 1 = 1");
sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id"); sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND a.STATUS = 1");
sb.append(" AND b.AGENT_ID IS NULL"); sb.append(" AND b.AGENT_ID IS NULL");
sb.append(" ORDER BY a.FULL_NAME ASC"); sb.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')");
sb.append(" ORDER BY UPPER(a.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sb.toString()); SQLQuery query = session.createSQLQuery(sb.toString());
...@@ -107,6 +112,7 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -107,6 +112,7 @@ public class AgentsServiceImpl implements AgentsService {
query.addScalar("companySiteId", new LongType()); query.addScalar("companySiteId", new LongType());
query.addScalar("filterType", new ShortType()); query.addScalar("filterType", new ShortType());
query.addScalar("campaignAgentId", new LongType()); query.addScalar("campaignAgentId", new LongType());
query.addScalar("roleCode", new StringType());
query.setResultTransformer(Transformers.aliasToBean(VSAUsersDTO.class)); query.setResultTransformer(Transformers.aliasToBean(VSAUsersDTO.class));
int count = 0; int count = 0;
...@@ -157,20 +163,21 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -157,20 +163,21 @@ public class AgentsServiceImpl implements AgentsService {
sb.append("SELECT"); sb.append("SELECT");
sb.append(" a.USER_ID userId,"); sb.append(" a.CAMPAIGN_AGENT_ID campaignAgentId,");
sb.append(" a.USER_NAME userName,"); sb.append(" a.FILTER_TYPE filterType,");
sb.append(" a.STATUS status,");
sb.append(" a.FULL_NAME fullName,");
sb.append(" a.COMPANY_SITE_ID companySiteId,"); sb.append(" a.COMPANY_SITE_ID companySiteId,");
sb.append(" b.FILTER_TYPE filterType,"); sb.append(" b.USER_ID userId,");
sb.append(" b.CAMPAIGN_AGENT_ID campaignAgentId"); sb.append(" b.USER_NAME userName,");
sb.append(" FROM VSA_USERS a"); sb.append(" b.STATUS status,");
sb.append(" b.FULL_NAME fullName");
sb.append(" FROM CAMPAIGN_AGENT a");
sb.append(" RIGHT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID"); sb.append(" INNER JOIN VSA_USERS b ON a.AGENT_ID = b.USER_ID");
sb.append(" WHERE 1 = 1"); sb.append(" WHERE 1 = 1");
sb.append(" AND b.COMPANY_SITE_ID = :p_company_site_id"); sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND b.CAMPAIGN_ID = :p_campaign_id"); sb.append(" AND a.CAMPAIGN_ID = :p_campaign_id");
sb.append(" ORDER BY a.FULL_NAME ASC"); sb.append(" ORDER BY UPPER(b.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sb.toString()); SQLQuery query = session.createSQLQuery(sb.toString());
...@@ -295,8 +302,8 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -295,8 +302,8 @@ public class AgentsServiceImpl implements AgentsService {
sqlStrBuilder.append(" b.CAMPAIGN_AGENT_ID campaignAgentId"); sqlStrBuilder.append(" b.CAMPAIGN_AGENT_ID campaignAgentId");
sqlStrBuilder.append(" FROM VSA_USERS a"); sqlStrBuilder.append(" FROM VSA_USERS a");
sqlStrBuilder.append(" LEFT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID"); sqlStrBuilder.append(" LEFT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID");
sqlStrBuilder.append(" JOIN USER_ROLE c on a.USER_ID = c.USER_ID"); sqlStrBuilder.append(" INNER JOIN USER_ROLE c on a.USER_ID = c.USER_ID");
sqlStrBuilder.append(" JOIN ROLE d on c.ROLE_ID = d.ROLE_ID"); sqlStrBuilder.append(" INNER JOIN ROLE d on c.ROLE_ID = d.ROLE_ID");
sqlStrBuilder.append(" WHERE 1 = 1"); sqlStrBuilder.append(" WHERE 1 = 1");
sqlStrBuilder.append(" AND a.COMPANY_SITE_ID = :p_company_site_id"); sqlStrBuilder.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
...@@ -310,8 +317,8 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -310,8 +317,8 @@ public class AgentsServiceImpl implements AgentsService {
sqlStrBuilder.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')"); sqlStrBuilder.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')");
sqlStrBuilder.append(" AND a.STATUS = 1"); sqlStrBuilder.append(" AND a.STATUS = 1");
sqlStrBuilder.append(" AND b.CAMPAIGN_AGENT_ID IS NULL"); sqlStrBuilder.append(" AND b.AGENT_ID IS NULL");
sqlStrBuilder.append(" ORDER BY a.FULL_NAME ASC"); sqlStrBuilder.append(" ORDER BY UPPER(a.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString()); SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
...@@ -319,7 +326,112 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -319,7 +326,112 @@ public class AgentsServiceImpl implements AgentsService {
if (!DataUtil.isNullOrEmpty(userName)) { if (!DataUtil.isNullOrEmpty(userName)) {
query.setParameter("p_user_name", "%" + query.setParameter("p_user_name", "%" +
userName userName.trim()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
if (!DataUtil.isNullOrEmpty(fullName)) {
query.setParameter("p_full_name", "%" +
fullName.trim()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
query.addScalar("userId", new LongType());
query.addScalar("userName", new StringType());
query.addScalar("status", new ShortType());
query.addScalar("fullName", new StringType());
query.addScalar("companySiteId", new LongType());
query.addScalar("filterType", new ShortType());
query.addScalar("campaignAgentId", new LongType());
query.setResultTransformer(Transformers.aliasToBean(VSAUsersDTO.class));
int count = 0;
List<VSAUsersDTO> dtoList = query.list();
if (dtoList.size() > 0) {
count = query.list().size();
}
Pageable pageable = PageRequest.of(page, pageSize);
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<VSAUsersDTO> data = query.list();
Page<VSAUsersDTO> dataPage = new PageImpl<>(data, pageable, count);
resultDTO.setData(dataPage);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally {
session.close();
}
return resultDTO;
}
@Override
public ResultDTO searchCampaignAgentSelectByName(int page, int pageSize, Long companySiteId, Long campaignId, String userName, String fullName) {
ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
if (DataUtil.isNullOrZero(companySiteId)) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return resultDTO;
}
try {
// StringBuilder sb = new StringBuilder();
// sb.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-agents-by-params"));
StringBuilder sb = new StringBuilder();
sb.append("SELECT");
sb.append(" a.CAMPAIGN_AGENT_ID campaignAgentId,");
sb.append(" a.FILTER_TYPE filterType,");
sb.append(" a.COMPANY_SITE_ID companySiteId,");
sb.append(" b.USER_ID userId,");
sb.append(" b.USER_NAME userName,");
sb.append(" b.STATUS status,");
sb.append(" b.FULL_NAME fullName");
sb.append(" FROM CAMPAIGN_AGENT a");
sb.append(" INNER JOIN VSA_USERS b ON a.AGENT_ID = b.USER_ID");
sb.append(" WHERE 1 = 1");
sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND a.CAMPAIGN_ID = :p_campaign_id");
if (!DataUtil.isNullOrEmpty(userName)) {
sb.append(" AND UPPER(b.USER_NAME) LIKE UPPER(:p_user_name)");
}
if (!DataUtil.isNullOrEmpty(fullName)) {
sb.append(" AND UPPER(b.FULL_NAME) LIKE UPPER(:p_full_name)");
}
sb.append(" ORDER BY UPPER(b.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sb.toString());
query.setParameter("p_company_site_id", companySiteId);
query.setParameter("p_campaign_id", campaignId);
if (!DataUtil.isNullOrEmpty(userName)) {
query.setParameter("p_user_name", "%" +
userName.trim()
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replaceAll("%", "\\%") .replaceAll("%", "\\%")
.replaceAll("_", "\\_") .replaceAll("_", "\\_")
...@@ -328,7 +440,7 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -328,7 +440,7 @@ public class AgentsServiceImpl implements AgentsService {
if (!DataUtil.isNullOrEmpty(fullName)) { if (!DataUtil.isNullOrEmpty(fullName)) {
query.setParameter("p_full_name", "%" + query.setParameter("p_full_name", "%" +
fullName fullName.trim()
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replaceAll("%", "\\%") .replaceAll("%", "\\%")
.replaceAll("_", "\\_") .replaceAll("_", "\\_")
......
...@@ -850,7 +850,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -850,7 +850,7 @@ public class CustomerServiceImpl implements CustomerService {
count = query.list().size(); count = query.list().size();
} }
Pageable pageable = PageRequest.of(searchCustomerRequestDTO.getPage(), searchCustomerRequestDTO.getPageSize(), Sort.by(searchCustomerRequestDTO.getSort())); Pageable pageable = PageRequest.of(searchCustomerRequestDTO.getPage(), searchCustomerRequestDTO.getPageSize(), Sort.by(searchCustomerRequestDTO.getSort()).descending());
if (pageable != null) { if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize()); query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize()); query.setMaxResults(pageable.getPageSize());
......
...@@ -35,4 +35,5 @@ public class VSAUsersDTO { ...@@ -35,4 +35,5 @@ public class VSAUsersDTO {
// String userKazooId; // String userKazooId;
Short filterType; Short filterType;
Long campaignAgentId; Long campaignAgentId;
String roleCode;
} }
...@@ -68,6 +68,13 @@ public class AgentsController { ...@@ -68,6 +68,13 @@ public class AgentsController {
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
@GetMapping("/searchCampaignAgentSelect")
@ResponseBody
public ResponseEntity<ResultDTO> searchCampaignAgentSelect(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId, @RequestParam("campaignId") Long campaignId, @RequestParam("userName") String userName, @RequestParam("fullName") String fullName) {
ResultDTO result = agentsService.searchCampaignAgentSelectByName(page, pageSize, companySiteId, campaignId, userName, fullName);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/createMultipleCampaignAgent") @PostMapping("/createMultipleCampaignAgent")
@ResponseBody @ResponseBody
public ResultDTO createMultipleCampaignAgent(@RequestBody @Valid CampaignAgentRequestDTO campaignAgentRequestDTO) { public ResultDTO createMultipleCampaignAgent(@RequestBody @Valid CampaignAgentRequestDTO campaignAgentRequestDTO) {
......
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