Преглед изворни кода

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

humingfen пре 6 година
родитељ
комит
10859acd94
35 измењених фајлова са 2515 додато и 156 уклоњено
  1. 12 0
      common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/AccountDO.java
  2. 221 22
      common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/ActivityDO.java
  3. 115 0
      common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/ActivityRuleDO.java
  4. 70 1
      common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/CreditsDetailDO.java
  5. 79 12
      common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/ExchangeGoodsDO.java
  6. 55 14
      common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/TaskGoodsDO.java
  7. 73 2
      common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/TaskPatientDetailDO.java
  8. 13 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/health/bank/HealthBankMapping.java
  9. 1 1
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/role/RoleEndpoint.java
  10. 14 14
      svr/svr-base/src/main/java/com/yihu/jw/base/service/system/SystemDictService.java
  11. 1 1
      svr/svr-patient/src/main/java/com/yihu/jw/patient/config/SwaggerDocs.java
  12. 19 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/AccountController.java
  13. 187 13
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/ActivityController.java
  14. 64 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/ActivityRuleController.java
  15. 101 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/CreditsDetailController.java
  16. 20 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/ExchangeGoodsController.java
  17. 28 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/TaskPatientDetailController.java
  18. 4 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/AccountDao.java
  19. 9 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/ActivityDao.java
  20. 16 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/ActivityRuleDao.java
  21. 5 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/ExchangeGoodsDao.java
  22. 11 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskDao.java
  23. 17 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskGoodsDao.java
  24. 7 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskPatientDetailDao.java
  25. 3 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskRuleDao.java
  26. 14 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/AccountService.java
  27. 52 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/ActivityRuleService.java
  28. 810 15
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/ActivityService.java
  29. 362 26
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/CreditsDetailService.java
  30. 74 31
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/ExchangeGoodsService.java
  31. 1 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/TaskDetailService.java
  32. 3 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/TaskGoodsService.java
  33. 23 4
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/TaskPatientDtailService.java
  34. 29 0
      svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/util/DateUtils.java
  35. 2 0
      svr/svr-wlyy-health-bank/src/main/resources/application.yml

+ 12 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/AccountDO.java

@ -28,6 +28,9 @@ public class AccountDO extends UuidIdentityEntityWithOperator implements Seriali
    @Column(name = "total")
    private Integer total;//积分总数
    @Column(name = "coupon_total")
    private Long couponTotal;//活动劵总数
    @Column(name = "password")
    private String password;//密码
@ -251,4 +254,13 @@ public class AccountDO extends UuidIdentityEntityWithOperator implements Seriali
    public void setStatus(Integer status) {
        this.status = status;
    }
    @Column(name = "coupon_total")
    public Long getCouponTotal() {
        return couponTotal;
    }
    public void setCouponTotal(Long couponTotal) {
        this.couponTotal = couponTotal;
    }
}

+ 221 - 22
common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/ActivityDO.java

@ -36,13 +36,14 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
    @Column(name = "img")
    private String img;//活动图片
    @Column(name = "start_time")
    @Column(name = "registration_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date startTime;//开始时间
    private Date registrationTime;//报名时间
    @Column(name = "end_time")
    @Column(name = "activity_offline_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date endTime; //结束时间
    private Date activityOfflineTime; //活动下线时间
    @Column(name = "status")
    private Integer status;//状态(1代表有效,0代表无效,-1代表过期)
@ -62,6 +63,49 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
    @Column(name = "type")
    private String type;//活动类型
    @Column(name = "dead_line")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date deadLine;//参与截止时间
    @Column(name = "crowd_type")
    private Integer crowdType;//面向人群
    @Column(name = "recommended")
    private Integer recommended;//是否推荐
    @Column(name = "info")
    private String info;//报名信息
    @Column(name="limit_register")
    private Integer limitRegister;//报名限制 0、所有居民可以报名,1、仅当前居民账号可报名
    @Column(name = "count")
    private Long count;//报名人数
    @Column(name = "globel_template")
    private String globelTemplate;//通用模板
/*
    @Column(name = "del")
    private Integer del;//1有效0无效*/
    @Column(name = "del_flag")
    private Integer delFlag;//1有效0无效
  /*  *//**
     * 通用模板code
     *//*
    private String globelTemplate;*/
    /**
     * 活动发布、上线时间
     */
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
//    private Date releaseTime;
    /**
     * 实用范围名称
     */
    @Column(name = "area_name")
    private String areaName;
    @Transient
    private String patientId;//居民id
@ -78,7 +122,10 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
    private Long total;//参加总数
    @Transient
    private Integer activityRanking;//活动中的排名
    private Integer activityRanking;//活动中的积分的排名
    @Transient
    private Integer activityCouponRanking;//活动中积分劵的排名
    @Transient
    private List<TaskPatientDetailDO> taskPatientDetailDOS;//参与活动详情
@ -89,6 +136,14 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
    @Transient
    private Long sum;//活动积分总数
    @Transient
    private ActivityRuleDO activityRuleDO;//活动规则
    @Transient
    private List<TaskGoodsDO> taskGoodsDOS;//活动奖品
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
@ -97,6 +152,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.saasId = saasId;
    }
    @Column(name = "organizer")
    public String getOrganizer() {
        return organizer;
    }
@ -105,6 +161,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.organizer = organizer;
    }
    @Column(name = "title")
    public String getTitle() {
        return title;
    }
@ -113,6 +170,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.title = title;
    }
    @Column(name = "description")
    public String getDescription() {
        return description;
    }
@ -121,6 +179,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.description = description;
    }
    @Column(name = "location")
    public String getLocation() {
        return location;
    }
@ -129,6 +188,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.location = location;
    }
    @Column(name = "img")
    public String getImg() {
        return img;
    }
@ -137,15 +197,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.img = img;
    }
    public Date getStartTime() {
        return startTime;
    }
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
@ -154,6 +206,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.status = status;
    }
    @Column(name = "is_flag")
    public Integer getIsFlag() {
        return isFlag;
    }
@ -162,6 +215,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.isFlag = isFlag;
    }
    @Column(name = "remark")
    public String getRemark() {
        return remark;
    }
@ -170,14 +224,7 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
        this.remark = remark;
    }
    public Date getEndTime() {
        return endTime;
    }
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
    @Column(name = "area")
    public String getArea() {
        return area;
    }
@ -282,4 +329,156 @@ public class ActivityDO extends UuidIdentityEntityWithOperator implements Serial
    public void setTaskDOS(List<TaskDO> taskDOS) {
        this.taskDOS = taskDOS;
    }
    @Column(name = "registration_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getRegistrationTime() {
        return registrationTime;
    }
    public void setRegistrationTime(Date registrationTime) {
        this.registrationTime = registrationTime;
    }
    @Column(name = "activity_offline_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getActivityOfflineTime() {
        return activityOfflineTime;
    }
    public void setActivityOfflineTime(Date activityOfflineTime) {
        this.activityOfflineTime = activityOfflineTime;
    }
    @Column(name = "dead_line")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getDeadLine() {
        return deadLine;
    }
    public void setDeadLine(Date deadLine) {
        this.deadLine = deadLine;
    }
    @Column(name = "crowd_type")
    public Integer getCrowdType() {
        return crowdType;
    }
    public void setCrowdType(Integer crowdType) {
        this.crowdType = crowdType;
    }
    @Column(name = "recommended")
    public Integer getRecommended() {
        return recommended;
    }
    public void setRecommended(Integer recommended) {
        this.recommended = recommended;
    }
    @Column(name = "info")
    public String getInfo() {
        return info;
    }
    public void setInfo(String info) {
        this.info = info;
    }
    @Column(name = "count")
    public Long getCount() {
        return count;
    }
    public void setCount(Long count) {
        this.count = count;
    }
    @Transient
    public ActivityRuleDO getActivityRuleDO() {
        return activityRuleDO;
    }
    public void setActivityRuleDO(ActivityRuleDO activityRuleDO) {
        this.activityRuleDO = activityRuleDO;
    }
    @Column(name="limit_register")
    public Integer getLimitRegister() {
        return limitRegister;
    }
    public void setLimitRegister(Integer limitRegister) {
        this.limitRegister = limitRegister;
    }
    @Column(name = "del_flag")
    public Integer getDelFlag() {
        return delFlag;
    }
    public void setDelFlag(Integer delFlag) {
        this.delFlag = delFlag;
    }
    @Column(name = "globel_template")
    public String getGlobelTemplate() {
        return globelTemplate;
    }
    public void setGlobelTemplate(String globelTemplate) {
        this.globelTemplate = globelTemplate;
    }
    @Transient
    public Integer getActivityCouponRanking() {
        return activityCouponRanking;
    }
    public void setActivityCouponRanking(Integer activityCouponRanking) {
        this.activityCouponRanking = activityCouponRanking;
    }
    @Transient
    public List<TaskGoodsDO> getTaskGoodsDOS() {
        return taskGoodsDOS;
    }
    public void setTaskGoodsDOS(List<TaskGoodsDO> taskGoodsDOS) {
        this.taskGoodsDOS = taskGoodsDOS;
    }
    @Column(name = "area_name")
    public String getAreaName() {
        return areaName;
    }
    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }
/*
    @Column(name = "del")
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }*/
//    public Date getReleaseTime() {
//        return releaseTime;
//    }
//
//    public void setReleaseTime(Date releaseTime) {
//        this.releaseTime = releaseTime;
//    }
}

+ 115 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/ActivityRuleDO.java

@ -0,0 +1,115 @@
package com.yihu.jw.entity.health.bank;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.List;
/**
 * Created by wzn54 on 2018/12/28.
 */
@Entity
@Table(name = "wlyy_health_bank_activity_rule")
public class ActivityRuleDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "activityId")
    private String activityId;//活动id
    @Column(name = "value1")
    private String value1;//规则1 1、健康竟步 健康积分:type:"","step":""
    @Column(name = "value2")
    private String value2;//规则2 1、健康竟步 "time":"{"registrationTime":"","activityOfflineTime":"","deadLine":"","exchangeTime":""}",
    @Column(name = "value3")
    private String value3;//规则3  1、健康竟步 "exchangeType", "shoppingUrl","exchangeDescription":""
    @Column(name = "value4")
    private String value4;//规则4
    @Column(name = "del_flag")
    private Integer delFlag;//1有效、0无效
    @Transient
    private List<TaskGoodsDO> taskGoodsDOS;
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "activityId")
    public String getActivityId() {
        return activityId;
    }
    public void setActivityId(String activityId) {
        this.activityId = activityId;
    }
    @Column(name = "value1")
    public String getValue1() {
        return value1;
    }
    public void setValue1(String value1) {
        this.value1 = value1;
    }
    @Column(name = "value2")
    public String getValue2() {
        return value2;
    }
    public void setValue2(String value2) {
        this.value2 = value2;
    }
    @Column(name = "value3")
    public String getValue3() {
        return value3;
    }
    public void setValue3(String value3) {
        this.value3 = value3;
    }
    @Column(name = "value4")
    public String getValue4() {
        return value4;
    }
    public void setValue4(String value4) {
        this.value4 = value4;
    }
    @Column(name = "del_flag")
    public Integer getDelFlag() {
        return delFlag;
    }
    public void setDelFlag(Integer delFlag) {
        this.delFlag = delFlag;
    }
    @Transient
    public List<TaskGoodsDO> getTaskGoodsDOS() {
        return taskGoodsDOS;
    }
    public void setTaskGoodsDOS(List<TaskGoodsDO> taskGoodsDOS) {
        this.taskGoodsDOS = taskGoodsDOS;
    }
}

+ 70 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/CreditsDetailDO.java

@ -27,6 +27,9 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
    @Column(name="integrate")
    private Integer integrate;//积分
    @Column(name = "coupon")
    private Integer coupon;//活动劵
    @Column(name = "status")
    private Integer status;//状态(有效/无效)
@ -81,8 +84,18 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
    @Transient
    private String weekTimes;//一周的日期
    @Transient
    private Long ActivityRanking;//活动排名
    @Transient
    private Integer mark;//1活动劵,2积分
    @Transient
    private ExchangeGoodsDO exchangeGoodsDO;//兑换商品
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
@ -90,7 +103,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "integrate")
    public Integer getIntegrate() {
        return integrate;
    }
@ -99,6 +112,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.integrate = integrate;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
@ -107,6 +121,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.status = status;
    }
    @Column(name = "account_id")
    public String getAccountId() {
        return accountId;
    }
@ -115,6 +130,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.accountId = accountId;
    }
    @Column(name = "patient_id")
    public String getPatientId() {
        return patientId;
    }
@ -123,6 +139,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.patientId = patientId;
    }
    @Column(name = "hospital")
    public String getHospital() {
        return hospital;
    }
@ -131,6 +148,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.hospital = hospital;
    }
    @Column(name = "trade_direction")
    public Integer getTradeDirection() {
        return tradeDirection;
    }
@ -139,6 +157,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.tradeDirection = tradeDirection;
    }
    @Column(name = "transaction_id")
    public String getTransactionId() {
        return transactionId;
    }
@ -147,6 +166,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.transactionId = transactionId;
    }
    @Column(name = "trade_type")
    public String getTradeType() {
        return tradeType;
    }
@ -155,6 +175,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.tradeType = tradeType;
    }
    @Transient
    public TaskDO getTaskDO() {
        return taskDO;
    }
@ -163,6 +184,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.taskDO = taskDO;
    }
    @Transient
    public ActivityDO getActivityDO() {
        return activityDO;
    }
@ -171,6 +193,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.activityDO = activityDO;
    }
    @Transient
    public String getFlag() {
        return flag;
    }
@ -179,6 +202,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.flag = flag;
    }
    @Transient
    public Integer getTotal() {
        return total;
    }
@ -187,6 +211,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.total = total;
    }
    @Transient
    public String getName() {
        return name;
    }
@ -195,6 +220,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.name = name;
    }
    @Transient
    public String getIdCard() {
        return idCard;
    }
@ -203,6 +229,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.idCard = idCard;
    }
    @Transient
    public String getOpenId() {
        return openId;
    }
@ -211,6 +238,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.openId = openId;
    }
    @Column(name = "description")
    public String getDescription() {
        return description;
    }
@ -219,6 +247,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.description = description;
    }
    @Transient
    public Long getStepNumber() {
        return stepNumber;
    }
@ -227,6 +256,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.stepNumber = stepNumber;
    }
    @Transient
    public String getActivityId() {
        return activityId;
    }
@ -235,6 +265,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.activityId = activityId;
    }
    @Transient
    public String getUnionId() {
        return unionId;
    }
@ -243,6 +274,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.unionId = unionId;
    }
    @Transient
    public String getHospitalName() {
        return hospitalName;
    }
@ -251,6 +283,7 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
        this.hospitalName = hospitalName;
    }
    @Transient
    public String getWeekTimes() {
        return weekTimes;
    }
@ -258,4 +291,40 @@ public class CreditsDetailDO extends UuidIdentityEntityWithOperator implements S
    public void setWeekTimes(String weekTimes) {
        this.weekTimes = weekTimes;
    }
    @Column(name = "coupon")
    public Integer getCoupon() {
        return coupon;
    }
    public void setCoupon(Integer coupon) {
        this.coupon = coupon;
    }
    @Transient
    public Long getActivityRanking() {
        return ActivityRanking;
    }
    public void setActivityRanking(Long activityRanking) {
        ActivityRanking = activityRanking;
    }
    @Transient
    public Integer getMark() {
        return mark;
    }
    public void setMark(Integer mark) {
        this.mark = mark;
    }
    @Transient
    public ExchangeGoodsDO getExchangeGoodsDO() {
        return exchangeGoodsDO;
    }
    public void setExchangeGoodsDO(ExchangeGoodsDO exchangeGoodsDO) {
        this.exchangeGoodsDO = exchangeGoodsDO;
    }
}

+ 79 - 12
common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/ExchangeGoodsDO.java

