Commit 3fecf5d817bd25a050105ccc1c3305a3ecaa92a8
1 parent
cc57679ac4
Exists in
master
and in
6 other branches
产检券数据导出完成
Showing 6 changed files with 179 additions and 7 deletions
- regional-etl/pom.xml
- regional-etl/src/main/java/com/lyms/etl/ApplicationRunner.java
- regional-etl/src/main/java/com/lyms/etl/dao/ICouponInfoDao.java
- regional-etl/src/main/java/com/lyms/etl/model/HospitalCouponTemplateGroup.java
- regional-etl/src/main/java/com/lyms/etl/service/impl/CouponInfoServiceImpl.java
- regional-etl/src/main/resources/mappers/CouponInfoMapper.xml
regional-etl/pom.xml
View file @
3fecf5d
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 | <dependencies> |
19 | 19 | <dependency> |
20 | 20 | <groupId>org.springframework.boot</groupId> |
21 | - <artifactId>spring-boot-starter-web</artifactId> | |
21 | + <artifactId>spring-boot-starter</artifactId> | |
22 | 22 | </dependency> |
23 | 23 | |
24 | 24 | <dependency> |
... | ... | @@ -73,6 +73,17 @@ |
73 | 73 | <dependency> |
74 | 74 | <groupId>org.slf4j</groupId> |
75 | 75 | <artifactId>log4j-over-slf4j</artifactId> |
76 | + </dependency> | |
77 | + | |
78 | + <dependency> | |
79 | + <groupId>org.apache.commons</groupId> | |
80 | + <artifactId>commons-collections4</artifactId> | |
81 | + <version>4.1</version> | |
82 | + </dependency> | |
83 | + <dependency> | |
84 | + <groupId>org.apache.commons</groupId> | |
85 | + <artifactId>commons-lang3</artifactId> | |
86 | + <version>3.5</version> | |
76 | 87 | </dependency> |
77 | 88 | </dependencies> |
78 | 89 |
regional-etl/src/main/java/com/lyms/etl/ApplicationRunner.java
View file @
3fecf5d
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | import org.springframework.boot.CommandLineRunner; |
9 | 9 | import org.springframework.boot.SpringApplication; |
10 | 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
11 | +import org.springframework.transaction.annotation.EnableTransactionManagement; | |
11 | 12 | |
12 | 13 | import java.util.Date; |
13 | 14 | |
... | ... | @@ -17,6 +18,7 @@ |
17 | 18 | * @Version: V1.0 |
18 | 19 | */ |
19 | 20 | @SpringBootApplication |
21 | +@EnableTransactionManagement | |
20 | 22 | @MapperScan("com.lyms.etl.dao") |
21 | 23 | public class ApplicationRunner implements CommandLineRunner{ |
22 | 24 |
regional-etl/src/main/java/com/lyms/etl/dao/ICouponInfoDao.java
View file @
3fecf5d
1 | 1 | package com.lyms.etl.dao; |
2 | 2 | |
3 | 3 | import com.lyms.etl.model.CouponInfo; |
4 | +import com.lyms.etl.model.HospitalCouponTemplateGroup; | |
4 | 5 | |
6 | +import java.util.List; | |
7 | + | |
5 | 8 | /** |
6 | 9 | * @Author: litao |
7 | 10 | * @Date: 2017/5/3 0003 11:30 |
... | ... | @@ -12,5 +15,13 @@ |
12 | 15 | CouponInfo find(String id); |
13 | 16 | |
14 | 17 | void save(CouponInfo couponInfo); |
18 | + | |
19 | + String findTempId(Integer number); | |
20 | + | |
21 | + HospitalCouponTemplateGroup findHospital(String hospitalId); | |
22 | + | |
23 | + void saveHospitalGroup(HospitalCouponTemplateGroup hospitalCouponTemplateGroup); | |
24 | + | |
25 | + void batchSave(List<CouponInfo> commitList); | |
15 | 26 | } |
regional-etl/src/main/java/com/lyms/etl/model/HospitalCouponTemplateGroup.java
View file @
3fecf5d
1 | +package com.lyms.etl.model; | |
2 | + | |
3 | +/** | |
4 | + * 医院和优惠券模板表 多对一 对应关系 | |
5 | + * @date: 2017-05-05 11:43:33 | |
6 | + */ | |
7 | +public class HospitalCouponTemplateGroup { | |
8 | + private String id; | |
9 | + | |
10 | + private String hospitalId; | |
11 | + | |
12 | + private String couponTemplateGroupId; | |
13 | + | |
14 | + | |
15 | + public String getId() { | |
16 | + return id; | |
17 | + } | |
18 | + | |
19 | + public void setId(String id) { | |
20 | + this.id = id; | |
21 | + } | |
22 | + public String getHospitalId() { | |
23 | + return hospitalId; | |
24 | + } | |
25 | + | |
26 | + public void setHospitalId(String hospitalId) { | |
27 | + this.hospitalId = hospitalId; | |
28 | + } | |
29 | + public String getCouponTemplateGroupId() { | |
30 | + return couponTemplateGroupId; | |
31 | + } | |
32 | + | |
33 | + public void setCouponTemplateGroupId(String couponTemplateGroupId) { | |
34 | + this.couponTemplateGroupId = couponTemplateGroupId; | |
35 | + } | |
36 | + | |
37 | + @Override | |
38 | + public String toString() { | |
39 | + StringBuilder sb = new StringBuilder(); | |
40 | + sb.append("HospitalCouponTemplateGroup [ "); | |
41 | + sb.append("id=" + id + ","); | |
42 | + sb.append("hospitalId=" + hospitalId + ","); | |
43 | + sb.append("couponTemplateGroupId=" + couponTemplateGroupId + ","); | |
44 | + sb.replace(sb.length()-1, sb.length(), " ]"); | |
45 | + return sb.toString(); | |
46 | + } | |
47 | + | |
48 | + | |
49 | +} |
regional-etl/src/main/java/com/lyms/etl/service/impl/CouponInfoServiceImpl.java
View file @
3fecf5d
... | ... | @@ -3,14 +3,20 @@ |
3 | 3 | import com.lyms.etl.dao.ICouponInfoDao; |
4 | 4 | import com.lyms.etl.model.AntExChu; |
5 | 5 | import com.lyms.etl.model.CouponInfo; |
6 | +import com.lyms.etl.model.HospitalCouponTemplateGroup; | |
6 | 7 | import com.lyms.etl.model.PatientCheckTicket; |
7 | 8 | import com.lyms.etl.repository.AntExChuRepository; |
8 | 9 | import com.lyms.etl.repository.PatientCheckTicketRepository; |
9 | 10 | import com.lyms.etl.service.ICouponInfoService; |
10 | 11 | import com.lyms.etl.util.UUIDUtil; |
12 | +import org.apache.commons.collections4.CollectionUtils; | |
11 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 14 | import org.springframework.stereotype.Service; |
15 | +import org.springframework.transaction.annotation.Transactional; | |
13 | 16 | |
17 | +import java.util.ArrayList; | |
18 | +import java.util.HashSet; | |
19 | +import java.util.Set; | |
14 | 20 | import java.util.List; |
15 | 21 | |
16 | 22 | /** |
17 | 23 | |
18 | 24 | |
19 | 25 | |
20 | 26 | |
... | ... | @@ -34,19 +40,33 @@ |
34 | 40 | } |
35 | 41 | |
36 | 42 | @Override |
43 | + @Transactional | |
37 | 44 | public void transferCoupon() { |
45 | + List<CouponInfo> couponInfos = new ArrayList<>(); | |
46 | + Set<String> hospitalIds = new HashSet<>(); | |
38 | 47 | List<PatientCheckTicket> patientCheckTickets = patientCheckTicketRepository.findAll(); |
39 | - for (PatientCheckTicket patientCheckTicket : patientCheckTickets) { | |
40 | - System.err.println(patientCheckTicket); | |
48 | + for (PatientCheckTicket checkTicket : patientCheckTickets) { | |
49 | + couponInfos.add(createCouponInfo(checkTicket, hospitalIds)); | |
41 | 50 | } |
42 | - PatientCheckTicket checkTicket = patientCheckTicketRepository.findOne("033500003781"); | |
51 | + batchInsert(couponInfos, 100); | |
52 | + | |
53 | + setnx(hospitalIds); | |
54 | + } | |
55 | + | |
56 | + /** | |
57 | + * 创建产检券model 并且得到hospitalId | |
58 | + * @param checkTicket | |
59 | + * @param hospitalIds | |
60 | + * @return | |
61 | + */ | |
62 | + private CouponInfo createCouponInfo(PatientCheckTicket checkTicket, Set<String> hospitalIds) { | |
43 | 63 | CouponInfo couponInfo = new CouponInfo(); |
44 | 64 | couponInfo.setId(UUIDUtil.createId()); |
45 | 65 | couponInfo.setSequenceId(checkTicket.getId()); |
46 | 66 | couponInfo.setCreateDate(checkTicket.getCreated()); |
47 | 67 | couponInfo.setUseDate(checkTicket.getConsumeDate()); |
48 | 68 | couponInfo.setUserId(checkTicket.getPid()); |
49 | - couponInfo.setCouponTemplateId(""); | |
69 | + couponInfo.setCouponTemplateId(parseSuffix(checkTicket.getId())); | |
50 | 70 | couponInfo.setCreateHospitalId(checkTicket.getHospitalId()); |
51 | 71 | couponInfo.setUsedHospitalId(checkTicket.getConsumeHospitalId()); |
52 | 72 | couponInfo.setStatus(checkTicket.getStatus()); |
53 | 73 | |
... | ... | @@ -55,9 +75,60 @@ |
55 | 75 | if(antExChu != null) { |
56 | 76 | couponInfo.setOperatorUseId(antExChu.getProdDoctor()); |
57 | 77 | } |
58 | - couponInfoDao.save(couponInfo); | |
59 | - System.err.println("xx》 " + antExChuRepository.findByBarCode("033500000051")); | |
78 | + hospitalIds.add(checkTicket.getHospitalId()); | |
60 | 79 | |
80 | + return couponInfo; | |
81 | + } | |
82 | + | |
83 | + /** | |
84 | + * 批量插入 | |
85 | + * @param couponInfos | |
86 | + * @param size | |
87 | + */ | |
88 | + private void batchInsert(List<CouponInfo> couponInfos, Integer size) { | |
89 | + List<CouponInfo> commitList = new ArrayList<>(); | |
90 | + for (int i = 0; i < couponInfos.size(); i++) { | |
91 | + commitList.add(couponInfos.get(i)); | |
92 | + | |
93 | + if(i != 0 && commitList.size() % size == 0) { | |
94 | + couponInfoDao.batchSave(commitList); | |
95 | + commitList.clear(); | |
96 | + } | |
97 | + } | |
98 | + if(CollectionUtils.isNotEmpty(commitList)) { | |
99 | + couponInfoDao.batchSave(commitList); | |
100 | + } | |
101 | + } | |
102 | + | |
103 | + /** | |
104 | + * 验证医院是否存在 | |
105 | + * @param hospitalId | |
106 | + * @return | |
107 | + */ | |
108 | + private boolean validateHospital(String hospitalId) { | |
109 | + HospitalCouponTemplateGroup hospital = couponInfoDao.findHospital(hospitalId); | |
110 | + return hospital == null ? false : true; | |
111 | + } | |
112 | + | |
113 | + private String parseSuffix(String id) { | |
114 | + Integer number = Integer.parseInt(id.substring(id.length() - 1, id.length())); | |
115 | + return couponInfoDao.findTempId(number); | |
116 | + } | |
117 | + | |
118 | + /** | |
119 | + * 医院 不存在就创建 | |
120 | + * @param hospitalIds | |
121 | + */ | |
122 | + public void setnx(Set<String> hospitalIds) { | |
123 | + for (String hospitalId : hospitalIds) { | |
124 | + if(!validateHospital(hospitalId)) { | |
125 | + HospitalCouponTemplateGroup hospitalCouponTemplateGroup = new HospitalCouponTemplateGroup(); | |
126 | + hospitalCouponTemplateGroup.setId(UUIDUtil.createId()); | |
127 | + hospitalCouponTemplateGroup.setHospitalId(hospitalId); | |
128 | + hospitalCouponTemplateGroup.setCouponTemplateGroupId("5150e962-2af9-11e7-9daf-8dc94911792e"); | |
129 | + couponInfoDao.saveHospitalGroup(hospitalCouponTemplateGroup); | |
130 | + } | |
131 | + } | |
61 | 132 | } |
62 | 133 | } |
regional-etl/src/main/resources/mappers/CouponInfoMapper.xml
View file @
3fecf5d
... | ... | @@ -18,6 +18,12 @@ |
18 | 18 | <result column="operator_use_id" property="operatorUseId"/> |
19 | 19 | </resultMap> |
20 | 20 | |
21 | + <resultMap type="HospitalCouponTemplateGroup" id="hospitalCouponTemplateGroupMap"> | |
22 | + <result column="id" property="id"/> | |
23 | + <result column="hospital_id" property="hospitalId"/> | |
24 | + <result column="coupon_template_group_id" property="couponTemplateGroupId"/> | |
25 | + </resultMap> | |
26 | + | |
21 | 27 | <sql id="columnList"> |
22 | 28 | sequence_id,create_date,use_date,user_id,create_user_id,coupon_template_id,create_hospital_id,used_hospital_id,status |
23 | 29 | </sql> |
... | ... | @@ -28,6 +34,28 @@ |
28 | 34 | |
29 | 35 | <insert id="save" parameterType="CouponInfo"> |
30 | 36 | insert into coupon_info(id, <include refid="columnList" />) values(#{id},#{sequenceId},#{createDate},#{useDate},#{userId},#{createUserId},#{couponTemplateId},#{createHospitalId},#{usedHospitalId},#{status}) |
37 | + </insert> | |
38 | + | |
39 | + <select id="findTempId" parameterType="integer" resultType="string"> | |
40 | + SELECT a.id FROM | |
41 | + coupon_template a, coupon_type b | |
42 | + WHERE a.type_id = b.id and b.type = 2 and a.coupon_order = #{number} | |
43 | + order by a.coupon_order | |
44 | + </select> | |
45 | + | |
46 | + <select id="findHospital" parameterType="string" resultMap="hospitalCouponTemplateGroupMap"> | |
47 | + select id,hospital_id,coupon_template_group_id from hospital_coupon_template_group where hospital_id = #{id} | |
48 | + </select> | |
49 | + | |
50 | + <insert id="saveHospitalGroup" parameterType="HospitalCouponTemplateGroup"> | |
51 | + insert into hospital_coupon_template_group values(#{id}, #{hospitalId},#{couponTemplateGroupId}) | |
52 | + </insert> | |
53 | + | |
54 | + <insert id="batchSave" parameterType="list"> | |
55 | + insert into coupon_info(id, <include refid="columnList" />) values | |
56 | + <foreach collection="list" item="item" index="index" separator="," > | |
57 | + (#{item.id}, #{item.sequenceId}, #{item.createDate}, #{item.useDate}, #{item.userId}, #{item.createUserId}, #{item.couponTemplateId}, #{item.createHospitalId}, #{item.usedHospitalId}, #{item.status}) | |
58 | + </foreach> | |
31 | 59 | </insert> |
32 | 60 | </mapper> |