Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ufo
/
ufo-platform
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
chenchao
5 years ago
Commit
6c014b6824b10f9f00b91960bfd33bb823caff53
1 parent
3db9495c
add retrieve and update display
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
6 deletions
coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java
dal/src/main/java/com/yoho/ufo/dal/CouponDisplayMapper.java
dal/src/main/java/com/yoho/ufo/dal/model/CouponDisplay.java
dal/src/main/resources/META-INF/mybatis/CouponDisplayMapper.xml
web/src/main/resources/databases.yml
web/src/main/webapp/META-INF/autoconf/databases.yml
coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java
View file @
6c014b6
...
...
@@ -7,11 +7,14 @@ import com.google.common.base.Splitter;
import
com.google.common.collect.Iterables
;
import
com.google.common.collect.Lists
;
import
com.yoho.core.rabbitmq.YhProducer
;
import
com.yoho.core.rest.client.ServiceCaller
;
import
com.yoho.error.exception.ServiceException
;
import
com.yoho.ufo.coupon.service.ICouponService
;
import
com.yoho.ufo.dal.CouponDisplayMapper
;
import
com.yoho.ufo.dal.CouponMapper
;
import
com.yoho.ufo.dal.CouponProductLimitMapper
;
import
com.yoho.ufo.dal.UserCouponMapper
;
import
com.yoho.ufo.dal.model.CouponDisplay
;
import
com.yoho.ufo.dal.model.UidImportTranItem
;
import
com.yoho.ufo.exception.PlatformException
;
import
com.yoho.ufo.model.coupon.Coupon
;
...
...
@@ -28,7 +31,10 @@ import com.yoho.ufo.service.model.ApiResponse;
import
com.yohobuy.ufo.coupon.req.*
;
import
com.yohobuy.ufo.model.common.PageResponseBO
;
import
com.yohobuy.ufo.model.order.constants.SkupType
;
import
com.yohobuy.ufo.model.promotion.CouponDisplayBo
;
import
com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum
;
import
com.yohobuy.ufo.model.promotion.constant.PositionType
;
import
com.yohobuy.ufo.model.promotion.constant.Visibility
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.math.NumberUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -56,6 +62,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
private
CouponMapper
couponMapper
;
@Autowired
private
CouponDisplayMapper
couponDisplayMapper
;
@Autowired
private
CouponProductLimitMapper
couponProductLimitMapper
;
@Autowired
...
...
@@ -70,6 +79,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
@Resource
(
name
=
"yhProducer"
)
private
YhProducer
yhProducer
;
@Autowired
private
ServiceCaller
serviceCaller
;
@Override
public
Class
getDataClass
()
{
return
(
Class
)
request
.
getAttribute
(
"exportClassType"
);
...
...
@@ -210,7 +222,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
throw
new
ServiceException
(
400
,
"错误:优惠券信息不存在"
);
}
}
Integer
couponId
;
// 插入
if
(
Objects
.
isNull
(
coupon
)){
LOGGER
.
info
(
"before saveOrUpdateCoupon#insert,req is {}"
,
req
);
...
...
@@ -220,17 +232,18 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
couponMapper
.
insertByCouponSaveUpdateReq
(
req
);
LOGGER
.
info
(
"after saveOrUpdateCoupon#insert,req is {}"
,
req
);
saveProductLimitItems
(
req
,
productLimitType
,
productIds
);
couponId
=
req
.
getId
();
}
// 更新
else
{
LOGGER
.
info
(
"before saveOrUpdateCoupon#deleteByCouponId,couponId is {}"
,
req
.
getId
());
// 已经有了优惠券的发放记录
UserCouponNum
userCouponNum
=
userCouponMapper
.
selectByCouponId
(
coupon
.
getId
());
UserCouponNum
userCouponNum
=
userCouponMapper
.
selectByCouponId
(
coupon
Id
=
coupon
.
getId
());
if
(
Objects
.
nonNull
(
userCouponNum
)
&&
userCouponNum
.
getCnt
()>
0
){
LOGGER
.
info
(
"sendNum bigger than 0, name|couponNu|remark only can update, couponId {}"
,
req
.
getId
());
CouponSaveUpdateReq
couponSaveUpdateReq
=
new
CouponSaveUpdateReq
();
couponSaveUpdateReq
.
setId
(
coupon
.
getId
()
);
couponSaveUpdateReq
.
setId
(
coupon
Id
);
// 名称
couponSaveUpdateReq
.
setCouponName
(
req
.
getCouponName
());
...
...
@@ -252,6 +265,8 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
LOGGER
.
info
(
"has coupon send, saveOrUpdateCoupon#update,req is {}"
,
req
);
couponMapper
.
updateByCouponSaveUpdateReq
(
couponSaveUpdateReq
);
}
else
{
LOGGER
.
info
(
"sendNum noting, all info can update, couponId {}"
,
req
.
getId
());
...
...
@@ -264,9 +279,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
LOGGER
.
info
(
"after saveOrUpdateCoupon#update,req is {}"
,
req
);
}
saveOrUpdateDisplay
(
couponId
,
req
.
getShowInPrdDetail
());
return
new
ApiResponse
.
ApiResponseBuilder
().
build
();
}
...
...
@@ -279,6 +292,27 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
req
.
setSkupAllowType
(
Joiner
.
on
(
","
).
join
(
allowAttributeTypes
));
}
private
final
static
String
API_ADDORUPDATEDISPLAY
=
"coupon.addOrUpdateDisplay"
;
private
void
saveOrUpdateDisplay
(
Integer
couponId
,
String
showInPrdDetail
){
LOGGER
.
info
(
"saveOrUpdateDisplay couponId {} showInPrdDetail {}"
,
couponId
,
showInPrdDetail
);
PositionType
positionType
=
PositionType
.
PRD_DETAIL
;
Visibility
visibilityEnum
;
if
(
StringUtils
.
isNotBlank
(
showInPrdDetail
)&&
"Y"
.
equalsIgnoreCase
(
showInPrdDetail
)){
visibilityEnum
=
Visibility
.
YES
;
}
else
{
visibilityEnum
=
Visibility
.
NO
;
}
byte
visibility
=
visibilityEnum
.
getCode
();
CouponDisplayBo
req
=
CouponDisplayBo
.
builder
().
couponId
(
couponId
)
.
positionType
(
positionType
.
getCode
())
.
visibility
(
visibility
)
.
build
();
final
String
api
=
API_ADDORUPDATEDISPLAY
;
LOGGER
.
info
(
"saveOrUpdateDisplay ready call {}, req {}"
,
api
,
req
);
Integer
num
=
serviceCaller
.
call
(
api
,
req
,
Integer
.
class
);
LOGGER
.
info
(
"saveOrUpdateDisplay finish call {}, req {} num {}"
,
api
,
req
,
num
);
}
private
void
parseSkupForbidType
(
CouponSaveUpdateReq
req
)
{
if
(
StringUtils
.
isBlank
(
req
.
getSkupForbidType
()))
{
...
...
@@ -352,8 +386,29 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
.
orElse
(
0
);
coupon
.
setSendNum
(
userCouponNum
);
//
String
showInPrdDetail
=
"N"
;
List
<
CouponDisplay
>
pcdList
=
couponDisplayMapper
.
selectByCouponId
(
id
);
if
(
CollectionUtils
.
isNotEmpty
(
pcdList
)){
for
(
CouponDisplay
pcd
:
pcdList
){
Integer
positionTypeCode
;
if
(
Objects
.
isNull
(
positionTypeCode
=
pcd
.
getPositionType
())){
continue
;
}
PositionType
positionType
=
PositionType
.
getPositionTypeByCode
(
positionTypeCode
);
switch
(
positionType
){
case
PRD_DETAIL:
if
(
pcd
.
getVisibility
()
==
(
byte
)
1
){
showInPrdDetail
=
"Y"
;
}
break
;
}
}
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"coupon"
,
coupon
);
jsonObject
.
put
(
"showInPrdDetail"
,
showInPrdDetail
);
jsonObject
.
put
(
"productLimits"
,
productLimitList
);
return
new
ApiResponse
.
ApiResponseBuilder
().
data
(
jsonObject
).
build
();
}
...
...
dal/src/main/java/com/yoho/ufo/dal/CouponDisplayMapper.java
0 → 100644
View file @
6c014b6
package
com
.
yoho
.
ufo
.
dal
;
import
com.yoho.ufo.dal.model.CouponDisplay
;
import
java.util.List
;
public
interface
CouponDisplayMapper
{
List
<
CouponDisplay
>
selectByCouponId
(
Integer
id
);
}
\ No newline at end of file
...
...
dal/src/main/java/com/yoho/ufo/dal/model/CouponDisplay.java
0 → 100644
View file @
6c014b6
package
com
.
yoho
.
ufo
.
dal
.
model
;
import
lombok.Data
;
@Data
public
class
CouponDisplay
{
private
Integer
id
;
private
Integer
couponId
;
private
Integer
positionType
;
private
Byte
visibility
;
}
\ No newline at end of file
...
...
dal/src/main/resources/META-INF/mybatis/CouponDisplayMapper.xml
0 → 100644
View file @
6c014b6
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.yoho.ufo.dal.CouponDisplayMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.yoho.ufo.dal.model.CouponDisplay"
>
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"coupon_id"
jdbcType=
"INTEGER"
property=
"couponId"
/>
<result
column=
"position_type"
jdbcType=
"INTEGER"
property=
"positionType"
/>
<result
column=
"visibility"
jdbcType=
"TINYINT"
property=
"visibility"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
id, coupon_id, position_type, visibility
</sql>
<select
id=
"selectByCouponId"
parameterType=
"java.lang.Integer"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from coupon_display
where coupon_id = #{couponId,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
...
...
web/src/main/resources/databases.yml
View file @
6c014b6
...
...
@@ -116,6 +116,7 @@ datasources:
-
com.yoho.ufo.dal.PromotionActivityMapper
-
com.yoho.ufo.dal.PromotionProductScopeMapper
-
com.yoho.ufo.dal.PromotionTypeConditionMapper
-
com.yoho.ufo.dal.CouponDisplayMapper
ufo_passport
:
servers
:
...
...
web/src/main/webapp/META-INF/autoconf/databases.yml
View file @
6c014b6
...
...
@@ -119,6 +119,7 @@ datasources:
-
com.yoho.ufo.dal.PromotionActivityMapper
-
com.yoho.ufo.dal.PromotionProductScopeMapper
-
com.yoho.ufo.dal.PromotionTypeConditionMapper
-
com.yoho.ufo.dal.CouponDisplayMapper
ufo_passport
:
servers
:
...
...
Please
register
or
login
to post a comment