@ -3,6 +3,7 @@ package com.yihu.jw.entity.health.bank;/**
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javafx.concurrent.Task;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -22,19 +23,35 @@ public class ExchangeGoodsDO extends UuidIdentityEntityWithOperator implements S
    @Column(name = "saas_id")
    private String saasId;//saasid
    @Column(name = "goods_id")
    private String goodsId;//商品id
    @Column(name = "activity_goods_id")
    private String activityGoodsId;//商品id
    @Column(name = "integrate")
    private String integrate;//积分
    private Integer integrate;//积分
    @Column(name = "patient_id")
    private String patientId;//居民id
    @Column(name = "status")
    private Integer status;//状态
    @Column(name = "coupon")
    private Integer coupon;//活动劵
    @Transient
    private GoodsDO goodsDO;//商品对象
    @Transient
    private String hospital;
    @Transient
    private String hospitalName;
    @Transient
    private TaskGoodsDO taskGoodsDO;
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
@ -43,22 +60,17 @@ public class ExchangeGoodsDO extends UuidIdentityEntityWithOperator implements S
        this.saasId = saasId;
    }
    public String getGoodsId() {
        return goodsId;
    }
    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }
    public String getIntegrate() {
    @Column(name = "integrate")
    public Integer getIntegrate() {
        return integrate;
    }
    public void setIntegrate(String integrate) {
    public void setIntegrate(Integer integrate) {
        this.integrate = integrate;
    }
    @Column(name = "patient_id")
    public String getPatientId() {
        return patientId;
    }
@ -67,6 +79,7 @@ public class ExchangeGoodsDO extends UuidIdentityEntityWithOperator implements S
        this.patientId = patientId;
    }
    @Transient
    public GoodsDO getGoodsDO() {
        return goodsDO;
    }
@ -74,4 +87,58 @@ public class ExchangeGoodsDO extends UuidIdentityEntityWithOperator implements S
    public void setGoodsDO(GoodsDO goodsDO) {
        this.goodsDO = goodsDO;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    @Column(name = "activity_goods_id")
    public String getActivityGoodsId() {
        return activityGoodsId;
    }
    public void setActivityGoodsId(String activityGoodsId) {
        this.activityGoodsId = activityGoodsId;
    }
    @Column(name = "coupon")
    public Integer getCoupon() {
        return coupon;
    }
    public void setCoupon(Integer coupon) {
        this.coupon = coupon;
    }
    @Transient
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    @Transient
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    @Transient
    public TaskGoodsDO getTaskGoodsDO() {
        return taskGoodsDO;
    }
    public void setTaskGoodsDO(TaskGoodsDO taskGoodsDO) {
        this.taskGoodsDO = taskGoodsDO;
    }
}

+ 55 - 14
common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/TaskGoodsDO.java

@ -3,10 +3,12 @@ package com.yihu.jw.entity.health.bank;/**
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import org.hibernate.annotations.ColumnTransformer;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
/**
@ -15,14 +17,14 @@ import java.io.Serializable;
 * @desc 活动商品
 **/
@Entity
@Table(name = "wlyy_health_bank_task_goods")
@Table(name = "wlyy_health_bank_activity_goods")
public class TaskGoodsDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;//环境id
    @Column(name = "task_id")
    private String taskId;//任务id
    @Column(name = "activity_id")
    private String activityId;//任务id
    @Column(name = "img")
    private String img;//商品图片
@ -31,8 +33,18 @@ public class TaskGoodsDO extends UuidIdentityEntityWithOperator implements Seria
    private String name;//商品名称
    @Column(name = "integrate")
    private int integrate;//积分
    private Integer integrate;//积分
    @Column(name = "coupon")
    private Integer coupon;//活动劵
    @Column(name = "status")
    private Integer status;//状态(1:充足,-1:库存不足)
    @Transient
    private ExchangeGoodsDO exchangeGoodsDO;//兑换商品
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
@ -41,14 +53,7 @@ public class TaskGoodsDO extends UuidIdentityEntityWithOperator implements Seria
        this.saasId = saasId;
    }
    public String getTaskId() {
        return taskId;
    }
    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }
    @Column(name = "img")
    public String getImg() {
        return img;
    }
