Commit d0614416052b904c84d98a06d302adf4c508df9e
1 parent
76950d319d
Exists in
master
and in
6 other branches
etl项目多环境配置增加
Showing 9 changed files with 210 additions and 145 deletions
- regional-etl/src/main/java/com/lyms/etl/ApplicationRunner.java
- regional-etl/src/main/java/com/lyms/etl/service/ICouponInfoService.java
- regional-etl/src/main/java/com/lyms/etl/service/IEtlService.java
- regional-etl/src/main/java/com/lyms/etl/service/IInvokeHandler.java
- regional-etl/src/main/java/com/lyms/etl/service/impl/CouponInfoServiceImpl.java
- regional-etl/src/main/java/com/lyms/etl/service/impl/CouponServiceImpl.java
- regional-etl/src/main/java/com/lyms/etl/service/impl/EtlServiceImpl.java
- regional-etl/src/main/resources/application-prod.yml
- regional-etl/src/main/resources/application.yml
regional-etl/src/main/java/com/lyms/etl/ApplicationRunner.java
View file @
d061441
| 1 | 1 | package com.lyms.etl; | 
| 2 | 2 | |
| 3 | -import com.lyms.etl.service.ICouponInfoService; | |
| 3 | +import com.lyms.etl.service.IInvokeHandler; | |
| 4 | 4 | import org.mybatis.spring.annotation.MapperScan; | 
| 5 | 5 | import org.slf4j.Logger; | 
| 6 | 6 | import org.slf4j.LoggerFactory; | 
| ... | ... | @@ -11,6 +11,7 @@ | 
| 11 | 11 | import org.springframework.transaction.annotation.EnableTransactionManagement; | 
| 12 | 12 | |
| 13 | 13 | import java.util.Date; | 
| 14 | +import java.util.Set; | |
| 14 | 15 | |
| 15 | 16 | /** | 
| 16 | 17 | * @Author: litao | 
| ... | ... | @@ -25,7 +26,7 @@ | 
| 25 | 26 | private static final Logger log = LoggerFactory.getLogger(ApplicationRunner.class); | 
| 26 | 27 | |
| 27 | 28 | @Autowired | 
| 28 | - private ICouponInfoService couponInfoService; | |
| 29 | + Set<IInvokeHandler> invokeHandlers; | |
| 29 | 30 | |
| 30 | 31 | public static void main(String[] args) { | 
| 31 | 32 | SpringApplication.run(ApplicationRunner.class, args); | 
| ... | ... | @@ -34,10 +35,12 @@ | 
| 34 | 35 | |
| 35 | 36 | @Override | 
| 36 | 37 | public void run(String... strings) throws Exception { | 
| 37 | - log.info("start import coupon"); | |
| 38 | - Date start = new Date(); | |
| 39 | - couponInfoService.transferCoupon(); | |
| 40 | - log.info("end import coupon, used: {} ms", System.currentTimeMillis() - start.getTime()); | |
| 38 | + for (IInvokeHandler handler : invokeHandlers) { | |
| 39 | + Date start = new Date(); | |
| 40 | + log.info("start ................ {}", handler.getClass().getName()); | |
| 41 | + handler.invoke(); | |
| 42 | + log.info("end ................ used: {} ms", System.currentTimeMillis() - start.getTime()); | |
| 43 | + } | |
| 41 | 44 | } | 
| 42 | 45 | } | 
regional-etl/src/main/java/com/lyms/etl/service/ICouponInfoService.java
View file @
d061441
| 1 | 1 | package com.lyms.etl.service; | 
| 2 | 2 | |
| 3 | -import com.lyms.etl.model.CouponInfo; | |
| 4 | - | |
| 5 | 3 | /** | 
| 6 | 4 | * @Author: litao | 
| 7 | 5 | * @Date: 2017/5/3 0003 11:43 | 
| 8 | 6 | * @Version: V1.0 | 
| 9 | 7 | */ | 
| 10 | -public interface ICouponInfoService { | |
| 11 | - CouponInfo find(String id); | |
| 12 | - | |
| 8 | +public interface ICouponInfoService extends IInvokeHandler { | |
| 13 | 9 | void transferCoupon(); | 
| 14 | 10 | } | 
regional-etl/src/main/java/com/lyms/etl/service/IEtlService.java
View file @
d061441
regional-etl/src/main/java/com/lyms/etl/service/IInvokeHandler.java
View file @
d061441
regional-etl/src/main/java/com/lyms/etl/service/impl/CouponInfoServiceImpl.java
View file @
d061441
| 1 | -package com.lyms.etl.service.impl; | |
| 2 | - | |
| 3 | -import com.lyms.etl.dao.ICouponInfoDao; | |
| 4 | -import com.lyms.etl.model.AntExChu; | |
| 5 | -import com.lyms.etl.model.CouponInfo; | |
| 6 | -import com.lyms.etl.model.HospitalCouponTemplateGroup; | |
| 7 | -import com.lyms.etl.model.PatientCheckTicket; | |
| 8 | -import com.lyms.etl.repository.AntExChuRepository; | |
| 9 | -import com.lyms.etl.repository.PatientCheckTicketRepository; | |
| 10 | -import com.lyms.etl.service.ICouponInfoService; | |
| 11 | -import com.lyms.etl.util.UUIDUtil; | |
| 12 | -import org.apache.commons.collections4.CollectionUtils; | |
| 13 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | -import org.springframework.stereotype.Service; | |
| 15 | -import org.springframework.transaction.annotation.Transactional; | |
| 16 | - | |
| 17 | -import java.util.ArrayList; | |
| 18 | -import java.util.HashSet; | |
| 19 | -import java.util.Set; | |
| 20 | -import java.util.List; | |
| 21 | - | |
| 22 | -/** | |
| 23 | - * @Author: litao | |
| 24 | - * @Date: 2017/5/3 0003 11:45 | |
| 25 | - * @Version: V1.0 | |
| 26 | - */ | |
| 27 | -@Service | |
| 28 | -public class CouponInfoServiceImpl implements ICouponInfoService { | |
| 29 | - @Autowired | |
| 30 | - private ICouponInfoDao couponInfoDao; | |
| 31 | - | |
| 32 | - @Autowired | |
| 33 | - private PatientCheckTicketRepository patientCheckTicketRepository; | |
| 34 | - @Autowired | |
| 35 | - private AntExChuRepository antExChuRepository; | |
| 36 | - | |
| 37 | - @Override | |
| 38 | - public CouponInfo find(String id) { | |
| 39 | - return couponInfoDao.find(id); | |
| 40 | - } | |
| 41 | - | |
| 42 | - @Override | |
| 43 | - @Transactional | |
| 44 | - public void transferCoupon() { | |
| 45 | - List<CouponInfo> couponInfos = new ArrayList<>(); | |
| 46 | - Set<String> hospitalIds = new HashSet<>(); | |
| 47 | - List<PatientCheckTicket> patientCheckTickets = patientCheckTicketRepository.findAll(); | |
| 48 | - for (PatientCheckTicket checkTicket : patientCheckTickets) { | |
| 49 | - couponInfos.add(createCouponInfo(checkTicket, hospitalIds)); | |
| 50 | - } | |
| 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) { | |
| 63 | - CouponInfo couponInfo = new CouponInfo(); | |
| 64 | - couponInfo.setId(UUIDUtil.createId()); | |
| 65 | - couponInfo.setSequenceId(checkTicket.getId()); | |
| 66 | - couponInfo.setCreateDate(checkTicket.getCreated()); | |
| 67 | - couponInfo.setUseDate(checkTicket.getConsumeDate()); | |
| 68 | - couponInfo.setUserId(checkTicket.getPid()); | |
| 69 | - couponInfo.setCouponTemplateId(parseSuffix(checkTicket.getId())); | |
| 70 | - couponInfo.setCreateHospitalId(checkTicket.getHospitalId()); | |
| 71 | - couponInfo.setUsedHospitalId(checkTicket.getConsumeHospitalId()); | |
| 72 | - couponInfo.setStatus(checkTicket.getStatus()); | |
| 73 | - couponInfo.setCreateUserId(null); | |
| 74 | - AntExChu antExChu = antExChuRepository.findByBarCode(checkTicket.getId()); | |
| 75 | - if(antExChu != null) { | |
| 76 | - couponInfo.setOperatorUseId(antExChu.getProdDoctor()); | |
| 77 | - } | |
| 78 | - hospitalIds.add(checkTicket.getHospitalId()); | |
| 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 | - } | |
| 132 | - } | |
| 133 | -} | 
regional-etl/src/main/java/com/lyms/etl/service/impl/CouponServiceImpl.java
View file @
d061441
| 1 | +package com.lyms.etl.service.impl; | |
| 2 | + | |
| 3 | +import com.lyms.etl.dao.ICouponInfoDao; | |
| 4 | +import com.lyms.etl.model.AntExChu; | |
| 5 | +import com.lyms.etl.model.CouponInfo; | |
| 6 | +import com.lyms.etl.model.HospitalCouponTemplateGroup; | |
| 7 | +import com.lyms.etl.model.PatientCheckTicket; | |
| 8 | +import com.lyms.etl.repository.AntExChuRepository; | |
| 9 | +import com.lyms.etl.repository.PatientCheckTicketRepository; | |
| 10 | +import com.lyms.etl.service.ICouponInfoService; | |
| 11 | +import com.lyms.etl.util.UUIDUtil; | |
| 12 | +import org.apache.commons.collections4.CollectionUtils; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.context.annotation.Profile; | |
| 15 | +import org.springframework.stereotype.Service; | |
| 16 | +import org.springframework.transaction.annotation.Transactional; | |
| 17 | + | |
| 18 | +import java.util.ArrayList; | |
| 19 | +import java.util.HashSet; | |
| 20 | +import java.util.Set; | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * @Author: litao | |
| 25 | + * @Date: 2017/5/3 0003 11:45 | |
| 26 | + * @Version: V1.0 | |
| 27 | + */ | |
| 28 | +@Profile("coupon") | |
| 29 | +@Service | |
| 30 | +public class CouponServiceImpl implements ICouponInfoService { | |
| 31 | + @Autowired | |
| 32 | + private ICouponInfoDao couponInfoDao; | |
| 33 | + | |
| 34 | + @Autowired | |
| 35 | + private PatientCheckTicketRepository patientCheckTicketRepository; | |
| 36 | + @Autowired | |
| 37 | + private AntExChuRepository antExChuRepository; | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + @Transactional | |
| 41 | + public void transferCoupon() { | |
| 42 | + List<CouponInfo> couponInfos = new ArrayList<>(); | |
| 43 | + Set<String> hospitalIds = new HashSet<>(); | |
| 44 | + List<PatientCheckTicket> patientCheckTickets = patientCheckTicketRepository.findAll(); | |
| 45 | + for (PatientCheckTicket checkTicket : patientCheckTickets) { | |
| 46 | + couponInfos.add(createCouponInfo(checkTicket, hospitalIds)); | |
| 47 | + } | |
| 48 | + batchInsert(couponInfos, 100); | |
| 49 | + | |
| 50 | + setnx(hospitalIds); | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * 创建产检券model 并且得到hospitalId | |
| 55 | + * @param checkTicket | |
| 56 | + * @param hospitalIds | |
| 57 | + * @return | |
| 58 | + */ | |
| 59 | + private CouponInfo createCouponInfo(PatientCheckTicket checkTicket, Set<String> hospitalIds) { | |
| 60 | + CouponInfo couponInfo = new CouponInfo(); | |
| 61 | + couponInfo.setId(UUIDUtil.createId()); | |
| 62 | + couponInfo.setSequenceId(checkTicket.getId()); | |
| 63 | + couponInfo.setCreateDate(checkTicket.getCreated()); | |
| 64 | + couponInfo.setUseDate(checkTicket.getConsumeDate()); | |
| 65 | + couponInfo.setUserId(checkTicket.getPid()); | |
| 66 | + couponInfo.setCouponTemplateId(parseSuffix(checkTicket.getId())); | |
| 67 | + couponInfo.setCreateHospitalId(checkTicket.getHospitalId()); | |
| 68 | + couponInfo.setUsedHospitalId(checkTicket.getConsumeHospitalId()); | |
| 69 | + couponInfo.setStatus(checkTicket.getStatus()); | |
| 70 | + couponInfo.setCreateUserId(null); | |
| 71 | + AntExChu antExChu = antExChuRepository.findByBarCode(checkTicket.getId()); | |
| 72 | + if(antExChu != null) { | |
| 73 | + couponInfo.setOperatorUseId(antExChu.getProdDoctor()); | |
| 74 | + } | |
| 75 | + hospitalIds.add(checkTicket.getHospitalId()); | |
| 76 | + | |
| 77 | + return couponInfo; | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * 批量插入 | |
| 82 | + * @param couponInfos | |
| 83 | + * @param size | |
| 84 | + */ | |
| 85 | + private void batchInsert(List<CouponInfo> couponInfos, Integer size) { | |
| 86 | + List<CouponInfo> commitList = new ArrayList<>(); | |
| 87 | + for (int i = 0; i < couponInfos.size(); i++) { | |
| 88 | + commitList.add(couponInfos.get(i)); | |
| 89 | + | |
| 90 | + if(i != 0 && commitList.size() % size == 0) { | |
| 91 | + couponInfoDao.batchSave(commitList); | |
| 92 | + commitList.clear(); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + if(CollectionUtils.isNotEmpty(commitList)) { | |
| 96 | + couponInfoDao.batchSave(commitList); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * 验证医院是否存在 | |
| 102 | + * @param hospitalId | |
| 103 | + * @return | |
| 104 | + */ | |
| 105 | + private boolean validateHospital(String hospitalId) { | |
| 106 | + HospitalCouponTemplateGroup hospital = couponInfoDao.findHospital(hospitalId); | |
| 107 | + return hospital == null ? false : true; | |
| 108 | + } | |
| 109 | + | |
| 110 | + private String parseSuffix(String id) { | |
| 111 | + Integer number = Integer.parseInt(id.substring(id.length() - 1, id.length())); | |
| 112 | + return couponInfoDao.findTempId(number); | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * 医院 不存在就创建 | |
| 117 | + * @param hospitalIds | |
| 118 | + */ | |
| 119 | + public void setnx(Set<String> hospitalIds) { | |
| 120 | + for (String hospitalId : hospitalIds) { | |
| 121 | + if(!validateHospital(hospitalId)) { | |
| 122 | + HospitalCouponTemplateGroup hospitalCouponTemplateGroup = new HospitalCouponTemplateGroup(); | |
| 123 | + hospitalCouponTemplateGroup.setId(UUIDUtil.createId()); | |
| 124 | + hospitalCouponTemplateGroup.setHospitalId(hospitalId); | |
| 125 | + hospitalCouponTemplateGroup.setCouponTemplateGroupId("5150e962-2af9-11e7-9daf-8dc94911792e"); | |
| 126 | + couponInfoDao.saveHospitalGroup(hospitalCouponTemplateGroup); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + } | |
| 130 | + | |
| 131 | + @Override | |
| 132 | + public void invoke() { | |
| 133 | + transferCoupon(); | |
| 134 | + } | |
| 135 | +} | 
regional-etl/src/main/java/com/lyms/etl/service/impl/EtlServiceImpl.java
View file @
d061441
| 1 | 1 | package com.lyms.etl.service.impl; | 
| 2 | 2 | |
| 3 | 3 | import com.lyms.etl.service.IEtlService; | 
| 4 | +import org.springframework.context.annotation.Profile; | |
| 5 | +import org.springframework.stereotype.Service; | |
| 4 | 6 | |
| 5 | 7 | /** | 
| 6 | 8 | * @Author: litao | 
| 7 | 9 | * @Date: 2017/5/3 0003 12:00 | 
| 8 | 10 | * @Version: V1.0 | 
| 9 | 11 | */ | 
| 12 | +@Profile("etl") | |
| 13 | +@Service | |
| 10 | 14 | public class EtlServiceImpl implements IEtlService { | 
| 15 | + @Override | |
| 16 | + public void invoke() { | |
| 17 | + System.out.println("etl >> "); | |
| 18 | + } | |
| 19 | + | |
| 11 | 20 | } | 
regional-etl/src/main/resources/application-prod.yml
View file @
d061441
| 1 | +server: | |
| 2 | + port: 8081 | |
| 3 | +spring: | |
| 4 | + datasource: | |
| 5 | + url: jdbc:mysql://119.90.43.68:3307/platform?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 | |
| 6 | + username: platform | |
| 7 | + password: platform123 | |
| 8 | + driver-class-name: com.mysql.jdbc.Driver | |
| 9 | + | |
| 10 | + type: com.alibaba.druid.pool.DruidDataSource | |
| 11 | + initialSize: 5 | |
| 12 | + minIdle: 5 | |
| 13 | + maxActive: 20 | |
| 14 | + maxWait: 60000 | |
| 15 | + timeBetweenEvictionRunsMillis: 60000 | |
| 16 | + minEvictableIdleTimeMillis: 300000 | |
| 17 | + validationQuery: SELECT 1 FROM DUAL | |
| 18 | + testWhileIdle: true | |
| 19 | + testOnBorrow: false | |
| 20 | + testOnReturn: false | |
| 21 | + poolPreparedStatements: true | |
| 22 | + maxPoolPreparedStatementPerConnectionSize: 20 | |
| 23 | + filters: stat,wall,log4j | |
| 24 | + useGlobalDataSourceStat: true | |
| 25 | + connectionProperties: | |
| 26 | + druid: | |
| 27 | + stat: | |
| 28 | + mergeSql: true | |
| 29 | + druid: | |
| 30 | + stat: | |
| 31 | + slowSqlMillis: 5000 | |
| 32 | + data: | |
| 33 | + mongodb: | |
| 34 | + host: 119.90.57.26 | |
| 35 | + port: 10001 | |
| 36 | + database: platform | |
| 37 | + username: platform | |
| 38 | + password: platform123 | |
| 39 | + profiles: | |
| 40 | + active: etl | |
| 41 | +mybatis: | |
| 42 | + typeAliasesPackage: com.lyms.etl.model | |
| 43 | + mapperLocations: classpath:mappers/*.xml | 
regional-etl/src/main/resources/application.yml
View file @
d061441