diff --git a/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java b/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java index 7de9438..b47ff09 100644 --- a/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java +++ b/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java @@ -14,6 +14,10 @@ import java.util.Set; public interface CouponMapper { List findList(Map params); + List findErrorData(); + + void updateUsed(Map map); + void save(CouponInfo couponInfo); List> findTemp(Map map); diff --git a/platform-biz-service/src/main/java/com/lyms/platform/permission/service/CouponService.java b/platform-biz-service/src/main/java/com/lyms/platform/permission/service/CouponService.java index b295463..734f203 100644 --- a/platform-biz-service/src/main/java/com/lyms/platform/permission/service/CouponService.java +++ b/platform-biz-service/src/main/java/com/lyms/platform/permission/service/CouponService.java @@ -15,6 +15,8 @@ import java.util.Set; public interface CouponService{ BaseObjectResponse create(String userId, String hospitalId, Integer createUserId, String patientId); + BaseObjectResponse distErrorData(); + BaseObjectResponse validate(String code, Integer type, String hospitalId); BaseObjectResponse findList(String userId, String hospitalId, String url,Integer type); diff --git a/platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/CouponServiceImpl.java b/platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/CouponServiceImpl.java index 0d8904f..00d9bc1 100644 --- a/platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/CouponServiceImpl.java +++ b/platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/CouponServiceImpl.java @@ -3,6 +3,7 @@ package com.lyms.platform.permission.service.impl; import com.alibaba.fastjson.JSON; import com.lyms.platform.biz.SequenceConstant; import com.lyms.platform.biz.dal.IPatientDao; +import com.lyms.platform.biz.service.AntExRecordService; import com.lyms.platform.biz.service.GenSequenceIdService; import com.lyms.platform.common.result.BaseObjectResponse; import com.lyms.platform.common.result.RespBuilder; @@ -19,6 +20,7 @@ import com.lyms.platform.permission.service.CouponService; import com.lyms.platform.permission.service.OrganizationService; import com.lyms.platform.permission.service.WeixinQrcodeConfigService; import com.lyms.platform.pojo.*; +import com.lyms.platform.query.AntExRecordQuery; import net.sf.json.JSONObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; @@ -46,24 +48,37 @@ public class CouponServiceImpl implements CouponService { private Logger logger = LoggerFactory.getLogger(CouponServiceImpl.class); - /** 1 = 孕妇 */ + /** + * 1 = 孕妇 + */ private static final String PREGNANT_WOMAN = "1"; - /** 2 = 儿童 */ + /** + * 2 = 儿童 + */ private static final String CHILDREN = "2"; - + @Autowired + private AntExRecordService antExRecordService; @Autowired private IPatientDao iPatientDao; /** 3_{?} = 产妇 */ - /** 产妇没有分娩记录且没有出院小结 */ + /** + * 产妇没有分娩记录且没有出院小结 + */ private static final String MATERNAL_NCHILDBIRTH_NHOSPITAL = "3_1"; - /** 产妇有分娩记录且没有出院小结 */ + /** + * 产妇有分娩记录且没有出院小结 + */ private static final String MATERNAL_YCHILDBIRTH_NHOSPITAL = "3_2"; - /** 产妇有分娩记录且有出院小结 */ + /** + * 产妇有分娩记录且有出院小结 + */ private static final String MATERNAL_YCHILDBIRTH_YHOSPITAL = "3_3"; - /** 建档 */ + /** + * 建档 + */ private static final String PUT_ON_RECORD = "4"; @Autowired @@ -91,8 +106,10 @@ public class CouponServiceImpl implements CouponService { * 建档:统一处理,如果点击创建中配置了建档券,自动使用,使用日期为建档日期,使用人为建档人,建档机构为建档人机构 */ /** key>> 1=孕妇 2=儿童 3=产妇 */ - /** value>> 1=孕妇建档 2=孕妇产检 3=产妇建档 4=产妇分娩 5=产妇出院小结 6=产妇产后复查 7=儿童建档 8=儿童保健 */ - private Map> typeMap = new HashMap>() { + /** + * value>> 1=孕妇建档 2=孕妇产检 3=产妇建档 4=产妇分娩 5=产妇出院小结 6=产妇产后复查 7=儿童建档 8=儿童保健 + */ + private Map> typeMap = new HashMap>() { { put(PREGNANT_WOMAN, Arrays.asList(1, 2, 4, 5, 6)); put(CHILDREN, Arrays.asList(7, 8, 9, 10)); @@ -105,18 +122,18 @@ public class CouponServiceImpl implements CouponService { @Override public BaseObjectResponse create(String userId, String hospitalId, Integer createUserId, String patientId) { - if(isCreated(userId, hospitalId)) { + if (isCreated(userId, hospitalId)) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_CREATED); } /** 1=孕妇 2=儿童 3=产妇 */ PersonModel person = mongoTemplate.findById(userId, PersonModel.class); - if(person == null || person.getType() == null) { + if (person == null || person.getType() == null) { return RespBuilder.buildErro(ResponseCode.PERSON_NOT_FOUND); } List types = findTypeByPerson(person); - if(CollectionUtils.isEmpty(types)) { + if (CollectionUtils.isEmpty(types)) { return RespBuilder.buildErro(ResponseCode.PATIENT_NOT_FOUND); } @@ -125,78 +142,56 @@ public class CouponServiceImpl implements CouponService { param.put("hospitalId", hospitalId); Integer start = null; - if (person.getType() == 1 || person.getType() == 3) - { + if (person.getType() == 1 || person.getType() == 3) { Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("id").is(patientId)), Patients.class); - if (patients != null && patients.getType() == 3) - { + if (patients != null && patients.getType() == 3) { Date fmDate = patients.getFmDate(); - if (fmDate != null) - { - start = DateUtil.getDays(fmDate,new Date()); + if (fmDate != null) { + start = DateUtil.getDays(fmDate, new Date()); } - } - else if (patients != null && patients.getType() == 1) - { + } else if (patients != null && patients.getType() == 1) { start = DateUtil.getWeek2(patients.getLastMenses(), new Date()); } - } - else if (person.getType() == 2) - { + } else if (person.getType() == 2) { BabyModel babyModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(patientId)), BabyModel.class); - if (babyModel != null && babyModel.getBirth() != null) - { + if (babyModel != null && babyModel.getBirth() != null) { start = DateUtil.getMonth(babyModel.getBirth(), new Date()); } } - List> temps = couponMapper.findTemp(param); + List> temps = couponMapper.findTemp(param); - List> list = new ArrayList<>(); + List> list = new ArrayList<>(); //滦平县妇幼保健院 - if ("2100001377".equals(hospitalId)) - { - if (CollectionUtils.isNotEmpty(temps)) - { - for (Map map : temps) - { + if ("2100001377".equals(hospitalId)) { + if (CollectionUtils.isNotEmpty(temps)) { + for (Map map : temps) { Integer type = Integer.parseInt(map.get("type").toString()); - if (person.getType() == 1) - { - if (type != 2) - { + if (person.getType() == 1) { + if (type != 2) { list.add(map); } - } - else if (person.getType() == 3) - { - if (type != 6) - { + } else if (person.getType() == 3) { + if (type != 6) { list.add(map); } } } - for (Map map : temps) - { + for (Map map : temps) { Integer type = Integer.parseInt(map.get("type").toString()); - if (person.getType() == 1 && type == 2) - { + if (person.getType() == 1 && type == 2) { Integer showStart = Integer.parseInt(map.get("show_start").toString()); Integer showEnd = Integer.parseInt(map.get("show_end").toString()); - if ((showStart <= start && showEnd >= start) || showStart >= start) - { + if ((showStart <= start && showEnd >= start) || showStart >= start) { list.add(map); } - } - else if (person.getType() == 3 && type == 6) - { + } else if (person.getType() == 3 && type == 6) { Integer showStart = Integer.parseInt(map.get("show_start").toString()); Integer showEnd = Integer.parseInt(map.get("show_end").toString()); - if ((showStart <= start && showEnd >= start) || showStart >= start) - { + if ((showStart <= start && showEnd >= start) || showStart >= start) { list.add(map); } @@ -204,19 +199,17 @@ public class CouponServiceImpl implements CouponService { } } - } - else - { + } else { list.addAll(temps); } - if(CollectionUtils.isEmpty(list)) { + if (CollectionUtils.isEmpty(list)) { return RespBuilder.buildErro(ResponseCode.COUPON_TEMP_NOT_FOUND); } String areaCode = getAreaCode(hospitalId); - if(StringUtils.isBlank(areaCode)) { + if (StringUtils.isBlank(areaCode)) { return RespBuilder.buildErro(ResponseCode.OUPON_HOSPITAL_NOT_BOUND_AREA); } @@ -227,14 +220,14 @@ public class CouponServiceImpl implements CouponService { /** 如果配置了医院打印人数 mongo人数自增1 */ PlantformConfigModel model = mongoTemplate.findOne(Query.query(Criteria.where("key").is(hospitalId).and("type").is(SequenceConstant.HOSPITAL_COUPON_CODE)), PlantformConfigModel.class); - if(model != null) { + if (model != null) { String value = model.getValue(); Map map = new HashMap<>(); Integer year = DateUtil.getCurrentYear(); - if(StringUtils.isNotEmpty(value)) { + if (StringUtils.isNotEmpty(value)) { map = JSON.parseObject(value, Map.class); Integer code = map.get(year); - if(code != null) { + if (code != null) { map.put(year, ++code); } else { map.put(year, 1); @@ -249,21 +242,45 @@ public class CouponServiceImpl implements CouponService { return RespBuilder.buildSuccess(); } + @Override + public BaseObjectResponse distErrorData() { + List couponInfos = couponMapper.findErrorData(); + if (CollectionUtils.isNotEmpty(couponInfos)) { + for (CouponInfo co : couponInfos) { + AntExRecordQuery antExRecordQuery = new AntExRecordQuery(); + antExRecordQuery.setPid(co.getUserId()); + antExRecordQuery.setBarCode(co.getSequenceId()); + List antExRecordModels = antExRecordService.queryAntExRecords(antExRecordQuery); + if (CollectionUtils.isNotEmpty(antExRecordModels)) { + AntExRecordModel antExRecordModel = antExRecordModels.get(0); + if (antExRecordModel != null) { + Map map = new HashMap<>(); + map.put("id", co.getId()); + map.put("usedId", antExRecordModel.getId()); + couponMapper.updateUsed(map); + } + } + } + } + return new BaseObjectResponse(); + } + /** * 根据医院id查询区域id + * * @param hospitalId * @return */ private String getAreaCode(String hospitalId) { String cityId = couponMapper.findCityId(hospitalId); - if(StringUtils.isNotBlank(cityId)) { + if (StringUtils.isNotBlank(cityId)) { AreaCodeModel areaCodeModel = mongoTemplate.findOne(Query.query(Criteria.where("areaId").is(cityId)), AreaCodeModel.class); - if(areaCodeModel != null) { + if (areaCodeModel != null) { String areaCode = areaCodeModel.getAreaCode(); - if(StringUtils.isNotBlank(areaCode)) { + if (StringUtils.isNotBlank(areaCode)) { int length = areaCode.length(); - if(length == 4) { + if (length == 4) { return areaCode; } else { for (int i = 0; i < 4 - length; i++) { @@ -288,7 +305,7 @@ public class CouponServiceImpl implements CouponService { private void sendCoupon(List> temps, String hospitalId, Integer createUserId, String userId, Integer personType, String areaCode) { for (Map temp : temps) { Object sendType = temp.get("send_type"); - if(sendType != null) {/** 1=全部发放 2=按有效时间发放 */ + if (sendType != null) {/** 1=全部发放 2=按有效时间发放 */ CouponInfo couponInfo = new CouponInfo(); couponInfo.setCreateDate(new Date()); couponInfo.setCreateHospitalId(hospitalId); @@ -296,18 +313,18 @@ public class CouponServiceImpl implements CouponService { couponInfo.setSequenceId(genIdService.poll(areaCode)); couponInfo.setStatus(1); couponInfo.setUserId(userId); - if(temp.get("coupon_template_id") != null) { + if (temp.get("coupon_template_id") != null) { couponInfo.setCouponTemplateId(temp.get("coupon_template_id").toString()); } /** 统一处理建档数据 自动使用,使用日期为建档日期,使用人为建档人,建档机构为建档人机构 */ Object type = temp.get("type"); - if(type != null && typeMap.get(PUT_ON_RECORD).contains(Integer.parseInt(type.toString()))) { + if (type != null && typeMap.get(PUT_ON_RECORD).contains(Integer.parseInt(type.toString()))) { couponInfo.setStatus(2); /** 1=孕妇 2=儿童 3=产妇 */ - if(1 == personType || 3 == personType) { + if (1 == personType || 3 == personType) { Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), Patients.class); - if(patients != null){ + if (patients != null) { couponInfo.setUseDate(patients.getBookbuildingDate()); couponInfo.setOperatorUseId(patients.getBookbuildingDoctor()); couponInfo.setUsedHospitalId(patients.getHospitalId()); @@ -315,7 +332,7 @@ public class CouponServiceImpl implements CouponService { } } else { BabyModel baby = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), BabyModel.class); - if(baby != null) { + if (baby != null) { couponInfo.setUseDate(baby.getBuildDate()); couponInfo.setOperatorUseId(baby.getBuildDoctor()); couponInfo.setUsedHospitalId(baby.getHospitalId()); @@ -324,25 +341,23 @@ public class CouponServiceImpl implements CouponService { } } - if("1".equals(sendType.toString())) { + if ("1".equals(sendType.toString())) { couponMapper.save(couponInfo); - } else if("2".equals(sendType.toString())) { + } else if ("2".equals(sendType.toString())) { /** 孕妇 > 分娩、出院小结、产后复查【分娩券、出院小结券、产后复查券全部发放】 */ List list = Arrays.asList("4", "5", "6"); - if(personType == 1 && list.contains(temp.get("type").toString())) { + if (personType == 1 && list.contains(temp.get("type").toString())) { couponMapper.save(couponInfo); continue; } - - Object actualStart = temp.get("actual_start"); Object actualEnd = temp.get("actual_end"); Object unitType = temp.get("unit_type"); - if(actualStart != null && actualEnd != null && unitType != null && type != null) { - if(validateDate(userId, Integer.parseInt(actualStart.toString()), Integer.parseInt(actualEnd.toString()), + if (actualStart != null && actualEnd != null && unitType != null && type != null) { + if (validateDate(userId, Integer.parseInt(actualStart.toString()), Integer.parseInt(actualEnd.toString()), Integer.parseInt(unitType.toString()), hospitalId, Integer.parseInt(type.toString()), 1, personType)) { couponMapper.save(couponInfo); } @@ -355,27 +370,27 @@ public class CouponServiceImpl implements CouponService { private List findTypeByPerson(PersonModel person) { List types = new ArrayList<>(); - if(person.getType() == 1) { + if (person.getType() == 1) { return typeMap.get(PREGNANT_WOMAN); - } else if(person.getType() == 2) { + } else if (person.getType() == 2) { return typeMap.get(CHILDREN); - } else if(person.getType() == 3) { + } else if (person.getType() == 3) { /** 是否有分娩记录 */ boolean isChildbirth = false; /** 是否有出院小结 */ boolean isHospital = false; List patients = mongoTemplate.find(Query.query(Criteria.where("pid").is(person.getId())).with(new Sort(Sort.Direction.DESC, "lastMenses")), Patients.class); - if(CollectionUtils.isEmpty(patients)) { + if (CollectionUtils.isEmpty(patients)) { return types; } List deliverModels = mongoTemplate.find(Query.query(Criteria.where("pid").is(patients.get(0).getPid())), MaternalDeliverModel.class); - if(CollectionUtils.isNotEmpty(deliverModels)) { + if (CollectionUtils.isNotEmpty(deliverModels)) { isChildbirth = true; } List motherModels = mongoTemplate.find(Query.query(Criteria.where("patientId").is(patients.get(0).getId())), DischargeAbstractMotherModel.class); - if(CollectionUtils.isNotEmpty(motherModels)) { + if (CollectionUtils.isNotEmpty(motherModels)) { isHospital = true; } types = parseType(isChildbirth, isHospital); @@ -384,9 +399,9 @@ public class CouponServiceImpl implements CouponService { } private List parseType(boolean isChildbirth, boolean isHospital) { - if(isChildbirth == false && isHospital == false) { + if (isChildbirth == false && isHospital == false) { return typeMap.get(MATERNAL_NCHILDBIRTH_NHOSPITAL); - } else if(isChildbirth == true && isHospital == false) { + } else if (isChildbirth == true && isHospital == false) { return typeMap.get(MATERNAL_YCHILDBIRTH_NHOSPITAL); } else { return typeMap.get(MATERNAL_YCHILDBIRTH_YHOSPITAL); @@ -399,47 +414,45 @@ public class CouponServiceImpl implements CouponService { param.put("code", code); param.put("type", type); List couponInfos = couponMapper.findList(param); - if(CollectionUtils.isEmpty(couponInfos)) + if (CollectionUtils.isEmpty(couponInfos)) return RespBuilder.buildErro(ResponseCode.COUPON_NOT_FOUND); - if(couponInfos.size() > 1) - return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE); + if (couponInfos.size() > 1) + return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE); CouponInfo couponInfo = couponInfos.get(0); Map patientsInfo = getPatientsInfo(couponInfo.getUserId()); - if(couponInfo.getStatus() == 3) { + if (couponInfo.getStatus() == 3) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_INVALID, patientsInfo); } - if(couponInfo.getStatus() == -1) { + if (couponInfo.getStatus() == -1) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_DISABLED, patientsInfo); } - if(couponInfo.getStatus() == 2) { + if (couponInfo.getStatus() == 2) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_USERD, patientsInfo); } Map data = couponMapper.findValidateParam(param); - if(MapUtils.isEmpty(data)) { + if (MapUtils.isEmpty(data)) { return RespBuilder.buildErro(ResponseCode.COUPON_NOT_AVAILABLE, patientsInfo); } PersonModel person = mongoTemplate.findById(couponInfo.getUserId(), PersonModel.class); /** 验证时间 */ - 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()), + 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()), data.get("create_hospital_id").toString(), Integer.parseInt(data.get("type").toString()), 2, person.getType())) return RespBuilder.buildErro(ResponseCode.COUPON_TIME_OUT, patientsInfo); /** 验证区域 */ - if(!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) { + if (!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) { return RespBuilder.buildErro(ResponseCode.COUPON_AREA_NO_USE, patientsInfo); } //验证优惠劵是否临时使用了 该功能属于秦皇岛区域 - if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1) - { + if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1) { //验证临时使用的医院是不是当前登陆的医院 - if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId)) - { + if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId)) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_USED); } } @@ -449,48 +462,45 @@ public class CouponServiceImpl implements CouponService { } - @Override public BaseObjectResponse validateUse(String code, Integer type, String hospitalId) { Map param = new HashMap<>(); param.put("code", code); param.put("type", type); List couponInfos = couponMapper.findList(param); - if(CollectionUtils.isEmpty(couponInfos)) + if (CollectionUtils.isEmpty(couponInfos)) return RespBuilder.buildErro(ResponseCode.COUPON_NOT_FOUND); - if(couponInfos.size() > 1) - return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE); + if (couponInfos.size() > 1) + return RespBuilder.buildErro(ResponseCode.COUPON_NOT_UNIQUE); CouponInfo couponInfo = couponInfos.get(0); Map patientsInfo = getPatientsInfo(couponInfo.getUserId()); - if(couponInfo.getStatus() == 3) { + if (couponInfo.getStatus() == 3) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_INVALID, patientsInfo); } - if(couponInfo.getStatus() == -1) { + if (couponInfo.getStatus() == -1) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_DISABLED, patientsInfo); } - if(couponInfo.getStatus() == 2) { + if (couponInfo.getStatus() == 2) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_USERD, patientsInfo); } Map data = couponMapper.findValidateParam(param); - if(MapUtils.isEmpty(data)) { + if (MapUtils.isEmpty(data)) { return RespBuilder.buildErro(ResponseCode.COUPON_NOT_AVAILABLE, patientsInfo); } /** 验证区域 */ - if(!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) { + if (!validateArea(data.get("area_type").toString(), couponInfo.getCreateHospitalId(), hospitalId)) { return RespBuilder.buildErro(ResponseCode.COUPON_AREA_NO_USE, patientsInfo); } //验证优惠劵是否临时使用了 该功能属于秦皇岛区域 - if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1) - { + if (couponInfo.getTempStatus() != null && couponInfo.getTempStatus() == 1) { //验证临时使用的医院是不是当前登陆的医院 - if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId)) - { + if (StringUtils.isNotEmpty(couponInfo.getTempHospitalId()) && !couponInfo.getTempHospitalId().equals(hospitalId)) { return RespBuilder.buildErro(ResponseCode.COUPON_IS_USED); } } @@ -507,22 +517,22 @@ public class CouponServiceImpl implements CouponService { /** 1=孕妇 2=儿童 3=产妇 */ PersonModel person = mongoTemplate.findById(userId, PersonModel.class); - if(person != null){ - if(person.getType() == 2) { + if (person != null) { + if (person.getType() == 2) { BabyModel baby = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), BabyModel.class); restMap.put("vcCardNo", baby.getVcCardNo()); /** 就诊卡号 */ // restMap.put("cardNo", baby.getCardNo()); /** 证件号 */ restMap.put("cardNo", person.getCardNo()); /** 证件号 */ List list = mongoTemplate.find(Query.query(Criteria.where("cardNo").is(person.getCardNo())).with(new Sort(Sort.Direction.DESC, "created")), Patients.class); - if(CollectionUtils.isNotEmpty(list)) { + if (CollectionUtils.isNotEmpty(list)) { restMap.put("pcerteTypeId", list.get(0).getPcerteTypeId()); /** 证件类型id */ } else { restMap.put("pcerteTypeId", "57e1dd12f0f02e7ca519d6c7"); /** 其他*/ } } else { Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), Patients.class); - if(patients != null) { + if (patients != null) { restMap.put("vcCardNo", patients.getVcCardNo()); /** 就诊卡号 */ restMap.put("cardNo", patients.getCardNo()); /** 证件号 */ restMap.put("pcerteTypeId", patients.getPcerteTypeId()); /** 证件类型id */ @@ -535,11 +545,11 @@ public class CouponServiceImpl implements CouponService { @Override public Map getPatientsInfoByCode(String code) { - if(org.apache.commons.lang.StringUtils.isNotEmpty(code)){ + if (org.apache.commons.lang.StringUtils.isNotEmpty(code)) { Map param = new HashMap<>(); param.put("code", code); List list = couponMapper.findList(param); - if(CollectionUtils.isNotEmpty(list)) { + if (CollectionUtils.isNotEmpty(list)) { return getPatientsInfo(list.get(0).getUserId()); } } @@ -549,9 +559,10 @@ public class CouponServiceImpl implements CouponService { /** * 当删除孕妇或儿童档案时,默认修改该孕妇和儿童下所有的优惠券为已删除的状态 * 操作人为当前登陆人的id - * @param userId 登陆人的id + * + * @param userId 登陆人的id * @param hospitalId 医院id - * @param delUserId 被删除优惠券人的id + * @param delUserId 被删除优惠券人的id */ @Override public void del(String userId, String hospitalId, String delUserId) { @@ -593,23 +604,22 @@ public class CouponServiceImpl implements CouponService { params.put("hId", hId); params.put("dpId", person.getType() == 2 ? "2" : "1"); //调用本地 - if(type == 1) { + if (type == 1) { WeixinQrcodeConfigQuery query = new WeixinQrcodeConfigQuery(); query.setDpId(person.getType() == 2 ? 2 : 1); query.setHospitalId(hId); List weixinQrcodeConfigs = weixinQrcodeConfigService.queryWeixinShowqrcodeConfig(query); - if(CollectionUtils.isNotEmpty(weixinQrcodeConfigs)) { + if (CollectionUtils.isNotEmpty(weixinQrcodeConfigs)) { String url = weixinQrcodeConfigs.get(0).getWxUrl(); return url; - } - else - { + } else { System.out.println("no coupon config ; hospital id = " + hId); } } - try {String s = HttpClientUtil.doGet(PropertiesUtil.getInstance().getDefault("or.code.create.url"), params, "utf-8", null); + try { + String s = HttpClientUtil.doGet(PropertiesUtil.getInstance().getDefault("or.code.create.url"), params, "utf-8", null); JSONObject jsonObject = JSONObject.fromObject(s); return jsonObject.get("url").toString(); } catch (Exception e) { @@ -632,7 +642,7 @@ public class CouponServiceImpl implements CouponService { } @Override - public Map findCouponByCode(Map param) { + public Map findCouponByCode(Map param) { return couponMapper.findCouponByCode(param); } @@ -673,25 +683,27 @@ public class CouponServiceImpl implements CouponService { return couponMapper.queryCouponItemsByType(params); } - /** 1=省 2=市 3=区 4=单医院 */ + /** + * 1=省 2=市 3=区 4=单医院 + */ private boolean validateArea(String areaType, String createHospitalId, String useHospitald) { Organization createHospital = organizationService.getOrganization(Integer.parseInt(createHospitalId)); Organization useHospital = organizationService.getOrganization(Integer.parseInt(useHospitald)); - if(createHospital != null && useHospital != null) { - if("1".equals(areaType)) { - if(StringUtils.isNotBlank(createHospital.getProvinceId())) { + if (createHospital != null && useHospital != null) { + if ("1".equals(areaType)) { + if (StringUtils.isNotBlank(createHospital.getProvinceId())) { return createHospital.getProvinceId().equals(useHospital.getProvinceId()); } - } else if("2".equals(areaType)) { - if(StringUtils.isNotBlank(createHospital.getCityId())) { + } else if ("2".equals(areaType)) { + if (StringUtils.isNotBlank(createHospital.getCityId())) { return createHospital.getCityId().equals(useHospital.getCityId()); } - } else if("3".equals(areaType)) { - if(StringUtils.isNotBlank(createHospital.getAreaId())) { + } else if ("3".equals(areaType)) { + if (StringUtils.isNotBlank(createHospital.getAreaId())) { return createHospital.getAreaId().equals(useHospital.getAreaId()); } - } else if("4".equals(areaType)) { + } else if ("4".equals(areaType)) { return createHospitalId.equals(useHospitald); } } @@ -700,14 +712,15 @@ public class CouponServiceImpl implements CouponService { /** * 判断当前时间是否满足生成规则的时间 - * @param userId 孕妇id - * @param start 真实的开始时间 - * @param end 真实的结束时间 - * @param unitType 时间单位 1=孕周 2=天数 3=月龄 - * @param hospitalId 医院id - * @param couponType 产检券类型 1=孕妇 2=产妇 3=儿童 + * + * @param userId 孕妇id + * @param start 真实的开始时间 + * @param end 真实的结束时间 + * @param unitType 时间单位 1=孕周 2=天数 3=月龄 + * @param hospitalId 医院id + * @param couponType 产检券类型 1=孕妇 2=产妇 3=儿童 * @param validateType 验证类型 1=创建 2=使用 - * @param personType 1=孕妇 2=儿童 3=产妇 + * @param personType 1=孕妇 2=儿童 3=产妇 * @return */ private boolean validateDate(String userId, Integer start, Integer end, Integer unitType, String hospitalId, Integer couponType, Integer validateType, Integer personType) { @@ -715,38 +728,38 @@ public class CouponServiceImpl implements CouponService { Date startDate = null; Date endDate = null; - if(personType == 2) { /** 儿童根据生日对比 */ + if (personType == 2) { /** 儿童根据生日对比 */ BabyModel baby = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), BabyModel.class); midDate = baby.getBirth(); } else { Patients patient = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)), Patients.class); - if(personType == 1 || couponType == 4) { /** 孕妇根据末次月经对比 分娩券按照末次月经对比 */ + if (personType == 1 || couponType == 4) { /** 孕妇根据末次月经对比 分娩券按照末次月经对比 */ midDate = patient.getLastMenses(); - } else if(personType == 3) { /** 产妇根据分娩时间对比 */ + } else if (personType == 3) { /** 产妇根据分娩时间对比 */ midDate = patient.getFmDate(); } else { return false; } } - if(midDate != null) { - if(unitType == 1) { /** 孕周: startDate = lastMenses + start*7、 endDate = lastMenses + end*7 + 6*/ + if (midDate != null) { + if (unitType == 1) { /** 孕周: startDate = lastMenses + start*7、 endDate = lastMenses + end*7 + 6*/ startDate = DateUtils.addDays(midDate, start * 7); endDate = DateUtils.addDays(midDate, end * 7 + 6); - } else if(unitType == 2) { /** 天数 stratDate = 孕妇:fmDate/儿童:birth + start、 endDate = lastMenses + end */ + } else if (unitType == 2) { /** 天数 stratDate = 孕妇:fmDate/儿童:birth + start、 endDate = lastMenses + end */ startDate = DateUtils.addDays(midDate, start); endDate = DateUtils.addDays(midDate, end); - } else if(unitType == 3) { /** 月龄 startDate = fmDate/birth + start、 endDate = fmDate/birth + end + 1 如果是31号 计算出来的月份没有31号 取最后一天*/ + } else if (unitType == 3) { /** 月龄 startDate = fmDate/birth + start、 endDate = fmDate/birth + end + 1 如果是31号 计算出来的月份没有31号 取最后一天*/ startDate = DateUtils.addMonths(midDate, start); endDate = DateUtils.addMonths(midDate, end + 1); } - if(validateType == 2) { /**使用 */ + if (validateType == 2) { /**使用 */ // if(DateUtil.isBetween(new Date(), startDate, endDate)) { - if(DateUtil.isBetween(new Date(), startDate, DateUtils.addDays(endDate, 1))) { + if (DateUtil.isBetween(new Date(), startDate, DateUtils.addDays(endDate, 1))) { return true; } - } else if(validateType == 1) { + } else if (validateType == 1) { return DateUtil.isLtOrEq(new Date(), endDate); } } @@ -754,16 +767,16 @@ public class CouponServiceImpl implements CouponService { } @Override - public BaseObjectResponse findList(String userId, String hospitalId, String url,Integer type) { + public BaseObjectResponse findList(String userId, String hospitalId, String url, Integer type) { Integer year = DateUtil.getCurrentYear(); String peopleNum = null; PlantformConfigModel model = mongoTemplate.findOne(Query.query(Criteria.where("key").is(hospitalId).and("type").is(SequenceConstant.QUEUE_TYPE)), PlantformConfigModel.class); - if(model != null) { + if (model != null) { String value = model.getValue(); - if(StringUtils.isNotEmpty(value)) { + if (StringUtils.isNotEmpty(value)) { Map map = JSON.parseObject(value, Map.class); Integer code = map.get(year); - if(code != null) { + if (code != null) { peopleNum = String.valueOf(year).substring(2) + "-" + code; } } @@ -776,20 +789,18 @@ public class CouponServiceImpl implements CouponService { Map restMap = new HashMap<>(); restMap.put("topName", couponMapper.findTopName(hospitalId)); List> couponInfos = couponMapper.findInfo(param); - for (Map map : couponInfos) { - map.put("url", findUrl(map.get("sequence_id").toString(),type)); - if(StringUtils.isNotEmpty(peopleNum)) { + for (Map map : couponInfos) { + map.put("url", findUrl(map.get("sequence_id").toString(), type)); + if (StringUtils.isNotEmpty(peopleNum)) { map.put("peopleNum", peopleNum); } - map.put("days",0); + map.put("days", 0); //滦平县妇幼保健院2100001377 //滦平县妇幼保健院首次产检券 孕0-12周 改为 孕0-12周+6天 - if ("2100001377".equals(hospitalId)) - { + if ("2100001377".equals(hospitalId)) { Integer show_end = Integer.parseInt(String.valueOf(map.get("show_end"))); - if (show_end == 12) - { - map.put("days",6); + if (show_end == 12) { + map.put("days", 6); } } } 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 a7ac712..e523a5b 100644 --- a/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml +++ b/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml @@ -27,6 +27,10 @@ select * from coupon_info where user_id = #{userId} and sequence_id = #{code} + + @@ -94,6 +98,12 @@ where sequence_id = #{code} + + update coupon_info + set used_id = #{usedId} + where id = #{id} + + update coupon_info set use_date = #{useDate}, operator_use_id = #{operatorUseId}, used_hospital_id = #{hospitalId}, status = #{status} diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java index 2192af6..33d5413 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java @@ -18,7 +18,6 @@ import com.lyms.platform.pojo.PlantformConfigModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; @@ -80,6 +79,16 @@ public class CouponController extends BaseController { } /** + * 处理垃圾数据 + * @return + */ + @RequestMapping(method = RequestMethod.GET, value = "/distErrorData") + @ResponseBody + public BaseObjectResponse distErrorData() { + return couponService.distErrorData(); + } + + /** * 查询用户优惠券 * @param userId * @param hospitalId