Commit 438c812c authored by Phạm Duy Phi's avatar Phạm Duy Phi

phipd commit

parent 79e56468
This diff is collapsed.
...@@ -32,7 +32,7 @@ public class ApParam implements Serializable { ...@@ -32,7 +32,7 @@ public class ApParam implements Serializable {
private String parCode; private String parCode;
@Column(name = "DESCRIPTION") @Column(name = "DESCRIPTION")
private Long description; private String description;
@Column(name = "IS_DELETE") @Column(name = "IS_DELETE")
private Long isDelete; private Long isDelete;
......
...@@ -4,6 +4,7 @@ import com.viettel.campaign.model.ccms_full.ApParam; ...@@ -4,6 +4,7 @@ import com.viettel.campaign.model.ccms_full.ApParam;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -23,4 +24,12 @@ public interface ApParamRepository extends JpaRepository<ApParam, Long> { ...@@ -23,4 +24,12 @@ public interface ApParamRepository extends JpaRepository<ApParam, Long> {
@Query(value = "FROM ApParam WHERE status = 1 AND parType = :parType") @Query(value = "FROM ApParam WHERE status = 1 AND parType = :parType")
List<ApParam> findAllParam(@Param("parType") String parType); List<ApParam> findAllParam(@Param("parType") String parType);
// ----------- sql lay so thu tu bang customer list ------------ //
@Query("select a from ApParam a where a.parType = 'CUSTOMER_LIST_SEQ'")
ApParam getCustomerListSeq();
@Modifying
@Query("update ApParam a set a.parValue = :p_par_value, a.description = :p_description where a.parType = 'CUSTOMER_LIST_SEQ'")
int updateCustomerListSeq(@Param("p_par_value") String p_par_value, @Param("p_description") String p_description);
} }
...@@ -38,7 +38,7 @@ public interface CustomerService { ...@@ -38,7 +38,7 @@ public interface CustomerService {
// VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY // VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY
ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName); ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName);
ResultDTO updateCustomerList(CustomerListDTO customerListDTO); ResultDTO updateCustomerList(CustomerListDTO customerListDTO, String userName);
ResultDTO deleteCustomerList(CustomerListDTO customerListDTO); ResultDTO deleteCustomerList(CustomerListDTO customerListDTO);
......
...@@ -48,6 +48,7 @@ import java.io.ByteArrayOutputStream; ...@@ -48,6 +48,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -94,6 +95,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -94,6 +95,9 @@ public class CustomerServiceImpl implements CustomerService {
@Autowired @Autowired
CustomizeFieldOptionValueRepository customizeFieldOptionValueRepository; CustomizeFieldOptionValueRepository customizeFieldOptionValueRepository;
@Autowired
ApParamRepository apParamRepository;
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId) { public ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId) {
...@@ -600,6 +604,23 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -600,6 +604,23 @@ public class CustomerServiceImpl implements CustomerService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName) { public ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName) {
ApParam apParam = apParamRepository.getCustomerListSeq();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date currentDate = new Date(dateFormat.format(new Date()));
Date oldDate = new Date(apParam.getDescription());
Long newDay = (currentDate.getTime() - oldDate.getTime())/(1000*60*60*24);
String convertDate = dateFormat.format(new Date());
String[] dateArray = convertDate.split("/");
if (newDay == 0) {
apParamRepository.updateCustomerListSeq(String.valueOf(Integer.parseInt(apParam.getParValue()) + 1), apParam.getDescription());
customerListDTO.setCustomerListCode(dateArray[0]+dateArray[2]+dateArray[1]+"_"+(Integer.parseInt(apParam.getParValue()) + 1)+" "+customerListDTO.getCustomerListCode());
} else {
apParamRepository.updateCustomerListSeq("1", dateFormat.format(new Date()));
customerListDTO.setCustomerListCode(dateArray[0]+dateArray[2]+dateArray[1]+"_1"+" "+customerListDTO.getCustomerListCode());
}
// THÍM NÀO MERGE CONFLICT THÌ GIỮ LẠI HỘ E CÁI METHOD NÀY VỚI // THÍM NÀO MERGE CONFLICT THÌ GIỮ LẠI HỘ E CÁI METHOD NÀY VỚI
// VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY // VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
...@@ -636,9 +657,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -636,9 +657,8 @@ public class CustomerServiceImpl implements CustomerService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO updateCustomerList(CustomerListDTO customerListDTO) { public ResultDTO updateCustomerList(CustomerListDTO customerListDTO, String userName) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper();
try { try {
if (customerListDTO != null) { if (customerListDTO != null) {
...@@ -646,7 +666,19 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -646,7 +666,19 @@ public class CustomerServiceImpl implements CustomerService {
CustomerList customerList = customerListRepository.findByCustomerListIdAndCompanySiteId(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId()); CustomerList customerList = customerListRepository.findByCustomerListIdAndCompanySiteId(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
if (customerList != null) { if (customerList != null) {
customerList = customerListMapper.toPersistenceBean(customerListDTO); customerList.setCreateBy(customerListDTO.getCreateBy());
customerList.setCompanySiteId(customerListDTO.getCompanySiteId());
customerList.setCreateAt(customerListDTO.getCreateAt());
customerList.setCustomerListCode(customerListDTO.getCustomerListCode());
customerList.setCustomerListName(customerListDTO.getCustomerListName());
customerList.setDeptCreate(customerListDTO.getDeptCreate());
customerList.setStatus(customerList.getStatus());
customerList.setUpdateBy(userName);
customerList.setUpdateAt(new Date());
customerList.setSource(customerListDTO.getSource());
customerList.setCustomerListId(customerListDTO.getCustomerListId());
customerListRepository.save(customerList); customerListRepository.save(customerList);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
...@@ -741,21 +773,26 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -741,21 +773,26 @@ public class CustomerServiceImpl implements CustomerService {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("SELECT"); sb.append("SELECT");
sb.append(" CUSTOMER_LIST_ID customerListId,"); sb.append(" a.CUSTOMER_LIST_ID customerListId,");
sb.append(" COMPANY_SITE_ID companySiteId,"); sb.append(" a.COMPANY_SITE_ID companySiteId,");
sb.append(" CUSTOMER_LIST_CODE customerListCode,"); sb.append(" a.CUSTOMER_LIST_CODE customerListCode,");
sb.append(" CUSTOMER_LIST_NAME customerListName,"); sb.append(" a.CUSTOMER_LIST_NAME customerListName,");
sb.append(" STATUS status,"); sb.append(" a.STATUS status,");
sb.append(" CREATE_BY createBy,"); sb.append(" a.CREATE_BY createBy,");
sb.append(" CREATE_AT createAt,"); sb.append(" a.CREATE_AT createAt,");
sb.append(" UPDATE_BY updateBy,"); sb.append(" a.UPDATE_BY updateBy,");
sb.append(" UPDATE_AT updateAt,"); sb.append(" a.UPDATE_AT updateAt,");
sb.append(" SOURCE source,"); sb.append(" a.SOURCE source,");
sb.append(" DEPT_CREATE deptCreate"); sb.append(" a.DEPT_CREATE deptCreate,");
sb.append(" FROM CUSTOMER_LIST"); sb.append(" b.count count");
sb.append(" FROM CUSTOMER_LIST a");
sb.append(" LEFT JOIN (SELECT COUNT(CAMPAIGN_ID) as count, CUSTOMER_LIST_ID");
sb.append(" FROM CAMPAIGN_CUSTOMERLIST");
sb.append(" GROUP BY CUSTOMER_LIST_ID) b");
sb.append(" ON a.CUSTOMER_LIST_ID = b.CUSTOMER_LIST_ID");
sb.append(" WHERE 1 = 1"); sb.append(" WHERE 1 = 1");
sb.append(" AND STATUS = 1"); sb.append(" AND a.STATUS = 1");
sb.append(" AND COMPANY_SITE_ID = :p_company_site_id"); sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND CREATE_AT BETWEEN to_date(:p_date_from, 'YYYYMMDD') AND to_date(:p_date_to, 'YYYYMMDD')"); sb.append(" AND CREATE_AT BETWEEN to_date(:p_date_from, 'YYYYMMDD') AND to_date(:p_date_to, 'YYYYMMDD')");
...@@ -766,6 +803,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -766,6 +803,8 @@ public class CustomerServiceImpl implements CustomerService {
sb.append(" AND CUSTOMER_LIST_NAME LIKE :p_list_name"); sb.append(" AND CUSTOMER_LIST_NAME LIKE :p_list_name");
} }
sb.append(" ORDER BY CREATE_AT DESC");
SQLQuery query = session.createSQLQuery(sb.toString()); SQLQuery query = session.createSQLQuery(sb.toString());
query.setParameter("p_company_site_id", searchCustomerRequestDTO.getCompanySiteId()); query.setParameter("p_company_site_id", searchCustomerRequestDTO.getCompanySiteId());
...@@ -801,6 +840,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -801,6 +840,7 @@ public class CustomerServiceImpl implements CustomerService {
query.addScalar("updateAt", new DateType()); query.addScalar("updateAt", new DateType());
query.addScalar("source", new StringType()); query.addScalar("source", new StringType());
query.addScalar("deptCreate", new StringType()); query.addScalar("deptCreate", new StringType());
query.addScalar("count", new StringType());
query.setResultTransformer(Transformers.aliasToBean(CustomerListDTO.class)); query.setResultTransformer(Transformers.aliasToBean(CustomerListDTO.class));
int count = 0; int count = 0;
......
...@@ -12,7 +12,7 @@ public class ApParamDTO extends BaseDTO { ...@@ -12,7 +12,7 @@ public class ApParamDTO extends BaseDTO {
private String parName; private String parName;
private String parValue; private String parValue;
private String parCode; private String parCode;
private Long description; private String description;
private Long isDelete; private Long isDelete;
private Long isDefault; private Long isDefault;
private Long enableEdit; private Long enableEdit;
......
...@@ -123,10 +123,15 @@ public class CustomerController { ...@@ -123,10 +123,15 @@ public class CustomerController {
@PostMapping("/updateCustomerList") @PostMapping("/updateCustomerList")
@ResponseBody @ResponseBody
public ResultDTO updateCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO) { public ResultDTO updateCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO, HttpServletRequest request) {
ResultDTO result = new ResultDTO(); String xAuthToken = request.getHeader("X-Auth-Token");
result = customerService.updateCustomerList(customerListDTO); UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken);
return result; if (userSession == null) {
userSession = new UserSession();
userSession.setSiteId(customerListDTO.getCompanySiteId());
userSession.setUserName("its4");
}
return customerService.updateCustomerList(customerListDTO, userSession.getUserName());
} }
@PostMapping("/deleteCustomerList") @PostMapping("/deleteCustomerList")
......
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