@ -65,11 +70,47 @@ public class TaskGoodsDO extends UuidIdentityEntityWithOperator implements Seria
        this.name = name;
    }
    public int getIntegrate() {
    public Integer getIntegrate() {
        return integrate;
    }
    public void setIntegrate(int integrate) {
    public void setIntegrate(Integer integrate) {
        this.integrate = integrate;
    }
    @Column(name = "activity_id")
    public String getActivityId() {
        return activityId;
    }
    public void setActivityId(String activityId) {
        this.activityId = activityId;
    }
    @Column(name = "coupon")
    public int getCoupon() {
        return coupon;
    }
    public void setCoupon(Integer coupon) {
        this.coupon = coupon;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    @Transient
    public ExchangeGoodsDO getExchangeGoodsDO() {
        return exchangeGoodsDO;
    }
    public void setExchangeGoodsDO(ExchangeGoodsDO exchangeGoodsDO) {
        this.exchangeGoodsDO = exchangeGoodsDO;
    }
}

+ 73 - 2
common/common-entity/src/main/java/com/yihu/jw/entity/health/bank/TaskPatientDetailDO.java

@ -7,6 +7,7 @@ import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.List;
/**
 * Created by wamg zhinan 2018/4/27.
@ -42,9 +43,18 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
    @Column(name = "total")
    private Long total;//活动中获取的积分
    @Column(name = "coupon_total")
    private Long couponTotal;//活动劵总数
    @Column(name = "union_id")
    private String unionId;
    @Column(name = "hospital")
    private String hospital;
    @Column(name = "street")
    private String street;
    @Transient
    private AccountDO accountDO;//账户信息
@ -57,12 +67,19 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
    @Transient
    private String name;//居民名称
    @Transient
    private String hospital;//社区
    @Transient
    private String hospitalName;//社区名称
    @Transient
    private String timeSeparated;//至今多久
    @Transient
    private List<ExchangeGoodsDO> exchangeGoodsDO;//兑换商品
    @Transient
    private ActivityDO activityDO ;//活动实体
    public String getSaasId() {
        return saasId;
    }
@ -135,6 +152,7 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.total = total;
    }
    @Transient
    public AccountDO getAccountDO() {
        return accountDO;
    }
@ -151,6 +169,7 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.unionId = unionId;
    }
    @Transient
    public Integer getIsFlag() {
        return isFlag;
    }
@ -159,6 +178,7 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.isFlag = isFlag;
    }
    @Transient
    public String getTaskCode() {
        return taskCode;
    }
@ -167,6 +187,7 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.taskCode = taskCode;
    }
    @Transient
    public String getName() {
        return name;
    }
@ -175,6 +196,7 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.name = name;
    }
    @Column(name = "hospital")
    public String getHospital() {
        return hospital;
    }
@ -183,6 +205,7 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.hospital = hospital;
    }
    @Transient
    public String getHospitalName() {
        return hospitalName;
    }
@ -190,4 +213,52 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    @Column(name = "coupon_total")
    public Long getCouponTotal() {
        return couponTotal;
    }
    public void setCouponTotal(Long couponTotal) {
        this.couponTotal = couponTotal;
    }
    @Transient
    public String getTimeSeparated() {
        return timeSeparated;
    }
    public void setTimeSeparated(String timeSeparated) {
        this.timeSeparated = timeSeparated;
    }
    @Column(name = "street")
    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    @Transient
    public List<ExchangeGoodsDO> getExchangeGoodsDO() {
        return exchangeGoodsDO;
    }
    public void setExchangeGoodsDO(List<ExchangeGoodsDO> exchangeGoodsDO) {
        this.exchangeGoodsDO = exchangeGoodsDO;
    }
    @Transient
    public ActivityDO getActivityDO() {
        return activityDO;
    }
    public void setActivityDO(ActivityDO activityDO) {
        this.activityDO = activityDO;
    }
}

+ 13 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/health/bank/HealthBankMapping.java

@ -38,8 +38,13 @@ public class HealthBankMapping {
        public static final String selectByPatient = "/selectByPatient";
        public static final String createActivity="/createActivity";
        public static final String findActivity="/findActivity";
        public static final String pageActivity="/pageActivity";
        public static final String updateActivity="/updateActivity";
        public static final String editActivity="/editActivity";
        public static final String findActivityById="/findActivityById";
        public static final String findActivityByType="/findActivityByType";
        public static final String batchActivity = "/batchActivity";
        public static final String daleteActivity = "/daleteActivity";
        public static final String createActivityInfo ="/createActivityInfo";
        public static final String findActivityInfo = "/findActivityInfo";
        public static final String updateActivityInfo ="/updateActivityInfo";
@ -60,5 +65,13 @@ public class HealthBankMapping {
        public static final String addStepIntegrate = "/addStepIntegrate";
        public static final String weekReward = "/weekReward";
        public static final String selectByDate = "/selectByDate";
        public static final String doctorDescreaseIntegrate = "/doctorDescreaseIntegrate";
        public static final String selectAccountByPatient="/selectAccountByPatient";
        public static final String selectByActivityRule = "/selectByActivityRule";
        public static final String patientGetInteger = "/patientGetInteger";
        public static final String selectActivityRanking = "/selectActivityRanking";
        public static final String selectByPatientAndDate = "/selectByPatientAndDate";
        public static final String selectTaskAndPatients = "/selectTaskAndPatients";
        public static final String shareIntegrate = "/shareIntegrate";
    }
}

+ 1 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/role/RoleEndpoint.java

@ -103,7 +103,7 @@ public class RoleEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<RoleDO> roleDOS = roleService.search(fields, filters, sorts, page, size);
        List<RoleDO> roleDOS = roleService.search(fields, filters, "-status,-updateTime", page, size);
        int count = (int)roleService.getCount(filters);
        return success(roleDOS, count, page, size, RoleVO.class);
    }

+ 14 - 14
svr/svr-base/src/main/java/com/yihu/jw/base/service/system/SystemDictService.java

@ -76,23 +76,23 @@ public class SystemDictService extends BaseJpaService<SystemDictDO, SystemDictDa
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        if (SystemDictEnum.Icd10Dict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictIcd10Service.queryAll(saasId, creatPage(page, size, sorts));
            jsonObject = dictIcd10Service.queryAll(saasId, createPage(page, size, sorts));
        } else if (SystemDictEnum.HospitalDeptDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictHospitalDeptService.queryAll(saasId, creatPage(page, size, sorts));
            jsonObject = dictHospitalDeptService.queryAll(saasId, createPage(page, size, sorts));
        } else if (SystemDictEnum.JobTitleDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictJobTitleService.queryAll(saasId, creatPage(page, size, sorts));
            jsonObject = dictJobTitleService.queryAll(saasId, createPage(page, size, sorts));
        } else if (SystemDictEnum.HealthProblemDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictHealthProblemService.queryAll(saasId, creatPage(page, size, sorts));
            jsonObject = dictHealthProblemService.queryAll(saasId, createPage(page, size, sorts));
        } else if (SystemDictEnum.MedicineDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictMedicineService.queryAll(saasId, creatPage(page, size, sorts));
            jsonObject = dictMedicineService.queryAll(saasId, createPage(page, size, sorts));
        } else if (SystemDictEnum.DiseaseDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictDiseaseService.queryAll(saasId, creatPage(page, size, sorts));
            jsonObject = dictDiseaseService.queryAll(saasId, createPage(page, size, sorts));
        } else {
            jsonObject = this.queryAll(saasId, creatPage(page, size, sorts));
            jsonObject = this.queryAll(saasId, createPage(page, size, sorts));
        }
        jsonArray.add(jsonObject);
        return jsonArray;
@ -123,23 +123,23 @@ public class SystemDictService extends BaseJpaService<SystemDictDO, SystemDictDa
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        if (SystemDictEnum.Icd10Dict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictIcd10Service.queryAll(userId, creatPage(page, size, sorts));
            jsonObject = dictIcd10Service.queryAll(userId, createPage(page, size, sorts));
        } else if (SystemDictEnum.HospitalDeptDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictHospitalDeptService.queryAll("", creatPage(page, size, sorts));
            jsonObject = dictHospitalDeptService.queryAll("", createPage(page, size, sorts));
        } else if (SystemDictEnum.JobTitleDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictJobTitleService.queryAll("", creatPage(page, size, sorts));
            jsonObject = dictJobTitleService.queryAll("", createPage(page, size, sorts));
        } else if (SystemDictEnum.HealthProblemDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictHealthProblemService.queryAll("", creatPage(page, size, sorts));
            jsonObject = dictHealthProblemService.queryAll("", createPage(page, size, sorts));
        } else if (SystemDictEnum.MedicineDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictMedicineService.queryAll("", creatPage(page, size, sorts));
            jsonObject = dictMedicineService.queryAll("", createPage(page, size, sorts));
        } else if (SystemDictEnum.DiseaseDict == SystemDictEnum.valueOf(type)) {
            jsonObject = dictDiseaseService.queryAll("", creatPage(page, size, sorts));
            jsonObject = dictDiseaseService.queryAll("", createPage(page, size, sorts));
        } else {
            jsonObject = this.queryAll("", creatPage(page, size, sorts));
            jsonObject = this.queryAll("", createPage(page, size, sorts));
        }
        jsonArray.add(jsonObject);
        return jsonArray;

+ 1 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/config/SwaggerDocs.java

@ -12,7 +12,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
/**
 * Created by lith on 2018/11/23.
 * Created by lith on 2018/11/23
 */
public class SwaggerDocs {
    public static void main(String[] args) throws Exception {

+ 19 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/AccountController.java

@ -159,4 +159,23 @@ public class AccountController extends EnvelopRestEndpoint {
        }
    }
    /**
     * 根据居民id获取银行账户信息
     *
     * @param patientId
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.selectAccountByPatient)
    @ApiOperation(value = "根据id获取居民账户")
    public MixEnvelop<AccountDO, AccountDO> selectByPatient(@ApiParam(name = "patientId",value = "居民id")
                                                                   @RequestParam(value = "patientId",required = true)String patientId){
        try {
            return service.selectByPatient(patientId);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 187 - 13
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/ActivityController.java

@ -3,22 +3,27 @@ package com.yihu.jw.controller;/**
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.yihu.jw.entity.health.bank.ActivityDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.service.ActivityService;
import com.yihu.jw.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -46,13 +51,19 @@ public class ActivityController extends EnvelopRestEndpoint {
    @PostMapping(value = HealthBankMapping.healthBank.createActivity)
    @ApiOperation(value = "发布活动")
    public MixEnvelop<Boolean, Boolean> publishActivity(@ApiParam(name = "activity",value = "健康活动JSON")
                                          @RequestParam(value = "activity",required = true)String activity){
                                          @RequestParam(value = "activity",required = true)String activity,
                                                        @ApiParam(name = "value1",value = "积分JSON")
                                                        @RequestParam(value = "value1",required = false)String value1,
                                                        @ApiParam(name = "value2",value = "时间规则")
                                                            @RequestParam(value = "value2",required = false)String value2,
                                                        @ApiParam(name = "value3",value = "兑奖规则")
                                                            @RequestParam(value = "value3",required = false)String value3){
        try {
            ActivityDO activityDO = toEntity(activity,ActivityDO.class);
            return service.insert(activityDO);
            return service.insert(activityDO,value1,value2,value3);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
//            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
@ -91,13 +102,19 @@ public class ActivityController extends EnvelopRestEndpoint {
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
    @ApiOperation(value = "下架活动")
    public MixEnvelop<Boolean, Boolean> outActivity(@ApiParam(name = "activity",value = "健康活动JSON")
                                            @RequestParam(value = "activity",required = true)String activity){
    @ApiOperation(value = "编辑活动")
    public MixEnvelop<Boolean, Boolean> outActivity(@ApiParam(name = "activity", value = "健康活动JSON")
                                                    @RequestParam(value = "activity", required = true) String activity,
                                                    @ApiParam(name = "value1", value = "活动币JSON")
                                                    @RequestParam(value = "value1", required = false) String value1,
                                                    @ApiParam(name = "value2", value = "活动时间")
                                                    @RequestParam(value = "value2", required = false) String value2,
                                                    @ApiParam(name = "value3", value = "兑奖设置")
                                                    @RequestParam(value = "value3", required = false) String value3) {
        try {
            ActivityDO activityDO = toEntity(activity,ActivityDO.class);
            return service.update(activityDO);
        }catch (Exception e){
            ActivityDO activityDO = toEntity(activity, ActivityDO.class);
            return service.update(activityDO,value1,value2,value3);
        } catch (Exception e) {
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
@ -159,4 +176,161 @@ public class ActivityController extends EnvelopRestEndpoint {
    }
    /**
     * 获取活动排行
     *
     * @param activityId
     * @param patient
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.selectActivityRanking)
    @ApiOperation(value = "获取活动排行")
    public MixEnvelop<JSONObject, JSONObject> selectActivityRanking(@ApiParam(name="activityId",value = "活动id")
                                                                        @RequestParam(value = "activityId",required = false)String activityId,
                                                                    @ApiParam(name="patient",value = "居民id")
                                                                        @RequestParam(value = "patient",required = false)String patient,
                                                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                                                        @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                                                        @RequestParam(value = "size", required = false)Integer size,
                                                                    @ApiParam(name="street",value = "街道")
                                                                        @RequestParam(value = "street",required = false)String street,
                                                                    @ApiParam(name="town",value = "区")
                                                                        @RequestParam(value = "town",required = false)String town){
        try{
            return service.selectActivityRanking(activityId,patient,page,size,street,town);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 删除数据
     *
     * @param id 活动id
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.daleteActivity)
    @ApiOperation(value = "删除活动")
    public MixEnvelop<Boolean, Boolean> daleteActivity(@ApiParam(name="id",value = "id集合")
                                                    @RequestParam(value = "id",required = false)String id){
        try{
            MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
            service.daleteActivity(id);
            envelop.setObj(true);
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 编辑活动:上下线、推荐
     *
     * @param id
     * @param type
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.editActivity)
    @ApiOperation(value = "编辑活动:上下线、推荐")
    public ObjEnvelop<ActivityDO> editActivity(
            @ApiParam(name = "id", value = "活动id")
            @RequestParam(value = "id", required = true) String id,
            @ApiParam(name = "type", value = "操作类型:上线:0,下线:2,推荐:3,取消推荐:4")
            @RequestParam(value = "type", required = true) String type) {
        try {
            ActivityDO activityDO=service.editActivity(id, type);
            return  ObjEnvelop.getSuccess("操作成功!",activityDO);
        } catch (Exception e) {
            e.printStackTrace();
//            tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 编辑活动:上下线、推荐
     *
     * @param id
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.findActivityById)
    @ApiOperation(value = "根据id获取活动详情+活动规则")
    public ObjEnvelop<JSONObject> findActivityById(
            @ApiParam(name = "id", value = "活动id")
            @RequestParam(value = "id", required = true) String id) {
        try {
            JSONObject activityDO=service.findActivityById(id);
            return  ObjEnvelop.getSuccess("获取成功!",activityDO);
        } catch (Exception e) {
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError("获取失败!"+e.getMessage());
        }
    }
    @PostMapping(value = HealthBankMapping.healthBank.pageActivity)
    @ApiOperation(value = "分页查询活动")
    public PageEnvelop<ActivityDO> pageActivity(@ApiParam(name = "type", value = "活动类型")
                                                @RequestParam(value = "type", required = false) String type,
                                                @ApiParam(name = "status", value = "活动状态:1上线,2下线")
                                                @RequestParam(value = "status", required = false) String status,
                                                @ApiParam(name = "crowdType", value = "人群类型:1:签约居民、2平台用户")
                                                @RequestParam(value = "crowdType", required = false) String crowdType,
                                                @ApiParam(name = "releaseTime", value = "下线开始时间")
                                                @RequestParam(value = "releaseTime", required = false) String releaseTime,
                                                @ApiParam(name = "activityOfflineTime", value = "下线结束时间")
                                                @RequestParam(value = "activityOfflineTime", required = false) String activityOfflineTime,
                                                @ApiParam(name = "filter", value = "活动名、发布机构、面向范围名称")
                                                @RequestParam(value = "filter", required = false) String filter,
                                                @ApiParam(name = "page", value = "第几页,从1开始")
                                                @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                                                @ApiParam(name = "size", defaultValue = "10", value = ",每页分页大小")
                                                @RequestParam(value = "size", required = false) Integer size) {
        try{
            JSONObject obj = service.ListActivityDO(type, status,crowdType,releaseTime,activityOfflineTime,filter,page,size);
//            int count = (int) service.getCount(stringBuffer.toString());
            List<ActivityDO> list=(List<ActivityDO>)obj.get("activityDOList");
            int count =obj.getInteger("count");
            return success(list, count, page, size);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return PageEnvelop.getError("获取失败"+e.getMessage(),-1);
        }
    }
    /**
     * 编辑活动:上下线、推荐
     *
     * @param type
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.findActivityByType)
    @ApiOperation(value = "获取是否存在在线的竞走活动")
    public ObjEnvelop<Boolean> findActivityByType(
            @ApiParam(name = "type", value = "活动类型")
            @RequestParam(value = "type", required = true) String type) {
        try {
            JSONObject obj=service.findActivityByType(type);
            return  ObjEnvelop.getSuccess("获取成功!",obj);
        } catch (Exception e) {
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError("获取失败!"+e.getMessage());
        }
    }
}

+ 64 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/ActivityRuleController.java

@ -0,0 +1,64 @@
package com.yihu.jw.controller;/**
 * Created by nature of king on 2018/4/27.
 */
import com.alibaba.fastjson.JSONArray;
import com.yihu.jw.entity.health.bank.ActivityDO;
import com.yihu.jw.entity.health.bank.ActivityRuleDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.service.ActivityRuleService;
import com.yihu.jw.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-04-27 14:14
 * @desc 健康活动
 **/
@RestController
@RequestMapping(HealthBankMapping.api_health_bank_common)
@Api(tags = "健康活动规则相关操作",description = "健康活动规则相关操作")
public class ActivityRuleController extends EnvelopRestEndpoint {
    @Autowired
    private ActivityRuleService ruleservice;
    @Autowired
    private Tracer tracer;
    /**
     *  publish activity
     *
     * @param activityId
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.selectByActivityRule)
    @ApiOperation(value = "获取规则")
    public MixEnvelop<ActivityRuleDO, ActivityRuleDO> publishActivity(@ApiParam(name = "activityId",value = "活动id")
                                          @RequestParam(value = "activityId",required = true)String activityId){
        try {
            return ruleservice.selectByActivityId(activityId);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 101 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/CreditsDetailController.java

@ -246,4 +246,105 @@ public class CreditsDetailController extends EnvelopRestEndpoint {
    }
    /**
     * 医生手动减积分
     * @param ruleId
     * @param patientId
     * @param hospital
     * @param hospitalName
     * @param integrate
     * @param reason
     * @param doctorId
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.doctorDescreaseIntegrate)
    @ApiOperation(value = "医生手动减积分")
    public MixEnvelop<Boolean, Boolean> doctorDescreaseIntegrate(@ApiParam(name = "ruleId",value = "规则id")
                                                                     @RequestParam(value = "ruleId",required = false)String ruleId,
                                                                 @ApiParam(name = "patientId",value = "居民id")
                                                                 @RequestParam(value = "patientId",required = false)String patientId,
                                                                 @ApiParam(name = "hospital",value = "机构code")
                                                                     @RequestParam(value = "hospital",required = false)String hospital,
                                                                 @ApiParam(name = "hospitalName",value = "机构名称")
                                                                     @RequestParam(value = "hospitalName",required = false)String hospitalName,
                                                                 @ApiParam(name = "integrate",value = "扣减的积分")
                                                                     @RequestParam(value = "integrate",required = false)Integer integrate,
                                                                 @ApiParam(name = "reason",value = "扣减的原因")
                                                                     @RequestParam(value = "reason",required = false)String reason,
                                                                 @ApiParam(name = "doctorId",value = "医生code")
                                                                     @RequestParam(value = "doctorId",required = false)String doctorId){
        try {
            return service.doctorDescreaseIntegrate(ruleId,patientId,doctorId,hospital,hospitalName,integrate,reason);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 居民获取积分
     *
     * @param creditsDetail
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.patientGetInteger)
    @ApiOperation(value = "居民获取积分")
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> patientGetInteger(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
                                                               @RequestParam(value = "creditsDetail",required = true)String creditsDetail){
        try {
            CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
            return service.patientGetInteger(creditsDetailDO);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 获取当日积分
     *
     * @param patient
     * @param transactionId
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.selectByPatientAndDate)
    @ApiOperation(value = "健康问答--获取当日积分")
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> patientGetInteger(@ApiParam(name = "patient",value = "居民code")
                                                                          @RequestParam(value = "patient",required = true)String patient,
                                                                          @ApiParam(name = "transactionId",value = "任务id")
                                                                          @RequestParam(value = "transactionId",required = true)String transactionId){
        try {
            return service.selectByDate(patient,transactionId);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 分享获取积分
     * @param creditsDetail
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.shareIntegrate)
    @ApiOperation(value = "分享获取积分")
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> shareIntegrate(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
                                                                   @RequestParam(value = "creditsDetail",required = true)String creditsDetail){
        try {
            CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
            return service.shareIntegrate(creditsDetailDO);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 20 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/ExchangeGoodsController.java

@ -59,6 +59,26 @@ public class ExchangeGoodsController extends EnvelopRestEndpoint {
        }
    }
    /**
     *
     * @param exchangeGoods
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.exchangeGoods)
    @ApiOperation(value = "兑换奖品")
    public MixEnvelop<ExchangeGoodsDO, ExchangeGoodsDO> exchangeGoods(@ApiParam(name = "exchangeGoods",value = "兑换商品JSON")
                                                                         @RequestParam(value = "exchangeGoods",required = false)String exchangeGoods){
        try{
            ExchangeGoodsDO exchangeGoodsDO = toEntity(exchangeGoods,ExchangeGoodsDO.class);
            return service.insert(exchangeGoodsDO);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
   /* *//**
     * exchange goods
     *

+ 28 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/TaskPatientDetailController.java

@ -10,6 +10,8 @@ import com.yihu.jw.service.TaskPatientDtailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.apache.catalina.LifecycleState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.web.bind.annotation.PostMapping;
@ -17,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-06-11 10:37
@ -52,5 +56,29 @@ public class TaskPatientDetailController extends EnvelopRestEndpoint {
        }
    }
    /**
     *
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = HealthBankMapping.healthBank.selectTaskAndPatients)
    @ApiOperation(value = "获取居民活动")
    public MixEnvelop<TaskPatientDetailDO,TaskPatientDetailDO> select(@ApiParam(name = "page", value = "第几页,从1开始")
                                                                      @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                                                      @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                                                      @RequestParam(value = "size", required = false)Integer size){
        MixEnvelop<TaskPatientDetailDO,TaskPatientDetailDO> envelop =new MixEnvelop<>();
        try {
            List<TaskPatientDetailDO> taskPatientDetailDOS = service.select(page,size);
            envelop.setDetailModelList(taskPatientDetailDOS);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
        return envelop;
    }
}

+ 4 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/AccountDao.java

@ -3,7 +3,9 @@ package com.yihu.jw.dao;/**
 */
import com.yihu.jw.entity.health.bank.AccountDO;
import com.yihu.jw.entity.health.bank.ActivityRuleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
@ -12,4 +14,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 * @desc health bank account dao
 **/
public interface AccountDao extends PagingAndSortingRepository<AccountDO,String>,JpaSpecificationExecutor<AccountDO> {
    @Query("select t from AccountDO t where t.patientId=?1 and t.status=1")
    AccountDO selectByPatientId(String patientId);
}

+ 9 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/ActivityDao.java

@ -1,11 +1,20 @@
package com.yihu.jw.dao;
import com.yihu.jw.entity.health.bank.ActivityDO;
import com.yihu.jw.entity.health.bank.ActivityRuleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by wang zhinan on 2018/4/27.
 */
public interface ActivityDao extends PagingAndSortingRepository<ActivityDO,String>,JpaSpecificationExecutor<ActivityDO> {
    @Query("select t from ActivityDO t where t.id=?1")
    ActivityDO selectById(String id);
    @Query("select t from ActivityDO t where t.type=?1 and (t.status=0 or t.status=1) and t.delFlag=1")
    List<ActivityDO> findByIdAndType(String type);
}

+ 16 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/ActivityRuleDao.java

@ -0,0 +1,16 @@
package com.yihu.jw.dao;
import com.yihu.jw.entity.health.bank.ActivityDO;
import com.yihu.jw.entity.health.bank.ActivityRuleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by wang zhinan on 2018/4/27.
 */
public interface ActivityRuleDao extends PagingAndSortingRepository<ActivityRuleDO,String>,JpaSpecificationExecutor<ActivityRuleDO> {
    @Query("select t from ActivityRuleDO t where t.activityId=?1")
    ActivityRuleDO selectByActivityId(String activityId);
}

+ 5 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/ExchangeGoodsDao.java

@ -3,7 +3,9 @@ package com.yihu.jw.dao;/**
 */
import com.yihu.jw.entity.health.bank.ExchangeGoodsDO;
import com.yihu.jw.entity.health.bank.TaskDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
@ -12,4 +14,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 * @desc exchange goods dao
 **/
public interface ExchangeGoodsDao extends PagingAndSortingRepository<ExchangeGoodsDO,String>,JpaSpecificationExecutor<ExchangeGoodsDO> {
    @Query("select t from ExchangeGoodsDO t where t.activityGoodsId = ?1 and t.patientId = ?2")
    ExchangeGoodsDO selectByActivityGoodsIdAndPatientId(String activityGoodsId,String patientId);
}

+ 11 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskDao.java

@ -4,9 +4,11 @@ package com.yihu.jw.dao;/**
import com.yihu.jw.entity.health.bank.TaskDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import javax.print.DocFlavor;
import java.util.List;
/**
@ -20,4 +22,13 @@ public interface TaskDao extends PagingAndSortingRepository<TaskDO,String>,JpaSp
    @Query("select t from TaskDO t where t.transactionId = ?1 and t.type='RULE_TASK'")
    TaskDO selectByTaskRuleId(String transactionId);
    @Query("select t from TaskDO t where t.id = ?1 ")
    TaskDO selectById(String id);
    @Modifying
    @Query("delete from TaskDO t where t.transactionId=?1")
    void deleteByTransactionId(String transactionId);
}

+ 17 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskGoodsDao.java

@ -2,14 +2,31 @@ package com.yihu.jw.dao;/**
 * Created by nature of king on 2018/6/8.
 */
import com.yihu.jw.entity.health.bank.ActivityDO;
import com.yihu.jw.entity.health.bank.TaskGoodsDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-06-08 15:28
 * @desc 商品 dao
 **/
public interface TaskGoodsDao extends PagingAndSortingRepository<TaskGoodsDO,String>,JpaSpecificationExecutor<TaskGoodsDO> {
    @Query("select t from TaskGoodsDO t where t.activityId=?1")
    List<TaskGoodsDO> selectByActivityId(String activityId);
    @Query("select t from TaskGoodsDO t where t.id=?1")
    TaskGoodsDO selectById(String di);
    @Modifying
    @Query("delete from TaskGoodsDO tg  where tg.activityId=?1")
    void deleteByActivityId(String activityId);
}

+ 7 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskPatientDetailDao.java

@ -16,4 +16,11 @@ public interface TaskPatientDetailDao extends PagingAndSortingRepository<TaskPat
    @Query("select t from TaskPatientDetailDO t where taskId = ?1")
    List<TaskPatientDetailDO> selectByTaskId(String taskId);
    @Query("select t from TaskPatientDetailDO t where taskId = ?1 and patientId =?2")
    TaskPatientDetailDO selectByTaskIdAndPatientId(String taskId,String patientId);
    @Query("select t from TaskPatientDetailDO t where activityId = ?1 and patientId =?2")
    TaskPatientDetailDO selectByActivityIdAndPatientId(String activityId,String patientId);
}

+ 3 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/dao/TaskRuleDao.java

@ -5,6 +5,7 @@ package com.yihu.jw.dao;
import com.yihu.jw.entity.health.bank.TaskRuleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
@ -13,4 +14,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 * @desc health bank task dao
 **/
public interface TaskRuleDao extends PagingAndSortingRepository<TaskRuleDO,String>,JpaSpecificationExecutor<TaskRuleDO> {
    @Query("select t from TaskRuleDO t where t.id = ?1 and t.status=1")
    public TaskRuleDO findByCode(String id);
}

+ 14 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/AccountService.java

@ -397,4 +397,18 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
        }
        return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, accountDOS,page,size,count);
    }
    /**
     * 根据居民code获取积分
     *
     * @param patient
     * @return
     */
    public MixEnvelop<AccountDO, AccountDO> selectByPatient(String patient){
        MixEnvelop<AccountDO,AccountDO> envelop = new MixEnvelop<>();
        String sql = "select * from wlyy_health_bank_account where status = 1 and patient_id = '"+patient+"'";
        List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
        envelop.setObj(accountDOS.get(0));
        return envelop;
    }
}

