Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
service-campaign
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyen Ha
service-campaign
Commits
dc1821a0
Commit
dc1821a0
authored
Jul 30, 2019
by
Vu Duy Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
anhvd commit hibernate util + campaign mng services
parent
0ccb72e3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
145 additions
and
54 deletions
+145
-54
pom.xml
pom.xml
+2
-0
src/main/java/com/viettel/campaign/dto/BaseDTO.java
src/main/java/com/viettel/campaign/dto/BaseDTO.java
+3
-0
src/main/java/com/viettel/campaign/dto/request_dto/CampaignRequestDTO.java
.../viettel/campaign/dto/request_dto/CampaignRequestDTO.java
+2
-4
src/main/java/com/viettel/campaign/repository/impl/CampaignRepositoryImpl.java
...ttel/campaign/repository/impl/CampaignRepositoryImpl.java
+79
-29
src/main/java/com/viettel/campaign/utils/HibernateUtil.java
src/main/java/com/viettel/campaign/utils/HibernateUtil.java
+42
-0
src/main/resources/hibernate.cfg.xml
src/main/resources/hibernate.cfg.xml
+16
-0
src/main/resources/sql/campaign-mng/search-campaign-by-params.sql
.../resources/sql/campaign-mng/search-campaign-by-params.sql
+1
-21
No files found.
pom.xml
View file @
dc1821a0
...
...
@@ -93,6 +93,8 @@
<dependency>
<groupId>
com.oracle
</groupId>
<artifactId>
ojdbc7
</artifactId>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/lib/ojdbc7.jar</systemPath>-->
<version>
1.0
</version>
</dependency>
<dependency>
...
...
src/main/java/com/viettel/campaign/dto/BaseDTO.java
View file @
dc1821a0
...
...
@@ -10,4 +10,7 @@ import java.io.Serializable;
public
class
BaseDTO
implements
Serializable
{
protected
String
keySet
;
protected
int
pageSize
;
protected
int
page
;
protected
String
sort
;
}
src/main/java/com/viettel/campaign/dto/request_dto/CampaignRequestDTO.java
View file @
dc1821a0
package
com.viettel.campaign.dto.request_dto
;
import
com.viettel.campaign.dto.BaseDTO
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -12,10 +13,7 @@ import java.util.Date;
@Getter
@Setter
public
class
CampaignRequestDTO
{
int
pageSize
;
int
page
;
String
sort
;
public
class
CampaignRequestDTO
extends
BaseDTO
{
String
campaignCode
;
String
campaignName
;
Short
status
;
...
...
src/main/java/com/viettel/campaign/repository/impl/CampaignRepositoryImpl.java
View file @
dc1821a0
...
...
@@ -3,14 +3,20 @@ package com.viettel.campaign.repository.impl;
import
com.viettel.campaign.dto.CampaignDTO
;
import
com.viettel.campaign.dto.ResultDTO
;
import
com.viettel.campaign.dto.request_dto.CampaignRequestDTO
;
import
com.viettel.campaign.model.Campaign
;
import
com.viettel.campaign.repository.CampaignRepositoryCustom
;
import
com.viettel.campaign.utils.Constants
;
import
com.viettel.campaign.utils.DataUtil
;
import
com.viettel.campaign.utils.DateTimeUtil
;
import
com.viettel.campaign.utils.SQLBuilder
;
import
com.viettel.campaign.utils.*
;
import
org.hibernate.SQLQuery
;
import
org.hibernate.Session
;
import
org.hibernate.SessionFactory
;
import
org.hibernate.hql.internal.ast.util.SessionFactoryHelper
;
import
org.hibernate.transform.Transformers
;
import
org.hibernate.type.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.*
;
import
org.springframework.jdbc.object.SqlQuery
;
import
org.springframework.stereotype.Repository
;
import
sun.jvm.hotspot.ui.action.ShowAction
;
import
javax.persistence.EntityManager
;
import
javax.persistence.Query
;
...
...
@@ -42,8 +48,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
for
(
Object
[]
obj
:
data
)
{
CampaignDTO
item
=
new
CampaignDTO
();
item
.
setCampaignId
((
Long
)
obj
[
0
]);
item
.
setCampaignName
((
String
)
obj
[
1
]);
item
.
setCampaignId
((
Long
)
obj
[
0
]);
item
.
setCampaignName
((
String
)
obj
[
1
]);
item
.
setStatus
((
Short
)
obj
[
0
]);
lst
.
add
(
item
);
...
...
@@ -56,26 +62,49 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
public
ResultDTO
search
(
CampaignRequestDTO
requestDto
)
{
ResultDTO
result
=
new
ResultDTO
();
try
{
String
sqlStr
=
SQLBuilder
.
getSqlQueryById
(
SQLBuilder
.
SQL_MODULE_CAMPAIGN_MNG
,
"search-campaign-by-params"
);
// sqlStr.append(" SELECT CAMPAIGN_CODE campaignCode, CAMPAIGN_NAME campaignName, CAMPAIGN_TYPE campaignType, CHANEL chanel, START_TIME startTime, END_TIME endTime, CUSTOMER_NUMBER customerNumber, STATUS status FROM CAMPAIGN WHERE 1 = 1 ");
// if(!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) { sqlStr.append(" AND UPPER(CAMPAIGN_CODE) LIKE :code"); }
// if(!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) { sqlStr.append(" AND UPPER(CAMPAIGN_NAME) LIKE :name"); }
// if(requestDto.getStatus() != null) { sqlStr.append(" AND STATUS = :status"); }
// if(requestDto.getFromDateFr() != null && DateTimeUtil.isValid(requestDto.getFromDateFr().getTime())) { sqlStr.append(" AND START_TIME >= :frDateFr"); }
// if(requestDto.getFromDateTo() != null && DateTimeUtil.isValid(requestDto.getFromDateTo().getTime())) { sqlStr.append(" AND START_TIME <= :frDateTo"); }
// if(requestDto.getToDateFr() != null && DateTimeUtil.isValid(requestDto.getToDateFr().getTime())) { sqlStr.append(" AND END_TIME >= :toDateFr"); }
// if(requestDto.getToDateTo() != null && DateTimeUtil.isValid(requestDto.getToDateTo().getTime())) { sqlStr.append(" AND END_TIME <= :toDateTo"); }
// if(!DataUtil.isNullOrZero(requestDto.getNumOfCusFr())) {
//// sqlStr.append(" AND ")
// }
// if(!DataUtil.isNullOrZero(requestDto.getNumOfCusTo())) {
//
// }
// if(requestDto.getType() != null) { sqlStr.append(" AND CAMPAIGN_TYPE = :type"); }
// if(requestDto.getChanel() != null) { sqlStr.append(" AND CHANEL = :chanel"); }
SessionFactory
sessionFactory
=
HibernateUtil
.
getSessionFactory
();
Session
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
Query
query
=
entityManager
.
createNativeQuery
(
sqlStr
,
CampaignDTO
.
class
);
StringBuilder
sqlStr
=
new
StringBuilder
();
sqlStr
.
append
(
SQLBuilder
.
getSqlQueryById
(
SQLBuilder
.
SQL_MODULE_CAMPAIGN_MNG
,
"search-campaign-by-params"
));
if
(!
DataUtil
.
isNullOrEmpty
(
requestDto
.
getCampaignCode
()))
{
sqlStr
.
append
(
" AND UPPER(CAMPAIGN_CODE) LIKE :p_code"
);
}
if
(!
DataUtil
.
isNullOrEmpty
(
requestDto
.
getCampaignName
()))
{
sqlStr
.
append
(
" AND UPPER(CAMPAIGN_NAME) LIKE :p_name"
);
}
if
(
requestDto
.
getStatus
()
!=
null
)
{
sqlStr
.
append
(
" AND STATUS = :p_status"
);
}
if
(
requestDto
.
getFromDateFr
()
!=
null
&&
DateTimeUtil
.
isValid
(
requestDto
.
getFromDateFr
().
getTime
()))
{
sqlStr
.
append
(
" AND START_TIME >= :p_frDateFr"
);
}
if
(
requestDto
.
getFromDateTo
()
!=
null
&&
DateTimeUtil
.
isValid
(
requestDto
.
getFromDateTo
().
getTime
()))
{
sqlStr
.
append
(
" AND START_TIME <= :p_frDateTo"
);
}
if
(
requestDto
.
getToDateFr
()
!=
null
&&
DateTimeUtil
.
isValid
(
requestDto
.
getToDateFr
().
getTime
()))
{
sqlStr
.
append
(
" AND END_TIME >= :p_toDateFr"
);
}
if
(
requestDto
.
getToDateTo
()
!=
null
&&
DateTimeUtil
.
isValid
(
requestDto
.
getToDateTo
().
getTime
()))
{
sqlStr
.
append
(
" AND END_TIME <= :p_toDateTo"
);
}
if
(!
DataUtil
.
isNullOrZero
(
requestDto
.
getNumOfCusFr
()))
{
// sqlStr.append(" AND ")
}
if
(!
DataUtil
.
isNullOrZero
(
requestDto
.
getNumOfCusTo
()))
{
}
if
(
requestDto
.
getType
()
!=
null
)
{
sqlStr
.
append
(
" AND CAMPAIGN_TYPE = :p_type"
);
}
if
(
requestDto
.
getChanel
()
!=
null
)
{
sqlStr
.
append
(
" AND CHANEL = :p_chanel"
);
}
// Query query = entityManager.createNativeQuery(sqlStr.toString(), Campaign.class);
SQLQuery
query
=
session
.
createSQLQuery
(
sqlStr
.
toString
());
if
(!
DataUtil
.
isNullOrEmpty
(
requestDto
.
getCampaignCode
()))
{
query
.
setParameter
(
"p_code"
,
"%"
+
requestDto
.
getCampaignCode
().
toUpperCase
()
...
...
@@ -84,6 +113,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
.
replaceAll
(
"_"
,
"\\\\_"
)
+
"%"
);
}
if
(!
DataUtil
.
isNullOrEmpty
(
requestDto
.
getCampaignName
()))
{
query
.
setParameter
(
"p_name"
,
"%"
+
requestDto
.
getCampaignName
().
toUpperCase
()
...
...
@@ -92,6 +122,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
.
replaceAll
(
"_"
,
"\\\\_"
)
+
"%"
);
}
if
(
requestDto
.
getStatus
()
!=
null
)
{
query
.
setParameter
(
"p_status"
,
requestDto
.
getStatus
());
}
...
...
@@ -114,21 +145,35 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
query
.
setParameter
(
"p_chanel"
,
requestDto
.
getChanel
());
}
List
<
CampaignDTO
>
dataCount
=
query
.
getResultList
();
long
count
=
dataCount
.
size
();
query
.
addScalar
(
"campaignId"
,
new
LongType
());
query
.
addScalar
(
"campaignCode"
,
new
StringType
());
query
.
addScalar
(
"campaignName"
,
new
StringType
());
query
.
addScalar
(
"campaignType"
,
new
StringType
());
query
.
addScalar
(
"chanel"
,
new
ShortType
());
query
.
addScalar
(
"startTime"
,
new
DateType
());
query
.
addScalar
(
"endTime"
,
new
DateType
());
query
.
addScalar
(
"customerNumber"
,
new
LongType
());
query
.
addScalar
(
"status"
,
new
ShortType
());
query
.
setResultTransformer
(
Transformers
.
aliasToBean
(
CampaignDTO
.
class
));
int
count
=
0
;
List
<
CampaignDTO
>
list
=
query
.
list
();
if
(
list
.
size
()
>
0
)
{
count
=
query
.
list
().
size
();
}
Pageable
pageable
=
buildPageable
(
requestDto
);
if
(
pageable
!=
null
)
{
query
.
setFirstResult
(
pageable
.
getPageNumber
()
*
pageable
.
getPageSize
());
query
.
setMaxResults
(
pageable
.
getPageSize
());
}
List
<
CampaignDTO
>
data
=
query
.
getResultL
ist
();
List
<
CampaignDTO
>
data
=
query
.
l
ist
();
Page
<
CampaignDTO
>
dataPage
=
new
PageImpl
<>(
data
,
pageable
,
count
);
result
.
setData
(
dataPage
);
result
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
result
.
setDescription
(
Constants
.
ApiErrorDesc
.
SUCCESS
);
session
.
close
();
return
result
;
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
}
result
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
...
...
@@ -143,4 +188,9 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
pageable
=
new
PageRequest
(
obj
.
getPage
(),
obj
.
getPageSize
(),
sort
);
return
pageable
;
}
// private CampaignDTO mappingData(Object[] object) {
// CampaignDTO dto = new CampaignDTO();
//
// }
}
src/main/java/com/viettel/campaign/utils/HibernateUtil.java
0 → 100644
View file @
dc1821a0
package
com.viettel.campaign.utils
;
import
org.hibernate.SessionFactory
;
import
org.hibernate.boot.registry.StandardServiceRegistryBuilder
;
import
org.hibernate.cfg.Configuration
;
import
org.hibernate.service.ServiceRegistry
;
/**
* @author anhvd_itsol
*/
public
class
HibernateUtil
{
private
static
SessionFactory
sessionFactory
=
buildSessionFactory
();
private
static
SessionFactory
buildSessionFactory
()
{
try
{
if
(
sessionFactory
==
null
)
{
Configuration
configuration
=
new
Configuration
().
configure
(
HibernateUtil
.
class
.
getResource
(
"/hibernate.cfg.xml"
));
StandardServiceRegistryBuilder
serviceRegistryBuilder
=
new
StandardServiceRegistryBuilder
();
serviceRegistryBuilder
.
applySettings
(
configuration
.
getProperties
());
ServiceRegistry
serviceRegistry
=
serviceRegistryBuilder
.
build
();
sessionFactory
=
configuration
.
buildSessionFactory
(
serviceRegistry
);
}
return
sessionFactory
;
}
catch
(
Throwable
ex
)
{
System
.
err
.
println
(
"Initial SessionFactory creation failed."
+
ex
);
throw
new
ExceptionInInitializerError
(
ex
);
}
}
public
static
SessionFactory
getSessionFactory
()
{
return
sessionFactory
;
}
public
static
void
shutdown
()
{
getSessionFactory
().
close
();
}
}
src/main/resources/hibernate.cfg.xml
0 → 100644
View file @
dc1821a0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name=
"hibernate.connection.driver_class"
>
oracle.jdbc.driver.OracleDriver
</property>
<property
name=
"hibernate.connection.url"
>
jdbc:oracle:thin:@10.60.157.135:1521:vt
</property>
<property
name=
"hibernate.connection.username"
>
CCMS_FULL
</property>
<property
name=
"hibernate.connection.password"
>
CCMS_FULL#123
</property>
<property
name=
"hibernate.connection.pool_size"
>
64
</property>
<property
name=
"hibernate.current_session_context_class"
>
thread
</property>
<property
name=
"hibernate.show_sql"
>
true
</property>
<property
name=
"hibernate.dialect"
>
org.hibernate.dialect.Oracle10gDialect
</property>
</session-factory>
</hibernate-configuration>
src/main/resources/sql/campaign-mng/search-campaign-by-params.sql
View file @
dc1821a0
SELECT
CAMPAIGN_ID
campaignId
,
CAMPAIGN_CODE
campaignCode
,
CAMPAIGN_NAME
campaignName
,
CAMPAIGN_TYPE
campaignType
,
...
...
@@ -9,24 +10,3 @@ SELECT
STATUS
status
FROM
CAMPAIGN
WHERE
1
=
1
AND
(:
p_code
IS
NULL
OR
(:
p_code
IS
NOT
NULL
AND
UPPER
(
CAMPAIGN_CODE
)
LIKE
:
p_code
))
AND
(:
p_name
IS
NULL
OR
(:
p_name
IS
NOT
NULL
AND
UPPER
(
CAMPAIGN_NAME
)
LIKE
:
p_name
))
AND
(:
p_status
IS
NULL
OR
(:
p_status
IS
NOT
NULL
AND
STATUS
=
:
status
))
AND
((:
p_frDateFr
IS
NULL
AND
:
p_frDateTo
IS
NULL
)
OR
((:
p_frDateFr
IS
NOT
NULL
AND
:
p_frDateTo
IS
NOT
NULL
)
AND
(
trunc
(
START_TIME
)
BETWEEN
TO_DATE
(:
p_frDateFr
,
'YYYYMMDD'
)
AND
TO_DATE
(:
p_frDateTo
,
'YYYYMMDD'
)))
OR
((:
p_frDateFr
IS
NOT
NULL
AND
:
p_frDateTo
IS
NULL
)
AND
(
trunc
(
START_TIME
)
>=
TO_DATE
(:
p_frDateFr
,
'YYYYMMDD'
)))
OR
((:
p_frDateFr
IS
NULL
AND
:
p_frDateTo
IS
NOT
NULL
)
AND
(
trunc
(
START_TIME
)
<=
TO_DATE
(:
p_frDateTo
,
'YYYYMMDD'
)))
)
AND
((:
p_toDateFr
IS
NULL
AND
:
p_toDateTo
IS
NULL
)
OR
((:
p_toDateFr
IS
NOT
NULL
AND
:
p_toDateTo
IS
NOT
NULL
)
AND
(
trunc
(
END_TIME
)
BETWEEN
TO_DATE
(:
p_toDateFr
,
'YYYYMMDD'
)
AND
TO_DATE
(:
p_toDateTo
,
'YYYYMMDD'
)))
OR
((:
p_toDateFr
IS
NOT
NULL
AND
:
p_toDateTo
IS
NULL
)
AND
(
trunc
(
END_TIME
)
>=
TO_DATE
(:
p_toDateFr
,
'YYYYMMDD'
)))
OR
((:
p_toDateFr
IS
NULL
AND
:
p_toDateTo
IS
NOT
NULL
)
AND
(
trunc
(
END_TIME
)
<=
TO_DATE
(:
p_toDateTo
,
'YYYYMMDD'
)))
)
AND
(:
p_type
IS
NULL
OR
(:
p_type
IS
NOT
NULL
AND
CAMPAIGN_TYPE
=
:
p_type
))
AND
(:
p_chanel
IS
NULL
OR
(:
p_chanel
IS
NOT
NULl
AND
CHANEL
=
:
p_chanel
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment