Commit 7037a3c0652936a3a4baf6ef9e3ab7e1dda326ad

Authored by yangfei
1 parent 216795ed94

追访

Showing 5 changed files with 205 additions and 169 deletions

platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java View file @ 7037a3c
... ... @@ -14,6 +14,10 @@
14 14 public interface CouponMapper {
15 15 List<CouponInfo> findList(Map<String, Object> params);
16 16  
  17 + List<CouponInfo> findErrorData();
  18 +
  19 + void updateUsed(Map<String, Object> map);
  20 +
17 21 void save(CouponInfo couponInfo);
18 22  
19 23 List<Map<String,Object>> findTemp(Map<String, Object> map);
platform-biz-service/src/main/java/com/lyms/platform/permission/service/CouponService.java View file @ 7037a3c
... ... @@ -15,6 +15,8 @@
15 15 public interface CouponService{
16 16 BaseObjectResponse create(String userId, String hospitalId, Integer createUserId, String patientId);
17 17  
  18 + BaseObjectResponse distErrorData();
  19 +
18 20 BaseObjectResponse validate(String code, Integer type, String hospitalId);
19 21  
20 22 BaseObjectResponse findList(String userId, String hospitalId, String url,Integer type);
platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/CouponServiceImpl.java View file @ 7037a3c
... ... @@ -3,6 +3,7 @@
3 3 import com.alibaba.fastjson.JSON;
4 4 import com.lyms.platform.biz.SequenceConstant;
5 5 import com.lyms.platform.biz.dal.IPatientDao;
  6 +import com.lyms.platform.biz.service.AntExRecordService;
6 7 import com.lyms.platform.biz.service.GenSequenceIdService;
7 8 import com.lyms.platform.common.result.BaseObjectResponse;
8 9 import com.lyms.platform.common.result.RespBuilder;
... ... @@ -19,6 +20,7 @@
19 20 import com.lyms.platform.permission.service.OrganizationService;
20 21 import com.lyms.platform.permission.service.WeixinQrcodeConfigService;
21 22 import com.lyms.platform.pojo.*;
  23 +import com.lyms.platform.query.AntExRecordQuery;
22 24 import net.sf.json.JSONObject;
23 25 import org.apache.commons.collections.CollectionUtils;
24 26 import org.apache.commons.collections.MapUtils;
25 27  
26 28  
27 29  
28 30  
29 31  
30 32  
31 33  
... ... @@ -46,24 +48,37 @@
46 48  
47 49 private Logger logger = LoggerFactory.getLogger(CouponServiceImpl.class);
48 50  
49   - /** 1 = 孕妇 */
  51 + /**
  52 + * 1 = 孕妇
  53 + */
50 54 private static final String PREGNANT_WOMAN = "1";
51 55  
52   - /** 2 = 儿童 */
  56 + /**
  57 + * 2 = 儿童
  58 + */
53 59 private static final String CHILDREN = "2";
54   -
55 60 @Autowired
  61 + private AntExRecordService antExRecordService;
  62 + @Autowired
56 63 private IPatientDao iPatientDao;
57 64  
58 65 /** 3_{?} = 产妇 */
59   - /** 产妇没有分娩记录且没有出院小结 */
  66 + /**
  67 + * 产妇没有分娩记录且没有出院小结
  68 + */
60 69 private static final String MATERNAL_NCHILDBIRTH_NHOSPITAL = "3_1";
61   - /** 产妇有分娩记录且没有出院小结 */
  70 + /**
  71 + * 产妇有分娩记录且没有出院小结
  72 + */
62 73 private static final String MATERNAL_YCHILDBIRTH_NHOSPITAL = "3_2";
63   - /** 产妇有分娩记录且有出院小结 */
  74 + /**
  75 + * 产妇有分娩记录且有出院小结
  76 + */
64 77 private static final String MATERNAL_YCHILDBIRTH_YHOSPITAL = "3_3";
65 78  
66   - /** 建档 */
  79 + /**
  80 + * 建档
  81 + */
67 82 private static final String PUT_ON_RECORD = "4";
68 83  
69 84 @Autowired
... ... @@ -91,8 +106,10 @@
91 106 * 建档:统一处理,如果点击创建中配置了建档券,自动使用,使用日期为建档日期,使用人为建档人,建档机构为建档人机构
92 107 */
93 108 /** key>> 1=孕妇 2=儿童 3=产妇 */
94   - /** value>> 1=孕妇建档 2=孕妇产检 3=产妇建档 4=产妇分娩 5=产妇出院小结 6=产妇产后复查 7=儿童建档 8=儿童保健 */
95   - private Map<String, List<Integer>> typeMap = new HashMap<String,List<Integer>>() {
  109 + /**
  110 + * value>> 1=孕妇建档 2=孕妇产检 3=产妇建档 4=产妇分娩 5=产妇出院小结 6=产妇产后复查 7=儿童建档 8=儿童保健
  111 + */
  112 + private Map<String, List<Integer>> typeMap = new HashMap<String, List<Integer>>() {
96 113 {
97 114 put(PREGNANT_WOMAN, Arrays.asList(1, 2, 4, 5, 6));
98 115 put(CHILDREN, Arrays.asList(7, 8, 9, 10));
99 116  
100 117  
... ... @@ -105,18 +122,18 @@
105 122  
106 123 @Override
107 124 public BaseObjectResponse create(String userId, String hospitalId, Integer createUserId, String patientId) {
108   - if(isCreated(userId, hospitalId)) {
  125 + if (isCreated(userId, hospitalId)) {
109 126 return RespBuilder.buildErro(ResponseCode.COUPON_IS_CREATED);
110 127 }
111 128  
112 129 /** 1=孕妇 2=儿童 3=产妇 */
113 130 PersonModel person = mongoTemplate.findById(userId, PersonModel.class);
114   - if(person == null || person.getType() == null) {
  131 + if (person == null || person.getType() == null) {
115 132 return RespBuilder.buildErro(ResponseCode.PERSON_NOT_FOUND);
116 133 }
117 134  
118 135 List<Integer> types = findTypeByPerson(person);
119   - if(CollectionUtils.isEmpty(types)) {
  136 + if (CollectionUtils.isEmpty(types)) {
120 137 return RespBuilder.buildErro(ResponseCode.PATIENT_NOT_FOUND);
121 138 }
122 139  
123 140  
124 141  
125 142  
126 143  
127 144  
128 145  
129 146  
130 147  
131 148  
132 149  
133 150  
134 151  
135 152  
136 153  
137 154  
... ... @@ -125,78 +142,56 @@
125 142 param.put("hospitalId", hospitalId);
126 143  
127 144 Integer start = null;
128   - if (person.getType() == 1 || person.getType() == 3)
129   - {
  145 + if (person.getType() == 1 || person.getType() == 3) {
130 146 Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("id").is(patientId)), Patients.class);
131   - if (patients != null && patients.getType() == 3)
132   - {
  147 + if (patients != null && patients.getType() == 3) {
133 148 Date fmDate = patients.getFmDate();
134   - if (fmDate != null)
135   - {
136   - start = DateUtil.getDays(fmDate,new Date());
  149 + if (fmDate != null) {
  150 + start = DateUtil.getDays(fmDate, new Date());
137 151 }
138   - }
139   - else if (patients != null && patients.getType() == 1)
140   - {
  152 + } else if (patients != null && patients.getType() == 1) {
141 153 start = DateUtil.getWeek2(patients.getLastMenses(), new Date());
142 154 }
143   - }
144   - else if (person.getType() == 2)
145   - {
  155 + } else if (person.getType() == 2) {
146 156 BabyModel babyModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(patientId)), BabyModel.class);
147   - if (babyModel != null && babyModel.getBirth() != null)
148   - {
  157 + if (babyModel != null && babyModel.getBirth() != null) {
149 158 start = DateUtil.getMonth(babyModel.getBirth(), new Date());
150 159  
151 160 }
152 161 }
153 162  
154   - List<Map<String,Object>> temps = couponMapper.findTemp(param);
  163 + List<Map<String, Object>> temps = couponMapper.findTemp(param);
155 164  
156   - List<Map<String,Object>> list = new ArrayList<>();
  165 + List<Map<String, Object>> list = new ArrayList<>();
157 166 //滦平县妇幼保健院
158   - if ("2100001377".equals(hospitalId))
159   - {
160   - if (CollectionUtils.isNotEmpty(temps))
161   - {
162   - for (Map<String,Object> map : temps)
163   - {
  167 + if ("2100001377".equals(hospitalId)) {
  168 + if (CollectionUtils.isNotEmpty(temps)) {
  169 + for (Map<String, Object> map : temps) {
164 170 Integer type = Integer.parseInt(map.get("type").toString());
165   - if (person.getType() == 1)
166   - {
167   - if (type != 2)
168   - {
  171 + if (person.getType() == 1) {
  172 + if (type != 2) {
169 173 list.add(map);
170 174 }
171   - }
172   - else if (person.getType() == 3)
173   - {
174   - if (type != 6)
175   - {
  175 + } else if (person.getType() == 3) {
  176 + if (type != 6) {
176 177 list.add(map);
177 178 }
178 179 }
179 180 }
180 181  
181   - for (Map<String,Object> map : temps)
182   - {
  182 + for (Map<String, Object> map : temps) {
183 183 Integer type = Integer.parseInt(map.get("type").toString());
184 184  
185   - if (person.getType() == 1 && type == 2)
186   - {
  185 + if (person.getType() == 1 && type == 2) {
187 186 Integer showStart = Integer.parseInt(map.get("show_start").toString());
188 187 Integer showEnd = Integer.parseInt(map.get("show_end").toString());
189   - if ((showStart <= start && showEnd >= start) || showStart >= start)
190   - {
  188 + if ((showStart <= start && showEnd >= start) || showStart >= start) {
191 189 list.add(map);
192 190 }
193   - }
194   - else if (person.getType() == 3 && type == 6)
195   - {
  191 + } else if (person.getType() == 3 && type == 6) {
196 192 Integer showStart = Integer.parseInt(map.get("show_start").toString());
197 193 Integer showEnd = Integer.parseInt(map.get("show_end").toString());
198   - if ((showStart <= start && showEnd >= start) || showStart >= start)
199   - {
  194 + if ((showStart <= start && showEnd >= start) || showStart >= start) {
200 195 list.add(map);
201 196 }
202 197  
203 198  
204 199  
... ... @@ -204,19 +199,17 @@
204 199 }
205 200 }
206 201  
207   - }
208   - else
209   - {
  202 + } else {
210 203 list.addAll(temps);
211 204 }
212 205  
213 206  
214   - if(CollectionUtils.isEmpty(list)) {
  207 + if (CollectionUtils.isEmpty(list)) {
215 208 return RespBuilder.buildErro(ResponseCode.COUPON_TEMP_NOT_FOUND);
216 209 }
217 210  
218 211 String areaCode = getAreaCode(hospitalId);
219   - if(StringUtils.isBlank(areaCode)) {
  212 + if (StringUtils.isBlank(areaCode)) {
220 213 return RespBuilder.buildErro(ResponseCode.OUPON_HOSPITAL_NOT_BOUND_AREA);
221 214 }
222 215  
223 216  
224 217  
... ... @@ -227,14 +220,14 @@
227 220  
228 221 /** 如果配置了医院打印人数 mongo人数自增1 */
229 222 PlantformConfigModel model = mongoTemplate.findOne(Query.query(Criteria.where("key").is(hospitalId).and("type").is(SequenceConstant.HOSPITAL_COUPON_CODE)), PlantformConfigModel.class);
230   - if(model != null) {
  223 + if (model != null) {
231 224 String value = model.getValue();
232 225 Map<Integer, Integer> map = new HashMap<>();
233 226 Integer year = DateUtil.getCurrentYear();
234   - if(StringUtils.isNotEmpty(value)) {
  227 + if (StringUtils.isNotEmpty(value)) {
235 228 map = JSON.parseObject(value, Map.class);
236 229 Integer code = map.get(year);
237   - if(code != null) {
  230 + if (code != null) {
238 231 map.put(year, ++code);
239 232 } else {
240 233 map.put(year, 1);
241 234  
242 235  
243 236  
244 237  
245 238  
... ... @@ -249,21 +242,45 @@
249 242 return RespBuilder.buildSuccess();
250 243 }
251 244  
  245 + @Override
  246 + public BaseObjectResponse distErrorData() {
  247 + List<CouponInfo> couponInfos = couponMapper.findErrorData();
  248 + if (CollectionUtils.isNotEmpty(couponInfos)) {
  249 + for (CouponInfo co : couponInfos) {
  250 + AntExRecordQuery antExRecordQuery = new AntExRecordQuery();
  251 + antExRecordQuery.setPid(co.getUserId());
  252 + antExRecordQuery.setBarCode(co.getSequenceId());
  253 + List<AntExRecordModel> antExRecordModels = antExRecordService.queryAntExRecords(antExRecordQuery);
  254 + if (CollectionUtils.isNotEmpty(antExRecordModels)) {
  255 + AntExRecordModel antExRecordModel = antExRecordModels.get(0);
  256 + if (antExRecordModel != null) {
  257 + Map<String, Object> map = new HashMap<>();
  258 + map.put("id", co.getId());
  259 + map.put("usedId", antExRecordModel.getId());
  260 + couponMapper.updateUsed(map);
  261 + }
  262 + }
  263 + }
  264 + }
  265 + return new BaseObjectResponse();
  266 + }
  267 +
252 268 /**
253 269 * 根据医院id查询区域id
  270 + *
254 271 * @param hospitalId
255 272 * @return
256 273 */
257 274 private String getAreaCode(String hospitalId) {
258 275 String cityId = couponMapper.findCityId(hospitalId);
259   - if(StringUtils.isNotBlank(cityId)) {
  276 + if (StringUtils.isNotBlank(cityId)) {
260 277 AreaCodeModel areaCodeModel = mongoTemplate.findOne(Query.query(Criteria.where("areaId").is(cityId)), AreaCodeModel.class);
261   - if(areaCodeModel != null) {
  278 + if (areaCodeModel != null) {
262 279 String areaCode = areaCodeModel.getAreaCode();
263   - if(StringUtils.isNotBlank(areaCode)) {
  280 + if (StringUtils.isNotBlank(areaCode)) {
264 281 int length = areaCode.length();
265 282  
266   - if(length == 4) {
  283 + if (length == 4) {
267 284 return areaCode;
268 285 } else {
269 286 for (int i = 0; i < 4 - length; i++) {
... ... @@ -288,7 +305,7 @@
288 305 private void sendCoupon(List<Map<String, Object>> temps, String hospitalId, Integer createUserId, String userId, Integer personType, String areaCode) {
289 306 for (Map<String, Object> temp : temps) {
290 307 Object sendType = temp.get("send_type");
291   - if(sendType != null) {/** 1=全部发放 2=按有效时间发放 */
  308 + if (sendType != null) {/** 1=全部发放 2=按有效时间发放 */
292 309 CouponInfo couponInfo = new CouponInfo();
293 310 couponInfo.setCreateDate(new Date());
294 311 couponInfo.setCreateHospitalId(hospitalId);
295 312  
296 313  
297 314  
... ... @@ -296,18 +313,18 @@
296 313 couponInfo.setSequenceId(genIdService.poll(areaCode));
297 314 couponInfo.setStatus(1);
298 315 couponInfo.setUserId(userId);
299   - if(temp.get("coupon_template_id") != null) {
  316 + if (temp.get("coupon_template_id") != null) {
300 317 couponInfo.setCouponTemplateId(temp.get("coupon_template_id").toString());
301 318 }
302 319 /** 统一处理建档数据 自动使用,使用日期为建档日期,使用人为建档人,建档机构为建档人机构 */
303 320 Object type = temp.get("type");
304   - if(type != null && typeMap.get(PUT_ON_RECORD).contains(Integer.parseInt(type.toString()))) {
  321 + if (type != null && typeMap.get(PUT_ON_RECORD).contains(Integer.parseInt(type.toString()))) {
305 322 couponInfo.setStatus(2);
306 323  
307 324 /** 1=孕妇 2=儿童 3=产妇 */
308   - if(1 == personType || 3 == personType) {
  325 + if (1 == personType || 3 == personType) {
309 326 Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), Patients.class);
310   - if(patients != null){
  327 + if (patients != null) {
311 328 couponInfo.setUseDate(patients.getBookbuildingDate());
312 329 couponInfo.setOperatorUseId(patients.getBookbuildingDoctor());
313 330 couponInfo.setUsedHospitalId(patients.getHospitalId());
... ... @@ -315,7 +332,7 @@
315 332 }
316 333 } else {
317 334 BabyModel baby = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), BabyModel.class);
318   - if(baby != null) {
  335 + if (baby != null) {
319 336 couponInfo.setUseDate(baby.getBuildDate());
320 337 couponInfo.setOperatorUseId(baby.getBuildDoctor());
321 338 couponInfo.setUsedHospitalId(baby.getHospitalId());
322 339  
323 340  
324 341  
325 342  
... ... @@ -324,25 +341,23 @@
324 341 }
325 342 }
326 343  
327   - if("1".equals(sendType.toString())) {
  344 + if ("1".equals(sendType.toString())) {
328 345 couponMapper.save(couponInfo);
329   - } else if("2".equals(sendType.toString())) {
  346 + } else if ("2".equals(sendType.toString())) {
330 347  
331 348 /** 孕妇 > 分娩、出院小结、产后复查【分娩券、出院小结券、产后复查券全部发放】 */
332 349 List<String> list = Arrays.asList("4", "5", "6");
333   - if(personType == 1 && list.contains(temp.get("type").toString())) {
  350 + if (personType == 1 && list.contains(temp.get("type").toString())) {
334 351 couponMapper.save(couponInfo);
335 352 continue;
336 353 }
337 354  
338 355  
339   -
340   -
341 356 Object actualStart = temp.get("actual_start");
342 357 Object actualEnd = temp.get("actual_end");
343 358 Object unitType = temp.get("unit_type");
344   - if(actualStart != null && actualEnd != null && unitType != null && type != null) {
345   - if(validateDate(userId, Integer.parseInt(actualStart.toString()), Integer.parseInt(actualEnd.toString()),
  359 + if (actualStart != null && actualEnd != null && unitType != null && type != null) {
  360 + if (validateDate(userId, Integer.parseInt(actualStart.toString()), Integer.parseInt(actualEnd.toString()),
346 361 Integer.parseInt(unitType.toString()), hospitalId, Integer.parseInt(type.toString()), 1, personType)) {
347 362 couponMapper.save(couponInfo);
348 363 }
349 364  
350 365  
351 366  
352 367  
353 368  
... ... @@ -355,27 +370,27 @@
355 370 private List<Integer> findTypeByPerson(PersonModel person) {
356 371 List<Integer> types = new ArrayList<>();
357 372  
358   - if(person.getType() == 1) {
  373 + if (person.getType() == 1) {
359 374 return typeMap.get(PREGNANT_WOMAN);
360   - } else if(person.getType() == 2) {
  375 + } else if (person.getType() == 2) {
361 376 return typeMap.get(CHILDREN);
362   - } else if(person.getType() == 3) {
  377 + } else if (person.getType() == 3) {
363 378 /** 是否有分娩记录 */
364 379 boolean isChildbirth = false;
365 380 /** 是否有出院小结 */
366 381 boolean isHospital = false;
367 382  
368 383 List<Patients> patients = mongoTemplate.find(Query.query(Criteria.where("pid").is(person.getId())).with(new Sort(Sort.Direction.DESC, "lastMenses")), Patients.class);
369   - if(CollectionUtils.isEmpty(patients)) {
  384 + if (CollectionUtils.isEmpty(patients)) {
370 385 return types;
371 386 }
372 387 List<MaternalDeliverModel> deliverModels = mongoTemplate.find(Query.query(Criteria.where("pid").is(patients.get(0).getPid())), MaternalDeliverModel.class);
373   - if(CollectionUtils.isNotEmpty(deliverModels)) {
  388 + if (CollectionUtils.isNotEmpty(deliverModels)) {
374 389 isChildbirth = true;
375 390 }
376 391  
377 392 List<DischargeAbstractMotherModel> motherModels = mongoTemplate.find(Query.query(Criteria.where("patientId").is(patients.get(0).getId())), DischargeAbstractMotherModel.class);
378   - if(CollectionUtils.isNotEmpty(motherModels)) {
  393 + if (CollectionUtils.isNotEmpty(motherModels)) {
379 394 isHospital = true;
380 395 }
381 396 types = parseType(isChildbirth, isHospital);
382 397  
... ... @@ -384,9 +399,9 @@
384 399 }
385 400  
386 401 private List<Integer> parseType(boolean isChildbirth, boolean isHospital) {
387   - if(isChildbirth == false && isHospital == false) {
  402 + if (isChildbirth == false && isHospital == false) {
388 403 return typeMap.get(MATERNAL_NCHILDBIRTH_NHOSPITAL);
389   - } else if(isChildbirth == true && isHospital == false) {
  404 + } else if (isChildbirth == true && isHospital == false) {
390 405 return typeMap.get(MATERNAL_YCHILDBIRTH_NHOSPITAL);
391 406 } else {
392 407 return typeMap.get(MATERNAL_YCHILDBIRTH_YHOSPITAL);
393 408  
394 409  
395 410  
396 411  
397 412  
398 413  
399 414  
400 415  
401 416  
... ... @@ -399,47 +414,45 @@
399 414 param.put("code", code);
400 415 param.put("type", type);
401 416 List<CouponInfo> couponInfos = couponMapper.findList(param);
402   - if(CollectionUtils.isEmpty(couponInfos))
  417 + if (CollectionUtils.isEmpty(couponInfos))
403 418 return RespBuilder.buildErro(ResponseCode.COUPON_NOT_FOUND);
404   - if(couponInfos.size() > 1)
405   - return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE);
  419 + if (couponInfos.size() > 1)
  420 + return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE);
406 421  
407 422 CouponInfo couponInfo = couponInfos.get(0);
408 423 Map<String, Object> patientsInfo = getPatientsInfo(couponInfo.getUserId());
409 424  
410   - if(couponInfo.getStatus() == 3) {
  425 + if (couponInfo.getStatus() == 3) {
411 426 return RespBuilder.buildErro(ResponseCode.COUPON_IS_INVALID, patientsInfo);
412 427 }
413   - if(couponInfo.getStatus() == -1) {
  428 + if (couponInfo.getStatus() == -1) {
414 429 return RespBuilder.buildErro(ResponseCode.COUPON_IS_DISABLED, patientsInfo);
415 430 }
416   - if(couponInfo.getStatus() == 2) {
  431 + if (couponInfo.getStatus() == 2) {
417 432 return RespBuilder.buildErro(ResponseCode.COUPON_IS_USERD, patientsInfo);
418 433 }
419 434  
420 435 Map<String, Object> data = couponMapper.findValidateParam(param);
421   - if(MapUtils.isEmpty(data)) {
  436 + if (MapUtils.isEmpty(data)) {
422 437 return RespBuilder.buildErro(ResponseCode.COUPON_NOT_AVAILABLE, patientsInfo);
423 438 }
424 439  
425 440 PersonModel person = mongoTemplate.findById(couponInfo.getUserId(), PersonModel.class);
426 441  
427 442 /** 验证时间 */
428   - if(!validateDate(couponInfo.getUserId(), Integer.parseInt(data.get("actual_start").toString()), Integer.parseInt(data.get("actual_end").toString()), Integer.parseInt(data.get("unit_type").toString()),
  443 + if (!validateDate(couponInfo.getUserId(), Integer.parseInt(data.get("actual_start").toString()), Integer.parseInt(data.get("actual_end").toString()), Integer.parseInt(data.get("unit_type").toString()),
429 444 data.get("create_hospital_id").toString(), Integer.parseInt(data.get("type").toString()), 2, person.getType()))
430 445 return RespBuilder.buildErro(ResponseCode.COUPON_TIME_OUT, patientsInfo);
431 446  
432 447 /** 验证区域 */
433   - if(!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) {
  448 + if (!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) {
434 449 return RespBuilder.buildErro(ResponseCode.COUPON_AREA_NO_USE, patientsInfo);
435 450 }
436 451  
437 452 //验证优惠劵是否临时使用了 该功能属于秦皇岛区域
438   - if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1)
439   - {
  453 + if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1) {
440 454 //验证临时使用的医院是不是当前登陆的医院
441   - if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId))
442   - {
  455 + if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId)) {
443 456 return RespBuilder.buildErro(ResponseCode.COUPON_IS_USED);
444 457 }
445 458 }
446 459  
447 460  
448 461  
449 462  
450 463  
451 464  
452 465  
453 466  
454 467  
... ... @@ -449,48 +462,45 @@
449 462 }
450 463  
451 464  
452   -
453 465 @Override
454 466 public BaseObjectResponse validateUse(String code, Integer type, String hospitalId) {
455 467 Map<String, Object> param = new HashMap<>();
456 468 param.put("code", code);
457 469 param.put("type", type);
458 470 List<CouponInfo> couponInfos = couponMapper.findList(param);
459   - if(CollectionUtils.isEmpty(couponInfos))
  471 + if (CollectionUtils.isEmpty(couponInfos))
460 472 return RespBuilder.buildErro(ResponseCode.COUPON_NOT_FOUND);
461   - if(couponInfos.size() > 1)
462   - return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE);
  473 + if (couponInfos.size() > 1)
  474 + return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE);
463 475  
464 476 CouponInfo couponInfo = couponInfos.get(0);
465 477 Map<String, Object> patientsInfo = getPatientsInfo(couponInfo.getUserId());
466 478  
467   - if(couponInfo.getStatus() == 3) {
  479 + if (couponInfo.getStatus() == 3) {
468 480 return RespBuilder.buildErro(ResponseCode.COUPON_IS_INVALID, patientsInfo);
469 481 }
470   - if(couponInfo.getStatus() == -1) {
  482 + if (couponInfo.getStatus() == -1) {
471 483 return RespBuilder.buildErro(ResponseCode.COUPON_IS_DISABLED, patientsInfo);
472 484 }
473   - if(couponInfo.getStatus() == 2) {
  485 + if (couponInfo.getStatus() == 2) {
474 486 return RespBuilder.buildErro(ResponseCode.COUPON_IS_USERD, patientsInfo);
475 487 }
476 488  
477 489 Map<String, Object> data = couponMapper.findValidateParam(param);
478   - if(MapUtils.isEmpty(data)) {
  490 + if (MapUtils.isEmpty(data)) {
479 491 return RespBuilder.buildErro(ResponseCode.COUPON_NOT_AVAILABLE, patientsInfo);
480 492 }
481 493  
482 494  
483 495 /** 验证区域 */
484   - if(!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) {
  496 + if (!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) {
485 497 return RespBuilder.buildErro(ResponseCode.COUPON_AREA_NO_USE, patientsInfo);
486 498 }
487 499  
488 500 //验证优惠劵是否临时使用了 该功能属于秦皇岛区域
489   - if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1)
490   - {
  501 + if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1) {
491 502 //验证临时使用的医院是不是当前登陆的医院
492   - if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId))
493   - {
  503 + if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId)) {
494 504 return RespBuilder.buildErro(ResponseCode.COUPON_IS_USED);
495 505 }
496 506 }
497 507  
498 508  
... ... @@ -507,22 +517,22 @@
507 517  
508 518 /** 1=孕妇 2=儿童 3=产妇 */
509 519 PersonModel person = mongoTemplate.findById(userId, PersonModel.class);
510   - if(person != null){
511   - if(person.getType() == 2) {
  520 + if (person != null) {
  521 + if (person.getType() == 2) {
512 522 BabyModel baby = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), BabyModel.class);
513 523 restMap.put("vcCardNo", baby.getVcCardNo()); /** 就诊卡号 */
514 524 // restMap.put("cardNo", baby.getCardNo()); /** 证件号 */
515 525 restMap.put("cardNo", person.getCardNo()); /** 证件号 */
516 526  
517 527 List<Patients> list = mongoTemplate.find(Query.query(Criteria.where("cardNo").is(person.getCardNo())).with(new Sort(Sort.Direction.DESC, "created")), Patients.class);
518   - if(CollectionUtils.isNotEmpty(list)) {
  528 + if (CollectionUtils.isNotEmpty(list)) {
519 529 restMap.put("pcerteTypeId", list.get(0).getPcerteTypeId()); /** 证件类型id */
520 530 } else {
521 531 restMap.put("pcerteTypeId", "57e1dd12f0f02e7ca519d6c7"); /** 其他*/
522 532 }
523 533 } else {
524 534 Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), Patients.class);
525   - if(patients != null) {
  535 + if (patients != null) {
526 536 restMap.put("vcCardNo", patients.getVcCardNo()); /** 就诊卡号 */
527 537 restMap.put("cardNo", patients.getCardNo()); /** 证件号 */
528 538 restMap.put("pcerteTypeId", patients.getPcerteTypeId()); /** 证件类型id */
529 539  
... ... @@ -535,11 +545,11 @@
535 545  
536 546 @Override
537 547 public Map<String, Object> getPatientsInfoByCode(String code) {
538   - if(org.apache.commons.lang.StringUtils.isNotEmpty(code)){
  548 + if (org.apache.commons.lang.StringUtils.isNotEmpty(code)) {
539 549 Map<String, Object> param = new HashMap<>();
540 550 param.put("code", code);
541 551 List<CouponInfo> list = couponMapper.findList(param);
542   - if(CollectionUtils.isNotEmpty(list)) {
  552 + if (CollectionUtils.isNotEmpty(list)) {
543 553 return getPatientsInfo(list.get(0).getUserId());
544 554 }
545 555 }
546 556  
... ... @@ -549,9 +559,10 @@
549 559 /**
550 560 * 当删除孕妇或儿童档案时,默认修改该孕妇和儿童下所有的优惠券为已删除的状态
551 561 * 操作人为当前登陆人的id
552   - * @param userId 登陆人的id
  562 + *
  563 + * @param userId 登陆人的id
553 564 * @param hospitalId 医院id
554   - * @param delUserId 被删除优惠券人的id
  565 + * @param delUserId 被删除优惠券人的id
555 566 */
556 567 @Override
557 568 public void del(String userId, String hospitalId, String delUserId) {
558 569  
559 570  
560 571  
... ... @@ -593,23 +604,22 @@
593 604 params.put("hId", hId);
594 605 params.put("dpId", person.getType() == 2 ? "2" : "1");
595 606 //调用本地
596   - if(type == 1) {
  607 + if (type == 1) {
597 608 WeixinQrcodeConfigQuery query = new WeixinQrcodeConfigQuery();
598 609 query.setDpId(person.getType() == 2 ? 2 : 1);
599 610 query.setHospitalId(hId);
600 611  
601 612  
602 613 List<WeixinQrcodeConfig> weixinQrcodeConfigs = weixinQrcodeConfigService.queryWeixinShowqrcodeConfig(query);
603   - if(CollectionUtils.isNotEmpty(weixinQrcodeConfigs)) {
  614 + if (CollectionUtils.isNotEmpty(weixinQrcodeConfigs)) {
604 615 String url = weixinQrcodeConfigs.get(0).getWxUrl();
605 616 return url;
606   - }
607   - else
608   - {
  617 + } else {
609 618 System.out.println("no coupon config ; hospital id = " + hId);
610 619 }
611 620 }
612   - try {String s = HttpClientUtil.doGet(PropertiesUtil.getInstance().getDefault("or.code.create.url"), params, "utf-8", null);
  621 + try {
  622 + String s = HttpClientUtil.doGet(PropertiesUtil.getInstance().getDefault("or.code.create.url"), params, "utf-8", null);
613 623 JSONObject jsonObject = JSONObject.fromObject(s);
614 624 return jsonObject.get("url").toString();
615 625 } catch (Exception e) {
... ... @@ -632,7 +642,7 @@
632 642 }
633 643  
634 644 @Override
635   - public Map<String,String> findCouponByCode(Map<String,String> param) {
  645 + public Map<String, String> findCouponByCode(Map<String, String> param) {
636 646  
637 647 return couponMapper.findCouponByCode(param);
638 648 }
639 649  
640 650  
641 651  
642 652  
... ... @@ -673,25 +683,27 @@
673 683 return couponMapper.queryCouponItemsByType(params);
674 684 }
675 685  
676   - /** 1=省 2=市 3=区 4=单医院 */
  686 + /**
  687 + * 1=省 2=市 3=区 4=单医院
  688 + */
677 689 private boolean validateArea(String areaType, String createHospitalId, String useHospitald) {
678 690 Organization createHospital = organizationService.getOrganization(Integer.parseInt(createHospitalId));
679 691 Organization useHospital = organizationService.getOrganization(Integer.parseInt(useHospitald));
680 692  
681   - if(createHospital != null && useHospital != null) {
682   - if("1".equals(areaType)) {
683   - if(StringUtils.isNotBlank(createHospital.getProvinceId())) {
  693 + if (createHospital != null && useHospital != null) {
  694 + if ("1".equals(areaType)) {
  695 + if (StringUtils.isNotBlank(createHospital.getProvinceId())) {
684 696 return createHospital.getProvinceId().equals(useHospital.getProvinceId());
685 697 }
686   - } else if("2".equals(areaType)) {
687   - if(StringUtils.isNotBlank(createHospital.getCityId())) {
  698 + } else if ("2".equals(areaType)) {
  699 + if (StringUtils.isNotBlank(createHospital.getCityId())) {
688 700 return createHospital.getCityId().equals(useHospital.getCityId());
689 701 }
690   - } else if("3".equals(areaType)) {
691   - if(StringUtils.isNotBlank(createHospital.getAreaId())) {
  702 + } else if ("3".equals(areaType)) {
  703 + if (StringUtils.isNotBlank(createHospital.getAreaId())) {
692 704 return createHospital.getAreaId().equals(useHospital.getAreaId());
693 705 }
694   - } else if("4".equals(areaType)) {
  706 + } else if ("4".equals(areaType)) {
695 707 return createHospitalId.equals(useHospitald);
696 708 }
697 709 }
698 710  
... ... @@ -700,14 +712,15 @@
700 712  
701 713 /**
702 714 * 判断当前时间是否满足生成规则的时间
703   - * @param userId 孕妇id
704   - * @param start 真实的开始时间
705   - * @param end 真实的结束时间
706   - * @param unitType 时间单位 1=孕周 2=天数 3=月龄
707   - * @param hospitalId 医院id
708   - * @param couponType 产检券类型 1=孕妇 2=产妇 3=儿童
  715 + *
  716 + * @param userId 孕妇id
  717 + * @param start 真实的开始时间
  718 + * @param end 真实的结束时间
  719 + * @param unitType 时间单位 1=孕周 2=天数 3=月龄
  720 + * @param hospitalId 医院id
  721 + * @param couponType 产检券类型 1=孕妇 2=产妇 3=儿童
709 722 * @param validateType 验证类型 1=创建 2=使用
710   - * @param personType 1=孕妇 2=儿童 3=产妇
  723 + * @param personType 1=孕妇 2=儿童 3=产妇
711 724 * @return
712 725 */
713 726 private boolean validateDate(String userId, Integer start, Integer end, Integer unitType, String hospitalId, Integer couponType, Integer validateType, Integer personType) {
714 727  
715 728  
716 729  
717 730  
718 731  
719 732  
720 733  
721 734  
... ... @@ -715,38 +728,38 @@
715 728 Date startDate = null;
716 729 Date endDate = null;
717 730  
718   - if(personType == 2) { /** 儿童根据生日对比 */
  731 + if (personType == 2) { /** 儿童根据生日对比 */
719 732 BabyModel baby = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), BabyModel.class);
720 733 midDate = baby.getBirth();
721 734 } else {
722 735 Patients patient = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), Patients.class);
723 736  
724   - if(personType == 1 || couponType == 4) { /** 孕妇根据末次月经对比 分娩券按照末次月经对比 */
  737 + if (personType == 1 || couponType == 4) { /** 孕妇根据末次月经对比 分娩券按照末次月经对比 */
725 738 midDate = patient.getLastMenses();
726   - } else if(personType == 3) { /** 产妇根据分娩时间对比 */
  739 + } else if (personType == 3) { /** 产妇根据分娩时间对比 */
727 740 midDate = patient.getFmDate();
728 741 } else {
729 742 return false;
730 743 }
731 744 }
732 745  
733   - if(midDate != null) {
734   - if(unitType == 1) { /** 孕周: startDate = lastMenses + start*7、 endDate = lastMenses + end*7 + 6*/
  746 + if (midDate != null) {
  747 + if (unitType == 1) { /** 孕周: startDate = lastMenses + start*7、 endDate = lastMenses + end*7 + 6*/
735 748 startDate = DateUtils.addDays(midDate, start * 7);
736 749 endDate = DateUtils.addDays(midDate, end * 7 + 6);
737   - } else if(unitType == 2) { /** 天数 stratDate = 孕妇:fmDate/儿童:birth + start、 endDate = lastMenses + end */
  750 + } else if (unitType == 2) { /** 天数 stratDate = 孕妇:fmDate/儿童:birth + start、 endDate = lastMenses + end */
738 751 startDate = DateUtils.addDays(midDate, start);
739 752 endDate = DateUtils.addDays(midDate, end);
740   - } else if(unitType == 3) { /** 月龄 startDate = fmDate/birth + start、 endDate = fmDate/birth + end + 1 如果是31号 计算出来的月份没有31号 取最后一天*/
  753 + } else if (unitType == 3) { /** 月龄 startDate = fmDate/birth + start、 endDate = fmDate/birth + end + 1 如果是31号 计算出来的月份没有31号 取最后一天*/
741 754 startDate = DateUtils.addMonths(midDate, start);
742 755 endDate = DateUtils.addMonths(midDate, end + 1);
743 756 }
744   - if(validateType == 2) { /**使用 */
  757 + if (validateType == 2) { /**使用 */
745 758 // if(DateUtil.isBetween(new Date(), startDate, endDate)) {
746   - if(DateUtil.isBetween(new Date(), startDate, DateUtils.addDays(endDate, 1))) {
  759 + if (DateUtil.isBetween(new Date(), startDate, DateUtils.addDays(endDate, 1))) {
747 760 return true;
748 761 }
749   - } else if(validateType == 1) {
  762 + } else if (validateType == 1) {
750 763 return DateUtil.isLtOrEq(new Date(), endDate);
751 764 }
752 765 }
753 766  
754 767  
755 768  
... ... @@ -754,16 +767,16 @@
754 767 }
755 768  
756 769 @Override
757   - public BaseObjectResponse findList(String userId, String hospitalId, String url,Integer type) {
  770 + public BaseObjectResponse findList(String userId, String hospitalId, String url, Integer type) {
758 771 Integer year = DateUtil.getCurrentYear();
759 772 String peopleNum = null;
760 773 PlantformConfigModel model = mongoTemplate.findOne(Query.query(Criteria.where("key").is(hospitalId).and("type").is(SequenceConstant.QUEUE_TYPE)), PlantformConfigModel.class);
761   - if(model != null) {
  774 + if (model != null) {
762 775 String value = model.getValue();
763   - if(StringUtils.isNotEmpty(value)) {
  776 + if (StringUtils.isNotEmpty(value)) {
764 777 Map<Integer, Integer> map = JSON.parseObject(value, Map.class);
765 778 Integer code = map.get(year);
766   - if(code != null) {
  779 + if (code != null) {
767 780 peopleNum = String.valueOf(year).substring(2) + "-" + code;
768 781 }
769 782 }
770 783  
771 784  
772 785  
... ... @@ -776,20 +789,18 @@
776 789 Map<String, Object> restMap = new HashMap<>();
777 790 restMap.put("topName", couponMapper.findTopName(hospitalId));
778 791 List<Map<String, Object>> couponInfos = couponMapper.findInfo(param);
779   - for (Map<String,Object> map : couponInfos) {
780   - map.put("url", findUrl(map.get("sequence_id").toString(),type));
781   - if(StringUtils.isNotEmpty(peopleNum)) {
  792 + for (Map<String, Object> map : couponInfos) {
  793 + map.put("url", findUrl(map.get("sequence_id").toString(), type));
  794 + if (StringUtils.isNotEmpty(peopleNum)) {
782 795 map.put("peopleNum", peopleNum);
783 796 }
784   - map.put("days",0);
  797 + map.put("days", 0);
785 798 //滦平县妇幼保健院2100001377
786 799 //滦平县妇幼保健院首次产检券 孕0-12周 改为 孕0-12周+6天
787   - if ("2100001377".equals(hospitalId))
788   - {
  800 + if ("2100001377".equals(hospitalId)) {
789 801 Integer show_end = Integer.parseInt(String.valueOf(map.get("show_end")));
790   - if (show_end == 12)
791   - {
792   - map.put("days",6);
  802 + if (show_end == 12) {
  803 + map.put("days", 6);
793 804 }
794 805 }
795 806 }
platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml View file @ 7037a3c
... ... @@ -27,6 +27,10 @@
27 27 select * from coupon_info where user_id = #{userId} and sequence_id = #{code}
28 28 </select>
29 29  
  30 + <select id="findErrorData" resultMap="couponInfoMap">
  31 + select * from coupon_info where `status`='2' and used_id is null order by create_date desc
  32 + </select>
  33 +
30 34 <select id="getUserName" parameterType="string" resultType="string">
31 35 select name from users where id = #{id}
32 36 </select>
... ... @@ -92,6 +96,12 @@
92 96 update coupon_info
93 97 set use_date = #{useDate}, operator_use_id = #{operatorUseId}, used_hospital_id = #{hospitalId}, status = #{status}, used_id = #{usedId}
94 98 where sequence_id = #{code}
  99 + </update>
  100 +
  101 + <update id="updateUsed" parameterType="map">
  102 + update coupon_info
  103 + set used_id = #{usedId}
  104 + where id = #{id}
95 105 </update>
96 106  
97 107 <update id="update" parameterType="map">
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java View file @ 7037a3c
... ... @@ -18,7 +18,6 @@
18 18 import org.slf4j.Logger;
19 19 import org.slf4j.LoggerFactory;
20 20 import org.springframework.beans.factory.annotation.Autowired;
21   -import org.springframework.beans.factory.annotation.Value;
22 21 import org.springframework.data.mongodb.core.MongoTemplate;
23 22 import org.springframework.stereotype.Controller;
24 23 import org.springframework.web.bind.annotation.PathVariable;
... ... @@ -77,6 +76,16 @@
77 76 public BaseObjectResponse create(String userId, String hospitalId, String patientId, HttpServletRequest request) {
78 77 LoginContext loginState = (LoginContext) request.getAttribute("loginContext");
79 78 return couponService.create(userId, hospitalId, loginState.getId(), patientId);
  79 + }
  80 +
  81 + /**
  82 + * 处理垃圾数据
  83 + * @return
  84 + */
  85 + @RequestMapping(method = RequestMethod.GET, value = "/distErrorData")
  86 + @ResponseBody
  87 + public BaseObjectResponse distErrorData() {
  88 + return couponService.distErrorData();
80 89 }
81 90  
82 91 /**