+ 52 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/ActivityRuleService.java

@ -0,0 +1,52 @@
package com.yihu.jw.service;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.dao.ActivityDao;
import com.yihu.jw.dao.ActivityRuleDao;
import com.yihu.jw.dao.TaskGoodsDao;
import com.yihu.jw.entity.health.bank.ActivityDO;
import com.yihu.jw.entity.health.bank.ActivityRuleDO;
import com.yihu.jw.entity.health.bank.TaskGoodsDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.catalina.LifecycleState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by wzn54 on 2019/1/4.
 */
@Service
@Transactional
public class ActivityRuleService extends BaseJpaService<ActivityDO,ActivityDao> {
    @Autowired
    private ActivityRuleDao activityRuleDao;
    @Autowired
    private TaskGoodsDao taskGoodsDao;
    /**
     * 根据id获取活动id
     * @param id
     * @return
     */
    public MixEnvelop<ActivityRuleDO,ActivityRuleDO> selectByActivityId(String id){
        MixEnvelop<ActivityRuleDO,ActivityRuleDO> envelop = new MixEnvelop<>();
        ActivityRuleDO ruleDO = activityRuleDao.selectByActivityId(id);
        if (ruleDO.getValue3() != null && ruleDO.getValue3() != ""){
            JSONObject object = JSONObject.parseObject(ruleDO.getValue3());
            Integer exchangeType = object.getInteger("exchangeType");
            List<TaskGoodsDO> taskGoodsDOS = null;
            if (exchangeType == 2){
               taskGoodsDOS = taskGoodsDao.selectByActivityId(id);
            }
            ruleDO.setTaskGoodsDOS(taskGoodsDOS);
        }
        envelop.setObj(ruleDO);
        return envelop;
    }
}

+ 810 - 15
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/ActivityService.java

@ -2,26 +2,31 @@ package com.yihu.jw.service;/**
 * Created by nature of king on 2018/4/27.
 */
