From 98a72001c95cacf076b92921197c959a327b1057 Mon Sep 17 00:00:00 2001 From: litao Date: Tue, 23 May 2017 17:48:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/mainOrm/master/CouponMapper.xml | 93 +++++++++++----------- .../lyms/platform/common/result/RespBuilder.java | 12 +-- .../operate/web/controller/ReportController.java | 2 +- .../web/service/impl/ReportServiceImpl.java | 20 ++--- .../main/java/com/lyms/etl/dao/ICouponInfoDao.java | 3 +- .../etl/datasource/DynamicDataSourceRegister.java | 29 ++++--- .../lyms/etl/service/impl/CouponServiceImpl.java | 34 +++++--- .../src/main/resources/application.properties | 2 +- regional-etl/src/main/resources/application.yml | 12 ++- regional-etl/src/main/resources/logback.xml | 6 +- .../main/resources/mappers/CouponInfoMapper.xml | 7 +- 11 files changed, 123 insertions(+), 97 deletions(-) diff --git a/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml b/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml index 2e60501..093b437 100644 --- a/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml +++ b/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml @@ -109,13 +109,13 @@ update coupon_info a inner join ( - select a.id - from coupon_info a, coupon_template b, coupon_type c - where a.coupon_template_id = b.id and b.type_id = c.id and a.status=1 and c.type in - - #{type} - - and a.user_id = #{personId} + select a.id + from coupon_info a, coupon_template b, coupon_type c + where a.coupon_template_id = b.id and b.type_id = c.id and a.status=1 and c.type in + + #{type} + + and a.user_id = #{personId} ) b on a.id = b.id set a.status = 3 @@ -135,52 +135,52 @@ - \ No newline at end of file diff --git a/platform-common/src/main/java/com/lyms/platform/common/result/RespBuilder.java b/platform-common/src/main/java/com/lyms/platform/common/result/RespBuilder.java index 17b3234..d17c8fe 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/result/RespBuilder.java +++ b/platform-common/src/main/java/com/lyms/platform/common/result/RespBuilder.java @@ -1,6 +1,7 @@ package com.lyms.platform.common.result; import org.apache.commons.lang3.StringUtils; +import org.springframework.util.Assert; import java.util.HashMap; import java.util.Map; @@ -15,21 +16,19 @@ public class RespBuilder { return buildSuccess(null); } - public static BaseObjectResponse buildSuccess(Object data) { + public static BaseObjectResponse buildSuccess(Object ... data) { BaseObjectResponse resp = new BaseObjectResponse(); - resp.setData(data); - return resp; - /* BaseObjectResponse resp = new BaseObjectResponse(); + if(data != null) { Assert.isTrue(data.length == 1 || data.length % 2 == 0, "length必须为偶数"); if(data.length == 1) { - resp.setData(data); + resp.setData(data[0]); } else { resp.setData(createMap(data)); } } - return resp;*/ + return resp; } public static BaseObjectResponse buildErro(ResponseCode code) { @@ -60,4 +59,5 @@ public class RespBuilder { } return map; } + } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java index c9f0a69..0dd2e1b 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java @@ -209,7 +209,7 @@ public class ReportController extends BaseController { public BaseObjectResponse coupon(HttpServletRequest request, Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType) { Map param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate, - "endDate", endDate, "hospitalIds", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", + "endDate", endDate, "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "tempId", tempId, "couponType", couponType); return reportService.couponInfo(param); } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java index df36dca..1315085 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java @@ -407,25 +407,26 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService @Override public BaseObjectResponse couponInfo(Map param) { - List hospitalIds = Arrays.asList("216", "245"); /** 模拟根据登陆人id 查询出来的医院 */ - - param.put("hospitalIds", CollectionUtils.asList((String) param.get("hospitalIds"))); + if(StringUtils.isBlank((String) param.get("hospitalId"))) { + param.put("hospitalId", Arrays.asList("216", "245")); /** 模拟根据登陆人id 查询出来的医院 */ + } else { + param.put("hospitalId", CollectionUtils.asList((String) param.get("hospitalId"))); + } param.put("status", 2); - param.put("couponTypes", CollectionUtils.asList((String) param.get("couponTypes"))); + param.put("couponType", CollectionUtils.asList((String) param.get("couponType"))); List> couponReport = couponMapper.findReport(param); /** 优惠券统计详情(发放人数、发放券数、使用人数、使用券数) */ List> usedInfo = couponMapper.findUsedInfo(param); /** 优惠券使用详情 */ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) && org.apache.commons.collections.CollectionUtils.isNotEmpty(usedInfo)) { - if(CollectionUtils.putAll(couponReport, usedInfo, "used_hospital_id", "used_hospital_id")) { - + if(CollectionUtils.putAll(couponReport, usedInfo, "create_hospital_id", "used_hospital_id")) { for (Map map : couponReport) { map.put("province_name", findName(map.get("province_id"))); map.put("city_name", findName(map.get("city_id"))); map.put("area_name", findName(map.get("area_id"))); } -// return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", couponReportMap); + return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", couponReportMap); } else{ return RespBuilder.buildErro(ResponseCode.DATA_ERROR); } @@ -437,9 +438,8 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService public BaseObjectResponse couponInit(Map param) { List hospitalIds = Arrays.asList("216", "245"); /** 模拟根据登陆人id 查询出来的医院 */ param.put("hospitalIds", hospitalIds); - /* return RespBuilder.buildSuccess("coupons", EnumUtil.toJson(CouponEnums.class, "code", "name"), - "hTemp", couponMapper.findHospitals(param));*/ - return RespBuilder.buildSuccess(); + return RespBuilder.buildSuccess("coupons", EnumUtil.toJson(CouponEnums.class, "code", "name"), + "hTemp", couponMapper.findHospitals(param)); } public static void main(String[] args) { diff --git a/regional-etl/src/main/java/com/lyms/etl/dao/ICouponInfoDao.java b/regional-etl/src/main/java/com/lyms/etl/dao/ICouponInfoDao.java index 1c02442..66bb2d3 100644 --- a/regional-etl/src/main/java/com/lyms/etl/dao/ICouponInfoDao.java +++ b/regional-etl/src/main/java/com/lyms/etl/dao/ICouponInfoDao.java @@ -4,6 +4,7 @@ import com.lyms.etl.model.CouponInfo; import com.lyms.etl.model.HospitalCouponTemplateGroup; import java.util.List; +import java.util.Map; /** * @Author: litao @@ -16,7 +17,7 @@ public interface ICouponInfoDao { void save(CouponInfo couponInfo); - String findTempId(Integer number); + String findTempId(Map number); HospitalCouponTemplateGroup findHospital(String hospitalId); diff --git a/regional-etl/src/main/java/com/lyms/etl/datasource/DynamicDataSourceRegister.java b/regional-etl/src/main/java/com/lyms/etl/datasource/DynamicDataSourceRegister.java index c6666e9..4c4c128 100644 --- a/regional-etl/src/main/java/com/lyms/etl/datasource/DynamicDataSourceRegister.java +++ b/regional-etl/src/main/java/com/lyms/etl/datasource/DynamicDataSourceRegister.java @@ -32,41 +32,44 @@ public class DynamicDataSourceRegister @Override public void setEnvironment(Environment environment) { initDefaultDataSource(environment); - initCustomDataSources(environment); +// initCustomDataSources(environment); } /** - * 初始化多数据源 + * 初始化主数据源(默认数据源) * @param environment */ - private void initCustomDataSources(Environment environment) { + @ConfigurationProperties + private void initDefaultDataSource(Environment environment) { try { RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, "spring.datasource"); - Map connProperties = propertyResolver.getSubProperties("."); - System.err.println("connProperties>>> " + connProperties); - List customs = (List) connProperties.get("customs"); + Map connProperties = propertyResolver.getSubProperties(".default."); + System.err.println("connProperties = [" + connProperties + "]"); + defaultDataSource = DruidDataSourceFactory.createDataSource(connProperties); } catch (Exception e) { - LOG.error("初始化多数据源失败:", e.fillInStackTrace()); + LOG.error("初始化主数据源出错:", e.fillInStackTrace()); } } + /** - * 初始化主数据源(默认数据源) + * 初始化多数据源 * @param environment */ - @ConfigurationProperties - private void initDefaultDataSource(Environment environment) { + private void initCustomDataSources(Environment environment) { try { RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, "spring.datasource"); - Map connProperties = propertyResolver.getSubProperties("."); - defaultDataSource = DruidDataSourceFactory.createDataSource(connProperties); + Map connProperties = propertyResolver.getSubProperties(".default."); + System.err.println("connProperties>>> " + connProperties); + List customs = (List) connProperties.get("customs"); } catch (Exception e) { - LOG.error("初始化主数据源出错:", e.fillInStackTrace()); + LOG.error("初始化多数据源失败:", e.fillInStackTrace()); } } + @Override public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) { System.err.println("registerBeanDefinitions"); diff --git a/regional-etl/src/main/java/com/lyms/etl/service/impl/CouponServiceImpl.java b/regional-etl/src/main/java/com/lyms/etl/service/impl/CouponServiceImpl.java index ff52cb8..1a9e425 100644 --- a/regional-etl/src/main/java/com/lyms/etl/service/impl/CouponServiceImpl.java +++ b/regional-etl/src/main/java/com/lyms/etl/service/impl/CouponServiceImpl.java @@ -10,15 +10,15 @@ import com.lyms.etl.repository.PatientCheckTicketRepository; import com.lyms.etl.service.ICouponInfoService; import com.lyms.etl.util.UUIDUtil; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; -import java.util.List; +import java.util.*; /** * @Author: litao @@ -28,6 +28,9 @@ import java.util.List; @Profile("coupon") @Service public class CouponServiceImpl implements ICouponInfoService { + + private Logger LOG = LoggerFactory.getLogger(CouponServiceImpl.class); + @Autowired private ICouponInfoDao couponInfoDao; @@ -42,8 +45,13 @@ public class CouponServiceImpl implements ICouponInfoService { List couponInfos = new ArrayList<>(); Set hospitalIds = new HashSet<>(); List patientCheckTickets = patientCheckTicketRepository.findAll(); + LOG.info("本次共需要导入 [{}] 条数据", patientCheckTickets.size()); for (PatientCheckTicket checkTicket : patientCheckTickets) { - couponInfos.add(createCouponInfo(checkTicket, hospitalIds)); + CouponInfo couponInfo = createCouponInfo(checkTicket, hospitalIds); + if(couponInfo != null) { + couponInfos.add(couponInfo); + LOG.info("正在创建第 [{}] 个优惠券", couponInfos.size()); + } } batchInsert(couponInfos, 100); @@ -63,7 +71,7 @@ public class CouponServiceImpl implements ICouponInfoService { couponInfo.setCreateDate(checkTicket.getCreated()); couponInfo.setUseDate(checkTicket.getConsumeDate()); couponInfo.setUserId(checkTicket.getPid()); - couponInfo.setCouponTemplateId(parseSuffix(checkTicket.getId())); + couponInfo.setCouponTemplateId(parseSuffix(checkTicket.getId(), checkTicket.getHospitalId())); couponInfo.setCreateHospitalId(checkTicket.getHospitalId()); couponInfo.setUsedHospitalId(checkTicket.getConsumeHospitalId()); couponInfo.setStatus(checkTicket.getStatus()); @@ -74,6 +82,9 @@ public class CouponServiceImpl implements ICouponInfoService { } hospitalIds.add(checkTicket.getHospitalId()); + if(StringUtils.isBlank(couponInfo.getCouponTemplateId())) { + return null; + } return couponInfo; } @@ -83,11 +94,13 @@ public class CouponServiceImpl implements ICouponInfoService { * @param size */ private void batchInsert(List couponInfos, Integer size) { + LOG.info("开始导入数据, 共 [{}] 条: ", couponInfos.size()); List commitList = new ArrayList<>(); for (int i = 0; i < couponInfos.size(); i++) { commitList.add(couponInfos.get(i)); if(i != 0 && commitList.size() % size == 0) { + LOG.info("插入第 [{}] 条数据, 共 [{}] 条: ", i, couponInfos.size()); couponInfoDao.batchSave(commitList); commitList.clear(); } @@ -107,9 +120,12 @@ public class CouponServiceImpl implements ICouponInfoService { return hospital == null ? false : true; } - private String parseSuffix(String id) { + private String parseSuffix(String id, String hospitalId) { Integer number = Integer.parseInt(id.substring(id.length() - 1, id.length())); - return couponInfoDao.findTempId(number); + Map map = new HashMap<>(); + map.put("number", number); + map.put("hospitalId", hospitalId); + return couponInfoDao.findTempId(map); } /** @@ -122,7 +138,7 @@ public class CouponServiceImpl implements ICouponInfoService { HospitalCouponTemplateGroup hospitalCouponTemplateGroup = new HospitalCouponTemplateGroup(); hospitalCouponTemplateGroup.setId(UUIDUtil.createId()); hospitalCouponTemplateGroup.setHospitalId(hospitalId); - hospitalCouponTemplateGroup.setCouponTemplateGroupId("5150e962-2af9-11e7-9daf-8dc94911792e"); + hospitalCouponTemplateGroup.setCouponTemplateGroupId(couponInfoDao.findHospital(hospitalId).getCouponTemplateGroupId()); couponInfoDao.saveHospitalGroup(hospitalCouponTemplateGroup); } } diff --git a/regional-etl/src/main/resources/application.properties b/regional-etl/src/main/resources/application.properties index 8b25b99..a7e87f7 100644 --- a/regional-etl/src/main/resources/application.properties +++ b/regional-etl/src/main/resources/application.properties @@ -22,4 +22,4 @@ mybatis.typeAliasesPackage=com.lyms.etl.model mybatis.mapperLocations=classpath:mappers/*.xml #spring.profiles.active=prod, etl -spring.profiles.active=etl \ No newline at end of file +spring.profiles.active=coupon \ No newline at end of file diff --git a/regional-etl/src/main/resources/application.yml b/regional-etl/src/main/resources/application.yml index aed8b4e..c632bd3 100644 --- a/regional-etl/src/main/resources/application.yml +++ b/regional-etl/src/main/resources/application.yml @@ -2,11 +2,19 @@ spring: datasource: url: jdbc:mysql://119.90.57.26:3306/platform username: platform - password: platform123 + password: platform123 driver-class-name: com.mysql.jdbc.Driver # 必须配置为字符类型 @see com.alibaba.druid.pool.DruidDataSourceFactory > value = (String)properties.get("init"); init: "true" + default: + url: jdbc:mysql://119.90.57.26:3306/platform + username: platform + password: platform123 + driver-class-name: com.mysql.jdbc.Driver + # 必须配置为字符类型 @see com.alibaba.druid.pool.DruidDataSourceFactory > value = (String)properties.get("init"); + init: "true" + customs: - ds1 - ds2 @@ -18,7 +26,5 @@ spring: database: platform username: platform password: platform123 - profiles: - active: coupon server: port: 8888 \ No newline at end of file diff --git a/regional-etl/src/main/resources/logback.xml b/regional-etl/src/main/resources/logback.xml index 864e4e5..b54144c 100644 --- a/regional-etl/src/main/resources/logback.xml +++ b/regional-etl/src/main/resources/logback.xml @@ -18,8 +18,8 @@ - - INFO + + INFO NEUTRAL DENY @@ -146,7 +146,7 @@ - System.out + System.err %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n diff --git a/regional-etl/src/main/resources/mappers/CouponInfoMapper.xml b/regional-etl/src/main/resources/mappers/CouponInfoMapper.xml index 20be920..659dacc 100644 --- a/regional-etl/src/main/resources/mappers/CouponInfoMapper.xml +++ b/regional-etl/src/main/resources/mappers/CouponInfoMapper.xml @@ -36,10 +36,11 @@ insert into coupon_info(id, ) values(#{id},#{sequenceId},#{createDate},#{useDate},#{userId},#{createUserId},#{couponTemplateId},#{createHospitalId},#{usedHospitalId},#{status}) - SELECT a.id FROM - coupon_template a, coupon_type b - WHERE a.type_id = b.id and b.type = 2 and a.coupon_order = #{number} + coupon_template a, coupon_type b, hospital_coupon_template_group c + WHERE a.type_id = b.id and b.type = 2 and a.coupon_order = #{number} and c.hospital_id = #{hospitalId} and c.coupon_template_group_id = a.group_id + and a.group_id = b.template_group_id order by a.coupon_order -- 1.8.3.1