init project
Showing
188 changed files
with
9764 additions
and
0 deletions
pom.xml
0 → 100644
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
5 | <modelVersion>4.0.0</modelVersion> | ||
6 | |||
7 | <groupId>com.topdraw</groupId> | ||
8 | <artifactId>member-engine</artifactId> | ||
9 | <version>0.0.1-SNAPSHOT</version> | ||
10 | |||
11 | <properties> | ||
12 | <maven.compiler.source>8</maven.compiler.source> | ||
13 | <maven.compiler.target>8</maven.compiler.target> | ||
14 | <jjwt.version>0.9.1</jjwt.version> | ||
15 | </properties> | ||
16 | |||
17 | <parent> | ||
18 | <groupId>org.springframework.boot</groupId> | ||
19 | <artifactId>spring-boot-starter-parent</artifactId> | ||
20 | <version>2.2.10.RELEASE</version> | ||
21 | <relativePath/> | ||
22 | </parent> | ||
23 | |||
24 | <dependencies> | ||
25 | |||
26 | <!--代码生成器--> | ||
27 | <dependency> | ||
28 | <groupId>com.topdraw</groupId> | ||
29 | <artifactId>code-generator</artifactId> | ||
30 | <version>3.1.0</version> | ||
31 | </dependency> | ||
32 | |||
33 | <!-- Spring boot 热部署 : 此热部署会遇到 java.lang.ClassCastException 异常 --> | ||
34 | <dependency> | ||
35 | <groupId>org.springframework.boot</groupId> | ||
36 | <artifactId>spring-boot-devtools</artifactId> | ||
37 | <optional>true</optional> | ||
38 | <scope>runtime</scope> | ||
39 | </dependency> | ||
40 | |||
41 | <dependency> | ||
42 | <groupId>org.springframework.boot</groupId> | ||
43 | <artifactId>spring-boot-starter-test</artifactId> | ||
44 | </dependency> | ||
45 | |||
46 | <!--Mysql依赖包,版本差异,需单独引入--> | ||
47 | <dependency> | ||
48 | <groupId>mysql</groupId> | ||
49 | <artifactId>mysql-connector-java</artifactId> | ||
50 | <version>8.0.26</version> | ||
51 | </dependency> | ||
52 | |||
53 | <dependency> | ||
54 | <groupId>junit</groupId> | ||
55 | <artifactId>junit</artifactId> | ||
56 | <version>4.12</version> | ||
57 | <scope>test</scope> | ||
58 | </dependency> | ||
59 | |||
60 | <!-- 支持AES/CBC/PKCS7Padding,用于微信小程序登录数据解密 --> | ||
61 | <dependency> | ||
62 | <groupId>org.bouncycastle</groupId> | ||
63 | <artifactId>bcprov-jdk16</artifactId> | ||
64 | <version>1.46</version> | ||
65 | </dependency> | ||
66 | |||
67 | <!--消息队列相关依赖--> | ||
68 | <dependency> | ||
69 | <groupId>org.springframework.boot</groupId> | ||
70 | <artifactId>spring-boot-starter-amqp</artifactId> | ||
71 | </dependency> | ||
72 | |||
73 | <!--重试--> | ||
74 | <dependency> | ||
75 | <groupId>org.springframework.retry</groupId> | ||
76 | <artifactId>spring-retry</artifactId> | ||
77 | </dependency> | ||
78 | |||
79 | <dependency> | ||
80 | <groupId>org.aspectj</groupId> | ||
81 | <artifactId>aspectjweaver</artifactId> | ||
82 | </dependency> | ||
83 | |||
84 | <dependency> | ||
85 | <groupId>commons-codec</groupId> | ||
86 | <artifactId>commons-codec</artifactId> | ||
87 | <version>1.9</version> | ||
88 | </dependency> | ||
89 | |||
90 | </dependencies> | ||
91 | |||
92 | |||
93 | <profiles> | ||
94 | <profile> | ||
95 | <!-- 本地开发环境 --> | ||
96 | <id>dev</id> | ||
97 | <properties> | ||
98 | <profiles.active>dev</profiles.active> | ||
99 | </properties> | ||
100 | <activation> | ||
101 | <!-- 默认的,不加参数时执行这个profile --> | ||
102 | <activeByDefault>true</activeByDefault> | ||
103 | </activation> | ||
104 | </profile> | ||
105 | <profile> | ||
106 | <!-- 生产环境 --> | ||
107 | <id>prod</id> | ||
108 | <properties> | ||
109 | <profiles.active>prod</profiles.active> | ||
110 | <modifier>-prod</modifier> | ||
111 | </properties> | ||
112 | </profile> | ||
113 | </profiles> | ||
114 | |||
115 | <build> | ||
116 | <finalName>member-engine</finalName> | ||
117 | <plugins> | ||
118 | <plugin> | ||
119 | <groupId>org.springframework.boot</groupId> | ||
120 | <artifactId>spring-boot-maven-plugin</artifactId> | ||
121 | <configuration> | ||
122 | <fork>true</fork> | ||
123 | </configuration> | ||
124 | </plugin> | ||
125 | <!-- 跳过单元测试 --> | ||
126 | <plugin> | ||
127 | <groupId>org.apache.maven.plugins</groupId> | ||
128 | <artifactId>maven-surefire-plugin</artifactId> | ||
129 | <configuration> | ||
130 | <skipTests>true</skipTests> | ||
131 | </configuration> | ||
132 | </plugin> | ||
133 | <!-- 复制指定配置文件到指定目录 --> | ||
134 | <plugin> | ||
135 | <artifactId>maven-resources-plugin</artifactId> | ||
136 | <executions> | ||
137 | <execution> | ||
138 | <id>copy-resources</id> | ||
139 | <phase>package</phase> | ||
140 | <goals> | ||
141 | <goal>copy-resources</goal> | ||
142 | </goals> | ||
143 | <configuration> | ||
144 | <resources> | ||
145 | <resource> | ||
146 | <directory>src/main/resources/config</directory> | ||
147 | <includes> | ||
148 | <include>application.yml</include> | ||
149 | <include>application-${profiles.active}.yml</include> | ||
150 | </includes> | ||
151 | </resource> | ||
152 | </resources> | ||
153 | <outputDirectory>${project.build.directory}/config</outputDirectory> | ||
154 | </configuration> | ||
155 | </execution> | ||
156 | </executions> | ||
157 | </plugin> | ||
158 | <!-- jar包内剔除所有配置文件 --> | ||
159 | <plugin> | ||
160 | <artifactId>maven-jar-plugin</artifactId> | ||
161 | <configuration> | ||
162 | <!--不打入jar包的文件类型或者路径--> | ||
163 | <excludes> | ||
164 | <exclude>config/**</exclude> | ||
165 | </excludes> | ||
166 | </configuration> | ||
167 | </plugin> | ||
168 | </plugins> | ||
169 | </build> | ||
170 | |||
171 | </project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | package com.topdraw; | ||
2 | |||
3 | |||
4 | import com.topdraw.utils.SpringContextHolder; | ||
5 | import org.springframework.boot.SpringApplication; | ||
6 | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
7 | import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; | ||
8 | import org.springframework.boot.builder.SpringApplicationBuilder; | ||
9 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
10 | import org.springframework.context.annotation.Bean; | ||
11 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
12 | import org.springframework.retry.annotation.EnableRetry; | ||
13 | import org.springframework.scheduling.annotation.EnableAsync; | ||
14 | import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
15 | |||
16 | @EnableJpaAuditing | ||
17 | @EnableAsync | ||
18 | @SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) | ||
19 | @EnableTransactionManagement | ||
20 | @EnableRetry | ||
21 | public class MemberEngineApplication extends SpringBootServletInitializer { | ||
22 | |||
23 | public static void main(String[] args) { | ||
24 | SpringApplication.run(MemberEngineApplication.class, args); | ||
25 | } | ||
26 | |||
27 | @Override | ||
28 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { | ||
29 | return builder.sources(MemberEngineApplication.class); | ||
30 | } | ||
31 | |||
32 | @Bean | ||
33 | public SpringContextHolder springContextHolder() { | ||
34 | return new SpringContextHolder(); | ||
35 | } | ||
36 | |||
37 | } | ||
38 |
1 | package com.topdraw.business.basicdata.coupon.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.math.BigDecimal; | ||
14 | import java.sql.Timestamp; | ||
15 | |||
16 | /** | ||
17 | * @author XiangHan | ||
18 | * @date 2021-10-22 | ||
19 | */ | ||
20 | @Entity | ||
21 | @Data | ||
22 | @EntityListeners(AuditingEntityListener.class) | ||
23 | @Accessors(chain = true) | ||
24 | @Table(name="m_coupon") | ||
25 | public class Coupon implements Serializable { | ||
26 | |||
27 | // id | ||
28 | @Id | ||
29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
30 | @Column(name = "id") | ||
31 | private Long id; | ||
32 | |||
33 | // 标识 | ||
34 | @Column(name = "code", nullable = false) | ||
35 | private String code; | ||
36 | |||
37 | // 名称 | ||
38 | @Column(name = "title", nullable = false) | ||
39 | private String title; | ||
40 | |||
41 | // 图片 | ||
42 | @Column(name = "images") | ||
43 | private String images; | ||
44 | |||
45 | // 发行量,-1代表不限量 | ||
46 | @Column(name = "stock") | ||
47 | private Integer stock; | ||
48 | |||
49 | // 剩余量,-1代表不限量 | ||
50 | @Column(name = "remain_stock") | ||
51 | private Integer remainStock; | ||
52 | |||
53 | // 优惠形式:1:现金;2:折扣 | ||
54 | @Column(name = "use_type") | ||
55 | private Integer useType; | ||
56 | |||
57 | // 面额 | ||
58 | @Column(name = "denomination") | ||
59 | private BigDecimal denomination; | ||
60 | |||
61 | // 折扣 | ||
62 | @Column(name = "discount") | ||
63 | private BigDecimal discount; | ||
64 | |||
65 | // 适用用户范围:1:新用户;2:全体用户 | ||
66 | @Column(name = "user_range") | ||
67 | private Integer userRange; | ||
68 | |||
69 | // 限领次数 -1:无限次; >0:具体次数 | ||
70 | @Column(name = "collect_limit") | ||
71 | private Integer collectLimit; | ||
72 | |||
73 | // 适用门槛:1:无门槛;2:满减形式 | ||
74 | @Column(name = "threshold_type") | ||
75 | private Integer thresholdType; | ||
76 | |||
77 | // 满减门槛 | ||
78 | @Column(name = "amount_threshold") | ||
79 | private BigDecimal amountThreshold; | ||
80 | |||
81 | // 产品范围:1:全部商品;2:指定商品 | ||
82 | @Column(name = "item_range") | ||
83 | private Integer itemRange; | ||
84 | |||
85 | // 生效形式:1:固定日期;2:相对日期 | ||
86 | @Column(name = "effect_type") | ||
87 | private Integer effectType; | ||
88 | |||
89 | // 生效时间 | ||
90 | @Column(name = "start_time") | ||
91 | private Timestamp startTime; | ||
92 | |||
93 | // 过期时间 | ||
94 | @Column(name = "expire_time") | ||
95 | private Timestamp expireTime; | ||
96 | |||
97 | // 自领取当日,几天内有效 | ||
98 | @Column(name = "valid_days") | ||
99 | private Integer validDays; | ||
100 | |||
101 | // 使用说明 | ||
102 | @Column(name = "description") | ||
103 | private String description; | ||
104 | |||
105 | // 状态0:未开始,1:启用;2:停用 | ||
106 | @Column(name = "status") | ||
107 | private Integer status; | ||
108 | |||
109 | // 创建时间 | ||
110 | @CreatedDate | ||
111 | @Column(name = "create_time") | ||
112 | private Timestamp createTime; | ||
113 | |||
114 | // 更新时间 | ||
115 | @LastModifiedDate | ||
116 | @Column(name = "update_time") | ||
117 | private Timestamp updateTime; | ||
118 | |||
119 | public void copy(Coupon source){ | ||
120 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
121 | } | ||
122 | } |
1 | package com.topdraw.business.basicdata.coupon.history.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-23 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="m_coupon_history") | ||
24 | public class CouponHistory implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 优惠券id | ||
33 | @Column(name = "coupon_id") | ||
34 | private Long couponId; | ||
35 | |||
36 | // 领券用户id(对应账号) | ||
37 | @Column(name = "user_id") | ||
38 | private Long userId; | ||
39 | |||
40 | // 优惠券code | ||
41 | @Column(name = "coupon_code") | ||
42 | private String couponCode; | ||
43 | |||
44 | // 领取人昵称 | ||
45 | @Column(name = "user_nickname") | ||
46 | private String userNickname; | ||
47 | |||
48 | // 领取时间 | ||
49 | @Column(name = "receive_time") | ||
50 | private Timestamp receiveTime; | ||
51 | |||
52 | // 失效时间 | ||
53 | @Column(name = "expire_time") | ||
54 | private Timestamp expireTime; | ||
55 | |||
56 | // 使用状态 0:未使用;1:已使用;-1:已过期 | ||
57 | @Column(name = "use_status") | ||
58 | private Integer useStatus; | ||
59 | |||
60 | // 使用时间 | ||
61 | @Column(name = "use_time") | ||
62 | private Timestamp useTime; | ||
63 | |||
64 | // 订单详情id | ||
65 | @Column(name = "order_detail_id") | ||
66 | private Long orderDetailId; | ||
67 | |||
68 | // 创建时间 | ||
69 | @CreatedDate | ||
70 | @Column(name = "create_time") | ||
71 | private Timestamp createTime; | ||
72 | |||
73 | // 更新时间 | ||
74 | @LastModifiedDate | ||
75 | @Column(name = "update_time") | ||
76 | private Timestamp updateTime; | ||
77 | |||
78 | public void copy(CouponHistory source){ | ||
79 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
80 | } | ||
81 | } |
src/main/java/com/topdraw/business/basicdata/coupon/history/repository/CouponHistoryRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.coupon.history.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.sql.Timestamp; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-23 | ||
12 | */ | ||
13 | public interface CouponHistoryRepository extends JpaRepository<CouponHistory, Long>, JpaSpecificationExecutor<CouponHistory> { | ||
14 | |||
15 | Long countByUserId(Long userId); | ||
16 | |||
17 | Long countByUserIdAndExpireTimeBefore(Long userId, Timestamp now); | ||
18 | |||
19 | Long countByUserIdAndExpireTimeBetween(Long userId, Timestamp now, Timestamp expireTime); | ||
20 | } |
src/main/java/com/topdraw/business/basicdata/coupon/history/rest/CouponHistoryController.java
0 → 100644
1 | package com.topdraw.business.basicdata.coupon.history.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory; | ||
5 | import com.topdraw.business.basicdata.coupon.history.service.CouponHistoryService; | ||
6 | import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-23 | ||
18 | */ | ||
19 | @Api(tags = "CouponHistory管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/CouponHistory") | ||
22 | public class CouponHistoryController { | ||
23 | |||
24 | @Autowired | ||
25 | private CouponHistoryService CouponHistoryService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询CouponHistory") | ||
29 | public ResultInfo getCouponHistorys(CouponHistoryQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(CouponHistoryService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有CouponHistory") | ||
35 | public ResultInfo getCouponHistorys(CouponHistoryQueryCriteria criteria) { | ||
36 | return ResultInfo.success(CouponHistoryService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增CouponHistory") | ||
42 | public ResultInfo create(@Validated @RequestBody CouponHistory resources) { | ||
43 | CouponHistoryService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改CouponHistory") | ||
50 | public ResultInfo update(@Validated @RequestBody CouponHistory resources) { | ||
51 | CouponHistoryService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除CouponHistory") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | CouponHistoryService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | } |
src/main/java/com/topdraw/business/basicdata/coupon/history/service/CouponHistoryService.java
0 → 100644
1 | package com.topdraw.business.basicdata.coupon.history.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory; | ||
4 | import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryDTO; | ||
5 | import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.sql.Timestamp; | ||
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | |||
12 | /** | ||
13 | * @author XiangHan | ||
14 | * @date 2021-10-23 | ||
15 | */ | ||
16 | public interface CouponHistoryService { | ||
17 | |||
18 | /** | ||
19 | * 查询数据分页 | ||
20 | * @param criteria 条件参数 | ||
21 | * @param pageable 分页参数 | ||
22 | * @return Map<String,Object> | ||
23 | */ | ||
24 | Map<String,Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable); | ||
25 | |||
26 | /** | ||
27 | * 查询所有数据不分页 | ||
28 | * @param criteria 条件参数 | ||
29 | * @return List<CouponHistoryDTO> | ||
30 | */ | ||
31 | List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria); | ||
32 | |||
33 | /** | ||
34 | * 根据ID查询 | ||
35 | * @param id ID | ||
36 | * @return CouponHistoryDTO | ||
37 | */ | ||
38 | CouponHistoryDTO findById(Long id); | ||
39 | |||
40 | void create(CouponHistory resources); | ||
41 | |||
42 | void update(CouponHistory resources); | ||
43 | |||
44 | void delete(Long id); | ||
45 | |||
46 | Long countByUserId(Long userId); | ||
47 | |||
48 | Long countByUserIdAndExpireTimeBefore(Long userId, Timestamp now); | ||
49 | |||
50 | Long countByUserIdAndExpireTimeBetween(Long userId, Timestamp now, Timestamp expireTime); | ||
51 | } |
src/main/java/com/topdraw/business/basicdata/coupon/history/service/dto/CouponHistoryDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.coupon.history.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-23 | ||
12 | */ | ||
13 | @Data | ||
14 | public class CouponHistoryDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 优惠券id | ||
20 | private Long couponId; | ||
21 | |||
22 | // 领券用户id(对应账号) | ||
23 | private Long userId; | ||
24 | |||
25 | // 优惠券code | ||
26 | private String couponCode; | ||
27 | |||
28 | // 领取人昵称 | ||
29 | private String userNickname; | ||
30 | |||
31 | // 领取时间 | ||
32 | private Timestamp receiveTime; | ||
33 | |||
34 | // 失效时间 | ||
35 | private Timestamp expireTime; | ||
36 | |||
37 | // 使用状态 0:未使用;1:已使用;-1:已过期 | ||
38 | private Integer useStatus; | ||
39 | |||
40 | // 使用时间 | ||
41 | private Timestamp useTime; | ||
42 | |||
43 | // 订单详情id | ||
44 | private Long orderDetailId; | ||
45 | |||
46 | // 创建时间 | ||
47 | private Timestamp createTime; | ||
48 | |||
49 | // 更新时间 | ||
50 | private Timestamp updateTime; | ||
51 | } |
1 | package com.topdraw.business.basicdata.coupon.history.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory; | ||
4 | import com.topdraw.business.basicdata.coupon.history.repository.CouponHistoryRepository; | ||
5 | import com.topdraw.business.basicdata.coupon.history.service.CouponHistoryService; | ||
6 | import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryDTO; | ||
7 | import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.coupon.history.service.mapper.CouponHistoryMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.ValidationUtil; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
14 | import org.springframework.data.domain.Page; | ||
15 | import org.springframework.data.domain.Pageable; | ||
16 | import org.springframework.stereotype.Service; | ||
17 | import org.springframework.transaction.annotation.Propagation; | ||
18 | import org.springframework.transaction.annotation.Transactional; | ||
19 | import org.springframework.util.Assert; | ||
20 | |||
21 | import java.sql.Timestamp; | ||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-23 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class CouponHistoryServiceImpl implements CouponHistoryService { | ||
32 | |||
33 | @Autowired | ||
34 | private CouponHistoryRepository CouponHistoryRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private CouponHistoryMapper CouponHistoryMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<CouponHistory> page = CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(CouponHistoryMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria) { | ||
47 | return CouponHistoryMapper.toDto(CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public CouponHistoryDTO findById(Long id) { | ||
52 | CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseGet(CouponHistory::new); | ||
53 | ValidationUtil.isNull(CouponHistory.getId(),"CouponHistory","id",id); | ||
54 | return CouponHistoryMapper.toDto(CouponHistory); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(CouponHistory resources) { | ||
60 | CouponHistoryRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(CouponHistory resources) { | ||
66 | CouponHistory CouponHistory = CouponHistoryRepository.findById(resources.getId()).orElseGet(CouponHistory::new); | ||
67 | ValidationUtil.isNull( CouponHistory.getId(),"CouponHistory","id",resources.getId()); | ||
68 | CouponHistory.copy(resources); | ||
69 | CouponHistoryRepository.save(CouponHistory); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", CouponHistory.class, id), 1)); | ||
78 | CouponHistoryRepository.delete(CouponHistory); | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Long countByUserId(Long userId) { | ||
83 | return this.CouponHistoryRepository.countByUserId(userId); | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public Long countByUserIdAndExpireTimeBefore(Long userId, Timestamp now) { | ||
88 | return this.CouponHistoryRepository.countByUserIdAndExpireTimeBefore(userId,now); | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | public Long countByUserIdAndExpireTimeBetween(Long userId, Timestamp now, Timestamp expireTime) { | ||
93 | return this.CouponHistoryRepository.countByUserIdAndExpireTimeBetween(userId,now,expireTime); | ||
94 | } | ||
95 | |||
96 | |||
97 | } |
src/main/java/com/topdraw/business/basicdata/coupon/history/service/mapper/CouponHistoryMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.coupon.history.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory; | ||
5 | import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-23 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface CouponHistoryMapper extends BaseMapper<CouponHistoryDTO, CouponHistory> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.coupon.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.coupon.domain.Coupon; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface CouponRepository extends JpaRepository<Coupon, Long>, JpaSpecificationExecutor<Coupon> { | ||
14 | |||
15 | Optional<Coupon> findFirstByCode(String code); | ||
16 | } |
1 | package com.topdraw.business.basicdata.coupon.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.coupon.domain.Coupon; | ||
5 | import com.topdraw.business.basicdata.coupon.service.CouponService; | ||
6 | import com.topdraw.business.basicdata.coupon.service.dto.CouponQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "Coupon管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/Coupon") | ||
22 | public class CouponController { | ||
23 | |||
24 | @Autowired | ||
25 | private CouponService CouponService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询Coupon") | ||
29 | public ResultInfo getCoupons(CouponQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(CouponService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有Coupon") | ||
35 | public ResultInfo getCoupons(CouponQueryCriteria criteria) { | ||
36 | return ResultInfo.success(CouponService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增Coupon") | ||
42 | public ResultInfo create(@Validated @RequestBody Coupon resources) { | ||
43 | CouponService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改Coupon") | ||
50 | public ResultInfo update(@Validated @RequestBody Coupon resources) { | ||
51 | CouponService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除Coupon") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | CouponService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | @GetMapping(value = "/getByCode/{code}") | ||
65 | @ApiOperation(value = "根据标识查询") | ||
66 | public ResultInfo getByCode(@PathVariable String code) { | ||
67 | return ResultInfo.success(CouponService.getByCode(code)); | ||
68 | } | ||
69 | } |
1 | package com.topdraw.business.basicdata.coupon.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.coupon.domain.Coupon; | ||
4 | import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO; | ||
5 | import com.topdraw.business.basicdata.coupon.service.dto.CouponQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface CouponService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(CouponQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<CouponDTO> | ||
29 | */ | ||
30 | List<CouponDTO> queryAll(CouponQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return CouponDTO | ||
36 | */ | ||
37 | CouponDTO findById(Long id); | ||
38 | |||
39 | void create(Coupon resources); | ||
40 | |||
41 | void update(Coupon resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return CouponDTO | ||
49 | */ | ||
50 | CouponDTO getByCode(String code); | ||
51 | } |
1 | package com.topdraw.business.basicdata.coupon.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.math.BigDecimal; | ||
7 | import java.sql.Timestamp; | ||
8 | |||
9 | |||
10 | /** | ||
11 | * @author XiangHan | ||
12 | * @date 2021-10-22 | ||
13 | */ | ||
14 | @Data | ||
15 | public class CouponDTO implements Serializable { | ||
16 | |||
17 | // id | ||
18 | private Long id; | ||
19 | |||
20 | // 标识 | ||
21 | private String code; | ||
22 | |||
23 | // 名称 | ||
24 | private String title; | ||
25 | |||
26 | // 图片 | ||
27 | private String images; | ||
28 | |||
29 | // 发行量,-1代表不限量 | ||
30 | private Integer stock; | ||
31 | |||
32 | // 剩余量,-1代表不限量 | ||
33 | private Integer remainStock; | ||
34 | |||
35 | // 优惠形式:1:现金;2:折扣 | ||
36 | private Integer useType; | ||
37 | |||
38 | // 面额 | ||
39 | private BigDecimal denomination; | ||
40 | |||
41 | // 折扣 | ||
42 | private BigDecimal discount; | ||
43 | |||
44 | // 适用用户范围:1:新用户;2:全体用户 | ||
45 | private Integer userRange; | ||
46 | |||
47 | // 限领次数 -1:无限次; >0:具体次数 | ||
48 | private Integer collectLimit; | ||
49 | |||
50 | // 适用门槛:1:无门槛;2:满减形式 | ||
51 | private Integer thresholdType; | ||
52 | |||
53 | // 满减门槛 | ||
54 | private BigDecimal amountThreshold; | ||
55 | |||
56 | // 产品范围:1:全部商品;2:指定商品 | ||
57 | private Integer itemRange; | ||
58 | |||
59 | // 生效形式:1:固定日期;2:相对日期 | ||
60 | private Integer effectType; | ||
61 | |||
62 | // 生效时间 | ||
63 | private Timestamp startTime; | ||
64 | |||
65 | // 过期时间 | ||
66 | private Timestamp expireTime; | ||
67 | |||
68 | // 自领取当日,几天内有效 | ||
69 | private Integer validDays; | ||
70 | |||
71 | // 使用说明 | ||
72 | private String description; | ||
73 | |||
74 | // 状态0:未开始,1:启用;2:停用 | ||
75 | private Integer status; | ||
76 | |||
77 | // 创建时间 | ||
78 | private Timestamp createTime; | ||
79 | |||
80 | // 更新时间 | ||
81 | private Timestamp updateTime; | ||
82 | } |
1 | package com.topdraw.business.basicdata.coupon.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.coupon.domain.Coupon; | ||
4 | import com.topdraw.business.basicdata.coupon.repository.CouponRepository; | ||
5 | import com.topdraw.business.basicdata.coupon.service.CouponService; | ||
6 | import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO; | ||
7 | import com.topdraw.business.basicdata.coupon.service.dto.CouponQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.coupon.service.mapper.CouponMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class CouponServiceImpl implements CouponService { | ||
32 | |||
33 | @Autowired | ||
34 | private CouponRepository CouponRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private CouponMapper CouponMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(CouponQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<Coupon> page = CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(CouponMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<CouponDTO> queryAll(CouponQueryCriteria criteria) { | ||
47 | return CouponMapper.toDto(CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public CouponDTO findById(Long id) { | ||
52 | Coupon Coupon = CouponRepository.findById(id).orElseGet(Coupon::new); | ||
53 | ValidationUtil.isNull(Coupon.getId(),"Coupon","id",id); | ||
54 | return CouponMapper.toDto(Coupon); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(Coupon resources) { | ||
60 | CouponRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(Coupon resources) { | ||
66 | Coupon Coupon = CouponRepository.findById(resources.getId()).orElseGet(Coupon::new); | ||
67 | ValidationUtil.isNull( Coupon.getId(),"Coupon","id",resources.getId()); | ||
68 | Coupon.copy(resources); | ||
69 | CouponRepository.save(Coupon); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | Coupon Coupon = CouponRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Coupon.class, id), 1)); | ||
78 | CouponRepository.delete(Coupon); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public CouponDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? CouponMapper.toDto(CouponRepository.findFirstByCode(code).orElseGet(Coupon::new)) | ||
85 | : new CouponDTO(); | ||
86 | } | ||
87 | } |
1 | package com.topdraw.business.basicdata.coupon.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.coupon.domain.Coupon; | ||
5 | import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface CouponMapper extends BaseMapper<CouponDTO, Coupon> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.exp.detail.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_exp_detail") | ||
24 | public class ExpDetail implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 应用code | ||
37 | @Column(name = "app_code") | ||
38 | private String appCode; | ||
39 | |||
40 | // 会员id | ||
41 | @Column(name = "member_id", nullable = false) | ||
42 | private Long memberId; | ||
43 | |||
44 | // 账号id | ||
45 | @Column(name = "account_id") | ||
46 | private Long accountId; | ||
47 | |||
48 | // 原始成长值 | ||
49 | @Column(name = "original_exp", nullable = false) | ||
50 | private Long originalExp; | ||
51 | |||
52 | // 结果成长值 | ||
53 | @Column(name = "result_exp", nullable = false) | ||
54 | private Long resultExp; | ||
55 | |||
56 | // 成长值变化,一般为正数 | ||
57 | @Column(name = "exp", nullable = false) | ||
58 | private Long exp; | ||
59 | |||
60 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
61 | @Column(name = "device_type", nullable = false) | ||
62 | private Integer deviceType; | ||
63 | |||
64 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 | ||
65 | @Column(name = "evt_type", nullable = false) | ||
66 | private Integer evtType; | ||
67 | |||
68 | // 订单id(针对订购操作) | ||
69 | @Column(name = "order_id") | ||
70 | private Long orderId; | ||
71 | |||
72 | // 节目id(针对观影操作) | ||
73 | @Column(name = "media_id") | ||
74 | private Long mediaId; | ||
75 | |||
76 | // 活动id(针对参与活动) | ||
77 | @Column(name = "activity_id") | ||
78 | private Long activityId; | ||
79 | |||
80 | // 成长值变化描述,用于管理侧显示 | ||
81 | @Column(name = "description", nullable = false) | ||
82 | private String description; | ||
83 | |||
84 | // 创建时间 | ||
85 | @CreatedDate | ||
86 | @Column(name = "create_time") | ||
87 | private Timestamp createTime; | ||
88 | |||
89 | // 更新时间 | ||
90 | @LastModifiedDate | ||
91 | @Column(name = "update_time") | ||
92 | private Timestamp updateTime; | ||
93 | |||
94 | public void copy(ExpDetail source){ | ||
95 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
96 | } | ||
97 | } |
src/main/java/com/topdraw/business/basicdata/exp/detail/repository/ExpDetailRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.exp.detail.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface ExpDetailRepository extends JpaRepository<ExpDetail, Long>, JpaSpecificationExecutor<ExpDetail> { | ||
14 | |||
15 | Optional<ExpDetail> findFirstByCode(String code); | ||
16 | } |
1 | package com.topdraw.business.basicdata.exp.detail.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail; | ||
5 | import com.topdraw.business.basicdata.exp.detail.service.ExpDetailService; | ||
6 | import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "ExpDetail管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/ExpDetail") | ||
22 | public class ExpDetailController { | ||
23 | |||
24 | @Autowired | ||
25 | private ExpDetailService ExpDetailService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询ExpDetail") | ||
29 | public ResultInfo getExpDetails(ExpDetailQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(ExpDetailService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有ExpDetail") | ||
35 | public ResultInfo getExpDetails(ExpDetailQueryCriteria criteria) { | ||
36 | return ResultInfo.success(ExpDetailService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增ExpDetail") | ||
42 | public ResultInfo create(@Validated @RequestBody ExpDetail resources) { | ||
43 | ExpDetailService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改ExpDetail") | ||
50 | public ResultInfo update(@Validated @RequestBody ExpDetail resources) { | ||
51 | ExpDetailService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除ExpDetail") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | ExpDetailService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | @GetMapping(value = "/getByCode/{code}") | ||
65 | @ApiOperation(value = "根据标识查询") | ||
66 | public ResultInfo getByCode(@PathVariable String code) { | ||
67 | return ResultInfo.success(ExpDetailService.getByCode(code)); | ||
68 | } | ||
69 | } |
1 | package com.topdraw.business.basicdata.exp.detail.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail; | ||
4 | import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailDTO; | ||
5 | import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface ExpDetailService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<ExpDetailDTO> | ||
29 | */ | ||
30 | List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return ExpDetailDTO | ||
36 | */ | ||
37 | ExpDetailDTO findById(Long id); | ||
38 | |||
39 | void create(ExpDetail resources); | ||
40 | |||
41 | void update(ExpDetail resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return ExpDetailDTO | ||
49 | */ | ||
50 | ExpDetailDTO getByCode(String code); | ||
51 | } |
1 | package com.topdraw.business.basicdata.exp.detail.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class ExpDetailDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 应用code | ||
23 | private String appCode; | ||
24 | |||
25 | // 会员id | ||
26 | private Long memberId; | ||
27 | |||
28 | // 账号id | ||
29 | private Long accountId; | ||
30 | |||
31 | // 原始成长值 | ||
32 | private Long originalExp; | ||
33 | |||
34 | // 结果成长值 | ||
35 | private Long resultExp; | ||
36 | |||
37 | // 成长值变化,一般为正数 | ||
38 | private Long exp; | ||
39 | |||
40 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
41 | private Integer deviceType; | ||
42 | |||
43 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 | ||
44 | private Integer evtType; | ||
45 | |||
46 | // 订单id(针对订购操作) | ||
47 | private Long orderId; | ||
48 | |||
49 | // 节目id(针对观影操作) | ||
50 | private Long mediaId; | ||
51 | |||
52 | // 活动id(针对参与活动) | ||
53 | private Long activityId; | ||
54 | |||
55 | // 成长值变化描述,用于管理侧显示 | ||
56 | private String description; | ||
57 | |||
58 | // 创建时间 | ||
59 | private Timestamp createTime; | ||
60 | |||
61 | // 更新时间 | ||
62 | private Timestamp updateTime; | ||
63 | } |
src/main/java/com/topdraw/business/basicdata/exp/detail/service/impl/ExpDetailServiceImpl.java
0 → 100644
1 | package com.topdraw.business.basicdata.exp.detail.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail; | ||
4 | import com.topdraw.business.basicdata.exp.detail.repository.ExpDetailRepository; | ||
5 | import com.topdraw.business.basicdata.exp.detail.service.ExpDetailService; | ||
6 | import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailDTO; | ||
7 | import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.exp.detail.service.mapper.ExpDetailMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class ExpDetailServiceImpl implements ExpDetailService { | ||
32 | |||
33 | @Autowired | ||
34 | private ExpDetailRepository ExpDetailRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private ExpDetailMapper ExpDetailMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<ExpDetail> page = ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(ExpDetailMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria) { | ||
47 | return ExpDetailMapper.toDto(ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public ExpDetailDTO findById(Long id) { | ||
52 | ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseGet(ExpDetail::new); | ||
53 | ValidationUtil.isNull(ExpDetail.getId(),"ExpDetail","id",id); | ||
54 | return ExpDetailMapper.toDto(ExpDetail); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(ExpDetail resources) { | ||
60 | ExpDetailRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(ExpDetail resources) { | ||
66 | ExpDetail ExpDetail = ExpDetailRepository.findById(resources.getId()).orElseGet(ExpDetail::new); | ||
67 | ValidationUtil.isNull( ExpDetail.getId(),"ExpDetail","id",resources.getId()); | ||
68 | ExpDetail.copy(resources); | ||
69 | ExpDetailRepository.save(ExpDetail); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpDetail.class, id), 1)); | ||
78 | ExpDetailRepository.delete(ExpDetail); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public ExpDetailDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? ExpDetailMapper.toDto(ExpDetailRepository.findFirstByCode(code).orElseGet(ExpDetail::new)) | ||
85 | : new ExpDetailDTO(); | ||
86 | } | ||
87 | } |
src/main/java/com/topdraw/business/basicdata/exp/detail/service/mapper/ExpDetailMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.exp.detail.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail; | ||
5 | import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface ExpDetailMapper extends BaseMapper<ExpDetailDTO, ExpDetail> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.exp.history.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_exp_history") | ||
24 | public class ExpHistory implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 会员id | ||
37 | @Column(name = "member_id", nullable = false) | ||
38 | private Long memberId; | ||
39 | |||
40 | // 账号id | ||
41 | @Column(name = "account_id") | ||
42 | private Long accountId; | ||
43 | |||
44 | // 原始成长值 | ||
45 | @Column(name = "original_exp", nullable = false) | ||
46 | private Long originalExp; | ||
47 | |||
48 | // 结果成长值 | ||
49 | @Column(name = "result_exp", nullable = false) | ||
50 | private Long resultExp; | ||
51 | |||
52 | // 成长值变化,一般为正数 | ||
53 | @Column(name = "exp", nullable = false) | ||
54 | private Long exp; | ||
55 | |||
56 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)4.系统赠送 | ||
57 | @Column(name = "device_type", nullable = false) | ||
58 | private Integer deviceType; | ||
59 | |||
60 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 | ||
61 | @Column(name = "evt_type", nullable = false) | ||
62 | private Integer evtType; | ||
63 | |||
64 | // 订单id(针对订购操作) | ||
65 | @Column(name = "order_id") | ||
66 | private Long orderId; | ||
67 | |||
68 | // 节目id(针对观影操作) | ||
69 | @Column(name = "media_id") | ||
70 | private Long mediaId; | ||
71 | |||
72 | // 活动id(针对参与活动) | ||
73 | @Column(name = "activity_id") | ||
74 | private Long activityId; | ||
75 | |||
76 | // 成长值变化描述,用于管理侧显示 | ||
77 | @Column(name = "description", nullable = false) | ||
78 | private String description; | ||
79 | |||
80 | // 创建时间 | ||
81 | @CreatedDate | ||
82 | @Column(name = "create_time") | ||
83 | private Timestamp createTime; | ||
84 | |||
85 | // 更新时间 | ||
86 | @LastModifiedDate | ||
87 | @Column(name = "update_time") | ||
88 | private Timestamp updateTime; | ||
89 | |||
90 | public void copy(ExpHistory source){ | ||
91 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
92 | } | ||
93 | } |
src/main/java/com/topdraw/business/basicdata/exp/history/repository/ExpHistoryRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.exp.history.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.exp.history.domain.ExpHistory; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface ExpHistoryRepository extends JpaRepository<ExpHistory, Long>, JpaSpecificationExecutor<ExpHistory> { | ||
14 | |||
15 | Optional<ExpHistory> findFirstByCode(String code); | ||
16 | } |
1 | package com.topdraw.business.basicdata.exp.history.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.exp.history.domain.ExpHistory; | ||
5 | import com.topdraw.business.basicdata.exp.history.service.ExpHistoryService; | ||
6 | import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "ExpHistory管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/ExpHistory") | ||
22 | public class ExpHistoryController { | ||
23 | |||
24 | @Autowired | ||
25 | private ExpHistoryService ExpHistoryService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询ExpHistory") | ||
29 | public ResultInfo getExpHistorys(ExpHistoryQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(ExpHistoryService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有ExpHistory") | ||
35 | public ResultInfo getExpHistorys(ExpHistoryQueryCriteria criteria) { | ||
36 | return ResultInfo.success(ExpHistoryService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增ExpHistory") | ||
42 | public ResultInfo create(@Validated @RequestBody ExpHistory resources) { | ||
43 | ExpHistoryService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改ExpHistory") | ||
50 | public ResultInfo update(@Validated @RequestBody ExpHistory resources) { | ||
51 | ExpHistoryService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除ExpHistory") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | ExpHistoryService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | @GetMapping(value = "/getByCode/{code}") | ||
65 | @ApiOperation(value = "根据标识查询") | ||
66 | public ResultInfo getByCode(@PathVariable String code) { | ||
67 | return ResultInfo.success(ExpHistoryService.getByCode(code)); | ||
68 | } | ||
69 | } |
1 | package com.topdraw.business.basicdata.exp.history.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.exp.history.domain.ExpHistory; | ||
4 | import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryDTO; | ||
5 | import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface ExpHistoryService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<ExpHistoryDTO> | ||
29 | */ | ||
30 | List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return ExpHistoryDTO | ||
36 | */ | ||
37 | ExpHistoryDTO findById(Long id); | ||
38 | |||
39 | void create(ExpHistory resources); | ||
40 | |||
41 | void update(ExpHistory resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return ExpHistoryDTO | ||
49 | */ | ||
50 | ExpHistoryDTO getByCode(String code); | ||
51 | } |
1 | package com.topdraw.business.basicdata.exp.history.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class ExpHistoryDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 会员id | ||
23 | private Long memberId; | ||
24 | |||
25 | // 账号id | ||
26 | private Long accountId; | ||
27 | |||
28 | // 原始成长值 | ||
29 | private Long originalExp; | ||
30 | |||
31 | // 结果成长值 | ||
32 | private Long resultExp; | ||
33 | |||
34 | // 成长值变化,一般为正数 | ||
35 | private Long exp; | ||
36 | |||
37 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)4.系统赠送 | ||
38 | private Integer deviceType; | ||
39 | |||
40 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 | ||
41 | private Integer evtType; | ||
42 | |||
43 | // 订单id(针对订购操作) | ||
44 | private Long orderId; | ||
45 | |||
46 | // 节目id(针对观影操作) | ||
47 | private Long mediaId; | ||
48 | |||
49 | // 活动id(针对参与活动) | ||
50 | private Long activityId; | ||
51 | |||
52 | // 成长值变化描述,用于管理侧显示 | ||
53 | private String description; | ||
54 | |||
55 | // 创建时间 | ||
56 | private Timestamp createTime; | ||
57 | |||
58 | // 更新时间 | ||
59 | private Timestamp updateTime; | ||
60 | } |
src/main/java/com/topdraw/business/basicdata/exp/history/service/impl/ExpHistoryServiceImpl.java
0 → 100644
1 | package com.topdraw.business.basicdata.exp.history.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.exp.history.domain.ExpHistory; | ||
4 | import com.topdraw.business.basicdata.exp.history.repository.ExpHistoryRepository; | ||
5 | import com.topdraw.business.basicdata.exp.history.service.ExpHistoryService; | ||
6 | import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryDTO; | ||
7 | import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.exp.history.service.mapper.ExpHistoryMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class ExpHistoryServiceImpl implements ExpHistoryService { | ||
32 | |||
33 | @Autowired | ||
34 | private ExpHistoryRepository ExpHistoryRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private ExpHistoryMapper ExpHistoryMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<ExpHistory> page = ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(ExpHistoryMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria) { | ||
47 | return ExpHistoryMapper.toDto(ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public ExpHistoryDTO findById(Long id) { | ||
52 | ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseGet(ExpHistory::new); | ||
53 | ValidationUtil.isNull(ExpHistory.getId(),"ExpHistory","id",id); | ||
54 | return ExpHistoryMapper.toDto(ExpHistory); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(ExpHistory resources) { | ||
60 | ExpHistoryRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(ExpHistory resources) { | ||
66 | ExpHistory ExpHistory = ExpHistoryRepository.findById(resources.getId()).orElseGet(ExpHistory::new); | ||
67 | ValidationUtil.isNull( ExpHistory.getId(),"ExpHistory","id",resources.getId()); | ||
68 | ExpHistory.copy(resources); | ||
69 | ExpHistoryRepository.save(ExpHistory); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpHistory.class, id), 1)); | ||
78 | ExpHistoryRepository.delete(ExpHistory); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public ExpHistoryDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? ExpHistoryMapper.toDto(ExpHistoryRepository.findFirstByCode(code).orElseGet(ExpHistory::new)) | ||
85 | : new ExpHistoryDTO(); | ||
86 | } | ||
87 | } |
src/main/java/com/topdraw/business/basicdata/exp/history/service/mapper/ExpHistoryMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.exp.history.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.exp.history.domain.ExpHistory; | ||
5 | import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface ExpHistoryMapper extends BaseMapper<ExpHistoryDTO, ExpHistory> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.member.address.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_member_address") | ||
24 | public class MemberAddress implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 会员id | ||
33 | @Column(name = "member_id", nullable = false) | ||
34 | private Long memberId; | ||
35 | |||
36 | // 类型 1:家;2:公司;3:学校 | ||
37 | @Column(name = "type", nullable = false) | ||
38 | private Integer type; | ||
39 | |||
40 | // 是否默认地址 | ||
41 | @Column(name = "is_default", nullable = false) | ||
42 | private Integer isDefault; | ||
43 | |||
44 | // 显示顺序 | ||
45 | @Column(name = "sequence") | ||
46 | private Integer sequence; | ||
47 | |||
48 | // 状态 0:不可用;1-可用 | ||
49 | @Column(name = "status", nullable = false) | ||
50 | private Integer status; | ||
51 | |||
52 | // 联系人姓名 | ||
53 | @Column(name = "contactor", nullable = false) | ||
54 | private String contactor; | ||
55 | |||
56 | // 联系人电话 | ||
57 | @Column(name = "cellphone", nullable = false) | ||
58 | private String cellphone; | ||
59 | |||
60 | // 国家 | ||
61 | @Column(name = "country", nullable = false) | ||
62 | private String country; | ||
63 | |||
64 | // 省份 | ||
65 | @Column(name = "province", nullable = false) | ||
66 | private String province; | ||
67 | |||
68 | // 城市 | ||
69 | @Column(name = "city", nullable = false) | ||
70 | private String city; | ||
71 | |||
72 | // 区县 | ||
73 | @Column(name = "district", nullable = false) | ||
74 | private String district; | ||
75 | |||
76 | // 地址 | ||
77 | @Column(name = "address", nullable = false) | ||
78 | private String address; | ||
79 | |||
80 | // 邮编 | ||
81 | @Column(name = "zip_code") | ||
82 | private String zipCode; | ||
83 | |||
84 | // 创建时间 | ||
85 | @CreatedDate | ||
86 | @Column(name = "create_time") | ||
87 | private Timestamp createTime; | ||
88 | |||
89 | // 更新时间 | ||
90 | @LastModifiedDate | ||
91 | @Column(name = "update_time") | ||
92 | private Timestamp updateTime; | ||
93 | |||
94 | public void copy(MemberAddress source){ | ||
95 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
96 | } | ||
97 | } |
src/main/java/com/topdraw/business/basicdata/member/address/repository/MemberAddressRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.address.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.address.domain.MemberAddress; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | /** | ||
8 | * @author XiangHan | ||
9 | * @date 2021-10-22 | ||
10 | */ | ||
11 | public interface MemberAddressRepository extends JpaRepository<MemberAddress, Long>, JpaSpecificationExecutor<MemberAddress> { | ||
12 | |||
13 | } |
src/main/java/com/topdraw/business/basicdata/member/address/rest/MemberAddressController.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.address.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.member.address.domain.MemberAddress; | ||
5 | import com.topdraw.business.basicdata.member.address.service.MemberAddressService; | ||
6 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "MemberAddress管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/MemberAddress") | ||
22 | public class MemberAddressController { | ||
23 | |||
24 | @Autowired | ||
25 | private MemberAddressService MemberAddressService; | ||
26 | |||
27 | @GetMapping(value = "/pageMemberAddress") | ||
28 | @ApiOperation("查询MemberAddress") | ||
29 | public ResultInfo pageMemberAddress(MemberAddressQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(MemberAddressService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/findById/{id}") | ||
34 | @ApiOperation("查询指定MemberAddress") | ||
35 | public ResultInfo findById(@PathVariable(value = "id") Long id) { | ||
36 | return ResultInfo.success(MemberAddressService.findById(id)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping(value = "/create") | ||
41 | @ApiOperation("新增MemberAddress") | ||
42 | public ResultInfo create(@Validated @RequestBody MemberAddress resources) { | ||
43 | MemberAddressService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping(value = "/update") | ||
49 | @ApiOperation("修改MemberAddress") | ||
50 | public ResultInfo update(@Validated @RequestBody MemberAddress resources) { | ||
51 | MemberAddressService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | @Log | ||
56 | @DeleteMapping(value = "/delete/{id}") | ||
57 | @ApiOperation("删除MemberAddress") | ||
58 | public ResultInfo delete(@PathVariable Long id) { | ||
59 | MemberAddressService.delete(id); | ||
60 | return ResultInfo.success(); | ||
61 | } | ||
62 | |||
63 | } |
src/main/java/com/topdraw/business/basicdata/member/address/service/MemberAddressService.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.address.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.address.domain.MemberAddress; | ||
4 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO; | ||
5 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface MemberAddressService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<MemberAddressDTO> | ||
29 | */ | ||
30 | List<MemberAddressDTO> queryAll(MemberAddressQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return MemberAddressDTO | ||
36 | */ | ||
37 | MemberAddressDTO findById(Long id); | ||
38 | |||
39 | void create(MemberAddress resources); | ||
40 | |||
41 | void update(MemberAddress resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | } |
src/main/java/com/topdraw/business/basicdata/member/address/service/dto/MemberAddressDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.address.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class MemberAddressDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 会员id | ||
20 | private Long memberId; | ||
21 | |||
22 | // 类型 1:家;2:公司;3:学校 | ||
23 | private Integer type; | ||
24 | |||
25 | // 是否默认地址 | ||
26 | private Integer isDefault; | ||
27 | |||
28 | // 显示顺序 | ||
29 | private Integer sequence; | ||
30 | |||
31 | // 状态 0:不可用;1-可用 | ||
32 | private Integer status; | ||
33 | |||
34 | // 联系人姓名 | ||
35 | private String contactor; | ||
36 | |||
37 | // 联系人电话 | ||
38 | private String cellphone; | ||
39 | |||
40 | // 国家 | ||
41 | private String country; | ||
42 | |||
43 | // 省份 | ||
44 | private String province; | ||
45 | |||
46 | // 城市 | ||
47 | private String city; | ||
48 | |||
49 | // 区县 | ||
50 | private String district; | ||
51 | |||
52 | // 地址 | ||
53 | private String address; | ||
54 | |||
55 | // 邮编 | ||
56 | private String zipCode; | ||
57 | |||
58 | // 创建时间 | ||
59 | private Timestamp createTime; | ||
60 | |||
61 | // 更新时间 | ||
62 | private Timestamp updateTime; | ||
63 | } |
1 | package com.topdraw.business.basicdata.member.address.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.address.domain.MemberAddress; | ||
4 | import com.topdraw.business.basicdata.member.address.repository.MemberAddressRepository; | ||
5 | import com.topdraw.business.basicdata.member.address.service.MemberAddressService; | ||
6 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO; | ||
7 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.member.address.service.mapper.MemberAddressMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.ValidationUtil; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
14 | import org.springframework.data.domain.Page; | ||
15 | import org.springframework.data.domain.Pageable; | ||
16 | import org.springframework.stereotype.Service; | ||
17 | import org.springframework.transaction.annotation.Propagation; | ||
18 | import org.springframework.transaction.annotation.Transactional; | ||
19 | import org.springframework.util.Assert; | ||
20 | |||
21 | import java.util.List; | ||
22 | import java.util.Map; | ||
23 | |||
24 | /** | ||
25 | * @author XiangHan | ||
26 | * @date 2021-10-22 | ||
27 | */ | ||
28 | @Service | ||
29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
30 | public class MemberAddressServiceImpl implements MemberAddressService { | ||
31 | |||
32 | @Autowired | ||
33 | private MemberAddressRepository MemberAddressRepository; | ||
34 | |||
35 | @Autowired | ||
36 | private MemberAddressMapper MemberAddressMapper; | ||
37 | |||
38 | @Override | ||
39 | public Map<String, Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable) { | ||
40 | Page<MemberAddress> page = MemberAddressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
41 | return PageUtil.toPage(page.map(MemberAddressMapper::toDto)); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public List<MemberAddressDTO> queryAll(MemberAddressQueryCriteria criteria) { | ||
46 | return MemberAddressMapper.toDto(MemberAddressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public MemberAddressDTO findById(Long id) { | ||
51 | MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseGet(MemberAddress::new); | ||
52 | ValidationUtil.isNull(MemberAddress.getId(),"MemberAddress","id",id); | ||
53 | return MemberAddressMapper.toDto(MemberAddress); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | @Transactional(rollbackFor = Exception.class) | ||
58 | public void create(MemberAddress resources) { | ||
59 | MemberAddressRepository.save(resources); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | @Transactional(rollbackFor = Exception.class) | ||
64 | public void update(MemberAddress resources) { | ||
65 | MemberAddress MemberAddress = MemberAddressRepository.findById(resources.getId()).orElseGet(MemberAddress::new); | ||
66 | ValidationUtil.isNull( MemberAddress.getId(),"MemberAddress","id",resources.getId()); | ||
67 | MemberAddress.copy(resources); | ||
68 | MemberAddressRepository.save(MemberAddress); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | @Transactional(rollbackFor = Exception.class) | ||
73 | public void delete(Long id) { | ||
74 | Assert.notNull(id, "The given id must not be null!"); | ||
75 | MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseThrow( | ||
76 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberAddress.class, id), 1)); | ||
77 | MemberAddressRepository.delete(MemberAddress); | ||
78 | } | ||
79 | |||
80 | |||
81 | } |
src/main/java/com/topdraw/business/basicdata/member/address/service/mapper/MemberAddressMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.address.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.member.address.domain.MemberAddress; | ||
5 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface MemberAddressMapper extends BaseMapper<MemberAddressDTO, MemberAddress> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.member.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_member") | ||
24 | public class Member implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 类型 1:大屏;2:小屏 | ||
37 | @Column(name = "`type`", nullable = false) | ||
38 | private Integer type; | ||
39 | |||
40 | // 状态 0:不可用;1:可用 | ||
41 | @Column(name = "`status`", nullable = false) | ||
42 | private Integer status; | ||
43 | |||
44 | // 昵称 base64 | ||
45 | @Column(name = "nickname") | ||
46 | private String nickname; | ||
47 | |||
48 | // 描述 | ||
49 | @Column(name = "description") | ||
50 | private String description; | ||
51 | |||
52 | // 性别 0:女;1:男;-1:未知 | ||
53 | @Column(name = "gender", nullable = false) | ||
54 | private Integer gender; | ||
55 | |||
56 | // 生日 | ||
57 | @Column(name = "birthday") | ||
58 | private String birthday; | ||
59 | |||
60 | // 头像 | ||
61 | @Column(name = "avatar_url") | ||
62 | private String avatarUrl; | ||
63 | |||
64 | // 分组信息 | ||
65 | @Column(name = "`groups`") | ||
66 | private String groups; | ||
67 | |||
68 | // 标签 | ||
69 | @Column(name = "tags") | ||
70 | private String tags; | ||
71 | |||
72 | // 是否会员 0:非会员;1:会员 | ||
73 | @Column(name = "vip", nullable = false) | ||
74 | private Integer vip; | ||
75 | |||
76 | // 会员等级(对应level表的level字段,非id) | ||
77 | @Column(name = "`level`", nullable = false) | ||
78 | private Integer level; | ||
79 | |||
80 | // 成长值 | ||
81 | @Column(name = "`exp`") | ||
82 | private Long exp; | ||
83 | |||
84 | // 当前积分 | ||
85 | @Column(name = "`points`") | ||
86 | private Integer points; | ||
87 | |||
88 | // 即将到期积分(一个月内) | ||
89 | @Column(name = "due_points") | ||
90 | private Long duePoints; | ||
91 | |||
92 | // 优惠券数量 | ||
93 | @Column(name = "coupon_amount") | ||
94 | private Integer couponAmount; | ||
95 | |||
96 | // 即将过期优惠券数量 | ||
97 | @Column(name = "due_coupon_amount") | ||
98 | private Integer dueCouponAmount; | ||
99 | |||
100 | // iptv账号id | ||
101 | @Column(name = "user_iptv_id") | ||
102 | private Long userIptvId; | ||
103 | |||
104 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
105 | @Column(name = "bind_iptv_platform_type") | ||
106 | private Integer bindIptvPlatformType; | ||
107 | |||
108 | // iptv账号绑定时间 | ||
109 | @Column(name = "bind_iptv_time") | ||
110 | private Timestamp bindIptvTime; | ||
111 | |||
112 | // 创建时间 | ||
113 | @CreatedDate | ||
114 | @Column(name = "create_time") | ||
115 | private Timestamp createTime; | ||
116 | |||
117 | // 更新时间 | ||
118 | @LastModifiedDate | ||
119 | @Column(name = "update_time") | ||
120 | private Timestamp updateTime; | ||
121 | |||
122 | // 是否在黑名单 1:是;0否 | ||
123 | // @Column(name = "black_status") | ||
124 | // private Integer blackStatus; | ||
125 | |||
126 | public void copy(Member source){ | ||
127 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
128 | } | ||
129 | } |
1 | package com.topdraw.business.basicdata.member.level.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_member_level") | ||
24 | public class MemberLevel implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 名称 | ||
37 | @Column(name = "name", nullable = false) | ||
38 | private String name; | ||
39 | |||
40 | // 状态 0:未启用;1:启用 | ||
41 | @Column(name = "status", nullable = false) | ||
42 | private Integer status; | ||
43 | |||
44 | // 对应成长值 | ||
45 | @Column(name = "exp_value", nullable = false) | ||
46 | private Long expValue; | ||
47 | |||
48 | // 等级(不可重复,数字越大等级越高) | ||
49 | @Column(name = "level", nullable = false) | ||
50 | private Integer level; | ||
51 | |||
52 | // 会员徽标 | ||
53 | @Column(name = "icon_url") | ||
54 | private String iconUrl; | ||
55 | |||
56 | // 描述 | ||
57 | @Column(name = "description") | ||
58 | private String description; | ||
59 | |||
60 | // 对应任务id,通过此字段可获得该等级所对应的权益 | ||
61 | @Column(name = "task_id") | ||
62 | private Long taskId; | ||
63 | |||
64 | // 创建时间 | ||
65 | @CreatedDate | ||
66 | @Column(name = "create_time") | ||
67 | private Timestamp createTime; | ||
68 | |||
69 | // 更新时间 | ||
70 | @LastModifiedDate | ||
71 | @Column(name = "update_time") | ||
72 | private Timestamp updateTime; | ||
73 | |||
74 | public void copy(MemberLevel source){ | ||
75 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
76 | } | ||
77 | } |
src/main/java/com/topdraw/business/basicdata/member/level/repository/MemberLevelRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.level.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.level.domain.MemberLevel; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.List; | ||
8 | import java.util.Optional; | ||
9 | |||
10 | /** | ||
11 | * @author XiangHan | ||
12 | * @date 2021-10-22 | ||
13 | */ | ||
14 | public interface MemberLevelRepository extends JpaRepository<MemberLevel, Long>, JpaSpecificationExecutor<MemberLevel> { | ||
15 | |||
16 | Optional<MemberLevel> findFirstByCode(String code); | ||
17 | |||
18 | List<MemberLevel> findByLevelAndStatus(Integer level, Integer status); | ||
19 | } |
src/main/java/com/topdraw/business/basicdata/member/level/rest/MemberLevelController.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.level.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.member.level.domain.MemberLevel; | ||
5 | import com.topdraw.business.basicdata.member.level.service.MemberLevelService; | ||
6 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "MemberLevel管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/MemberLevel") | ||
22 | public class MemberLevelController { | ||
23 | |||
24 | @Autowired | ||
25 | private MemberLevelService MemberLevelService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询MemberLevel") | ||
29 | public ResultInfo getMemberLevels(MemberLevelQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(MemberLevelService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有MemberLevel") | ||
35 | public ResultInfo getMemberLevels(MemberLevelQueryCriteria criteria) { | ||
36 | return ResultInfo.success(MemberLevelService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增MemberLevel") | ||
42 | public ResultInfo create(@Validated @RequestBody MemberLevel resources) { | ||
43 | MemberLevelService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改MemberLevel") | ||
50 | public ResultInfo update(@Validated @RequestBody MemberLevel resources) { | ||
51 | MemberLevelService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除MemberLevel") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | MemberLevelService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | @GetMapping(value = "/getByCode/{code}") | ||
65 | @ApiOperation(value = "根据标识查询") | ||
66 | public ResultInfo getByCode(@PathVariable String code) { | ||
67 | return ResultInfo.success(MemberLevelService.getByCode(code)); | ||
68 | } | ||
69 | } |
src/main/java/com/topdraw/business/basicdata/member/level/service/MemberLevelService.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.level.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.level.domain.MemberLevel; | ||
4 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO; | ||
5 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface MemberLevelService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(MemberLevelQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<MemberLevelDTO> | ||
29 | */ | ||
30 | List<MemberLevelDTO> queryAll(MemberLevelQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return MemberLevelDTO | ||
36 | */ | ||
37 | MemberLevelDTO findById(Long id); | ||
38 | |||
39 | void create(MemberLevel resources); | ||
40 | |||
41 | void update(MemberLevel resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return MemberLevelDTO | ||
49 | */ | ||
50 | MemberLevelDTO getByCode(String code); | ||
51 | |||
52 | List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status); | ||
53 | } |
src/main/java/com/topdraw/business/basicdata/member/level/service/dto/MemberLevelDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.level.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class MemberLevelDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 名称 | ||
23 | private String name; | ||
24 | |||
25 | // 状态 0:未启用;1:启用 | ||
26 | private Integer status; | ||
27 | |||
28 | // 对应成长值 | ||
29 | private Long expValue; | ||
30 | |||
31 | // 等级(不可重复,数字越大等级越高) | ||
32 | private Integer level; | ||
33 | |||
34 | // 会员徽标 | ||
35 | private String iconUrl; | ||
36 | |||
37 | // 描述 | ||
38 | private String description; | ||
39 | |||
40 | // 对应任务id,通过此字段可获得该等级所对应的权益 | ||
41 | private Long taskId; | ||
42 | |||
43 | // 创建时间 | ||
44 | private Timestamp createTime; | ||
45 | |||
46 | // 更新时间 | ||
47 | private Timestamp updateTime; | ||
48 | } |
src/main/java/com/topdraw/business/basicdata/member/level/service/impl/MemberLevelServiceImpl.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.level.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.level.domain.MemberLevel; | ||
4 | import com.topdraw.business.basicdata.member.level.repository.MemberLevelRepository; | ||
5 | import com.topdraw.business.basicdata.member.level.service.MemberLevelService; | ||
6 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO; | ||
7 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.member.level.service.mapper.MemberLevelMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class MemberLevelServiceImpl implements MemberLevelService { | ||
32 | |||
33 | @Autowired | ||
34 | private MemberLevelRepository MemberLevelRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private MemberLevelMapper MemberLevelMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(MemberLevelQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<MemberLevel> page = MemberLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(MemberLevelMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<MemberLevelDTO> queryAll(MemberLevelQueryCriteria criteria) { | ||
47 | return MemberLevelMapper.toDto(MemberLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public MemberLevelDTO findById(Long id) { | ||
52 | MemberLevel MemberLevel = MemberLevelRepository.findById(id).orElseGet(MemberLevel::new); | ||
53 | ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); | ||
54 | return MemberLevelMapper.toDto(MemberLevel); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(MemberLevel resources) { | ||
60 | MemberLevelRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(MemberLevel resources) { | ||
66 | MemberLevel MemberLevel = MemberLevelRepository.findById(resources.getId()).orElseGet(MemberLevel::new); | ||
67 | ValidationUtil.isNull( MemberLevel.getId(),"MemberLevel","id",resources.getId()); | ||
68 | MemberLevel.copy(resources); | ||
69 | MemberLevelRepository.save(MemberLevel); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | MemberLevel MemberLevel = MemberLevelRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberLevel.class, id), 1)); | ||
78 | MemberLevelRepository.delete(MemberLevel); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public MemberLevelDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? MemberLevelMapper.toDto(MemberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) | ||
85 | : new MemberLevelDTO(); | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | ||
90 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | ||
91 | } | ||
92 | } |
src/main/java/com/topdraw/business/basicdata/member/level/service/mapper/MemberLevelMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.level.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.member.level.domain.MemberLevel; | ||
5 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface MemberLevelMapper extends BaseMapper<MemberLevelDTO, MemberLevel> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.member.profile.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_member_profile") | ||
24 | public class MemberProfile implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 会员id | ||
33 | @Column(name = "member_id", nullable = false) | ||
34 | private Long memberId; | ||
35 | |||
36 | // 姓名 | ||
37 | @Column(name = "realname") | ||
38 | private String realname; | ||
39 | |||
40 | // 性别 0:女; 1:男 -1:未知 | ||
41 | @Column(name = "gender", nullable = false) | ||
42 | private Integer gender; | ||
43 | |||
44 | // 生日 | ||
45 | @Column(name = "birthday", nullable = false) | ||
46 | private Timestamp birthday; | ||
47 | |||
48 | // 星座 | ||
49 | @Column(name = "constellation") | ||
50 | private String constellation; | ||
51 | |||
52 | // 身份证 | ||
53 | @Column(name = "id_card", nullable = false) | ||
54 | private String idCard; | ||
55 | |||
56 | // 电子邮件 | ||
57 | @Column(name = "email") | ||
58 | private String email; | ||
59 | |||
60 | // 国家 | ||
61 | @Column(name = "country") | ||
62 | private String country; | ||
63 | |||
64 | // 省份 | ||
65 | @Column(name = "province") | ||
66 | private String province; | ||
67 | |||
68 | // 城市 | ||
69 | @Column(name = "city") | ||
70 | private String city; | ||
71 | |||
72 | // 区县 | ||
73 | @Column(name = "district") | ||
74 | private String district; | ||
75 | |||
76 | // 描述 | ||
77 | @Column(name = "description") | ||
78 | private String description; | ||
79 | |||
80 | // 创建时间 | ||
81 | @CreatedDate | ||
82 | @Column(name = "create_time") | ||
83 | private Timestamp createTime; | ||
84 | |||
85 | // 更新时间 | ||
86 | @LastModifiedDate | ||
87 | @Column(name = "update_time") | ||
88 | private Timestamp updateTime; | ||
89 | |||
90 | public void copy(MemberProfile source){ | ||
91 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
92 | } | ||
93 | } |
src/main/java/com/topdraw/business/basicdata/member/profile/repository/MemberProfileRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.profile.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.profile.domain.MemberProfile; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | /** | ||
8 | * @author XiangHan | ||
9 | * @date 2021-10-22 | ||
10 | */ | ||
11 | public interface MemberProfileRepository extends JpaRepository<MemberProfile, Long>, JpaSpecificationExecutor<MemberProfile> { | ||
12 | |||
13 | } |
src/main/java/com/topdraw/business/basicdata/member/profile/rest/MemberProfileController.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.profile.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.member.profile.domain.MemberProfile; | ||
5 | import com.topdraw.business.basicdata.member.profile.service.MemberProfileService; | ||
6 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "MemberProfile管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/MemberProfile") | ||
22 | public class MemberProfileController { | ||
23 | |||
24 | @Autowired | ||
25 | private MemberProfileService MemberProfileService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询MemberProfile") | ||
29 | public ResultInfo getMemberProfiles(MemberProfileQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(MemberProfileService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有MemberProfile") | ||
35 | public ResultInfo getMemberProfiles(MemberProfileQueryCriteria criteria) { | ||
36 | return ResultInfo.success(MemberProfileService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增MemberProfile") | ||
42 | public ResultInfo create(@Validated @RequestBody MemberProfile resources) { | ||
43 | MemberProfileService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改MemberProfile") | ||
50 | public ResultInfo update(@Validated @RequestBody MemberProfile resources) { | ||
51 | MemberProfileService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除MemberProfile") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | MemberProfileService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | } |
src/main/java/com/topdraw/business/basicdata/member/profile/service/MemberProfileService.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.profile.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.profile.domain.MemberProfile; | ||
4 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO; | ||
5 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface MemberProfileService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<MemberProfileDTO> | ||
29 | */ | ||
30 | List<MemberProfileDTO> queryAll(MemberProfileQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return MemberProfileDTO | ||
36 | */ | ||
37 | MemberProfileDTO findById(Long id); | ||
38 | |||
39 | void create(MemberProfile resources); | ||
40 | |||
41 | void update(MemberProfile resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | } |
src/main/java/com/topdraw/business/basicdata/member/profile/service/dto/MemberProfileDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.profile.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class MemberProfileDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 会员id | ||
20 | private Long memberId; | ||
21 | |||
22 | // 姓名 | ||
23 | private String realname; | ||
24 | |||
25 | // 性别 0:女; 1:男 -1:未知 | ||
26 | private Integer gender; | ||
27 | |||
28 | // 生日 | ||
29 | private Timestamp birthday; | ||
30 | |||
31 | // 星座 | ||
32 | private String constellation; | ||
33 | |||
34 | // 身份证 | ||
35 | private String idCard; | ||
36 | |||
37 | // 电子邮件 | ||
38 | private String email; | ||
39 | |||
40 | // 国家 | ||
41 | private String country; | ||
42 | |||
43 | // 省份 | ||
44 | private String province; | ||
45 | |||
46 | // 城市 | ||
47 | private String city; | ||
48 | |||
49 | // 区县 | ||
50 | private String district; | ||
51 | |||
52 | // 描述 | ||
53 | private String description; | ||
54 | |||
55 | // 创建时间 | ||
56 | private Timestamp createTime; | ||
57 | |||
58 | // 更新时间 | ||
59 | private Timestamp updateTime; | ||
60 | } |
1 | package com.topdraw.business.basicdata.member.profile.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.profile.domain.MemberProfile; | ||
4 | import com.topdraw.business.basicdata.member.profile.repository.MemberProfileRepository; | ||
5 | import com.topdraw.business.basicdata.member.profile.service.MemberProfileService; | ||
6 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO; | ||
7 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.member.profile.service.mapper.MemberProfileMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.ValidationUtil; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
14 | import org.springframework.data.domain.Page; | ||
15 | import org.springframework.data.domain.Pageable; | ||
16 | import org.springframework.stereotype.Service; | ||
17 | import org.springframework.transaction.annotation.Propagation; | ||
18 | import org.springframework.transaction.annotation.Transactional; | ||
19 | import org.springframework.util.Assert; | ||
20 | |||
21 | import java.util.List; | ||
22 | import java.util.Map; | ||
23 | |||
24 | /** | ||
25 | * @author XiangHan | ||
26 | * @date 2021-10-22 | ||
27 | */ | ||
28 | @Service | ||
29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
30 | public class MemberProfileServiceImpl implements MemberProfileService { | ||
31 | |||
32 | @Autowired | ||
33 | private MemberProfileRepository MemberProfileRepository; | ||
34 | |||
35 | @Autowired | ||
36 | private MemberProfileMapper MemberProfileMapper; | ||
37 | |||
38 | @Override | ||
39 | public Map<String, Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable) { | ||
40 | Page<MemberProfile> page = MemberProfileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
41 | return PageUtil.toPage(page.map(MemberProfileMapper::toDto)); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public List<MemberProfileDTO> queryAll(MemberProfileQueryCriteria criteria) { | ||
46 | return MemberProfileMapper.toDto(MemberProfileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public MemberProfileDTO findById(Long id) { | ||
51 | MemberProfile MemberProfile = MemberProfileRepository.findById(id).orElseGet(MemberProfile::new); | ||
52 | ValidationUtil.isNull(MemberProfile.getId(),"MemberProfile","id",id); | ||
53 | return MemberProfileMapper.toDto(MemberProfile); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | @Transactional(rollbackFor = Exception.class) | ||
58 | public void create(MemberProfile resources) { | ||
59 | MemberProfileRepository.save(resources); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | @Transactional(rollbackFor = Exception.class) | ||
64 | public void update(MemberProfile resources) { | ||
65 | MemberProfile MemberProfile = MemberProfileRepository.findById(resources.getId()).orElseGet(MemberProfile::new); | ||
66 | ValidationUtil.isNull( MemberProfile.getId(),"MemberProfile","id",resources.getId()); | ||
67 | MemberProfile.copy(resources); | ||
68 | MemberProfileRepository.save(MemberProfile); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | @Transactional(rollbackFor = Exception.class) | ||
73 | public void delete(Long id) { | ||
74 | Assert.notNull(id, "The given id must not be null!"); | ||
75 | MemberProfile MemberProfile = MemberProfileRepository.findById(id).orElseThrow( | ||
76 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberProfile.class, id), 1)); | ||
77 | MemberProfileRepository.delete(MemberProfile); | ||
78 | } | ||
79 | |||
80 | |||
81 | } |
src/main/java/com/topdraw/business/basicdata/member/profile/service/mapper/MemberProfileMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.profile.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.member.profile.domain.MemberProfile; | ||
5 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface MemberProfileMapper extends BaseMapper<MemberProfileDTO, MemberProfile> { | ||
15 | |||
16 | } |
src/main/java/com/topdraw/business/basicdata/member/relatedinfo/domain/MemberRelatedInfo.java
0 → 100644
1 | package com.topdraw.business.basicdata.member.relatedinfo.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_member_related_info") | ||
24 | public class MemberRelatedInfo implements Serializable { | ||
25 | |||
26 | // ID | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 会员id | ||
33 | @Column(name = "member_id", nullable = false) | ||
34 | private Long memberId; | ||
35 | |||
36 | // 人物关系 0:子女;1:父母 | ||
37 | @Column(name = "type") | ||
38 | private Integer type; | ||
39 | |||
40 | // 手机号 | ||
41 | @Column(name = "cellphone") | ||
42 | private String cellphone; | ||
43 | |||
44 | // 身份证号 | ||
45 | @Column(name = "id_card") | ||
46 | private String idCard; | ||
47 | |||
48 | // 姓名 | ||
49 | @Column(name = "name") | ||
50 | private String name; | ||
51 | |||
52 | // 性别 0:女;1:男;-1:未知 | ||
53 | @Column(name = "sex") | ||
54 | private Integer sex; | ||
55 | |||
56 | // 创建时间 | ||
57 | @CreatedDate | ||
58 | @Column(name = "create_time") | ||
59 | private Timestamp createTime; | ||
60 | |||
61 | // 更新时间 | ||
62 | @LastModifiedDate | ||
63 | @Column(name = "update_time") | ||
64 | private Timestamp updateTime; | ||
65 | |||
66 | public void copy(MemberRelatedInfo source){ | ||
67 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
68 | } | ||
69 | } |
1 | package com.topdraw.business.basicdata.member.relatedinfo.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | /** | ||
8 | * @author XiangHan | ||
9 | * @date 2021-10-22 | ||
10 | */ | ||
11 | public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> { | ||
12 | |||
13 | } |
1 | package com.topdraw.business.basicdata.member.relatedinfo.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; | ||
5 | import com.topdraw.business.basicdata.member.relatedinfo.service.MemberRelatedInfoService; | ||
6 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan /api/MemberRelatedInfo | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "MemberRelatedInfo管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/MemberRelatedInfo") | ||
22 | public class MemberRelatedInfoController { | ||
23 | |||
24 | @Autowired | ||
25 | private MemberRelatedInfoService MemberRelatedInfoService; | ||
26 | |||
27 | @GetMapping(value = "/pageMemberRelatedInfos") | ||
28 | @ApiOperation("查询MemberRelatedInfo") | ||
29 | public ResultInfo pageMemberRelatedInfos(@Validated MemberRelatedInfoQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(MemberRelatedInfoService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @Log | ||
34 | @PostMapping(value = "/create") | ||
35 | @ApiOperation("新增MemberRelatedInfo") | ||
36 | public ResultInfo create(@Validated @RequestBody MemberRelatedInfo resources) { | ||
37 | MemberRelatedInfoService.create(resources); | ||
38 | return ResultInfo.success(); | ||
39 | } | ||
40 | |||
41 | @Log | ||
42 | @PutMapping(value = "/update") | ||
43 | @ApiOperation("修改MemberRelatedInfo") | ||
44 | public ResultInfo update(@Validated @RequestBody MemberRelatedInfo resources) { | ||
45 | MemberRelatedInfoService.update(resources); | ||
46 | return ResultInfo.success(); | ||
47 | } | ||
48 | |||
49 | @GetMapping(value = "/findById/{id}") | ||
50 | @ApiOperation("查询指定MemberRelatedInfo") | ||
51 | public ResultInfo findById(@PathVariable("id") Long id) { | ||
52 | return ResultInfo.success(MemberRelatedInfoService.findById(id)); | ||
53 | } | ||
54 | |||
55 | @Log | ||
56 | @DeleteMapping(value = "/delete//{id}") | ||
57 | @ApiOperation("删除MemberRelatedInfo") | ||
58 | public ResultInfo delete(@PathVariable Long id) { | ||
59 | MemberRelatedInfoService.delete(id); | ||
60 | return ResultInfo.success(); | ||
61 | } | ||
62 | |||
63 | } |
1 | package com.topdraw.business.basicdata.member.relatedinfo.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; | ||
4 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | ||
5 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface MemberRelatedInfoService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<MemberRelatedInfoDTO> | ||
29 | */ | ||
30 | List<MemberRelatedInfoDTO> queryAll(MemberRelatedInfoQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return MemberRelatedInfoDTO | ||
36 | */ | ||
37 | MemberRelatedInfoDTO findById(Long id); | ||
38 | |||
39 | void create(MemberRelatedInfo resources); | ||
40 | |||
41 | void update(MemberRelatedInfo resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | } |
1 | package com.topdraw.business.basicdata.member.relatedinfo.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class MemberRelatedInfoDTO implements Serializable { | ||
15 | |||
16 | // ID | ||
17 | private Long id; | ||
18 | |||
19 | // 会员id | ||
20 | private Long memberId; | ||
21 | |||
22 | // 人物关系 0:子女;1:父母 | ||
23 | private Integer type; | ||
24 | |||
25 | // 手机号 | ||
26 | private String cellphone; | ||
27 | |||
28 | // 身份证号 | ||
29 | private String idCard; | ||
30 | |||
31 | // 姓名 | ||
32 | private String name; | ||
33 | |||
34 | // 性别 0:女;1:男;-1:未知 | ||
35 | private Integer sex; | ||
36 | |||
37 | // 创建时间 | ||
38 | private Timestamp createTime; | ||
39 | |||
40 | // 更新时间 | ||
41 | private Timestamp updateTime; | ||
42 | } |
1 | package com.topdraw.business.basicdata.member.relatedinfo.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-10-22 | ||
9 | */ | ||
10 | @Data | ||
11 | public class MemberRelatedInfoQueryCriteria{ | ||
12 | |||
13 | @Query | ||
14 | private Long memberId; | ||
15 | |||
16 | |||
17 | |||
18 | } |
1 | package com.topdraw.business.basicdata.member.relatedinfo.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; | ||
4 | import com.topdraw.business.basicdata.member.relatedinfo.repository.MemberRelatedInfoRepository; | ||
5 | import com.topdraw.business.basicdata.member.relatedinfo.service.MemberRelatedInfoService; | ||
6 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | ||
7 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.member.relatedinfo.service.mapper.MemberRelatedInfoMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.ValidationUtil; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
14 | import org.springframework.data.domain.Page; | ||
15 | import org.springframework.data.domain.Pageable; | ||
16 | import org.springframework.stereotype.Service; | ||
17 | import org.springframework.transaction.annotation.Propagation; | ||
18 | import org.springframework.transaction.annotation.Transactional; | ||
19 | import org.springframework.util.Assert; | ||
20 | |||
21 | import java.util.List; | ||
22 | import java.util.Map; | ||
23 | |||
24 | /** | ||
25 | * @author XiangHan | ||
26 | * @date 2021-10-22 | ||
27 | */ | ||
28 | @Service | ||
29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
30 | public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { | ||
31 | |||
32 | @Autowired | ||
33 | private MemberRelatedInfoRepository MemberRelatedInfoRepository; | ||
34 | |||
35 | @Autowired | ||
36 | private MemberRelatedInfoMapper MemberRelatedInfoMapper; | ||
37 | |||
38 | @Override | ||
39 | public Map<String, Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable) { | ||
40 | Page<MemberRelatedInfo> page = MemberRelatedInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
41 | return PageUtil.toPage(page.map(MemberRelatedInfoMapper::toDto)); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public List<MemberRelatedInfoDTO> queryAll(MemberRelatedInfoQueryCriteria criteria) { | ||
46 | return MemberRelatedInfoMapper.toDto(MemberRelatedInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public MemberRelatedInfoDTO findById(Long id) { | ||
51 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseGet(MemberRelatedInfo::new); | ||
52 | ValidationUtil.isNull(MemberRelatedInfo.getId(),"MemberRelatedInfo","id",id); | ||
53 | return MemberRelatedInfoMapper.toDto(MemberRelatedInfo); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | @Transactional(rollbackFor = Exception.class) | ||
58 | public void create(MemberRelatedInfo resources) { | ||
59 | MemberRelatedInfoRepository.save(resources); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | @Transactional(rollbackFor = Exception.class) | ||
64 | public void update(MemberRelatedInfo resources) { | ||
65 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new); | ||
66 | ValidationUtil.isNull( MemberRelatedInfo.getId(),"MemberRelatedInfo","id",resources.getId()); | ||
67 | MemberRelatedInfo.copy(resources); | ||
68 | MemberRelatedInfoRepository.save(MemberRelatedInfo); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | @Transactional(rollbackFor = Exception.class) | ||
73 | public void delete(Long id) { | ||
74 | Assert.notNull(id, "The given id must not be null!"); | ||
75 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseThrow( | ||
76 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberRelatedInfo.class, id), 1)); | ||
77 | MemberRelatedInfoRepository.delete(MemberRelatedInfo); | ||
78 | } | ||
79 | |||
80 | |||
81 | } |
1 | package com.topdraw.business.basicdata.member.relatedinfo.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; | ||
5 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface MemberRelatedInfoMapper extends BaseMapper<MemberRelatedInfoDTO, MemberRelatedInfo> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.member.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.domain.Member; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecificationExecutor<Member> { | ||
14 | |||
15 | Optional<Member> findFirstByCode(String code); | ||
16 | } |
1 | package com.topdraw.business.basicdata.member.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.member.domain.Member; | ||
5 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
6 | import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "Member管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/member") | ||
22 | public class MemberController { | ||
23 | |||
24 | @Autowired | ||
25 | private MemberService memberService; | ||
26 | |||
27 | @GetMapping(value = "/pageMembers") | ||
28 | @ApiOperation("查询Member") | ||
29 | public ResultInfo pageMembers(MemberQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(memberService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/findById/{id}") | ||
34 | @ApiOperation("查询指定Member") | ||
35 | public ResultInfo findById(@PathVariable("id") Long id) { | ||
36 | return ResultInfo.success(memberService.findById(id)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping(value = "/create") | ||
41 | @ApiOperation("新增Member") | ||
42 | public ResultInfo create(@Validated @RequestBody Member resources) { | ||
43 | memberService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping(value = "/update") | ||
49 | @ApiOperation("修改Member") | ||
50 | public ResultInfo update(@Validated @RequestBody Member resources) { | ||
51 | memberService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | @GetMapping(value = "/getByCode/{code}") | ||
56 | @ApiOperation(value = "根据标识查询") | ||
57 | public ResultInfo getByCode(@PathVariable String code) { | ||
58 | return ResultInfo.success(memberService.getByCode(code)); | ||
59 | } | ||
60 | } |
1 | package com.topdraw.business.basicdata.member.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.domain.Member; | ||
4 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
5 | import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface MemberService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(MemberQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<MemberDTO> | ||
29 | */ | ||
30 | List<MemberDTO> queryAll(MemberQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return MemberDTO | ||
36 | */ | ||
37 | MemberDTO findById(Long id); | ||
38 | |||
39 | void create(Member resources); | ||
40 | |||
41 | void update(Member resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return MemberDTO | ||
49 | */ | ||
50 | MemberDTO getByCode(String code); | ||
51 | } |
1 | package com.topdraw.business.basicdata.member.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class MemberDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 类型 1:大屏;2:小屏 | ||
23 | private Integer type; | ||
24 | |||
25 | // 状态 0:不可用;1:可用 | ||
26 | private Integer status; | ||
27 | |||
28 | // 昵称 base64 | ||
29 | private String nickname; | ||
30 | |||
31 | // 描述 | ||
32 | private String description; | ||
33 | |||
34 | // 性别 0:女;1:男;-1:未知 | ||
35 | private Integer gender; | ||
36 | |||
37 | // 生日 | ||
38 | private String birthday; | ||
39 | |||
40 | // 头像 | ||
41 | private String avatarUrl; | ||
42 | |||
43 | // 分组信息 | ||
44 | private String groups; | ||
45 | |||
46 | // 标签 | ||
47 | private String tags; | ||
48 | |||
49 | // 是否会员 0:非会员;1:会员 | ||
50 | private Integer vip; | ||
51 | |||
52 | // 会员等级(对应level表的level字段,非id) | ||
53 | private Integer level; | ||
54 | |||
55 | // 成长值 | ||
56 | private Long exp; | ||
57 | |||
58 | // 当前积分 | ||
59 | private Long points; | ||
60 | |||
61 | // 即将到期积分(一个月内) | ||
62 | private Long duePoints; | ||
63 | |||
64 | // 优惠券数量 | ||
65 | private Integer couponAmount; | ||
66 | |||
67 | // 即将过期优惠券数量 | ||
68 | private Integer dueCouponAmount; | ||
69 | |||
70 | // iptv账号id | ||
71 | private Long userIptvId; | ||
72 | |||
73 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
74 | private Integer bindIptvPlatformType; | ||
75 | |||
76 | // iptv账号绑定时间 | ||
77 | private Timestamp bindIptvTime; | ||
78 | |||
79 | // 创建时间 | ||
80 | private Timestamp createTime; | ||
81 | |||
82 | // 更新时间 | ||
83 | private Timestamp updateTime; | ||
84 | |||
85 | // 是否在黑名单 1:是;0否 | ||
86 | // private Integer blackStatus; | ||
87 | } |
1 | package com.topdraw.business.basicdata.member.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-10-22 | ||
9 | */ | ||
10 | @Data | ||
11 | public class MemberQueryCriteria{ | ||
12 | |||
13 | @Query(type = Query.Type.LEFT_LIKE) | ||
14 | private String code; | ||
15 | |||
16 | // 类型 1:大屏;2:小屏 | ||
17 | @Query(type = Query.Type.EQUAL) | ||
18 | private Integer type; | ||
19 | |||
20 | // 状态 0:不可用;1:可用 | ||
21 | @Query(type = Query.Type.EQUAL) | ||
22 | private Integer status; | ||
23 | |||
24 | // 昵称 base64 | ||
25 | @Query(type = Query.Type.LEFT_LIKE) | ||
26 | private String nickname; | ||
27 | |||
28 | // 性别 0:女;1:男;-1:未知 | ||
29 | @Query(type = Query.Type.EQUAL) | ||
30 | private Integer gender; | ||
31 | |||
32 | // 分组信息 | ||
33 | @Query(type = Query.Type.EQUAL) | ||
34 | private String groups; | ||
35 | |||
36 | // 标签 | ||
37 | @Query(type = Query.Type.IN) | ||
38 | private String tags; | ||
39 | |||
40 | // 是否会员 0:非会员;1:会员 | ||
41 | @Query(type = Query.Type.EQUAL) | ||
42 | private Integer vip; | ||
43 | |||
44 | // 会员等级(对应level表的level字段,非id) | ||
45 | @Query(type = Query.Type.EQUAL) | ||
46 | private Integer level; | ||
47 | |||
48 | // iptv账号id | ||
49 | @Query(type = Query.Type.EQUAL) | ||
50 | private Long userIptvId; | ||
51 | |||
52 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
53 | @Query(type = Query.Type.IN) | ||
54 | private Integer bindIptvPlatformType; | ||
55 | |||
56 | } |
1 | package com.topdraw.business.basicdata.member.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.domain.Member; | ||
4 | import com.topdraw.business.basicdata.member.repository.MemberRepository; | ||
5 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
6 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
7 | import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.member.service.mapper.MemberMapper; | ||
9 | import com.topdraw.util.IdWorker; | ||
10 | import com.topdraw.utils.PageUtil; | ||
11 | import com.topdraw.utils.QueryHelp; | ||
12 | import com.topdraw.utils.StringUtils; | ||
13 | import com.topdraw.utils.ValidationUtil; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | ||
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.stereotype.Service; | ||
19 | import org.springframework.transaction.annotation.Propagation; | ||
20 | import org.springframework.transaction.annotation.Transactional; | ||
21 | import org.springframework.util.Assert; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | |||
26 | /** | ||
27 | * @author XiangHan | ||
28 | * @date 2021-10-22 | ||
29 | */ | ||
30 | @Service | ||
31 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
32 | public class MemberServiceImpl implements MemberService { | ||
33 | |||
34 | @Autowired | ||
35 | private MemberRepository memberRepository; | ||
36 | |||
37 | @Autowired | ||
38 | private MemberMapper memberMapper; | ||
39 | |||
40 | @Override | ||
41 | public Map<String, Object> queryAll(MemberQueryCriteria criteria, Pageable pageable) { | ||
42 | Page<Member> page = memberRepository.findAll((root, criteriaQuery, criteriaBuilder) | ||
43 | -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
44 | return PageUtil.toPage(page.map(memberMapper::toDto)); | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public List<MemberDTO> queryAll(MemberQueryCriteria criteria) { | ||
49 | return memberMapper.toDto(memberRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | public MemberDTO findById(Long id) { | ||
54 | Member member = memberRepository.findById(id).orElseGet(Member::new); | ||
55 | ValidationUtil.isNull(member.getId(),"Member","id",id); | ||
56 | return memberMapper.toDto(member); | ||
57 | } | ||
58 | |||
59 | @Override | ||
60 | @Transactional(rollbackFor = Exception.class) | ||
61 | public void create(Member resources) { | ||
62 | Member member = this.checkMemberData(resources); | ||
63 | memberRepository.save(member); | ||
64 | } | ||
65 | |||
66 | private Member checkMemberData(Member member) { | ||
67 | member.setCode(String.valueOf(IdWorker.generator())); | ||
68 | member.setGender(0); | ||
69 | member.setType(-1); | ||
70 | member.setStatus(1); | ||
71 | member.setVip(0); | ||
72 | member.setLevel(0); | ||
73 | member.setExp(0L); | ||
74 | member.setPoints(0); | ||
75 | member.setDuePoints(0L); | ||
76 | member.setCouponAmount(0); | ||
77 | member.setDueCouponAmount(0); | ||
78 | return member; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | @Transactional(rollbackFor = Exception.class) | ||
83 | public void update(Member resources) { | ||
84 | Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); | ||
85 | ValidationUtil.isNull( member.getId(),"Member","id",resources.getId()); | ||
86 | member.copy(resources); | ||
87 | memberRepository.save(member); | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | @Transactional(rollbackFor = Exception.class) | ||
92 | public void delete(Long id) { | ||
93 | Assert.notNull(id, "The given id must not be null!"); | ||
94 | Member member = memberRepository.findById(id).orElseThrow( | ||
95 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Member.class, id), 1)); | ||
96 | memberRepository.delete(member); | ||
97 | } | ||
98 | |||
99 | |||
100 | @Override | ||
101 | public MemberDTO getByCode(String code) { | ||
102 | return StringUtils.isNotEmpty(code) ? memberMapper.toDto(memberRepository.findFirstByCode(code).orElseGet(Member::new)) | ||
103 | : new MemberDTO(); | ||
104 | } | ||
105 | } |
1 | package com.topdraw.business.basicdata.member.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.member.domain.Member; | ||
5 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface MemberMapper extends BaseMapper<MemberDTO, Member> { | ||
15 | |||
16 | } |
src/main/java/com/topdraw/business/basicdata/points/available/domain/PointsAvailable.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.available.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import com.fasterxml.jackson.annotation.JsonFormat; | ||
6 | import lombok.Data; | ||
7 | import lombok.experimental.Accessors; | ||
8 | import org.springframework.data.annotation.CreatedDate; | ||
9 | import org.springframework.data.annotation.LastModifiedDate; | ||
10 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
11 | |||
12 | import javax.persistence.*; | ||
13 | import java.io.Serializable; | ||
14 | import java.sql.Timestamp; | ||
15 | |||
16 | /** | ||
17 | * @author XiangHan | ||
18 | * @date 2021-10-23 | ||
19 | */ | ||
20 | @Entity | ||
21 | @Data | ||
22 | @EntityListeners(AuditingEntityListener.class) | ||
23 | @Accessors(chain = true) | ||
24 | @Table(name="uc_points_available") | ||
25 | public class PointsAvailable implements Serializable { | ||
26 | |||
27 | // 主键 | ||
28 | @Id | ||
29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
30 | @Column(name = "id") | ||
31 | private Long id; | ||
32 | |||
33 | // 标识 | ||
34 | @Column(name = "code") | ||
35 | private String code; | ||
36 | |||
37 | // 积分类型 0:通用型 | ||
38 | @Column(name = "points_type") | ||
39 | private Integer pointsType; | ||
40 | |||
41 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
42 | @Column(name = "device_type") | ||
43 | private Integer deviceType; | ||
44 | |||
45 | // 会员id | ||
46 | @Column(name = "member_id", nullable = false) | ||
47 | private Long memberId; | ||
48 | |||
49 | // 积分值 | ||
50 | @Column(name = "points") | ||
51 | private Long points; | ||
52 | |||
53 | // 过期时间 | ||
54 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
55 | @Column(name = "expire_time") | ||
56 | private Timestamp expireTime; | ||
57 | |||
58 | // 描述 | ||
59 | @Column(name = "description") | ||
60 | private String description; | ||
61 | |||
62 | // 创建时间 | ||
63 | @CreatedDate | ||
64 | @Column(name = "create_time") | ||
65 | private Timestamp createTime; | ||
66 | |||
67 | // 更新时间 | ||
68 | @LastModifiedDate | ||
69 | @Column(name = "update_time") | ||
70 | private Timestamp updateTime; | ||
71 | |||
72 | public void copy(PointsAvailable source){ | ||
73 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
74 | } | ||
75 | } |
1 | package com.topdraw.business.basicdata.points.available.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; | ||
4 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; | ||
5 | import org.springframework.data.jpa.repository.JpaRepository; | ||
6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
7 | |||
8 | import java.util.Date; | ||
9 | import java.util.List; | ||
10 | import java.util.Optional; | ||
11 | |||
12 | /** | ||
13 | * @author XiangHan | ||
14 | * @date 2021-10-23 | ||
15 | */ | ||
16 | public interface PointsAvailableRepository extends JpaRepository<PointsAvailable, Long>, JpaSpecificationExecutor<PointsAvailable> { | ||
17 | |||
18 | Optional<PointsAvailable> findFirstByCode(String code); | ||
19 | |||
20 | List<PointsAvailableDTO> findByMemberId(Long memberId); | ||
21 | |||
22 | List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId , Date now); | ||
23 | } |
src/main/java/com/topdraw/business/basicdata/points/available/rest/PointsAvailableController.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.available.rest; | ||
2 | |||
3 | /** | ||
4 | * @author XiangHan | ||
5 | * @date 2021-10-23 | ||
6 | */ | ||
7 | //@Api(tags = "PointsAvailable管理") | ||
8 | //@RestController | ||
9 | //@RequestMapping("/api/PointsAvailable") | ||
10 | public class PointsAvailableController { | ||
11 | |||
12 | /*@Autowired | ||
13 | private PointsAvailableService PointsAvailableService; | ||
14 | |||
15 | @GetMapping | ||
16 | @ApiOperation("查询PointsAvailable") | ||
17 | public ResultInfo getPointsAvailables(PointsAvailableQueryCriteria criteria, Pageable pageable) { | ||
18 | return ResultInfo.successPage(PointsAvailableService.queryAll(criteria,pageable)); | ||
19 | } | ||
20 | |||
21 | @GetMapping(value = "/all") | ||
22 | @ApiOperation("查询所有PointsAvailable") | ||
23 | public ResultInfo getPointsAvailables(PointsAvailableQueryCriteria criteria) { | ||
24 | return ResultInfo.success(PointsAvailableService.queryAll(criteria)); | ||
25 | } | ||
26 | |||
27 | @Log | ||
28 | @PostMapping | ||
29 | @ApiOperation("新增PointsAvailable") | ||
30 | public ResultInfo create(@Validated @RequestBody PointsAvailable resources) { | ||
31 | PointsAvailableService.create(resources); | ||
32 | return ResultInfo.success(); | ||
33 | } | ||
34 | |||
35 | @Log | ||
36 | @PutMapping | ||
37 | @ApiOperation("修改PointsAvailable") | ||
38 | public ResultInfo update(@Validated @RequestBody PointsAvailable resources) { | ||
39 | PointsAvailableService.update(resources); | ||
40 | return ResultInfo.success(); | ||
41 | } | ||
42 | |||
43 | |||
44 | @Log | ||
45 | @DeleteMapping(value = "/{id}") | ||
46 | @ApiOperation("删除PointsAvailable") | ||
47 | public ResultInfo delete(@PathVariable Long id) { | ||
48 | PointsAvailableService.delete(id); | ||
49 | return ResultInfo.success(); | ||
50 | } | ||
51 | |||
52 | @GetMapping(value = "/getByCode/{code}") | ||
53 | @ApiOperation(value = "根据标识查询") | ||
54 | public ResultInfo getByCode(@PathVariable String code) { | ||
55 | return ResultInfo.success(PointsAvailableService.getByCode(code)); | ||
56 | }*/ | ||
57 | } |
src/main/java/com/topdraw/business/basicdata/points/available/service/PointsAvailableService.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.available.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; | ||
4 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; | ||
5 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.Date; | ||
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | |||
12 | /** | ||
13 | * @author XiangHan | ||
14 | * @date 2021-10-23 | ||
15 | */ | ||
16 | public interface PointsAvailableService { | ||
17 | |||
18 | /** | ||
19 | * 查询数据分页 | ||
20 | * @param criteria 条件参数 | ||
21 | * @param pageable 分页参数 | ||
22 | * @return Map<String,Object> | ||
23 | */ | ||
24 | Map<String,Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable); | ||
25 | |||
26 | /** | ||
27 | * 查询所有数据不分页 | ||
28 | * @param criteria 条件参数 | ||
29 | * @return List<PointsAvailableDTO> | ||
30 | */ | ||
31 | List<PointsAvailableDTO> queryAll(PointsAvailableQueryCriteria criteria); | ||
32 | |||
33 | /** | ||
34 | * 根据ID查询 | ||
35 | * @param id ID | ||
36 | * @return PointsAvailableDTO | ||
37 | */ | ||
38 | PointsAvailableDTO findById(Long id); | ||
39 | |||
40 | /** | ||
41 | * | ||
42 | * @param resources | ||
43 | */ | ||
44 | void create(PointsAvailable resources); | ||
45 | |||
46 | /** | ||
47 | * | ||
48 | * @param resources | ||
49 | */ | ||
50 | void update(PointsAvailable resources); | ||
51 | |||
52 | /** | ||
53 | * | ||
54 | * @param id | ||
55 | */ | ||
56 | void delete(Long id); | ||
57 | |||
58 | /** | ||
59 | * Code校验 | ||
60 | * @param code | ||
61 | * @return PointsAvailableDTO | ||
62 | */ | ||
63 | PointsAvailableDTO getByCode(String code); | ||
64 | |||
65 | /** | ||
66 | * | ||
67 | * @param memberId | ||
68 | * @param timestamp | ||
69 | * @return | ||
70 | */ | ||
71 | List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp); | ||
72 | |||
73 | /** | ||
74 | * 查询数据分页 | ||
75 | * @param criteria 条件参数 | ||
76 | * @param pageable 分页参数 | ||
77 | * @return Map<String,Object> | ||
78 | */ | ||
79 | Map<String,Object> findByMemberIdAndExpireTimeBefore(PointsAvailableQueryCriteria criteria, Pageable pageable); | ||
80 | } |
src/main/java/com/topdraw/business/basicdata/points/available/service/dto/PointsAvailableDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.available.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-23 | ||
12 | */ | ||
13 | @Data | ||
14 | public class PointsAvailableDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 积分类型 0:通用型 | ||
23 | private Integer pointsType; | ||
24 | |||
25 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
26 | private Integer deviceType; | ||
27 | |||
28 | // 会员id | ||
29 | private Long memberId; | ||
30 | |||
31 | // 积分值 | ||
32 | private Long points; | ||
33 | |||
34 | // 过期时间 | ||
35 | private Timestamp expireTime; | ||
36 | |||
37 | // 描述 | ||
38 | private String description; | ||
39 | |||
40 | // 创建时间 | ||
41 | private Timestamp createTime; | ||
42 | |||
43 | // 更新时间 | ||
44 | private Timestamp updateTime; | ||
45 | } |
1 | package com.topdraw.business.basicdata.points.available.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2021-10-23 | ||
11 | */ | ||
12 | @Data | ||
13 | public class PointsAvailableQueryCriteria{ | ||
14 | |||
15 | @Query | ||
16 | private Long memberId; | ||
17 | |||
18 | @Query | ||
19 | private Long accountId; | ||
20 | |||
21 | @Query(type = Query.Type.GREATER_THAN) | ||
22 | private Timestamp expireTime; | ||
23 | |||
24 | private PointsAvailableQueryType queryType; | ||
25 | |||
26 | } |
1 | package com.topdraw.business.basicdata.points.available.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; | ||
4 | import com.topdraw.business.basicdata.points.available.repository.PointsAvailableRepository; | ||
5 | import com.topdraw.business.basicdata.points.available.service.PointsAvailableService; | ||
6 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; | ||
7 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.points.available.service.mapper.PointsAvailableMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.Date; | ||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.util.Objects; | ||
26 | |||
27 | /** | ||
28 | * @author XiangHan | ||
29 | * @date 2021-10-23 | ||
30 | */ | ||
31 | @Service | ||
32 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
33 | public class PointsAvailableServiceImpl implements PointsAvailableService { | ||
34 | |||
35 | @Autowired | ||
36 | private PointsAvailableRepository PointsAvailableRepository; | ||
37 | |||
38 | @Autowired | ||
39 | private PointsAvailableMapper PointsAvailableMapper; | ||
40 | |||
41 | @Override | ||
42 | public Map<String, Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable) { | ||
43 | Page<PointsAvailable> page = PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> | ||
44 | QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
45 | return PageUtil.toPage(page.map(PointsAvailableMapper::toDto)); | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | public Map<String, Object> findByMemberIdAndExpireTimeBefore(PointsAvailableQueryCriteria criteria, Pageable pageable) { | ||
50 | return this.queryAll(criteria,pageable); | ||
51 | } | ||
52 | |||
53 | @Override | ||
54 | public List<PointsAvailableDTO> queryAll(PointsAvailableQueryCriteria criteria) { | ||
55 | return PointsAvailableMapper.toDto(PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | public PointsAvailableDTO findById(Long id) { | ||
60 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseGet(PointsAvailable::new); | ||
61 | ValidationUtil.isNull(PointsAvailable.getId(),"PointsAvailable","id",id); | ||
62 | return PointsAvailableMapper.toDto(PointsAvailable); | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | @Transactional(rollbackFor = Exception.class) | ||
67 | public void create(PointsAvailable resources) { | ||
68 | PointsAvailableRepository.save(resources); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | @Transactional(rollbackFor = Exception.class) | ||
73 | public void update(PointsAvailable resources) { | ||
74 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new); | ||
75 | ValidationUtil.isNull( PointsAvailable.getId(),"PointsAvailable","id",resources.getId()); | ||
76 | PointsAvailable.copy(resources); | ||
77 | PointsAvailableRepository.save(PointsAvailable); | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | @Transactional(rollbackFor = Exception.class) | ||
82 | public void delete(Long id) { | ||
83 | Assert.notNull(id, "The given id must not be null!"); | ||
84 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow( | ||
85 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1)); | ||
86 | PointsAvailableRepository.delete(PointsAvailable); | ||
87 | } | ||
88 | |||
89 | |||
90 | @Override | ||
91 | public PointsAvailableDTO getByCode(String code) { | ||
92 | return StringUtils.isNotEmpty(code) ? PointsAvailableMapper.toDto(PointsAvailableRepository.findFirstByCode(code).orElseGet(PointsAvailable::new)) | ||
93 | : new PointsAvailableDTO(); | ||
94 | } | ||
95 | |||
96 | @Override | ||
97 | public List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp) { | ||
98 | return Objects.nonNull(memberId)? | ||
99 | PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp)) | ||
100 | :null; | ||
101 | } | ||
102 | |||
103 | |||
104 | } |
1 | package com.topdraw.business.basicdata.points.available.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; | ||
5 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-23 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PointsAvailableMapper extends BaseMapper<PointsAvailableDTO, PointsAvailable> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.points.detail.detailhistory.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_points_detail_history") | ||
24 | public class PointsDetailHistory implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 应用code | ||
37 | @Column(name = "app_code") | ||
38 | private String appCode; | ||
39 | |||
40 | // 会员id | ||
41 | @Column(name = "member_id", nullable = false) | ||
42 | private Long memberId; | ||
43 | |||
44 | // 账号id | ||
45 | @Column(name = "account_id") | ||
46 | private Long accountId; | ||
47 | |||
48 | // 原始积分 | ||
49 | @Column(name = "original_points", nullable = false) | ||
50 | private Long originalPoints; | ||
51 | |||
52 | // 结果积分 | ||
53 | @Column(name = "result_points", nullable = false) | ||
54 | private Long resultPoints; | ||
55 | |||
56 | // 积分变化,积分获得为正,积分消耗为负 | ||
57 | @Column(name = "points", nullable = false) | ||
58 | private Long points; | ||
59 | |||
60 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
61 | @Column(name = "device_type", nullable = false) | ||
62 | private Integer deviceType; | ||
63 | |||
64 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他 | ||
65 | @Column(name = "evt_type", nullable = false) | ||
66 | private Integer evtType; | ||
67 | |||
68 | // 订单id(针对订购操作) | ||
69 | @Column(name = "order_id") | ||
70 | private Long orderId; | ||
71 | |||
72 | // 节目id(针对观影操作) | ||
73 | @Column(name = "media_id") | ||
74 | private Long mediaId; | ||
75 | |||
76 | // 活动id(针对参与活动) | ||
77 | @Column(name = "activity_id") | ||
78 | private Long activityId; | ||
79 | |||
80 | // 积分变化描述,用于管理侧显示 | ||
81 | @Column(name = "description", nullable = false) | ||
82 | private String description; | ||
83 | |||
84 | // 创建时间 | ||
85 | @CreatedDate | ||
86 | @Column(name = "create_time") | ||
87 | private Timestamp createTime; | ||
88 | |||
89 | // 更新时间 | ||
90 | @LastModifiedDate | ||
91 | @Column(name = "update_time") | ||
92 | private Timestamp updateTime; | ||
93 | |||
94 | public void copy(PointsDetailHistory source){ | ||
95 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
96 | } | ||
97 | } |
1 | package com.topdraw.business.basicdata.points.detail.detailhistory.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface PointsDetailHistoryRepository extends JpaRepository<PointsDetailHistory, Long>, JpaSpecificationExecutor<PointsDetailHistory> { | ||
14 | |||
15 | Optional<PointsDetailHistory> findFirstByCode(String code); | ||
16 | } |
1 | package com.topdraw.business.basicdata.points.detail.detailhistory.rest; | ||
2 | |||
3 | import io.swagger.annotations.Api; | ||
4 | |||
5 | /** | ||
6 | * @author XiangHan | ||
7 | * @date 2021-10-22 | ||
8 | */ | ||
9 | @Api(tags = "PointsDetailHistory管理") | ||
10 | //@RestController | ||
11 | //@RequestMapping("/api/PointsDetailHistory") | ||
12 | public class PointsDetailHistoryController { | ||
13 | |||
14 | /*@Autowired | ||
15 | private PointsDetailHistoryService PointsDetailHistoryService; | ||
16 | |||
17 | @GetMapping | ||
18 | @ApiOperation("查询PointsDetailHistory") | ||
19 | public ResultInfo getPointsDetailHistorys(PointsDetailHistoryQueryCriteria criteria, Pageable pageable) { | ||
20 | return ResultInfo.successPage(PointsDetailHistoryService.queryAll(criteria,pageable)); | ||
21 | } | ||
22 | |||
23 | @GetMapping(value = "/all") | ||
24 | @ApiOperation("查询所有PointsDetailHistory") | ||
25 | public ResultInfo getPointsDetailHistorys(PointsDetailHistoryQueryCriteria criteria) { | ||
26 | return ResultInfo.success(PointsDetailHistoryService.queryAll(criteria)); | ||
27 | } | ||
28 | |||
29 | @Log | ||
30 | @PostMapping | ||
31 | @ApiOperation("新增PointsDetailHistory") | ||
32 | public ResultInfo create(@Validated @RequestBody PointsDetailHistory resources) { | ||
33 | PointsDetailHistoryService.create(resources); | ||
34 | return ResultInfo.success(); | ||
35 | } | ||
36 | |||
37 | @Log | ||
38 | @PutMapping | ||
39 | @ApiOperation("修改PointsDetailHistory") | ||
40 | public ResultInfo update(@Validated @RequestBody PointsDetailHistory resources) { | ||
41 | PointsDetailHistoryService.update(resources); | ||
42 | return ResultInfo.success(); | ||
43 | } | ||
44 | |||
45 | |||
46 | @Log | ||
47 | @DeleteMapping(value = "/{id}") | ||
48 | @ApiOperation("删除PointsDetailHistory") | ||
49 | public ResultInfo delete(@PathVariable Long id) { | ||
50 | PointsDetailHistoryService.delete(id); | ||
51 | return ResultInfo.success(); | ||
52 | } | ||
53 | |||
54 | @GetMapping(value = "/getByCode/{code}") | ||
55 | @ApiOperation(value = "根据标识查询") | ||
56 | public ResultInfo getByCode(@PathVariable String code) { | ||
57 | return ResultInfo.success(PointsDetailHistoryService.getByCode(code)); | ||
58 | }*/ | ||
59 | } |
1 | package com.topdraw.business.basicdata.points.detail.detailhistory.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory; | ||
4 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO; | ||
5 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface PointsDetailHistoryService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(PointsDetailHistoryQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<PointsDetailHistoryDTO> | ||
29 | */ | ||
30 | List<PointsDetailHistoryDTO> queryAll(PointsDetailHistoryQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return PointsDetailHistoryDTO | ||
36 | */ | ||
37 | PointsDetailHistoryDTO findById(Long id); | ||
38 | |||
39 | void create(PointsDetailHistory resources); | ||
40 | |||
41 | void update(PointsDetailHistory resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return PointsDetailHistoryDTO | ||
49 | */ | ||
50 | PointsDetailHistoryDTO getByCode(String code); | ||
51 | } |
1 | package com.topdraw.business.basicdata.points.detail.detailhistory.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class PointsDetailHistoryDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 应用code | ||
23 | private String appCode; | ||
24 | |||
25 | // 会员id | ||
26 | private Long memberId; | ||
27 | |||
28 | // 账号id | ||
29 | private Long accountId; | ||
30 | |||
31 | // 原始积分 | ||
32 | private Long originalPoints; | ||
33 | |||
34 | // 结果积分 | ||
35 | private Long resultPoints; | ||
36 | |||
37 | // 积分变化,积分获得为正,积分消耗为负 | ||
38 | private Long points; | ||
39 | |||
40 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
41 | private Integer deviceType; | ||
42 | |||
43 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他 | ||
44 | private Integer evtType; | ||
45 | |||
46 | // 订单id(针对订购操作) | ||
47 | private Long orderId; | ||
48 | |||
49 | // 节目id(针对观影操作) | ||
50 | private Long mediaId; | ||
51 | |||
52 | // 活动id(针对参与活动) | ||
53 | private Long activityId; | ||
54 | |||
55 | // 积分变化描述,用于管理侧显示 | ||
56 | private String description; | ||
57 | |||
58 | // 创建时间 | ||
59 | private Timestamp createTime; | ||
60 | |||
61 | // 更新时间 | ||
62 | private Timestamp updateTime; | ||
63 | } |
1 | package com.topdraw.business.basicdata.points.detail.detailhistory.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory; | ||
4 | import com.topdraw.business.basicdata.points.detail.detailhistory.repository.PointsDetailHistoryRepository; | ||
5 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.PointsDetailHistoryService; | ||
6 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO; | ||
7 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.mapper.PointsDetailHistoryMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryService { | ||
32 | |||
33 | @Autowired | ||
34 | private PointsDetailHistoryRepository PointsDetailHistoryRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private PointsDetailHistoryMapper PointsDetailHistoryMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(PointsDetailHistoryQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<PointsDetailHistory> page = PointsDetailHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(PointsDetailHistoryMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<PointsDetailHistoryDTO> queryAll(PointsDetailHistoryQueryCriteria criteria) { | ||
47 | return PointsDetailHistoryMapper.toDto(PointsDetailHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public PointsDetailHistoryDTO findById(Long id) { | ||
52 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseGet(PointsDetailHistory::new); | ||
53 | ValidationUtil.isNull(PointsDetailHistory.getId(),"PointsDetailHistory","id",id); | ||
54 | return PointsDetailHistoryMapper.toDto(PointsDetailHistory); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(PointsDetailHistory resources) { | ||
60 | PointsDetailHistoryRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(PointsDetailHistory resources) { | ||
66 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(resources.getId()).orElseGet(PointsDetailHistory::new); | ||
67 | ValidationUtil.isNull( PointsDetailHistory.getId(),"PointsDetailHistory","id",resources.getId()); | ||
68 | PointsDetailHistory.copy(resources); | ||
69 | PointsDetailHistoryRepository.save(PointsDetailHistory); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetailHistory.class, id), 1)); | ||
78 | PointsDetailHistoryRepository.delete(PointsDetailHistory); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public PointsDetailHistoryDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? PointsDetailHistoryMapper.toDto(PointsDetailHistoryRepository.findFirstByCode(code).orElseGet(PointsDetailHistory::new)) | ||
85 | : new PointsDetailHistoryDTO(); | ||
86 | } | ||
87 | } |
1 | package com.topdraw.business.basicdata.points.detail.detailhistory.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory; | ||
5 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PointsDetailHistoryMapper extends BaseMapper<PointsDetailHistoryDTO, PointsDetailHistory> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.points.detail.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_points_detail") | ||
24 | public class PointsDetail implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 应用code | ||
37 | @Column(name = "app_code") | ||
38 | private String appCode; | ||
39 | |||
40 | // 会员id | ||
41 | @Column(name = "member_id", nullable = false) | ||
42 | private Long memberId; | ||
43 | |||
44 | // 账号id | ||
45 | @Column(name = "account_id") | ||
46 | private Long accountId; | ||
47 | |||
48 | // 原始积分 | ||
49 | @Column(name = "original_points", nullable = false) | ||
50 | private Long originalPoints; | ||
51 | |||
52 | // 结果积分 | ||
53 | @Column(name = "result_points", nullable = false) | ||
54 | private Long resultPoints; | ||
55 | |||
56 | // 积分变化,积分获得为正,积分消耗为负 | ||
57 | @Column(name = "points", nullable = false) | ||
58 | private Long points; | ||
59 | |||
60 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
61 | @Column(name = "device_type", nullable = false) | ||
62 | private Integer deviceType; | ||
63 | |||
64 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他 | ||
65 | @Column(name = "evt_type", nullable = false) | ||
66 | private Integer evtType; | ||
67 | |||
68 | // 订单id(针对订购操作) | ||
69 | @Column(name = "order_id") | ||
70 | private Long orderId; | ||
71 | |||
72 | // 节目id(针对观影操作) | ||
73 | @Column(name = "media_id") | ||
74 | private Long mediaId; | ||
75 | |||
76 | // 活动id(针对参与活动) | ||
77 | @Column(name = "activity_id") | ||
78 | private Long activityId; | ||
79 | |||
80 | // 积分变化描述,用于管理侧显示 | ||
81 | @Column(name = "description", nullable = false) | ||
82 | private String description; | ||
83 | |||
84 | // 创建时间 | ||
85 | @CreatedDate | ||
86 | @Column(name = "create_time") | ||
87 | private Timestamp createTime; | ||
88 | |||
89 | // 更新时间 | ||
90 | @LastModifiedDate | ||
91 | @Column(name = "update_time") | ||
92 | private Timestamp updateTime; | ||
93 | |||
94 | public void copy(PointsDetail source){ | ||
95 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
96 | } | ||
97 | } |
src/main/java/com/topdraw/business/basicdata/points/detail/repository/PointsDetailRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.detail.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long>, JpaSpecificationExecutor<PointsDetail> { | ||
14 | |||
15 | Optional<PointsDetail> findFirstByCode(String code); | ||
16 | } |
src/main/java/com/topdraw/business/basicdata/points/detail/rest/PointsDetailController.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.detail.rest; | ||
2 | |||
3 | import io.swagger.annotations.Api; | ||
4 | |||
5 | /** | ||
6 | * @author XiangHan | ||
7 | * @date 2021-10-22 | ||
8 | */ | ||
9 | @Api(tags = "PointsDetail管理") | ||
10 | //@RestController | ||
11 | //@RequestMapping("/api/PointsDetail") | ||
12 | public class PointsDetailController { | ||
13 | |||
14 | /*@Autowired | ||
15 | private PointsDetailService PointsDetailService; | ||
16 | |||
17 | @GetMapping | ||
18 | @ApiOperation("查询PointsDetail") | ||
19 | public ResultInfo getPointsDetails(PointsDetailQueryCriteria criteria, Pageable pageable) { | ||
20 | return ResultInfo.successPage(PointsDetailService.queryAll(criteria,pageable)); | ||
21 | } | ||
22 | |||
23 | @GetMapping(value = "/all") | ||
24 | @ApiOperation("查询所有PointsDetail") | ||
25 | public ResultInfo getPointsDetails(PointsDetailQueryCriteria criteria) { | ||
26 | return ResultInfo.success(PointsDetailService.queryAll(criteria)); | ||
27 | } | ||
28 | |||
29 | @Log | ||
30 | @PostMapping | ||
31 | @ApiOperation("新增PointsDetail") | ||
32 | public ResultInfo create(@Validated @RequestBody PointsDetail resources) { | ||
33 | PointsDetailService.create(resources); | ||
34 | return ResultInfo.success(); | ||
35 | } | ||
36 | |||
37 | @Log | ||
38 | @PutMapping | ||
39 | @ApiOperation("修改PointsDetail") | ||
40 | public ResultInfo update(@Validated @RequestBody PointsDetail resources) { | ||
41 | PointsDetailService.update(resources); | ||
42 | return ResultInfo.success(); | ||
43 | } | ||
44 | |||
45 | @Log | ||
46 | @DeleteMapping(value = "/{id}") | ||
47 | @ApiOperation("删除PointsDetail") | ||
48 | public ResultInfo delete(@PathVariable Long id) { | ||
49 | PointsDetailService.delete(id); | ||
50 | return ResultInfo.success(); | ||
51 | } | ||
52 | |||
53 | @GetMapping(value = "/getByCode/{code}") | ||
54 | @ApiOperation(value = "根据标识查询") | ||
55 | public ResultInfo getByCode(@PathVariable String code) { | ||
56 | return ResultInfo.success(PointsDetailService.getByCode(code)); | ||
57 | }*/ | ||
58 | } |
src/main/java/com/topdraw/business/basicdata/points/detail/service/PointsDetailService.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.detail.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; | ||
4 | import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailDTO; | ||
5 | import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface PointsDetailService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<PointsDetailDTO> | ||
29 | */ | ||
30 | List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return PointsDetailDTO | ||
36 | */ | ||
37 | PointsDetailDTO findById(Long id); | ||
38 | |||
39 | void create(PointsDetail resources); | ||
40 | |||
41 | void update(PointsDetail resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return PointsDetailDTO | ||
49 | */ | ||
50 | PointsDetailDTO getByCode(String code); | ||
51 | |||
52 | List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId); | ||
53 | } |
src/main/java/com/topdraw/business/basicdata/points/detail/service/dto/PointsDetailDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.detail.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class PointsDetailDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 应用code | ||
23 | private String appCode; | ||
24 | |||
25 | // 会员id | ||
26 | private Long memberId; | ||
27 | |||
28 | // 账号id | ||
29 | private Long accountId; | ||
30 | |||
31 | // 原始积分 | ||
32 | private Long originalPoints; | ||
33 | |||
34 | // 结果积分 | ||
35 | private Long resultPoints; | ||
36 | |||
37 | // 积分变化,积分获得为正,积分消耗为负 | ||
38 | private Long points; | ||
39 | |||
40 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
41 | private Integer deviceType; | ||
42 | |||
43 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他 | ||
44 | private Integer evtType; | ||
45 | |||
46 | // 订单id(针对订购操作) | ||
47 | private Long orderId; | ||
48 | |||
49 | // 节目id(针对观影操作) | ||
50 | private Long mediaId; | ||
51 | |||
52 | // 活动id(针对参与活动) | ||
53 | private Long activityId; | ||
54 | |||
55 | // 积分变化描述,用于管理侧显示 | ||
56 | private String description; | ||
57 | |||
58 | // 创建时间 | ||
59 | private Timestamp createTime; | ||
60 | |||
61 | // 更新时间 | ||
62 | private Timestamp updateTime; | ||
63 | } |
1 | package com.topdraw.business.basicdata.points.detail.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-10-22 | ||
9 | */ | ||
10 | @Data | ||
11 | public class PointsDetailQueryCriteria{ | ||
12 | |||
13 | @Query(type = Query.Type.EQUAL) | ||
14 | private Long memberId; | ||
15 | |||
16 | @Query(type = Query.Type.EQUAL) | ||
17 | private Long accountId; | ||
18 | |||
19 | } |
src/main/java/com/topdraw/business/basicdata/points/detail/service/impl/PointsDetailServiceImpl.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.detail.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; | ||
4 | import com.topdraw.business.basicdata.points.detail.repository.PointsDetailRepository; | ||
5 | import com.topdraw.business.basicdata.points.detail.service.PointsDetailService; | ||
6 | import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailDTO; | ||
7 | import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.points.detail.service.mapper.PointsDetailMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class PointsDetailServiceImpl implements PointsDetailService { | ||
32 | |||
33 | @Autowired | ||
34 | private PointsDetailRepository PointsDetailRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private PointsDetailMapper PointsDetailMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<PointsDetail> page = PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(PointsDetailMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria) { | ||
47 | return PointsDetailMapper.toDto(PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public PointsDetailDTO findById(Long id) { | ||
52 | PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseGet(PointsDetail::new); | ||
53 | ValidationUtil.isNull(PointsDetail.getId(),"PointsDetail","id",id); | ||
54 | return PointsDetailMapper.toDto(PointsDetail); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(PointsDetail resources) { | ||
60 | PointsDetailRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(PointsDetail resources) { | ||
66 | PointsDetail PointsDetail = PointsDetailRepository.findById(resources.getId()).orElseGet(PointsDetail::new); | ||
67 | ValidationUtil.isNull( PointsDetail.getId(),"PointsDetail","id",resources.getId()); | ||
68 | PointsDetail.copy(resources); | ||
69 | PointsDetailRepository.save(PointsDetail); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetail.class, id), 1)); | ||
78 | PointsDetailRepository.delete(PointsDetail); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public PointsDetailDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? PointsDetailMapper.toDto(PointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new)) | ||
85 | : new PointsDetailDTO(); | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId) { | ||
90 | return null; | ||
91 | } | ||
92 | } |
src/main/java/com/topdraw/business/basicdata/points/detail/service/mapper/PointsDetailMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.points.detail.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; | ||
5 | import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PointsDetailMapper extends BaseMapper<PointsDetailDTO, PointsDetail> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.points.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_points") | ||
24 | public class Points implements Serializable { | ||
25 | |||
26 | @Id | ||
27 | @Column(name = "id") | ||
28 | private Long id; | ||
29 | |||
30 | @Column(name = "user_id") | ||
31 | private Long userId; | ||
32 | |||
33 | // 积分类型,通用,绑定, 区分大小屏 todo | ||
34 | @Column(name = "point_type") | ||
35 | private Integer pointType; | ||
36 | |||
37 | // 绑定对应的实体, 如何描述? | ||
38 | @Column(name = "target_no") | ||
39 | private String targetNo; | ||
40 | |||
41 | // 本月期初积分值 | ||
42 | @Column(name = "begin_points") | ||
43 | private Integer beginPoints; | ||
44 | |||
45 | // 当前积分余额 | ||
46 | @Column(name = "current_points") | ||
47 | private Integer currentPoints; | ||
48 | |||
49 | // 本月到期积分 | ||
50 | @Column(name = "expire_points") | ||
51 | private Integer expirePoints; | ||
52 | |||
53 | // 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途) | ||
54 | @CreatedDate | ||
55 | @Column(name = "create_time") | ||
56 | private Timestamp createTime; | ||
57 | |||
58 | // 最后修改时间 | ||
59 | @LastModifiedDate | ||
60 | @Column(name = "update_time") | ||
61 | private Timestamp updateTime; | ||
62 | |||
63 | public void copy(Points source){ | ||
64 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
65 | } | ||
66 | } |
1 | package com.topdraw.business.basicdata.points.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.domain.Points; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | /** | ||
8 | * @author XiangHan | ||
9 | * @date 2021-10-22 | ||
10 | */ | ||
11 | public interface PointsRepository extends JpaRepository<Points, Long>, JpaSpecificationExecutor<Points> { | ||
12 | |||
13 | } |
1 | package com.topdraw.business.basicdata.points.rest; | ||
2 | |||
3 | import io.swagger.annotations.Api; | ||
4 | |||
5 | /** | ||
6 | * @author XiangHan | ||
7 | * @date 2021-10-22 | ||
8 | */ | ||
9 | @Api(tags = "Points管理") | ||
10 | //@RestController | ||
11 | //@RequestMapping("/api/Points") | ||
12 | public class PointsController { | ||
13 | |||
14 | /* @Autowired | ||
15 | private PointsService PointsService; | ||
16 | |||
17 | @GetMapping | ||
18 | @ApiOperation("查询Points") | ||
19 | public ResultInfo getPointss(PointsQueryCriteria criteria, Pageable pageable) { | ||
20 | return ResultInfo.successPage(PointsService.queryAll(criteria,pageable)); | ||
21 | } | ||
22 | |||
23 | @GetMapping(value = "/all") | ||
24 | @ApiOperation("查询所有Points") | ||
25 | public ResultInfo getPointss(PointsQueryCriteria criteria) { | ||
26 | return ResultInfo.success(PointsService.queryAll(criteria)); | ||
27 | } | ||
28 | |||
29 | @Log | ||
30 | @PostMapping | ||
31 | @ApiOperation("新增Points") | ||
32 | public ResultInfo create(@Validated @RequestBody Points resources) { | ||
33 | PointsService.create(resources); | ||
34 | return ResultInfo.success(); | ||
35 | } | ||
36 | |||
37 | @Log | ||
38 | @PutMapping | ||
39 | @ApiOperation("修改Points") | ||
40 | public ResultInfo update(@Validated @RequestBody Points resources) { | ||
41 | PointsService.update(resources); | ||
42 | return ResultInfo.success(); | ||
43 | } | ||
44 | |||
45 | |||
46 | @Log | ||
47 | @DeleteMapping(value = "/{id}") | ||
48 | @ApiOperation("删除Points") | ||
49 | public ResultInfo delete(@PathVariable Long id) { | ||
50 | PointsService.delete(id); | ||
51 | return ResultInfo.success(); | ||
52 | }*/ | ||
53 | |||
54 | } |
1 | package com.topdraw.business.basicdata.points.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.points.domain.Points; | ||
4 | import com.topdraw.business.basicdata.points.service.dto.PointsDTO; | ||
5 | import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface PointsService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(PointsQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<PointsDTO> | ||
29 | */ | ||
30 | List<PointsDTO> queryAll(PointsQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return PointsDTO | ||
36 | */ | ||
37 | PointsDTO findById(Long id); | ||
38 | |||
39 | void create(Points resources); | ||
40 | |||
41 | void update(Points resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | } |
1 | package com.topdraw.business.basicdata.points.service.dto; | ||
2 | |||
3 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
4 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||
5 | import lombok.Data; | ||
6 | |||
7 | import java.io.Serializable; | ||
8 | import java.sql.Timestamp; | ||
9 | |||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | @Data | ||
16 | public class PointsDTO implements Serializable { | ||
17 | |||
18 | // 处理精度丢失问题 | ||
19 | @JsonSerialize(using= ToStringSerializer.class) | ||
20 | private Long id; | ||
21 | |||
22 | private Long userId; | ||
23 | |||
24 | // 积分类型,通用,绑定, 区分大小屏 todo | ||
25 | private Integer pointType; | ||
26 | |||
27 | // 绑定对应的实体, 如何描述? | ||
28 | private String targetNo; | ||
29 | |||
30 | // 本月期初积分值 | ||
31 | private Integer beginPoints; | ||
32 | |||
33 | // 当前积分余额 | ||
34 | private Integer currentPoints; | ||
35 | |||
36 | // 本月到期积分 | ||
37 | private Integer expirePoints; | ||
38 | |||
39 | // 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途) | ||
40 | private Timestamp createTime; | ||
41 | |||
42 | // 最后修改时间 | ||
43 | private Timestamp updateTime; | ||
44 | } |
1 | package com.topdraw.business.basicdata.points.service.impl; | ||
2 | |||
3 | import cn.hutool.core.lang.Snowflake; | ||
4 | import cn.hutool.core.util.IdUtil; | ||
5 | import com.topdraw.business.basicdata.points.domain.Points; | ||
6 | import com.topdraw.business.basicdata.points.repository.PointsRepository; | ||
7 | import com.topdraw.business.basicdata.points.service.PointsService; | ||
8 | import com.topdraw.business.basicdata.points.service.dto.PointsDTO; | ||
9 | import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria; | ||
10 | import com.topdraw.business.basicdata.points.service.mapper.PointsMapper; | ||
11 | import com.topdraw.utils.PageUtil; | ||
12 | import com.topdraw.utils.QueryHelp; | ||
13 | import com.topdraw.utils.ValidationUtil; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | ||
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.stereotype.Service; | ||
19 | import org.springframework.transaction.annotation.Propagation; | ||
20 | import org.springframework.transaction.annotation.Transactional; | ||
21 | import org.springframework.util.Assert; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | |||
26 | /** | ||
27 | * @author XiangHan | ||
28 | * @date 2021-10-22 | ||
29 | */ | ||
30 | @Service | ||
31 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
32 | public class PointsServiceImpl implements PointsService { | ||
33 | |||
34 | @Autowired | ||
35 | private PointsRepository PointsRepository; | ||
36 | |||
37 | @Autowired | ||
38 | private PointsMapper PointsMapper; | ||
39 | |||
40 | @Override | ||
41 | public Map<String, Object> queryAll(PointsQueryCriteria criteria, Pageable pageable) { | ||
42 | Page<Points> page = PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
43 | return PageUtil.toPage(page.map(PointsMapper::toDto)); | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public List<PointsDTO> queryAll(PointsQueryCriteria criteria) { | ||
48 | return PointsMapper.toDto(PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public PointsDTO findById(Long id) { | ||
53 | Points Points = PointsRepository.findById(id).orElseGet(Points::new); | ||
54 | ValidationUtil.isNull(Points.getId(),"Points","id",id); | ||
55 | return PointsMapper.toDto(Points); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | @Transactional(rollbackFor = Exception.class) | ||
60 | public void create(Points resources) { | ||
61 | Snowflake snowflake = IdUtil.createSnowflake(1, 1); | ||
62 | resources.setId(snowflake.nextId()); | ||
63 | PointsRepository.save(resources); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | @Transactional(rollbackFor = Exception.class) | ||
68 | public void update(Points resources) { | ||
69 | Points Points = PointsRepository.findById(resources.getId()).orElseGet(Points::new); | ||
70 | ValidationUtil.isNull( Points.getId(),"Points","id",resources.getId()); | ||
71 | Points.copy(resources); | ||
72 | PointsRepository.save(Points); | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | @Transactional(rollbackFor = Exception.class) | ||
77 | public void delete(Long id) { | ||
78 | Assert.notNull(id, "The given id must not be null!"); | ||
79 | Points Points = PointsRepository.findById(id).orElseThrow( | ||
80 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Points.class, id), 1)); | ||
81 | PointsRepository.delete(Points); | ||
82 | } | ||
83 | |||
84 | |||
85 | } |
1 | package com.topdraw.business.basicdata.points.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.points.domain.Points; | ||
5 | import com.topdraw.business.basicdata.points.service.dto.PointsDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PointsMapper extends BaseMapper<PointsDTO, Points> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.rights.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="tr_rights") | ||
24 | public class Rights implements Serializable { | ||
25 | |||
26 | // 主键 | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 权益名称 | ||
37 | // @Column(name = "name") | ||
38 | // private String name; | ||
39 | |||
40 | // 类型 1:实体类 (预留字段) | ||
41 | @Column(name = "type", nullable = false) | ||
42 | private Integer type; | ||
43 | |||
44 | // 终端类型 0:大屏;1:微信小程序/公众号;2:App | ||
45 | @Column(name = "device_type", nullable = false) | ||
46 | private Integer deviceType; | ||
47 | |||
48 | // 权益的实体类型 1:积分;2成长值;3优惠券 | ||
49 | @Column(name = "entity_type", nullable = false) | ||
50 | private String entityType; | ||
51 | |||
52 | // 实体id | ||
53 | @Column(name = "entity_id", nullable = false) | ||
54 | private Long entityId; | ||
55 | |||
56 | // 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 | ||
57 | @Column(name = "valid_time") | ||
58 | private Timestamp validTime; | ||
59 | |||
60 | // 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 | ||
61 | @Column(name = "expire_time") | ||
62 | private Long expireTime; | ||
63 | |||
64 | // 创建时间 | ||
65 | @CreatedDate | ||
66 | @Column(name = "create_time") | ||
67 | private Timestamp createTime; | ||
68 | |||
69 | // 更新时间 | ||
70 | @LastModifiedDate | ||
71 | @Column(name = "update_time") | ||
72 | private Timestamp updateTime; | ||
73 | |||
74 | // 图片 | ||
75 | @Column(name = "image") | ||
76 | private String image; | ||
77 | |||
78 | // 图片 | ||
79 | @Column(name = "images") | ||
80 | private String images; | ||
81 | |||
82 | // 描述 | ||
83 | @Column(name = "description") | ||
84 | private String description; | ||
85 | |||
86 | public void copy(Rights source){ | ||
87 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
88 | } | ||
89 | } |
1 | package com.topdraw.business.basicdata.rights.history.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="tr_rights_histroy") | ||
24 | public class RightsHistory implements Serializable { | ||
25 | |||
26 | // 主键id | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 权益id | ||
33 | @Column(name = "rights_id",nullable = false) | ||
34 | private Long rightsId; | ||
35 | |||
36 | // 会员id | ||
37 | @Column(name = "member_id",nullable = false) | ||
38 | private Long memberId; | ||
39 | |||
40 | @Transient | ||
41 | private Long userId; | ||
42 | |||
43 | // 操作者id(手动发放时保存) | ||
44 | @Column(name = "operator_id",nullable = false) | ||
45 | private Long operatorId; | ||
46 | |||
47 | // 操作者名称(手动发放时保存) | ||
48 | @Column(name = "operator_name",nullable = false) | ||
49 | private String operatorName; | ||
50 | |||
51 | // 发放时间 | ||
52 | @Column(name = "send_time") | ||
53 | private Timestamp sendTime; | ||
54 | |||
55 | // 失效时间 | ||
56 | @Column(name = "expire_time") | ||
57 | private Timestamp expireTime; | ||
58 | |||
59 | @CreatedDate | ||
60 | @Column(name = "create_time") | ||
61 | private Timestamp createTime; | ||
62 | |||
63 | @LastModifiedDate | ||
64 | @Column(name = "update_time") | ||
65 | private Timestamp updateTime; | ||
66 | |||
67 | public void copy(RightsHistory source){ | ||
68 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
69 | } | ||
70 | } |
src/main/java/com/topdraw/business/basicdata/rights/history/repository/RightsHistoryRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.rights.history.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.history.domain.RightsHistory; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | /** | ||
8 | * @author XiangHan | ||
9 | * @date 2021-10-22 | ||
10 | */ | ||
11 | public interface RightsHistoryRepository extends JpaRepository<RightsHistory, Long>, JpaSpecificationExecutor<RightsHistory> { | ||
12 | |||
13 | } |
src/main/java/com/topdraw/business/basicdata/rights/history/rest/RightsHistoryController.java
0 → 100644
1 | package com.topdraw.business.basicdata.rights.history.rest; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService; | ||
4 | import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria; | ||
5 | import com.topdraw.common.ResultInfo; | ||
6 | import com.topdraw.util.TimestampUtil; | ||
7 | import io.swagger.annotations.Api; | ||
8 | import io.swagger.annotations.ApiOperation; | ||
9 | import org.springframework.beans.factory.annotation.Autowired; | ||
10 | import org.springframework.data.domain.Pageable; | ||
11 | import org.springframework.web.bind.annotation.GetMapping; | ||
12 | import org.springframework.web.bind.annotation.RequestMapping; | ||
13 | import org.springframework.web.bind.annotation.RestController; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "RightsHistory管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/RightsHistory") | ||
22 | public class RightsHistoryController { | ||
23 | |||
24 | @Autowired | ||
25 | private RightsHistoryService RightsHistoryService; | ||
26 | |||
27 | @GetMapping(value = "/pageRightsHistory") | ||
28 | @ApiOperation("查询RightsHistory") | ||
29 | public ResultInfo pageRightsHistory(RightsHistoryQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(RightsHistoryService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/pageAvailableRights") | ||
34 | @ApiOperation("查询用户可用权益列表") | ||
35 | public ResultInfo pageAvailableRights(RightsHistoryQueryCriteria criteria, Pageable pageable) { | ||
36 | criteria.setExpireTime(TimestampUtil.now()); | ||
37 | return ResultInfo.successPage(RightsHistoryService.queryAll(criteria,pageable)); | ||
38 | } | ||
39 | |||
40 | } |
src/main/java/com/topdraw/business/basicdata/rights/history/service/RightsHistoryService.java
0 → 100644
1 | package com.topdraw.business.basicdata.rights.history.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.history.domain.RightsHistory; | ||
4 | import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryDTO; | ||
5 | import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface RightsHistoryService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<RightsHistoryDTO> | ||
29 | */ | ||
30 | List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return RightsHistoryDTO | ||
36 | */ | ||
37 | RightsHistoryDTO findById(Long id); | ||
38 | |||
39 | /** | ||
40 | * | ||
41 | * @param resources | ||
42 | */ | ||
43 | void create(RightsHistory resources); | ||
44 | |||
45 | /** | ||
46 | * | ||
47 | * @param resources | ||
48 | */ | ||
49 | void update(RightsHistory resources); | ||
50 | |||
51 | /** | ||
52 | * | ||
53 | * @param id | ||
54 | */ | ||
55 | void delete(Long id); | ||
56 | |||
57 | } |
src/main/java/com/topdraw/business/basicdata/rights/history/service/dto/RightsHistoryDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.rights.history.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class RightsHistoryDTO implements Serializable { | ||
15 | |||
16 | // 主键id | ||
17 | private Long id; | ||
18 | |||
19 | // 权益id | ||
20 | private Long rightsId; | ||
21 | |||
22 | // 会员id | ||
23 | private Long memberId; | ||
24 | |||
25 | // 操作者id(手动发放时保存) | ||
26 | private Long operatorId; | ||
27 | |||
28 | // 操作者名称(手动发放时保存) | ||
29 | private String operatorName; | ||
30 | |||
31 | // 发放时间 | ||
32 | private Timestamp sendTime; | ||
33 | |||
34 | // 失效时间 | ||
35 | private Timestamp expireTime; | ||
36 | |||
37 | private Timestamp createTime; | ||
38 | |||
39 | private Timestamp updateTime; | ||
40 | } |
1 | package com.topdraw.business.basicdata.rights.history.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2021-10-22 | ||
11 | */ | ||
12 | @Data | ||
13 | public class RightsHistoryQueryCriteria{ | ||
14 | |||
15 | @Query | ||
16 | private Long memberId; | ||
17 | |||
18 | @Query(type = Query.Type.GREATER_THAN) | ||
19 | private Timestamp expireTime; | ||
20 | |||
21 | private RightsHistoryQueryType queryType; | ||
22 | |||
23 | } |
1 | package com.topdraw.business.basicdata.rights.history.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.history.domain.RightsHistory; | ||
4 | import com.topdraw.business.basicdata.rights.history.repository.RightsHistoryRepository; | ||
5 | import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService; | ||
6 | import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryDTO; | ||
7 | import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.rights.history.service.mapper.RightsHistoryMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.ValidationUtil; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
14 | import org.springframework.data.domain.Page; | ||
15 | import org.springframework.data.domain.Pageable; | ||
16 | import org.springframework.stereotype.Service; | ||
17 | import org.springframework.transaction.annotation.Propagation; | ||
18 | import org.springframework.transaction.annotation.Transactional; | ||
19 | import org.springframework.util.Assert; | ||
20 | |||
21 | import java.util.List; | ||
22 | import java.util.Map; | ||
23 | |||
24 | /** | ||
25 | * @author XiangHan | ||
26 | * @date 2021-10-22 | ||
27 | */ | ||
28 | @Service | ||
29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
30 | public class RightsHistoryServiceImpl implements RightsHistoryService { | ||
31 | |||
32 | @Autowired | ||
33 | private RightsHistoryRepository RightsHistoryRepository; | ||
34 | |||
35 | @Autowired | ||
36 | private RightsHistoryMapper RightsHistoryMapper; | ||
37 | |||
38 | @Override | ||
39 | public Map<String, Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable) { | ||
40 | Page<RightsHistory> page = RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
41 | return PageUtil.toPage(page.map(RightsHistoryMapper::toDto)); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria) { | ||
46 | return RightsHistoryMapper.toDto(RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public RightsHistoryDTO findById(Long id) { | ||
51 | RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseGet(RightsHistory::new); | ||
52 | ValidationUtil.isNull(RightsHistory.getId(),"RightsHistory","id",id); | ||
53 | return RightsHistoryMapper.toDto(RightsHistory); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | @Transactional(rollbackFor = Exception.class) | ||
58 | public void create(RightsHistory resources) { | ||
59 | RightsHistoryRepository.save(resources); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | @Transactional(rollbackFor = Exception.class) | ||
64 | public void update(RightsHistory resources) { | ||
65 | RightsHistory RightsHistory = RightsHistoryRepository.findById(resources.getId()).orElseGet(RightsHistory::new); | ||
66 | ValidationUtil.isNull( RightsHistory.getId(),"RightsHistory","id",resources.getId()); | ||
67 | RightsHistory.copy(resources); | ||
68 | RightsHistoryRepository.save(RightsHistory); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | @Transactional(rollbackFor = Exception.class) | ||
73 | public void delete(Long id) { | ||
74 | Assert.notNull(id, "The given id must not be null!"); | ||
75 | RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseThrow( | ||
76 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", RightsHistory.class, id), 1)); | ||
77 | RightsHistoryRepository.delete(RightsHistory); | ||
78 | } | ||
79 | |||
80 | |||
81 | } |
src/main/java/com/topdraw/business/basicdata/rights/history/service/mapper/RightsHistoryMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.rights.history.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.rights.history.domain.RightsHistory; | ||
5 | import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface RightsHistoryMapper extends BaseMapper<RightsHistoryDTO, RightsHistory> { | ||
15 | |||
16 | } |
src/main/java/com/topdraw/business/basicdata/rights/permanentrights/domain/PermanentRights.java
0 → 100644
1 | package com.topdraw.business.basicdata.rights.permanentrights.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.math.BigDecimal; | ||
14 | import java.sql.Timestamp; | ||
15 | |||
16 | /** | ||
17 | * @author XiangHan | ||
18 | * @date 2021-10-22 | ||
19 | */ | ||
20 | @Entity | ||
21 | @Data | ||
22 | @EntityListeners(AuditingEntityListener.class) | ||
23 | @Accessors(chain = true) | ||
24 | @Table(name="uc_permanent_rights") | ||
25 | public class PermanentRights implements Serializable { | ||
26 | |||
27 | // ID | ||
28 | @Id | ||
29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
30 | @Column(name = "id") | ||
31 | private Long id; | ||
32 | |||
33 | // 标识 | ||
34 | @Column(name = "code", nullable = false) | ||
35 | private String code; | ||
36 | |||
37 | // 名称 | ||
38 | @Column(name = "name", nullable = false) | ||
39 | private String name; | ||
40 | |||
41 | // 永久权益类型 0:vip;1:会员等级 | ||
42 | @Column(name = "type") | ||
43 | private Integer type; | ||
44 | |||
45 | // 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) | ||
46 | @Column(name = "level") | ||
47 | private Integer level; | ||
48 | |||
49 | // 商品折扣,10代表10% off,范围为0-100 | ||
50 | @Column(name = "item_discount", nullable = false) | ||
51 | private BigDecimal itemDiscount; | ||
52 | |||
53 | // 额外积分比率,范围为0-1000 | ||
54 | @Column(name = "extra_points", nullable = false) | ||
55 | private BigDecimal extraPoints; | ||
56 | |||
57 | // 免广告 | ||
58 | @Column(name = "ad_disabled", nullable = false) | ||
59 | private Integer adDisabled; | ||
60 | |||
61 | // 额外活动参与机会 | ||
62 | @Column(name = "extra_activity_ticket", nullable = false) | ||
63 | private Integer extraActivityTicket; | ||
64 | |||
65 | // 免费试看 | ||
66 | @Column(name = "free_trial", nullable = false) | ||
67 | private Integer freeTrial; | ||
68 | |||
69 | // 上电视专区权益 | ||
70 | @Column(name = "zone_sds", nullable = false) | ||
71 | private Integer zoneSds; | ||
72 | |||
73 | // 创建时间 | ||
74 | @CreatedDate | ||
75 | @Column(name = "create_time") | ||
76 | private Timestamp createTime; | ||
77 | |||
78 | // 更新时间 | ||
79 | @LastModifiedDate | ||
80 | @Column(name = "update_time") | ||
81 | private Timestamp updateTime; | ||
82 | |||
83 | public void copy(PermanentRights source){ | ||
84 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
85 | } | ||
86 | } |
1 | package com.topdraw.business.basicdata.rights.permanentrights.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> { | ||
14 | |||
15 | Optional<PermanentRights> findFirstByCode(String code); | ||
16 | } |
1 | package com.topdraw.business.basicdata.rights.permanentrights.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights; | ||
5 | import com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService; | ||
6 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "PermanentRights管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/PermanentRights") | ||
22 | public class PermanentRightsController { | ||
23 | |||
24 | @Autowired | ||
25 | private PermanentRightsService PermanentRightsService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询PermanentRights") | ||
29 | public ResultInfo pagePermanentRights(PermanentRightsQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(PermanentRightsService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/findById/{id}") | ||
34 | @ApiOperation("查询PermanentRights") | ||
35 | public ResultInfo findById(@PathVariable("id") Long id) { | ||
36 | return ResultInfo.success(PermanentRightsService.findById(id)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping(value = "/create") | ||
41 | @ApiOperation("新增PermanentRights") | ||
42 | public ResultInfo create(@Validated @RequestBody PermanentRights resources) { | ||
43 | PermanentRightsService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping(value = "/update") | ||
49 | @ApiOperation("修改PermanentRights") | ||
50 | public ResultInfo update(@Validated @RequestBody PermanentRights resources) { | ||
51 | PermanentRightsService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | @Log | ||
56 | @DeleteMapping(value = "/delete/{id}") | ||
57 | @ApiOperation("删除PermanentRights") | ||
58 | public ResultInfo delete(@PathVariable Long id) { | ||
59 | PermanentRightsService.delete(id); | ||
60 | return ResultInfo.success(); | ||
61 | } | ||
62 | |||
63 | @GetMapping(value = "/getByCode/{code}") | ||
64 | @ApiOperation(value = "根据标识查询") | ||
65 | public ResultInfo getByCode(@PathVariable String code) { | ||
66 | return ResultInfo.success(PermanentRightsService.getByCode(code)); | ||
67 | } | ||
68 | } |
1 | package com.topdraw.business.basicdata.rights.permanentrights.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights; | ||
4 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO; | ||
5 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface PermanentRightsService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<PermanentRightsDTO> | ||
29 | */ | ||
30 | List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return PermanentRightsDTO | ||
36 | */ | ||
37 | PermanentRightsDTO findById(Long id); | ||
38 | |||
39 | void create(PermanentRights resources); | ||
40 | |||
41 | void update(PermanentRights resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return PermanentRightsDTO | ||
49 | */ | ||
50 | PermanentRightsDTO getByCode(String code); | ||
51 | } |
1 | package com.topdraw.business.basicdata.rights.permanentrights.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.math.BigDecimal; | ||
7 | import java.sql.Timestamp; | ||
8 | |||
9 | |||
10 | /** | ||
11 | * @author XiangHan | ||
12 | * @date 2021-10-22 | ||
13 | */ | ||
14 | @Data | ||
15 | public class PermanentRightsDTO implements Serializable { | ||
16 | |||
17 | // ID | ||
18 | private Long id; | ||
19 | |||
20 | // 标识 | ||
21 | private String code; | ||
22 | |||
23 | // 名称 | ||
24 | private String name; | ||
25 | |||
26 | // 永久权益类型 0:vip;1:会员等级 | ||
27 | private Integer type; | ||
28 | |||
29 | // 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) | ||
30 | private Integer level; | ||
31 | |||
32 | // 商品折扣,10代表10% off,范围为0-100 | ||
33 | private BigDecimal itemDiscount; | ||
34 | |||
35 | // 额外积分比率,范围为0-1000 | ||
36 | private BigDecimal extraPoints; | ||
37 | |||
38 | // 免广告 | ||
39 | private Integer adDisabled; | ||
40 | |||
41 | // 额外活动参与机会 | ||
42 | private Integer extraActivityTicket; | ||
43 | |||
44 | // 免费试看 | ||
45 | private Integer freeTrial; | ||
46 | |||
47 | // 上电视专区权益 | ||
48 | private Integer zoneSds; | ||
49 | |||
50 | // 创建时间 | ||
51 | private Timestamp createTime; | ||
52 | |||
53 | // 更新时间 | ||
54 | private Timestamp updateTime; | ||
55 | } |
1 | package com.topdraw.business.basicdata.rights.permanentrights.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-10-22 | ||
9 | */ | ||
10 | @Data | ||
11 | public class PermanentRightsQueryCriteria{ | ||
12 | |||
13 | @Query(type = Query.Type.EQUAL) | ||
14 | private Integer level; | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.rights.permanentrights.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights; | ||
4 | import com.topdraw.business.basicdata.rights.permanentrights.repository.PermanentRightsRepository; | ||
5 | import com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService; | ||
6 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO; | ||
7 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.rights.permanentrights.service.mapper.PermanentRightsMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class PermanentRightsServiceImpl implements PermanentRightsService { | ||
32 | |||
33 | @Autowired | ||
34 | private PermanentRightsRepository PermanentRightsRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private PermanentRightsMapper PermanentRightsMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<PermanentRights> page = PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(PermanentRightsMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria) { | ||
47 | return PermanentRightsMapper.toDto(PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public PermanentRightsDTO findById(Long id) { | ||
52 | PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseGet(PermanentRights::new); | ||
53 | ValidationUtil.isNull(PermanentRights.getId(),"PermanentRights","id",id); | ||
54 | return PermanentRightsMapper.toDto(PermanentRights); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(PermanentRights resources) { | ||
60 | PermanentRightsRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(PermanentRights resources) { | ||
66 | PermanentRights PermanentRights = PermanentRightsRepository.findById(resources.getId()).orElseGet(PermanentRights::new); | ||
67 | ValidationUtil.isNull( PermanentRights.getId(),"PermanentRights","id",resources.getId()); | ||
68 | PermanentRights.copy(resources); | ||
69 | PermanentRightsRepository.save(PermanentRights); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PermanentRights.class, id), 1)); | ||
78 | PermanentRightsRepository.delete(PermanentRights); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public PermanentRightsDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? PermanentRightsMapper.toDto(PermanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new)) | ||
85 | : new PermanentRightsDTO(); | ||
86 | } | ||
87 | } |
1 | package com.topdraw.business.basicdata.rights.permanentrights.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights; | ||
5 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PermanentRightsMapper extends BaseMapper<PermanentRightsDTO, PermanentRights> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.rights.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.domain.Rights; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | import org.springframework.data.jpa.repository.Query; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Optional; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface RightsRepository extends JpaRepository<Rights, Long>, JpaSpecificationExecutor<Rights> { | ||
16 | |||
17 | Optional<Rights> findFirstByCode(String code); | ||
18 | |||
19 | @Query(value = "FROM Rights r WHERE r.id IN (?2)",nativeQuery = false) | ||
20 | List<Rights> findBatchByIds(Long[] ids); | ||
21 | } |
1 | package com.topdraw.business.basicdata.rights.rest; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.service.RightsService; | ||
4 | import com.topdraw.common.ResultInfo; | ||
5 | import io.swagger.annotations.Api; | ||
6 | import io.swagger.annotations.ApiOperation; | ||
7 | import org.springframework.beans.factory.annotation.Autowired; | ||
8 | import org.springframework.web.bind.annotation.GetMapping; | ||
9 | import org.springframework.web.bind.annotation.PathVariable; | ||
10 | import org.springframework.web.bind.annotation.RequestMapping; | ||
11 | import org.springframework.web.bind.annotation.RestController; | ||
12 | |||
13 | /** | ||
14 | * @author XiangHan | ||
15 | * @date 2021-10-22 | ||
16 | */ | ||
17 | @Api(tags = "Rights管理") | ||
18 | @RestController | ||
19 | @RequestMapping("/api/Rights") | ||
20 | public class RightsController { | ||
21 | |||
22 | @Autowired | ||
23 | private RightsService rightsService; | ||
24 | |||
25 | @GetMapping(value = "/findById/{id}") | ||
26 | @ApiOperation("查询Rights") | ||
27 | public ResultInfo findById(@PathVariable("id") Long id) { | ||
28 | return ResultInfo.success(rightsService.findById(id)); | ||
29 | } | ||
30 | |||
31 | } |
1 | package com.topdraw.business.basicdata.rights.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.domain.Rights; | ||
4 | import com.topdraw.business.basicdata.rights.service.dto.RightsDTO; | ||
5 | import com.topdraw.business.basicdata.rights.service.dto.RightsQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface RightsService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(RightsQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<RightsDTO> | ||
29 | */ | ||
30 | List<RightsDTO> queryAll(RightsQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return RightsDTO | ||
36 | */ | ||
37 | RightsDTO findById(Long id); | ||
38 | |||
39 | /** | ||
40 | * 批量查询 | ||
41 | * @param ids | ||
42 | * @return | ||
43 | */ | ||
44 | List<RightsDTO> findBatchByIds(Long... ids); | ||
45 | |||
46 | void create(Rights resources); | ||
47 | |||
48 | void update(Rights resources); | ||
49 | |||
50 | void delete(Long id); | ||
51 | |||
52 | /** | ||
53 | * Code校验 | ||
54 | * @param code | ||
55 | * @return RightsDTO | ||
56 | */ | ||
57 | RightsDTO getByCode(String code); | ||
58 | } |
1 | package com.topdraw.business.basicdata.rights.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class RightsDTO implements Serializable { | ||
15 | |||
16 | // 主键 | ||
17 | private Long id; | ||
18 | |||
19 | // 标识 | ||
20 | private String code; | ||
21 | |||
22 | // 权益名称 | ||
23 | // private String name; | ||
24 | // 终端类型 0:大屏;1:微信小程序/公众号;2:App | ||
25 | private Integer deviceType; | ||
26 | |||
27 | // 类型 1:实体类 (预留字段) | ||
28 | private Integer type; | ||
29 | |||
30 | // 权益的实体类型 1:积分;2成长值;3优惠券 | ||
31 | private String entityType; | ||
32 | |||
33 | // 实体id | ||
34 | private Long entityId; | ||
35 | |||
36 | // 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 | ||
37 | private Timestamp validTime; | ||
38 | |||
39 | // 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 | ||
40 | private Long expireTime; | ||
41 | |||
42 | // 创建时间 | ||
43 | private Timestamp createTime; | ||
44 | |||
45 | // 更新时间 | ||
46 | private Timestamp updateTime; | ||
47 | |||
48 | // 图片 | ||
49 | private String image; | ||
50 | |||
51 | // 图片 | ||
52 | private String images; | ||
53 | |||
54 | // 描述 | ||
55 | private String description; | ||
56 | } |
1 | package com.topdraw.business.basicdata.rights.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-10-22 | ||
9 | */ | ||
10 | @Data | ||
11 | public class RightsQueryCriteria{ | ||
12 | |||
13 | @Query | ||
14 | private Long memberId; | ||
15 | |||
16 | private RightsQueryType queryType; | ||
17 | |||
18 | } |
1 | package com.topdraw.business.basicdata.rights.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.rights.domain.Rights; | ||
4 | import com.topdraw.business.basicdata.rights.repository.RightsRepository; | ||
5 | import com.topdraw.business.basicdata.rights.service.RightsService; | ||
6 | import com.topdraw.business.basicdata.rights.service.dto.RightsDTO; | ||
7 | import com.topdraw.business.basicdata.rights.service.dto.RightsQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.rights.service.mapper.RightsMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | import org.springframework.util.CollectionUtils; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | |||
26 | /** | ||
27 | * @author XiangHan | ||
28 | * @date 2021-10-22 | ||
29 | */ | ||
30 | @Service | ||
31 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
32 | public class RightsServiceImpl implements RightsService { | ||
33 | |||
34 | @Autowired | ||
35 | private RightsRepository RightsRepository; | ||
36 | |||
37 | @Autowired | ||
38 | private RightsMapper RightsMapper; | ||
39 | |||
40 | @Override | ||
41 | public Map<String, Object> queryAll(RightsQueryCriteria criteria, Pageable pageable) { | ||
42 | Page<Rights> page = RightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
43 | return PageUtil.toPage(page.map(RightsMapper::toDto)); | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public List<RightsDTO> queryAll(RightsQueryCriteria criteria) { | ||
48 | return RightsMapper.toDto(RightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public RightsDTO findById(Long id) { | ||
53 | Rights Rights = RightsRepository.findById(id).orElseGet(Rights::new); | ||
54 | ValidationUtil.isNull(Rights.getId(),"Rights","id",id); | ||
55 | return RightsMapper.toDto(Rights); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | public List<RightsDTO> findBatchByIds(Long... ids) { | ||
60 | List<Rights> rightsList = this.RightsRepository.findBatchByIds(ids); | ||
61 | return !CollectionUtils.isEmpty(rightsList) ? RightsMapper.toDto(rightsList) : null; | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | @Transactional(rollbackFor = Exception.class) | ||
66 | public void create(Rights resources) { | ||
67 | RightsRepository.save(resources); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | @Transactional(rollbackFor = Exception.class) | ||
72 | public void update(Rights resources) { | ||
73 | Rights Rights = RightsRepository.findById(resources.getId()).orElseGet(Rights::new); | ||
74 | ValidationUtil.isNull( Rights.getId(),"Rights","id",resources.getId()); | ||
75 | Rights.copy(resources); | ||
76 | RightsRepository.save(Rights); | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | @Transactional(rollbackFor = Exception.class) | ||
81 | public void delete(Long id) { | ||
82 | Assert.notNull(id, "The given id must not be null!"); | ||
83 | Rights Rights = RightsRepository.findById(id).orElseThrow( | ||
84 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Rights.class, id), 1)); | ||
85 | RightsRepository.delete(Rights); | ||
86 | } | ||
87 | |||
88 | |||
89 | @Override | ||
90 | public RightsDTO getByCode(String code) { | ||
91 | return StringUtils.isNotEmpty(code) ? RightsMapper.toDto(RightsRepository.findFirstByCode(code).orElseGet(Rights::new)) | ||
92 | : new RightsDTO(); | ||
93 | } | ||
94 | } |
1 | package com.topdraw.business.basicdata.rights.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.rights.domain.Rights; | ||
5 | import com.topdraw.business.basicdata.rights.service.dto.RightsDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface RightsMapper extends BaseMapper<RightsDTO, Rights> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.task.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="tr_task") | ||
24 | public class Task implements Serializable { | ||
25 | |||
26 | @Id | ||
27 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
28 | @Column(name = "id") | ||
29 | private Long id; | ||
30 | |||
31 | // 任务模板id | ||
32 | @Column(name = "task_template_id", nullable = false) | ||
33 | private Long taskTemplateId; | ||
34 | |||
35 | // 任务重复类型,-1:不限次;1:单次;>1:多次 | ||
36 | @Column(name = "task_repeat_type", nullable = false) | ||
37 | private Integer taskRepeatType; | ||
38 | |||
39 | // 任务每日重置 0:不重置;1:重置 | ||
40 | @Column(name = "task_daily_reset", nullable = false) | ||
41 | private Integer taskDailyReset; | ||
42 | |||
43 | // 行为量(完成此任务需要多少次相同行为的触发) | ||
44 | @Column(name = "action_amount", nullable = false) | ||
45 | private Integer actionAmount; | ||
46 | |||
47 | // 任务生效时间 | ||
48 | @Column(name = "valid_time") | ||
49 | private Timestamp validTime; | ||
50 | |||
51 | // 任务失效时间 | ||
52 | @Column(name = "expire_time") | ||
53 | private Timestamp expireTime; | ||
54 | |||
55 | // 显示顺序 | ||
56 | @Column(name = "sequence") | ||
57 | private Integer sequence; | ||
58 | |||
59 | // 获得成长值 | ||
60 | @Column(name = "reward_exp", nullable = false) | ||
61 | private Long rewardExp; | ||
62 | |||
63 | // 获得积分 | ||
64 | @Column(name = "reward_points", nullable = false) | ||
65 | private Long rewardPoints; | ||
66 | |||
67 | // 积分过期时间(空为不过期) | ||
68 | @Column(name = "reward_points_expire_time") | ||
69 | private Long rewardPointsExpireTime; | ||
70 | |||
71 | // 积分获取类型 0:定值;1:随机 | ||
72 | @Column(name = "points_type") | ||
73 | private Integer pointsType; | ||
74 | |||
75 | // 随机积分最大值 | ||
76 | @Column(name = "reward_max_points") | ||
77 | private Integer rewardMaxPoints; | ||
78 | |||
79 | // 能够获取该任务的用户分组,为空则都能获取 | ||
80 | @Column(name = "groups") | ||
81 | private String groups; | ||
82 | |||
83 | // 权益发放策略 0:立即发放;1:次日发放;2:次月发放 | ||
84 | @Column(name = "rights_send_strategy", nullable = false) | ||
85 | private Integer rightsSendStrategy; | ||
86 | |||
87 | // 会员等级门槛(0表示无门槛) | ||
88 | @Column(name = "member_level", nullable = false) | ||
89 | private Integer memberLevel; | ||
90 | |||
91 | // 会员vip门槛(0表示没有门槛) | ||
92 | @Column(name = "member_vip") | ||
93 | private Integer memberVip; | ||
94 | |||
95 | // 权益id | ||
96 | @Column(name = "rights_id") | ||
97 | private Long rightsId; | ||
98 | |||
99 | // 权益数量(活动机会次数、优惠券数量、奖品数量) | ||
100 | @Column(name = "rights_amount") | ||
101 | private Integer rightsAmount; | ||
102 | |||
103 | // 权益2id | ||
104 | @Column(name = "rights2_id") | ||
105 | private Long rights2Id; | ||
106 | |||
107 | // 权益2数量 | ||
108 | @Column(name = "rights2_amount") | ||
109 | private Integer rights2Amount; | ||
110 | |||
111 | // 权益3id | ||
112 | @Column(name = "rights3_id") | ||
113 | private Long rights3Id; | ||
114 | |||
115 | // 权益3数量 | ||
116 | @Column(name = "rights3_amount") | ||
117 | private Integer rights3Amount; | ||
118 | |||
119 | // 状态 0:失效;1:生效 | ||
120 | @Column(name = "status", nullable = false) | ||
121 | private Integer status; | ||
122 | |||
123 | // 创建时间 | ||
124 | @CreatedDate | ||
125 | @Column(name = "create_time") | ||
126 | private Timestamp createTime; | ||
127 | |||
128 | // 更新时间 | ||
129 | @LastModifiedDate | ||
130 | @Column(name = "update_time") | ||
131 | private Timestamp updateTime; | ||
132 | |||
133 | public void copy(Task source){ | ||
134 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
135 | } | ||
136 | } |
1 | package com.topdraw.business.basicdata.task.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.task.domain.Task; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.List; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificationExecutor<Task> { | ||
14 | |||
15 | List<Task> findByTaskTemplateId(Long taskTemplateId); | ||
16 | |||
17 | // List<Task> findByTemplateId(Long taskTemplateId); | ||
18 | } |
1 | package com.topdraw.business.basicdata.task.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.task.domain.Task; | ||
5 | import com.topdraw.business.basicdata.task.service.TaskService; | ||
6 | import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "Task管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/Task") | ||
22 | public class TaskController { | ||
23 | |||
24 | @Autowired | ||
25 | private TaskService TaskService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询Task") | ||
29 | public ResultInfo getTasks(TaskQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(TaskService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有Task") | ||
35 | public ResultInfo getTasks(TaskQueryCriteria criteria) { | ||
36 | return ResultInfo.success(TaskService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增Task") | ||
42 | public ResultInfo create(@Validated @RequestBody Task resources) { | ||
43 | TaskService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改Task") | ||
50 | public ResultInfo update(@Validated @RequestBody Task resources) { | ||
51 | TaskService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除Task") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | TaskService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | } |
1 | package com.topdraw.business.basicdata.task.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.task.domain.Task; | ||
4 | import com.topdraw.business.basicdata.task.service.dto.TaskDTO; | ||
5 | import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface TaskService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(TaskQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<TaskDTO> | ||
29 | */ | ||
30 | List<TaskDTO> queryAll(TaskQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return TaskDTO | ||
36 | */ | ||
37 | TaskDTO findById(Long id); | ||
38 | |||
39 | void create(Task resources); | ||
40 | |||
41 | void update(Task resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | List<Task> findByTemplateId(Long taskTemplateId); | ||
46 | } |
1 | package com.topdraw.business.basicdata.task.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class TaskDTO implements Serializable { | ||
15 | |||
16 | private Long id; | ||
17 | |||
18 | // 任务模板id | ||
19 | private Long taskTemplateId; | ||
20 | |||
21 | // 任务重复类型,-1:不限次;1:单次;>1:多次 | ||
22 | private Integer taskRepeatType; | ||
23 | |||
24 | // 任务每日重置 0:不重置;1:重置 | ||
25 | private Integer taskDailyReset; | ||
26 | |||
27 | // 行为量(完成此任务需要多少次相同行为的触发) | ||
28 | private Integer actionAmount; | ||
29 | |||
30 | // 任务生效时间 | ||
31 | private Timestamp validTime; | ||
32 | |||
33 | // 任务失效时间 | ||
34 | private Timestamp expireTime; | ||
35 | |||
36 | // 显示顺序 | ||
37 | private Integer sequence; | ||
38 | |||
39 | // 获得成长值 | ||
40 | private Long rewardExp; | ||
41 | |||
42 | // 获得积分 | ||
43 | private Long rewardPoints; | ||
44 | |||
45 | // 积分过期时间(空为不过期) | ||
46 | private Long rewardPointsExpireTime; | ||
47 | |||
48 | // 能够获取该任务的用户分组,为空则都能获取 | ||
49 | private String groups; | ||
50 | |||
51 | // 会员等级门槛(0表示无门槛) | ||
52 | private Integer memberLevel; | ||
53 | |||
54 | // 会员vip门槛(0表示没有门槛) | ||
55 | private Integer memberVip; | ||
56 | |||
57 | // 权益id | ||
58 | private Long rightsId; | ||
59 | |||
60 | // 权益数量(活动机会次数、优惠券数量、奖品数量) | ||
61 | private Integer rightsAmount; | ||
62 | |||
63 | // 权益2id | ||
64 | private Long rights2Id; | ||
65 | |||
66 | // 权益2数量 | ||
67 | private Integer rights2Amount; | ||
68 | |||
69 | // 权益3id | ||
70 | private Long rights3Id; | ||
71 | |||
72 | // 权益3数量 | ||
73 | private Integer rights3Amount; | ||
74 | |||
75 | // 状态 0:失效;1:生效 | ||
76 | private Integer status; | ||
77 | |||
78 | // 创建时间 | ||
79 | private Timestamp createTime; | ||
80 | |||
81 | // 更新时间 | ||
82 | private Timestamp updateTime; | ||
83 | } |
1 | package com.topdraw.business.basicdata.task.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.task.domain.Task; | ||
4 | import com.topdraw.business.basicdata.task.repository.TaskRepository; | ||
5 | import com.topdraw.business.basicdata.task.service.TaskService; | ||
6 | import com.topdraw.business.basicdata.task.service.dto.TaskDTO; | ||
7 | import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.task.service.mapper.TaskMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.ValidationUtil; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
14 | import org.springframework.data.domain.Page; | ||
15 | import org.springframework.data.domain.Pageable; | ||
16 | import org.springframework.stereotype.Service; | ||
17 | import org.springframework.transaction.annotation.Propagation; | ||
18 | import org.springframework.transaction.annotation.Transactional; | ||
19 | import org.springframework.util.Assert; | ||
20 | |||
21 | import java.util.List; | ||
22 | import java.util.Map; | ||
23 | import java.util.Objects; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class TaskServiceImpl implements TaskService { | ||
32 | |||
33 | @Autowired | ||
34 | private TaskRepository TaskRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private TaskMapper TaskMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(TaskQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<Task> page = TaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(TaskMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<TaskDTO> queryAll(TaskQueryCriteria criteria) { | ||
47 | return TaskMapper.toDto(TaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public TaskDTO findById(Long id) { | ||
52 | Task Task = TaskRepository.findById(id).orElseGet(Task::new); | ||
53 | ValidationUtil.isNull(Task.getId(),"Task","id",id); | ||
54 | return TaskMapper.toDto(Task); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(Task resources) { | ||
60 | TaskRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(Task resources) { | ||
66 | Task Task = TaskRepository.findById(resources.getId()).orElseGet(Task::new); | ||
67 | ValidationUtil.isNull( Task.getId(),"Task","id",resources.getId()); | ||
68 | Task.copy(resources); | ||
69 | TaskRepository.save(Task); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | Task Task = TaskRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Task.class, id), 1)); | ||
78 | TaskRepository.delete(Task); | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public List<Task> findByTemplateId(Long taskTemplateId) { | ||
83 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | ||
84 | } | ||
85 | |||
86 | |||
87 | } |
1 | package com.topdraw.business.basicdata.task.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.task.domain.Task; | ||
5 | import com.topdraw.business.basicdata.task.service.dto.TaskDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface TaskMapper extends BaseMapper<TaskDTO, Task> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.basicdata.task.template.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="tr_task_template") | ||
24 | public class TaskTemplate implements Serializable { | ||
25 | |||
26 | @Id | ||
27 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
28 | @Column(name = "id") | ||
29 | private Long id; | ||
30 | |||
31 | // 标识 | ||
32 | @Column(name = "code") | ||
33 | private String code; | ||
34 | |||
35 | // 名称 | ||
36 | @Column(name = "name") | ||
37 | private String name; | ||
38 | |||
39 | // 关注事件(和MQ topic相关) | ||
40 | @Column(name = "event") | ||
41 | private String event; | ||
42 | |||
43 | // 描述 | ||
44 | @Column(name = "description") | ||
45 | private String description; | ||
46 | |||
47 | // 状态 0:失效;1:生效 | ||
48 | @Column(name = "status") | ||
49 | private Integer status; | ||
50 | |||
51 | // 类型 0:活动任务模板 | ||
52 | @Column(name = "type") | ||
53 | private Integer type; | ||
54 | |||
55 | // 模板参数,json | ||
56 | @Column(name = "params") | ||
57 | private String params; | ||
58 | |||
59 | @CreatedDate | ||
60 | @Column(name = "create_time") | ||
61 | private Timestamp createTime; | ||
62 | |||
63 | @LastModifiedDate | ||
64 | @Column(name = "update_time") | ||
65 | private Timestamp updateTime; | ||
66 | |||
67 | public void copy(TaskTemplate source){ | ||
68 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
69 | } | ||
70 | } |
src/main/java/com/topdraw/business/basicdata/task/template/repository/TaskTemplateRepository.java
0 → 100644
1 | package com.topdraw.business.basicdata.task.template.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | public interface TaskTemplateRepository extends JpaRepository<TaskTemplate, Long>, JpaSpecificationExecutor<TaskTemplate> { | ||
14 | |||
15 | Optional<TaskTemplate> findFirstByCode(String code); | ||
16 | |||
17 | TaskTemplate findByEvent(String event); | ||
18 | } |
src/main/java/com/topdraw/business/basicdata/task/template/rest/TaskTemplateController.java
0 → 100644
1 | package com.topdraw.business.basicdata.task.template.rest; | ||
2 | |||
3 | import com.topdraw.annotation.Log; | ||
4 | import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; | ||
5 | import com.topdraw.business.basicdata.task.template.service.TaskTemplateService; | ||
6 | import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import io.swagger.annotations.Api; | ||
9 | import io.swagger.annotations.ApiOperation; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.data.domain.Pageable; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "TaskTemplate管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/api/TaskTemplate") | ||
22 | public class TaskTemplateController { | ||
23 | |||
24 | @Autowired | ||
25 | private TaskTemplateService TaskTemplateService; | ||
26 | |||
27 | @GetMapping | ||
28 | @ApiOperation("查询TaskTemplate") | ||
29 | public ResultInfo getTaskTemplates(TaskTemplateQueryCriteria criteria, Pageable pageable) { | ||
30 | return ResultInfo.successPage(TaskTemplateService.queryAll(criteria,pageable)); | ||
31 | } | ||
32 | |||
33 | @GetMapping(value = "/all") | ||
34 | @ApiOperation("查询所有TaskTemplate") | ||
35 | public ResultInfo getTaskTemplates(TaskTemplateQueryCriteria criteria) { | ||
36 | return ResultInfo.success(TaskTemplateService.queryAll(criteria)); | ||
37 | } | ||
38 | |||
39 | @Log | ||
40 | @PostMapping | ||
41 | @ApiOperation("新增TaskTemplate") | ||
42 | public ResultInfo create(@Validated @RequestBody TaskTemplate resources) { | ||
43 | TaskTemplateService.create(resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log | ||
48 | @PutMapping | ||
49 | @ApiOperation("修改TaskTemplate") | ||
50 | public ResultInfo update(@Validated @RequestBody TaskTemplate resources) { | ||
51 | TaskTemplateService.update(resources); | ||
52 | return ResultInfo.success(); | ||
53 | } | ||
54 | |||
55 | |||
56 | @Log | ||
57 | @DeleteMapping(value = "/{id}") | ||
58 | @ApiOperation("删除TaskTemplate") | ||
59 | public ResultInfo delete(@PathVariable Long id) { | ||
60 | TaskTemplateService.delete(id); | ||
61 | return ResultInfo.success(); | ||
62 | } | ||
63 | |||
64 | @GetMapping(value = "/getByCode/{code}") | ||
65 | @ApiOperation(value = "根据标识查询") | ||
66 | public ResultInfo getByCode(@PathVariable String code) { | ||
67 | return ResultInfo.success(TaskTemplateService.getByCode(code)); | ||
68 | } | ||
69 | } |
src/main/java/com/topdraw/business/basicdata/task/template/service/TaskTemplateService.java
0 → 100644
1 | package com.topdraw.business.basicdata.task.template.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; | ||
4 | import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateDTO; | ||
5 | import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | |||
11 | /** | ||
12 | * @author XiangHan | ||
13 | * @date 2021-10-22 | ||
14 | */ | ||
15 | public interface TaskTemplateService { | ||
16 | |||
17 | /** | ||
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(TaskTemplateQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<TaskTemplateDTO> | ||
29 | */ | ||
30 | List<TaskTemplateDTO> queryAll(TaskTemplateQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | ||
34 | * @param id ID | ||
35 | * @return TaskTemplateDTO | ||
36 | */ | ||
37 | TaskTemplateDTO findById(Long id); | ||
38 | |||
39 | void create(TaskTemplate resources); | ||
40 | |||
41 | void update(TaskTemplate resources); | ||
42 | |||
43 | void delete(Long id); | ||
44 | |||
45 | /** | ||
46 | * Code校验 | ||
47 | * @param code | ||
48 | * @return TaskTemplateDTO | ||
49 | */ | ||
50 | TaskTemplateDTO getByCode(String code); | ||
51 | |||
52 | TaskTemplate findByEvent(String event); | ||
53 | } |
src/main/java/com/topdraw/business/basicdata/task/template/service/dto/TaskTemplateDTO.java
0 → 100644
1 | package com.topdraw.business.basicdata.task.template.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Data | ||
14 | public class TaskTemplateDTO implements Serializable { | ||
15 | |||
16 | private Long id; | ||
17 | |||
18 | // 标识 | ||
19 | private String code; | ||
20 | |||
21 | // 名称 | ||
22 | private String name; | ||
23 | |||
24 | // 关注事件(和MQ topic相关) | ||
25 | private String event; | ||
26 | |||
27 | // 描述 | ||
28 | private String description; | ||
29 | |||
30 | // 状态 0:失效;1:生效 | ||
31 | private Integer status; | ||
32 | |||
33 | // 类型 0:活动任务模板 | ||
34 | private Integer type; | ||
35 | |||
36 | // 模板参数,json | ||
37 | private String params; | ||
38 | |||
39 | private Timestamp createTime; | ||
40 | |||
41 | private Timestamp updateTime; | ||
42 | } |
src/main/java/com/topdraw/business/basicdata/task/template/service/impl/TaskTemplateServiceImpl.java
0 → 100644
1 | package com.topdraw.business.basicdata.task.template.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; | ||
4 | import com.topdraw.business.basicdata.task.template.repository.TaskTemplateRepository; | ||
5 | import com.topdraw.business.basicdata.task.template.service.TaskTemplateService; | ||
6 | import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateDTO; | ||
7 | import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateQueryCriteria; | ||
8 | import com.topdraw.business.basicdata.task.template.service.mapper.TaskTemplateMapper; | ||
9 | import com.topdraw.utils.PageUtil; | ||
10 | import com.topdraw.utils.QueryHelp; | ||
11 | import com.topdraw.utils.StringUtils; | ||
12 | import com.topdraw.utils.ValidationUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.springframework.util.Assert; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | |||
25 | /** | ||
26 | * @author XiangHan | ||
27 | * @date 2021-10-22 | ||
28 | */ | ||
29 | @Service | ||
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
31 | public class TaskTemplateServiceImpl implements TaskTemplateService { | ||
32 | |||
33 | @Autowired | ||
34 | private TaskTemplateRepository TaskTemplateRepository; | ||
35 | |||
36 | @Autowired | ||
37 | private TaskTemplateMapper TaskTemplateMapper; | ||
38 | |||
39 | @Override | ||
40 | public Map<String, Object> queryAll(TaskTemplateQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<TaskTemplate> page = TaskTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(TaskTemplateMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<TaskTemplateDTO> queryAll(TaskTemplateQueryCriteria criteria) { | ||
47 | return TaskTemplateMapper.toDto(TaskTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public TaskTemplateDTO findById(Long id) { | ||
52 | TaskTemplate TaskTemplate = TaskTemplateRepository.findById(id).orElseGet(TaskTemplate::new); | ||
53 | ValidationUtil.isNull(TaskTemplate.getId(),"TaskTemplate","id",id); | ||
54 | return TaskTemplateMapper.toDto(TaskTemplate); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void create(TaskTemplate resources) { | ||
60 | TaskTemplateRepository.save(resources); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void update(TaskTemplate resources) { | ||
66 | TaskTemplate TaskTemplate = TaskTemplateRepository.findById(resources.getId()).orElseGet(TaskTemplate::new); | ||
67 | ValidationUtil.isNull( TaskTemplate.getId(),"TaskTemplate","id",resources.getId()); | ||
68 | TaskTemplate.copy(resources); | ||
69 | TaskTemplateRepository.save(TaskTemplate); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | @Transactional(rollbackFor = Exception.class) | ||
74 | public void delete(Long id) { | ||
75 | Assert.notNull(id, "The given id must not be null!"); | ||
76 | TaskTemplate TaskTemplate = TaskTemplateRepository.findById(id).orElseThrow( | ||
77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", TaskTemplate.class, id), 1)); | ||
78 | TaskTemplateRepository.delete(TaskTemplate); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public TaskTemplateDTO getByCode(String code) { | ||
84 | return StringUtils.isNotEmpty(code) ? TaskTemplateMapper.toDto(TaskTemplateRepository.findFirstByCode(code).orElseGet(TaskTemplate::new)) | ||
85 | : new TaskTemplateDTO(); | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public TaskTemplate findByEvent(String event) { | ||
90 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; | ||
91 | } | ||
92 | } |
src/main/java/com/topdraw/business/basicdata/task/template/service/mapper/TaskTemplateMapper.java
0 → 100644
1 | package com.topdraw.business.basicdata.task.template.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; | ||
5 | import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-10-22 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface TaskTemplateMapper extends BaseMapper<TaskTemplateDTO, TaskTemplate> { | ||
15 | |||
16 | } |
1 | package com.topdraw.config; | ||
2 | |||
3 | public class LocalConstants { | ||
4 | |||
5 | // 小屏侧 | ||
6 | public static final String ENV_MOBILE = "mobile"; | ||
7 | |||
8 | // 大屏侧 | ||
9 | public static final String ENV_VIS = "vis"; | ||
10 | |||
11 | // 大屏类型 | ||
12 | public static final int DEVICE_VIS = 1; | ||
13 | |||
14 | // 小屏类型 | ||
15 | public static final int DEVICE_MOBILE = 2; | ||
16 | } |
1 | package com.topdraw.config; | ||
2 | |||
3 | import cn.hutool.core.util.ObjectUtil; | ||
4 | import org.springframework.beans.factory.annotation.Value; | ||
5 | import org.springframework.stereotype.Component; | ||
6 | |||
7 | @Component | ||
8 | public class ServiceEnvConfig { | ||
9 | |||
10 | // uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧 | ||
11 | public static String UC_SERVICE_TYPE; | ||
12 | |||
13 | @Value("${uc.service.type:mobile}") | ||
14 | public void setUcServiceType(String ucServiceType) { | ||
15 | UC_SERVICE_TYPE = ucServiceType; | ||
16 | } | ||
17 | |||
18 | public static boolean isMobile() { | ||
19 | return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_MOBILE); | ||
20 | } | ||
21 | |||
22 | public static boolean isVis() { | ||
23 | return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_VIS); | ||
24 | } | ||
25 | |||
26 | } |
1 | package com.topdraw.mq.config; | ||
2 | |||
3 | import org.springframework.amqp.core.*; | ||
4 | import org.springframework.beans.factory.annotation.Value; | ||
5 | import org.springframework.context.annotation.Bean; | ||
6 | import org.springframework.context.annotation.Configuration; | ||
7 | |||
8 | @Configuration | ||
9 | public class RabbitMqConfig { | ||
10 | |||
11 | /** 路由(事件)--direct route.key*/ | ||
12 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_AAA = "uc.route.key.direct.event.aaa"; | ||
13 | |||
14 | /** 队列-- */ | ||
15 | public static final String UC_QUEUE_FANOUT_IPTV = "uc.fanout.iptv"; | ||
16 | public static final String UC_QUEUE_FANOUT_WEIXIN = "uc.fanout.weixin"; | ||
17 | |||
18 | |||
19 | /** | ||
20 | * 处理事件 | ||
21 | * @return org.springframework.amqp.core.Queue | ||
22 | * @author XiangHan | ||
23 | * @date 2021/9/7 10:19 上午 | ||
24 | */ | ||
25 | @Bean | ||
26 | public Queue eventDirect() { | ||
27 | return new Queue(UC_ROUTE_KEY_DIRECT_EVENT_AAA); | ||
28 | } | ||
29 | } |
1 | package com.topdraw.mq.consumer; | ||
2 | |||
3 | import com.topdraw.mq.domain.TableOperationMsg; | ||
4 | import com.topdraw.util.JSONUtil; | ||
5 | import lombok.extern.slf4j.Slf4j; | ||
6 | import org.springframework.beans.factory.annotation.Autowired; | ||
7 | import org.springframework.context.ApplicationContext; | ||
8 | import org.springframework.stereotype.Component; | ||
9 | import org.springframework.util.ClassUtils; | ||
10 | |||
11 | import java.lang.reflect.InvocationTargetException; | ||
12 | import java.lang.reflect.Method; | ||
13 | |||
14 | @Component | ||
15 | @Slf4j | ||
16 | public class AutoRoute { | ||
17 | |||
18 | @Autowired | ||
19 | private ApplicationContext applicationContext; | ||
20 | |||
21 | public void route(TableOperationMsg tableOperationMsg) { | ||
22 | String interfaceName = tableOperationMsg.getInterfaceName(); | ||
23 | try { | ||
24 | String methodName = tableOperationMsg.getMethodName(); | ||
25 | |||
26 | ClassLoader defaultClassLoader = ClassUtils.getDefaultClassLoader(); | ||
27 | log.info("AutoRoute -->>> route -->> " + defaultClassLoader); | ||
28 | Class<?> aClass = defaultClassLoader.loadClass(tableOperationMsg.getEntityName()); | ||
29 | // Class<?> aClass = classLoader.loadClass(tableOperationMsg.getEntityName()); | ||
30 | log.info("AutoRoute -->>> route -->> " + aClass); | ||
31 | Class<?> serviceImpl = Class.forName(interfaceName); | ||
32 | Method[] declaredMethods = serviceImpl.getDeclaredMethods(); | ||
33 | for (Method declaredMethod : declaredMethods) { | ||
34 | declaredMethod.setAccessible(true); | ||
35 | String name = declaredMethod.getName(); | ||
36 | if (name.equalsIgnoreCase(methodName)) { | ||
37 | Class<?>[] parameterTypes = declaredMethod.getParameterTypes(); | ||
38 | Class<?> parameterType = parameterTypes[0]; | ||
39 | aClass = parameterType; | ||
40 | break; | ||
41 | } else { | ||
42 | continue; | ||
43 | } | ||
44 | } | ||
45 | String entityBody = tableOperationMsg.getEntityBody(); | ||
46 | Object o = JSONUtil.parseMsg2Object(entityBody, aClass.getConstructor().newInstance().getClass()); | ||
47 | Method method1 = serviceImpl.getDeclaredMethod(methodName, aClass); | ||
48 | method1.invoke(applicationContext.getBean(serviceImpl),o); | ||
49 | } catch (ClassNotFoundException e) { | ||
50 | e.printStackTrace(); | ||
51 | } catch (InvocationTargetException e) { | ||
52 | e.printStackTrace(); | ||
53 | } catch (InstantiationException e) { | ||
54 | e.printStackTrace(); | ||
55 | } catch (IllegalAccessException e) { | ||
56 | e.printStackTrace(); | ||
57 | } catch (NoSuchMethodException e) { | ||
58 | e.printStackTrace(); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | } |
1 | package com.topdraw.mq.consumer; | ||
2 | |||
3 | import com.topdraw.config.ServiceEnvConfig; | ||
4 | import com.topdraw.mq.config.RabbitMqConfig; | ||
5 | import com.topdraw.mq.domain.DataSyncMsg; | ||
6 | import com.topdraw.mq.domain.TableOperationMsg; | ||
7 | import com.topdraw.util.JSONUtil; | ||
8 | import lombok.extern.slf4j.Slf4j; | ||
9 | import org.slf4j.Logger; | ||
10 | import org.slf4j.LoggerFactory; | ||
11 | import org.springframework.amqp.core.ExchangeTypes; | ||
12 | import org.springframework.amqp.rabbit.annotation.*; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.stereotype.Component; | ||
15 | |||
16 | @Component | ||
17 | @Slf4j | ||
18 | public class MemberServiceConsumer { | ||
19 | |||
20 | private static final Logger LOG = LoggerFactory.getLogger(MemberServiceConsumer.class); | ||
21 | |||
22 | @Autowired | ||
23 | AutoRoute autoUser; | ||
24 | |||
25 | /** | ||
26 | * @param content | ||
27 | * @description 基础数据同步 | ||
28 | * @author Hongyan Wang | ||
29 | * @date 2021/9/7 11:26 上午 | ||
30 | */ | ||
31 | @RabbitHandler | ||
32 | @RabbitListener(queues = "#{memberServiceConsumer.platform()}") | ||
33 | public void memberServiceFanoutConsumer(String content) { | ||
34 | try { | ||
35 | log.info(" receive dataSync msg , content is : {} ", content); | ||
36 | TableOperationMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, TableOperationMsg.class); | ||
37 | autoUser.route(dataSyncMsg); | ||
38 | LOG.info("memberServiceFanoutConsumer ====>>>> "+dataSyncMsg); | ||
39 | } catch (Exception e) { | ||
40 | log.error(" LocalDataSyncMsg || msg:{} || error:{} ", content, e.getMessage()); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * @return java.lang.String | ||
46 | * @description 根据环境获取队列名称 | ||
47 | * @author Hongyan Wang | ||
48 | * @date 2021/9/8 4:00 下午 | ||
49 | */ | ||
50 | public String platform() { | ||
51 | String platform = ""; | ||
52 | if (ServiceEnvConfig.isMobile()) { | ||
53 | platform = RabbitMqConfig.UC_QUEUE_FANOUT_WEIXIN; | ||
54 | } else { | ||
55 | if (ServiceEnvConfig.isVis()) platform = RabbitMqConfig.UC_QUEUE_FANOUT_IPTV; | ||
56 | } | ||
57 | return platform; | ||
58 | } | ||
59 | } |
1 | package com.topdraw.mq.consumer; | ||
2 | |||
3 | import com.topdraw.mq.config.RabbitMqConfig; | ||
4 | import com.topdraw.mq.domain.DataSyncMsg; | ||
5 | import com.topdraw.resttemplate.RestTemplateClient; | ||
6 | import com.topdraw.util.JSONUtil; | ||
7 | import lombok.extern.slf4j.Slf4j; | ||
8 | import org.springframework.amqp.rabbit.annotation.*; | ||
9 | import org.springframework.beans.factory.annotation.Autowired; | ||
10 | import org.springframework.stereotype.Component; | ||
11 | import org.springframework.util.Assert; | ||
12 | |||
13 | @Component | ||
14 | @Slf4j | ||
15 | public class UserCenterConsumer { | ||
16 | |||
17 | @Autowired | ||
18 | RestTemplateClient restTemplateClient; | ||
19 | |||
20 | /** | ||
21 | * 事件 | ||
22 | * @param content | ||
23 | * @description 基础数据同步 | ||
24 | * @author Hongyan Wang | ||
25 | * @date 2021/9/7 11:26 上午 | ||
26 | */ | ||
27 | @RabbitHandler | ||
28 | @RabbitListener(queues = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_AAA) | ||
29 | public void ucEventConsumer(String content) { | ||
30 | log.info(" receive dataSync msg , content is : {} ", content); | ||
31 | DataSyncMsg dataSyncMsg = this.parseContent(content); | ||
32 | this.taskDeal(dataSyncMsg); | ||
33 | log.info("ucEventConsumer ====>>>> end"); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * 数据解析 | ||
38 | * @param content | ||
39 | * @return | ||
40 | */ | ||
41 | private DataSyncMsg parseContent(String content) { | ||
42 | DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content,DataSyncMsg.class); | ||
43 | Assert.notNull(dataSyncMsg,"ERROR -->> operationConsumer -->> parseContent -->> 【dataSyncMsg】 not be null !!"); | ||
44 | DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg(); | ||
45 | Assert.notNull(msgData,"ERROR -->> operationConsumer -->> parseContent -->> 【msgData】 not be null !!"); | ||
46 | return dataSyncMsg; | ||
47 | } | ||
48 | |||
49 | /** | ||
50 | * 任务处理 | ||
51 | * @param dataSyncMsg | ||
52 | */ | ||
53 | private void taskDeal(DataSyncMsg dataSyncMsg) { | ||
54 | this.restTemplateClient.dealTask(dataSyncMsg); | ||
55 | } | ||
56 | } |
1 | package com.topdraw.mq.domain; | ||
2 | |||
3 | import lombok.AllArgsConstructor; | ||
4 | import lombok.Data; | ||
5 | import lombok.NoArgsConstructor; | ||
6 | |||
7 | import javax.validation.constraints.NotNull; | ||
8 | import java.io.Serializable; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | */ | ||
13 | @Data | ||
14 | @AllArgsConstructor | ||
15 | @NoArgsConstructor | ||
16 | public class DataSyncMsg implements Serializable { | ||
17 | |||
18 | // 实体类型(表示需要修改的数据模型) | ||
19 | // @NotNull | ||
20 | // private EntityType entityType; | ||
21 | |||
22 | // 事件类型(用户的实际操作) | ||
23 | @NotNull | ||
24 | private String eventType; | ||
25 | |||
26 | // 消息体 | ||
27 | private MsgData msg; | ||
28 | |||
29 | // 其他属性 | ||
30 | private String extraData; | ||
31 | |||
32 | |||
33 | /** | ||
34 | * 消息体 | ||
35 | */ | ||
36 | @Data | ||
37 | @AllArgsConstructor | ||
38 | @NoArgsConstructor | ||
39 | public static class MsgData { | ||
40 | private String remarks; //备注 | ||
41 | @NotNull | ||
42 | private Integer event; // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他 | ||
43 | @NotNull | ||
44 | private Long memberId; // 会员id | ||
45 | @NotNull | ||
46 | private Integer deviceType; //设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
47 | @NotNull | ||
48 | private String appCode; //用户对应的应用code | ||
49 | private Long accountId; // 账号id | ||
50 | private Long orderId; | ||
51 | private Long activityId; | ||
52 | private Long mediaId; | ||
53 | private Long itemId; | ||
54 | } | ||
55 | |||
56 | } |
1 | package com.topdraw.mq.domain; | ||
2 | |||
3 | import lombok.AllArgsConstructor; | ||
4 | import lombok.Data; | ||
5 | import lombok.NoArgsConstructor; | ||
6 | |||
7 | /** | ||
8 | * | ||
9 | */ | ||
10 | @Data | ||
11 | @AllArgsConstructor | ||
12 | @NoArgsConstructor | ||
13 | public class TableOperationMsg { | ||
14 | |||
15 | // 数据表操作类型 | ||
16 | private TableOperationType tableOperationType; | ||
17 | |||
18 | // 模型名称 | ||
19 | private String entityName; | ||
20 | |||
21 | // 消息体 | ||
22 | private String entityBody; | ||
23 | |||
24 | private String interfaceName; | ||
25 | private String methodName; | ||
26 | } |
1 | package com.topdraw.resttemplate; | ||
2 | |||
3 | import com.alibaba.fastjson.JSON; | ||
4 | import com.alibaba.fastjson.JSONObject; | ||
5 | import com.topdraw.business.basicdata.member.address.domain.MemberAddress; | ||
6 | import com.topdraw.business.basicdata.member.domain.Member; | ||
7 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; | ||
8 | import com.topdraw.mq.domain.DataSyncMsg; | ||
9 | import lombok.extern.slf4j.Slf4j; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.core.env.Environment; | ||
12 | import org.springframework.http.ResponseEntity; | ||
13 | import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
14 | import org.springframework.stereotype.Component; | ||
15 | import org.springframework.web.client.RestTemplate; | ||
16 | |||
17 | import javax.annotation.PostConstruct; | ||
18 | import java.util.HashMap; | ||
19 | import java.util.Map; | ||
20 | |||
21 | @Slf4j | ||
22 | @Component | ||
23 | public class RestTemplateClient { | ||
24 | |||
25 | private static RestTemplate restTemplate; | ||
26 | |||
27 | private static String BASE_URL; | ||
28 | |||
29 | @Autowired | ||
30 | private Environment environment; | ||
31 | |||
32 | @PostConstruct | ||
33 | private void init() { | ||
34 | BASE_URL = environment.getProperty("api.baseUrl"); | ||
35 | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); | ||
36 | // 设置连接超时 | ||
37 | factory.setConnectTimeout(5000); | ||
38 | // 设置读取超时 | ||
39 | factory.setReadTimeout(8000); | ||
40 | restTemplate = new RestTemplate(factory); | ||
41 | } | ||
42 | |||
43 | public JSONObject dealTask(DataSyncMsg dataSyncMsg) { | ||
44 | JSONObject resultSet = null; | ||
45 | String url = BASE_URL + "/api/TaskOperation/dealTask"; | ||
46 | log.info("request uc : url is " + url + ", dataSyncMsg is " + dataSyncMsg); | ||
47 | String content = JSON.toJSONString(dataSyncMsg); | ||
48 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); | ||
49 | objectObjectHashMap.put("content", content); | ||
50 | restTemplate.postForEntity(url, objectObjectHashMap, String.class); | ||
51 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, objectObjectHashMap, String.class); | ||
52 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
53 | String entityBody = responseEntity.getBody(); | ||
54 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
55 | if (jsonObject.getInteger("businessCode").equals(200)) { | ||
56 | resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0); | ||
57 | } | ||
58 | } | ||
59 | log.info("uc response: " + resultSet.toJSONString()); | ||
60 | return resultSet;*/ | ||
61 | return null; | ||
62 | } | ||
63 | |||
64 | public JSONObject getMemberInfo(Long memberId) { | ||
65 | JSONObject resultSet = null; | ||
66 | String url = BASE_URL + "/api/member/findById/" + memberId; | ||
67 | log.info("request uc : url is " + url + ", memberId is " + memberId); | ||
68 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
69 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
70 | String entityBody = responseEntity.getBody(); | ||
71 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
72 | if (jsonObject.getInteger("businessCode").equals(200)) { | ||
73 | resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0); | ||
74 | } | ||
75 | } | ||
76 | log.info("uc response: " + resultSet.toJSONString()); | ||
77 | return resultSet; | ||
78 | } | ||
79 | |||
80 | public String createMember(Member member) { | ||
81 | String entityBody = ""; | ||
82 | String url = BASE_URL + "/api/member/create"; | ||
83 | log.info("request uc : url is " + url + ", memberId is " + JSONObject.toJSONString(member)); | ||
84 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class); | ||
85 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
86 | entityBody = responseEntity.getBody(); | ||
87 | |||
88 | } | ||
89 | return entityBody; | ||
90 | } | ||
91 | |||
92 | public String updateMember(Member member) { | ||
93 | String entityBody = ""; | ||
94 | String url = BASE_URL + "/api/member/update"; | ||
95 | log.info("request uc : url is " + url + ", memberId is " + JSONObject.toJSONString(member)); | ||
96 | restTemplate.put(url, member); | ||
97 | |||
98 | return entityBody; | ||
99 | } | ||
100 | |||
101 | public String createMemberAddress(MemberAddress member) { | ||
102 | JSONObject resultSet = null; | ||
103 | String url = BASE_URL + "/api/MemberAddress/create"; | ||
104 | log.info("request uc : url is " + url + ", memberId is " + JSONObject.toJSONString(member)); | ||
105 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class); | ||
106 | String entityBody = ""; | ||
107 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
108 | entityBody = responseEntity.getBody(); | ||
109 | } | ||
110 | log.info("uc response: " + entityBody); | ||
111 | return entityBody; | ||
112 | } | ||
113 | |||
114 | public void updateMemberAddress(MemberAddress member) { | ||
115 | String url = BASE_URL + "/api/MemberAddress/update"; | ||
116 | log.info("request uc : url is " + url + ", memberId is " + JSONObject.toJSONString(member)); | ||
117 | restTemplate.put(url, member); | ||
118 | |||
119 | } | ||
120 | |||
121 | public void deleteMemberAddress(Long id) { | ||
122 | String url = BASE_URL + "/api/MemberAddress/delete/" + id; | ||
123 | log.info("request uc : url is " + url + ", memberId is " + id); | ||
124 | restTemplate.delete(url); | ||
125 | |||
126 | } | ||
127 | |||
128 | public JSONObject getMemberProfile(Long memberId) { | ||
129 | JSONObject resultSet = null; | ||
130 | String url = BASE_URL + "/api/MemberRelatedInfo/getMemberRelatedInfos"; | ||
131 | log.info("request uc : url is " + url + ", memberId is " + memberId); | ||
132 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
133 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
134 | String entityBody = responseEntity.getBody(); | ||
135 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
136 | if (jsonObject.getInteger("businessCode").equals(200)) { | ||
137 | resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0); | ||
138 | } | ||
139 | } | ||
140 | log.info("uc response: " + resultSet.toJSONString()); | ||
141 | return resultSet; | ||
142 | } | ||
143 | |||
144 | public String getMemberAddress(Map<String, Object> param) { | ||
145 | String entityBody = ""; | ||
146 | String url = BASE_URL + "/api/MemberAddress/pageMemberAddress?page=" + param.get("page") + "&size=" + param.get("size") + "&memberId=" + param.get("memberId"); | ||
147 | log.info("request uc : url is " + url + ", param is " + param); | ||
148 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
149 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
150 | entityBody = responseEntity.getBody(); | ||
151 | } | ||
152 | log.info("uc response: " + entityBody); | ||
153 | return entityBody; | ||
154 | } | ||
155 | |||
156 | public String getMemberRelatedInfo(Map<String, Object> param) { | ||
157 | String entityBody = ""; | ||
158 | String url = BASE_URL + "/api/MemberRelatedInfo/pageMemberRelatedInfos?page=" + param.get("page") + "&size=" + param.get("size") + "&memberId=" + param.get("memberId"); | ||
159 | log.info("request uc : url is " + url + ", memberId is " + param); | ||
160 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
161 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
162 | entityBody = responseEntity.getBody(); | ||
163 | } | ||
164 | log.info("uc response: " + entityBody); | ||
165 | return entityBody; | ||
166 | } | ||
167 | |||
168 | public void deleteMemberRelatedInfo(Long memberRelatedId) { | ||
169 | String url = BASE_URL + "/api/MemberRelatedInfo/delete/" + memberRelatedId; | ||
170 | log.info("request uc : url is " + url + ", memberId is " + memberRelatedId); | ||
171 | restTemplate.delete(url, String.class); | ||
172 | } | ||
173 | |||
174 | public String addMemberRelatedInfo(MemberRelatedInfo resources) { | ||
175 | String entityBody = null; | ||
176 | String url = BASE_URL + "/api/MemberRelatedInfo/create"; | ||
177 | log.info("request uc : url is " + url + ", memberRelatedId is " + JSONObject.toJSONString(resources)); | ||
178 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, resources, String.class); | ||
179 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
180 | entityBody = responseEntity.getBody(); | ||
181 | // JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
182 | // if (jsonObject.getInteger("businessCode").equals(200)) { | ||
183 | // resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0); | ||
184 | // } | ||
185 | } | ||
186 | log.info("uc response: " + entityBody); | ||
187 | return entityBody; | ||
188 | } | ||
189 | |||
190 | public String updateMemberRelatedInfo(MemberRelatedInfo resources) { | ||
191 | String resultSet = ""; | ||
192 | String url = BASE_URL + "/api/MemberRelatedInfo/update"; | ||
193 | log.info("request uc : url is " + url + ", memberRelatedId is " + JSONObject.toJSONString(resources)); | ||
194 | restTemplate.put(url, resources); | ||
195 | |||
196 | return resultSet; | ||
197 | } | ||
198 | } |
src/main/java/com/topdraw/util/DateUtil.java
0 → 100644
src/main/java/com/topdraw/util/IdWorker.java
0 → 100644
1 | package com.topdraw.util; | ||
2 | |||
3 | import org.slf4j.Logger; | ||
4 | import org.slf4j.LoggerFactory; | ||
5 | |||
6 | import java.lang.management.ManagementFactory; | ||
7 | import java.net.InetAddress; | ||
8 | import java.net.NetworkInterface; | ||
9 | |||
10 | /** | ||
11 | * 生成订单ID, 雪花算法代码实现 | ||
12 | */ | ||
13 | public class IdWorker { | ||
14 | private static final Logger LOG = LoggerFactory.getLogger(IdWorker.class.getName()); | ||
15 | // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) | ||
16 | private final static long twepoch = 1288834974657L; | ||
17 | // 机器标识位数 | ||
18 | private final static long workerIdBits = 5L; | ||
19 | // 数据中心标识位数 | ||
20 | private final static long datacenterIdBits = 5L; | ||
21 | // 机器ID最大值 | ||
22 | private final static long maxWorkerId = -1L ^ (-1L << workerIdBits); | ||
23 | // 数据中心ID最大值 | ||
24 | private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); | ||
25 | // 毫秒内自增位 | ||
26 | private final static long sequenceBits = 12L; | ||
27 | // 机器ID偏左移12位 | ||
28 | private final static long workerIdShift = sequenceBits; | ||
29 | // 数据中心ID左移17位 | ||
30 | private final static long datacenterIdShift = sequenceBits + workerIdBits; | ||
31 | // 时间毫秒左移22位 | ||
32 | private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits; | ||
33 | |||
34 | private final static long sequenceMask = -1L ^ (-1L << sequenceBits); | ||
35 | /* 上次生产id时间戳 */ | ||
36 | private static long lastTimestamp = -1L; | ||
37 | // 0,并发控制 | ||
38 | private long sequence = 0L; | ||
39 | |||
40 | private final long workerId; | ||
41 | // 数据标识id部分 | ||
42 | private final long datacenterId; | ||
43 | |||
44 | public IdWorker(){ | ||
45 | this.datacenterId = getDatacenterId(maxDatacenterId); | ||
46 | this.workerId = getMaxWorkerId(datacenterId, maxWorkerId); | ||
47 | } | ||
48 | /** | ||
49 | * @param workerId 工作机器ID | ||
50 | * @param datacenterId 序列号 | ||
51 | */ | ||
52 | public IdWorker(long workerId, long datacenterId) { | ||
53 | if (workerId > maxWorkerId || workerId < 0) { | ||
54 | throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId)); | ||
55 | } | ||
56 | if (datacenterId > maxDatacenterId || datacenterId < 0) { | ||
57 | throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId)); | ||
58 | } | ||
59 | this.workerId = workerId; | ||
60 | this.datacenterId = datacenterId; | ||
61 | } | ||
62 | /** | ||
63 | * 获取下一个ID | ||
64 | * @return | ||
65 | */ | ||
66 | public synchronized long nextId() { | ||
67 | long timestamp = timeGen(); | ||
68 | if (timestamp < lastTimestamp) { | ||
69 | throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); | ||
70 | } | ||
71 | |||
72 | if (lastTimestamp == timestamp) { | ||
73 | // 当前毫秒内,则+1 | ||
74 | sequence = (sequence + 1) & sequenceMask; | ||
75 | if (sequence == 0) { | ||
76 | // 当前毫秒内计数满了,则等待下一秒 | ||
77 | timestamp = tilNextMillis(lastTimestamp); | ||
78 | } | ||
79 | } else { | ||
80 | sequence = 0L; | ||
81 | } | ||
82 | lastTimestamp = timestamp; | ||
83 | // ID偏移组合生成最终的ID,并返回ID | ||
84 | long nextId = ((timestamp - twepoch) << timestampLeftShift) | ||
85 | | (datacenterId << datacenterIdShift) | ||
86 | | (workerId << workerIdShift) | sequence; | ||
87 | |||
88 | return nextId; | ||
89 | } | ||
90 | |||
91 | private long tilNextMillis(final long lastTimestamp) { | ||
92 | long timestamp = this.timeGen(); | ||
93 | while (timestamp <= lastTimestamp) { | ||
94 | timestamp = this.timeGen(); | ||
95 | } | ||
96 | return timestamp; | ||
97 | } | ||
98 | |||
99 | private long timeGen() { | ||
100 | return System.currentTimeMillis(); | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * 获取 maxWorkerId | ||
105 | */ | ||
106 | protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) { | ||
107 | StringBuffer mpid = new StringBuffer(); | ||
108 | mpid.append(datacenterId); | ||
109 | String name = ManagementFactory.getRuntimeMXBean().getName(); | ||
110 | if (!name.isEmpty()) { | ||
111 | /* | ||
112 | * GET jvmPid | ||
113 | */ | ||
114 | mpid.append(name.split("@")[0]); | ||
115 | } | ||
116 | /* | ||
117 | * MAC + PID 的 hashcode 获取16个低位 | ||
118 | */ | ||
119 | return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1); | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * 数据标识id部分 | ||
124 | */ | ||
125 | protected static long getDatacenterId(long maxDatacenterId) { | ||
126 | long id = 0L; | ||
127 | try { | ||
128 | InetAddress ip = InetAddress.getLocalHost(); | ||
129 | NetworkInterface network = NetworkInterface.getByInetAddress(ip); | ||
130 | if (network == null) { | ||
131 | id = 1L; | ||
132 | } else { | ||
133 | byte[] mac = network.getHardwareAddress(); | ||
134 | if (null == mac) { | ||
135 | return 1L; | ||
136 | } | ||
137 | id = ((0x000000FF & (long) mac[mac.length - 1]) | ||
138 | | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6; | ||
139 | id = id % (maxDatacenterId + 1); | ||
140 | } | ||
141 | } catch (Exception e) { | ||
142 | LOG.warn(" getDatacenterId: " + e.getMessage()); | ||
143 | } | ||
144 | return id; | ||
145 | } | ||
146 | |||
147 | public static long generator(){ | ||
148 | IdWorker idWorker = new IdWorker(); | ||
149 | return idWorker.nextId(); | ||
150 | } | ||
151 | |||
152 | public static void main(String[] args) { | ||
153 | IdWorker idWorker = new IdWorker(); | ||
154 | System.out.println(idWorker.nextId()); | ||
155 | } | ||
156 | } |
src/main/java/com/topdraw/util/JSONUtil.java
0 → 100644
1 | package com.topdraw.util; | ||
2 | |||
3 | import java.util.Random; | ||
4 | |||
5 | public class RandomUtil { | ||
6 | |||
7 | /** | ||
8 | * 获取随机积分 | ||
9 | * @param max | ||
10 | * @param min | ||
11 | * @return | ||
12 | */ | ||
13 | public static long getRandomPoints(Integer min,Integer max) { | ||
14 | Random random = new Random(); | ||
15 | int s = random.nextInt(max)%(max-min+1) + min; | ||
16 | return s; | ||
17 | } | ||
18 | |||
19 | public static void main(String[] args) { | ||
20 | for (int i=0;i<30;i++) { | ||
21 | long randomPoints = getRandomPoints(1, 10); | ||
22 | System.out.println(randomPoints); | ||
23 | } | ||
24 | |||
25 | } | ||
26 | |||
27 | } |
1 | package com.topdraw.util; | ||
2 | |||
3 | import java.sql.Timestamp; | ||
4 | import java.time.Instant; | ||
5 | import java.time.LocalDateTime; | ||
6 | import java.time.ZoneOffset; | ||
7 | |||
8 | public class TimestampUtil { | ||
9 | |||
10 | public static Timestamp now(){ | ||
11 | return new Timestamp(System.currentTimeMillis()); | ||
12 | } | ||
13 | |||
14 | public static Timestamp now(LocalDateTime localDateTime) { | ||
15 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).getEpochSecond(); | ||
16 | return new Timestamp(epochSecond); | ||
17 | } | ||
18 | |||
19 | public static long localDateTime2Timestamp(LocalDateTime localDateTime){ | ||
20 | long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond(); | ||
21 | return epochSecond; | ||
22 | } | ||
23 | |||
24 | public static Timestamp long2Timestamp(long timestamp){ | ||
25 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp)); | ||
26 | return timestamp1; | ||
27 | } | ||
28 | |||
29 | public static long Timestamp2long(Timestamp timestamp){ | ||
30 | return timestamp.toInstant().getEpochSecond(); | ||
31 | } | ||
32 | |||
33 | public static void main(String[] args) { | ||
34 | LocalDateTime of = LocalDateTime.of(2021, 10, 28, 11, 00, 00); | ||
35 | long l = localDateTime2Timestamp(of); | ||
36 | Timestamp timestamp = long2Timestamp(l); | ||
37 | System.out.println(timestamp.toString()); | ||
38 | } | ||
39 | } |
src/main/resources/banner.txt
0 → 100644
1 | #配置数据源 | ||
2 | spring: | ||
3 | datasource: | ||
4 | # 测试/演示库 | ||
5 | #url: jdbc:log4jdbc:mysql://139.196.37.202:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
6 | #username: root | ||
7 | #password: Topdraw1qaz | ||
8 | url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
9 | username: root | ||
10 | password: root | ||
11 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | ||
12 | # driverClassName: com.mysql.jdbc.Driver | ||
13 | #Druid | ||
14 | type: com.alibaba.druid.pool.DruidDataSource | ||
15 | druid: | ||
16 | # 初始化配置 | ||
17 | initial-size: 3 | ||
18 | # 最小连接数 | ||
19 | min-idle: 3 | ||
20 | # 最大连接数 | ||
21 | max-active: 15 | ||
22 | # 获取连接超时时间 | ||
23 | max-wait: 5000 | ||
24 | # 连接有效性检测时间 | ||
25 | time-between-eviction-runs-millis: 90000 | ||
26 | # 最大空闲时间 | ||
27 | min-evictable-idle-time-millis: 1800000 | ||
28 | test-while-idle: true | ||
29 | test-on-borrow: false | ||
30 | test-on-return: false | ||
31 | |||
32 | validation-query: select 1 | ||
33 | # 配置监控统计拦截的filters | ||
34 | filters: stat | ||
35 | stat-view-servlet: | ||
36 | url-pattern: /druid/* | ||
37 | reset-enable: false | ||
38 | |||
39 | web-stat-filter: | ||
40 | url-pattern: /* | ||
41 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" | ||
42 | |||
43 | #配置 Jpa | ||
44 | jpa: | ||
45 | hibernate: | ||
46 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 | ||
47 | ddl-auto: none | ||
48 | servlet: | ||
49 | multipart: | ||
50 | file-size-threshold: 2KB | ||
51 | max-file-size: 100MB | ||
52 | max-request-size: 200MB | ||
53 | redis: | ||
54 | #数据库索引 | ||
55 | database: 6 | ||
56 | host: 127.0.0.1 | ||
57 | port: 6379 | ||
58 | password: | ||
59 | #连接超时时间 | ||
60 | timeout: 5000 | ||
61 | rabbitmq: | ||
62 | host: 122.112.214.149 # rabbitmq的连接地址 | ||
63 | #host: 139.196.192.242 # rabbitmq的连接地址 | ||
64 | port: 5672 # rabbitmq的连接端口号 | ||
65 | #virtual-host: /member_center # rabbitmq的虚拟host | ||
66 | #username: member_center # rabbitmq的用户名 | ||
67 | #password: Tjlh@2021 # rabbitmq的密码 | ||
68 | virtual-host: / # rabbitmq的虚拟host | ||
69 | username: guest # rabbitmq的用户名 | ||
70 | password: guest # rabbitmq的密码 | ||
71 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
72 | |||
73 | #jwt。依赖的common中有需要jwt的部分属性。 | ||
74 | jwt: | ||
75 | header: Authorization | ||
76 | secret: mySecret | ||
77 | # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒 | ||
78 | expiration: 7200000 | ||
79 | # 在线用户key | ||
80 | online: online-token | ||
81 | # 验证码 | ||
82 | codeKey: code-key | ||
83 | # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 | ||
84 | detect: 3600000 | ||
85 | # 续期时间,2小时,单位毫秒 | ||
86 | renew: 7200000 | ||
87 | |||
88 | #是否允许生成代码,生产环境设置为false | ||
89 | generator: | ||
90 | enabled: true | ||
91 | |||
92 | #是否开启 swagger-ui | ||
93 | swagger: | ||
94 | enabled: true | ||
95 | |||
96 | # 文件存储路径(相对路径) | ||
97 | file: | ||
98 | path: system/file | ||
99 | avatar: system/avatar | ||
100 | upload: upload | ||
101 | # 文件大小 /M | ||
102 | maxSize: 100 | ||
103 | avatarMaxSize: 5 | ||
104 | |||
105 | uc: | ||
106 | service: | ||
107 | # uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧 | ||
108 | type: mobile | ||
109 | |||
110 | api: | ||
111 | # baseUrl: http://139.196.4.234:8447 | ||
112 | baseUrl: http://localhost:8447 |
1 | #配置数据源 | ||
2 | spring: | ||
3 | datasource: | ||
4 | # 测试/演示库 | ||
5 | #url: jdbc:log4jdbc:mysql://139.196.37.202:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
6 | #username: root | ||
7 | #password: Topdraw1qaz | ||
8 | url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
9 | username: root | ||
10 | password: root | ||
11 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | ||
12 | # driverClassName: com.mysql.jdbc.Driver | ||
13 | #Druid | ||
14 | type: com.alibaba.druid.pool.DruidDataSource | ||
15 | druid: | ||
16 | # 初始化配置 | ||
17 | initial-size: 3 | ||
18 | # 最小连接数 | ||
19 | min-idle: 3 | ||
20 | # 最大连接数 | ||
21 | max-active: 15 | ||
22 | # 获取连接超时时间 | ||
23 | max-wait: 5000 | ||
24 | # 连接有效性检测时间 | ||
25 | time-between-eviction-runs-millis: 90000 | ||
26 | # 最大空闲时间 | ||
27 | min-evictable-idle-time-millis: 1800000 | ||
28 | test-while-idle: true | ||
29 | test-on-borrow: false | ||
30 | test-on-return: false | ||
31 | |||
32 | validation-query: select 1 | ||
33 | # 配置监控统计拦截的filters | ||
34 | filters: stat | ||
35 | stat-view-servlet: | ||
36 | url-pattern: /druid/* | ||
37 | reset-enable: false | ||
38 | |||
39 | web-stat-filter: | ||
40 | url-pattern: /* | ||
41 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" | ||
42 | |||
43 | #配置 Jpa | ||
44 | jpa: | ||
45 | hibernate: | ||
46 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 | ||
47 | ddl-auto: none | ||
48 | servlet: | ||
49 | multipart: | ||
50 | file-size-threshold: 2KB | ||
51 | max-file-size: 100MB | ||
52 | max-request-size: 200MB | ||
53 | redis: | ||
54 | #数据库索引 | ||
55 | database: 6 | ||
56 | host: 127.0.0.1 | ||
57 | port: 6379 | ||
58 | password: | ||
59 | #连接超时时间 | ||
60 | timeout: 5000 | ||
61 | rabbitmq: | ||
62 | host: 122.112.214.149 # rabbitmq的连接地址 | ||
63 | #host: 139.196.192.242 # rabbitmq的连接地址 | ||
64 | port: 5672 # rabbitmq的连接端口号 | ||
65 | #virtual-host: /member_center # rabbitmq的虚拟host | ||
66 | #username: member_center # rabbitmq的用户名 | ||
67 | #password: Tjlh@2021 # rabbitmq的密码 | ||
68 | virtual-host: / # rabbitmq的虚拟host | ||
69 | username: guest # rabbitmq的用户名 | ||
70 | password: guest # rabbitmq的密码 | ||
71 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
72 | |||
73 | #jwt。依赖的common中有需要jwt的部分属性。 | ||
74 | jwt: | ||
75 | header: Authorization | ||
76 | secret: mySecret | ||
77 | # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒 | ||
78 | expiration: 7200000 | ||
79 | # 在线用户key | ||
80 | online: online-token | ||
81 | # 验证码 | ||
82 | codeKey: code-key | ||
83 | # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 | ||
84 | detect: 3600000 | ||
85 | # 续期时间,2小时,单位毫秒 | ||
86 | renew: 7200000 | ||
87 | |||
88 | #是否允许生成代码,生产环境设置为false | ||
89 | generator: | ||
90 | enabled: true | ||
91 | |||
92 | #是否开启 swagger-ui | ||
93 | swagger: | ||
94 | enabled: true | ||
95 | |||
96 | # 文件存储路径(相对路径) | ||
97 | file: | ||
98 | path: system/file | ||
99 | avatar: system/avatar | ||
100 | upload: upload | ||
101 | # 文件大小 /M | ||
102 | maxSize: 100 | ||
103 | avatarMaxSize: 5 | ||
104 | |||
105 | uc: | ||
106 | service: | ||
107 | # uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧 | ||
108 | type: mobile | ||
109 | |||
110 | api: | ||
111 | # baseUrl: http://139.196.4.234:8447 | ||
112 | baseUrl: http://localhost:8447 |
1 | #配置数据源 | ||
2 | spring: | ||
3 | datasource: | ||
4 | # 测试/演示库 | ||
5 | #url: jdbc:log4jdbc:mysql://139.196.37.202:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
6 | #username: root | ||
7 | #password: Topdraw1qaz | ||
8 | url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
9 | username: root | ||
10 | password: root | ||
11 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | ||
12 | # driverClassName: com.mysql.jdbc.Driver | ||
13 | #Druid | ||
14 | type: com.alibaba.druid.pool.DruidDataSource | ||
15 | druid: | ||
16 | # 初始化配置 | ||
17 | initial-size: 3 | ||
18 | # 最小连接数 | ||
19 | min-idle: 3 | ||
20 | # 最大连接数 | ||
21 | max-active: 15 | ||
22 | # 获取连接超时时间 | ||
23 | max-wait: 5000 | ||
24 | # 连接有效性检测时间 | ||
25 | time-between-eviction-runs-millis: 90000 | ||
26 | # 最大空闲时间 | ||
27 | min-evictable-idle-time-millis: 1800000 | ||
28 | test-while-idle: true | ||
29 | test-on-borrow: false | ||
30 | test-on-return: false | ||
31 | |||
32 | validation-query: select 1 | ||
33 | # 配置监控统计拦截的filters | ||
34 | filters: stat | ||
35 | stat-view-servlet: | ||
36 | url-pattern: /druid/* | ||
37 | reset-enable: false | ||
38 | |||
39 | web-stat-filter: | ||
40 | url-pattern: /* | ||
41 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" | ||
42 | |||
43 | #配置 Jpa | ||
44 | jpa: | ||
45 | hibernate: | ||
46 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 | ||
47 | ddl-auto: none | ||
48 | servlet: | ||
49 | multipart: | ||
50 | file-size-threshold: 2KB | ||
51 | max-file-size: 100MB | ||
52 | max-request-size: 200MB | ||
53 | redis: | ||
54 | #数据库索引 | ||
55 | database: 6 | ||
56 | host: 127.0.0.1 | ||
57 | port: 6379 | ||
58 | password: | ||
59 | #连接超时时间 | ||
60 | timeout: 5000 | ||
61 | rabbitmq: | ||
62 | host: 122.112.214.149 # rabbitmq的连接地址 | ||
63 | #host: 139.196.192.242 # rabbitmq的连接地址 | ||
64 | port: 5672 # rabbitmq的连接端口号 | ||
65 | #virtual-host: /member_center # rabbitmq的虚拟host | ||
66 | #username: member_center # rabbitmq的用户名 | ||
67 | #password: Tjlh@2021 # rabbitmq的密码 | ||
68 | virtual-host: / # rabbitmq的虚拟host | ||
69 | username: guest # rabbitmq的用户名 | ||
70 | password: guest # rabbitmq的密码 | ||
71 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
72 | |||
73 | #jwt。依赖的common中有需要jwt的部分属性。 | ||
74 | jwt: | ||
75 | header: Authorization | ||
76 | secret: mySecret | ||
77 | # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒 | ||
78 | expiration: 7200000 | ||
79 | # 在线用户key | ||
80 | online: online-token | ||
81 | # 验证码 | ||
82 | codeKey: code-key | ||
83 | # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 | ||
84 | detect: 3600000 | ||
85 | # 续期时间,2小时,单位毫秒 | ||
86 | renew: 7200000 | ||
87 | |||
88 | #是否允许生成代码,生产环境设置为false | ||
89 | generator: | ||
90 | enabled: true | ||
91 | |||
92 | #是否开启 swagger-ui | ||
93 | swagger: | ||
94 | enabled: true | ||
95 | |||
96 | # 文件存储路径(相对路径) | ||
97 | file: | ||
98 | path: system/file | ||
99 | avatar: system/avatar | ||
100 | upload: upload | ||
101 | # 文件大小 /M | ||
102 | maxSize: 100 | ||
103 | avatarMaxSize: 5 | ||
104 | |||
105 | uc: | ||
106 | service: | ||
107 | # uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧 | ||
108 | type: mobile | ||
109 | |||
110 | api: | ||
111 | # baseUrl: http://139.196.4.234:8447 | ||
112 | baseUrl: http://localhost:8447 |
src/main/resources/config/application.yml
0 → 100644
1 | server: | ||
2 | port: 8449 | ||
3 | |||
4 | spring: | ||
5 | application: | ||
6 | name: member-engine | ||
7 | freemarker: | ||
8 | check-template-location: false | ||
9 | profiles: | ||
10 | active: dev | ||
11 | jackson: | ||
12 | time-zone: GMT+8 | ||
13 | data: | ||
14 | redis: | ||
15 | repositories: | ||
16 | enabled: false | ||
17 | |||
18 | #配置 Jpa | ||
19 | jpa: | ||
20 | properties: | ||
21 | hibernate: | ||
22 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect | ||
23 | open-in-view: true | ||
24 | |||
25 | |||
26 | task: | ||
27 | pool: | ||
28 | # 核心线程池大小 | ||
29 | core-pool-size: 10 | ||
30 | # 最大线程数 | ||
31 | max-pool-size: 30 | ||
32 | # 活跃时间 | ||
33 | keep-alive-seconds: 60 | ||
34 | # 队列容量 | ||
35 | queue-capacity: 50 | ||
36 | |||
37 | #登录图形验证码有效时间/分钟 | ||
38 | loginCode: | ||
39 | expiration: 2 | ||
40 | |||
41 | #默认上传图片类型 | ||
42 | default-image-type: -1 |
src/main/resources/generator.properties
0 → 100644
1 | #数据库类型转Java类型 | ||
2 | tinyint=Integer | ||
3 | smallint=Integer | ||
4 | mediumint=Integer | ||
5 | int=Integer | ||
6 | integer=Integer | ||
7 | |||
8 | bigint=Long | ||
9 | |||
10 | float=Float | ||
11 | |||
12 | double=Double | ||
13 | |||
14 | decimal=BigDecimal | ||
15 | |||
16 | bit=Boolean | ||
17 | |||
18 | char=String | ||
19 | varchar=String | ||
20 | tinytext=String | ||
21 | text=String | ||
22 | mediumtext=String | ||
23 | longtext=String | ||
24 | |||
25 | date=Timestamp | ||
26 | datetime=Timestamp | ||
27 | timestamp=Timestamp |
1 | # If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger | ||
2 | log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator | ||
3 | log4jdbc.auto.load.popular.drivers=false | ||
4 | log4jdbc.drivers=com.mysql.cj.jdbc.Driver | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
src/main/resources/logback.xml
0 → 100644
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <configuration scan="true" scanPeriod="60 seconds" debug="false"> | ||
3 | |||
4 | <contextName>UserCenter</contextName> | ||
5 | <!--定义参数,后面可以通过${app.name}使用--> | ||
6 | <property name="app.name" value="member-engine"/> | ||
7 | <property name="log.path" value="./logs"/> | ||
8 | <property name="log.pattern" value="%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n"/> | ||
9 | |||
10 | <!--输出到控制台--> | ||
11 | <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | ||
12 | <!-- encoder 默认配置为PatternLayoutEncoder --> | ||
13 | <!--定义控制台输出格式--> | ||
14 | <encoder> | ||
15 | <pattern>%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %msg %n</pattern> | ||
16 | <charset>utf-8</charset> | ||
17 | </encoder> | ||
18 | </appender> | ||
19 | |||
20 | <!--获取比info级别高(包括info级别)但除error级别的日志--> | ||
21 | <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
22 | <filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||
23 | <level>ERROR</level> | ||
24 | <onMatch>DENY</onMatch> | ||
25 | <onMismatch>ACCEPT</onMismatch> | ||
26 | </filter> | ||
27 | <encoder> | ||
28 | <pattern>${log.pattern}</pattern> | ||
29 | </encoder> | ||
30 | <!--滚动策略--> | ||
31 | <file>${log.path}/${app.name}-info.log</file> | ||
32 | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
33 | <!--路径--> | ||
34 | <fileNamePattern>${log.path}/info/${app.name}-%d{yyyy-MM-dd}.log</fileNamePattern> | ||
35 | <maxHistory>30</maxHistory> | ||
36 | <totalSizeCap>10GB</totalSizeCap> | ||
37 | </rollingPolicy> | ||
38 | </appender> | ||
39 | |||
40 | <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
41 | <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
42 | <level>ERROR</level> | ||
43 | </filter> | ||
44 | <encoder> | ||
45 | <pattern>${log.pattern}</pattern> | ||
46 | </encoder> | ||
47 | <!--滚动策略--> | ||
48 | <file>${log.path}/${app.name}-error.log</file> | ||
49 | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
50 | <!--路径--> | ||
51 | <fileNamePattern>${log.path}/error/${app.name}-%d{yyyy-MM-dd}.log</fileNamePattern> | ||
52 | <maxHistory>30</maxHistory> | ||
53 | <totalSizeCap>10GB</totalSizeCap> | ||
54 | </rollingPolicy> | ||
55 | </appender> | ||
56 | |||
57 | |||
58 | <!--普通日志输出到控制台--> | ||
59 | <root level="info"> | ||
60 | <appender-ref ref="console" /> | ||
61 | <appender-ref ref="info" /> | ||
62 | <appender-ref ref="error" /> | ||
63 | </root> | ||
64 | |||
65 | |||
66 | <!--监控sql日志输出 --> | ||
67 | <logger name="jdbc.sqlonly" level="INFO" additivity="false"> | ||
68 | <appender-ref ref="console" /> | ||
69 | <appender-ref ref="info" /> | ||
70 | </logger> | ||
71 | |||
72 | <logger name="jdbc.resultset" level="ERROR" additivity="false"> | ||
73 | <appender-ref ref="console" /> | ||
74 | <appender-ref ref="info" /> | ||
75 | </logger> | ||
76 | |||
77 | <!-- 如想看到表格数据,将OFF改为INFO --> | ||
78 | <logger name="jdbc.resultsettable" level="OFF" additivity="false"> | ||
79 | <appender-ref ref="console" /> | ||
80 | </logger> | ||
81 | |||
82 | <logger name="jdbc.connection" level="OFF" additivity="false"> | ||
83 | <appender-ref ref="console" /> | ||
84 | <appender-ref ref="info" /> | ||
85 | </logger> | ||
86 | |||
87 | <logger name="jdbc.sqltiming" level="OFF" additivity="false"> | ||
88 | <appender-ref ref="console" /> | ||
89 | <appender-ref ref="info" /> | ||
90 | </logger> | ||
91 | |||
92 | <logger name="jdbc.audit" level="OFF" additivity="false"> | ||
93 | <appender-ref ref="console" /> | ||
94 | <appender-ref ref="info" /> | ||
95 | </logger> | ||
96 | </configuration> |
src/main/resources/template/email/email.ftl
0 → 100644
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
2 | <html xmlns="http://www.w3.org/1999/xhtml"> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
5 | <style> | ||
6 | @page { | ||
7 | margin: 0; | ||
8 | } | ||
9 | </style> | ||
10 | </head> | ||
11 | <body style="margin: 0px; | ||
12 | padding: 0px; | ||
13 | font: 100% SimSun, Microsoft YaHei, Times New Roman, Verdana, Arial, Helvetica, sans-serif; | ||
14 | color: #000;"> | ||
15 | <div style="height: auto; | ||
16 | width: 820px; | ||
17 | min-width: 820px; | ||
18 | margin: 0 auto; | ||
19 | margin-top: 20px; | ||
20 | border: 1px solid #eee;"> | ||
21 | <div style="padding: 10px;padding-bottom: 0px;"> | ||
22 | <p style="margin-bottom: 10px;padding-bottom: 0px;">尊敬的用户,您好:</p> | ||
23 | <p style="text-indent: 2em; margin-bottom: 10px;">您正在申请邮箱验证,您的验证码为:</p> | ||
24 | <p style="text-align: center; | ||
25 | font-family: Times New Roman; | ||
26 | font-size: 22px; | ||
27 | color: #C60024; | ||
28 | padding: 20px 0px; | ||
29 | margin-bottom: 10px; | ||
30 | font-weight: bold; | ||
31 | background: #ebebeb;">${code}</p> | ||
32 | <div style="list-style: none; | ||
33 | margin-top: 22px; | ||
34 | maigin-bottom: 10px; | ||
35 | font-size: 14px; | ||
36 | color: #555;"> | ||
37 | <p style="line-height: 12px;">Github:<a hover="color: #DA251D;" style="color: #999;" href="https://github.com/elunez/eladmin" target="_blank">https://github.com/elunez/eladmin</a></p> | ||
38 | </div> | ||
39 | <div class="foot-hr hr" style="margin: 0 auto; | ||
40 | z-index: 111; | ||
41 | width: 800px; | ||
42 | margin-top: 30px; | ||
43 | border-top: 1px solid #DA251D;"> | ||
44 | </div> | ||
45 | <div style="text-align: center; | ||
46 | font-size: 12px; | ||
47 | padding: 20px 0px; | ||
48 | font-family: Microsoft YaHei;"> | ||
49 | Copyright ©${.now?string("yyyy")} EL-ADMIN 后台管理系统 All Rights Reserved. | ||
50 | </div> | ||
51 | |||
52 | </div> | ||
53 | </div> | ||
54 | </body> | ||
55 | </html> |
1 | package ${package}.rest; | ||
2 | |||
3 | import com.topdraw.common.ResultInfo; | ||
4 | import com.topdraw.annotation.Log; | ||
5 | import ${package}.domain.${className}; | ||
6 | import ${package}.service.${className}Service; | ||
7 | import ${package}.service.dto.${className}QueryCriteria; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | ||
9 | import org.springframework.data.domain.Pageable; | ||
10 | import org.springframework.http.HttpStatus; | ||
11 | import org.springframework.http.ResponseEntity; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | import io.swagger.annotations.*; | ||
15 | import java.io.IOException; | ||
16 | import javax.servlet.http.HttpServletResponse; | ||
17 | |||
18 | /** | ||
19 | * @author ${author} | ||
20 | * @date ${date} | ||
21 | */ | ||
22 | @Api(tags = "${className}管理") | ||
23 | @RestController | ||
24 | @RequestMapping("/api/${changeClassName}") | ||
25 | public class ${className}Controller { | ||
26 | |||
27 | @Autowired | ||
28 | private ${className}Service ${changeClassName}Service; | ||
29 | |||
30 | @GetMapping | ||
31 | @ApiOperation("查询${className}") | ||
32 | public ResultInfo get${className}s(${className}QueryCriteria criteria, Pageable pageable) { | ||
33 | return ResultInfo.successPage(${changeClassName}Service.queryAll(criteria,pageable)); | ||
34 | } | ||
35 | |||
36 | @GetMapping(value = "/all") | ||
37 | @ApiOperation("查询所有${className}") | ||
38 | public ResultInfo get${className}s(${className}QueryCriteria criteria) { | ||
39 | return ResultInfo.success(${changeClassName}Service.queryAll(criteria)); | ||
40 | } | ||
41 | |||
42 | @Log | ||
43 | @PostMapping | ||
44 | @ApiOperation("新增${className}") | ||
45 | public ResultInfo create(@Validated @RequestBody ${className} resources) { | ||
46 | ${changeClassName}Service.create(resources); | ||
47 | return ResultInfo.success(); | ||
48 | } | ||
49 | |||
50 | @Log | ||
51 | @PutMapping | ||
52 | @ApiOperation("修改${className}") | ||
53 | public ResultInfo update(@Validated @RequestBody ${className} resources) { | ||
54 | ${changeClassName}Service.update(resources); | ||
55 | return ResultInfo.success(); | ||
56 | } | ||
57 | |||
58 | |||
59 | @Log | ||
60 | @DeleteMapping(value = "/{${pkChangeColName}}") | ||
61 | @ApiOperation("删除${className}") | ||
62 | public ResultInfo delete(@PathVariable ${pkColumnType} ${pkChangeColName}) { | ||
63 | ${changeClassName}Service.delete(${pkChangeColName}); | ||
64 | return ResultInfo.success(); | ||
65 | } | ||
66 | |||
67 | <#if columns??> | ||
68 | <#list columns as column> | ||
69 | <#if column.columnName == 'code'> | ||
70 | @GetMapping(value = "/getByCode/{code}") | ||
71 | @ApiOperation(value = "根据标识查询") | ||
72 | public ResultInfo getByCode(@PathVariable String code) { | ||
73 | return ResultInfo.success(${changeClassName}Service.getByCode(code)); | ||
74 | } | ||
75 | </#if> | ||
76 | </#list> | ||
77 | </#if> | ||
78 | } |
1 | package ${package}.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | <#if hasTimestamp> | ||
5 | import java.sql.Timestamp; | ||
6 | </#if> | ||
7 | <#if hasBigDecimal> | ||
8 | import java.math.BigDecimal; | ||
9 | </#if> | ||
10 | import java.io.Serializable; | ||
11 | <#if !auto && pkColumnType = 'Long'> | ||
12 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
13 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||
14 | </#if> | ||
15 | |||
16 | |||
17 | /** | ||
18 | * @author ${author} | ||
19 | * @date ${date} | ||
20 | */ | ||
21 | @Data | ||
22 | public class ${className}DTO implements Serializable { | ||
23 | <#if columns??> | ||
24 | <#list columns as column> | ||
25 | |||
26 | <#if column.columnComment != ''> | ||
27 | // ${column.columnComment} | ||
28 | </#if> | ||
29 | <#if column.columnKey = 'PRI'> | ||
30 | <#if !auto && pkColumnType = 'Long'> | ||
31 | // 处理精度丢失问题 | ||
32 | @JsonSerialize(using= ToStringSerializer.class) | ||
33 | </#if> | ||
34 | </#if> | ||
35 | private ${column.columnType} ${column.changeColumnName}; | ||
36 | </#list> | ||
37 | </#if> | ||
38 | } |
1 | package ${package}.domain; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import lombok.experimental.Accessors; | ||
5 | import cn.hutool.core.bean.BeanUtil; | ||
6 | import cn.hutool.core.bean.copier.CopyOptions; | ||
7 | import javax.persistence.*; | ||
8 | import org.springframework.data.annotation.CreatedDate; | ||
9 | import org.springframework.data.annotation.LastModifiedDate; | ||
10 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
11 | <#if hasTimestamp> | ||
12 | import java.sql.Timestamp; | ||
13 | </#if> | ||
14 | <#if hasBigDecimal> | ||
15 | import java.math.BigDecimal; | ||
16 | </#if> | ||
17 | <#if hasCode> | ||
18 | import java.util.UUID; | ||
19 | </#if> | ||
20 | |||
21 | import java.io.Serializable; | ||
22 | |||
23 | /** | ||
24 | * @author ${author} | ||
25 | * @date ${date} | ||
26 | */ | ||
27 | @Entity | ||
28 | @Data | ||
29 | @EntityListeners(AuditingEntityListener.class) | ||
30 | @Accessors(chain = true) | ||
31 | @Table(name="${tableName}") | ||
32 | public class ${className} implements Serializable { | ||
33 | <#if columns??> | ||
34 | <#list columns as column> | ||
35 | |||
36 | <#if column.columnComment != ''> | ||
37 | // ${column.columnComment} | ||
38 | </#if> | ||
39 | <#if column.columnKey = 'PRI'> | ||
40 | @Id | ||
41 | <#if auto> | ||
42 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
43 | </#if> | ||
44 | </#if> | ||
45 | <#if column.columnName == 'create_time'> | ||
46 | @CreatedDate | ||
47 | </#if> | ||
48 | <#if column.columnName == 'update_time'> | ||
49 | @LastModifiedDate | ||
50 | </#if> | ||
51 | @Column(name = "${column.columnName}"<#if column.columnKey = 'UNI'>,unique = true</#if><#if column.isNullable = 'NO' && column.columnKey != 'PRI'>, nullable = false</#if>) | ||
52 | private ${column.columnType} ${column.changeColumnName}; | ||
53 | </#list> | ||
54 | </#if> | ||
55 | |||
56 | public void copy(${className} source){ | ||
57 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
58 | } | ||
59 | } |
1 | package ${package}.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import ${package}.domain.${className}; | ||
5 | import ${package}.service.dto.${className}DTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author ${author} | ||
11 | * @date ${date} | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface ${className}Mapper extends BaseMapper<${className}DTO, ${className}> { | ||
15 | |||
16 | } |
1 | package ${package}.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | <#if queryHasTimestamp> | ||
5 | import java.sql.Timestamp; | ||
6 | </#if> | ||
7 | <#if queryHasBigDecimal> | ||
8 | import java.math.BigDecimal; | ||
9 | </#if> | ||
10 | <#if queryColumns??> | ||
11 | import com.topdraw.annotation.Query; | ||
12 | </#if> | ||
13 | |||
14 | /** | ||
15 | * @author ${author} | ||
16 | * @date ${date} | ||
17 | */ | ||
18 | @Data | ||
19 | public class ${className}QueryCriteria{ | ||
20 | <#if queryColumns??> | ||
21 | <#list queryColumns as column> | ||
22 | |||
23 | <#if column.columnQuery = '1'> | ||
24 | // 模糊 | ||
25 | @Query(type = Query.Type.INNER_LIKE) | ||
26 | </#if> | ||
27 | <#if column.columnQuery = '2'> | ||
28 | // 精确 | ||
29 | @Query | ||
30 | </#if> | ||
31 | private ${column.columnType} ${column.changeColumnName}; | ||
32 | </#list> | ||
33 | </#if> | ||
34 | } |
1 | package ${package}.repository; | ||
2 | |||
3 | import ${package}.domain.${className}; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author ${author} | ||
11 | * @date ${date} | ||
12 | */ | ||
13 | public interface ${className}Repository extends JpaRepository<${className}, ${pkColumnType}>, JpaSpecificationExecutor<${className}> { | ||
14 | <#if columns??> | ||
15 | <#list columns as column> | ||
16 | <#if column.columnKey = 'UNI'> | ||
17 | |||
18 | ${className} findBy${column.capitalColumnName}(${column.columnType} ${column.columnName}); | ||
19 | </#if> | ||
20 | </#list> | ||
21 | </#if> | ||
22 | |||
23 | <#if columns??> | ||
24 | <#list columns as column> | ||
25 | <#if column.columnName == 'code'> | ||
26 | Optional<${className}> findFirstByCode(String code); | ||
27 | </#if> | ||
28 | </#list> | ||
29 | </#if> | ||
30 | } |
1 | package ${package}.service; | ||
2 | |||
3 | import ${package}.domain.${className}; | ||
4 | import ${package}.service.dto.${className}DTO; | ||
5 | import ${package}.service.dto.${className}QueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | import java.util.Map; | ||
8 | import java.util.List; | ||
9 | import java.io.IOException; | ||
10 | import javax.servlet.http.HttpServletResponse; | ||
11 | |||
12 | /** | ||
13 | * @author ${author} | ||
14 | * @date ${date} | ||
15 | */ | ||
16 | public interface ${className}Service { | ||
17 | |||
18 | /** | ||
19 | * 查询数据分页 | ||
20 | * @param criteria 条件参数 | ||
21 | * @param pageable 分页参数 | ||
22 | * @return Map<String,Object> | ||
23 | */ | ||
24 | Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable); | ||
25 | |||
26 | /** | ||
27 | * 查询所有数据不分页 | ||
28 | * @param criteria 条件参数 | ||
29 | * @return List<${className}DTO> | ||
30 | */ | ||
31 | List<${className}DTO> queryAll(${className}QueryCriteria criteria); | ||
32 | |||
33 | /** | ||
34 | * 根据ID查询 | ||
35 | * @param ${pkChangeColName} ID | ||
36 | * @return ${className}DTO | ||
37 | */ | ||
38 | ${className}DTO findById(${pkColumnType} ${pkChangeColName}); | ||
39 | |||
40 | void create(${className} resources); | ||
41 | |||
42 | void update(${className} resources); | ||
43 | |||
44 | void delete(${pkColumnType} ${pkChangeColName}); | ||
45 | |||
46 | <#if columns??> | ||
47 | <#list columns as column> | ||
48 | <#if column.columnName == 'code'> | ||
49 | /** | ||
50 | * Code校验 | ||
51 | * @param code | ||
52 | * @return ${className}DTO | ||
53 | */ | ||
54 | ${className}DTO getByCode(String code); | ||
55 | </#if> | ||
56 | </#list> | ||
57 | </#if> | ||
58 | } |
1 | package ${package}.service.impl; | ||
2 | |||
3 | import ${package}.domain.${className}; | ||
4 | <#if columns??> | ||
5 | <#list columns as column> | ||
6 | <#if column.columnKey = 'UNI'> | ||
7 | <#if column_index = 1> | ||
8 | import com.topdraw.exception.EntityExistException; | ||
9 | </#if> | ||
10 | </#if> | ||
11 | </#list> | ||
12 | </#if> | ||
13 | import com.topdraw.utils.ValidationUtil; | ||
14 | import com.topdraw.utils.FileUtil; | ||
15 | import ${package}.repository.${className}Repository; | ||
16 | import ${package}.service.${className}Service; | ||
17 | import ${package}.service.dto.${className}DTO; | ||
18 | import ${package}.service.dto.${className}QueryCriteria; | ||
19 | import ${package}.service.mapper.${className}Mapper; | ||
20 | import org.springframework.beans.factory.annotation.Autowired; | ||
21 | import org.springframework.stereotype.Service; | ||
22 | import org.springframework.transaction.annotation.Propagation; | ||
23 | import org.springframework.transaction.annotation.Transactional; | ||
24 | import org.springframework.dao.EmptyResultDataAccessException; | ||
25 | <#if !auto && pkColumnType = 'Long'> | ||
26 | import cn.hutool.core.lang.Snowflake; | ||
27 | import cn.hutool.core.util.IdUtil; | ||
28 | </#if> | ||
29 | <#if !auto && pkColumnType = 'String'> | ||
30 | import cn.hutool.core.util.IdUtil; | ||
31 | </#if> | ||
32 | import org.springframework.data.domain.Page; | ||
33 | import org.springframework.data.domain.Pageable; | ||
34 | import org.springframework.util.Assert; | ||
35 | import com.topdraw.utils.PageUtil; | ||
36 | import com.topdraw.utils.QueryHelp; | ||
37 | import com.topdraw.utils.StringUtils; | ||
38 | |||
39 | import java.util.List; | ||
40 | import java.util.Map; | ||
41 | import java.io.IOException; | ||
42 | import javax.servlet.http.HttpServletResponse; | ||
43 | import java.util.ArrayList; | ||
44 | import java.util.LinkedHashMap; | ||
45 | |||
46 | /** | ||
47 | * @author ${author} | ||
48 | * @date ${date} | ||
49 | */ | ||
50 | @Service | ||
51 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
52 | public class ${className}ServiceImpl implements ${className}Service { | ||
53 | |||
54 | @Autowired | ||
55 | private ${className}Repository ${changeClassName}Repository; | ||
56 | |||
57 | @Autowired | ||
58 | private ${className}Mapper ${changeClassName}Mapper; | ||
59 | |||
60 | @Override | ||
61 | public Map<String, Object> queryAll(${className}QueryCriteria criteria, Pageable pageable) { | ||
62 | Page<${className}> page = ${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
63 | return PageUtil.toPage(page.map(${changeClassName}Mapper::toDto)); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public List<${className}DTO> queryAll(${className}QueryCriteria criteria) { | ||
68 | return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public ${className}DTO findById(${pkColumnType} ${pkChangeColName}) { | ||
73 | ${className} ${changeClassName} = ${changeClassName}Repository.findById(${pkChangeColName}).orElseGet(${className}::new); | ||
74 | ValidationUtil.isNull(${changeClassName}.get${pkCapitalColName}(),"${className}","${pkChangeColName}",${pkChangeColName}); | ||
75 | return ${changeClassName}Mapper.toDto(${changeClassName}); | ||
76 | } | ||
77 | |||
78 | @Override | ||
79 | @Transactional(rollbackFor = Exception.class) | ||
80 | public void create(${className} resources) { | ||
81 | <#if !auto && pkColumnType = 'Long'> | ||
82 | Snowflake snowflake = IdUtil.createSnowflake(1, 1); | ||
83 | resources.set${pkCapitalColName}(snowflake.nextId()); | ||
84 | </#if> | ||
85 | <#if !auto && pkColumnType = 'String'> | ||
86 | resources.set${pkCapitalColName}(IdUtil.simpleUUID()); | ||
87 | </#if> | ||
88 | <#if columns??> | ||
89 | <#list columns as column> | ||
90 | <#if column.columnKey = 'UNI'> | ||
91 | if(${changeClassName}Repository.findBy${column.capitalColumnName}(resources.get${column.capitalColumnName}()) != null) { | ||
92 | throw new EntityExistException(${className}.class,"${column.columnName}",resources.get${column.capitalColumnName}()); | ||
93 | } | ||
94 | </#if> | ||
95 | </#list> | ||
96 | </#if> | ||
97 | ${changeClassName}Repository.save(resources); | ||
98 | } | ||
99 | |||
100 | @Override | ||
101 | @Transactional(rollbackFor = Exception.class) | ||
102 | public void update(${className} resources) { | ||
103 | ${className} ${changeClassName} = ${changeClassName}Repository.findById(resources.get${pkCapitalColName}()).orElseGet(${className}::new); | ||
104 | ValidationUtil.isNull( ${changeClassName}.get${pkCapitalColName}(),"${className}","id",resources.get${pkCapitalColName}()); | ||
105 | <#if columns??> | ||
106 | <#list columns as column> | ||
107 | <#if column.columnKey = 'UNI'> | ||
108 | <#if column_index = 1> | ||
109 | ${className} ${changeClassName}1 = null; | ||
110 | </#if> | ||
111 | ${changeClassName}1 = ${changeClassName}Repository.findBy${column.capitalColumnName}(resources.get${column.capitalColumnName}()); | ||
112 | if(${changeClassName}1 != null && !${changeClassName}1.get${pkCapitalColName}().equals(${changeClassName}.get${pkCapitalColName}())){ | ||
113 | throw new EntityExistException(${className}.class,"${column.columnName}",resources.get${column.capitalColumnName}()); | ||
114 | } | ||
115 | </#if> | ||
116 | </#list> | ||
117 | </#if> | ||
118 | ${changeClassName}.copy(resources); | ||
119 | ${changeClassName}Repository.save(${changeClassName}); | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | @Transactional(rollbackFor = Exception.class) | ||
124 | public void delete(${pkColumnType} ${pkChangeColName}) { | ||
125 | Assert.notNull(id, "The given id must not be null!"); | ||
126 | ${className} ${changeClassName} = ${changeClassName}Repository.findById(id).orElseThrow( | ||
127 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ${className}.class, id), 1)); | ||
128 | ${changeClassName}Repository.delete(${changeClassName}); | ||
129 | } | ||
130 | |||
131 | |||
132 | <#if columns??> | ||
133 | <#list columns as column> | ||
134 | <#if column.columnName == 'code'> | ||
135 | @Override | ||
136 | public ${className}DTO getByCode(String code) { | ||
137 | return StringUtils.isNotEmpty(code) ? ${changeClassName}Mapper.toDto(${changeClassName}Repository.findFirstByCode(code).orElseGet(${className}::new)) | ||
138 | : new ${className}DTO(); | ||
139 | } | ||
140 | </#if> | ||
141 | </#list> | ||
142 | </#if> | ||
143 | } |
1 | import request from '@/utils/request' | ||
2 | |||
3 | export function add(data) { | ||
4 | return request({ | ||
5 | url: 'api/${changeClassName}', | ||
6 | method: 'post', | ||
7 | data | ||
8 | }) | ||
9 | } | ||
10 | |||
11 | export function del(${pkChangeColName}) { | ||
12 | return request({ | ||
13 | url: 'api/${changeClassName}/' + ${pkChangeColName}, | ||
14 | method: 'delete' | ||
15 | }) | ||
16 | } | ||
17 | |||
18 | export function edit(data) { | ||
19 | return request({ | ||
20 | url: 'api/${changeClassName}', | ||
21 | method: 'put', | ||
22 | data | ||
23 | }) | ||
24 | } | ||
25 | |||
26 | export function download${className}(params) { | ||
27 | return request({ | ||
28 | url: 'api/${changeClassName}/download', | ||
29 | method: 'get', | ||
30 | params, | ||
31 | responseType: 'blob' | ||
32 | }) | ||
33 | } | ||
34 | |||
35 | <#if columns??> | ||
36 | <#list columns as column> | ||
37 | <#if column.columnName == 'code'> | ||
38 | export function getByCode(code) { | ||
39 | return request({ | ||
40 | url: 'api/${changeClassName}/getByCode/' + code, | ||
41 | method: 'get' | ||
42 | }) | ||
43 | } | ||
44 | </#if> | ||
45 | </#list> | ||
46 | </#if> |
1 | <template> | ||
2 | <el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="960px" @closed="doClose"> | ||
3 | <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px" style="padding: 30px;margin: -20px 0"> | ||
4 | <el-row> | ||
5 | <#if columns??> | ||
6 | <#list columns as column> | ||
7 | <#if column.changeColumnName != '${pkChangeColName}'> | ||
8 | <#if column.columnName != 'images' && column.columnName != 'create_time' && column.columnName != 'update_time'> | ||
9 | <el-col :span="12"> | ||
10 | <el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.isNullable = | ||
11 | 'NO'>prop="${column.changeColumnName}"</#if>> | ||
12 | <#if column.columnName = 'code'> | ||
13 | <el-input v-model="form.${column.changeColumnName}" prop="code"/> | ||
14 | <#elseif column.columnType = 'Timestamp'> | ||
15 | <el-date-picker v-model="form.${column.changeColumnName}" type="datetime"/> | ||
16 | <#elseif column.columnName = 'image'> | ||
17 | <images-upload ref="upload" :limit="5" :image.sync="form.image" :images.sync="form.images" upload-entity="${changeClassName}" /> | ||
18 | <#else> | ||
19 | <el-input v-model="form.${column.changeColumnName}"/> | ||
20 | </#if> | ||
21 | </el-form-item> | ||
22 | </el-col> | ||
23 | </#if> | ||
24 | </#if> | ||
25 | </#list> | ||
26 | </#if> | ||
27 | </el-row> | ||
28 | </el-form> | ||
29 | <div slot="footer" class="dialog-footer"> | ||
30 | <el-button type="text" @click="cancel">取消</el-button> | ||
31 | <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button> | ||
32 | </div> | ||
33 | </el-dialog> | ||
34 | </template> | ||
35 | |||
36 | <script> | ||
37 | import { add, edit } from '@/api/${changeClassName}' | ||
38 | <#if columns??> | ||
39 | <#list columns as column> | ||
40 | <#if column.columnName == 'code'> | ||
41 | import { getByCode } from '@/api/${changeClassName}' | ||
42 | </#if> | ||
43 | </#list> | ||
44 | </#if> | ||
45 | import ImagesUpload from '@/components/ImagesUpload/index' | ||
46 | export default { | ||
47 | components: { ImagesUpload }, | ||
48 | props: { | ||
49 | isAdd: { | ||
50 | type: Boolean, | ||
51 | required: true | ||
52 | }, | ||
53 | dictMap: { | ||
54 | type: Object, | ||
55 | required: true | ||
56 | } | ||
57 | }, | ||
58 | data() { | ||
59 | return { | ||
60 | loading: false, dialog: false, | ||
61 | form: { | ||
62 | <#if columns??> | ||
63 | <#list columns as column> | ||
64 | ${column.changeColumnName}: ''<#if column_has_next>,</#if> | ||
65 | </#list> | ||
66 | </#if> | ||
67 | }, | ||
68 | rules: { | ||
69 | <#if columns??> | ||
70 | <#list columns as column> | ||
71 | <#if column.columnName == 'code'> | ||
72 | code: [ | ||
73 | { required: true, message: '请输入标识', trigger: 'blur' }, { validator: this.validateCode, trigger: 'blur' } | ||
74 | ], | ||
75 | </#if> | ||
76 | </#list> | ||
77 | </#if> | ||
78 | <#function filter columns> | ||
79 | <#local result = []> | ||
80 | <#list columns as column> | ||
81 | <#if column.columnKey != 'PRI' && column.isNullable = 'NO'> | ||
82 | <#local result = result + [column]> | ||
83 | </#if> | ||
84 | </#list> | ||
85 | <#return result> | ||
86 | </#function> | ||
87 | <#assign filteredData = filter(columns)> | ||
88 | <#list filteredData as column> | ||
89 | ${column.changeColumnName}: [ | ||
90 | { required: true, message: '${column.columnComment}不能为空', trigger: 'blur' } | ||
91 | ]<#sep>,</#sep> | ||
92 | </#list> | ||
93 | } | ||
94 | } | ||
95 | }, | ||
96 | methods: { | ||
97 | <#if columns??> | ||
98 | <#list columns as column> | ||
99 | <#if column.columnName == 'code'> | ||
100 | validateCode(rule, value, callback) { | ||
101 | // 当为编辑状态且code未改变时不进行校验 | ||
102 | if (!this.isAdd && this.form.originalCode === value) { | ||
103 | callback() | ||
104 | } else { | ||
105 | getByCode(value) | ||
106 | .then(res => { | ||
107 | typeof (res) === 'undefined' || res.id === null || this.form.id === res.id | ||
108 | ? callback() | ||
109 | : callback(new Error('该code已存在!')) | ||
110 | }) | ||
111 | .catch((err) => { | ||
112 | console.log(err) | ||
113 | callback() | ||
114 | }) | ||
115 | } | ||
116 | }, | ||
117 | </#if> | ||
118 | </#list> | ||
119 | </#if> | ||
120 | cancel() { | ||
121 | this.dialog = false | ||
122 | }, | ||
123 | doSubmit() { | ||
124 | if (this.isAdd) { | ||
125 | this.doAdd() | ||
126 | } else this.doEdit() | ||
127 | }, | ||
128 | doAdd() { | ||
129 | this.$refs['form'].validate((valid) => { | ||
130 | if (valid) { | ||
131 | this.loading = true | ||
132 | add(this.form).then(() => { | ||
133 | this.$notify({ | ||
134 | title: '添加成功', | ||
135 | type: 'success', | ||
136 | duration: 2500 | ||
137 | }) | ||
138 | this.dialog = false | ||
139 | this.loading = false | ||
140 | this.$parent.init() | ||
141 | }).catch(err => { | ||
142 | this.loading = false | ||
143 | console.log(err) | ||
144 | }) | ||
145 | } else { | ||
146 | this.$notify({ | ||
147 | title: '警告', | ||
148 | message: '信息不合法', | ||
149 | type: 'warning', | ||
150 | duration: 2000 | ||
151 | }) | ||
152 | } | ||
153 | }) | ||
154 | }, | ||
155 | doEdit() { | ||
156 | this.$refs['form'].validate((valid) => { | ||
157 | if (valid) { | ||
158 | this.loading = true | ||
159 | edit(this.form).then(() => { | ||
160 | this.$notify({ | ||
161 | title: '修改成功', | ||
162 | type: 'success', | ||
163 | duration: 2500 | ||
164 | }) | ||
165 | this.loading = false | ||
166 | this.dialog = false | ||
167 | this.$parent.init() | ||
168 | }).catch(err => { | ||
169 | console.log(err) | ||
170 | this.loading = false | ||
171 | }) | ||
172 | } else { | ||
173 | this.$notify({ | ||
174 | title: '警告', | ||
175 | message: '信息不合法', | ||
176 | type: 'warning', | ||
177 | duration: 2000 | ||
178 | }) | ||
179 | } | ||
180 | }) | ||
181 | }, | ||
182 | doClose() { | ||
183 | this.resetForm() | ||
184 | }, | ||
185 | resetForm() { | ||
186 | this.$refs['form'].resetFields() | ||
187 | this.form = { | ||
188 | <#if columns??> | ||
189 | <#list columns as column> | ||
190 | <#if column.columnName == 'code'> | ||
191 | originalCode: '', | ||
192 | </#if> | ||
193 | ${column.changeColumnName}: ''<#if column_has_next>,</#if> | ||
194 | </#list> | ||
195 | </#if> | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | </script> | ||
201 | |||
202 | <style scoped> | ||
203 | |||
204 | </style> |
1 | <#--noinspection ALL--> | ||
2 | <template> | ||
3 | <div class="app-container"> | ||
4 | <!--工具栏--> | ||
5 | <div class="head-container"> | ||
6 | <#if hasQuery> | ||
7 | <!-- 搜索 --> | ||
8 | <el-select v-model="query.type" clearable placeholder="聚合筛选条件" class="filter-item" style="width: 130px"> | ||
9 | <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/> | ||
10 | </el-select> | ||
11 | <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/> | ||
12 | <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button> | ||
13 | </#if> | ||
14 | <!-- 新增 --> | ||
15 | <div style="display: inline-block;margin: 0 2px;"> | ||
16 | <el-button | ||
17 | v-permission="['admin','${changeClassName}:add']" | ||
18 | class="filter-item" | ||
19 | size="mini" | ||
20 | type="primary" | ||
21 | icon="el-icon-plus" | ||
22 | @click="add">新增</el-button> | ||
23 | </div> | ||
24 | </div> | ||
25 | <!--表单组件--> | ||
26 | <eForm ref="form" :is-add="isAdd" :dict-map="dictMap"/> | ||
27 | <!--表格渲染--> | ||
28 | <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" @row-dblclick="edit"> | ||
29 | <#if columns??> | ||
30 | <#list columns as column> | ||
31 | <#if column.columnShow = 'true'> | ||
32 | <#if column.columnType != 'Timestamp'> | ||
33 | <el-table-column prop="${column.changeColumnName}" label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.columnName = 'id' || column.columnName = 'name' || column.columnName = 'code'>sortable </#if>/> | ||
34 | <#else> | ||
35 | <el-table-column prop="${column.changeColumnName}" label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>"> | ||
36 | <template slot-scope="scope"> | ||
37 | <span>{{ parseTime(scope.row.${column.changeColumnName}) }}</span> | ||
38 | </template> | ||
39 | </el-table-column> | ||
40 | </#if> | ||
41 | </#if> | ||
42 | </#list> | ||
43 | </#if> | ||
44 | <el-table-column label="操作" width="120px" fixed="right" align="center"> | ||
45 | <template slot-scope="scope"> | ||
46 | <el-button v-permission="['admin','${changeClassName}:edit']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)"/> | ||
47 | <el-popover | ||
48 | v-permission="['admin','${changeClassName}:del']" | ||
49 | :ref="scope.row.${pkChangeColName}" | ||
50 | placement="top" | ||
51 | width="180"> | ||
52 | <p>确定删除本条数据吗?</p> | ||
53 | <div style="text-align: right; margin: 0"> | ||
54 | <el-button size="mini" type="text" @click="$refs[scope.row.${pkChangeColName}].doClose()">取消</el-button> | ||
55 | <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.${pkChangeColName})">确定</el-button> | ||
56 | </div> | ||
57 | <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/> | ||
58 | </el-popover> | ||
59 | </template> | ||
60 | </el-table-column> | ||
61 | </el-table> | ||
62 | <!--分页组件--> | ||
63 | <el-pagination | ||
64 | :total="total" | ||
65 | :current-page="page + 1" | ||
66 | style="margin-top: 8px;" | ||
67 | layout="total, prev, pager, next, sizes" | ||
68 | @size-change="sizeChange" | ||
69 | @current-change="pageChange"/> | ||
70 | </div> | ||
71 | </template> | ||
72 | |||
73 | <script> | ||
74 | import initData from '@/mixins/initData' | ||
75 | import initDict from '@/mixins/initDict' | ||
76 | import { getAttrByValueFromDict } from '@/utils/common-util' | ||
77 | import { del, download${className} } from '@/api/${changeClassName}' | ||
78 | <#if hasTimestamp> | ||
79 | import { parseTime, downloadFile } from '@/utils/index' | ||
80 | </#if> | ||
81 | import eForm from './form' | ||
82 | export default { | ||
83 | components: { eForm }, | ||
84 | mixins: [initData, initDict], | ||
85 | data() { | ||
86 | return { | ||
87 | delLoading: false<#if hasQuery>,</#if> | ||
88 | <#if hasQuery> | ||
89 | queryTypeOptions: [ | ||
90 | <#if queryColumns??> | ||
91 | <#list queryColumns as column> | ||
92 | { key: '${column.changeColumnName}', display_name: '<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>' }<#if column_has_next>,</#if> | ||
93 | </#list> | ||
94 | </#if> | ||
95 | ] | ||
96 | </#if> | ||
97 | } | ||
98 | }, | ||
99 | created() { | ||
100 | this.$nextTick(() => { | ||
101 | this.init() | ||
102 | this.getDictMap('') | ||
103 | }) | ||
104 | }, | ||
105 | methods: { | ||
106 | <#if hasTimestamp> | ||
107 | parseTime, | ||
108 | </#if> | ||
109 | getAttrByValueFromDict, | ||
110 | beforeInit() { | ||
111 | this.url = 'api/${changeClassName}' | ||
112 | const sort = '${pkChangeColName},desc' | ||
113 | this.params = { page: this.page, size: this.size, sort: sort } | ||
114 | <#if hasQuery> | ||
115 | const query = this.query | ||
116 | const type = query.type | ||
117 | const value = query.value | ||
118 | if (type && value) { this.params[type] = value } | ||
119 | </#if> | ||
120 | return true | ||
121 | }, | ||
122 | subDelete(${pkChangeColName}) { | ||
123 | this.delLoading = true | ||
124 | del(${pkChangeColName}).then(res => { | ||
125 | this.delLoading = false | ||
126 | this.$refs[${pkChangeColName}].doClose() | ||
127 | this.dleChangePage() | ||
128 | this.init() | ||
129 | this.$notify({ | ||
130 | title: '删除成功', | ||
131 | type: 'success', | ||
132 | duration: 2500 | ||
133 | }) | ||
134 | }).catch(err => { | ||
135 | this.delLoading = false | ||
136 | this.$refs[${pkChangeColName}].doClose() | ||
137 | console.log(err.response.data.message) | ||
138 | }) | ||
139 | }, | ||
140 | add() { | ||
141 | this.isAdd = true | ||
142 | this.$refs.form.dialog = true | ||
143 | }, | ||
144 | edit(data) { | ||
145 | this.isAdd = false | ||
146 | const _this = this.$refs.form | ||
147 | _this.form = { | ||
148 | <#if columns??> | ||
149 | <#list columns as column> | ||
150 | <#if column.columnName == 'code'> | ||
151 | originalCode: data.code, | ||
152 | </#if> | ||
153 | ${column.changeColumnName}: data.${column.changeColumnName}<#if column_has_next>,</#if> | ||
154 | </#list> | ||
155 | </#if> | ||
156 | } | ||
157 | _this.dialog = true | ||
158 | }, | ||
159 | // 导出 | ||
160 | download() { | ||
161 | this.beforeInit() | ||
162 | this.downloadLoading = true | ||
163 | download${className}(this.params).then(result => { | ||
164 | downloadFile(result, '${className}列表', 'xlsx') | ||
165 | this.downloadLoading = false | ||
166 | }).catch(() => { | ||
167 | this.downloadLoading = false | ||
168 | }) | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | </script> | ||
173 | |||
174 | <style scoped> | ||
175 | |||
176 | </style> |
src/test/java/com/topdraw/BaseTest.java
0 → 100644
1 | package com.topdraw; | ||
2 | |||
3 | |||
4 | import org.junit.runner.RunWith; | ||
5 | import org.springframework.boot.test.context.SpringBootTest; | ||
6 | import org.springframework.test.context.junit4.SpringRunner; | ||
7 | |||
8 | @SpringBootTest(classes = MemberEngineApplication.class) | ||
9 | @RunWith(SpringRunner.class) | ||
10 | public class BaseTest { | ||
11 | } |
1 | package com.topdraw.resttemplate; | ||
2 | |||
3 | import com.alibaba.fastjson.JSONObject; | ||
4 | import com.topdraw.BaseTest; | ||
5 | import org.junit.Test; | ||
6 | import org.springframework.beans.factory.annotation.Autowired; | ||
7 | |||
8 | public class RestTemplateTest extends BaseTest { | ||
9 | |||
10 | @Autowired | ||
11 | RestTemplateClient apiUtil; | ||
12 | |||
13 | @Test | ||
14 | public void t(){ | ||
15 | JSONObject memberInfo = this.apiUtil.getMemberInfo(5L); | ||
16 | System.out.println(memberInfo); | ||
17 | } | ||
18 | |||
19 | } |
-
Please register or sign in to post a comment