import com.yihu.jw.dao.ActivityDao;
import com.yihu.jw.dao.TaskDao;
import com.yihu.jw.dao.TaskPatientDetailDao;
import com.yihu.jw.entity.health.bank.ActivityDO;
import com.yihu.jw.entity.health.bank.TaskDO;
import com.yihu.jw.entity.health.bank.TaskPatientDetailDO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import com.netflix.discovery.util.StringUtil;
import com.yihu.jw.dao.*;
import com.yihu.jw.entity.health.bank.*;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.util.DateUtils;
import com.yihu.jw.util.ISqlUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.RollbackException;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @author wangzhinan
@ -40,6 +45,14 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
    private TaskDao taskDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private ActivityRuleDao activityRuleDao;
    @Autowired
    private TaskGoodsDao taskGoodsDao;
    @Autowired
    private AccountDao accountDao;
    @Autowired
    private ExchangeGoodsDao exchangeGoodsDao;
    /**
@ -48,10 +61,67 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
     * @param activityDO 活动参数对象
     * @return
     */
    public MixEnvelop<Boolean, Boolean> insert(ActivityDO activityDO){
    @org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
    public MixEnvelop<Boolean, Boolean> insert(ActivityDO activityDO,String value1,String value2,String value3){
        if (value2 != null && value2 !=""){
            JSONObject object = JSONObject.parseObject(value2);
            activityDO.setActivityOfflineTime(object.getDate("activityOfflineTime"));
            activityDO.setRegistrationTime(object.getDate("registrationTime"));
            activityDO.setDeadLine(object.getDate("deadLine"));
        }
        activityDO.setCreateTime(new Date());
        activityDO.setUpdateTime(new Date());
        activityDao.save(activityDO);
        activityDO.setDelFlag(1);
        activityDO= activityDao.save(activityDO);
        if (value3 !=null && value3 !=""){
            JSONObject object = JSONObject.parseObject(value3);
            String exchangeType = object.getString("exchangeType");
            if (exchangeType.equals("1")){
                String array = (null!=object.get("goodDetail")?String.valueOf(object.get("goodDetail")):"");
                if (StringUtils.isNotBlank(array)){
                    JSONArray array1= JSON.parseArray(array);
                    for (int i =0;i<array1.size();i++){
                        JSONObject jsonObject = array1.getJSONObject(i);
                        TaskGoodsDO taskGoodsDO = new TaskGoodsDO();
                        taskGoodsDO.setCreateTime(new Date());
                        taskGoodsDO.setUpdateTime(new Date());
                        taskGoodsDO.setActivityId(activityDO.getId());
                        taskGoodsDO.setCoupon(jsonObject.getInteger("couponNum"));
                        taskGoodsDO.setImg(jsonObject.getString("picUrl"));
                        taskGoodsDO.setName(jsonObject.getString("name"));
                        taskGoodsDO.setSaasId("dev");
                        taskGoodsDO.setStatus(1);
                        taskGoodsDao.save(taskGoodsDO);
                    }
                }
            }
        }
        TaskDO taskDO = new TaskDO();
        taskDO.setTitle(activityDO.getTitle());
        taskDO.setStatus(1);
        taskDO.setTransactionId(activityDO.getId());
        taskDO.setType("ACTIVITY_TASK");
        taskDO.setSaasId("dev");
        taskDO.setContent(activityDO.getDescription());
        taskDO.setPeriod(1);
        taskDO.setTaskCode("ACTIVITY_QUESTION");
        taskDO.setStartTime(activityDO.getRegistrationTime());
        taskDO.setEndTime(activityDO.getActivityOfflineTime());
        taskDO.setCreateTime(new Date());
        taskDO.setUpdateTime(new Date());
        taskDao.save(taskDO);
        ActivityRuleDO activityRuleDO = new ActivityRuleDO();
        activityRuleDO.setCreateTime(new Date());
        activityRuleDO.setUpdateTime(new Date());
        activityRuleDO.setActivityId(activityDO.getId());
        activityRuleDO.setSaasId("dev");
        activityRuleDO.setValue1(value1);
        activityRuleDO.setValue2(value2);
        activityRuleDO.setValue3(value3);
        activityRuleDO.setDelFlag(1);
      /*  activityRuleDO.setDel(1);*/
        activityRuleDao.save(activityRuleDO);
        MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
        envelop.setObj(true);
        return envelop;
@ -94,6 +164,14 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
            activityDO1.setTaskPatientDetailDOS(taskPatientDetailDOS);
            String tasksql = "select * from wlyy_health_bank_task where transaction_id = '"+activityDO1.getId()+"'";
            List<TaskDO> taskDOList = jdbcTemplate.query(tasksql,new BeanPropertyRowMapper(TaskDO.class));
            List<TaskGoodsDO> taskGoodsDOS = taskGoodsDao.selectByActivityId(activityDO1.getId());
            for (TaskGoodsDO taskGoodsDO:taskGoodsDOS){
                ExchangeGoodsDO exchangeGoodsDO = exchangeGoodsDao.selectByActivityGoodsIdAndPatientId(taskGoodsDO.getId(),activityDO.getPatientId());
                taskGoodsDO.setExchangeGoodsDO(exchangeGoodsDO);
            }
            activityDO1.setTaskGoodsDOS(taskGoodsDOS);
            ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(activityDO1.getId());
            activityDO1.setActivityRuleDO(activityRuleDO);
            activityDO1.setTaskDOS(taskDOList);
        }
        String sqlcount = new ISqlUtils().getSql(activityDO,0,0,"count");
@ -111,7 +189,55 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
     * @param activityDO 活动参数对象
     * @return
     */
    public MixEnvelop<Boolean, Boolean> update(ActivityDO activityDO){
    @org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
    public MixEnvelop<Boolean, Boolean> update(ActivityDO activityDO, String value1, String value2, String value3) throws Exception {
        if (StringUtils.isBlank(activityDO.getId())) {
            throw new Exception("活动id不能为空!");
        }
        if (StringUtils.isNotBlank(value2)){
            JSONObject object = JSONObject.parseObject(value2);
            activityDO.setActivityOfflineTime(object.getDate("activityOfflineTime"));
            activityDO.setRegistrationTime(object.getDate("registrationTime"));
            activityDO.setDeadLine(object.getDate("deadLine"));
        }
        activityDO.setUpdateTime(new Date());
        activityDO.setDelFlag(1);
        //删除活动任务与奖品
        taskGoodsDao.deleteByActivityId(activityDO.getId());
        if (value3 !=null && value3 !=""){
            JSONObject object = JSONObject.parseObject(value3);
            String exchangeType = object.getString("exchangeType");
            if (exchangeType.equals("1")){
                String array = (null!=object.get("goodDetail")?String.valueOf(object.get("goodDetail")):"");
                if (StringUtils.isNotBlank(array)){
                    JSONArray array1= JSON.parseArray(array);
                    for (int i =0;i<array1.size();i++){
                        JSONObject jsonObject = array1.getJSONObject(i);
                        TaskGoodsDO taskGoodsDO = new TaskGoodsDO();
                        taskGoodsDO.setActivityId(activityDO.getId());
                        taskGoodsDO.setCoupon(jsonObject.getInteger("couponNum"));
                        taskGoodsDO.setImg(jsonObject.getString("picUrl"));
                        taskGoodsDO.setName(jsonObject.getString("name"));
                        taskGoodsDO.setCreateTime(new Date());
                        taskGoodsDO.setUpdateTime(new Date());
                        taskGoodsDO.setSaasId("dev");
                        taskGoodsDO.setStatus(1);
                        taskGoodsDao.save(taskGoodsDO);
                    }
                }
            }
        }
        ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(activityDO.getId());
        activityRuleDO.setUpdateTime(new Date());
        activityRuleDO.setSaasId("dev");
        activityRuleDO.setValue1(value1);
        activityRuleDO.setValue2(value2);
        activityRuleDO.setValue3(value3);
        activityRuleDO.setDelFlag(1);
        activityRuleDao.save(activityRuleDO);
        System.out.println("----------------------------update--"+activityDO.getId()+activityDO.getAreaName());
//        activityDO.setCreateTime(new Date());
        activityDao.save(activityDO);
        MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
        envelop.setObj(true);
@ -127,6 +253,10 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
     * @return
     */
    public MixEnvelop<ActivityDO, ActivityDO> selectByPatient(ActivityDO activityDO, Integer page, Integer size){
        String condition = "";
        if (activityDO.getUnionId()!=null&&activityDO.getUnionId() !=""){
            condition="AND union_id = '"+ activityDO.getUnionId()+"'";
        }
        String sql ="SELECT * " +
                " FROM wlyy_health_bank_activity " +
                "WHERE " +
@ -137,7 +267,7 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
                " SELECT task_id FROM " +
                "wlyy_health_bank_task_patient_detail" +
                " WHERE " +
                " patient_idcard = '"+activityDO.getPatientIdcard()+"' AND union_id = '"+ activityDO.getUnionId()+"')" +
                " patient_idcard = '"+activityDO.getPatientIdcard()+"' "+ condition+")" +
                " )" +
                " LIMIT "+(page-1)*size +","+size;
        List<ActivityDO> activityDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ActivityDO.class));
@ -153,7 +283,7 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
                    " wlyy_health_bank_task_patient_detail " +
                    "GROUP BY patient_openid,patient_idcard,union_id)btpd1 " +
                    "WHERE " +
                    " btpd1.activity_id = '"+activityDO1.getId() +"' AND patient_openid = '"+activityDO.getOpenId()+ "' AND patient_idcard = '"+activityDO.getPatientIdcard()+"' AND union_id = '"+ activityDO.getUnionId()+"'";
                    " btpd1.activity_id = '"+activityDO1.getId() +"' AND patient_openid = '"+activityDO.getOpenId()+ "' AND patient_idcard = '"+activityDO.getPatientIdcard()+"' "+condition;
            List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(activitySql);
            Long count = 0L;
            if(rstotal!=null&&rstotal.size()>0){
@ -206,7 +336,7 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
                " SELECT task_id FROM " +
                "wlyy_health_bank_task_patient_detail" +
                " WHERE " +
                " patient_openid = '"+activityDO.getOpenId()+ "' AND patient_idcard = '"+activityDO.getPatientIdcard()+"' AND union_id = '"+ activityDO.getUnionId()+"' )" +
                " patient_openid = '"+activityDO.getOpenId()+ "' AND patient_idcard = '"+activityDO.getPatientIdcard()+"'"+condition+ ")" +
                " )";
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
@ -239,12 +369,677 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
                taskPatientDetailDO.setUpdateTime(new Date());
                taskPatientDetailDao.save(taskPatientDetailDO);
            }
            ActivityRuleDO ruleDO = activityRuleDao.selectByActivityId(ids.get(i));
            if(null!=ruleDO){
                ruleDO.setDelFlag(0);
                activityRuleDao.save(ruleDO);
            }
            ActivityDO activityDO = activityDao.findOne(ids.get(i));
            activityDO.setStatus(-1);
            activityDO.setCreateTime(new Date());
            activityDO.setUpdateTime(new Date());
            activityDO.setDelFlag(0);
            activityDao.save(activityDO);
        }
        return envelop;
    }
    /**
     * 删除活动
     *
     * @param id 活动id
     * @return
     */
    public MixEnvelop<Boolean, Boolean> daleteActivity(String id){
        MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
            List<TaskDO> taskDOList = taskDao.selectByActivityId(id);
            for (TaskDO taskDO:taskDOList){
                taskDO.setStatus(0);
                taskDO.setCreateTime(new Date());
                taskDO.setUpdateTime(new Date());
                taskDao.save(taskDO);
            }
            List<TaskPatientDetailDO> taskPatientDetailDOS = taskPatientDetailDao.selectByActivityId(id);
            for(TaskPatientDetailDO taskPatientDetailDO:taskPatientDetailDOS){
                taskPatientDetailDO.setStatus(-1);
                taskPatientDetailDO.setCreateTime(new Date());
                taskPatientDetailDO.setUpdateTime(new Date());
                taskPatientDetailDao.save(taskPatientDetailDO);
            }
            ActivityRuleDO ruleDO = activityRuleDao.selectByActivityId(id);
            if(null!=ruleDO){
                ruleDO.setDelFlag(0);
                activityRuleDao.save(ruleDO);
            }
            ActivityDO activityDO = activityDao.findOne(id);
            activityDO.setStatus(-1);
            activityDO.setCreateTime(new Date());
            activityDO.setUpdateTime(new Date());
            activityDO.setDelFlag(0);
            activityDao.save(activityDO);
        return envelop;
    }
    /**
     * 编辑活动:上、下线,推荐
     * @param id
     * @param type 操作类型:上线:0,下线:2,推荐:3,取消推荐:4
     * @return
     * @throws Exception
     */
    public ActivityDO editActivity(String id, String type) throws Exception {
        ActivityDO activityDO = activityDao.findOne(id);
        ActivityRuleDO activityRuleDO= activityRuleDao.selectByActivityId(id);
        if("3".equals(type)){
            //推荐
            activityDO.setRecommended(1);
        }else if("4".equals(type)){
            //取消推荐
            activityDO.setRecommended(0);
        }
        else if("2".equals(type)){
            //下线
            activityDO.setStatus(2);
        }else if("0".equals(type)){
            //判断该活动是不是竞走,只能存在一条有效竞走
            if("竞走".equals(activityDO.getType())){
                List<ActivityDO>  lst=   activityDao.findByIdAndType(activityDO.getType());
                if(null!=lst&&lst.size()>0){
                    throw new Exception("已存在一条上线的竞走活动!");
                }
            }
            //上线
            if(null!=activityRuleDO){
                String ruleJson=activityRuleDO.getValue2();
                JSONObject obj=JSONObject.parseObject(ruleJson);
//                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                //报名截止时间
                Date registrationTime=(null!=obj.get("registrationTime")? sdf2.parse(obj.get("registrationTime").toString()):null);
                //参与截止时间
                Date deadLine=(null!=obj.get("deadLine")? sdf2.parse(obj.get("deadLine").toString()):null);
                //活动下线时间
                Date activityOfflineTime=(null!=obj.get("activityOfflineTime")? sdf2.parse(obj.get("activityOfflineTime").toString()):null);
                //获取当前时间
                Date now = DateUtil.strToDate(sdf2.format(new Date()),"yyyy-MM-dd HH:mm");
                if(null!=activityOfflineTime&&activityOfflineTime.compareTo(now)<=0){
                    //活动下线
                    activityDO.setStatus(2);
                }else if((null!=activityOfflineTime&&activityOfflineTime.compareTo(now)>0) && (null!=deadLine&&deadLine.compareTo(now)<=0)){
                    //活动结束
                    activityDO.setStatus(-1);
                }else if((null!=deadLine&&deadLine.compareTo(now)>0)&&(null!=registrationTime&&registrationTime.compareTo(now)<=0)){
                    //活动未结束
                    activityDO.setStatus(0);
                }else if (null!=registrationTime&&registrationTime.compareTo(now)>1){
                    //报名未截止
                    activityDO.setStatus(1);
                }else{
                    //没有时间限制,上线
                    activityDO.setStatus(0);
                }
            }else {
                throw new Exception("活动规则缺失!");
            }
        }
//        activityDO.setReleaseTime(new Date());
        activityDO=  activityDao.save(activityDO);
        return activityDO;
    }
    /**
     * 根据活动id获取活动详情+规则
     * @param id
     * @return
     * @throws Exception
     */
    public JSONObject findActivityById(String id)throws Exception{
        JSONObject obj=new JSONObject();
        ActivityDO activityDO = activityDao.findOne(id);
        obj.put("jsonData",activityDO);
        ActivityRuleDO activityRuleDO=new ActivityRuleDO();
        if(null!=activityDO){
            activityRuleDO= activityRuleDao.selectByActivityId(id);
            activityDO.setActivityRuleDO(activityRuleDO);
        }
        obj.put("value1", null == activityRuleDO ? null : activityRuleDO.getValue1());
        obj.put("value2", null == activityRuleDO ? null : activityRuleDO.getValue2());
        obj.put("value3", null == activityRuleDO ? null : activityRuleDO.getValue3());
        return obj;
    }
    /**
     * 活动排名
     *
     * @param activityId
     * @param patient
     * @param page
     * @param size
     * @return
     */
    public MixEnvelop<JSONObject,JSONObject> selectActivityRanking(String activityId,String patient,Integer page,Integer size,String street,String town){
        MixEnvelop<JSONObject,JSONObject> envelop = new MixEnvelop<>();
        ActivityDO activityDO = activityDao.selectById(activityId);
        JSONObject jsonObject = new JSONObject();
        TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDao.selectByActivityIdAndPatientId(activityId,patient);
        //积分排行
        String sql  ="SELECT btpd1.patientId, btpd1.total, btpd1.create_time AS updateTime FROM (SELECT btpd.patient_id AS patientId,btpd.total,btpd.create_time AS create_time FROM ( SELECT sum(btpd.total) AS total, btpd.patient_id,btpd.create_time " +
                "FROM wlyy_health_bank_task_patient_detail btpd " +
                "WHERE btpd.activity_id = '"+activityId +
                "' GROUP BY  btpd.patient_id " +
                " ) btpd " +
                "ORDER BY " +
                " btpd.total DESC)btpd1 ORDER BY btpd1.create_time LIMIT " + (page-1)*size+","+size;
        List<TaskPatientDetailDO> patientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        long count=0L;
        for (TaskPatientDetailDO taskPatientDetailDO:patientDetailDOS){
            String timeSeparated = DateUtils.getDatePoor(new Date(),taskPatientDetailDO.getUpdateTime());
            String goodsSql = "select * from wlyy_health_bank_exchange_goods where patient_id ='"+taskPatientDetailDO.getPatientId()+"' " +
                    "and activity_goods_id in(select id from wlyy_health_bank_activity_goods where activity_id ='"+activityId+"')";
            List<ExchangeGoodsDO> exchangeGoodsDOS = jdbcTemplate.query(goodsSql,new BeanPropertyRowMapper<>(ExchangeGoodsDO.class));
            for (ExchangeGoodsDO exchangeGoodsDO :exchangeGoodsDOS){
                TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
                exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
            }
            taskPatientDetailDO.setExchangeGoodsDO(exchangeGoodsDOS);
            taskPatientDetailDO.setTimeSeparated(timeSeparated);
            if (!taskPatientDetailDO.getPatientId().equals(patient)){
                count+=1;
            }
        }
        //活动劵排行
        String sqlCoupon  ="SELECT btpd1.patientId, btpd1.couponTotal, btpd1.create_time AS updateTime FROM (SELECT btpd.patient_id AS patientId,btpd.couponTotal,btpd.create_time AS create_time  FROM ( SELECT sum(btpd.coupon_total) AS couponTotal, btpd.patient_id,btpd.create_time " +
                "FROM wlyy_health_bank_task_patient_detail btpd " +
                "WHERE btpd.activity_id = '"+activityId +
                "' GROUP BY  btpd.patient_id " +
                " ) btpd " +
                "ORDER BY " +
                " btpd.couponTotal DESC )btpd1 ORDER BY btpd1.create_time DESC LIMIT " + (page-1)*size+","+size;
        List<TaskPatientDetailDO> patientDetailDOS1 = jdbcTemplate.query(sqlCoupon,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        long count2 = 0l;
        for (TaskPatientDetailDO taskPatientDetailDO:patientDetailDOS1){
            String timeSeparated = DateUtils.getDatePoor(new Date(),taskPatientDetailDO.getUpdateTime());
            String goodsSql = "select * from wlyy_health_bank_exchange_goods where patient_id ='"+taskPatientDetailDO.getPatientId()+"' " +
                    "and activity_goods_id in(select id from wlyy_health_bank_activity_goods where activity_id ='"+activityId+"')";
            List<ExchangeGoodsDO> exchangeGoodsDOS = jdbcTemplate.query(goodsSql,new BeanPropertyRowMapper<>(ExchangeGoodsDO.class));
            for (ExchangeGoodsDO exchangeGoodsDO :exchangeGoodsDOS){
                TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
                exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
            }
            if (taskPatientDetailDO.getPatientId().equals(taskPatientDetailDO.getPatientId())){
                count2+=1;
            }
            taskPatientDetailDO.setExchangeGoodsDO(exchangeGoodsDOS);
            taskPatientDetailDO.setTimeSeparated(timeSeparated);
        }
        //活动总积分排名
        /*String rankingSql1 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(total) AS sum , " +
                " patient_id, " +
                " activity_id, " +
                " create_time "+
                " FROM " +
                " wlyy_health_bank_task_patient_detail htpd " +
                " where htpd.activity_id ='"+activityId+"' AND htpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE " +
                " btpd1.sum >= (SELECT SUM(s.total) as total " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"') " +
                " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(rankingSql1);
        Long count = 0L;
        if(rstotal1!=null&&rstotal1.size()>0){
            count = (Long) rstotal1.get(0).get("total");
        }*/
        Long countTotal = 0L;
        if ((count-2)>=0){
            countTotal = (count-2);
        }
        //排名前一个积分
        String rankingSql9 = "SELECT btpd1.sum as total FROM (SELECT " +
                " SUM(total) AS sum , " +
                " patient_id, " +
                " activity_id " +
                " FROM " +
                " wlyy_health_bank_task_patient_detail btpd where btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE " +
                " btpd1.activity_id = '"+activityDO.getId()+"' AND btpd1.sum >= (SELECT SUM(s.total) as total " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" +
                " limit "+countTotal+",1" ;
        List<Map<String,Object>> rstotal9 = jdbcTemplate.queryForList(rankingSql9);
        Integer total = 0;
        if(rstotal9!=null&&rstotal9.size()>0){
            total = Integer.parseInt(rstotal9.get(0).get("total").toString()) ;
        }
        String totalSql = " SELECT SUM(s.total) as total " +
                " FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"'";
        List<Map<String,Object>> rstotal10 = jdbcTemplate.queryForList(totalSql);
        Integer total1 = 0;
        if(rstotal10!=null&&rstotal10.size()>0){
            total1 = Integer.parseInt( rstotal10.get(0).get("total").toString());
        }
        //总活动劵的排名
        /*String rankingSql2 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(coupon_total) AS sum , " +
                " patient_id, " +
                " activity_id," +
                " create_time " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail htpd WHERE htpd.activity_id ='"+activityId+"' AND htpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE " +
                "   btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')"+
                " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')";
        List<Map<String,Object>> rstotal2 = jdbcTemplate.queryForList(rankingSql2);
        Long count2 = 0L;
        if(rstotal2!=null&&rstotal2.size()>0){
            count2 = (Long) rstotal2.get(0).get("total");
        }*/
        Long countTotal1 = 0L;
        if ((count2-2)>=0){
            countTotal1=(count2-2);
        }
        //活动劵前一个活动劵
        String rankingSql10 = "SELECT btpd1.sum as total FROM (SELECT " +
                " SUM(coupon_total) AS sum , " +
                " patient_id, " +
                " activity_id "+
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE " +
                 " btpd1.sum >= (SELECT SUM(s.total) as total " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" +
                " limit "+countTotal1+",1" ;
        List<Map<String,Object>> totalSql10 = jdbcTemplate.queryForList(rankingSql10);
        Integer total2 = 0;
        if(totalSql10!=null&&totalSql10.size()>0){
            total2 = Integer.parseInt(totalSql10.get(0).get("total").toString());
        }
        String totalSql1 = " SELECT SUM(s.coupon_total) as total " +
                " FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"'";
        List<Map<String,Object>> totalSql11 = jdbcTemplate.queryForList(totalSql1);
        Integer total3 = 0;
        if(totalSql11!=null&&totalSql11.size()>0){
            total3 = Integer.parseInt(totalSql11.get(0).get("total").toString());
        }
        //活动劵
        //街道
        String rankingSql3  ="SELECT btpd1.patientId, btpd1.total, btpd1.create_time AS updateTime FROM (SELECT btpd.patient_id AS patientId,btpd.total,btpd.create_time AS create_time FROM ( SELECT sum(btpd.total) AS total, btpd.patient_id,btpd.create_time " +
                "FROM wlyy_health_bank_task_patient_detail btpd " +
                "WHERE btpd.activity_id = '"+activityId +
                "' GROUP BY  btpd.patient_id " +
                " ) btpd "+
                "ORDER BY " +
                " btpd.total DESC)btpd1 WHERE  btpd1.patientId IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.street = '"+street+"')"+" ORDER BY btpd1.create_time ";
        List<TaskPatientDetailDO> patientDetailDOS2 = jdbcTemplate.query(rankingSql3,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        long count3=0L;
        for (TaskPatientDetailDO taskPatientDetailDO:patientDetailDOS2){
            String timeSeparated = DateUtils.getDatePoor(new Date(),taskPatientDetailDO.getUpdateTime());
            String goodsSql = "select * from wlyy_health_bank_exchange_goods where patient_id ='"+taskPatientDetailDO.getPatientId()+"' " +
                    "and activity_goods_id in(select id from wlyy_health_bank_activity_goods where activity_id ='"+activityId+"')";
            List<ExchangeGoodsDO> exchangeGoodsDOS = jdbcTemplate.query(goodsSql,new BeanPropertyRowMapper<>(ExchangeGoodsDO.class));
            for (ExchangeGoodsDO exchangeGoodsDO :exchangeGoodsDOS){
                TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
                exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
            }
            taskPatientDetailDO.setExchangeGoodsDO(exchangeGoodsDOS);
            taskPatientDetailDO.setTimeSeparated(timeSeparated);
            if (!taskPatientDetailDO.getPatientId().equals(patient)){
                count3+=1;
            }
        }
        //区排名
        String rankingSql4  ="SELECT btpd1.patientId, btpd1.total, btpd1.create_time AS updateTime FROM (SELECT btpd.patient_id AS patientId,btpd.total,btpd.create_time AS create_time FROM ( SELECT sum(btpd.total) AS total, btpd.patient_id,btpd.create_time " +
                "FROM wlyy_health_bank_task_patient_detail btpd " +
                "WHERE btpd.activity_id = '"+activityId +
                "' GROUP BY  btpd.patient_id " +
                " ) btpd "+
                "ORDER BY " +
                " btpd.total DESC)btpd1 WHERE  btpd1.patientId IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.town = '"+town+"')"+" ORDER BY btpd1.create_time ";
        List<TaskPatientDetailDO> patientDetailDOS3 = jdbcTemplate.query(rankingSql4,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        long count4=0L;
        for (TaskPatientDetailDO taskPatientDetailDO:patientDetailDOS3){
            String timeSeparated = DateUtils.getDatePoor(new Date(),taskPatientDetailDO.getUpdateTime());
            String goodsSql = "select * from wlyy_health_bank_exchange_goods where patient_id ='"+taskPatientDetailDO.getPatientId()+"' " +
                    "and activity_goods_id in(select id from wlyy_health_bank_activity_goods where activity_id ='"+activityId+"')";
            List<ExchangeGoodsDO> exchangeGoodsDOS = jdbcTemplate.query(goodsSql,new BeanPropertyRowMapper<>(ExchangeGoodsDO.class));
            for (ExchangeGoodsDO exchangeGoodsDO :exchangeGoodsDOS){
                TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
                exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
            }
            taskPatientDetailDO.setExchangeGoodsDO(exchangeGoodsDOS);
            taskPatientDetailDO.setTimeSeparated(timeSeparated);
            if (!taskPatientDetailDO.getPatientId().equals(patient)){
                count4+=1;
            }
        }
        //活动劵排名
        //街道
        String rankingSql5  ="SELECT btpd1.patientId, btpd1.couponTotal, btpd1.create_time AS updateTime FROM (SELECT btpd.patient_id AS patientId,btpd.couponTotal,btpd.create_time AS create_time  FROM ( SELECT sum(btpd.coupon_total) AS couponTotal, btpd.patient_id,btpd.create_time " +
                "FROM wlyy_health_bank_task_patient_detail btpd " +
                "WHERE btpd.activity_id = '"+activityId +
                "' GROUP BY  btpd.patient_id " +
                " ) btpd " +
                "ORDER BY " +
                " btpd.couponTotal DESC )btpd1 WHERE  btpd1.patientId IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.street = '"+street+"') ORDER BY btpd1.create_time ";
        List<TaskPatientDetailDO> patientDetailDOS4 = jdbcTemplate.query(rankingSql5,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        long count5 = 0l;
        for (TaskPatientDetailDO taskPatientDetailDO:patientDetailDOS4){
            String timeSeparated = DateUtils.getDatePoor(new Date(),taskPatientDetailDO.getUpdateTime());
            String goodsSql = "select * from wlyy_health_bank_exchange_goods where patient_id ='"+taskPatientDetailDO.getPatientId()+"' " +
                    "and activity_goods_id in(select id from wlyy_health_bank_activity_goods where activity_id ='"+activityId+"')";
            List<ExchangeGoodsDO> exchangeGoodsDOS = jdbcTemplate.query(goodsSql,new BeanPropertyRowMapper<>(ExchangeGoodsDO.class));
            for (ExchangeGoodsDO exchangeGoodsDO :exchangeGoodsDOS){
                TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
                exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
            }
            if (taskPatientDetailDO.getPatientId().equals(taskPatientDetailDO.getPatientId())){
                count5+=1;
            }
            taskPatientDetailDO.setExchangeGoodsDO(exchangeGoodsDOS);
            taskPatientDetailDO.setTimeSeparated(timeSeparated);
        }
        //区排名
        String rankingSql6  ="SELECT btpd1.patientId, btpd1.couponTotal, btpd1.create_time AS updateTime FROM (SELECT btpd.patient_id AS patientId,btpd.couponTotal,btpd.create_time AS create_time  FROM ( SELECT sum(btpd.coupon_total) AS couponTotal, btpd.patient_id,btpd.create_time " +
                "FROM wlyy_health_bank_task_patient_detail btpd " +
                "WHERE btpd.activity_id = '"+activityId +
                "' GROUP BY  btpd.patient_id " +
                " ) btpd " +
                "ORDER BY " +
                " btpd.couponTotal DESC )btpd1 WHERE  btpd1.patientId IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.town = '"+town+"') ORDER BY btpd1.create_time ";
        List<TaskPatientDetailDO> patientDetailDOS5 = jdbcTemplate.query(rankingSql6,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        long count6 = 0l;
        for (TaskPatientDetailDO taskPatientDetailDO:patientDetailDOS5){
            String timeSeparated = DateUtils.getDatePoor(new Date(),taskPatientDetailDO.getUpdateTime());
            String goodsSql = "select * from wlyy_health_bank_exchange_goods where patient_id ='"+taskPatientDetailDO.getPatientId()+"' " +
                    "and activity_goods_id in(select id from wlyy_health_bank_activity_goods where activity_id ='"+activityId+"')";
            List<ExchangeGoodsDO> exchangeGoodsDOS = jdbcTemplate.query(goodsSql,new BeanPropertyRowMapper<>(ExchangeGoodsDO.class));
            for (ExchangeGoodsDO exchangeGoodsDO :exchangeGoodsDOS){
                TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
                exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
            }
            if (taskPatientDetailDO.getPatientId().equals(taskPatientDetailDO.getPatientId())){
                count6+=1;
            }
            taskPatientDetailDO.setExchangeGoodsDO(exchangeGoodsDOS);
            taskPatientDetailDO.setTimeSeparated(timeSeparated);
        }
        //街道排名
       /* String rankingSql3 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(btpd.coupon_total) AS sum , " +
                " btpd.patient_id, " +
                " btpd.activity_id," +
                " create_time " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE  btpd1.patient_id IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.street = '"+street+"') AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')"+
                " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal3 = jdbcTemplate.queryForList(rankingSql3);
        Long count3 = 0L;
        if(rstotal3!=null&&rstotal3.size()>0){
            count3 = (Long) rstotal3.get(0).get("total");
        }*/
        //区排名
       /* String rankingSql4 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(btpd.coupon_total) AS sum , " +
                " btpd.patient_id, " +
                " btpd.activity_id," +
                " create_time  " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE  btpd1.patient_id IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.town = '"+town+"') AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')"+
                " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal4 = jdbcTemplate.queryForList(rankingSql4);
        Long count4 = 0L;
        if(rstotal4!=null&&rstotal4.size()>0){
            count4= (Long) rstotal4.get(0).get("total");
        }*/
        //积分
        //街道排名
        /*String rankingSql5 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(btpd.total) AS sum , " +
                " btpd.patient_id, " +
                " btpd.activity_id," +
                " create_time  " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE  btpd1.patient_id IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.street = '"+street+"') AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')"+
                " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal5 = jdbcTemplate.queryForList(rankingSql5);
        Long count5 = 0L;
        if(rstotal5!=null&&rstotal5.size()>0){
            count5 = (Long) rstotal5.get(0).get("total");
        }
        //区排名
        String rankingSql6 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(btpd.total) AS sum , " +
                " btpd.patient_id, " +
                " btpd.activity_id," +
                " create_time " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE " +
                " btpd1.activity_id = '"+activityDO.getId()+"' and  btpd1.patient_id IN(SELECT p.code FROM wlyy.wlyy_patient p WHERE p.town = '"+town+"') AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')"
                + " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal6 = jdbcTemplate.queryForList(rankingSql6);
        Long count6 = 0L;
        if(rstotal6!=null&&rstotal6.size()>0){
            count6= (Long) rstotal6.get(0).get("total");
        }
*/
        //团队排名
        String rankingSql7 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(btpd.total) AS sum , " +
                " btpd.patient_id, " +
                " btpd.activity_id," +
                " create_time " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE  btpd1.patient_id IN(SELECT sf.patient FROM wlyy.wlyy_sign_family sf WHERE sf.status=1 " +
                "AND sf.admin_team_code=(SELECT sf.admin_team_code FROM wlyy.wlyy_sign_family sf WHERE sf.status=1 AND sf.patient='"+patient+"') ) AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')"+
                " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal7 = jdbcTemplate.queryForList(rankingSql7);
        Long count7 = 0L;
        if(rstotal7!=null&&rstotal7.size()>0){
            count7 = (Long) rstotal7.get(0).get("total");
        }
        //区排名
        String rankingSql8 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(btpd.total) AS sum , " +
                " btpd.patient_id, " +
                " btpd.activity_id," +
                " create_time " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.activity_id ='"+activityId+"' AND btpd.patient_id !='"+patient+
                "' GROUP BY patient_id )btpd1 " +
                "WHERE btpd1.patient_id IN(SELECT sf.patient FROM wlyy.wlyy_sign_family sf WHERE sf.status=1 " +
                "AND sf.admin_team_code=(SELECT sf.admin_team_code FROM wlyy.wlyy_sign_family sf WHERE sf.status=1 AND sf.patient='"+patient+"') ) AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" +
                " AND btpd1.create_time >=(SELECT s.create_time " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal8 = jdbcTemplate.queryForList(rankingSql8);
        Long count8 = 0L;
        if(rstotal8!=null&&rstotal8.size()>0){
            count8 = (Long) rstotal8.get(0).get("total");
        }
      /*  //活动劵
        String rankingSql4 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(coupon_total) AS sum , " +
                " patient_id, " +
                " activity_id " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail " +
                "GROUP BY patient_id )btpd1 " +
                "WHERE " +
                " btpd1.activity_id = '"+activityDO.getId()+"'"+buffer+" AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal4 = jdbcTemplate.queryForList(rankingSql4);
        Long count4 = 0L;
        if(rstotal4!=null&&rstotal4.size()>0){
            count4= (Long) rstotal4.get(0).get("total");
        }
        //积分
        String rankingSql5 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(total) AS sum , " +
                " patient_id, " +
                " activity_id " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail " +
                "GROUP BY patient_id )btpd1 " +
                "WHERE " +
                " btpd1.activity_id = '"+activityDO.getId()+"'"+buffer+" AND btpd1.sum >= (SELECT SUM(s.total) as total " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal5 = jdbcTemplate.queryForList(rankingSql5);
        Long count5 = 0L;
        if(rstotal5!=null&&rstotal5.size()>0){
            count5 = (Long) rstotal5.get(0).get("total");
        }
        String rankingSql6 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(total) AS sum , " +
                " patient_id, " +
                " activity_id " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail " +
                "GROUP BY patient_id )btpd1 " +
                "WHERE " +
                " btpd1.activity_id = '"+activityDO.getId()+"'"+buffer+" AND btpd1.sum >= (SELECT SUM(s.total) as total " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+activityId+"')" ;
        List<Map<String,Object>> rstotal6 = jdbcTemplate.queryForList(rankingSql6);
        Long count6 = 0L;
        if(rstotal6!=null&&rstotal6.size()>0){
            count6= (Long) rstotal6.get(0).get("total");
        }*/
        ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(activityId);
        JSONObject object = JSONObject.parseObject(activityRuleDO.getValue1());
        Integer type = object.getInteger("type");
        if (type == 2){
            jsonObject.put("activityTownCouponRanking",count6);//活动劵全区排名
            jsonObject.put("activityStreetCouponRanking",count5);//活动劵街道排名
            jsonObject.put("activityCouponRanking",count2);//活动劵的排名
            jsonObject.put("couponTotal",taskPatientDetailDO1.getCouponTotal());//本人活动劵总数
            jsonObject.put("couponRanking",patientDetailDOS1);//活动劵人数排名
            jsonObject.put("signCouponRanking",count7);//活动劵团队排名
            if (count2 ==1){
                jsonObject.put("differTotal",0);
            }else {
                jsonObject.put("differTotal",total2-total3);//相距前一个差多少活动劵
            }
        }else if (type ==1){
            jsonObject.put("IntegrateRanking",patientDetailDOS);
            jsonObject.put("activityStreetIntegrateRanking",count3);//积分街道排名
            jsonObject.put("total",taskPatientDetailDO1.getTotal());//本人总积分
            jsonObject.put("activityTownIntegrateRanking",count4);//积分全区排名
            jsonObject.put("activityRanking",count);//积分排名
            jsonObject.put("signRanking",count8);//积分团队排名
            if (count==1){
                jsonObject.put("differTotal",0);//相距前一个差多少积分
            }else {
                jsonObject.put("differTotal",total-total1);//相距前一个差多少积分
            }
        }
        jsonObject.put("type",type);//积分还是活动劵
        envelop.setObj(jsonObject);
        return envelop;
    }
    public JSONObject findActivityByType(String type){
        JSONObject object=new JSONObject();
        List<String> types = Arrays.asList(type.split(","));
        for(String str:types){
            List<ActivityDO>  lst=   activityDao.findByIdAndType(str);
            if(null!=lst&&lst.size()>0){
                object.put(str,true);
            }else {
                object.put(str,false);
            }
        }
        return object;
    }
    public JSONObject ListActivityDO(String type, String status,String crowdType,String releaseTime,String activityOfflineTime, String filter,Integer page,Integer size)throws ParseException {
        JSONObject obj=new JSONObject();
        StringBuffer stringBuffer=new StringBuffer();
        if (StringUtils.isNotEmpty(type)) {
            stringBuffer.append(" and type='").append(type).append("'");
        }
        if (StringUtils.isNotEmpty(filter)) {
            stringBuffer.append(" and (title like '%").append(filter).append("%' or ").append("organizer like '%").append(filter).append("%' or ").append("area_name like '%").append(filter).append("%')");
        }
        if (null != status && "2".equals(status) ) {
            stringBuffer.append(" and status in (-1,2) ");
        } else if (null != status && "1".equals(status) ) {
            stringBuffer.append(" and status in (0,1) ");
        }
        if(null!=crowdType&&StringUtils.isNotBlank(crowdType)){
            stringBuffer.append(" and crowd_type="+crowdType);
        }
        if(StringUtils.isNotBlank(releaseTime)){
            stringBuffer.append(" and activity_offline_time>='"+releaseTime+" 00:00:00' ");
        }
        if(StringUtils.isNotBlank(activityOfflineTime)){
            stringBuffer.append(" and activity_offline_time<='"+ activityOfflineTime+" 59:59:59' ");
        }
        stringBuffer.append(" order by create_time desc");
        String sql = "SELECT * FROM wlyy_health_bank.wlyy_health_bank_activity  WHERE 1=1 AND del_flag=1 "+stringBuffer.toString()+" LIMIT "+(page-1)*size+","+size;
        List<ActivityDO> activityDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ActivityDO.class));
        String sqlcount = "SELECT COUNT(1)  AS total  FROM wlyy_health_bank.wlyy_health_bank_activity  WHERE 1=1 AND del_flag=1 "+stringBuffer.toString();
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        obj .put("activityDOList",activityDOList);
        obj .put("count",count);
        return obj;
    }
}

+ 362 - 26
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/CreditsDetailService.java

@ -10,6 +10,7 @@ import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.util.DateUtils;
import com.yihu.jw.util.ISqlUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -20,6 +21,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.print.DocFlavor;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -55,6 +57,12 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
    private StringRedisTemplate redisTemplate;
    @Autowired
    private ActiveRecordService activeRecordService;
    @Autowired
    private ActivityRuleDao activityRuleDao;
    @Autowired
    private ExchangeGoodsDao exchangeGoodsDao;
    @Autowired
    private TaskGoodsDao taskGoodsDao;
   /**
     *  find creditsLogInfo
@ -69,6 +77,11 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
            if (creditsDetailDO1.getTradeType() != null && creditsDetailDO1.getTradeType().equalsIgnoreCase("ACTIVITY_TASK")){
                TaskDO taskDO = taskDao.findOne(creditsDetailDO1.getTransactionId());
                creditsDetailDO1.setTaskDO(taskDO);
            }else if (creditsDetailDO1.getTradeType()!=null&&creditsDetailDO1.getTradeType().equals("EXCHANGE_GOODS")){
                ExchangeGoodsDO exchangeGoodsDO =exchangeGoodsDao.findOne(creditsDetailDO1.getTransactionId());
                TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
                exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
                creditsDetailDO1.setExchangeGoodsDO(exchangeGoodsDO);
            }
        }
        String sqlcount = new ISqlUtils().getSql(creditsDetailDO,0,0,"count");
@ -227,6 +240,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                    AccountDO accountDO1 = new AccountDO();
                    accountDO1.setPatientId(creditsDetailDO.getPatientId());
                    accountDO1.setTotal(0);
                    accountDO1.setCouponTotal(0L);
                    accountDO1.setAccountName(creditsDetailDO.getName());
                    if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
                        String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
@ -642,17 +656,18 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                String integrateSql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+patientId+"' " +
                        "AND transaction_id IN (SELECT id FROM wlyy_health_bank_task WHERE task_code IN ('BP_BIND','GLU_BIND','BP_MEASURE','GLU_MEASURE','RULE'))";
                List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(integrateSql,new BeanPropertyRowMapper(CreditsDetailDO.class));
                AccountDO accountDO = accountDOS.get(0);
                for (CreditsDetailDO creditsDetailDO:creditsDetailDOS){
                    if (creditsDetailDO.getTradeDirection()==1&&creditsDetailDO.getStatus()!=0){
                        AccountDO accountDO = accountDOS.get(0);
                        int total = accountDO.getTotal() - creditsDetailDO.getIntegrate();
                  /*      int total = accountDO.getTotal() - creditsDetailDO.getIntegrate();*/
                        creditsDetailDO.setStatus(0);
                        creditsDetailDO.setDescription(description);
                        credittsLogDetailDao.save(creditsDetailDO);
                        accountDO.setTotal(total);
                        accountDao.save(accountDO);
                    }
                }
                accountDO.setTotal(0);
                accountDao.save(accountDO);
                CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
                creditsDetailDO1.setStatus(1);
                creditsDetailDO1.setSaasId("dev");
@ -683,21 +698,28 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                creditsDetailDO.setUpdateTime(new Date());
                creditsDetailDO.setTransactionId(taskDO1.getId());
                creditsDetailDO.setTradeType("ACTIVITY_TASK");
                credittsLogDetailDao.save(creditsDetailDO);
                creditsDetailDO = credittsLogDetailDao.save(creditsDetailDO);
                if (taskRuleDO.getTradeDirection() == -1){
                    String integrateSql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+patientId+"' " +
                            "AND transaction_id IN (SELECT id FROM wlyy_health_bank_task WHERE task_code IN ('BP_BIND','GLU_BIND','BP_MEASURE','GLU_MEASURE','RULE'))";
                    List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(integrateSql,new BeanPropertyRowMapper(CreditsDetailDO.class));
                    for (CreditsDetailDO creditsDetailDO1:creditsDetailDOS){
                        if (creditsDetailDO1.getTradeDirection()==1&&creditsDetailDO1.getStatus()!=0){
                            AccountDO accountDO = accountDOS.get(0);
                            int total = accountDO.getTotal() - creditsDetailDO1.getIntegrate();
                            creditsDetailDO1.setStatus(0);
                            creditsDetailDO1.setDescription(description);
                            credittsLogDetailDao.save(creditsDetailDO1);
                            accountDO.setTotal(total);
                            accountDao.save(accountDO);
                    if (taskRuleDO.getIntegrate() == 0){
                        String integrateSql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+patientId+"' " +
                                "AND transaction_id IN (SELECT id FROM wlyy_health_bank_task WHERE task_code IN ('BP_BIND','GLU_BIND','BP_MEASURE','GLU_MEASURE','RULE'))";
                        List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(integrateSql,new BeanPropertyRowMapper(CreditsDetailDO.class));
                        AccountDO accountDO = accountDOS.get(0);
                        for (CreditsDetailDO creditsDetailDO1:creditsDetailDOS){
                            if (creditsDetailDO1.getTradeDirection()==1&&creditsDetailDO1.getStatus()!=0){
                                int total = accountDO.getTotal() - creditsDetailDO1.getIntegrate();
                                creditsDetailDO1.setStatus(0);
                                creditsDetailDO1.setDescription(description);
                                credittsLogDetailDao.save(creditsDetailDO1);
                            }
                        }
                        accountDO.setTotal(0);
                        accountDao.save(accountDO);
                    }else if (taskRuleDO.getIntegrate()!=0){
                        AccountDO accountDO = accountDOS.get(0);
                        int total = accountDO.getTotal() - creditsDetailDO.getIntegrate();
                        accountDO.setTotal(total);
                        accountDao.save(accountDO);
                    }
                }else if (taskRuleDO.getTradeDirection() == 1){
                    AccountDO accountDO = accountDOS.get(0);
@ -709,6 +731,8 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
        envelop.setObj(true);
        return envelop;
    }
    /**
     * 固定数据
     *
@ -755,6 +779,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                    accountDO1.setPatientId(creditsDetailDO.getPatientId());
                    accountDO1.setSaasId("dev");
                    accountDO1.setTotal(0);
                    accountDO1.setCouponTotal(0L);
                    accountDO1.setAccountName(creditsDetailDO.getName());
                    if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
                        String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
@ -771,7 +796,6 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                    List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
                    creditsDetailDO.setAccountId(accountDOS.get(0).getId());
                }
                TaskDO taskDO = taskDao.findOne(creditsDetailDO.getTransactionId());
                String sql1 = "select *  from wlyy_health_bank_task_patient_detail where "+
                        " patient_idcard = '"+creditsDetailDO.getIdCard()+"' AND union_id = '"+creditsDetailDO.getUnionId()+"' AND task_id = '"+creditsDetailDO.getTransactionId()+"'";
                List<TaskPatientDetailDO> taskPatientDetailDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
@ -783,13 +807,63 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                        "transaction_id = '"+creditsDetailDO.getTransactionId()+"' AND create_time > '"+DateUtils.getDayBegin() +"' AND" +
                        " create_time < '"+DateUtils.getDayEnd()+"'AND ISNULL(description)";
                List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
                String step = redisTemplate.opsForValue().get(STEP);
                if (StringUtils.isEmpty(step)){
                    throw new Exception("获取步数失败!");
                ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(taskPatientDetailDO.getActivityId());
                if (activityRuleDO.getValue1() != null){
                    JSONObject object = JSONObject.parseObject(activityRuleDO.getValue1());
                    //获取步数
                    JSONArray array = object.getJSONArray("healthStep");
                    int j = array.size();
                    int z= 0;
                    for (int i = 0;i<=array.size();i++){
                        JSONObject jsonObject = array.getJSONObject(i);
                        Long step = jsonObject.getLong("step");
                        int integrate = jsonObject.getInteger("integrate");
                        if (creditsDetailDOS != null && creditsDetailDOS.size() != 0){
                            CreditsDetailDO creditsDetailDO1 = creditsDetailDOS.get(0);
                            if (creditsDetailDO.getStepNumber()>0 && creditsDetailDO.getStepNumber()<=step){
                                int integrate1=creditsDetailDO1.getIntegrate();
                                creditsDetailDO1.setIntegrate(creditsDetailDO.getIntegrate());
                                creditsDetailDO1.setTradeDirection(1);
                                CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
                                AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
                                accountDO.setTotal(accountDO.getTotal()-integrate1+creditsDetailDO2.getIntegrate());
                                AccountDO accountDO1 = accountDao.save(accountDO);
                                creditsDetailDO2.setTotal(accountDO1.getTotal());
                                taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()-integrate1+creditsDetailDO2.getIntegrate());
                                taskPatientDetailDao.save(taskPatientDetailDO);
                                creditsDetailDOS.clear();
                                creditsDetailDOS.add(creditsDetailDO2);
                                break;
                            }
                        }else {
                            CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
                            if (creditsDetailDO.getStepNumber()>0 && creditsDetailDO.getStepNumber()<=step){
                                creditsDetailDO1.setIntegrate(creditsDetailDO.getIntegrate());
                                creditsDetailDO1.setTradeDirection(1);
                                creditsDetailDO1.setSaasId("dev");
                                creditsDetailDO1.setTradeType("ACTIVITY_TASK");
                                creditsDetailDO1.setPatientId(creditsDetailDO.getPatientId());
                                creditsDetailDO1.setHospital(creditsDetailDO.getHospital());
                                creditsDetailDO1.setHospitalName(creditsDetailDO.getHospitalName());
                                creditsDetailDO1.setAccountId(creditsDetailDO.getAccountId());
                                creditsDetailDO1.setStatus(1);
                                creditsDetailDO1.setCreateTime(new Date());
                                creditsDetailDO1.setUpdateTime(new Date());
                                creditsDetailDO1.setTransactionId(taskPatientDetailDO.getTaskId());
                                CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
                                AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
                                accountDO.setTotal(accountDO.getTotal()+creditsDetailDO2.getIntegrate());
                                taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+creditsDetailDO2.getIntegrate());
                                taskPatientDetailDao.save(taskPatientDetailDO);
                                creditsDetailDO2.setTotal(accountDO.getTotal());
                                creditsDetailDOS.add(creditsDetailDO2);
                                break;
                            }
                        }
                    }
                }
                JSONObject object = JSONObject.parseObject(step);
                int step1 = object.getInteger("step1");
                int step2 = object.getInteger("step2");
          /*  for (int i = 0;i<array.size();i++){
                JSONObject jsonObject = array.getJSONObject(i);
                if (creditsDetailDOS != null && creditsDetailDOS.size() != 0){
                    CreditsDetailDO creditsDetailDO1 = creditsDetailDOS.get(0);
                    TaskRuleDO taskRuleDO = taskRuleDao.findOne(taskDO.getRuleCode());
@ -830,7 +904,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                            taskPatientDetailDao.save(taskPatientDetailDO);
                            creditsDetailDOS.clear();
                            creditsDetailDOS.add(creditsDetailDO2);
                        }/*else if(creditsDetailDO1.getIntegrate() == 3){
                        }*//*else if(creditsDetailDO1.getIntegrate() == 3){
                            creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+5);
                            creditsDetailDO1.setTradeDirection(1);
                            CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
@ -842,7 +916,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                            taskPatientDetailDao.save(taskPatientDetailDO);
                            creditsDetailDOS.clear();
                            creditsDetailDOS.add(creditsDetailDO2);
                        }*/
                        }*//*
                    }
                }else{
                    CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
@ -873,7 +947,15 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                    taskPatientDetailDao.save(taskPatientDetailDO);
                    creditsDetailDO2.setTotal(accountDO.getTotal());
                    creditsDetailDOS.add(creditsDetailDO2);
                }*/
              /*  String step = redisTemplate.opsForValue().get(STEP);
                if (StringUtils.isEmpty(step)){
                    throw new Exception("获取步数失败!");
                }
                JSONObject object = JSONObject.parseObject(step);
                int step1 = object.getInteger("step1");
                int step2 = object.getInteger("step2");
*/
                try{
                    activeRecordService.insert("dev",creditsDetailDOS.get(0).getTransactionId(),null,null,null,creditsDetailDOS.get(0).getPatientId());
                }catch (Exception e){
@ -890,6 +972,68 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
        }
    }
    public MixEnvelop doctorDescreaseIntegrate(String ruleId,String patientId,String doctorId,String hospital,String hospitalName,Integer integrate,String reason) throws Exception {
       MixEnvelop envelop = new MixEnvelop<>();
       envelop.setObj(true);
       TaskDO taskDO =  taskDao.selectByTaskRuleId(ruleId);
       String sql = "select * from wlyy_health_bank_account where status = 1 and patient_id = '"+patientId+"'";
       List<AccountDO> accountDOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
       AccountDO accountDO = accountDOs.get(0);
       if (taskDO == null){
           TaskRuleDO taskRuleDO =  taskRuleDao.findByCode(ruleId);
           TaskDO  taskDO1 = new TaskDO();
           taskDO1.setTitle(taskRuleDO.getName());
           taskDO1.setContent(taskRuleDO.getDescription());
           taskDO1.setSaasId("dev");
           taskDO1.setTaskCode("RULE");
           taskDO1.setType("RULE_TASK");
           taskDO1.setTransactionId(ruleId);
           taskDO1.setCreateTime(new Date());
           taskDO1.setUpdateTime(new Date());
           taskDO1.setRuleCode(taskRuleDO.getId());
           taskDO1.setStatus(1);
           taskDO = taskDao.save(taskDO1);
       }
       TaskPatientDetailDO patientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(taskDO.getId(),patientId);
       if (patientDetailDO == null){
           TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
           taskPatientDetailDO.setSaasId("dev");
           taskPatientDetailDO.setTaskId(taskDO.getId());
           taskPatientDetailDO.setPatientId(patientId);
           taskPatientDetailDO.setDoctorId(doctorId);
           taskPatientDetailDO.setPatientIdcard(accountDO.getIdCard());
           taskPatientDetailDO.setCreateTime(new Date());
           taskPatientDetailDO.setUpdateTime(new Date());
           taskPatientDetailDO.setStatus(1);
           taskPatientDetailDao.save(taskPatientDetailDO);
       }
       if (accountDO.getTotal().compareTo(integrate)>=0){
           CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
           creditsDetailDO.setAccountId(accountDO.getId());
           creditsDetailDO.setIdCard(accountDO.getIdCard());
           creditsDetailDO.setSaasId("dev");
           creditsDetailDO.setTradeType("ACTIVITY_TASK");
           creditsDetailDO.setTradeDirection(-1);
           creditsDetailDO.setIntegrate(integrate);
           creditsDetailDO.setDescription(reason);
           creditsDetailDO.setStatus(1);
           creditsDetailDO.setHospital(hospital);
           creditsDetailDO.setHospitalName(hospitalName);
           creditsDetailDO.setCreateTime(new Date());
           creditsDetailDO.setUpdateTime(new Date());
           creditsDetailDO.setTransactionId(taskDO.getId());
           creditsDetailDO.setPatientId(patientId);
           creditsDetailDO.setHospitalName(hospitalName);
           credittsLogDetailDao.save(creditsDetailDO);
           accountDO.setTotal(accountDO.getTotal()-integrate);
           accountDao.save(accountDO);
       }else {
           envelop.setMessage("积分不足!");
           throw new Exception("积分不足!");
       }
       return envelop;
    }
    /*public JSONObject getStepNumber(){
        String step = redisTemplate.·().get(STEP);
        logger.info("redis数据:"+step);
@ -1006,4 +1150,196 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
    }
    /**
     * 健康问答添加积分
     *
     * @param creditsDetailDO
     * @return
     * @throws Exception
     */
    public MixEnvelop<CreditsDetailDO,CreditsDetailDO> patientGetInteger(CreditsDetailDO creditsDetailDO) throws Exception {
        MixEnvelop<CreditsDetailDO,CreditsDetailDO> envelop = new MixEnvelop<>();
        TaskDO  taskDO = taskDao.selectById(creditsDetailDO.getTransactionId());
        ActivityRuleDO ruleDO = activityRuleDao.selectByActivityId(taskDO.getTransactionId());
        JSONObject object = JSONObject.parseObject(ruleDO.getValue1());
        Integer type = object.getInteger("type");
        AccountDO accountDO = accountDao.selectByPatientId(creditsDetailDO.getPatientId());
        creditsDetailDO.setUpdateTime(new Date());
        creditsDetailDO.setCreateTime(new Date());
        creditsDetailDO.setStatus(1);
        if (type == 2){
            creditsDetailDO.setCoupon(creditsDetailDO.getCoupon());
            creditsDetailDO.setIntegrate(null);
        }else if (type==1){
            creditsDetailDO.setIntegrate(creditsDetailDO.getCoupon());
            creditsDetailDO.setCoupon(null);
        }
        creditsDetailDO.setSaasId("dev");
        creditsDetailDO.setTradeType("ACTIVITY_TASK");
        creditsDetailDO.setTradeDirection(1);
        creditsDetailDO.setAccountId(accountDO.getId());
        CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
        if (creditsDetailDO1 == null){
            throw new Exception("积分添加失败!");
        }
        TaskPatientDetailDO patientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(creditsDetailDO.getTransactionId(),creditsDetailDO.getPatientId());
        patientDetailDO.setUpdateTime(new Date());
        patientDetailDO.setCreateTime(new Date());
        if (type == 2){
            patientDetailDO.setCouponTotal(patientDetailDO.getCouponTotal()+creditsDetailDO.getCoupon());
        }else if (type==1||type==3){
            patientDetailDO.setTotal(patientDetailDO.getTotal()+creditsDetailDO.getIntegrate());
        }
        patientDetailDO.setStatus(1);
        TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.save(patientDetailDO);
        if (taskPatientDetailDO == null){
            throw new Exception("修改活动状态和积分失败!");
        }
        if (type == 2){
            accountDO.setCouponTotal(accountDO.getCouponTotal()+creditsDetailDO.getCoupon());
        }else if (type==1||type==3){
            accountDO.setTotal(accountDO.getTotal()+creditsDetailDO.getIntegrate());
        }
        accountDO.setUpdateTime(new Date());
        AccountDO accountDO1 = accountDao.save(accountDO);
        if (accountDO1 == null){
            throw new Exception("修改银行账户积分失败!");
        }
        envelop.setObj(creditsDetailDO);
        return envelop;
    }
    /**
     * 健康问答--获取当日积分
     *
     * @param patient
     * @param transactionId
     * @return
     */
    public MixEnvelop<CreditsDetailDO,CreditsDetailDO> selectByDate(String patient,String transactionId){
        MixEnvelop<CreditsDetailDO,CreditsDetailDO> envelop = new MixEnvelop<>();
        String sql ="select * from wlyy_health_bank_credits_detail where patient_id = '"+patient+"' and " +
                "transaction_id = '"+transactionId+"' and create_time >='"+ DateUtils.getDayBegin()+"' and "  +
                "create_time <= '"+DateUtils.getDayEnd()+"'";
        List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
        CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
        if (creditsDetailDOS != null && creditsDetailDOS.size()!=0){
            creditsDetailDO = creditsDetailDOS.get(0);
        }
        TaskDO  taskDO = taskDao.selectById(transactionId);
        ActivityRuleDO ruleDO = activityRuleDao.selectByActivityId(taskDO.getTransactionId());
        //活动总积分排名
        String rankingSql1 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(total) AS sum , " +
                " patient_id, " +
                " activity_id " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.patient_id !='"+patient+"' " +
                "GROUP BY btpd.patient_id )btpd1 " +
                "WHERE " +
                " btpd1.activity_id = '"+taskDO.getTransactionId()+"' AND btpd1.sum >= (SELECT SUM(s.total) as total " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+taskDO.getTransactionId()+"')" ;
        List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(rankingSql1);
        Long count = 0L;
        if(rstotal1!=null&&rstotal1.size()>0){
            count = (Long) rstotal1.get(0).get("total");
        }
        //总活动劵的排名
        String rankingSql2 = "SELECT count(1)+1 AS total FROM (SELECT " +
                " SUM(coupon_total) AS sum , " +
                " patient_id, " +
                " activity_id " +
                "FROM " +
                " wlyy_health_bank_task_patient_detail btpd WHERE btpd.patient_id !='"+patient+"' "+
                "GROUP BY btpd.patient_id )btpd1 " +
                "WHERE " +
                " btpd1.activity_id = '"+taskDO.getTransactionId()+"' AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
                "FROM  wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND  s.activity_id='"+taskDO.getTransactionId()+"')" ;
        List<Map<String,Object>> rstotal2 = jdbcTemplate.queryForList(rankingSql2);
        Long count2 = 0L;
        if(rstotal2!=null&&rstotal2.size()>0){
            count2 = (Long) rstotal2.get(0).get("total");
        }
        JSONObject object = JSONObject.parseObject(ruleDO.getValue1());
        Integer type = object.getInteger("type");
        if (type == 2){
            creditsDetailDO.setActivityRanking(count2);
            creditsDetailDO.setMark(1);
        }else if (type==1||type==3){
            creditsDetailDO.setActivityRanking(count);
            creditsDetailDO.setMark(2);
        }
        envelop.setObj(creditsDetailDO);
        return envelop;
    }
    /**
     * 分享获取积分
     *
     * @param creditsDetailDO
     * @return
     */
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> shareIntegrate(CreditsDetailDO creditsDetailDO) {
        try {
            synchronized (creditsDetailDO.getPatientId()) {
                String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '" + creditsDetailDO.getPatientId() + "'";
                List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount, new BeanPropertyRowMapper(AccountDO.class));
                if (accountDOList != null && accountDOList.size() != 0) {
                    creditsDetailDO.setAccountId(accountDOList.get(0).getId());
                }
                String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and description = '分享'";
                List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
                List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
                MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
                if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
                    creditsDetailDO.setTradeType("ACTIVITY_TASK");
                    creditsDetailDO.setDescription("分享");
                    creditsDetailDO.setSaasId("dev");
                    creditsDetailDO.setStatus(1);
                    creditsDetailDO.setTransactionId(creditsDetailDO.getTransactionId());
                    creditsDetailDO.setCreateTime(new Date());
                    creditsDetailDO.setUpdateTime(new Date());
                    creditsDetailDO.setTradeDirection(1);
                    CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
                    creditsDetailDO1.setFlag("1");
                    creditsDetailDOList.add(creditsDetailDO1);
                    TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
                    taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
                    taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
                    String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
                    List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1, new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                    TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
                    if (creditsDetailDO1.getTradeDirection() == 1) {
                        taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() + creditsDetailDO1.getIntegrate());
                    } else if (creditsDetailDO.getTradeDirection() == -1) {
                        taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() - creditsDetailDO1.getIntegrate());
                    }
                    taskPatientDetailDao.save(taskPatientDetailDO1);
                    AccountDO accountDO = accountDao.findOne(creditsDetailDO1.getAccountId());
                    if (creditsDetailDO1.getTradeDirection() == 1) {
                        accountDO.setTotal(accountDO.getTotal() + creditsDetailDO1.getIntegrate());
                    } else if (creditsDetailDO.getTradeDirection() == -1) {
                        accountDO.setTotal(accountDO.getTotal() - creditsDetailDO1.getIntegrate());
                    }
                    accountDao.save(accountDO);
                    envelop.setDetailModelList(creditsDetailDOList);
                }else {
                    for (CreditsDetailDO creditsDetailDO1:creditsDetailDOS1){
                        creditsDetailDO1.setFlag("2");
                        creditsDetailDOList.add(creditsDetailDO1);
                    }
                    envelop.setDetailModelList(creditsDetailDOList);
                }
                return envelop;
            }
        } catch (Exception e) {
            e.printStackTrace();
            MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
            return envelop;
        }
    }
}

