Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
soss
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hooloo
ms
soss
Commits
6cd2da43
Commit
6cd2da43
authored
Jul 22, 2022
by
caiyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增优惠券类别服务接口
parent
4e22b068
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
346 additions
and
10 deletions
+346
-10
soss-admin/src/main/java/com/soss/web/controller/coupon/CouponCategoryController.java
+52
-3
soss-common/src/main/java/com/soss/common/enums/CouponCategoryType.java
+28
-0
soss-common/src/main/java/com/soss/common/enums/CouponState.java
+29
-0
soss-system/src/main/java/com/soss/system/domain/CouponCategory.java
+11
-0
soss-system/src/main/java/com/soss/system/mapper/CouponCategoryMapper.java
+26
-0
soss-system/src/main/java/com/soss/system/mapper/CouponMapper.java
+6
-1
soss-system/src/main/java/com/soss/system/service/ICouponCategoryService.java
+9
-0
soss-system/src/main/java/com/soss/system/service/ICouponRuleService.java
+0
-3
soss-system/src/main/java/com/soss/system/service/ICouponUserService.java
+0
-3
soss-system/src/main/java/com/soss/system/service/impl/CouponCategoryServiceImpl.java
+68
-0
soss-system/src/main/resources/mapper/system/CouponCategoryMapper.xml
+54
-0
soss-system/src/main/resources/mapper/system/CouponMapper.xml
+18
-0
soss-system/src/main/resources/mapper/system/CouponRuleMapper.xml
+27
-0
soss-system/src/main/resources/mapper/system/CouponUserMapper.xml
+18
-0
No files found.
soss-admin/src/main/java/com/soss/web/controller/coupon/CouponCategoryController.java
View file @
6cd2da43
package
com
.
soss
.
web
.
controller
.
coupon
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.soss.common.annotation.Log
;
import
com.soss.common.core.controller.BaseController
;
import
com.soss.common.core.domain.AjaxResult
;
import
com.soss.common.enums.BusinessType
;
import
com.soss.system.domain.CouponCategory
;
import
com.soss.system.service.ICouponCategoryService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* <p>
...
...
@@ -14,6 +25,44 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping
(
"/coupon-category"
)
public
class
CouponCategoryController
{
@Api
(
"优惠券类别服务类"
)
public
class
CouponCategoryController
extends
BaseController
{
@Autowired
private
ICouponCategoryService
couponCategoryService
;
/**
* 新增优惠券类别
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:category:add')"
)
@Log
(
title
=
"新增优惠券类别"
,
businessType
=
BusinessType
.
INSERT
)
@PutMapping
@ApiOperation
(
"新增优惠券类别"
)
public
AjaxResult
add
(
@RequestBody
CouponCategory
couponCategory
)
{
couponCategoryService
.
insertCouponCategory
(
couponCategory
);
return
AjaxResult
.
success
();
}
/**
* 查询优惠券类别列表
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:category:list')"
)
@Log
(
title
=
"查询优惠券类别列表"
,
businessType
=
BusinessType
.
INSERT
)
@GetMapping
@ApiOperation
(
"查询优惠券类别列表"
)
public
AjaxResult
listCouponCategory
(
@RequestBody
CouponCategory
couponCategory
)
{
List
<
CouponCategory
>
couponCategories
=
couponCategoryService
.
listCouponCategory
(
couponCategory
);
return
AjaxResult
.
success
(
couponCategories
);
}
/**
* 变更优惠券类别状态
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:category:state-switch')"
)
@Log
(
title
=
"变更优惠券类别状态"
,
businessType
=
BusinessType
.
INSERT
)
@GetMapping
(
"/{id}/{state}"
)
@ApiOperation
(
value
=
"变更优惠券类别状态"
,
notes
=
"state: 状态 0 默认 1 生效 2 下线 3删除"
)
public
AjaxResult
switchState
(
@PathVariable
Integer
id
,
@PathVariable
Integer
state
)
{
int
updateCnt
=
couponCategoryService
.
switchState
(
id
,
state
);
return
toAjax
(
updateCnt
);
}
}
soss-common/src/main/java/com/soss/common/enums/CouponCategoryType.java
0 → 100644
View file @
6cd2da43
package
com
.
soss
.
common
.
enums
;
public
enum
CouponCategoryType
{
DEDUCTION
(
1
,
"抵扣"
),
DISCOUNT
(
2
,
"折扣"
),
FREE
(
3
,
"免单"
);
private
Integer
type
;
private
String
desc
;
CouponCategoryType
(
Integer
type
,
String
desc
)
{
this
.
type
=
type
;
this
.
desc
=
desc
;
}
public
Integer
getType
()
{
return
type
;
}
public
static
String
getDesc
(
Integer
type
)
{
for
(
CouponCategoryType
categoryType
:
CouponCategoryType
.
values
())
{
if
(
categoryType
.
type
.
equals
(
type
))
{
return
categoryType
.
desc
;
}
}
return
null
;
}
}
soss-common/src/main/java/com/soss/common/enums/CouponState.java
0 → 100644
View file @
6cd2da43
package
com
.
soss
.
common
.
enums
;
public
enum
CouponState
{
DEFAULT
(
0
,
"默认"
),
ONLINE
(
1
,
"上架"
),
OFFLINE
(
2
,
"下架"
),
DELETE
(
3
,
"删除"
);
private
Integer
state
;
private
String
desc
;
CouponState
(
Integer
state
,
String
desc
)
{
this
.
state
=
state
;
this
.
desc
=
desc
;
}
public
Integer
getState
()
{
return
state
;
}
public
static
String
getDesc
(
Integer
state
)
{
for
(
CouponState
categoryType
:
CouponState
.
values
())
{
if
(
categoryType
.
state
.
equals
(
state
))
{
return
categoryType
.
desc
;
}
}
return
null
;
}
}
soss-system/src/main/java/com/soss/system/domain/CouponCategory.java
View file @
6cd2da43
...
...
@@ -3,6 +3,7 @@ package com.soss.system.domain;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.soss.common.core.domain.BaseEntity
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.time.LocalDateTime
;
...
...
@@ -15,6 +16,7 @@ import java.time.LocalDateTime;
* @since 2022-07-21
*/
@Data
@NoArgsConstructor
public
class
CouponCategory
extends
BaseEntity
{
/**
* 主键
...
...
@@ -40,6 +42,7 @@ public class CouponCategory extends BaseEntity {
* 优惠券类型 1 抵扣 2 折扣 3 免单
*/
private
Integer
type
;
private
String
typeDesc
;
/**
* 创建时间
...
...
@@ -53,5 +56,13 @@ public class CouponCategory extends BaseEntity {
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
updatedAt
;
/**
* 优惠券数量
*/
private
Long
couponCnt
;
public
CouponCategory
(
Integer
id
,
Integer
state
)
{
this
.
id
=
id
;
this
.
state
=
state
;
}
}
soss-system/src/main/java/com/soss/system/mapper/CouponCategoryMapper.java
View file @
6cd2da43
package
com
.
soss
.
system
.
mapper
;
import
com.soss.system.domain.CouponCategory
;
import
java.util.List
;
/**
* <p>
* 优惠券类别 Mapper 接口
...
...
@@ -9,5 +13,27 @@ package com.soss.system.mapper;
* @since 2022-07-21
*/
public
interface
CouponCategoryMapper
{
/**
* 新增优惠券类别
*
* @param couponCategory 优惠券类别
* @return 结果
*/
int
insertCouponCategory
(
CouponCategory
couponCategory
);
/**
* 查询优惠券类别列表
*
* @param couponCategory 优惠券类别
* @return 优惠券类别集合
*/
List
<
CouponCategory
>
listCouponCategory
(
CouponCategory
couponCategory
);
/**
* 更新优惠券类别
*
* @param couponCategory 优惠券类别
* @return 结果
*/
int
updateCouponCategory
(
CouponCategory
couponCategory
);
}
soss-system/src/main/java/com/soss/system/mapper/CouponMapper.java
View file @
6cd2da43
package
com
.
soss
.
system
.
mapper
;
import
com.soss.system.domain.CouponCategory
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* <p>
* 优惠券 Mapper 接口
...
...
@@ -9,5 +14,5 @@ package com.soss.system.mapper;
* @since 2022-07-21
*/
public
interface
CouponMapper
{
List
<
CouponCategory
>
getCouponCategoryTypeStat
(
@Param
(
"categoryIds"
)
List
<
Integer
>
categoryIds
);
}
soss-system/src/main/java/com/soss/system/service/ICouponCategoryService.java
View file @
6cd2da43
package
com
.
soss
.
system
.
service
;
import
com.soss.system.domain.CouponCategory
;
import
java.util.List
;
/**
* <p>
* 优惠券类别 服务类
...
...
@@ -10,4 +14,9 @@ package com.soss.system.service;
*/
public
interface
ICouponCategoryService
{
void
insertCouponCategory
(
CouponCategory
couponCategory
);
List
<
CouponCategory
>
listCouponCategory
(
CouponCategory
couponCategory
);
int
switchState
(
Integer
id
,
Integer
state
);
}
soss-system/src/main/java/com/soss/system/service/ICouponRuleService.java
View file @
6cd2da43
package
com
.
soss
.
system
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.sskuaixiu.settlement.bo.CouponRule
;
/**
* <p>
* 优惠券规则 服务类
...
...
soss-system/src/main/java/com/soss/system/service/ICouponUserService.java
View file @
6cd2da43
package
com
.
soss
.
system
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.sskuaixiu.settlement.bo.CouponUser
;
/**
* <p>
* 用户领取优惠券记录表 服务类
...
...
soss-system/src/main/java/com/soss/system/service/impl/CouponCategoryServiceImpl.java
View file @
6cd2da43
package
com
.
soss
.
system
.
service
.
impl
;
import
com.soss.common.enums.CouponCategoryType
;
import
com.soss.system.domain.CouponCategory
;
import
com.soss.system.mapper.CouponCategoryMapper
;
import
com.soss.system.mapper.CouponMapper
;
import
com.soss.system.service.ICouponCategoryService
;
import
io.jsonwebtoken.lang.Assert
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* <p>
...
...
@@ -13,5 +25,61 @@ import org.springframework.stereotype.Service;
*/
@Service
public
class
CouponCategoryServiceImpl
implements
ICouponCategoryService
{
@Autowired
private
CouponCategoryMapper
couponCategoryMapper
;
@Autowired
private
CouponMapper
couponMapper
;
/**
* 新增优惠券类别
*
* @param couponCategory 优惠券类别
* @return 结果
*/
@Override
@Transactional
public
void
insertCouponCategory
(
CouponCategory
couponCategory
)
{
Assert
.
notNull
(
couponCategory
.
getName
(),
"优惠券类别名称还未填写"
);
Assert
.
notNull
(
couponCategory
.
getType
(),
"优惠券类别的折扣形式还未选择"
);
LocalDateTime
now
=
LocalDateTime
.
now
();
couponCategory
.
setCreatedAt
(
now
);
couponCategory
.
setUpdatedAt
(
now
);
couponCategoryMapper
.
insertCouponCategory
(
couponCategory
);
}
/**
* 查询优惠券类别列表
*
* @param couponCategory 优惠券类别
* @return 优惠券类别
*/
@Override
public
List
<
CouponCategory
>
listCouponCategory
(
CouponCategory
couponCategory
)
{
List
<
CouponCategory
>
couponCategories
=
couponCategoryMapper
.
listCouponCategory
(
couponCategory
);
List
<
Integer
>
categoryIds
=
couponCategories
.
stream
().
map
(
CouponCategory:
:
getId
).
collect
(
Collectors
.
toList
());
List
<
CouponCategory
>
couponCategoryCountList
=
couponMapper
.
getCouponCategoryTypeStat
(
categoryIds
);
Map
<
Integer
,
Long
>
countMap
=
couponCategoryCountList
.
stream
()
.
collect
(
Collectors
.
toMap
(
CouponCategory:
:
getId
,
CouponCategory:
:
getCouponCnt
));
for
(
CouponCategory
category
:
couponCategories
)
{
category
.
setTypeDesc
(
CouponCategoryType
.
getDesc
(
category
.
getType
()));
Long
count
=
countMap
.
get
(
category
.
getId
());
category
.
setCouponCnt
(
count
==
null
?
0L
:
count
);
}
return
couponCategories
;
}
/**
* 更新优惠券类别状态
*
* @param id
* @param state
* @return
*/
@Override
@Transactional
public
int
switchState
(
Integer
id
,
Integer
state
)
{
CouponCategory
online
=
new
CouponCategory
(
id
,
state
);
int
updateCnt
=
couponCategoryMapper
.
updateCouponCategory
(
online
);
return
updateCnt
;
}
}
soss-system/src/main/resources/mapper/system/CouponCategoryMapper.xml
View file @
6cd2da43
<?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.soss.system.mapper.CouponCategoryMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.soss.system.domain.CouponCategory"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"name"
property=
"name"
/>
<result
column=
"state"
property=
"state"
/>
<result
column=
"desc"
property=
"desc"
/>
<result
column=
"type"
property=
"type"
/>
<result
column=
"created_at"
property=
"createdAt"
/>
<result
column=
"updated_at"
property=
"updatedAt"
/>
</resultMap>
<sql
id=
"selectCouponCategory"
>
select id, name, state, `desc`, type, created_at, updated_at from coupon_category
</sql>
<select
id=
"listCouponCategory"
parameterType=
"CouponCategory"
resultMap=
"BaseResultMap"
>
<include
refid=
"selectCouponCategory"
/>
<where>
<if
test=
"type != null"
>
and type = #{type}
</if>
<if
test=
"state != null and state != ''"
>
and state = #{state}
</if>
</where>
order by turn
</select>
<insert
id=
"insertCouponCategory"
parameterType=
"com.soss.system.domain.CouponCategory"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into coupon_category
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"name != null and name != ''"
>
name,
</if>
<if
test=
"state != null"
>
state,
</if>
<if
test=
"desc != null and desc != ''"
>
`desc`,
</if>
<if
test=
"type != null"
>
type,
</if>
<if
test=
"createdAt != null"
>
created_at,
</if>
<if
test=
"updatedAt != null"
>
updated_at,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"name != null and name != ''"
>
#{name},
</if>
<if
test=
"state != null"
>
#{state},
</if>
<if
test=
"desc != null and desc != ''"
>
#{desc},
</if>
<if
test=
"type != null"
>
#{type},
</if>
<if
test=
"createdAt != null"
>
#{createdAt},
</if>
<if
test=
"updatedAt != null"
>
#{updatedAt},
</if>
</trim>
</insert>
<update
id=
"updateCouponCategory"
parameterType=
"com.soss.system.domain.CouponCategory"
>
update coupon_category
<trim
prefix=
"SET"
suffixOverrides=
","
>
<if
test=
"name != null and name != ''"
>
name = #{name},
</if>
<if
test=
"state != null"
>
state = #{state},
</if>
<if
test=
"desc != null and desc != ''"
>
`desc` = #{desc},
</if>
<if
test=
"type != null"
>
type = #{type},
</if>
<if
test=
"updatedAt != null"
>
updated_at = #{updatedAt},
</if>
</trim>
where id = #{id}
</update>
</mapper>
soss-system/src/main/resources/mapper/system/CouponMapper.xml
View file @
6cd2da43
<?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.soss.system.mapper.CouponMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.soss.system.domain.Coupon"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"name"
property=
"name"
/>
<result
column=
"serial_no"
property=
"serialNo"
/>
<result
column=
"category_id"
property=
"categoryId"
/>
<result
column=
"category_name"
property=
"categoryName"
/>
<result
column=
"rule_id"
property=
"ruleId"
/>
<result
column=
"type"
property=
"type"
/>
<result
column=
"state"
property=
"state"
/>
<result
column=
"created_at"
property=
"createdAt"
/>
<result
column=
"updated_at"
property=
"updatedAt"
/>
</resultMap>
<select
id=
"getCouponCategoryTypeStat"
resultType=
"com.soss.system.domain.CouponCategory"
>
select category_id id, count(*) couponCnt from coupon
<foreach
collection=
"categoryIds"
item=
"categoryId"
open=
"("
close=
")"
separator=
","
>
#{categoryId}
</foreach>
group by category_id
</select>
</mapper>
soss-system/src/main/resources/mapper/system/CouponRuleMapper.xml
View file @
6cd2da43
<?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.soss.system.mapper.CouponRuleMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.soss.system.domain.CouponRule"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"name"
property=
"name"
/>
<result
column=
"desc"
property=
"desc"
/>
<result
column=
"province"
property=
"province"
/>
<result
column=
"city"
property=
"city"
/>
<result
column=
"area"
property=
"area"
/>
<result
column=
"shop_ids"
property=
"shopIds"
/>
<result
column=
"category_ids"
property=
"categoryIds"
/>
<result
column=
"goods_ids"
property=
"goodsIds"
/>
<result
column=
"start_time"
property=
"startTime"
/>
<result
column=
"end_time"
property=
"endTime"
/>
<result
column=
"use_start_time"
property=
"useStartTime"
/>
<result
column=
"use_end_time"
property=
"useEndTime"
/>
<result
column=
"relative_time"
property=
"relativeTime"
/>
<result
column=
"price_limit"
property=
"priceLimit"
/>
<result
column=
"order_limit"
property=
"orderLimit"
/>
<result
column=
"week_limit"
property=
"weekLimit"
/>
<result
column=
"user_limit"
property=
"userLimit"
/>
<result
column=
"days_limit"
property=
"daysLimit"
/>
<result
column=
"send_msg"
property=
"sendMsg"
/>
<result
column=
"msg_id"
property=
"msgId"
/>
<result
column=
"state"
property=
"state"
/>
<result
column=
"created_at"
property=
"createdAt"
/>
<result
column=
"updated_at"
property=
"updatedAt"
/>
</resultMap>
</mapper>
soss-system/src/main/resources/mapper/system/CouponUserMapper.xml
View file @
6cd2da43
<?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.soss.system.mapper.CouponUserMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.soss.system.domain.CouponUser"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"user_id"
property=
"userId"
/>
<result
column=
"user_name"
property=
"userName"
/>
<result
column=
"user_phone"
property=
"userPhone"
/>
<result
column=
"order_id"
property=
"orderId"
/>
<result
column=
"coupon_id"
property=
"couponId"
/>
<result
column=
"receive_time"
property=
"receiveTime"
/>
<result
column=
"active_time"
property=
"activeTime"
/>
<result
column=
"expired_time"
property=
"expiredTime"
/>
<result
column=
"discount"
property=
"discount"
/>
<result
column=
"source"
property=
"source"
/>
<result
column=
"type"
property=
"type"
/>
<result
column=
"state"
property=
"state"
/>
<result
column=
"created_at"
property=
"createdAt"
/>
<result
column=
"updated_at"
property=
"updatedAt"
/>
</resultMap>
</mapper>
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