init
0 parents
Showing
85 changed files
with
5144 additions
and
0 deletions
.gitignore
0 → 100644
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>redis-transfer-project</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 | <!--redisson--> | ||
27 | <dependency> | ||
28 | <groupId>redis.clients</groupId> | ||
29 | <artifactId>jedis</artifactId> | ||
30 | <version>3.1.0</version> | ||
31 | </dependency> | ||
32 | |||
33 | <!--代码生成器--> | ||
34 | <dependency> | ||
35 | <groupId>com.topdraw</groupId> | ||
36 | <artifactId>cronos-system</artifactId> | ||
37 | <version>1.1.0</version> | ||
38 | </dependency> | ||
39 | |||
40 | <!--Mysql依赖包,版本差异,需单独引入--> | ||
41 | <dependency> | ||
42 | <groupId>mysql</groupId> | ||
43 | <artifactId>mysql-connector-java</artifactId> | ||
44 | <version>8.0.26</version> | ||
45 | </dependency> | ||
46 | |||
47 | <dependency> | ||
48 | <groupId>commons-codec</groupId> | ||
49 | <artifactId>commons-codec</artifactId> | ||
50 | <version>1.9</version> | ||
51 | </dependency> | ||
52 | |||
53 | </dependencies> | ||
54 | |||
55 | |||
56 | <profiles> | ||
57 | <profile> | ||
58 | <!-- 本地开发环境 --> | ||
59 | <id>dev</id> | ||
60 | <properties> | ||
61 | <profiles.active>dev</profiles.active> | ||
62 | </properties> | ||
63 | <activation> | ||
64 | <!-- 默认的,不加参数时执行这个profile --> | ||
65 | <activeByDefault>true</activeByDefault> | ||
66 | </activation> | ||
67 | </profile> | ||
68 | <profile> | ||
69 | <!-- 生产环境 --> | ||
70 | <id>prod</id> | ||
71 | <properties> | ||
72 | <profiles.active>prod</profiles.active> | ||
73 | <modifier>-prod</modifier> | ||
74 | </properties> | ||
75 | </profile> | ||
76 | </profiles> | ||
77 | |||
78 | <build> | ||
79 | <finalName>redis-transfer-project</finalName> | ||
80 | <plugins> | ||
81 | <plugin> | ||
82 | <groupId>org.springframework.boot</groupId> | ||
83 | <artifactId>spring-boot-maven-plugin</artifactId> | ||
84 | <configuration> | ||
85 | <fork>true</fork> | ||
86 | </configuration> | ||
87 | </plugin> | ||
88 | <!-- 跳过单元测试 --> | ||
89 | <plugin> | ||
90 | <groupId>org.apache.maven.plugins</groupId> | ||
91 | <artifactId>maven-surefire-plugin</artifactId> | ||
92 | <configuration> | ||
93 | <skipTests>true</skipTests> | ||
94 | </configuration> | ||
95 | </plugin> | ||
96 | <!-- 复制指定配置文件到指定目录 --> | ||
97 | <plugin> | ||
98 | <artifactId>maven-resources-plugin</artifactId> | ||
99 | <executions> | ||
100 | <execution> | ||
101 | <id>copy-resources</id> | ||
102 | <phase>package</phase> | ||
103 | <goals> | ||
104 | <goal>copy-resources</goal> | ||
105 | </goals> | ||
106 | <configuration> | ||
107 | <resources> | ||
108 | <resource> | ||
109 | <directory>src/main/resources/config</directory> | ||
110 | <includes> | ||
111 | <include>application.yml</include> | ||
112 | <include>application-${profiles.active}.yml</include> | ||
113 | </includes> | ||
114 | </resource> | ||
115 | </resources> | ||
116 | <outputDirectory>${project.build.directory}/config</outputDirectory> | ||
117 | </configuration> | ||
118 | </execution> | ||
119 | </executions> | ||
120 | </plugin> | ||
121 | <!-- jar包内剔除所有配置文件 --> | ||
122 | <plugin> | ||
123 | <artifactId>maven-jar-plugin</artifactId> | ||
124 | <configuration> | ||
125 | <!--不打入jar包的文件类型或者路径--> | ||
126 | <excludes> | ||
127 | <exclude>config/**</exclude> | ||
128 | </excludes> | ||
129 | </configuration> | ||
130 | </plugin> | ||
131 | </plugins> | ||
132 | </build> | ||
133 | |||
134 | </project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | package com.topdraw; | ||
2 | |||
3 | import com.topdraw.base.BaseRepositoryFactory; | ||
4 | import com.topdraw.utils.SpringContextHolder; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | ||
6 | import org.springframework.boot.SpringApplication; | ||
7 | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
8 | import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; | ||
9 | import org.springframework.boot.builder.SpringApplicationBuilder; | ||
10 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
11 | import org.springframework.context.annotation.Bean; | ||
12 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
13 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
14 | import org.springframework.scheduling.annotation.EnableAsync; | ||
15 | import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
16 | |||
17 | /** | ||
18 | * @author : | ||
19 | * @description: | ||
20 | * @function : | ||
21 | * @date :Created in 2022/2/10 16:17 | ||
22 | * @version: : | ||
23 | * @modified By: | ||
24 | * @since : modified in 2022/2/10 16:17 | ||
25 | */ | ||
26 | @EnableJpaAuditing | ||
27 | @EnableAsync | ||
28 | @SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) | ||
29 | @EnableTransactionManagement | ||
30 | @EnableJpaRepositories(repositoryFactoryBeanClass = BaseRepositoryFactory.class) | ||
31 | public class RedisTransferApplication extends SpringBootServletInitializer { | ||
32 | |||
33 | @Override | ||
34 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { | ||
35 | return builder.sources(RedisTransferApplication.class); | ||
36 | } | ||
37 | |||
38 | public static void main(String[] args) { | ||
39 | SpringApplication.run(RedisTransferApplication.class, args); | ||
40 | } | ||
41 | |||
42 | @Bean | ||
43 | public SpringContextHolder springContextHolder() { | ||
44 | return new SpringContextHolder(); | ||
45 | } | ||
46 | |||
47 | |||
48 | } |
1 | package com.topdraw.business.module.activitybtn.all.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 2022-02-26 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_tpl_param_click") | ||
24 | public class ActTplParamClick 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 活动事件id | ||
37 | @Column(name = "activity_id", nullable = false) | ||
38 | private Long activityId; | ||
39 | |||
40 | // 活动按钮id | ||
41 | @Column(name = "template_param_value_id", nullable = false) | ||
42 | private Long templateParamValueId; | ||
43 | |||
44 | // 显示用名称,表示哪个按钮或者内容 | ||
45 | @Column(name = "name", nullable = false) | ||
46 | private String name; | ||
47 | |||
48 | // pv值 | ||
49 | @Column(name = "pv", nullable = false) | ||
50 | private Integer pv; | ||
51 | |||
52 | // uv值 | ||
53 | @Column(name = "uv", nullable = false) | ||
54 | private Integer uv; | ||
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(ActTplParamClick source){ | ||
67 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
68 | } | ||
69 | } |
src/main/java/com/topdraw/business/module/activitybtn/all/repository/ActivityBtnPvUvRepository.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.all.repository; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.all.domain.ActTplParamClick; | ||
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 2022-02-26 | ||
12 | */ | ||
13 | public interface ActivityBtnPvUvRepository extends JpaRepository<ActTplParamClick, Long>, JpaSpecificationExecutor<ActTplParamClick> { | ||
14 | |||
15 | Optional<ActTplParamClick> findByMarketingActivityIdAndActivityIdAndTemplateParamValueId(Long marketingActivityId, Long activityId, Long templateParamValueId); | ||
16 | } |
src/main/java/com/topdraw/business/module/activitybtn/all/service/ActivityBtnPvUvService.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.all.service; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.all.domain.ActTplParamClick; | ||
4 | |||
5 | /** | ||
6 | * @author XiangHan | ||
7 | * @date 2022-02-26 | ||
8 | */ | ||
9 | public interface ActivityBtnPvUvService { | ||
10 | |||
11 | void create(ActTplParamClick resources); | ||
12 | |||
13 | void update(ActTplParamClick resources); | ||
14 | |||
15 | ActTplParamClick findByMarketingActivityIdAndActivityIdAndTemplateParamValueId(Long marketingActivityId, Long activityId, Long templateParamValueId); | ||
16 | } |
src/main/java/com/topdraw/business/module/activitybtn/all/service/dto/ActTplParamClickDTO.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.all.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import javax.persistence.Column; | ||
6 | import java.io.Serializable; | ||
7 | import java.sql.Timestamp; | ||
8 | |||
9 | |||
10 | /** | ||
11 | * @author XiangHan | ||
12 | * @date 2022-02-26 | ||
13 | */ | ||
14 | @Data | ||
15 | public class ActTplParamClickDTO implements Serializable { | ||
16 | |||
17 | // ID | ||
18 | private Long id; | ||
19 | |||
20 | // 营销活动ID | ||
21 | private Long marketingActivityId; | ||
22 | |||
23 | // 活动事件id | ||
24 | private Long activityId; | ||
25 | |||
26 | // 活动按钮id | ||
27 | private Long templateParamValueId; | ||
28 | |||
29 | // 显示用名称,表示哪个按钮或者内容 | ||
30 | private String name; | ||
31 | |||
32 | // pv值 | ||
33 | private Long pv; | ||
34 | |||
35 | // uv值 | ||
36 | private Long uv; | ||
37 | |||
38 | // 创建时间 | ||
39 | private Timestamp createTime; | ||
40 | |||
41 | // 更新时间 | ||
42 | private Timestamp updateTime; | ||
43 | } |
1 | package com.topdraw.business.module.activitybtn.all.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.all.domain.ActTplParamClick; | ||
4 | import com.topdraw.business.module.activitybtn.all.repository.ActivityBtnPvUvRepository; | ||
5 | import com.topdraw.business.module.activitybtn.all.service.ActivityBtnPvUvService; | ||
6 | import com.topdraw.utils.ValidationUtil; | ||
7 | import org.springframework.beans.factory.annotation.Autowired; | ||
8 | import org.springframework.stereotype.Service; | ||
9 | import org.springframework.transaction.annotation.Propagation; | ||
10 | import org.springframework.transaction.annotation.Transactional; | ||
11 | |||
12 | /** | ||
13 | * @author XiangHan | ||
14 | * @date 2022-02-26 | ||
15 | */ | ||
16 | @Service | ||
17 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
18 | public class ActivityBtnPvUvServiceImpl implements ActivityBtnPvUvService { | ||
19 | |||
20 | @Autowired | ||
21 | private ActivityBtnPvUvRepository PvUvRepository; | ||
22 | |||
23 | @Override | ||
24 | @Transactional(rollbackFor = Exception.class) | ||
25 | public void create(ActTplParamClick resources) { | ||
26 | PvUvRepository.save(resources); | ||
27 | } | ||
28 | |||
29 | @Override | ||
30 | @Transactional(rollbackFor = Exception.class) | ||
31 | public void update(ActTplParamClick resources) { | ||
32 | ActTplParamClick PvUv = PvUvRepository.findById(resources.getId()).orElseGet(ActTplParamClick::new); | ||
33 | ValidationUtil.isNull( PvUv.getId(),"PvUv","id",resources.getId()); | ||
34 | PvUv.copy(resources); | ||
35 | PvUvRepository.save(PvUv); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public ActTplParamClick findByMarketingActivityIdAndActivityIdAndTemplateParamValueId(Long marketingActivityId, Long activityId, Long templateParamValueId) { | ||
40 | return PvUvRepository.findByMarketingActivityIdAndActivityIdAndTemplateParamValueId(marketingActivityId, activityId, templateParamValueId).orElseGet(ActTplParamClick::new); | ||
41 | } | ||
42 | |||
43 | } |
src/main/java/com/topdraw/business/module/activitybtn/day/domain/ActTplParamClickDay.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.day.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 2022-02-26 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_tpl_param_click_day") | ||
24 | public class ActTplParamClickDay 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 活动事件id | ||
37 | @Column(name = "activity_id", nullable = false) | ||
38 | private Long activityId; | ||
39 | |||
40 | // 显示用名称,表示哪个按钮或者内容 | ||
41 | @Column(name = "name", nullable = false) | ||
42 | private String name; | ||
43 | |||
44 | // 活动按钮id | ||
45 | @Column(name = "template_param_value_id", nullable = false) | ||
46 | private Long templateParamValueId; | ||
47 | |||
48 | // 日期 | ||
49 | @Column(name = "day", nullable = false) | ||
50 | private String day; | ||
51 | |||
52 | // pv值 | ||
53 | @Column(name = "pv", nullable = false) | ||
54 | private Integer pv; | ||
55 | |||
56 | // uv值 | ||
57 | @Column(name = "uv", nullable = false) | ||
58 | private Integer uv; | ||
59 | |||
60 | // 创建时间 | ||
61 | @CreatedDate | ||
62 | @Column(name = "create_time") | ||
63 | private Timestamp createTime; | ||
64 | |||
65 | // 更新时间 | ||
66 | @LastModifiedDate | ||
67 | @Column(name = "update_time") | ||
68 | private Timestamp updateTime; | ||
69 | |||
70 | public void copy(ActTplParamClickDay source){ | ||
71 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
72 | } | ||
73 | } |
1 | package com.topdraw.business.module.activitybtn.day.repository; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.day.domain.ActTplParamClickDay; | ||
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 2022-02-26 | ||
12 | */ | ||
13 | public interface ActivityBtnPvUvDayRepository extends JpaRepository<ActTplParamClickDay, Long>, JpaSpecificationExecutor<ActTplParamClickDay> { | ||
14 | |||
15 | Optional<ActTplParamClickDay> findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDay(Long marketingActivityId, Long activityId, Long paramValueId, String day); | ||
16 | |||
17 | } |
src/main/java/com/topdraw/business/module/activitybtn/day/service/ActivityBtnPvUvDayService.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.day.service; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.day.domain.ActTplParamClickDay; | ||
4 | |||
5 | /** | ||
6 | * @author XiangHan | ||
7 | * @date 2022-02-26 | ||
8 | */ | ||
9 | public interface ActivityBtnPvUvDayService { | ||
10 | |||
11 | void create(ActTplParamClickDay resources); | ||
12 | |||
13 | void update(ActTplParamClickDay resources); | ||
14 | |||
15 | ActTplParamClickDay findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDay(Long marketingActivityId, Long activityId, Long templateParamValueId, String toString); | ||
16 | } |
src/main/java/com/topdraw/business/module/activitybtn/day/service/dto/ActTplParamClickDTO.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.day.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 2022-02-26 | ||
12 | */ | ||
13 | @Data | ||
14 | public class ActTplParamClickDTO implements Serializable { | ||
15 | |||
16 | // ID | ||
17 | private Long id; | ||
18 | |||
19 | // 营销活动ID | ||
20 | private Long marketingActivityId; | ||
21 | |||
22 | // 活动事件id | ||
23 | private Long activityId; | ||
24 | |||
25 | // 活动按钮id | ||
26 | private Long templateParamValueId; | ||
27 | |||
28 | // 显示用名称,表示哪个按钮或者内容 | ||
29 | private String name; | ||
30 | |||
31 | // 日期 | ||
32 | private String day; | ||
33 | |||
34 | // pv值 | ||
35 | private Integer pv; | ||
36 | |||
37 | // uv值 | ||
38 | private Integer uv; | ||
39 | |||
40 | // 创建时间 | ||
41 | private Timestamp createTime; | ||
42 | |||
43 | // 更新时间 | ||
44 | private Timestamp updateTime; | ||
45 | } |
1 | package com.topdraw.business.module.activitybtn.day.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.day.domain.ActTplParamClickDay; | ||
4 | import com.topdraw.business.module.activitybtn.day.repository.ActivityBtnPvUvDayRepository; | ||
5 | import com.topdraw.business.module.activitybtn.day.service.ActivityBtnPvUvDayService; | ||
6 | import com.topdraw.utils.ValidationUtil; | ||
7 | import org.springframework.beans.factory.annotation.Autowired; | ||
8 | import org.springframework.stereotype.Service; | ||
9 | import org.springframework.transaction.annotation.Propagation; | ||
10 | import org.springframework.transaction.annotation.Transactional; | ||
11 | |||
12 | /** | ||
13 | * @author XiangHan | ||
14 | * @date 2022-02-26 | ||
15 | */ | ||
16 | @Service | ||
17 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
18 | public class ActivityBtnPvUvDayServiceImpl implements ActivityBtnPvUvDayService { | ||
19 | |||
20 | @Autowired | ||
21 | private ActivityBtnPvUvDayRepository pvUvDayRepository; | ||
22 | |||
23 | @Override | ||
24 | @Transactional(rollbackFor = Exception.class) | ||
25 | public void create(ActTplParamClickDay resources) { | ||
26 | pvUvDayRepository.save(resources); | ||
27 | } | ||
28 | |||
29 | @Override | ||
30 | @Transactional(rollbackFor = Exception.class) | ||
31 | public void update(ActTplParamClickDay resources) { | ||
32 | ActTplParamClickDay PvUvDay = pvUvDayRepository.findById(resources.getId()).orElseGet(ActTplParamClickDay::new); | ||
33 | ValidationUtil.isNull( PvUvDay.getId(),"PvUvDay","id",resources.getId()); | ||
34 | PvUvDay.copy(resources); | ||
35 | pvUvDayRepository.save(PvUvDay); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public ActTplParamClickDay findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDay(Long marketingActivityId, Long activityId, Long templateParamValueId, String day) { | ||
40 | return this.pvUvDayRepository.findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDay(marketingActivityId, | ||
41 | activityId, templateParamValueId, day).orElseGet(ActTplParamClickDay::new); | ||
42 | } | ||
43 | |||
44 | |||
45 | } |
src/main/java/com/topdraw/business/module/activitybtn/hour/domain/ActTplParamClickHour.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.hour.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 2022-02-26 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_tpl_param_click_hour") | ||
24 | public class ActTplParamClickHour 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 活动事件id | ||
37 | @Column(name = "activity_id", nullable = false) | ||
38 | private Long activityId; | ||
39 | |||
40 | // 显示用名称,表示哪个按钮或者内容 | ||
41 | @Column(name = "name", nullable = false) | ||
42 | private String name; | ||
43 | |||
44 | // 活动按钮id | ||
45 | @Column(name = "template_param_value_id", nullable = false) | ||
46 | private Long templateParamValueId; | ||
47 | |||
48 | // 日期 | ||
49 | @Column(name = "day", nullable = false) | ||
50 | private String day; | ||
51 | |||
52 | // 小时(0-23) | ||
53 | @Column(name = "hour", nullable = false) | ||
54 | private Integer hour; | ||
55 | |||
56 | // pv值 | ||
57 | @Column(name = "pv", nullable = false) | ||
58 | private Integer pv; | ||
59 | |||
60 | // uv值 | ||
61 | @Column(name = "uv", nullable = false) | ||
62 | private Integer uv; | ||
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(ActTplParamClickHour source){ | ||
75 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
76 | } | ||
77 | } |
1 | package com.topdraw.business.module.activitybtn.hour.repository; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.hour.domain.ActTplParamClickHour; | ||
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 2022-02-26 | ||
12 | */ | ||
13 | public interface ActivityBtnPvUvHourRepository extends JpaRepository<ActTplParamClickHour, Long>, JpaSpecificationExecutor<ActTplParamClickHour> { | ||
14 | |||
15 | Optional<ActTplParamClickHour> findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDayAndHour(Long marketingActivityId, Long activityId, Long paramValueId, String day, int hour); | ||
16 | } |
src/main/java/com/topdraw/business/module/activitybtn/hour/service/ActivityBtnPvUvHourService.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.hour.service; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.hour.domain.ActTplParamClickHour; | ||
4 | |||
5 | /** | ||
6 | * @author XiangHan | ||
7 | * @date 2022-02-26 | ||
8 | */ | ||
9 | public interface ActivityBtnPvUvHourService { | ||
10 | |||
11 | void create(ActTplParamClickHour resources); | ||
12 | |||
13 | void update(ActTplParamClickHour resources); | ||
14 | |||
15 | ActTplParamClickHour findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDayAndHour(Long marketingActivityId, Long activityId, Long paramValueId, String day, int hour); | ||
16 | } |
src/main/java/com/topdraw/business/module/activitybtn/hour/service/dto/ActTplParamClickHourDTO.java
0 → 100644
1 | package com.topdraw.business.module.activitybtn.hour.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import javax.persistence.Column; | ||
6 | import java.io.Serializable; | ||
7 | import java.sql.Timestamp; | ||
8 | |||
9 | |||
10 | /** | ||
11 | * @author XiangHan | ||
12 | * @date 2022-02-26 | ||
13 | */ | ||
14 | @Data | ||
15 | public class ActTplParamClickHourDTO implements Serializable { | ||
16 | |||
17 | // ID | ||
18 | private Long id; | ||
19 | |||
20 | // 营销活动ID | ||
21 | private Long marketingActivityId; | ||
22 | |||
23 | // 活动事件id | ||
24 | private Long activityId; | ||
25 | |||
26 | // 活动按钮id | ||
27 | private Long templateParamValueId; | ||
28 | |||
29 | // 显示用名称,表示哪个按钮或者内容 | ||
30 | private String name; | ||
31 | |||
32 | // 日期 | ||
33 | private String day; | ||
34 | |||
35 | // 小时(0-23) | ||
36 | private Integer hour; | ||
37 | |||
38 | // pv值 | ||
39 | private Integer pv; | ||
40 | |||
41 | // uv值 | ||
42 | private Integer uv; | ||
43 | |||
44 | // 创建时间 | ||
45 | private Timestamp createTime; | ||
46 | |||
47 | // 更新时间 | ||
48 | private Timestamp updateTime; | ||
49 | } |
1 | package com.topdraw.business.module.activitybtn.hour.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.hour.domain.ActTplParamClickHour; | ||
4 | import com.topdraw.business.module.activitybtn.hour.repository.ActivityBtnPvUvHourRepository; | ||
5 | import com.topdraw.business.module.activitybtn.hour.service.ActivityBtnPvUvHourService; | ||
6 | import com.topdraw.utils.ValidationUtil; | ||
7 | import org.springframework.beans.factory.annotation.Autowired; | ||
8 | import org.springframework.stereotype.Service; | ||
9 | import org.springframework.transaction.annotation.Propagation; | ||
10 | import org.springframework.transaction.annotation.Transactional; | ||
11 | |||
12 | /** | ||
13 | * @author XiangHan | ||
14 | * @date 2022-02-26 | ||
15 | */ | ||
16 | @Service | ||
17 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
18 | public class ActivityBtnPvUvHourServiceImpl implements ActivityBtnPvUvHourService { | ||
19 | |||
20 | @Autowired | ||
21 | private ActivityBtnPvUvHourRepository PvUvHourRepository; | ||
22 | |||
23 | |||
24 | @Override | ||
25 | @Transactional(rollbackFor = Exception.class) | ||
26 | public void create(ActTplParamClickHour resources) { | ||
27 | PvUvHourRepository.save(resources); | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | @Transactional(rollbackFor = Exception.class) | ||
32 | public void update(ActTplParamClickHour resources) { | ||
33 | ActTplParamClickHour PvUvHour = PvUvHourRepository.findById(resources.getId()).orElseGet(ActTplParamClickHour::new); | ||
34 | ValidationUtil.isNull( PvUvHour.getId(),"PvUvHour","id",resources.getId()); | ||
35 | PvUvHour.copy(resources); | ||
36 | PvUvHourRepository.save(PvUvHour); | ||
37 | } | ||
38 | |||
39 | @Override | ||
40 | public ActTplParamClickHour findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDayAndHour(Long marketingActivityId, | ||
41 | Long activityId, Long paramValueId, | ||
42 | String day, int hour) { | ||
43 | return PvUvHourRepository.findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDayAndHour(marketingActivityId, activityId, | ||
44 | paramValueId, day, hour). | ||
45 | orElseGet(ActTplParamClickHour::new); | ||
46 | } | ||
47 | |||
48 | |||
49 | } |
1 | package com.topdraw.business.module.subscribe.all.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 | import java.sql.Timestamp; | ||
12 | |||
13 | import java.io.Serializable; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2022-04-20 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_subscribe_pv_uv") | ||
24 | public class SubscribePvUv 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 营销活动标识 | ||
37 | @Column(name = "marketing_activity_code", nullable = false) | ||
38 | private String marketingActivityCode; | ||
39 | |||
40 | // 产品包id | ||
41 | @Column(name = "package_id", nullable = false) | ||
42 | private String packageId; | ||
43 | |||
44 | // 产品包标识 | ||
45 | @Column(name = "package_code") | ||
46 | private String packageCode; | ||
47 | |||
48 | // 产品包名称 | ||
49 | @Column(name = "package_name") | ||
50 | private String packageName; | ||
51 | |||
52 | // 订购按钮总点击量 | ||
53 | @Column(name = "btn_click_pv", nullable = false) | ||
54 | private Long btnClickPv; | ||
55 | |||
56 | // 订购按钮总点击人数 | ||
57 | @Column(name = "btn_click_uv", nullable = false) | ||
58 | private Long btnClickUv; | ||
59 | |||
60 | // 订购成功人数 | ||
61 | @Column(name = "subscribe_num", nullable = false) | ||
62 | private Long subscribeNum; | ||
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(SubscribePvUv source){ | ||
75 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
76 | } | ||
77 | } |
src/main/java/com/topdraw/business/module/subscribe/all/repository/SubscribePvUvRepository.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.all.repository; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.all.domain.SubscribePvUv; | ||
4 | import com.topdraw.business.module.subscribe.day.domain.SubscribePvUvDay; | ||
5 | import org.springframework.data.jpa.repository.JpaRepository; | ||
6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
7 | |||
8 | import java.util.Optional; | ||
9 | |||
10 | /** | ||
11 | * @author XiangHan | ||
12 | * @date 2022-04-20 | ||
13 | */ | ||
14 | public interface SubscribePvUvRepository extends JpaRepository<SubscribePvUv, Long>, JpaSpecificationExecutor<SubscribePvUv> { | ||
15 | |||
16 | Optional<SubscribePvUv> findByMarketingActivityCodeAndPackageId(String code, String packageId); | ||
17 | } |
src/main/java/com/topdraw/business/module/subscribe/all/service/SubscribePvUvService.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.all.service; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.all.domain.SubscribePvUv; | ||
4 | import com.topdraw.business.module.subscribe.all.service.dto.SubscribePvUvDTO; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2022-04-20 | ||
9 | */ | ||
10 | public interface SubscribePvUvService { | ||
11 | |||
12 | /** | ||
13 | * 根据ID查询 | ||
14 | * @param id ID | ||
15 | * @return SubscribePvUvDTO | ||
16 | */ | ||
17 | SubscribePvUvDTO findById(Long id); | ||
18 | |||
19 | void create(SubscribePvUv resources); | ||
20 | |||
21 | void update(SubscribePvUv resources); | ||
22 | |||
23 | void delete(Long id); | ||
24 | |||
25 | SubscribePvUv findByMarketingActivityCodeAndPackageId(String code, String packageId); | ||
26 | } |
src/main/java/com/topdraw/business/module/subscribe/all/service/dto/SubscribePvUvDTO.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.all.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import java.sql.Timestamp; | ||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2022-04-20 | ||
11 | */ | ||
12 | @Data | ||
13 | public class SubscribePvUvDTO implements Serializable { | ||
14 | |||
15 | // ID | ||
16 | private Long id; | ||
17 | |||
18 | // 营销活动ID | ||
19 | private Long marketingActivityId; | ||
20 | |||
21 | // 营销活动标识 | ||
22 | private String marketingActivityCode; | ||
23 | |||
24 | // 产品包id | ||
25 | private String packageId; | ||
26 | |||
27 | // 产品包标识 | ||
28 | private String packageCode; | ||
29 | |||
30 | // 产品包名称 | ||
31 | private String packageName; | ||
32 | |||
33 | // 订购按钮总点击量 | ||
34 | private Long btnClickPv; | ||
35 | |||
36 | // 订购按钮总点击人数 | ||
37 | private Long btnClickUv; | ||
38 | |||
39 | // 订购成功人数 | ||
40 | private Long subscribeNum; | ||
41 | |||
42 | // 创建时间 | ||
43 | private Timestamp createTime; | ||
44 | |||
45 | // 更新时间 | ||
46 | private Timestamp updateTime; | ||
47 | } |
src/main/java/com/topdraw/business/module/subscribe/all/service/impl/SubscribePvUvServiceImpl.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.all.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.all.domain.SubscribePvUv; | ||
4 | import com.topdraw.utils.ValidationUtil; | ||
5 | import com.topdraw.business.module.subscribe.all.repository.SubscribePvUvRepository; | ||
6 | import com.topdraw.business.module.subscribe.all.service.SubscribePvUvService; | ||
7 | import com.topdraw.business.module.subscribe.all.service.dto.SubscribePvUvDTO; | ||
8 | import com.topdraw.business.module.subscribe.all.service.mapper.SubscribePvUvMapper; | ||
9 | import org.springframework.beans.factory.annotation.Autowired; | ||
10 | import org.springframework.stereotype.Service; | ||
11 | import org.springframework.transaction.annotation.Propagation; | ||
12 | import org.springframework.transaction.annotation.Transactional; | ||
13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
14 | import org.springframework.util.Assert; | ||
15 | |||
16 | /** | ||
17 | * @author XiangHan | ||
18 | * @date 2022-04-20 | ||
19 | */ | ||
20 | @Service | ||
21 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
22 | public class SubscribePvUvServiceImpl implements SubscribePvUvService { | ||
23 | |||
24 | @Autowired | ||
25 | private SubscribePvUvRepository SubscribePvUvRepository; | ||
26 | |||
27 | @Autowired | ||
28 | private SubscribePvUvMapper SubscribePvUvMapper; | ||
29 | |||
30 | @Override | ||
31 | public SubscribePvUvDTO findById(Long id) { | ||
32 | SubscribePvUv SubscribePvUv = SubscribePvUvRepository.findById(id).orElseGet(SubscribePvUv::new); | ||
33 | ValidationUtil.isNull(SubscribePvUv.getId(),"SubscribePvUv","id",id); | ||
34 | return SubscribePvUvMapper.toDto(SubscribePvUv); | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | @Transactional(rollbackFor = Exception.class) | ||
39 | public void create(SubscribePvUv resources) { | ||
40 | SubscribePvUvRepository.save(resources); | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | @Transactional(rollbackFor = Exception.class) | ||
45 | public void update(SubscribePvUv resources) { | ||
46 | SubscribePvUv SubscribePvUv = SubscribePvUvRepository.findById(resources.getId()).orElseGet(SubscribePvUv::new); | ||
47 | ValidationUtil.isNull( SubscribePvUv.getId(),"SubscribePvUv","id",resources.getId()); | ||
48 | SubscribePvUv.copy(resources); | ||
49 | SubscribePvUvRepository.save(SubscribePvUv); | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | @Transactional(rollbackFor = Exception.class) | ||
54 | public void delete(Long id) { | ||
55 | Assert.notNull(id, "The given id must not be null!"); | ||
56 | SubscribePvUv SubscribePvUv = SubscribePvUvRepository.findById(id).orElseThrow( | ||
57 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", SubscribePvUv.class, id), 1)); | ||
58 | SubscribePvUvRepository.delete(SubscribePvUv); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public SubscribePvUv findByMarketingActivityCodeAndPackageId(String code, String packageId) { | ||
63 | SubscribePvUv SubscribePvUvDay = | ||
64 | SubscribePvUvRepository.findByMarketingActivityCodeAndPackageId(code, packageId).orElseGet(SubscribePvUv::new); | ||
65 | return SubscribePvUvDay; | ||
66 | } | ||
67 | |||
68 | |||
69 | } |
src/main/java/com/topdraw/business/module/subscribe/all/service/mapper/SubscribePvUvMapper.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.all.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.module.subscribe.all.domain.SubscribePvUv; | ||
5 | import com.topdraw.business.module.subscribe.all.service.dto.SubscribePvUvDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2022-04-20 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface SubscribePvUvMapper extends BaseMapper<SubscribePvUvDTO, SubscribePvUv> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.module.subscribe.day.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 | import java.sql.Timestamp; | ||
12 | |||
13 | import java.io.Serializable; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2022-04-20 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_subscribe_pv_uv_day") | ||
24 | public class SubscribePvUvDay 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 营销活动标识 | ||
37 | @Column(name = "marketing_activity_code", nullable = false) | ||
38 | private String marketingActivityCode; | ||
39 | |||
40 | // 产品包id | ||
41 | @Column(name = "package_id", nullable = false) | ||
42 | private String packageId; | ||
43 | |||
44 | // 产品包标识 | ||
45 | @Column(name = "package_code") | ||
46 | private String packageCode; | ||
47 | |||
48 | // 产品包名称 | ||
49 | @Column(name = "package_name") | ||
50 | private String packageName; | ||
51 | |||
52 | // 日期 | ||
53 | @Column(name = "day", nullable = false) | ||
54 | private String day; | ||
55 | |||
56 | // 订购按钮总点击量 | ||
57 | @Column(name = "btn_click_pv", nullable = false) | ||
58 | private Long btnClickPv; | ||
59 | |||
60 | // 订购按钮总点击人数 | ||
61 | @Column(name = "btn_click_uv", nullable = false) | ||
62 | private Long btnClickUv; | ||
63 | |||
64 | // 订购成功人数 | ||
65 | @Column(name = "subscribe_num", nullable = false) | ||
66 | private Long subscribeNum; | ||
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(SubscribePvUvDay source){ | ||
79 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
80 | } | ||
81 | } |
src/main/java/com/topdraw/business/module/subscribe/day/repository/SubscribePvUvDayRepository.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.day.repository; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.day.domain.SubscribePvUvDay; | ||
4 | import com.topdraw.business.module.subscribe.hour.domain.SubscribePvUvHour; | ||
5 | import org.springframework.data.jpa.repository.JpaRepository; | ||
6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
7 | |||
8 | import java.util.Optional; | ||
9 | |||
10 | /** | ||
11 | * @author XiangHan | ||
12 | * @date 2022-04-20 | ||
13 | */ | ||
14 | public interface SubscribePvUvDayRepository extends JpaRepository<SubscribePvUvDay, Long>, JpaSpecificationExecutor<SubscribePvUvDay> { | ||
15 | |||
16 | Optional<SubscribePvUvDay> findByMarketingActivityCodeAndPackageIdAndDay(String code, String packageId, String day); | ||
17 | } |
src/main/java/com/topdraw/business/module/subscribe/day/service/SubscribePvUvDayService.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.day.service; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.day.domain.SubscribePvUvDay; | ||
4 | import com.topdraw.business.module.subscribe.day.service.dto.SubscribePvUvDayDTO; | ||
5 | import com.topdraw.business.module.subscribe.day.service.dto.SubscribePvUvDayQueryCriteria; | ||
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 XiangHan | ||
14 | * @date 2022-04-20 | ||
15 | */ | ||
16 | public interface SubscribePvUvDayService { | ||
17 | |||
18 | /** | ||
19 | * 查询数据分页 | ||
20 | * @param criteria 条件参数 | ||
21 | * @param pageable 分页参数 | ||
22 | * @return Map<String,Object> | ||
23 | */ | ||
24 | Map<String,Object> queryAll(SubscribePvUvDayQueryCriteria criteria, Pageable pageable); | ||
25 | |||
26 | /** | ||
27 | * 查询所有数据不分页 | ||
28 | * @param criteria 条件参数 | ||
29 | * @return List<SubscribePvUvDayDTO> | ||
30 | */ | ||
31 | List<SubscribePvUvDayDTO> queryAll(SubscribePvUvDayQueryCriteria criteria); | ||
32 | |||
33 | /** | ||
34 | * 根据ID查询 | ||
35 | * @param id ID | ||
36 | * @return SubscribePvUvDayDTO | ||
37 | */ | ||
38 | SubscribePvUvDayDTO findById(Long id); | ||
39 | |||
40 | void create(SubscribePvUvDay resources); | ||
41 | |||
42 | void update(SubscribePvUvDay resources); | ||
43 | |||
44 | void delete(Long id); | ||
45 | |||
46 | SubscribePvUvDay findByMarketingActivityCodeAndPackageIdAndDay(String code, String packageId, String day); | ||
47 | |||
48 | void updateByMarketingActivityCodeAndDayAndPackageId(SubscribePvUvDay subscribePvUvDay); | ||
49 | |||
50 | } |
src/main/java/com/topdraw/business/module/subscribe/day/service/dto/SubscribePvUvDayDTO.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.day.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import java.sql.Timestamp; | ||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2022-04-20 | ||
11 | */ | ||
12 | @Data | ||
13 | public class SubscribePvUvDayDTO implements Serializable { | ||
14 | |||
15 | // ID | ||
16 | private Long id; | ||
17 | |||
18 | // 营销活动ID | ||
19 | private Long marketingActivityId; | ||
20 | |||
21 | // 营销活动标识 | ||
22 | private String marketingActivityCode; | ||
23 | |||
24 | // 产品包id | ||
25 | private String packageId; | ||
26 | |||
27 | // 产品包标识 | ||
28 | private String packageCode; | ||
29 | |||
30 | // 产品包名称 | ||
31 | private String packageName; | ||
32 | |||
33 | // 日期 | ||
34 | private String day; | ||
35 | |||
36 | // 订购按钮总点击量 | ||
37 | private Long btnClickPv; | ||
38 | |||
39 | // 订购按钮总点击人数 | ||
40 | private Long btnClickUv; | ||
41 | |||
42 | // 订购成功人数 | ||
43 | private Long subscribeNum; | ||
44 | |||
45 | // 创建时间 | ||
46 | private Timestamp createTime; | ||
47 | |||
48 | // 更新时间 | ||
49 | private Timestamp updateTime; | ||
50 | } |
1 | package com.topdraw.business.module.subscribe.day.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.day.domain.SubscribePvUvDay; | ||
4 | import com.topdraw.business.module.subscribe.hour.domain.SubscribePvUvHour; | ||
5 | import com.topdraw.utils.ValidationUtil; | ||
6 | import com.topdraw.utils.FileUtil; | ||
7 | import com.topdraw.business.module.subscribe.day.repository.SubscribePvUvDayRepository; | ||
8 | import com.topdraw.business.module.subscribe.day.service.SubscribePvUvDayService; | ||
9 | import com.topdraw.business.module.subscribe.day.service.dto.SubscribePvUvDayDTO; | ||
10 | import com.topdraw.business.module.subscribe.day.service.dto.SubscribePvUvDayQueryCriteria; | ||
11 | import com.topdraw.business.module.subscribe.day.service.mapper.SubscribePvUvDayMapper; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.stereotype.Service; | ||
14 | import org.springframework.transaction.annotation.Propagation; | ||
15 | import org.springframework.transaction.annotation.Transactional; | ||
16 | import org.springframework.dao.EmptyResultDataAccessException; | ||
17 | import org.springframework.data.domain.Page; | ||
18 | import org.springframework.data.domain.Pageable; | ||
19 | import org.springframework.util.Assert; | ||
20 | import com.topdraw.utils.PageUtil; | ||
21 | import com.topdraw.utils.QueryHelp; | ||
22 | import com.topdraw.utils.StringUtils; | ||
23 | |||
24 | import java.util.List; | ||
25 | import java.util.Map; | ||
26 | import java.io.IOException; | ||
27 | import javax.servlet.http.HttpServletResponse; | ||
28 | import java.util.ArrayList; | ||
29 | import java.util.LinkedHashMap; | ||
30 | |||
31 | /** | ||
32 | * @author XiangHan | ||
33 | * @date 2022-04-20 | ||
34 | */ | ||
35 | @Service | ||
36 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
37 | public class SubscribePvUvDayServiceImpl implements SubscribePvUvDayService { | ||
38 | |||
39 | @Autowired | ||
40 | private SubscribePvUvDayRepository SubscribePvUvDayRepository; | ||
41 | |||
42 | @Autowired | ||
43 | private SubscribePvUvDayMapper SubscribePvUvDayMapper; | ||
44 | |||
45 | @Override | ||
46 | public Map<String, Object> queryAll(SubscribePvUvDayQueryCriteria criteria, Pageable pageable) { | ||
47 | Page<SubscribePvUvDay> page = SubscribePvUvDayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
48 | return PageUtil.toPage(page.map(SubscribePvUvDayMapper::toDto)); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public List<SubscribePvUvDayDTO> queryAll(SubscribePvUvDayQueryCriteria criteria) { | ||
53 | return SubscribePvUvDayMapper.toDto(SubscribePvUvDayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public SubscribePvUvDayDTO findById(Long id) { | ||
58 | SubscribePvUvDay SubscribePvUvDay = SubscribePvUvDayRepository.findById(id).orElseGet(SubscribePvUvDay::new); | ||
59 | ValidationUtil.isNull(SubscribePvUvDay.getId(),"SubscribePvUvDay","id",id); | ||
60 | return SubscribePvUvDayMapper.toDto(SubscribePvUvDay); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | @Transactional(rollbackFor = Exception.class) | ||
65 | public void create(SubscribePvUvDay resources) { | ||
66 | SubscribePvUvDayRepository.save(resources); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | @Transactional(rollbackFor = Exception.class) | ||
71 | public void update(SubscribePvUvDay resources) { | ||
72 | SubscribePvUvDay SubscribePvUvDay = SubscribePvUvDayRepository.findById(resources.getId()).orElseGet(SubscribePvUvDay::new); | ||
73 | ValidationUtil.isNull( SubscribePvUvDay.getId(),"SubscribePvUvDay","id",resources.getId()); | ||
74 | SubscribePvUvDay.copy(resources); | ||
75 | SubscribePvUvDayRepository.save(SubscribePvUvDay); | ||
76 | } | ||
77 | |||
78 | @Override | ||
79 | @Transactional(rollbackFor = Exception.class) | ||
80 | public void delete(Long id) { | ||
81 | Assert.notNull(id, "The given id must not be null!"); | ||
82 | SubscribePvUvDay SubscribePvUvDay = SubscribePvUvDayRepository.findById(id).orElseThrow( | ||
83 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", SubscribePvUvDay.class, id), 1)); | ||
84 | SubscribePvUvDayRepository.delete(SubscribePvUvDay); | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public SubscribePvUvDay findByMarketingActivityCodeAndPackageIdAndDay(String code, String packageId, String day) { | ||
89 | SubscribePvUvDay SubscribePvUvDay = | ||
90 | SubscribePvUvDayRepository.findByMarketingActivityCodeAndPackageIdAndDay(code, packageId, day).orElseGet(SubscribePvUvDay::new); | ||
91 | return SubscribePvUvDay; | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public void updateByMarketingActivityCodeAndDayAndPackageId(SubscribePvUvDay subscribePvUvDay) { | ||
96 | |||
97 | } | ||
98 | |||
99 | |||
100 | } |
src/main/java/com/topdraw/business/module/subscribe/day/service/mapper/SubscribePvUvDayMapper.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.day.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.module.subscribe.day.domain.SubscribePvUvDay; | ||
5 | import com.topdraw.business.module.subscribe.day.service.dto.SubscribePvUvDayDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2022-04-20 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface SubscribePvUvDayMapper extends BaseMapper<SubscribePvUvDayDTO, SubscribePvUvDay> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.module.subscribe.hour.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 | import java.sql.Timestamp; | ||
12 | |||
13 | import java.io.Serializable; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2022-04-20 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_subscribe_pv_uv_hour") | ||
24 | public class SubscribePvUvHour 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 营销活动标识 | ||
37 | @Column(name = "marketing_activity_code", nullable = false) | ||
38 | private String marketingActivityCode; | ||
39 | |||
40 | // 产品包id | ||
41 | @Column(name = "package_id", nullable = false) | ||
42 | private String packageId; | ||
43 | |||
44 | // 产品包标识 | ||
45 | @Column(name = "package_code") | ||
46 | private String packageCode; | ||
47 | |||
48 | // 产品包名称 | ||
49 | @Column(name = "package_name") | ||
50 | private String packageName; | ||
51 | |||
52 | // 日期 | ||
53 | @Column(name = "day", nullable = false) | ||
54 | private String day; | ||
55 | |||
56 | // 小时(0-23) | ||
57 | @Column(name = "hour", nullable = false) | ||
58 | private Integer hour; | ||
59 | |||
60 | // 订购按钮总点击量 | ||
61 | @Column(name = "btn_click_pv", nullable = false) | ||
62 | private Long btnClickPv; | ||
63 | |||
64 | // 订购按钮总点击人数 | ||
65 | @Column(name = "btn_click_uv", nullable = false) | ||
66 | private Long btnClickUv; | ||
67 | |||
68 | // 订购成功人数 | ||
69 | @Column(name = "subscribe_num", nullable = false) | ||
70 | private Long subscribeNum; | ||
71 | |||
72 | // 创建时间 | ||
73 | @CreatedDate | ||
74 | @Column(name = "create_time") | ||
75 | private Timestamp createTime; | ||
76 | |||
77 | // 更新时间 | ||
78 | @LastModifiedDate | ||
79 | @Column(name = "update_time") | ||
80 | private Timestamp updateTime; | ||
81 | |||
82 | public void copy(SubscribePvUvHour source){ | ||
83 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
84 | } | ||
85 | } |
src/main/java/com/topdraw/business/module/subscribe/hour/repository/SubscribePvUvHourRepository.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.hour.repository; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.hour.domain.SubscribePvUvHour; | ||
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 2022-04-20 | ||
13 | */ | ||
14 | public interface SubscribePvUvHourRepository extends JpaRepository<SubscribePvUvHour, Long>, JpaSpecificationExecutor<SubscribePvUvHour> { | ||
15 | |||
16 | Optional<SubscribePvUvHour> findByMarketingActivityCodeAndPackageIdAndDayAndHour(String code, String packageId, String day, int hour); | ||
17 | } |
src/main/java/com/topdraw/business/module/subscribe/hour/service/SubscribePvUvHourService.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.hour.service; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.hour.domain.SubscribePvUvHour; | ||
4 | import com.topdraw.business.module.subscribe.hour.service.dto.SubscribePvUvHourDTO; | ||
5 | import com.topdraw.business.module.subscribe.hour.service.dto.SubscribePvUvHourQueryCriteria; | ||
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 XiangHan | ||
14 | * @date 2022-04-20 | ||
15 | */ | ||
16 | public interface SubscribePvUvHourService { | ||
17 | |||
18 | /** | ||
19 | * 根据ID查询 | ||
20 | * @param id ID | ||
21 | * @return SubscribePvUvHourDTO | ||
22 | */ | ||
23 | SubscribePvUvHourDTO findById(Long id); | ||
24 | |||
25 | void create(SubscribePvUvHour resources); | ||
26 | |||
27 | void update(SubscribePvUvHour resources); | ||
28 | |||
29 | void delete(Long id); | ||
30 | |||
31 | SubscribePvUvHour findByMarketingActivityCodeAndPackageIdAndDayAndHour(String code, String packageId, String toString, int hour); | ||
32 | |||
33 | void updateByMarketingActivityCodeAndDayAndHourAndPackageId(SubscribePvUvHour subscribePvUvHour); | ||
34 | } |
src/main/java/com/topdraw/business/module/subscribe/hour/service/dto/SubscribePvUvHourDTO.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.hour.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import java.sql.Timestamp; | ||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2022-04-20 | ||
11 | */ | ||
12 | @Data | ||
13 | public class SubscribePvUvHourDTO implements Serializable { | ||
14 | |||
15 | // ID | ||
16 | private Long id; | ||
17 | |||
18 | // 营销活动ID | ||
19 | private Long marketingActivityId; | ||
20 | |||
21 | // 营销活动标识 | ||
22 | private String marketingActivityCode; | ||
23 | |||
24 | // 产品包id | ||
25 | private String packageId; | ||
26 | |||
27 | // 产品包标识 | ||
28 | private String packageCode; | ||
29 | |||
30 | // 产品包名称 | ||
31 | private String packageName; | ||
32 | |||
33 | // 日期 | ||
34 | private String day; | ||
35 | |||
36 | // 小时(0-23) | ||
37 | private Integer hour; | ||
38 | |||
39 | // 订购按钮总点击量 | ||
40 | private Long btnClickPv; | ||
41 | |||
42 | // 订购按钮总点击人数 | ||
43 | private Long btnClickUv; | ||
44 | |||
45 | // 订购成功人数 | ||
46 | private Long subscribeNum; | ||
47 | |||
48 | // 创建时间 | ||
49 | private Timestamp createTime; | ||
50 | |||
51 | // 更新时间 | ||
52 | private Timestamp updateTime; | ||
53 | } |
1 | package com.topdraw.business.module.subscribe.hour.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.hour.domain.SubscribePvUvHour; | ||
4 | import com.topdraw.utils.ValidationUtil; | ||
5 | import com.topdraw.utils.FileUtil; | ||
6 | import com.topdraw.business.module.subscribe.hour.repository.SubscribePvUvHourRepository; | ||
7 | import com.topdraw.business.module.subscribe.hour.service.SubscribePvUvHourService; | ||
8 | import com.topdraw.business.module.subscribe.hour.service.dto.SubscribePvUvHourDTO; | ||
9 | import com.topdraw.business.module.subscribe.hour.service.dto.SubscribePvUvHourQueryCriteria; | ||
10 | import com.topdraw.business.module.subscribe.hour.service.mapper.SubscribePvUvHourMapper; | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | ||
12 | import org.springframework.stereotype.Service; | ||
13 | import org.springframework.transaction.annotation.Propagation; | ||
14 | import org.springframework.transaction.annotation.Transactional; | ||
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.util.Assert; | ||
19 | import com.topdraw.utils.PageUtil; | ||
20 | import com.topdraw.utils.QueryHelp; | ||
21 | import com.topdraw.utils.StringUtils; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.io.IOException; | ||
26 | import javax.servlet.http.HttpServletResponse; | ||
27 | import java.util.ArrayList; | ||
28 | import java.util.LinkedHashMap; | ||
29 | |||
30 | /** | ||
31 | * @author XiangHan | ||
32 | * @date 2022-04-20 | ||
33 | */ | ||
34 | @Service | ||
35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
36 | public class SubscribePvUvHourServiceImpl implements SubscribePvUvHourService { | ||
37 | |||
38 | @Autowired | ||
39 | private SubscribePvUvHourRepository SubscribePvUvHourRepository; | ||
40 | |||
41 | @Autowired | ||
42 | private SubscribePvUvHourMapper SubscribePvUvHourMapper; | ||
43 | |||
44 | @Override | ||
45 | public SubscribePvUvHourDTO findById(Long id) { | ||
46 | SubscribePvUvHour SubscribePvUvHour = SubscribePvUvHourRepository.findById(id).orElseGet(SubscribePvUvHour::new); | ||
47 | ValidationUtil.isNull(SubscribePvUvHour.getId(),"SubscribePvUvHour","id",id); | ||
48 | return SubscribePvUvHourMapper.toDto(SubscribePvUvHour); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | @Transactional(rollbackFor = Exception.class) | ||
53 | public void create(SubscribePvUvHour resources) { | ||
54 | SubscribePvUvHourRepository.save(resources); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void update(SubscribePvUvHour resources) { | ||
60 | SubscribePvUvHour SubscribePvUvHour = SubscribePvUvHourRepository.findById(resources.getId()).orElseGet(SubscribePvUvHour::new); | ||
61 | ValidationUtil.isNull( SubscribePvUvHour.getId(),"SubscribePvUvHour","id",resources.getId()); | ||
62 | SubscribePvUvHour.copy(resources); | ||
63 | SubscribePvUvHourRepository.save(SubscribePvUvHour); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | @Transactional(rollbackFor = Exception.class) | ||
68 | public void delete(Long id) { | ||
69 | Assert.notNull(id, "The given id must not be null!"); | ||
70 | SubscribePvUvHour SubscribePvUvHour = SubscribePvUvHourRepository.findById(id).orElseThrow( | ||
71 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", SubscribePvUvHour.class, id), 1)); | ||
72 | SubscribePvUvHourRepository.delete(SubscribePvUvHour); | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | public SubscribePvUvHour findByMarketingActivityCodeAndPackageIdAndDayAndHour(String code, String packageId, String day, int hour) { | ||
77 | SubscribePvUvHour SubscribePvUvHour = | ||
78 | SubscribePvUvHourRepository.findByMarketingActivityCodeAndPackageIdAndDayAndHour(code, packageId, day, hour).orElseGet(SubscribePvUvHour::new); | ||
79 | return SubscribePvUvHour; | ||
80 | } | ||
81 | |||
82 | @Override | ||
83 | public void updateByMarketingActivityCodeAndDayAndHourAndPackageId(SubscribePvUvHour subscribePvUvHour) { | ||
84 | |||
85 | } | ||
86 | |||
87 | |||
88 | } |
src/main/java/com/topdraw/business/module/subscribe/hour/service/mapper/SubscribePvUvHourMapper.java
0 → 100644
1 | package com.topdraw.business.module.subscribe.hour.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.module.subscribe.hour.domain.SubscribePvUvHour; | ||
5 | import com.topdraw.business.module.subscribe.hour.service.dto.SubscribePvUvHourDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2022-04-20 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface SubscribePvUvHourMapper extends BaseMapper<SubscribePvUvHourDTO, SubscribePvUvHour> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.module.uv.all.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 | import java.sql.Timestamp; | ||
12 | |||
13 | import java.io.Serializable; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2022-02-26 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_pv_uv") | ||
24 | public class PvUv 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 营销活动标识 | ||
37 | @Column(name = "marketing_activity_code", nullable = false) | ||
38 | private String marketingActivityCode; | ||
39 | |||
40 | // pv值 | ||
41 | @Column(name = "pv", nullable = false) | ||
42 | private Integer pv; | ||
43 | |||
44 | // uv值 | ||
45 | @Column(name = "uv", nullable = false) | ||
46 | private Integer uv; | ||
47 | |||
48 | // 创建时间 | ||
49 | @CreatedDate | ||
50 | @Column(name = "create_time") | ||
51 | private Timestamp createTime; | ||
52 | |||
53 | // 更新时间 | ||
54 | @LastModifiedDate | ||
55 | @Column(name = "update_time") | ||
56 | private Timestamp updateTime; | ||
57 | |||
58 | public void copy(PvUv source){ | ||
59 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
60 | } | ||
61 | } |
1 | package com.topdraw.business.module.uv.all.repository; | ||
2 | |||
3 | import com.topdraw.business.module.uv.all.domain.PvUv; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | import org.springframework.data.jpa.repository.Modifying; | ||
7 | import org.springframework.data.jpa.repository.Query; | ||
8 | import org.springframework.data.repository.query.Param; | ||
9 | import org.springframework.transaction.annotation.Transactional; | ||
10 | |||
11 | import java.util.Optional; | ||
12 | |||
13 | /** | ||
14 | * @author XiangHan | ||
15 | * @date 2022-02-26 | ||
16 | */ | ||
17 | public interface PvUvRepository extends JpaRepository<PvUv, Long>, JpaSpecificationExecutor<PvUv> { | ||
18 | |||
19 | @Modifying | ||
20 | @Transactional | ||
21 | @Query(value = "update act_pv_uv set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + | ||
22 | "update_time = :#{#resources.updateTime} where marketing_activity_code = :#{#resources.marketingActivityCode} " , nativeQuery = true) | ||
23 | void updateByMarketingActivityId(@Param("resources") PvUv resources); | ||
24 | |||
25 | Optional<PvUv> findByMarketingActivityCode(String marketingActivityCode); | ||
26 | |||
27 | Optional<PvUv> findByMarketingActivityId(Long mActivityId); | ||
28 | } |
1 | package com.topdraw.business.module.uv.all.service; | ||
2 | |||
3 | import com.topdraw.business.module.uv.all.domain.PvUv; | ||
4 | import com.topdraw.business.module.uv.all.service.dto.PvUvDTO; | ||
5 | import com.topdraw.business.module.uv.all.service.dto.PvUvQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | import org.springframework.transaction.annotation.Transactional; | ||
8 | |||
9 | import java.util.Map; | ||
10 | import java.util.List; | ||
11 | import java.io.IOException; | ||
12 | import javax.servlet.http.HttpServletResponse; | ||
13 | |||
14 | /** | ||
15 | * @author XiangHan | ||
16 | * @date 2022-02-26 | ||
17 | */ | ||
18 | public interface PvUvService { | ||
19 | |||
20 | /** | ||
21 | * 查询数据分页 | ||
22 | * @param criteria 条件参数 | ||
23 | * @param pageable 分页参数 | ||
24 | * @return Map<String,Object> | ||
25 | */ | ||
26 | Map<String,Object> queryAll(PvUvQueryCriteria criteria, Pageable pageable); | ||
27 | |||
28 | /** | ||
29 | * 查询所有数据不分页 | ||
30 | * @param criteria 条件参数 | ||
31 | * @return List<PvUvDTO> | ||
32 | */ | ||
33 | List<PvUvDTO> queryAll(PvUvQueryCriteria criteria); | ||
34 | |||
35 | /** | ||
36 | * 根据ID查询 | ||
37 | * @param id ID | ||
38 | * @return PvUvDTO | ||
39 | */ | ||
40 | PvUvDTO findById(Long id); | ||
41 | |||
42 | void create(PvUv resources); | ||
43 | |||
44 | @Transactional(rollbackFor = Exception.class) | ||
45 | void updateByMarketingActivityId(PvUv resources); | ||
46 | |||
47 | void update(PvUv resources); | ||
48 | |||
49 | void delete(Long id); | ||
50 | |||
51 | PvUv findByMarketingActivityCode(String code); | ||
52 | |||
53 | PvUv findByMarketingActivityId(Long parseLong); | ||
54 | } |
1 | package com.topdraw.business.module.uv.all.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import java.sql.Timestamp; | ||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2022-02-26 | ||
11 | */ | ||
12 | @Data | ||
13 | public class PvUvDTO implements Serializable { | ||
14 | |||
15 | // ID | ||
16 | private Long id; | ||
17 | |||
18 | // 营销活动ID | ||
19 | private Long marketingActivityId; | ||
20 | |||
21 | // 营销活动标识 | ||
22 | private String marketingActivityCode; | ||
23 | |||
24 | // pv值 | ||
25 | private Long pv; | ||
26 | |||
27 | // uv值 | ||
28 | private Long uv; | ||
29 | |||
30 | // 创建时间 | ||
31 | private Timestamp createTime; | ||
32 | |||
33 | // 更新时间 | ||
34 | private Timestamp updateTime; | ||
35 | } |
1 | package com.topdraw.business.module.uv.all.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.uv.all.domain.PvUv; | ||
4 | import com.topdraw.utils.ValidationUtil; | ||
5 | import com.topdraw.utils.FileUtil; | ||
6 | import com.topdraw.business.module.uv.all.repository.PvUvRepository; | ||
7 | import com.topdraw.business.module.uv.all.service.PvUvService; | ||
8 | import com.topdraw.business.module.uv.all.service.dto.PvUvDTO; | ||
9 | import com.topdraw.business.module.uv.all.service.dto.PvUvQueryCriteria; | ||
10 | import com.topdraw.business.module.uv.all.service.mapper.PvUvMapper; | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | ||
12 | import org.springframework.stereotype.Service; | ||
13 | import org.springframework.transaction.annotation.Propagation; | ||
14 | import org.springframework.transaction.annotation.Transactional; | ||
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.util.Assert; | ||
19 | import com.topdraw.utils.PageUtil; | ||
20 | import com.topdraw.utils.QueryHelp; | ||
21 | import com.topdraw.utils.StringUtils; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.io.IOException; | ||
26 | import javax.servlet.http.HttpServletResponse; | ||
27 | import java.util.ArrayList; | ||
28 | import java.util.LinkedHashMap; | ||
29 | |||
30 | /** | ||
31 | * @author XiangHan | ||
32 | * @date 2022-02-26 | ||
33 | */ | ||
34 | @Service | ||
35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
36 | public class PvUvServiceImpl implements PvUvService { | ||
37 | |||
38 | @Autowired | ||
39 | private PvUvRepository PvUvRepository; | ||
40 | |||
41 | @Autowired | ||
42 | private PvUvMapper PvUvMapper; | ||
43 | |||
44 | @Override | ||
45 | public Map<String, Object> queryAll(PvUvQueryCriteria criteria, Pageable pageable) { | ||
46 | Page<PvUv> page = PvUvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
47 | return PageUtil.toPage(page.map(PvUvMapper::toDto)); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public List<PvUvDTO> queryAll(PvUvQueryCriteria criteria) { | ||
52 | return PvUvMapper.toDto(PvUvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public PvUvDTO findById(Long id) { | ||
57 | PvUv PvUv = PvUvRepository.findById(id).orElseGet(PvUv::new); | ||
58 | ValidationUtil.isNull(PvUv.getId(),"PvUv","id",id); | ||
59 | return PvUvMapper.toDto(PvUv); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | @Transactional(rollbackFor = Exception.class) | ||
64 | public void create(PvUv resources) { | ||
65 | PvUvRepository.save(resources); | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | @Transactional(rollbackFor = Exception.class) | ||
70 | public void updateByMarketingActivityId(PvUv resources) { | ||
71 | PvUvRepository.updateByMarketingActivityId(resources); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | @Transactional(rollbackFor = Exception.class) | ||
76 | public void update(PvUv resources) { | ||
77 | PvUv PvUv = PvUvRepository.findById(resources.getId()).orElseGet(PvUv::new); | ||
78 | ValidationUtil.isNull( PvUv.getId(),"PvUv","id",resources.getId()); | ||
79 | PvUv.copy(resources); | ||
80 | PvUvRepository.save(PvUv); | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | @Transactional(rollbackFor = Exception.class) | ||
85 | public void delete(Long id) { | ||
86 | Assert.notNull(id, "The given id must not be null!"); | ||
87 | PvUv PvUv = PvUvRepository.findById(id).orElseThrow( | ||
88 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PvUv.class, id), 1)); | ||
89 | PvUvRepository.delete(PvUv); | ||
90 | } | ||
91 | |||
92 | @Override | ||
93 | public PvUv findByMarketingActivityCode(String code) { | ||
94 | PvUv PvUv = PvUvRepository.findByMarketingActivityCode(code).orElseGet(PvUv::new); | ||
95 | return PvUv; | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public PvUv findByMarketingActivityId(Long mActivityId) { | ||
100 | return PvUvRepository.findByMarketingActivityId(mActivityId).orElseGet(PvUv::new); | ||
101 | } | ||
102 | |||
103 | |||
104 | } |
1 | package com.topdraw.business.module.uv.all.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.module.uv.all.domain.PvUv; | ||
5 | import com.topdraw.business.module.uv.all.service.dto.PvUvDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2022-02-26 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PvUvMapper extends BaseMapper<PvUvDTO, PvUv> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.module.uv.day.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 | import java.sql.Timestamp; | ||
12 | |||
13 | import java.io.Serializable; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2022-02-26 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_pv_uv_day") | ||
24 | public class PvUvDay 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 营销活动标识 | ||
37 | @Column(name = "marketing_activity_code", nullable = false) | ||
38 | private String marketingActivityCode; | ||
39 | |||
40 | // 日期 | ||
41 | @Column(name = "day", nullable = false) | ||
42 | private String day; | ||
43 | |||
44 | // pv值 | ||
45 | @Column(name = "pv", nullable = false) | ||
46 | private Integer pv; | ||
47 | |||
48 | // uv值 | ||
49 | @Column(name = "uv", nullable = false) | ||
50 | private Integer uv; | ||
51 | |||
52 | // 创建时间 | ||
53 | @CreatedDate | ||
54 | @Column(name = "create_time") | ||
55 | private Timestamp createTime; | ||
56 | |||
57 | // 更新时间 | ||
58 | @LastModifiedDate | ||
59 | @Column(name = "update_time") | ||
60 | private Timestamp updateTime; | ||
61 | |||
62 | public void copy(PvUvDay source){ | ||
63 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
64 | } | ||
65 | } |
1 | package com.topdraw.business.module.uv.day.repository; | ||
2 | |||
3 | import com.topdraw.business.module.uv.day.domain.PvUvDay; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | import org.springframework.data.jpa.repository.Modifying; | ||
7 | import org.springframework.data.jpa.repository.Query; | ||
8 | import org.springframework.data.repository.query.Param; | ||
9 | import org.springframework.transaction.annotation.Transactional; | ||
10 | |||
11 | import java.util.Optional; | ||
12 | |||
13 | /** | ||
14 | * @author XiangHan | ||
15 | * @date 2022-02-26 | ||
16 | */ | ||
17 | public interface PvUvDayRepository extends JpaRepository<PvUvDay, Long>, JpaSpecificationExecutor<PvUvDay> { | ||
18 | |||
19 | Optional<PvUvDay> findByMarketingActivityCodeAndDay(String marketingActivityCode, String day); | ||
20 | |||
21 | @Modifying | ||
22 | @Transactional | ||
23 | @Query(value = "update act_pv_uv_day set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + | ||
24 | " update_time = :#{#resources.updateTime} where marketing_activity_code = :#{#resources.marketingActivityCode} and " + | ||
25 | " `day` = :#{#resources.day}" , nativeQuery = true) | ||
26 | void updateByMarketingActivityCodeAndDay(@Param("resources") PvUvDay pvUvDay); | ||
27 | |||
28 | Optional<PvUvDay> findByMarketingActivityIdAndDay(Long mActivityId, String day); | ||
29 | } |
1 | package com.topdraw.business.module.uv.day.service; | ||
2 | |||
3 | import com.topdraw.business.module.uv.day.domain.PvUvDay; | ||
4 | import com.topdraw.business.module.uv.day.service.dto.PvUvDayDTO; | ||
5 | import com.topdraw.business.module.uv.day.service.dto.PvUvDayQueryCriteria; | ||
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 XiangHan | ||
14 | * @date 2022-02-26 | ||
15 | */ | ||
16 | public interface PvUvDayService { | ||
17 | |||
18 | /** | ||
19 | * 查询数据分页 | ||
20 | * @param criteria 条件参数 | ||
21 | * @param pageable 分页参数 | ||
22 | * @return Map<String,Object> | ||
23 | */ | ||
24 | Map<String,Object> queryAll(PvUvDayQueryCriteria criteria, Pageable pageable); | ||
25 | |||
26 | /** | ||
27 | * 查询所有数据不分页 | ||
28 | * @param criteria 条件参数 | ||
29 | * @return List<PvUvDayDTO> | ||
30 | */ | ||
31 | List<PvUvDayDTO> queryAll(PvUvDayQueryCriteria criteria); | ||
32 | |||
33 | /** | ||
34 | * 根据ID查询 | ||
35 | * @param id ID | ||
36 | * @return PvUvDayDTO | ||
37 | */ | ||
38 | PvUvDayDTO findById(Long id); | ||
39 | |||
40 | void create(PvUvDay resources); | ||
41 | |||
42 | void update(PvUvDay resources); | ||
43 | |||
44 | void delete(Long id); | ||
45 | |||
46 | PvUvDay findByMarketingActivityCodeAndDay(String code, String day); | ||
47 | |||
48 | void updateByMarketingActivityCodeAndDay(PvUvDay pvUvDay); | ||
49 | |||
50 | PvUvDay findByMarketingActivityIdAndDay(Long mActivityId, String day); | ||
51 | } |
1 | package com.topdraw.business.module.uv.day.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import java.sql.Timestamp; | ||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2022-02-26 | ||
11 | */ | ||
12 | @Data | ||
13 | public class PvUvDayDTO implements Serializable { | ||
14 | |||
15 | // ID | ||
16 | private Long id; | ||
17 | |||
18 | // 营销活动ID | ||
19 | private Long marketingActivityId; | ||
20 | |||
21 | // 营销活动标识 | ||
22 | private String marketingActivityCode; | ||
23 | |||
24 | // 日期 | ||
25 | private String day; | ||
26 | |||
27 | // pv值 | ||
28 | private Integer pv; | ||
29 | |||
30 | // uv值 | ||
31 | private Integer uv; | ||
32 | |||
33 | // 创建时间 | ||
34 | private Timestamp createTime; | ||
35 | |||
36 | // 更新时间 | ||
37 | private Timestamp updateTime; | ||
38 | } |
1 | package com.topdraw.business.module.uv.day.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.uv.day.domain.PvUvDay; | ||
4 | import com.topdraw.utils.ValidationUtil; | ||
5 | import com.topdraw.utils.FileUtil; | ||
6 | import com.topdraw.business.module.uv.day.repository.PvUvDayRepository; | ||
7 | import com.topdraw.business.module.uv.day.service.PvUvDayService; | ||
8 | import com.topdraw.business.module.uv.day.service.dto.PvUvDayDTO; | ||
9 | import com.topdraw.business.module.uv.day.service.dto.PvUvDayQueryCriteria; | ||
10 | import com.topdraw.business.module.uv.day.service.mapper.PvUvDayMapper; | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | ||
12 | import org.springframework.stereotype.Service; | ||
13 | import org.springframework.transaction.annotation.Propagation; | ||
14 | import org.springframework.transaction.annotation.Transactional; | ||
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.util.Assert; | ||
19 | import com.topdraw.utils.PageUtil; | ||
20 | import com.topdraw.utils.QueryHelp; | ||
21 | import com.topdraw.utils.StringUtils; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.io.IOException; | ||
26 | import javax.servlet.http.HttpServletResponse; | ||
27 | import java.util.ArrayList; | ||
28 | import java.util.LinkedHashMap; | ||
29 | |||
30 | /** | ||
31 | * @author XiangHan | ||
32 | * @date 2022-02-26 | ||
33 | */ | ||
34 | @Service | ||
35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
36 | public class PvUvDayServiceImpl implements PvUvDayService { | ||
37 | |||
38 | @Autowired | ||
39 | private PvUvDayRepository PvUvDayRepository; | ||
40 | |||
41 | @Autowired | ||
42 | private PvUvDayMapper PvUvDayMapper; | ||
43 | |||
44 | @Override | ||
45 | public Map<String, Object> queryAll(PvUvDayQueryCriteria criteria, Pageable pageable) { | ||
46 | Page<PvUvDay> page = PvUvDayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
47 | return PageUtil.toPage(page.map(PvUvDayMapper::toDto)); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public List<PvUvDayDTO> queryAll(PvUvDayQueryCriteria criteria) { | ||
52 | return PvUvDayMapper.toDto(PvUvDayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public PvUvDayDTO findById(Long id) { | ||
57 | PvUvDay PvUvDay = PvUvDayRepository.findById(id).orElseGet(PvUvDay::new); | ||
58 | ValidationUtil.isNull(PvUvDay.getId(),"PvUvDay","id",id); | ||
59 | return PvUvDayMapper.toDto(PvUvDay); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | @Transactional(rollbackFor = Exception.class) | ||
64 | public void create(PvUvDay resources) { | ||
65 | PvUvDayRepository.save(resources); | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | @Transactional(rollbackFor = Exception.class) | ||
70 | public void update(PvUvDay resources) { | ||
71 | PvUvDay PvUvDay = PvUvDayRepository.findById(resources.getId()).orElseGet(PvUvDay::new); | ||
72 | ValidationUtil.isNull( PvUvDay.getId(),"PvUvDay","id",resources.getId()); | ||
73 | PvUvDay.copy(resources); | ||
74 | PvUvDayRepository.save(PvUvDay); | ||
75 | } | ||
76 | |||
77 | @Override | ||
78 | @Transactional(rollbackFor = Exception.class) | ||
79 | public void delete(Long id) { | ||
80 | Assert.notNull(id, "The given id must not be null!"); | ||
81 | PvUvDay PvUvDay = PvUvDayRepository.findById(id).orElseThrow( | ||
82 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PvUvDay.class, id), 1)); | ||
83 | PvUvDayRepository.delete(PvUvDay); | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public PvUvDay findByMarketingActivityCodeAndDay(String code, String day) { | ||
88 | PvUvDay PvUvDay = PvUvDayRepository.findByMarketingActivityCodeAndDay(code,day).orElseGet(PvUvDay::new); | ||
89 | return PvUvDay; | ||
90 | } | ||
91 | |||
92 | @Override | ||
93 | public void updateByMarketingActivityCodeAndDay(PvUvDay pvUvDay) { | ||
94 | PvUvDayRepository.updateByMarketingActivityCodeAndDay(pvUvDay); | ||
95 | } | ||
96 | |||
97 | @Override | ||
98 | public PvUvDay findByMarketingActivityIdAndDay(Long mActivityId, String day) { | ||
99 | return PvUvDayRepository.findByMarketingActivityIdAndDay(mActivityId, day).orElseGet(PvUvDay::new); | ||
100 | } | ||
101 | |||
102 | |||
103 | } |
1 | package com.topdraw.business.module.uv.day.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.module.uv.day.domain.PvUvDay; | ||
5 | import com.topdraw.business.module.uv.day.service.dto.PvUvDayDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2022-02-26 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PvUvDayMapper extends BaseMapper<PvUvDayDTO, PvUvDay> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.module.uv.hour.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 | import java.sql.Timestamp; | ||
12 | |||
13 | import java.io.Serializable; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2022-02-26 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="act_pv_uv_hour") | ||
24 | public class PvUvHour 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 = "marketing_activity_id", nullable = false) | ||
34 | private Long marketingActivityId; | ||
35 | |||
36 | // 营销活动标识 | ||
37 | @Column(name = "marketing_activity_code", nullable = false) | ||
38 | private String marketingActivityCode; | ||
39 | |||
40 | // 日期 | ||
41 | @Column(name = "day", nullable = false) | ||
42 | private String day; | ||
43 | |||
44 | // 小时(0-23) | ||
45 | @Column(name = "hour", nullable = false) | ||
46 | private Integer hour; | ||
47 | |||
48 | // pv值 | ||
49 | @Column(name = "pv", nullable = false) | ||
50 | private Integer pv; | ||
51 | |||
52 | // uv值 | ||
53 | @Column(name = "uv", nullable = false) | ||
54 | private Integer uv; | ||
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(PvUvHour source){ | ||
67 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
68 | } | ||
69 | } |
1 | package com.topdraw.business.module.uv.hour.repository; | ||
2 | |||
3 | import com.topdraw.business.module.uv.hour.domain.PvUvHour; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | import org.springframework.data.jpa.repository.Modifying; | ||
7 | import org.springframework.data.jpa.repository.Query; | ||
8 | import org.springframework.data.repository.query.Param; | ||
9 | import org.springframework.transaction.annotation.Transactional; | ||
10 | |||
11 | import java.util.Optional; | ||
12 | |||
13 | /** | ||
14 | * @author XiangHan | ||
15 | * @date 2022-02-26 | ||
16 | */ | ||
17 | public interface PvUvHourRepository extends JpaRepository<PvUvHour, Long>, JpaSpecificationExecutor<PvUvHour> { | ||
18 | |||
19 | Optional<PvUvHour> findByMarketingActivityCodeAndDayAndHour(String code, String day, int hour); | ||
20 | |||
21 | Optional<PvUvHour> findByMarketingActivityIdAndDayAndHour(Long id, String day, int hour); | ||
22 | |||
23 | @Modifying | ||
24 | @Transactional | ||
25 | @Query(value = "update act_pv_uv_hour set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + | ||
26 | "update_time = :#{#resources.updateTime} where marketing_activity_code = :#{#resources.marketingActivityCode} and " + | ||
27 | " `day` = :#{#resources.day} and `hour` = :#{#resources.hour}" , nativeQuery = true) | ||
28 | void updateByMarketingActivityCodeAndDayAndHour(@Param("resources") PvUvHour pvUvHour); | ||
29 | |||
30 | @Query(value = "select SUM(pv) pv ,SUM(uv) pv from (\n" + | ||
31 | "select pv,uv from act_pv_uv_hour where `marketing_activity_code` = ?1 and `day` = ?2 and `hour` = ?3) t " , nativeQuery = true) | ||
32 | Integer calculatePvDay(@Param("code") String code, @Param("day") String day, @Param("hour") int hour); | ||
33 | } |
1 | package com.topdraw.business.module.uv.hour.service; | ||
2 | |||
3 | import com.topdraw.business.module.uv.hour.domain.PvUvHour; | ||
4 | import com.topdraw.business.module.uv.hour.service.dto.PvUvHourDTO; | ||
5 | import com.topdraw.business.module.uv.hour.service.dto.PvUvHourQueryCriteria; | ||
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 XiangHan | ||
14 | * @date 2022-02-26 | ||
15 | */ | ||
16 | public interface PvUvHourService { | ||
17 | |||
18 | /** | ||
19 | * 根据ID查询 | ||
20 | * @param id ID | ||
21 | * @return PvUvHourDTO | ||
22 | */ | ||
23 | PvUvHourDTO findById(Long id); | ||
24 | |||
25 | void create(PvUvHour resources); | ||
26 | |||
27 | void update(PvUvHour resources); | ||
28 | |||
29 | void delete(Long id); | ||
30 | |||
31 | PvUvHour findByMarketingActivityCodeAndDayAndHour(String code, String toString, int hour); | ||
32 | |||
33 | void updateByMarketingActivityCodeAndDayAndHour(PvUvHour pvUvHour); | ||
34 | |||
35 | Integer calculatePvDay(String code, String toString, int hour); | ||
36 | |||
37 | PvUvHour findByMarketingActivityIdAndDayAndHour(Long parseLong, String toString, int hour); | ||
38 | } |
1 | package com.topdraw.business.module.uv.hour.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import java.sql.Timestamp; | ||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author XiangHan | ||
10 | * @date 2022-02-26 | ||
11 | */ | ||
12 | @Data | ||
13 | public class PvUvHourDTO implements Serializable { | ||
14 | |||
15 | // ID | ||
16 | private Long id; | ||
17 | |||
18 | // 营销活动ID | ||
19 | private Long marketingActivityId; | ||
20 | |||
21 | // 营销活动标识 | ||
22 | private String marketingActivityCode; | ||
23 | |||
24 | // 日期 | ||
25 | private String day; | ||
26 | |||
27 | // 小时(0-23) | ||
28 | private Integer hour; | ||
29 | |||
30 | // pv值 | ||
31 | private Integer pv; | ||
32 | |||
33 | // uv值 | ||
34 | private Integer uv; | ||
35 | |||
36 | // 创建时间 | ||
37 | private Timestamp createTime; | ||
38 | |||
39 | // 更新时间 | ||
40 | private Timestamp updateTime; | ||
41 | } |
1 | package com.topdraw.business.module.uv.hour.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.uv.hour.domain.PvUvHour; | ||
4 | import com.topdraw.utils.ValidationUtil; | ||
5 | import com.topdraw.utils.FileUtil; | ||
6 | import com.topdraw.business.module.uv.hour.repository.PvUvHourRepository; | ||
7 | import com.topdraw.business.module.uv.hour.service.PvUvHourService; | ||
8 | import com.topdraw.business.module.uv.hour.service.dto.PvUvHourDTO; | ||
9 | import com.topdraw.business.module.uv.hour.service.dto.PvUvHourQueryCriteria; | ||
10 | import com.topdraw.business.module.uv.hour.service.mapper.PvUvHourMapper; | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | ||
12 | import org.springframework.stereotype.Service; | ||
13 | import org.springframework.transaction.annotation.Propagation; | ||
14 | import org.springframework.transaction.annotation.Transactional; | ||
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.util.Assert; | ||
19 | import com.topdraw.utils.PageUtil; | ||
20 | import com.topdraw.utils.QueryHelp; | ||
21 | import com.topdraw.utils.StringUtils; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.io.IOException; | ||
26 | import javax.servlet.http.HttpServletResponse; | ||
27 | import java.util.ArrayList; | ||
28 | import java.util.LinkedHashMap; | ||
29 | |||
30 | /** | ||
31 | * @author XiangHan | ||
32 | * @date 2022-02-26 | ||
33 | */ | ||
34 | @Service | ||
35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
36 | public class PvUvHourServiceImpl implements PvUvHourService { | ||
37 | |||
38 | @Autowired | ||
39 | private PvUvHourRepository PvUvHourRepository; | ||
40 | |||
41 | @Autowired | ||
42 | private PvUvHourMapper PvUvHourMapper; | ||
43 | |||
44 | @Override | ||
45 | public PvUvHourDTO findById(Long id) { | ||
46 | PvUvHour PvUvHour = PvUvHourRepository.findById(id).orElseGet(PvUvHour::new); | ||
47 | ValidationUtil.isNull(PvUvHour.getId(),"PvUvHour","id",id); | ||
48 | return PvUvHourMapper.toDto(PvUvHour); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | @Transactional(rollbackFor = Exception.class) | ||
53 | public void create(PvUvHour resources) { | ||
54 | PvUvHourRepository.save(resources); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | @Transactional(rollbackFor = Exception.class) | ||
59 | public void update(PvUvHour resources) { | ||
60 | PvUvHour PvUvHour = PvUvHourRepository.findById(resources.getId()).orElseGet(PvUvHour::new); | ||
61 | ValidationUtil.isNull( PvUvHour.getId(),"PvUvHour","id",resources.getId()); | ||
62 | PvUvHour.copy(resources); | ||
63 | PvUvHourRepository.save(PvUvHour); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | @Transactional(rollbackFor = Exception.class) | ||
68 | public void delete(Long id) { | ||
69 | Assert.notNull(id, "The given id must not be null!"); | ||
70 | PvUvHour PvUvHour = PvUvHourRepository.findById(id).orElseThrow( | ||
71 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PvUvHour.class, id), 1)); | ||
72 | PvUvHourRepository.delete(PvUvHour); | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | public PvUvHour findByMarketingActivityCodeAndDayAndHour(String code, String day, int hour) { | ||
77 | PvUvHour PvUvHour = PvUvHourRepository.findByMarketingActivityCodeAndDayAndHour(code,day,hour).orElseGet(PvUvHour::new); | ||
78 | return PvUvHour; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public void updateByMarketingActivityCodeAndDayAndHour(PvUvHour pvUvHour) { | ||
83 | PvUvHourRepository.updateByMarketingActivityCodeAndDayAndHour(pvUvHour); | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public Integer calculatePvDay(String code, String day, int hour) { | ||
88 | Integer count = PvUvHourRepository.calculatePvDay(code,day,hour); | ||
89 | return count; | ||
90 | } | ||
91 | |||
92 | @Override | ||
93 | public PvUvHour findByMarketingActivityIdAndDayAndHour(Long mActivityId, String day, int hour) { | ||
94 | return PvUvHourRepository.findByMarketingActivityIdAndDayAndHour(mActivityId, day, hour).orElseGet(PvUvHour::new); | ||
95 | } | ||
96 | |||
97 | |||
98 | } |
1 | package com.topdraw.business.module.uv.hour.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.module.uv.hour.domain.PvUvHour; | ||
5 | import com.topdraw.business.module.uv.hour.service.dto.PvUvHourDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2022-02-26 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface PvUvHourMapper extends BaseMapper<PvUvHourDTO, PvUvHour> { | ||
15 | |||
16 | } |
src/main/java/com/topdraw/business/process/calculate/task/ActivityBtnClickPvUcCalculateTask.java
0 → 100644
1 | package com.topdraw.business.process.calculate.task; | ||
2 | |||
3 | import com.topdraw.business.module.activitybtn.all.domain.ActTplParamClick; | ||
4 | import com.topdraw.business.module.activitybtn.all.service.ActivityBtnPvUvService; | ||
5 | import com.topdraw.business.module.activitybtn.day.domain.ActTplParamClickDay; | ||
6 | import com.topdraw.business.module.activitybtn.day.service.ActivityBtnPvUvDayService; | ||
7 | import com.topdraw.business.module.activitybtn.hour.domain.ActTplParamClickHour; | ||
8 | import com.topdraw.business.module.activitybtn.hour.service.ActivityBtnPvUvHourService; | ||
9 | import com.topdraw.util.TimestampUtil; | ||
10 | import com.topdraw.utils.RedisUtils; | ||
11 | import lombok.extern.slf4j.Slf4j; | ||
12 | import org.apache.commons.collections4.CollectionUtils; | ||
13 | import org.apache.commons.lang3.StringUtils; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | ||
15 | import org.springframework.boot.autoconfigure.data.redis.RedisProperties; | ||
16 | import org.springframework.jdbc.core.JdbcTemplate; | ||
17 | import org.springframework.stereotype.Service; | ||
18 | import org.springframework.transaction.annotation.Propagation; | ||
19 | import org.springframework.transaction.annotation.Transactional; | ||
20 | import redis.clients.jedis.Jedis; | ||
21 | |||
22 | import java.time.LocalDate; | ||
23 | import java.time.LocalDateTime; | ||
24 | import java.util.*; | ||
25 | |||
26 | /** | ||
27 | * @author : | ||
28 | * @description: | ||
29 | * @function : | ||
30 | * @date :Created in 2022/2/26 19:40 | ||
31 | * @version: : | ||
32 | * @modified By: | ||
33 | * @since : modified in 2022/2/26 19:40 | ||
34 | */ | ||
35 | |||
36 | @Service | ||
37 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
38 | @Slf4j | ||
39 | public class ActivityBtnClickPvUcCalculateTask { | ||
40 | |||
41 | @Autowired | ||
42 | private Jedis redisUtils; | ||
43 | @Autowired | ||
44 | private JdbcTemplate jdbcTemplate; | ||
45 | |||
46 | @Autowired | ||
47 | private ActivityBtnPvUvService activityBtnPvUvService; | ||
48 | @Autowired | ||
49 | private ActivityBtnPvUvDayService activityBtnPvUvDayService; | ||
50 | @Autowired | ||
51 | private ActivityBtnPvUvHourService activityBtnPvUvHourService; | ||
52 | |||
53 | |||
54 | private List<Map<String,Object>> getAllMarketingActivityCode(){ | ||
55 | String sql = "SELECT tadr.`id` AS `id`,tadr.`code` AS `code` , tadr.`end_time` AS `endTime` FROM `act_marketing_activity` tadr WHERE " + | ||
56 | " now() BETWEEN `start_time` AND DATE_ADD(`end_time`,INTERVAL 3 DAY) GROUP BY `code`"; | ||
57 | return this.jdbcTemplate.queryForList(sql); | ||
58 | } | ||
59 | |||
60 | |||
61 | public void calculateRedisData2Mysql() { | ||
62 | |||
63 | List<Map<String, Object>> allMarketingActivityCode = this.getAllMarketingActivityCode(); | ||
64 | |||
65 | if (CollectionUtils.isNotEmpty(allMarketingActivityCode)) { | ||
66 | |||
67 | for (Map<String, Object> map : allMarketingActivityCode) { | ||
68 | |||
69 | // 营销活动code | ||
70 | Object codeObj = map.get("code"); | ||
71 | Object idObj = map.get("id"); | ||
72 | if (Objects.nonNull(codeObj) && Objects.nonNull(idObj)) { | ||
73 | String code = codeObj.toString(); | ||
74 | String id = idObj.toString(); | ||
75 | log.info("marktingActivity ===>>> code ====>>> [{}]", code); | ||
76 | |||
77 | LocalDateTime endTime = (LocalDateTime) map.get("endTime"); | ||
78 | |||
79 | if (Objects.nonNull(endTime)) { | ||
80 | |||
81 | String marktingActivityCode =""; | ||
82 | Long marktingActivityId = 0L; | ||
83 | String activityCode = ""; | ||
84 | Long activityId = 0L; | ||
85 | Long paramValueId = 0L; | ||
86 | String name = ""; | ||
87 | |||
88 | // 获取此营销活动对应的参数,格式 事件code-按钮id | ||
89 | Set<String> codeAndBtnIds = this.redisUtils.smembers("MS_M_ACTIVITY_CODE|"+code); | ||
90 | if (Objects.nonNull(codeAndBtnIds) && CollectionUtils.isNotEmpty(codeAndBtnIds)){ | ||
91 | for (String s1 : codeAndBtnIds) { | ||
92 | log.info("营销活动code、活动事件code ==>> {}", s1); | ||
93 | String[] split = s1.split("#"); | ||
94 | |||
95 | if (split.length == 0) { | ||
96 | split = s1.split("-"); | ||
97 | } | ||
98 | |||
99 | if (split.length == 0) { | ||
100 | continue; | ||
101 | } | ||
102 | log.info("分割后的结果 ==>> {}", split); | ||
103 | try { | ||
104 | marktingActivityCode = code; | ||
105 | log.info("营销活动code ==>> {}", marktingActivityCode); | ||
106 | marktingActivityId = this.findMarktingActivityByCode(marktingActivityCode); | ||
107 | if (Objects.isNull(marktingActivityId)) { | ||
108 | log.error("模板按钮点击次数统计异常,通过活动code无法获取营销活动, marktingActivityCode ==>> {}", marktingActivityCode); | ||
109 | continue; | ||
110 | } | ||
111 | activityCode = split[0]; | ||
112 | log.info("活动事件code ==>> {}", activityCode); | ||
113 | activityId = this.findActivityByCode(activityCode); | ||
114 | log.info("活动事件Id ==>> {}", activityId); | ||
115 | if (Objects.isNull(activityId)) { | ||
116 | log.warn("模板按钮点击次数统计异常,通过活动事件code无法获取活动事件, activityCode ==>> {}", activityCode); | ||
117 | // continue; | ||
118 | } | ||
119 | paramValueId = Long.valueOf(split[1]); | ||
120 | log.info("模板属性id ==>> {}", paramValueId); | ||
121 | name = this.findParamValueByValueId(paramValueId); | ||
122 | log.info("模板属性名称 ==>> {}", name); | ||
123 | if (StringUtils.isBlank(name)) { | ||
124 | log.warn("模板按钮点击次数统计异常,无实例内容名称, paramValueId ==>> {}", paramValueId); | ||
125 | name = "#"; | ||
126 | // continue; | ||
127 | } | ||
128 | } catch (Exception e) { | ||
129 | log.error(e.getMessage()); | ||
130 | continue; | ||
131 | } | ||
132 | |||
133 | log.info("活动结束时间 ==>> {}", endTime); | ||
134 | // 活动结束删除所有的对应的key | ||
135 | if (endTime.compareTo(LocalDateTime.now()) <= 0) { | ||
136 | log.warn("活动结束,活动结束时间两天后删除活动code对应的所有key"); | ||
137 | if (endTime.plusDays(2).compareTo(LocalDateTime.now()) <= 0) { | ||
138 | |||
139 | Set<String> keys = this.redisUtils.keys("*|" + code+"#"+activityCode+"#"+paramValueId + "*"); | ||
140 | if (CollectionUtils.isNotEmpty(keys)) { | ||
141 | for (Object key : keys) { | ||
142 | this.redisUtils.del(key.toString()); | ||
143 | log.info("删除活动code对应的所有的key --->>{},成功", key); | ||
144 | } | ||
145 | } else { | ||
146 | keys = this.redisUtils.keys("*|" + code+"-"+activityCode+"-"+paramValueId + "*"); | ||
147 | if (CollectionUtils.isNotEmpty(keys)) { | ||
148 | for (Object key : keys) { | ||
149 | this.redisUtils.del(key.toString()); | ||
150 | log.info("删除活动code对应的所有的key --->>{},成功", key); | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | |||
155 | // 删除营销活动下所有的活动事件对应的按钮 | ||
156 | Set<String> keys_ = this.redisUtils.keys("MS_M_ACTIVITY_CODE|" + code); | ||
157 | if (CollectionUtils.isNotEmpty(keys_)) { | ||
158 | this.redisUtils.del("MS_M_ACTIVITY_CODE|" + code); | ||
159 | log.info("删除活动code对应的所有的key --->>{},成功 ", "MS_M_ACTIVITY_CODE|" + code); | ||
160 | |||
161 | } | ||
162 | |||
163 | } | ||
164 | continue; | ||
165 | } | ||
166 | |||
167 | // 小时pv、uv值 | ||
168 | ActTplParamClickHour activityBtnPvUvHour_ = | ||
169 | this.activityBtnPvUvHourService. | ||
170 | findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDayAndHour(marktingActivityId, | ||
171 | activityId, paramValueId, LocalDate.now().toString(),LocalDateTime.now().getHour()); | ||
172 | |||
173 | if (Objects.isNull(activityBtnPvUvHour_.getId())) { | ||
174 | // 新增 | ||
175 | Integer hourPv = this.getHourPV(marktingActivityCode, activityCode, paramValueId); | ||
176 | Integer hourUv = this.getHourUV(marktingActivityCode, activityCode, paramValueId); | ||
177 | |||
178 | ActTplParamClickHour activityBtnPvUvHour = new ActTplParamClickHour(); | ||
179 | activityBtnPvUvHour.setMarketingActivityId(marktingActivityId); | ||
180 | activityBtnPvUvHour.setActivityId(activityId); | ||
181 | activityBtnPvUvHour.setName(name); | ||
182 | activityBtnPvUvHour.setDay(LocalDate.now().toString()); | ||
183 | activityBtnPvUvHour.setTemplateParamValueId(paramValueId); | ||
184 | activityBtnPvUvHour.setHour(LocalDateTime.now().getHour()); | ||
185 | activityBtnPvUvHour.setPv(hourPv); | ||
186 | activityBtnPvUvHour.setUv(hourUv); | ||
187 | this.activityBtnPvUvHourService.create(activityBtnPvUvHour); | ||
188 | |||
189 | } else { | ||
190 | |||
191 | // 修改 | ||
192 | Integer hourPv = this.getHourPV(marktingActivityCode, activityCode, paramValueId); | ||
193 | Integer hourUv = this.getHourUV(marktingActivityCode, activityCode, paramValueId); | ||
194 | log.info("hourPv ==>> {}", hourPv); | ||
195 | log.info("hourUv ==>> {}", hourUv); | ||
196 | |||
197 | if (hourPv != 0 && hourUv != 0) { | ||
198 | activityBtnPvUvHour_.setPv(hourPv); | ||
199 | activityBtnPvUvHour_.setUv(hourUv); | ||
200 | activityBtnPvUvHour_.setUpdateTime(TimestampUtil.now()); | ||
201 | this.activityBtnPvUvHourService.update(activityBtnPvUvHour_); | ||
202 | } | ||
203 | |||
204 | } | ||
205 | |||
206 | // day pv、uv值 | ||
207 | ActTplParamClickDay pvUvDay1 = this.activityBtnPvUvDayService. | ||
208 | findByMarketingActivityIdAndActivityIdAndTemplateParamValueIdAndDay(marktingActivityId, | ||
209 | activityId, paramValueId, LocalDate.now().toString()); | ||
210 | if(Objects.isNull(pvUvDay1.getId())){ | ||
211 | |||
212 | ActTplParamClickDay activityBtnPvUvDay = new ActTplParamClickDay(); | ||
213 | activityBtnPvUvDay.setMarketingActivityId(marktingActivityId); | ||
214 | activityBtnPvUvDay.setActivityId(activityId); | ||
215 | activityBtnPvUvDay.setDay(LocalDate.now().toString()); | ||
216 | activityBtnPvUvDay.setTemplateParamValueId(paramValueId); | ||
217 | activityBtnPvUvDay.setName(name); | ||
218 | |||
219 | Integer dayPv = this.getDayPV(marktingActivityCode, activityCode, paramValueId); | ||
220 | Integer dayUv = this.getDayUV(marktingActivityCode, activityCode, paramValueId); | ||
221 | log.info("dayPv ==>> {}", dayPv); | ||
222 | log.info("dayUv ==>> {}", dayUv); | ||
223 | activityBtnPvUvDay.setPv(dayPv); | ||
224 | activityBtnPvUvDay.setUv(dayUv); | ||
225 | this.activityBtnPvUvDayService.create(activityBtnPvUvDay); | ||
226 | |||
227 | } else { | ||
228 | |||
229 | Integer dayPv = this.getDayPV(marktingActivityCode, activityCode, paramValueId); | ||
230 | Integer dayUv = this.getDayUV(marktingActivityCode, activityCode, paramValueId); | ||
231 | log.info("dayPv ==>> {}", dayPv); | ||
232 | log.info("dayUv ==>> {}", dayUv); | ||
233 | if (dayPv != 0 && dayUv != 0) { | ||
234 | pvUvDay1.setPv(dayPv); | ||
235 | pvUvDay1.setUv(dayUv); | ||
236 | pvUvDay1.setUpdateTime(TimestampUtil.now()); | ||
237 | this.activityBtnPvUvDayService.update(pvUvDay1); | ||
238 | } | ||
239 | |||
240 | } | ||
241 | |||
242 | // all | ||
243 | ActTplParamClick pvUv1 = this.activityBtnPvUvService. | ||
244 | findByMarketingActivityIdAndActivityIdAndTemplateParamValueId(marktingActivityId, | ||
245 | activityId, paramValueId); | ||
246 | if(Objects.isNull(pvUv1.getId())){ | ||
247 | |||
248 | ActTplParamClick activityBtnPvUv = new ActTplParamClick(); | ||
249 | activityBtnPvUv.setMarketingActivityId(Long.parseLong(id)); | ||
250 | activityBtnPvUv.setActivityId(activityId); | ||
251 | activityBtnPvUv.setTemplateParamValueId(paramValueId); | ||
252 | activityBtnPvUv.setName(name); | ||
253 | |||
254 | Integer allPV = this.getAllPV(marktingActivityCode, activityCode, paramValueId); | ||
255 | Integer allUv = this.getAllUV(marktingActivityCode, activityCode, paramValueId); | ||
256 | log.info("allPV ==>> {}", allPV); | ||
257 | log.info("allUv ==>> {}", allUv); | ||
258 | activityBtnPvUv.setPv(allPV); | ||
259 | activityBtnPvUv.setUv(allUv); | ||
260 | |||
261 | this.activityBtnPvUvService.create(activityBtnPvUv); | ||
262 | |||
263 | } else { | ||
264 | |||
265 | Integer allPV = this.getAllPV(marktingActivityCode, activityCode, paramValueId); | ||
266 | Integer allUv = this.getAllUV(marktingActivityCode, activityCode, paramValueId); | ||
267 | log.info("allPV ==>> {}", allPV); | ||
268 | log.info("allUv ==>> {}", allUv); | ||
269 | |||
270 | if (allPV != 0 && allUv != 0) { | ||
271 | pvUv1.setPv(allPV); | ||
272 | pvUv1.setUv(allUv); | ||
273 | pvUv1.setUpdateTime(TimestampUtil.now()); | ||
274 | this.activityBtnPvUvService.update(pvUv1); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | } | ||
279 | |||
280 | } | ||
281 | } | ||
282 | |||
283 | } | ||
284 | } | ||
285 | |||
286 | } | ||
287 | |||
288 | } | ||
289 | |||
290 | |||
291 | private Integer getAllUV(String code, String activityCode, Long btnId) { | ||
292 | String key = "MS_ACTIVITY_BTN_UV|"+code+"#"+activityCode+"#"+btnId; | ||
293 | log.info("getAllUV ==>> key ==>> {}", key); | ||
294 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | ||
295 | if (Objects.nonNull(hourBtnClickUV)) { | ||
296 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
297 | } else { | ||
298 | key = "MS_ACTIVITY_BTN_UV|"+code+"-"+activityCode+"-"+btnId; | ||
299 | hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | ||
300 | if (Objects.nonNull(hourBtnClickUV)) { | ||
301 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | private Integer getAllPV(String code, String activityCode, Long btnId) { | ||
309 | String key = "MS_ACTIVITY_BTN_PV|"+code+"#"+activityCode+"#"+btnId; | ||
310 | log.info("getAllPV ==>> key ==>> {}", key); | ||
311 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | ||
312 | if (Objects.nonNull(hourBtnClickPV)) { | ||
313 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
314 | } else { | ||
315 | key = "MS_ACTIVITY_BTN_PV|"+code+"-"+activityCode+"-"+btnId; | ||
316 | hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | ||
317 | if (Objects.nonNull(hourBtnClickPV)) { | ||
318 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | private Integer getDayUV(String code, String activityCode, Long btnId) { | ||
326 | String key = "MS_ACTIVITY_BTN_UV|"+code+"#"+activityCode+"#"+btnId+ "|" + LocalDate.now(); | ||
327 | log.info("getDayUV ==>> key ==>> {}", key); | ||
328 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | ||
329 | if (Objects.nonNull(hourBtnClickUV)) { | ||
330 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
331 | } else { | ||
332 | key = "MS_ACTIVITY_BTN_UV|"+code+"-"+activityCode+"-"+btnId+ "|" + LocalDate.now(); | ||
333 | hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | ||
334 | if (Objects.nonNull(hourBtnClickUV)) { | ||
335 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
336 | } | ||
337 | } | ||
338 | |||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | private Integer getDayPV(String code, String activityCode, Long btnId) { | ||
343 | String key = "MS_ACTIVITY_BTN_PV|"+code+"#"+activityCode+"#"+btnId+ "|" + LocalDate.now(); | ||
344 | log.info("getDayUV ==>> key ==>> {}", key); | ||
345 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | ||
346 | if (Objects.nonNull(hourBtnClickPV)) { | ||
347 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
348 | } else { | ||
349 | key = "MS_ACTIVITY_BTN_PV|"+code+"-"+activityCode+"-"+btnId+ "|" + LocalDate.now(); | ||
350 | hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | ||
351 | if (Objects.nonNull(hourBtnClickPV)) { | ||
352 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
353 | } | ||
354 | } | ||
355 | |||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | private Integer getHourUV(String code, String activityCode, Long btnId) { | ||
360 | int hour = LocalDateTime.now().getHour(); | ||
361 | String hourStr = ""; | ||
362 | if (hour < 10) { | ||
363 | hourStr = "0"+hour; | ||
364 | } else { | ||
365 | hourStr = String.valueOf(hour); | ||
366 | } | ||
367 | |||
368 | String key = "MS_ACTIVITY_BTN_UV|"+code+"#"+activityCode+"#"+btnId+ "|" + LocalDate.now()+"|"+hourStr; | ||
369 | log.info("getHourUV ==>> key ==>> {}", key); | ||
370 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | ||
371 | if (Objects.nonNull(hourBtnClickUV)) { | ||
372 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
373 | } else { | ||
374 | key = "MS_ACTIVITY_BTN_UV|"+code+"-"+activityCode+"-"+btnId+ "|" + LocalDate.now()+"|"+hourStr; | ||
375 | hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | ||
376 | if (Objects.nonNull(hourBtnClickUV)) { | ||
377 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
378 | } | ||
379 | } | ||
380 | |||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | private Integer getHourPV(String code, String activityCode, Long btnId) { | ||
385 | int hour = LocalDateTime.now().getHour(); | ||
386 | String hourStr = ""; | ||
387 | if (hour < 10) { | ||
388 | hourStr = "0"+hour; | ||
389 | } else { | ||
390 | hourStr = String.valueOf(hour); | ||
391 | } | ||
392 | String key = "MS_ACTIVITY_BTN_PV|"+code+"#"+activityCode+"#"+btnId+ "|" + LocalDate.now()+"|"+hourStr; | ||
393 | log.info("getHourPV ==>> key ==>> {}", key); | ||
394 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | ||
395 | if (Objects.nonNull(hourBtnClickPV)) { | ||
396 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
397 | } else { | ||
398 | key = "MS_ACTIVITY_BTN_PV|"+code+"-"+activityCode+"-"+btnId+ "|" + LocalDate.now()+"|"+hourStr; | ||
399 | hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | ||
400 | if (Objects.nonNull(hourBtnClickPV)) { | ||
401 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
402 | } | ||
403 | } | ||
404 | |||
405 | return 0; | ||
406 | } | ||
407 | |||
408 | private String findParamValueByValueId(Long paramValueId) { | ||
409 | /* String sql = "SELECT pa.`name` FROM `tp_template_param` AS pa LEFT JOIN `tp_template_param_value` AS tt " + | ||
410 | " ON pa.id = tt.template_param_id WHERE tt.id = '"+paramValueId+"'";*/ | ||
411 | String sql = "SELECT tt.`name` FROM `tp_template_param_value` AS tt " + | ||
412 | " WHERE tt.id = '"+paramValueId+"'"; | ||
413 | List<Map<String, Object>> objectMap = this.jdbcTemplate.queryForList(sql); | ||
414 | if (CollectionUtils.isNotEmpty(objectMap)) { | ||
415 | return objectMap.get(0).get("name").toString(); | ||
416 | } | ||
417 | return null; | ||
418 | } | ||
419 | |||
420 | private Long findActivityByCode(String activityCode) { | ||
421 | String sql = "SELECT aa.`id` FROM `act_activity` AS aa WHERE `code` = '"+activityCode+"'"; | ||
422 | List<Map<String, Object>> objectMap = this.jdbcTemplate.queryForList(sql); | ||
423 | if (CollectionUtils.isNotEmpty(objectMap)) { | ||
424 | Map<String, Object> map = objectMap.get(0); | ||
425 | return Long.valueOf(map.get("id").toString()); | ||
426 | } | ||
427 | return null; | ||
428 | } | ||
429 | |||
430 | private Long findMarktingActivityByCode(String marktingActivityCode) { | ||
431 | String sql = "SELECT am.`id` FROM `act_marketing_activity` AS am WHERE `code` = '"+marktingActivityCode+"'"; | ||
432 | List<Map<String, Object>> objectMap = this.jdbcTemplate.queryForList(sql); | ||
433 | if (CollectionUtils.isNotEmpty(objectMap)) { | ||
434 | Map<String, Object> map = objectMap.get(0); | ||
435 | return Long.valueOf(map.get("id").toString()); | ||
436 | } | ||
437 | return null; | ||
438 | } | ||
439 | |||
440 | } |
1 | package com.topdraw.business.process.calculate.task; | ||
2 | |||
3 | import com.topdraw.business.module.uv.all.domain.PvUv; | ||
4 | import com.topdraw.business.module.uv.all.service.PvUvService; | ||
5 | import com.topdraw.business.module.uv.day.domain.PvUvDay; | ||
6 | import com.topdraw.business.module.uv.day.service.PvUvDayService; | ||
7 | import com.topdraw.business.module.uv.hour.domain.PvUvHour; | ||
8 | import com.topdraw.business.module.uv.hour.service.PvUvHourService; | ||
9 | import com.topdraw.util.TimestampUtil; | ||
10 | import com.topdraw.utils.RedisUtils; | ||
11 | import lombok.extern.slf4j.Slf4j; | ||
12 | import org.apache.commons.collections4.CollectionUtils; | ||
13 | import org.apache.commons.lang3.StringUtils; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | ||
15 | import org.springframework.jdbc.core.JdbcTemplate; | ||
16 | import org.springframework.stereotype.Service; | ||
17 | import org.springframework.transaction.annotation.Propagation; | ||
18 | import org.springframework.transaction.annotation.Transactional; | ||
19 | |||
20 | import java.time.LocalDate; | ||
21 | import java.time.LocalDateTime; | ||
22 | import java.util.*; | ||
23 | |||
24 | /** | ||
25 | * @author : | ||
26 | * @description: | ||
27 | * @function : | ||
28 | * @date :Created in 2022/2/26 19:40 | ||
29 | * @version: : | ||
30 | * @modified By: | ||
31 | * @since : modified in 2022/2/26 19:40 | ||
32 | */ | ||
33 | |||
34 | @Service | ||
35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
36 | @Slf4j | ||
37 | public class PvUvCalculateTask { | ||
38 | |||
39 | @Autowired | ||
40 | private RedisUtils redisUtils; | ||
41 | @Autowired | ||
42 | private JdbcTemplate jdbcTemplate; | ||
43 | @Autowired | ||
44 | private PvUvService pvUvService; | ||
45 | @Autowired | ||
46 | private PvUvDayService pvUvDayService; | ||
47 | @Autowired | ||
48 | private PvUvHourService pvUvHourService; | ||
49 | |||
50 | public boolean calculateRedisData2Mysql(){ | ||
51 | List<Map<String, Object>> allMarketingActivityCode = this.getAllMarketingActivityCode(); | ||
52 | |||
53 | if (CollectionUtils.isNotEmpty(allMarketingActivityCode)) { | ||
54 | |||
55 | for (Map<String, Object> map : allMarketingActivityCode) { | ||
56 | |||
57 | Object codeObj = map.get("code"); | ||
58 | Object idObj = map.get("id"); | ||
59 | if (Objects.nonNull(codeObj)&&Objects.nonNull(idObj)) { | ||
60 | String code = codeObj.toString(); | ||
61 | String id = idObj.toString(); | ||
62 | log.info("marktingActivity ===>>> code ====>>> [{}]",code); | ||
63 | |||
64 | LocalDateTime endTime = (LocalDateTime) map.get("endTime"); | ||
65 | |||
66 | if (Objects.nonNull(endTime)) { | ||
67 | log.info("活动结束时间-->>{}",endTime); | ||
68 | // 活动结束删除所有的对应的key | ||
69 | if (endTime.compareTo(LocalDateTime.now()) <= 0) { | ||
70 | log.info("活动结束,活动结束时间两天后删除活动code对应的所有key"); | ||
71 | if (endTime.plusDays(2).compareTo(LocalDateTime.now()) <= 0) { | ||
72 | |||
73 | Set<Object> keys = this.redisUtils.keys("*|"+code+"*"); | ||
74 | if (CollectionUtils.isNotEmpty(keys)) { | ||
75 | for (Object key : keys) { | ||
76 | this.redisUtils.del(key.toString()); | ||
77 | log.info("删除活动code对应的所有的key --->>{},成功",key); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | } | ||
82 | continue; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | // 小时pv、uv值 | ||
87 | PvUvHour pvUvHour1 = | ||
88 | this.pvUvHourService. | ||
89 | findByMarketingActivityIdAndDayAndHour(Long.parseLong(id), LocalDate.now().toString(), LocalDateTime.now().getHour()); | ||
90 | |||
91 | if (Objects.isNull(pvUvHour1.getId())) { | ||
92 | |||
93 | Integer hourPv = this.getHourPV(code); | ||
94 | Integer hourUv = this.getHourUV(code); | ||
95 | log.info("hourPv ==>> {}", hourPv); | ||
96 | log.info("hourUv ==>> {}", hourUv); | ||
97 | |||
98 | PvUvHour pvUvHour = new PvUvHour(); | ||
99 | pvUvHour.setMarketingActivityId(Long.parseLong(id)); | ||
100 | pvUvHour.setMarketingActivityCode(code); | ||
101 | pvUvHour.setDay(LocalDate.now().toString()); | ||
102 | pvUvHour.setHour(LocalDateTime.now().getHour()); | ||
103 | pvUvHour.setPv(hourPv); | ||
104 | pvUvHour.setUv(hourUv); | ||
105 | this.pvUvHourService.create(pvUvHour); | ||
106 | |||
107 | } else { | ||
108 | |||
109 | Integer hourPv = this.getHourPV(code); | ||
110 | Integer hourUv = this.getHourUV(code); | ||
111 | log.info("hourPv ==>> {}", hourPv); | ||
112 | log.info("hourUv ==>> {}", hourUv); | ||
113 | if (hourPv != 0 && hourUv != 0) { | ||
114 | pvUvHour1.setPv(hourPv); | ||
115 | pvUvHour1.setUv(hourUv); | ||
116 | pvUvHour1.setUpdateTime(TimestampUtil.now()); | ||
117 | this.pvUvHourService.updateByMarketingActivityCodeAndDayAndHour(pvUvHour1); | ||
118 | } | ||
119 | |||
120 | } | ||
121 | |||
122 | // day pv、uv值 | ||
123 | PvUvDay pvUvDay1 = this.pvUvDayService.findByMarketingActivityIdAndDay(Long.parseLong(id), LocalDate.now().toString()); | ||
124 | if(Objects.isNull(pvUvDay1.getId())){ | ||
125 | |||
126 | PvUvDay pvUvDay = new PvUvDay(); | ||
127 | pvUvDay.setMarketingActivityId(Long.parseLong(id)); | ||
128 | pvUvDay.setMarketingActivityCode(code); | ||
129 | pvUvDay.setDay(LocalDate.now().toString()); | ||
130 | |||
131 | Integer dayPv = this.getDayPV(code); | ||
132 | Integer dayUv = this.getDayUV(code); | ||
133 | log.info("dayPv ==>> {}", dayPv); | ||
134 | log.info("dayUv ==>> {}", dayUv); | ||
135 | pvUvDay.setPv(dayPv); | ||
136 | pvUvDay.setUv(dayUv); | ||
137 | this.pvUvDayService.create(pvUvDay); | ||
138 | |||
139 | } else { | ||
140 | |||
141 | Integer dayPv = this.getDayPV(code); | ||
142 | Integer dayUv = this.getDayUV(code); | ||
143 | log.info("dayPv ==>> {}", dayPv); | ||
144 | log.info("dayUv ==>> {}", dayUv); | ||
145 | |||
146 | if (dayPv != 0 && dayUv != 0) { | ||
147 | pvUvDay1.setPv(dayPv); | ||
148 | pvUvDay1.setUv(dayUv); | ||
149 | pvUvDay1.setUpdateTime(TimestampUtil.now()); | ||
150 | this.pvUvDayService.update(pvUvDay1); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | // all | ||
155 | PvUv pvUv1 = this.pvUvService.findByMarketingActivityId(Long.parseLong(id)); | ||
156 | if(Objects.isNull(pvUv1.getId())){ | ||
157 | PvUv pvUv = new PvUv(); | ||
158 | pvUv.setMarketingActivityId(Long.parseLong(id)); | ||
159 | pvUv.setMarketingActivityCode(code); | ||
160 | |||
161 | Integer allPV = this.getAllPV(code); | ||
162 | Integer allUv = this.getAllUV(code); | ||
163 | log.info("allPV ==>> {}", allPV); | ||
164 | log.info("allUv ==>> {}", allUv); | ||
165 | pvUv.setPv(allPV); | ||
166 | pvUv.setUv(allUv); | ||
167 | |||
168 | this.pvUvService.create(pvUv); | ||
169 | |||
170 | } else { | ||
171 | |||
172 | Integer allPV = this.getAllPV(code); | ||
173 | Integer allUv = this.getAllUV(code); | ||
174 | log.info("allPV ==>> {}", allPV); | ||
175 | log.info("allUv ==>> {}", allUv); | ||
176 | |||
177 | if (allPV != 0 && allUv != 0) { | ||
178 | pvUv1.setPv(allPV); | ||
179 | pvUv1.setUv(allUv); | ||
180 | pvUv1.setUpdateTime(TimestampUtil.now()); | ||
181 | this.pvUvService.update(pvUv1); | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | |||
186 | } | ||
187 | |||
188 | } | ||
189 | return true; | ||
190 | } | ||
191 | |||
192 | |||
193 | |||
194 | private Integer getHourPV(String code){ | ||
195 | int hour = LocalDateTime.now().getHour(); | ||
196 | String hourStr = ""; | ||
197 | if (hour < 10) { | ||
198 | hourStr = "0"+hour; | ||
199 | } else { | ||
200 | hourStr = String.valueOf(hour); | ||
201 | } | ||
202 | log.info("getHourPV ==>> key ==>> {}", "MS_PV" + "|" + code +"|" + LocalDate.now()+"|"+hourStr); | ||
203 | Object hourBtnClickPV = this.redisUtils.hget("MS_PV" + "|" + code +"|" + LocalDate.now()+"|"+hourStr, "ALL"); | ||
204 | if (Objects.nonNull(hourBtnClickPV)) { | ||
205 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
206 | } | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | private Integer getDayPV(String code){ | ||
212 | log.info("getDayPV ==>> key ==>> {}", "MS_PV" + "|" + code + "|" + LocalDate.now()); | ||
213 | Object hourBtnClickPV = this.redisUtils.hget("MS_PV" + "|" + code + "|" + LocalDate.now(), "ALL"); | ||
214 | if (Objects.nonNull(hourBtnClickPV)) { | ||
215 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
216 | } | ||
217 | |||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | private Integer getAllPV(String code){ | ||
222 | log.info("getAllPV ==>> key ==>> {}", "MS_PV" + "|" + code); | ||
223 | Object hourBtnClickPV = this.redisUtils.hget("MS_PV" + "|" + code, "ALL"); | ||
224 | if (Objects.nonNull(hourBtnClickPV)) { | ||
225 | return Integer.valueOf(hourBtnClickPV.toString()); | ||
226 | } | ||
227 | |||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | |||
232 | private Integer getHourUV(String code){ | ||
233 | int hour = LocalDateTime.now().getHour(); | ||
234 | String hourStr = ""; | ||
235 | if (hour < 10) { | ||
236 | hourStr = "0"+hour; | ||
237 | } else { | ||
238 | hourStr = String.valueOf(hour); | ||
239 | } | ||
240 | log.info("getHourUV ==>> key ==>> {}", "MS_UV" + "|" + code + "|" + LocalDate.now()+"|"+hourStr); | ||
241 | Object hourBtnClickUV = this.redisUtils.hget("MS_UV" + "|" + code + "|" + LocalDate.now()+"|"+hourStr, "ALL"); | ||
242 | if (Objects.nonNull(hourBtnClickUV)) { | ||
243 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
244 | } | ||
245 | |||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | |||
250 | private Integer getDayUV(String code){ | ||
251 | log.info("getDayBtnClickUV ==>> key ==>> {}", "MS_UV" + "|" + code + "|" + LocalDate.now()); | ||
252 | Object hourBtnClickUV = this.redisUtils.hget("MS_UV" + "|" + code + "|" + LocalDate.now(), "ALL"); | ||
253 | if (Objects.nonNull(hourBtnClickUV)) { | ||
254 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
255 | } | ||
256 | |||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | |||
261 | private Integer getAllUV(String code){ | ||
262 | log.info("getAllUV ==>> key ==>> {}", "MS_UV" + "|" + code); | ||
263 | Object hourBtnClickUV = this.redisUtils.hget("MS_UV" + "|" + code, "ALL"); | ||
264 | if (Objects.nonNull(hourBtnClickUV)) { | ||
265 | return Integer.valueOf(hourBtnClickUV.toString()); | ||
266 | } | ||
267 | |||
268 | return 0; | ||
269 | } | ||
270 | |||
271 | private List<Map<String,Object>> getAllMarketingActivityCode(){ | ||
272 | |||
273 | String sql = "SELECT adr.`id` AS `id`, adr.`code` AS `code`, adr.`end_time` AS `endTime` FROM " + | ||
274 | " `act_marketing_activity` adr WHERE now() BETWEEN `start_time` AND DATE_ADD(`end_time`,INTERVAL 3 DAY)" + | ||
275 | " GROUP BY `code`"; | ||
276 | return this.jdbcTemplate.queryForList(sql); | ||
277 | |||
278 | } | ||
279 | |||
280 | } |
1 | package com.topdraw.business.process.calculate.task; | ||
2 | |||
3 | import com.topdraw.business.module.subscribe.all.domain.SubscribePvUv; | ||
4 | import com.topdraw.business.module.subscribe.all.service.SubscribePvUvService; | ||
5 | import com.topdraw.business.module.subscribe.day.domain.SubscribePvUvDay; | ||
6 | import com.topdraw.business.module.subscribe.day.service.SubscribePvUvDayService; | ||
7 | import com.topdraw.business.module.subscribe.hour.domain.SubscribePvUvHour; | ||
8 | import com.topdraw.business.module.subscribe.hour.service.SubscribePvUvHourService; | ||
9 | import com.topdraw.util.TimestampUtil; | ||
10 | import lombok.extern.slf4j.Slf4j; | ||
11 | import org.apache.commons.collections4.CollectionUtils; | ||
12 | import org.apache.commons.collections4.MapUtils; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.jdbc.core.JdbcTemplate; | ||
15 | import org.springframework.stereotype.Service; | ||
16 | import org.springframework.transaction.annotation.Propagation; | ||
17 | import org.springframework.transaction.annotation.Transactional; | ||
18 | import redis.clients.jedis.Jedis; | ||
19 | |||
20 | import java.time.LocalDate; | ||
21 | import java.time.LocalDateTime; | ||
22 | import java.util.*; | ||
23 | |||
24 | /** | ||
25 | * @author : | ||
26 | * @description: | ||
27 | * @function : | ||
28 | * @date :Created in 2022/2/26 19:40 | ||
29 | * @version: : | ||
30 | * @modified By: | ||
31 | * @since : modified in 2022/2/26 19:40 | ||
32 | */ | ||
33 | |||
34 | @Service | ||
35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
36 | @Slf4j | ||
37 | public class SubscribeCalculateTask { | ||
38 | |||
39 | @Autowired | ||
40 | private Jedis redisUtils; | ||
41 | @Autowired | ||
42 | private JdbcTemplate jdbcTemplate; | ||
43 | |||
44 | @Autowired | ||
45 | private SubscribePvUvHourService subscribePvUvHourService; | ||
46 | @Autowired | ||
47 | private SubscribePvUvDayService subscribePvUvDayService; | ||
48 | @Autowired | ||
49 | private SubscribePvUvService subscribePvUvService; | ||
50 | |||
51 | private List<Map<String,Object>> getAllMarketingActivityCode(){ | ||
52 | |||
53 | String sql = "SELECT adr.`id` AS `id`, adr.`code` AS `code`, adr.`end_time` AS `endTime` " + | ||
54 | " FROM `act_marketing_activity` adr WHERE now() BETWEEN `start_time` AND DATE_ADD(`end_time`,INTERVAL 3 DAY) GROUP BY `code`"; | ||
55 | return this.jdbcTemplate.queryForList(sql); | ||
56 | |||
57 | } | ||
58 | |||
59 | private List<Map<String,Object>> getPackageInfo(String packageId){ | ||
60 | String sql = "SELECT pa.`code` , pa.`name` FROM `x_package` AS pa WHERE product_id = '"+packageId+"'"; | ||
61 | return this.jdbcTemplate.queryForList(sql); | ||
62 | |||
63 | } | ||
64 | |||
65 | private Long getHourBtnClickPV(String code, String packageId){ | ||
66 | int hour = LocalDateTime.now().getHour(); | ||
67 | String hourStr = ""; | ||
68 | if (hour < 10) { | ||
69 | hourStr = "0"+hour; | ||
70 | } else { | ||
71 | hourStr = String.valueOf(hour); | ||
72 | } | ||
73 | log.info("getHourBtnClickPV ==>> key ==>> {}", "MS_BTN_CLICK_PV" + "|" + code + "-" + packageId + "|" + LocalDate.now()+"|"+hourStr); | ||
74 | Object hourBtnClickPV = this.redisUtils.hget("MS_BTN_CLICK_PV" + "|" + code + "-" + packageId + "|" + LocalDate.now()+"|"+hourStr, "ALL"); | ||
75 | if (Objects.nonNull(hourBtnClickPV)) { | ||
76 | return (long) Integer.parseInt(hourBtnClickPV.toString()); | ||
77 | } | ||
78 | |||
79 | return 0L; | ||
80 | } | ||
81 | |||
82 | private Long getDayBtnClickPV(String code, String packageId){ | ||
83 | log.info("getDayBtnClickPV ==>> key ==>> {}", "MS_BTN_CLICK_PV" + "|" + code + "-" + packageId + "|" + LocalDate.now()); | ||
84 | Object hourBtnClickPV = this.redisUtils.hget("MS_BTN_CLICK_PV" + "|" + code + "-" + packageId + "|" + LocalDate.now(), "ALL"); | ||
85 | if (Objects.nonNull(hourBtnClickPV)) { | ||
86 | return (long) Integer.parseInt(hourBtnClickPV.toString()); | ||
87 | } | ||
88 | |||
89 | return 0L; | ||
90 | } | ||
91 | |||
92 | private Long getAllBtnClickPV(String code, String packageId){ | ||
93 | log.info("getAllBtnClickPV ==>> key ==>> {}", "MS_BTN_CLICK_PV" + "|" + code + "-" + packageId); | ||
94 | Object hourBtnClickPV = this.redisUtils.hget("MS_BTN_CLICK_PV" + "|" + code + "-" + packageId, "ALL"); | ||
95 | if (Objects.nonNull(hourBtnClickPV)) { | ||
96 | return (long) Integer.parseInt(hourBtnClickPV.toString()); | ||
97 | } | ||
98 | |||
99 | return 0L; | ||
100 | } | ||
101 | |||
102 | |||
103 | private Long getHourBtnClickUV(String code, String packageId){ | ||
104 | int hour = LocalDateTime.now().getHour(); | ||
105 | String hourStr = ""; | ||
106 | if (hour < 10) { | ||
107 | hourStr = "0"+hour; | ||
108 | } else { | ||
109 | hourStr = String.valueOf(hour); | ||
110 | } | ||
111 | log.info("getHourBtnClickUV ==>> key ==>> {}", "MS_BTN_CLICK_UV" + "|" + code + "-" + packageId + "|" + LocalDate.now()+"|"+hourStr); | ||
112 | Object hourBtnClickUV = this.redisUtils.hget("MS_BTN_CLICK_UV" + "|" + code + "-" + packageId + "|" + LocalDate.now()+"|"+hourStr, "ALL"); | ||
113 | if (Objects.nonNull(hourBtnClickUV)) { | ||
114 | return (long) Integer.parseInt(hourBtnClickUV.toString()); | ||
115 | } | ||
116 | |||
117 | return 0L; | ||
118 | } | ||
119 | |||
120 | |||
121 | private Long getDayBtnClickUV(String code, String packageId){ | ||
122 | log.info("getDayBtnClickUV ==>> key ==>> {}", "MS_BTN_CLICK_UV" + "|" + code + "-" + packageId + "|" + LocalDate.now()); | ||
123 | Object hourBtnClickUV = this.redisUtils.hget("MS_BTN_CLICK_UV" + "|" + code + "-" + packageId + "|" + LocalDate.now(), "ALL"); | ||
124 | if (Objects.nonNull(hourBtnClickUV)) { | ||
125 | return (long) Integer.parseInt(hourBtnClickUV.toString()); | ||
126 | } | ||
127 | |||
128 | return 0L; | ||
129 | } | ||
130 | |||
131 | |||
132 | private Long getAllBtnClickUV(String code, String packageId){ | ||
133 | log.info("getAllBtnClickUV ==>> key ==>> {}", "MS_BTN_CLICK_UV" + "|" + code + "-" + packageId); | ||
134 | Object hourBtnClickUV = this.redisUtils.hget("MS_BTN_CLICK_UV" + "|" + code + "-" + packageId, "ALL"); | ||
135 | if (Objects.nonNull(hourBtnClickUV)) { | ||
136 | return (long) Integer.parseInt(hourBtnClickUV.toString()); | ||
137 | } | ||
138 | |||
139 | return 0L; | ||
140 | } | ||
141 | |||
142 | |||
143 | private Long getHourSubscribeNum(String code, String packageId){ | ||
144 | |||
145 | int hour = LocalDateTime.now().getHour(); | ||
146 | String hourStr = ""; | ||
147 | if (hour < 10) { | ||
148 | hourStr = "0"+hour; | ||
149 | } else { | ||
150 | hourStr = String.valueOf(hour); | ||
151 | } | ||
152 | log.info("getHourSubscribeNum ==>> key ==>> {}", "MS_SUBSCRIB" + "|" + code + "-" + packageId + "|" + LocalDate.now()+"|"+hourStr); | ||
153 | Object hourBtnClickPV = this.redisUtils.hget("MS_SUBSCRIB" + "|" + code + "-" + packageId + "|" + LocalDate.now()+"|"+hourStr, "ALL"); | ||
154 | if (Objects.nonNull(hourBtnClickPV)) { | ||
155 | return Long.parseLong(hourBtnClickPV.toString()); | ||
156 | } | ||
157 | |||
158 | return 0L; | ||
159 | } | ||
160 | |||
161 | private Long getDaySubscribeNum(String code, String packageId, LocalDate localDate){ | ||
162 | log.info("getDaySubscribeNum ==>> key ==>> {}", "MS_SUBSCRIB" + "|" + code + "-" + packageId + "|" + localDate); | ||
163 | Object hourBtnClickUV = this.redisUtils.hget("MS_SUBSCRIB" + "|" + code + "-" + packageId + "|" + localDate, "ALL"); | ||
164 | if (Objects.nonNull(hourBtnClickUV)) { | ||
165 | return Long.parseLong(hourBtnClickUV.toString()); | ||
166 | } | ||
167 | return 0L; | ||
168 | } | ||
169 | |||
170 | private Long getAllSubscribeNum(String code, String packageId){ | ||
171 | log.info("getAllSubscribeNum ==>> key ==>> {}", "MS_SUBSCRIB" + "|" + code + "-" + packageId); | ||
172 | Object hourBtnClickUV = this.redisUtils.hget("MS_SUBSCRIB" + "|" + code + "-" + packageId, "ALL"); | ||
173 | if (Objects.nonNull(hourBtnClickUV)) { | ||
174 | return Long.parseLong(hourBtnClickUV.toString()); | ||
175 | } | ||
176 | return 0L; | ||
177 | } | ||
178 | |||
179 | private Set<String> getPackageIdByCode(String code) { | ||
180 | String key = "MS_PRODUCTID_SET|"+code; | ||
181 | log.info("getPackageIdByCode ==>> key ==>> {}", key); | ||
182 | return this.redisUtils.smembers(key); | ||
183 | } | ||
184 | |||
185 | public void calculateSubscribe2Mysql() { | ||
186 | List<Map<String, Object>> allMarketingActivityCode = this.getAllMarketingActivityCode(); | ||
187 | if (CollectionUtils.isNotEmpty(allMarketingActivityCode)) { | ||
188 | |||
189 | for (Map<String, Object> map : allMarketingActivityCode) { | ||
190 | |||
191 | Object codeObj = map.get("code"); | ||
192 | Object idObj = map.get("id"); | ||
193 | |||
194 | if (Objects.nonNull(codeObj)&&Objects.nonNull(idObj)) { | ||
195 | String id = idObj.toString(); | ||
196 | String code = codeObj.toString(); | ||
197 | log.info("活动code-->>{}",code); | ||
198 | LocalDateTime endTime = (LocalDateTime) map.get("endTime"); | ||
199 | if (Objects.nonNull(endTime)) { | ||
200 | log.info("活动结束时间-->>{}",endTime); | ||
201 | // 活动结束删除所有的对应的key | ||
202 | if (endTime.compareTo(LocalDateTime.now()) <= 0) { | ||
203 | log.info("活动结束,活动结束时间两天后删除活动code对应的所有key"); | ||
204 | if (endTime.plusDays(2).compareTo(LocalDateTime.now()) <= 0) { | ||
205 | |||
206 | Set<String> keys = this.redisUtils.keys("*|"+code+"*"); | ||
207 | if (CollectionUtils.isNotEmpty(keys)) { | ||
208 | for (Object key : keys) { | ||
209 | this.redisUtils.del(key.toString()); | ||
210 | log.info("删除活动code对应的所有的key --->>{},成功",key); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | } | ||
215 | continue; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | |||
220 | Set<String> packageIds = this.getPackageIdByCode(code); | ||
221 | log.info("subscribe ==>> packageIdList ==>> {}", packageIds); | ||
222 | if (CollectionUtils.isEmpty(packageIds)) { | ||
223 | log.info(" ==>> 产品id列表,不存在"); | ||
224 | continue; | ||
225 | } | ||
226 | |||
227 | for (String packageId: packageIds) { | ||
228 | //String packageId = packageIdStr.toString(); | ||
229 | log.info("subscribe ==>> packageId ==>> {}", packageId); | ||
230 | List<Map<String, Object>> packageInfo = this.getPackageInfo(packageId); | ||
231 | log.info("subscribe ==>> packageInfo ==>> {}", packageInfo); | ||
232 | String packageCode = ""; | ||
233 | String packageName = ""; | ||
234 | if (CollectionUtils.isNotEmpty(packageInfo)) { | ||
235 | Map<String, Object> packageInfoMap1 = packageInfo.get(0); | ||
236 | if (MapUtils.isNotEmpty(packageInfoMap1)) { | ||
237 | if (Objects.nonNull(packageInfoMap1.get("code"))) { | ||
238 | packageCode = packageInfoMap1.get("code").toString(); | ||
239 | } | ||
240 | if (Objects.nonNull(packageInfoMap1.get("name"))) { | ||
241 | packageName = packageInfoMap1.get("name").toString(); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | } | ||
246 | |||
247 | // 小时订购转换值 | ||
248 | SubscribePvUvHour subscribePvUvHour = | ||
249 | this.subscribePvUvHourService. | ||
250 | findByMarketingActivityCodeAndPackageIdAndDayAndHour(code, packageId, | ||
251 | LocalDate.now().toString(), LocalDateTime.now().getHour()); | ||
252 | log.info("subscribe ==>> subscribePvUvHour ==>> {}", subscribePvUvHour); | ||
253 | if (Objects.isNull(subscribePvUvHour.getId())) { | ||
254 | |||
255 | log.info("subscribe ==>> subscribePvUvHour ==>> create"); | ||
256 | SubscribePvUvHour pvUvHour = new SubscribePvUvHour(); | ||
257 | pvUvHour.setMarketingActivityId(Long.parseLong(id)); | ||
258 | pvUvHour.setMarketingActivityCode(code); | ||
259 | pvUvHour.setDay(LocalDate.now().toString()); | ||
260 | pvUvHour.setHour(LocalDateTime.now().getHour()); | ||
261 | pvUvHour.setPackageId(packageId); | ||
262 | pvUvHour.setPackageCode(packageCode); | ||
263 | pvUvHour.setPackageName(packageName); | ||
264 | |||
265 | Long hourSubscribeNum = this.getHourSubscribeNum(code, packageId); | ||
266 | log.info("subscribe ==>> hourSubscribeNum ==>> {}", hourSubscribeNum); | ||
267 | pvUvHour.setSubscribeNum(hourSubscribeNum); | ||
268 | |||
269 | Long hourBtnClickPV = this.getHourBtnClickPV(code, packageId); | ||
270 | log.info("subscribe ==>> hourBtnClickPV ==>> {}", hourBtnClickPV); | ||
271 | pvUvHour.setBtnClickPv(hourBtnClickPV); | ||
272 | |||
273 | Long hourBtnClickUV = this.getHourBtnClickUV(code, packageId); | ||
274 | log.info("subscribe ==>> hourBtnClickUV ==>> {}", hourBtnClickUV); | ||
275 | pvUvHour.setBtnClickUv(hourBtnClickUV); | ||
276 | this.subscribePvUvHourService.create(pvUvHour); | ||
277 | |||
278 | } else { | ||
279 | log.info("subscribe ==>> subscribePvUvHour ==>> update"); | ||
280 | |||
281 | Long hourSubscribeNum = this.getHourSubscribeNum(code, packageId); | ||
282 | log.info("subscribe ==>> hourSubscribeNum ==>> {}", hourSubscribeNum); | ||
283 | |||
284 | |||
285 | Long hourBtnClickPV = this.getHourBtnClickPV(code, packageId); | ||
286 | log.info("subscribe ==>> hourBtnClickPV ==>> {}", hourBtnClickPV); | ||
287 | |||
288 | Long hourBtnClickUV = this.getHourBtnClickUV(code, packageId); | ||
289 | log.info("subscribe ==>> hourBtnClickUV ==>> {}", hourBtnClickUV); | ||
290 | |||
291 | if (hourBtnClickPV != 0 && hourBtnClickUV != 0) { | ||
292 | subscribePvUvHour.setBtnClickUv(hourBtnClickUV); | ||
293 | subscribePvUvHour.setBtnClickPv(hourBtnClickPV); | ||
294 | subscribePvUvHour.setSubscribeNum(hourSubscribeNum); | ||
295 | subscribePvUvHour.setUpdateTime(TimestampUtil.now()); | ||
296 | log.info("subscribe ==>> subscribePvUvHour ==>> {}", subscribePvUvHour); | ||
297 | this.subscribePvUvHourService.update(subscribePvUvHour); | ||
298 | } | ||
299 | |||
300 | } | ||
301 | |||
302 | // 天订购转换值 | ||
303 | SubscribePvUvDay subscribePvUvDay = | ||
304 | this.subscribePvUvDayService. | ||
305 | findByMarketingActivityCodeAndPackageIdAndDay(code, packageId, | ||
306 | LocalDate.now().toString()); | ||
307 | log.info("subscribe ==>> subscribePvUvDay ==>> {}", subscribePvUvDay); | ||
308 | if (Objects.isNull(subscribePvUvDay.getId())) { | ||
309 | log.info("subscribe ==>> subscribePvUvDay ==>> create"); | ||
310 | SubscribePvUvDay subscribePvUvDay_ = new SubscribePvUvDay(); | ||
311 | subscribePvUvDay_.setMarketingActivityId(Long.parseLong(id)); | ||
312 | subscribePvUvDay_.setMarketingActivityCode(code); | ||
313 | subscribePvUvDay_.setDay(LocalDate.now().toString()); | ||
314 | subscribePvUvDay_.setPackageId(packageId); | ||
315 | subscribePvUvDay_.setPackageCode(packageCode); | ||
316 | subscribePvUvDay_.setPackageName(packageName); | ||
317 | |||
318 | Long daySubscribeNum = this.getDaySubscribeNum(code, packageId, LocalDate.now()); | ||
319 | log.info("subscribe ==>> daySubscribeNum ==>> {}", daySubscribeNum); | ||
320 | subscribePvUvDay_.setSubscribeNum(daySubscribeNum); | ||
321 | |||
322 | Long dayBtnClickPV = this.getDayBtnClickPV(code, packageId); | ||
323 | log.info("subscribe ==>> dayBtnClickPV ==>> {}", dayBtnClickPV); | ||
324 | subscribePvUvDay_.setBtnClickPv(dayBtnClickPV); | ||
325 | |||
326 | Long dayBtnClickUV = this.getDayBtnClickUV(code, packageId); | ||
327 | log.info("subscribe ==>> dayBtnClickUV ==>> {}", dayBtnClickUV); | ||
328 | subscribePvUvDay_.setBtnClickUv(dayBtnClickUV); | ||
329 | |||
330 | log.info("subscribe ==>> subscribePvUvDay_ ==>> {}", subscribePvUvDay_); | ||
331 | this.subscribePvUvDayService.create(subscribePvUvDay_); | ||
332 | |||
333 | } else { | ||
334 | |||
335 | log.info("subscribe ==>> subscribePvUvDay ==>> update"); | ||
336 | Long daySubscribeNum = this.getDaySubscribeNum(code, packageId, LocalDate.now()); | ||
337 | log.info("subscribe ==>> daySubscribeNum ==>> {}", daySubscribeNum); | ||
338 | Long dayBtnClickPV = this.getDayBtnClickPV(code, packageId); | ||
339 | log.info("subscribe ==>> dayBtnClickPV ==>> {}", dayBtnClickPV); | ||
340 | Long dayBtnClickUV = this.getDayBtnClickUV(code, packageId); | ||
341 | log.info("subscribe ==>> dayBtnClickUV ==>> {}", dayBtnClickUV); | ||
342 | |||
343 | if (dayBtnClickUV != 0 && dayBtnClickPV != 0) { | ||
344 | subscribePvUvDay.setSubscribeNum(daySubscribeNum); | ||
345 | subscribePvUvDay.setBtnClickUv(dayBtnClickUV); | ||
346 | subscribePvUvDay.setBtnClickPv(dayBtnClickPV); | ||
347 | subscribePvUvDay.setUpdateTime(TimestampUtil.now()); | ||
348 | log.info("subscribe ==>> subscribePvUvDay ==>> {}", subscribePvUvDay); | ||
349 | this.subscribePvUvDayService.update(subscribePvUvDay); | ||
350 | } | ||
351 | |||
352 | } | ||
353 | |||
354 | // 总订购转换值 | ||
355 | SubscribePvUv subscribePvUv = | ||
356 | this.subscribePvUvService. | ||
357 | findByMarketingActivityCodeAndPackageId(code, packageId); | ||
358 | log.info("subscribe ==>> subscribePvUv ==>> {}", subscribePvUv); | ||
359 | if (Objects.isNull(subscribePvUv.getId())) { | ||
360 | log.info("subscribe ==>> subscribePvUv ==>> create"); | ||
361 | SubscribePvUv subscribePvUv_ = new SubscribePvUv(); | ||
362 | subscribePvUv_.setMarketingActivityId(Long.parseLong(id)); | ||
363 | subscribePvUv_.setMarketingActivityCode(code); | ||
364 | subscribePvUv_.setPackageId(packageId); | ||
365 | subscribePvUv_.setPackageCode(packageCode); | ||
366 | subscribePvUv_.setPackageName(packageName); | ||
367 | |||
368 | Long allSubscribeNum = this.getAllSubscribeNum(code, packageId); | ||
369 | log.info("subscribe ==>> allSubscribeNum ==>> {}",allSubscribeNum); | ||
370 | subscribePvUv_.setSubscribeNum(allSubscribeNum); | ||
371 | |||
372 | Long allBtnClickPV = this.getAllBtnClickPV(code, packageId); | ||
373 | log.info("subscribe ==>> allBtnClickPV ==>> {}",allBtnClickPV); | ||
374 | subscribePvUv_.setBtnClickPv(allBtnClickPV); | ||
375 | |||
376 | Long allBtnClickUV = this.getAllBtnClickUV(code, packageId); | ||
377 | log.info("subscribe ==>> allBtnClickUV ==>> {}",allBtnClickUV); | ||
378 | subscribePvUv_.setBtnClickUv(allBtnClickUV); | ||
379 | |||
380 | log.info("subscribe ==>> subscribePvUv_ ==>> {}",subscribePvUv_); | ||
381 | this.subscribePvUvService.create(subscribePvUv_); | ||
382 | |||
383 | } else { | ||
384 | log.info("subscribe ==>> subscribePvUv ==>> update"); | ||
385 | Long allSubscribeNum = this.getAllSubscribeNum(code, packageId); | ||
386 | log.info("subscribe ==>> allSubscribeNum ==>> {}", allSubscribeNum); | ||
387 | Long allBtnClickPV = this.getAllBtnClickPV(code, packageId); | ||
388 | log.info("subscribe ==>> allBtnClickPV ==>> {}", allBtnClickPV); | ||
389 | Long allBtnClickUV = this.getAllBtnClickUV(code, packageId); | ||
390 | log.info("subscribe ==>> allBtnClickUV ==>> {}", allBtnClickUV); | ||
391 | |||
392 | if (allBtnClickUV != 0 && allBtnClickPV != 0) { | ||
393 | subscribePvUv.setBtnClickUv(allBtnClickUV); | ||
394 | subscribePvUv.setSubscribeNum(allSubscribeNum); | ||
395 | subscribePvUv.setBtnClickPv(allBtnClickPV); | ||
396 | subscribePvUv.setUpdateTime(TimestampUtil.now()); | ||
397 | log.info("subscribe ==>> subscribePvUv ==>> {}", subscribePvUv); | ||
398 | this.subscribePvUvService.update(subscribePvUv); | ||
399 | } | ||
400 | |||
401 | } | ||
402 | |||
403 | } | ||
404 | |||
405 | } | ||
406 | |||
407 | } | ||
408 | |||
409 | } | ||
410 | |||
411 | } | ||
412 | |||
413 | } |
1 | package com.topdraw.redis.config; | ||
2 | |||
3 | import lombok.extern.slf4j.Slf4j; | ||
4 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | ||
6 | import org.springframework.beans.factory.annotation.Qualifier; | ||
7 | import org.springframework.beans.factory.annotation.Value; | ||
8 | import org.springframework.boot.context.properties.ConfigurationProperties; | ||
9 | import org.springframework.context.annotation.Bean; | ||
10 | import org.springframework.context.annotation.Configuration; | ||
11 | import org.springframework.core.env.Environment; | ||
12 | import org.springframework.data.redis.connection.*; | ||
13 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
14 | import org.springframework.data.redis.core.RedisTemplate; | ||
15 | import org.springframework.data.redis.core.StringRedisTemplate; | ||
16 | import org.springframework.util.StringUtils; | ||
17 | import redis.clients.jedis.Jedis; | ||
18 | import redis.clients.jedis.JedisPool; | ||
19 | import redis.clients.jedis.JedisPoolConfig; | ||
20 | import redis.clients.jedis.JedisSentinelPool; | ||
21 | |||
22 | import javax.annotation.Resource; | ||
23 | import java.util.HashSet; | ||
24 | import java.util.Set; | ||
25 | |||
26 | /** | ||
27 | * @author : | ||
28 | * @description: | ||
29 | * @function : | ||
30 | * @date :Created in 2022/2/27 10:39 | ||
31 | * @version: : | ||
32 | * @modified By: | ||
33 | * @since : modified in 2022/2/27 10:39 | ||
34 | */ | ||
35 | @Configuration | ||
36 | @Slf4j | ||
37 | public class MyJedisConfig { | ||
38 | |||
39 | /***生产环境要打开此配置*/ | ||
40 | @Value("${spring.redis.sentinel.master}") | ||
41 | private String master; | ||
42 | |||
43 | @Value("${spring.redis.sentinel.nodes}") | ||
44 | private String sentinelHost; | ||
45 | |||
46 | @Bean | ||
47 | public Jedis jedisPool(JedisPoolConfig jedisPoolConfig) { | ||
48 | String[] split = sentinelHost.split(","); | ||
49 | Set<String> sentinels = new HashSet<>(); | ||
50 | for (int i = 0; i < split.length; i++) { | ||
51 | String s = split[i]; | ||
52 | sentinels.add(s); | ||
53 | } | ||
54 | |||
55 | JedisSentinelPool jedisPool = new JedisSentinelPool(master, sentinels, jedisPoolConfig); | ||
56 | Jedis jedis = jedisPool.getResource(); | ||
57 | return jedis; | ||
58 | } | ||
59 | |||
60 | @Bean | ||
61 | public JedisPoolConfig jedisPoolConfig() { | ||
62 | JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); | ||
63 | jedisPoolConfig.setMaxTotal(15); | ||
64 | jedisPoolConfig.setMaxIdle(10); | ||
65 | jedisPoolConfig.setMinIdle(5); | ||
66 | jedisPoolConfig.setMaxWaitMillis(10000); | ||
67 | jedisPoolConfig.setTestOnBorrow(true); | ||
68 | |||
69 | return jedisPoolConfig; | ||
70 | } | ||
71 | |||
72 | /*@Bean | ||
73 | public Jedis jedisPool(@Value("${spring.redis.host}") String host, | ||
74 | @Value("${spring.redis.port}") int port, | ||
75 | @Value("${spring.redis.timeout}") int timeout, | ||
76 | // @Value("${spring.redis.password}") String password, | ||
77 | JedisPoolConfig jedisPoolConfig) { | ||
78 | |||
79 | // JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout,"redis123"); | ||
80 | JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout); | ||
81 | |||
82 | return jedisPool.getResource(); | ||
83 | }*/ | ||
84 | } |
1 | package com.topdraw.schedule; | ||
2 | |||
3 | import com.topdraw.business.process.calculate.task.ActivityBtnClickPvUcCalculateTask; | ||
4 | import lombok.extern.slf4j.Slf4j; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | ||
6 | import org.springframework.beans.factory.annotation.Value; | ||
7 | import org.springframework.scheduling.annotation.EnableScheduling; | ||
8 | import org.springframework.scheduling.annotation.Scheduled; | ||
9 | import org.springframework.stereotype.Component; | ||
10 | |||
11 | import java.time.LocalDateTime; | ||
12 | |||
13 | /** | ||
14 | * @author : | ||
15 | * @description: | ||
16 | * @function : | ||
17 | * @date :Created in 2022/2/26 19:44 | ||
18 | * @version: : | ||
19 | * @modified By: | ||
20 | * @since : modified in 2022/2/26 19:44 | ||
21 | */ | ||
22 | @Component | ||
23 | @Slf4j | ||
24 | @EnableScheduling | ||
25 | public class TransferActivityBtnClickPvUvScheduleTask { | ||
26 | |||
27 | @Autowired | ||
28 | private ActivityBtnClickPvUcCalculateTask activityBtnClickPvUcCalculateTask; | ||
29 | |||
30 | @Value("${cronActivityBtn:50 0/5 * * * ?}") | ||
31 | private String cron; | ||
32 | |||
33 | public String cron(){ | ||
34 | return cron; | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * 统计订购转换数据 | ||
39 | */ | ||
40 | @Scheduled(cron = "#{transferActivityBtnClickPvUvScheduleTask.cron()}") | ||
41 | public void calculateSubscribe2Mysql(){ | ||
42 | log.info("活动按钮点击次数统计 ===>>> 开始 !!!" + LocalDateTime.now()); | ||
43 | this.activityBtnClickPvUcCalculateTask.calculateRedisData2Mysql(); | ||
44 | } | ||
45 | |||
46 | } |
1 | package com.topdraw.schedule; | ||
2 | |||
3 | import com.topdraw.business.process.calculate.task.PvUvCalculateTask; | ||
4 | import lombok.extern.slf4j.Slf4j; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | ||
6 | import org.springframework.beans.factory.annotation.Value; | ||
7 | import org.springframework.scheduling.annotation.EnableScheduling; | ||
8 | import org.springframework.scheduling.annotation.Scheduled; | ||
9 | import org.springframework.stereotype.Component; | ||
10 | |||
11 | import java.time.LocalDateTime; | ||
12 | |||
13 | /** | ||
14 | * @author : | ||
15 | * @description: | ||
16 | * @function : | ||
17 | * @date :Created in 2022/2/26 19:44 | ||
18 | * @version: : | ||
19 | * @modified By: | ||
20 | * @since : modified in 2022/2/26 19:44 | ||
21 | */ | ||
22 | @Component | ||
23 | @Slf4j | ||
24 | @EnableScheduling | ||
25 | public class TransferScheduleTask { | ||
26 | |||
27 | @Autowired | ||
28 | private PvUvCalculateTask pvUvCalculateTask; | ||
29 | |||
30 | @Value("${cron:50 0/5 * * * ?}") | ||
31 | private String cron; | ||
32 | |||
33 | public String cron(){ | ||
34 | return cron; | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * 统计pv、uv | ||
39 | */ | ||
40 | @Scheduled(cron = "#{transferScheduleTask.cron()}") | ||
41 | public void calculatePvUv2Mysql(){ | ||
42 | log.info("pv、uv统计 ===>>> 开始 !!!" + LocalDateTime.now()); | ||
43 | this.pvUvCalculateTask.calculateRedisData2Mysql(); | ||
44 | } | ||
45 | |||
46 | } |
1 | package com.topdraw.schedule; | ||
2 | |||
3 | import com.topdraw.business.process.calculate.task.SubscribeCalculateTask; | ||
4 | import lombok.extern.slf4j.Slf4j; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | ||
6 | import org.springframework.beans.factory.annotation.Value; | ||
7 | import org.springframework.scheduling.annotation.EnableScheduling; | ||
8 | import org.springframework.scheduling.annotation.Scheduled; | ||
9 | import org.springframework.stereotype.Component; | ||
10 | |||
11 | import java.time.LocalDateTime; | ||
12 | |||
13 | /** | ||
14 | * @author : | ||
15 | * @description: | ||
16 | * @function : | ||
17 | * @date :Created in 2022/2/26 19:44 | ||
18 | * @version: : | ||
19 | * @modified By: | ||
20 | * @since : modified in 2022/2/26 19:44 | ||
21 | */ | ||
22 | @Component | ||
23 | @Slf4j | ||
24 | @EnableScheduling | ||
25 | public class TransferSubscribeScheduleTask { | ||
26 | |||
27 | @Autowired | ||
28 | private SubscribeCalculateTask subscribeCalculateTask; | ||
29 | |||
30 | @Value("${cronSubscribe:50 0/5 * * * ?}") | ||
31 | // @Value("0/5 * * * * ?") | ||
32 | private String cron; | ||
33 | |||
34 | public String cron(){ | ||
35 | return cron; | ||
36 | } | ||
37 | |||
38 | /** | ||
39 | * 统计订购转换数据 | ||
40 | */ | ||
41 | @Scheduled(cron = "#{transferSubscribeScheduleTask.cron()}") | ||
42 | // @Scheduled(cron = "0/5 * * * * ?") | ||
43 | public void calculateSubscribe2Mysql(){ | ||
44 | log.info("订购数据统计 ===>>> 开始 !!!" + LocalDateTime.now()); | ||
45 | this.subscribeCalculateTask.calculateSubscribe2Mysql(); | ||
46 | } | ||
47 | |||
48 | } |
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")).toEpochMilli(); | ||
16 | return new Timestamp(epochSecond); | ||
17 | } | ||
18 | |||
19 | public static long localDateTime2long(LocalDateTime localDateTime){ | ||
20 | return localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); | ||
21 | } | ||
22 | |||
23 | public static Timestamp localDateTime2Timestamp(LocalDateTime localDateTime){ | ||
24 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); | ||
25 | return long2Timestamp(epochSecond); | ||
26 | } | ||
27 | public static Timestamp long2Timestamp(long timestamp){ | ||
28 | return Timestamp.from(Instant.ofEpochMilli(timestamp)); | ||
29 | } | ||
30 | |||
31 | public static long timestamp2long(Timestamp timestamp){ | ||
32 | return timestamp.toInstant().toEpochMilli(); | ||
33 | } | ||
34 | |||
35 | public static LocalDateTime long2LocalDateTime(Long expireTime) { | ||
36 | return LocalDateTime.ofInstant(Instant.ofEpochMilli(expireTime),ZoneOffset.of("+8")); | ||
37 | } | ||
38 | |||
39 | } |
src/main/resources/banner.txt
0 → 100644
1 | spring: | ||
2 | # 数据源 | ||
3 | datasource: | ||
4 | # 数据源地址 | ||
5 | url: jdbc:log4jdbc:mysql://139.196.145.150:3306/moss_test?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
6 | # 用户名 | ||
7 | username: root | ||
8 | # 密码 | ||
9 | password: Tjlh@2021 | ||
10 | # 驱动程序 | ||
11 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | ||
12 | # Druid | ||
13 | type: com.alibaba.druid.pool.DruidDataSource | ||
14 | druid: | ||
15 | # 初始化配置 | ||
16 | initial-size: 3 | ||
17 | # 最小连接数 | ||
18 | min-idle: 3 | ||
19 | # 最大连接数 | ||
20 | max-active: 15 | ||
21 | # 获取连接超时时间 | ||
22 | max-wait: 5000 | ||
23 | # 连接有效性检测时间 | ||
24 | time-between-eviction-runs-millis: 90000 | ||
25 | # 最大空闲时间 | ||
26 | min-evictable-idle-time-millis: 1800000 | ||
27 | test-while-idle: true | ||
28 | test-on-borrow: false | ||
29 | test-on-return: false | ||
30 | validation-query: select 1 | ||
31 | # 配置监控统计拦截的filters | ||
32 | filters: stat | ||
33 | stat-view-servlet: | ||
34 | url-pattern: /druid/* | ||
35 | reset-enable: false | ||
36 | # 过滤器 | ||
37 | web-stat-filter: | ||
38 | url-pattern: /* | ||
39 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" | ||
40 | # jpa | ||
41 | jpa: | ||
42 | properties: | ||
43 | hibernate: | ||
44 | # 数据库类型 | ||
45 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect | ||
46 | hibernate: | ||
47 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 | ||
48 | ddl-auto: none | ||
49 | open-in-view: true | ||
50 | show-sql: false | ||
51 | |||
52 | # redis | ||
53 | redis: | ||
54 | #数据库索引 | ||
55 | database: 0 | ||
56 | host: 122.112.214.149 | ||
57 | # host: 139.196.192.242 | ||
58 | port: 6379 | ||
59 | #连接超时时间 | ||
60 | timeout: 5000 | ||
61 | password: redis123 | ||
62 | #缓存过期时间 | ||
63 | expire-minutes: 5 | ||
64 | # sentinel: | ||
65 | # master: mymaster | ||
66 | # nodes: 122.112.214.149:6379,122.112.214.149:6379 | ||
67 |
src/main/resources/config/application.yml
0 → 100644
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="OFF" 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> |
-
Please register or sign in to post a comment