+ 74 - 31
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/ExchangeGoodsService.java

@ -2,11 +2,9 @@ package com.yihu.jw.service;/**
 * Created by nature of king on 2018/5/3.
 */
import com.yihu.jw.dao.CredittsLogDetailDao;
import com.yihu.jw.dao.ExchangeGoodsDao;
import com.yihu.jw.dao.GoodsDao;
import com.yihu.jw.entity.health.bank.ExchangeGoodsDO;
import com.yihu.jw.entity.health.bank.GoodsDO;
import com.netflix.discovery.converters.jackson.EurekaXmlJacksonCodec;
import com.yihu.jw.dao.*;
import com.yihu.jw.entity.health.bank.*;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.util.ISqlUtils;
@ -19,6 +17,7 @@ import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -39,36 +38,77 @@ public class ExchangeGoodsService extends BaseJpaService<ExchangeGoodsDO,Exchang
    private CredittsLogDetailDao credittsLogDetailDao;
    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private TaskGoodsDao taskGoodsDao;
    @Autowired
    private TaskPatientDetailDao taskPatientDetailDao;
    @Autowired
    private AccountDao accountDao;
  /*  *//**
    /**
     * exchange goods
     *
     * @param exchangeGoodsDO
     * @return
     *//*
    public Envelop<Boolean> insert(ExchangeGoodsDO exchangeGoodsDO){
        GoodsDO goodsDO = goodsDao.findOne(exchangeGoodsDO.getGoodsId());
        exchangeGoodsDO.setIntegrate(goodsDO.getRequireIntegrate());
        exchangeGoodsDao.save(exchangeGoodsDO);
        String sql = "select cl.status as status,cl.total as total from health_bank_credits_log cl order by cl.update_time desc";
        List<CreditsDetailDO> creditsLogDetailDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
        CreditsDetailDO creditsLogDetailDO = new CreditsDetailDO();
        if (creditsLogDetailDOList == null || creditsLogDetailDOList.size() ==0){
            creditsLogDetailDO.setTotal(Long.parseLong(goodsDO.getRequireIntegrate()));
        }else {
            creditsLogDetailDO.setTotal(creditsLogDetailDOList.get(0).getTotal()-Long.parseLong(goodsDO.getRequireIntegrate()));
        }
        creditsLogDetailDO.setPatientId(exchangeGoodsDO.getPatientId());
        creditsLogDetailDO.setIntegrate("-"+exchangeGoodsDO.getIntegrate());
        creditsLogDetailDO.setIntegrateType("EXCHANGE_GOODS");
        creditsLogDetailDO.setIntegrateId(exchangeGoodsDO.getGoodsId());
        creditsLogDetailDO.setStatus("used");
        creditsLogDetailDO.setCommunity(goodsDO.getCommunity());
        credittsLogDetailDao.save(creditsLogDetailDO);
        Envelop<Boolean> envelop = new Envelop<>();
        envelop.setObj(true);
        return envelop;
    }*/
     */
    public MixEnvelop<ExchangeGoodsDO,ExchangeGoodsDO> insert(ExchangeGoodsDO exchangeGoodsDO) throws Exception {
       MixEnvelop<ExchangeGoodsDO,ExchangeGoodsDO> envelop = new MixEnvelop<>();
       TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
       AccountDO accountDO = accountDao.selectByPatientId(exchangeGoodsDO.getPatientId());
       TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.selectByActivityIdAndPatientId(taskGoodsDO.getActivityId(),exchangeGoodsDO.getPatientId());
       if (taskPatientDetailDO.getTotal() != 0 && taskPatientDetailDO.getTotal() != null&&exchangeGoodsDO.getIntegrate()!=null){
           if (taskPatientDetailDO.getTotal() < exchangeGoodsDO.getIntegrate()){
               throw new Exception("积分余额不足!");
           }else {
               taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal() - exchangeGoodsDO.getIntegrate());
           }
       }
       if (taskPatientDetailDO.getCouponTotal() !=0 && taskPatientDetailDO.getCouponTotal() != null && exchangeGoodsDO.getCoupon() !=null){
           if (taskPatientDetailDO.getCouponTotal() < exchangeGoodsDO.getCoupon()){
               throw new Exception("活动劵余额不足!");
           }else {
               taskPatientDetailDO.setCouponTotal(taskPatientDetailDO.getCouponTotal() - exchangeGoodsDO.getCoupon());
           }
       }
       /*if (exchangeGoodsDO.getCoupon() == null){
           if (accountDO.getTotal() == null ){
               throw new Exception("积分余额不足!");
           }else {
               accountDO.setTotal(accountDO.getTotal()-exchangeGoodsDO.getIntegrate());
           }
       }else if (exchangeGoodsDO.getIntegrate() == null){
           if (accountDO.getCouponTotal() == null){
               throw new Exception("活动劵余额不足!");
           }else {
               accountDO.setCouponTotal(accountDO.getCouponTotal()-exchangeGoodsDO.getCoupon());
           }
       }*/
       exchangeGoodsDO.setCreateTime(new Date());
       exchangeGoodsDO.setUpdateTime(new Date());
       exchangeGoodsDO.setSaasId("dev");
       exchangeGoodsDO.setStatus(1);
       exchangeGoodsDO = exchangeGoodsDao.save(exchangeGoodsDO);
       envelop.setObj(exchangeGoodsDO);
       CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
       creditsDetailDO.setCoupon(exchangeGoodsDO.getCoupon());
       creditsDetailDO.setIntegrate(exchangeGoodsDO.getIntegrate());
       creditsDetailDO.setSaasId("dev");
       creditsDetailDO.setAccountId(accountDO.getId());
       creditsDetailDO.setTradeDirection(-1);
       creditsDetailDO.setStatus(1);
       creditsDetailDO.setTradeType("EXCHANGE_GOODS");
       creditsDetailDO.setIdCard(accountDO.getIdCard());
       creditsDetailDO.setHospital(exchangeGoodsDO.getHospital());
       creditsDetailDO.setHospitalName(exchangeGoodsDO.getHospitalName());
       creditsDetailDO.setTransactionId(exchangeGoodsDO.getId());
       creditsDetailDO.setPatientId(exchangeGoodsDO.getPatientId());
       creditsDetailDO.setCreateTime(new Date());
       creditsDetailDO.setUpdateTime(new Date());
       credittsLogDetailDao.save(creditsDetailDO);
       taskPatientDetailDao.save(taskPatientDetailDO);
       /*accountDao.save(accountDO);*/
       return envelop;
    }
    /**
     * find exchange goods info
@ -84,7 +124,7 @@ public class ExchangeGoodsService extends BaseJpaService<ExchangeGoodsDO,Exchang
        List<ExchangeGoodsDO> exchangeGoodsDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ExchangeGoodsDO.class));
        List<ExchangeGoodsDO> exchangeGoodsDOList = new ArrayList<>();
        for (ExchangeGoodsDO exchangeGoodsDO1:exchangeGoodsDOS){
            GoodsDO goodsDO = goodsDao.findOne(exchangeGoodsDO1.getGoodsId());
            GoodsDO goodsDO = goodsDao.findOne(exchangeGoodsDO1.getActivityGoodsId());
            exchangeGoodsDO1.setGoodsDO(goodsDO);
            exchangeGoodsDOList.add(exchangeGoodsDO1);
        }
@ -96,4 +136,7 @@ public class ExchangeGoodsService extends BaseJpaService<ExchangeGoodsDO,Exchang
        }
        return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success,exchangeGoodsDOList,page,size,count);
    }
}

+ 1 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/TaskDetailService.java

@ -37,6 +37,7 @@ public class TaskDetailService extends BaseJpaService<TaskPatientDetailDO,TaskPa
     * @return
     */
    public MixEnvelop<Boolean, Boolean> insert(TaskPatientDetailDO taskPatientDetailDO){
        taskPatientDetailDO.setCouponTotal(0L);
        taskPatientDetailDao.save(taskPatientDetailDO);
        MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
        envelop.setObj(true);

+ 3 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/TaskGoodsService.java

@ -3,6 +3,7 @@ package com.yihu.jw.service;/**
 */
import com.yihu.jw.dao.TaskGoodsDao;
import com.yihu.jw.entity.health.bank.ExchangeGoodsDO;
import com.yihu.jw.entity.health.bank.TaskGoodsDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
@ -82,4 +83,6 @@ public class TaskGoodsService extends BaseJpaService<TaskGoodsDO,TaskGoodsDao> {
        envelop.setObj(true);
        return envelop;
    }
}

