Commit 770a2de814b83ed2b88760e37b663222b72a855a
1 parent
29948b10bd
Exists in
master
and in
1 other branch
优惠券相关接口完成
Showing 12 changed files with 292 additions and 62 deletions
- platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/GenSequenceIdService.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/model/CouponInfo.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/service/CouponService.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/CouponServiceImpl.java
- platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml
- platform-common/src/main/java/com/lyms/platform/common/result/ResponseCode.java
- platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
- platform-operate-api/src/main/resources/database.properties
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/GenSequenceIdService.java
View file @
770a2de
| 1 | 1 | package com.lyms.platform.biz.service; |
| 2 | 2 | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.Collections; | |
| 5 | -import java.util.Date; | |
| 6 | -import java.util.List; | |
| 7 | - | |
| 3 | +import com.lyms.platform.biz.dal.IGenSequenceIdDao; | |
| 8 | 4 | import org.apache.commons.collections.CollectionUtils; |
| 9 | 5 | import org.apache.commons.lang.StringUtils; |
| 10 | 6 | import org.slf4j.Logger; |
| ... | ... | @@ -14,7 +10,9 @@ |
| 14 | 10 | import org.springframework.beans.factory.annotation.Value; |
| 15 | 11 | import org.springframework.stereotype.Service; |
| 16 | 12 | |
| 17 | -import com.lyms.platform.biz.dal.IGenSequenceIdDao; | |
| 13 | +import java.util.ArrayList; | |
| 14 | +import java.util.Collections; | |
| 15 | +import java.util.List; | |
| 18 | 16 | |
| 19 | 17 | @Service |
| 20 | 18 | public class GenSequenceIdService { |
| 21 | 19 | |
| ... | ... | @@ -29,13 +27,13 @@ |
| 29 | 27 | private int createSize; |
| 30 | 28 | |
| 31 | 29 | |
| 32 | - public String poll(String areaCode) { | |
| 30 | + public String poll() { | |
| 33 | 31 | String s = genSequenceIdDao.poll(); |
| 34 | 32 | if(StringUtils.isBlank(s)) { |
| 35 | 33 | generateData(); |
| 36 | 34 | s = genSequenceIdDao.poll(); |
| 37 | 35 | } |
| 38 | - return areaCode + s; | |
| 36 | + return s; | |
| 39 | 37 | } |
| 40 | 38 | |
| 41 | 39 | /** |
| 42 | 40 | |
| ... | ... | @@ -52,16 +50,16 @@ |
| 52 | 50 | private synchronized void generateData() { |
| 53 | 51 | if(genSequenceIdDao.check()) { |
| 54 | 52 | List<String> list = new ArrayList<>(); |
| 55 | - Integer startValue = Integer.valueOf(genSequenceIdDao.next()); | |
| 56 | - Integer endValue = startValue + createSize; | |
| 57 | - for(int i = startValue; i < endValue; i++) { | |
| 53 | + Long startValue = Long.valueOf(genSequenceIdDao.next()); | |
| 54 | + Long endValue = startValue + createSize; | |
| 55 | + for(Long i = startValue; i < endValue; i++) { | |
| 58 | 56 | list.add(String.valueOf(i)); |
| 59 | 57 | } |
| 60 | 58 | Collections.shuffle(list); |
| 61 | 59 | batchInsert(list, 1000); |
| 62 | 60 | } |
| 63 | 61 | } |
| 64 | - | |
| 62 | + | |
| 65 | 63 | /** |
| 66 | 64 | * 批量保存数据 |
| 67 | 65 | * @param list 数据列表 |
| ... | ... | @@ -80,6 +78,6 @@ |
| 80 | 78 | genSequenceIdDao.add(commitList); |
| 81 | 79 | } |
| 82 | 80 | } |
| 83 | - | |
| 81 | + | |
| 84 | 82 | } |
platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java
View file @
770a2de
| ... | ... | @@ -16,5 +16,13 @@ |
| 16 | 16 | void save(CouponInfo couponInfo); |
| 17 | 17 | |
| 18 | 18 | List<Map<String,Object>> findTemp(String hospitalId); |
| 19 | + | |
| 20 | + String findTopName(String hospitalId); | |
| 21 | + | |
| 22 | + List<Map<String,Object>> findInfo(Map<String, Object> param); | |
| 23 | + | |
| 24 | + Map<String,Object> findValidateParam(Map<String, Object> param); | |
| 25 | + | |
| 26 | + void use(Map<String, Object> param); | |
| 19 | 27 | } |
platform-biz-service/src/main/java/com/lyms/platform/permission/model/CouponInfo.java
View file @
770a2de
| 1 | 1 | package com.lyms.platform.permission.model; |
| 2 | 2 | |
| 3 | 3 | import java.util.Date; |
| 4 | +import java.util.UUID; | |
| 4 | 5 | |
| 5 | 6 | /** |
| 6 | 7 | * 优惠券详情 |
| ... | ... | @@ -55,8 +56,16 @@ |
| 55 | 56 | * 状态:1:未使用 2:已使用 -1:禁用 |
| 56 | 57 | */ |
| 57 | 58 | private Integer status; |
| 58 | - | |
| 59 | - | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * 使用优惠券时操作人的id | |
| 62 | + */ | |
| 63 | + private String operatorUseId; | |
| 64 | + | |
| 65 | + public CouponInfo() { | |
| 66 | + id = UUID.randomUUID().toString().replace("-", ""); | |
| 67 | + } | |
| 68 | + | |
| 60 | 69 | public String getId() { |
| 61 | 70 | return id; |
| 62 | 71 | } |
| 63 | 72 | |
| ... | ... | @@ -129,24 +138,12 @@ |
| 129 | 138 | this.status = status; |
| 130 | 139 | } |
| 131 | 140 | |
| 132 | - @Override | |
| 133 | - public String toString() { | |
| 134 | - StringBuilder sb = new StringBuilder(); | |
| 135 | - sb.append("CouponInfo [ "); | |
| 136 | - sb.append("id=" + id + ","); | |
| 137 | - sb.append("sequenceId=" + sequenceId + ","); | |
| 138 | - sb.append("createDate=" + createDate + ","); | |
| 139 | - sb.append("useDate=" + useDate + ","); | |
| 140 | - sb.append("userId=" + userId + ","); | |
| 141 | - sb.append("createUserId=" + createUserId + ","); | |
| 142 | - sb.append("couponTemplateId=" + couponTemplateId + ","); | |
| 143 | - sb.append("createHospitalId=" + createHospitalId + ","); | |
| 144 | - sb.append("usedHospitalId=" + usedHospitalId + ","); | |
| 145 | - sb.append("status=" + status + ","); | |
| 146 | - sb.replace(sb.length()-1, sb.length(), " ]"); | |
| 147 | - return sb.toString(); | |
| 141 | + public String getOperatorUseId() { | |
| 142 | + return operatorUseId; | |
| 148 | 143 | } |
| 149 | 144 | |
| 150 | - | |
| 145 | + public void setOperatorUseId(String operatorUseId) { | |
| 146 | + this.operatorUseId = operatorUseId; | |
| 147 | + } | |
| 151 | 148 | } |
platform-biz-service/src/main/java/com/lyms/platform/permission/service/CouponService.java
View file @
770a2de
| ... | ... | @@ -8,10 +8,12 @@ |
| 8 | 8 | * @Version: V1.0 |
| 9 | 9 | */ |
| 10 | 10 | public interface CouponService{ |
| 11 | - BaseObjectResponse create(String userId, String hospitalId); | |
| 11 | + BaseObjectResponse create(String userId, String hospitalId, Integer createUserId); | |
| 12 | 12 | |
| 13 | 13 | BaseObjectResponse validate(String userId, String code); |
| 14 | 14 | |
| 15 | 15 | BaseObjectResponse findList(String userId, String hospitalId); |
| 16 | + | |
| 17 | + BaseObjectResponse use(String hospitalId, String code, Integer userId); | |
| 16 | 18 | } |
platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/CouponServiceImpl.java
View file @
770a2de
| 1 | 1 | package com.lyms.platform.permission.service.impl; |
| 2 | 2 | |
| 3 | +import com.lyms.platform.biz.service.GenSequenceIdService; | |
| 3 | 4 | import com.lyms.platform.common.result.BaseObjectResponse; |
| 4 | 5 | import com.lyms.platform.common.result.RespBuilder; |
| 5 | 6 | import com.lyms.platform.common.result.ResponseCode; |
| 7 | +import com.lyms.platform.common.utils.DateUtil; | |
| 6 | 8 | import com.lyms.platform.permission.dao.master.CouponMapper; |
| 7 | 9 | import com.lyms.platform.permission.model.CouponInfo; |
| 8 | 10 | import com.lyms.platform.permission.service.CouponService; |
| 11 | +import com.lyms.platform.pojo.Patients; | |
| 9 | 12 | import org.apache.commons.collections.CollectionUtils; |
| 13 | +import org.apache.commons.lang3.time.DateUtils; | |
| 14 | +import org.slf4j.Logger; | |
| 15 | +import org.slf4j.LoggerFactory; | |
| 10 | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | +import org.springframework.data.domain.Sort; | |
| 18 | +import org.springframework.data.mongodb.core.MongoTemplate; | |
| 19 | +import org.springframework.data.mongodb.core.query.Criteria; | |
| 20 | +import org.springframework.data.mongodb.core.query.Query; | |
| 11 | 21 | import org.springframework.stereotype.Service; |
| 12 | 22 | |
| 13 | -import java.util.*; | |
| 23 | +import java.util.Date; | |
| 24 | +import java.util.HashMap; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 14 | 27 | |
| 15 | 28 | /** |
| 16 | 29 | * @Author: litao |
| 17 | 30 | |
| 18 | 31 | |
| 19 | 32 | |
| 20 | 33 | |
| ... | ... | @@ -20,15 +33,48 @@ |
| 20 | 33 | @Service |
| 21 | 34 | public class CouponServiceImpl implements CouponService { |
| 22 | 35 | |
| 36 | + private Logger logger = LoggerFactory.getLogger(CouponServiceImpl.class); | |
| 37 | + | |
| 23 | 38 | @Autowired |
| 24 | 39 | private CouponMapper couponMapper; |
| 25 | 40 | |
| 41 | + @Autowired | |
| 42 | + private GenSequenceIdService genIdService; | |
| 43 | + | |
| 44 | + @Autowired | |
| 45 | + private MongoTemplate mongoTemplate; | |
| 46 | + | |
| 26 | 47 | @Override |
| 27 | - public BaseObjectResponse create(String userId, String hospitalId) { | |
| 48 | + public BaseObjectResponse create(String userId, String hospitalId, Integer createUserId) { | |
| 28 | 49 | List<Map<String,Object>> temps = couponMapper.findTemp(hospitalId); |
| 29 | - System.err.println("CouponServiceImpl.create"); | |
| 30 | 50 | for (Map<String, Object> temp : temps) { |
| 31 | - System.err.println(temp); | |
| 51 | + Object sendType = temp.get("send_type"); | |
| 52 | + if(sendType != null) {/** 1=全部发放 2=按有效时间发放 */ | |
| 53 | + CouponInfo couponInfo = new CouponInfo(); | |
| 54 | + couponInfo.setCreateDate(new Date()); | |
| 55 | + couponInfo.setCreateHospitalId(hospitalId); | |
| 56 | + couponInfo.setCreateUserId(String.valueOf(createUserId)); | |
| 57 | + couponInfo.setSequenceId(genIdService.poll()); | |
| 58 | + couponInfo.setStatus(1); | |
| 59 | + couponInfo.setUserId(userId); | |
| 60 | + if(temp.get("coupon_template_id") != null) { | |
| 61 | + couponInfo.setCouponTemplateId(temp.get("coupon_template_id").toString()); | |
| 62 | + } | |
| 63 | + if("1".equals(sendType.toString())) { | |
| 64 | + couponMapper.save(couponInfo); | |
| 65 | + } else if("2".equals(sendType.toString())) { | |
| 66 | + Object actualStart = temp.get("actual_start"); | |
| 67 | + Object actualEnd = temp.get("actual_end"); | |
| 68 | + Object unitType = temp.get("unit_type"); | |
| 69 | + Object type = temp.get("type"); | |
| 70 | + if(actualStart != null && actualEnd != null && unitType != null && type != null) { | |
| 71 | + if(validateDate(userId, Integer.parseInt(actualStart.toString()), Integer.parseInt(actualEnd.toString()), | |
| 72 | + Integer.parseInt(unitType.toString()), hospitalId, Integer.parseInt(type.toString()))) { | |
| 73 | + couponMapper.save(couponInfo); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } | |
| 32 | 78 | } |
| 33 | 79 | return RespBuilder.buildSuccess(); |
| 34 | 80 | } |
| ... | ... | @@ -38,7 +84,6 @@ |
| 38 | 84 | Map<String, Object> param = new HashMap<>(); |
| 39 | 85 | param.put("userId", userId); |
| 40 | 86 | param.put("code", code); |
| 41 | - | |
| 42 | 87 | List<CouponInfo> couponInfos = couponMapper.findList(param); |
| 43 | 88 | if(CollectionUtils.isEmpty(couponInfos)) |
| 44 | 89 | return RespBuilder.buildErro(ResponseCode.COUPON_NOT_FOUND); |
| 45 | 90 | |
| 46 | 91 | |
| 47 | 92 | |
| 48 | 93 | |
| 49 | 94 | |
| ... | ... | @@ -53,24 +98,88 @@ |
| 53 | 98 | return RespBuilder.buildErro(ResponseCode.COUPON_IS_USERD); |
| 54 | 99 | } |
| 55 | 100 | |
| 56 | - if(!validate(couponInfo)) | |
| 101 | + Map<String, Object> data = couponMapper.findValidateParam(param); | |
| 102 | + | |
| 103 | + if(!validateDate(userId, Integer.parseInt(data.get("actual_start").toString()), Integer.parseInt(data.get("actual_end").toString()), Integer.parseInt(data.get("unit_type").toString()), | |
| 104 | + data.get("create_hospital_id").toString(), Integer.parseInt(data.get("type").toString()))) | |
| 57 | 105 | return RespBuilder.buildErro(ResponseCode.COUPON_TIME_OUT); |
| 58 | 106 | |
| 59 | - | |
| 60 | - return null; | |
| 107 | + return RespBuilder.buildSuccess(ResponseCode.COUPON_IS_NORMAL); | |
| 61 | 108 | } |
| 62 | 109 | |
| 63 | - private boolean validate(CouponInfo couponInfo) { | |
| 64 | - Date createDate = couponInfo.getCreateDate(); | |
| 110 | + /** | |
| 111 | + * 判断当前时间是否满足生成规则的时间 | |
| 112 | + * @param userId 孕妇id | |
| 113 | + * @param start 真实的开始时间 | |
| 114 | + * @param end 真实的结束时间 | |
| 115 | + * @param unitType 时间单位 1=孕周 2=天数 3=月龄 | |
| 116 | + * @param hospitalId 医院id | |
| 117 | + * @param couponType 产检券类型 1=孕妇 2=产妇 3=儿童 | |
| 118 | + * @return | |
| 119 | + */ | |
| 120 | + private boolean validateDate(String userId, Integer start, Integer end, Integer unitType, String hospitalId, Integer couponType) { | |
| 121 | + Date midDate = null; | |
| 122 | + Date startDate = null; | |
| 123 | + Date endDate = null; | |
| 124 | + if(couponType == 1) {/** 根据末次月经对比 midDate = 末次月经时间 */ | |
| 125 | + List<Patients> patients = mongoTemplate.find(Query.query(Criteria.where("type").is(1).and("hospitalId").is(hospitalId).and("pid").is(userId)), Patients.class); | |
| 126 | + if(CollectionUtils.isEmpty(patients)) { | |
| 127 | + logger.info("未找到pid: " + userId + ", hospitalId: " + hospitalId + ", type: 1 的孕妇信息"); | |
| 128 | + return false; | |
| 129 | + } | |
| 130 | + midDate = patients.get(0).getLastMenses(); | |
| 131 | + } else if(couponType == 2 || couponType == 3) {/** 根据分娩时间对比 midDate = 分娩时间 */ | |
| 132 | + List<Patients> patients = mongoTemplate.find(Query.query(Criteria.where("type").is(3).and("hospitalId").is(hospitalId).and("pid").is(userId)) | |
| 133 | + .with(new Sort(Sort.Direction.DESC, "fmDate")), Patients.class); | |
| 134 | + if(CollectionUtils.isEmpty(patients)) { | |
| 135 | + logger.info("未找到pid: " + userId + ", hospitalId: " + hospitalId + ", type: 3 的孕妇信息"); | |
| 136 | + return false; | |
| 137 | + } | |
| 138 | + midDate = patients.get(0).getFmDate(); | |
| 139 | + } | |
| 65 | 140 | |
| 66 | - return true; | |
| 141 | + if(midDate != null) { | |
| 142 | + if(unitType == 1) { /** 孕周: startDate = lastMenses + start*7、 endDate = lastMenses + end*7 + 6*/ | |
| 143 | + startDate = DateUtils.addDays(midDate, start * 7); | |
| 144 | + endDate = DateUtils.addDays(midDate, end * 7 + 6); | |
| 145 | + } else if(unitType == 2) { /** 天数 stratDate = lastMenses + start、 endDate = lastMenses + end */ | |
| 146 | + startDate = DateUtils.addDays(midDate, start); | |
| 147 | + endDate = DateUtils.addDays(midDate, end); | |
| 148 | + } else if(unitType == 3) { /** 月龄 startDate = lastMenses + start、 endDate = lastMenses + end + 1 如果是31号 计算出来的月份没有31号 取最后一天*/ | |
| 149 | + startDate = DateUtils.addMonths(midDate, start); | |
| 150 | + endDate = DateUtils.addMonths(midDate, end + 1); | |
| 151 | + } | |
| 152 | + if(DateUtil.isBetween(midDate, startDate, endDate)) { | |
| 153 | + return true; | |
| 154 | + } | |
| 155 | + } | |
| 156 | + return false; | |
| 67 | 157 | } |
| 68 | 158 | |
| 69 | 159 | @Override |
| 70 | 160 | public BaseObjectResponse findList(String userId, String hospitalId) { |
| 71 | 161 | Map<String, Object> param = new HashMap<>(); |
| 72 | - List<CouponInfo> couponInfos = couponMapper.findList(param); | |
| 73 | - return RespBuilder.buildSuccess(couponInfos); | |
| 162 | + param.put("userId", userId); | |
| 163 | + param.put("hospitalId", hospitalId); | |
| 164 | + | |
| 165 | + Map<String, Object> restMap = new HashMap<>(); | |
| 166 | + restMap.put("topName", couponMapper.findTopName(hospitalId)); | |
| 167 | + restMap.put("couponInfos", couponMapper.findInfo(param)); | |
| 168 | + | |
| 169 | + return RespBuilder.buildSuccess(restMap); | |
| 74 | 170 | } |
| 171 | + | |
| 172 | + @Override | |
| 173 | + public BaseObjectResponse use(String hospitalId, String code, Integer userId) { | |
| 174 | + Map<String, Object> param = new HashMap<>(); | |
| 175 | + param.put("hospitalId", hospitalId); | |
| 176 | + param.put("operatorUseId", userId); | |
| 177 | + param.put("status", 2); | |
| 178 | + param.put("useDate", new Date()); | |
| 179 | + param.put("code", code); | |
| 180 | + couponMapper.use(param); | |
| 181 | + return RespBuilder.buildSuccess(); | |
| 182 | + } | |
| 183 | + | |
| 75 | 184 | } |
platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml
View file @
770a2de
| ... | ... | @@ -13,25 +13,53 @@ |
| 13 | 13 | <result column="create_hospital_id" property="createHospitalId"/> |
| 14 | 14 | <result column="used_hospital_id" property="usedHospitalId"/> |
| 15 | 15 | <result column="status" property="status"/> |
| 16 | + <result column="operator_use_id" property="operatorUseId"/> | |
| 16 | 17 | </resultMap> |
| 17 | 18 | |
| 18 | 19 | <sql id="columnList"> |
| 19 | - <![CDATA[sequence_id,create_date,use_date,user_id,create_user_id,coupon_template_id,create_hospital_id,used_hospital_id,status]]> | |
| 20 | + sequence_id,create_date,use_date,user_id,create_user_id,coupon_template_id,create_hospital_id,used_hospital_id,status | |
| 20 | 21 | </sql> |
| 21 | 22 | |
| 22 | 23 | <select id="findList" parameterType="map" resultMap="couponInfoMap"> |
| 23 | - select * from coupon_info | |
| 24 | + select id,<include refid="columnList" /> from coupon_info | |
| 25 | + where user_id = #{userId} and sequence_id = #{code} | |
| 24 | 26 | </select> |
| 25 | 27 | |
| 26 | - <insert id="save" parameterType="com.lyms.platform.permission.model.CouponInfo" useGeneratedKeys="true" keyProperty="id"> | |
| 28 | + <insert id="save" parameterType="com.lyms.platform.permission.model.CouponInfo"> | |
| 27 | 29 | insert into coupon_info(id, <include refid="columnList" />) values(#{id},#{sequenceId},#{createDate},#{useDate},#{userId},#{createUserId},#{couponTemplateId},#{createHospitalId},#{usedHospitalId},#{status}) |
| 28 | 30 | </insert> |
| 29 | 31 | |
| 30 | 32 | <select id="findTemp" parameterType="string" resultType="map"> |
| 31 | - select b.id from | |
| 32 | - hospital_coupon_template_group a, coupon_template b | |
| 33 | - where a.hospital_id = #{hospitalId} and a.coupon_template_group_id = b.group_id | |
| 33 | + select b.id, b.id as coupon_template_id, b.actual_start, b.actual_end, b.unit_type, c.send_type, c.type from | |
| 34 | + hospital_coupon_template_group a, coupon_template b, coupon_type c | |
| 35 | + where a.hospital_id = #{hospitalId} and a.coupon_template_group_id = b.group_id and b.type_id = c.id | |
| 34 | 36 | order by b.coupon_order |
| 35 | 37 | </select> |
| 38 | + | |
| 39 | + <select id="findTopName" parameterType="string" resultType="string"> | |
| 40 | + select b.name | |
| 41 | + from hospital_coupon_template_group a, coupon_template_group b | |
| 42 | + where a.coupon_template_group_id = b.id and a.hospital_id = #{hospital_id} | |
| 43 | + </select> | |
| 44 | + | |
| 45 | + <select id="findInfo" parameterType="map" resultType="map"> | |
| 46 | + select b.name, b.title, b.show_start, b.show_end, b.unit_type, b.content, a.sequence_id, a.status | |
| 47 | + from coupon_info a, coupon_template b | |
| 48 | + where a.user_id = #{userId} and a.create_hospital_id = #{hospitalId} and a.coupon_template_id = b.id | |
| 49 | + </select> | |
| 50 | + | |
| 51 | + <select id="findValidateParam" parameterType="map" resultType="map"> | |
| 52 | + select b.actual_start, b.actual_end, b.unit_type, a.create_hospital_id, c.type | |
| 53 | + from coupon_info a, coupon_template b, coupon_type c | |
| 54 | + where a.user_id = #{userId} and a.sequence_id = #{code} | |
| 55 | + and a.coupon_template_id = b.id and b.type_id = c.id | |
| 56 | + </select> | |
| 57 | + | |
| 58 | + <update id="use" parameterType="map"> | |
| 59 | + update coupon_info | |
| 60 | + set use_date = #{useDate}, operator_use_id = #{operatorUseId}, used_hospital_id = #{hospitalId}, status = #{status} | |
| 61 | + where sequence_id = #{code} | |
| 62 | + </update> | |
| 63 | + | |
| 36 | 64 | </mapper> |
platform-common/src/main/java/com/lyms/platform/common/result/ResponseCode.java
View file @
770a2de
| ... | ... | @@ -13,7 +13,8 @@ |
| 13 | 13 | COUPON_NOT_UNIQUE(1002, "优惠券有多个"), |
| 14 | 14 | COUPON_TIME_OUT(1003, "优惠券已过期"), |
| 15 | 15 | COUPON_IS_USERD(1004, "优惠券已被使用"), |
| 16 | - COUPON_IS_DISABLED(1005, "优惠券已被禁用"); | |
| 16 | + COUPON_IS_DISABLED(1005, "优惠券已被禁用"), | |
| 17 | + COUPON_IS_NORMAL(1006, "正常可使用"); | |
| 17 | 18 | |
| 18 | 19 | private Integer code; |
| 19 | 20 | private String msg; |
platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java
View file @
770a2de
| ... | ... | @@ -779,10 +779,8 @@ |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
| 782 | - public static void main(String[] arg) { | |
| 783 | - System.out.println(getAge(parseYMD("1990-01-9"))); | |
| 784 | - } | |
| 785 | 782 | |
| 783 | + | |
| 786 | 784 | /** |
| 787 | 785 | * @auther HuJiaqi |
| 788 | 786 | * @createTime 2016年11月29日 11时30分 |
| ... | ... | @@ -835,6 +833,70 @@ |
| 835 | 833 | } catch (ParseException e) { |
| 836 | 834 | return null; |
| 837 | 835 | } |
| 836 | + } | |
| 837 | + | |
| 838 | + /** | |
| 839 | + * 判断第一个时间 是否大于或等于第二个时间 | |
| 840 | + * 只对比年月日 相同也返回true | |
| 841 | + * @param date1 | |
| 842 | + * @param date2 | |
| 843 | + * @return | |
| 844 | + */ | |
| 845 | + public static boolean isGtOrEq(Date date1, Date date2) { | |
| 846 | + try { | |
| 847 | + date1 = ymd.parse(ymd.format(date1)); | |
| 848 | + date2 = ymd.parse(ymd.format(date2)); | |
| 849 | + if(org.apache.commons.lang3.time.DateUtils.isSameDay(date1, date2) || date1.after(date2)) { | |
| 850 | + return true; | |
| 851 | + } | |
| 852 | + } catch (Exception e){ | |
| 853 | + e.printStackTrace(); | |
| 854 | + } | |
| 855 | + return false; | |
| 856 | + } | |
| 857 | + | |
| 858 | + /** | |
| 859 | + * 判断第一个时间 是否小于或等于第二个时间 | |
| 860 | + * 只对比年月日 相同也返回true | |
| 861 | + * @param date1 | |
| 862 | + * @param date2 | |
| 863 | + * @return | |
| 864 | + */ | |
| 865 | + public static boolean isLtOrEq(Date date1, Date date2) { | |
| 866 | + try { | |
| 867 | + date1 = ymd.parse(ymd.format(date1)); | |
| 868 | + date2 = ymd.parse(ymd.format(date2)); | |
| 869 | + if(org.apache.commons.lang3.time.DateUtils.isSameDay(date1, date2) || date1.before(date2)) { | |
| 870 | + return true; | |
| 871 | + } | |
| 872 | + } catch (Exception e){ | |
| 873 | + e.printStackTrace(); | |
| 874 | + } | |
| 875 | + return false; | |
| 876 | + } | |
| 877 | + | |
| 878 | + /** | |
| 879 | + * 判断date是否包含于 start 和 end 之间 | |
| 880 | + * 只对比年月日 包含相同天数 | |
| 881 | + * @param date | |
| 882 | + * @param start | |
| 883 | + * @param end | |
| 884 | + * @return | |
| 885 | + */ | |
| 886 | + public static boolean isBetween(Date date, Date start, Date end) { | |
| 887 | + if(DateUtil.isGtOrEq(date, start) && DateUtil.isLtOrEq(date, end)) { | |
| 888 | + return true; | |
| 889 | + } | |
| 890 | + return false; | |
| 891 | + } | |
| 892 | + | |
| 893 | + public static void main(String[] arg) throws Exception { | |
| 894 | + Date now = new Date(); | |
| 895 | + Date start = y_m_d_h_m_s.parse("2017-01-31 11:11:11"); | |
| 896 | + Date end = y_m_d_h_m_s.parse("2017-04-30 11:11:11"); | |
| 897 | + System.out.println(isBetween(now, start, end)); | |
| 898 | + | |
| 899 | + System.out.println(org.apache.commons.lang3.time.DateUtils.addMonths(start ,1).toLocaleString()); | |
| 838 | 900 | } |
| 839 | 901 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java
View file @
770a2de
| 1 | 1 | package com.lyms.platform.operate.web.controller; |
| 2 | 2 | |
| 3 | +import com.lyms.platform.common.annotation.TokenRequired; | |
| 3 | 4 | import com.lyms.platform.common.base.BaseController; |
| 5 | +import com.lyms.platform.common.base.LoginContext; | |
| 4 | 6 | import com.lyms.platform.common.result.BaseObjectResponse; |
| 5 | 7 | import com.lyms.platform.permission.service.CouponService; |
| 6 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -10,6 +12,8 @@ |
| 10 | 12 | import org.springframework.web.bind.annotation.RequestMethod; |
| 11 | 13 | import org.springframework.web.bind.annotation.ResponseBody; |
| 12 | 14 | |
| 15 | +import javax.servlet.http.HttpServletRequest; | |
| 16 | + | |
| 13 | 17 | /** |
| 14 | 18 | * @Author: litao |
| 15 | 19 | * @Date: 2017/4/27 0027 9:18 |
| ... | ... | @@ -30,8 +34,11 @@ |
| 30 | 34 | */ |
| 31 | 35 | @RequestMapping(method = RequestMethod.PUT, value = "/{userId}/{hospitalId}") |
| 32 | 36 | @ResponseBody |
| 33 | - public BaseObjectResponse create(@PathVariable String userId, @PathVariable String hospitalId) { | |
| 34 | - return couponService.create(userId, hospitalId); | |
| 37 | + @TokenRequired | |
| 38 | + public BaseObjectResponse create(@PathVariable String userId, @PathVariable String hospitalId, HttpServletRequest request) { | |
| 39 | + LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); | |
| 40 | + return couponService.create(userId, hospitalId, loginState.getId()); | |
| 41 | +// return couponService.create(userId, hospitalId, 200); | |
| 35 | 42 | } |
| 36 | 43 | |
| 37 | 44 | /** |
| 38 | 45 | |
| ... | ... | @@ -49,9 +56,26 @@ |
| 49 | 56 | |
| 50 | 57 | @RequestMapping(method = RequestMethod.GET, value = "/validate/{userId}/{code}") |
| 51 | 58 | @ResponseBody |
| 52 | - public BaseObjectResponse validate(String userId, String code) { | |
| 59 | + public BaseObjectResponse validate(@PathVariable String userId, @PathVariable String code) { | |
| 53 | 60 | return couponService.validate(userId, code); |
| 54 | 61 | } |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 后期再建档的时候 先验证优惠券 然后再使用 这里先不验证优惠券 | |
| 65 | + * @param code | |
| 66 | + * @param hospitalId | |
| 67 | + * @param request | |
| 68 | + * @return | |
| 69 | + */ | |
| 70 | + @RequestMapping(method = RequestMethod.PUT, value = "/use/{code}/{hospitalId}") | |
| 71 | +// @TokenRequired | |
| 72 | + @ResponseBody | |
| 73 | + public BaseObjectResponse testUse(@PathVariable String code, @PathVariable String hospitalId, HttpServletRequest request) { | |
| 74 | +// LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); | |
| 75 | +// return couponService.use(code, hospitalId, loginState.getId()); | |
| 76 | + return couponService.use(hospitalId, code, 110); | |
| 77 | + } | |
| 78 | + | |
| 55 | 79 | |
| 56 | 80 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java
View file @
770a2de
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
View file @
770a2de
| ... | ... | @@ -490,7 +490,8 @@ |
| 490 | 490 | ticket.setPatientId(p.getId()); |
| 491 | 491 | ticket.setCreated(new Date()); |
| 492 | 492 | // ticket.setId(areaCode.getAreaCode() + ticketPid + i); |
| 493 | - ticket.setId(genSequenceIdService.poll(areaCode.getAreaCode())); | |
| 493 | +// ticket.setId(genSequenceIdService.poll(areaCode.getAreaCode())); | |
| 494 | + ticket.setId(genSequenceIdService.poll()); | |
| 494 | 495 | ticket.setPid(p.getPid()); |
| 495 | 496 | ticket.setCoupon(CouponEnums.PRENATAL); |
| 496 | 497 | patientCheckTicketService.addTicket(ticket); |
platform-operate-api/src/main/resources/database.properties
View file @
770a2de