+ 23 - 4
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/TaskPatientDtailService.java

@ -6,10 +6,7 @@ import com.yihu.jw.dao.AccountDao;
import com.yihu.jw.dao.ActivityDao;
import com.yihu.jw.dao.TaskDao;
import com.yihu.jw.dao.TaskPatientDetailDao;
import com.yihu.jw.entity.health.bank.AccountDO;
import com.yihu.jw.entity.health.bank.TaskDO;
import com.yihu.jw.entity.health.bank.TaskPatientDetailDO;
import com.yihu.jw.entity.health.bank.TaskRangDO;
import com.yihu.jw.entity.health.bank.*;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.util.ISqlUtils;
@ -92,6 +89,7 @@ public class TaskPatientDtailService extends BaseJpaService<TaskPatientDetailDO,
            }
            accountDO.setAccountName(taskPatientDetailDO.getName());
            accountDO.setTotal(0);
            accountDO.setCouponTotal(0L);
            accountDO.setPatientId(taskPatientDetailDO.getPatientId());
            accountDO.setCardNumber(taskPatientDetailDO.getPatientIdcard());
            accountDO.setHospital(taskPatientDetailDO.getHospital());
@ -117,6 +115,7 @@ public class TaskPatientDtailService extends BaseJpaService<TaskPatientDetailDO,
        for (TaskDO taskDO : taskDOList){
            taskPatientDetailDO.setTotal(Long.parseLong("0"));
            taskPatientDetailDO.setTaskId(taskDO.getId());
            taskPatientDetailDO.setCouponTotal(0L);
            taskPatientDetailDao.save(taskPatientDetailDO);
        }
        envelop.setObj(true);
@ -157,4 +156,24 @@ public class TaskPatientDtailService extends BaseJpaService<TaskPatientDetailDO,
        logger.info("参与信息:"+taskPatientDetailDOS);
        return taskPatientDetailDOS.get(0);
    }
    /**
     * 获取参与详情
     *
     * @param page
     * @param size
     * @return
     */
    public List<TaskPatientDetailDO> select(Integer page,Integer size){
        String sql ="SELECT * FROM `wlyy_health_bank_task_patient_detail` btpd " +
                "GROUP BY btpd.activity_id, btpd.patient_id ORDER BY btpd.create_time limit "+(page-1)*size+","+size;
        List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        for (TaskPatientDetailDO taskPatientDetailDO : taskPatientDetailDOS){
            ActivityDO activityDO = activityDao.selectById(taskPatientDetailDO.getActivityId());
            taskPatientDetailDO.setActivityDO(activityDO);
        }
        return taskPatientDetailDOS;
    }
}

+ 29 - 0
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/util/DateUtils.java

@ -4,6 +4,7 @@ package com.yihu.jw.util;/**
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
@ -56,4 +57,32 @@ public  class DateUtils {
        }
        return null;
    }
    /**
     * 获取两天时间相差的
     *
     * @param endDate
     * @param nowDate
     * @return
     */
    public static String getDatePoor(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long diff = endDate.getTime() - nowDate.getTime();
        long day = diff / nd;//计算相差多少天
        long hour = diff % nd / nh;//计算相差多少小时
        long min = diff % nd % nh / nm;//计算相差多少分钟
        return day+"h "+hour+" h"+min+" m";
    }
}

+ 2 - 0
svr/svr-wlyy-health-bank/src/main/resources/application.yml

@ -1,6 +1,8 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主  git上 svr-base ->  git application ->本地 appliction ->本地 bootstarp
server:
  port: 10051
  tomcat:
    max-http-header-size: 102400
spring:
  jmx: