yeshijie 4 years ago
parent
commit
6c4e753963

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

@ -123,7 +123,6 @@ public class AccountDO extends UuidIdentityEntityWithOperator implements Seriali
        this.usedTotal = usedTotal;
    }
    @Convert(converter = StringFStringEncryptConverter.class)
    public String getPassword() {
        return password;
    }
@ -132,7 +131,6 @@ public class AccountDO extends UuidIdentityEntityWithOperator implements Seriali
        this.password = password;
    }
    @Convert(converter = StringFStringEncryptConverter.class)
    public String getCardNumber() {
        return cardNumber;
    }

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

@ -111,6 +111,7 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.patientId = patientId;
    }
    @Convert(converter = StringFStringEncryptConverter.class)
    public String getPatientIdcard() {
        return patientIdcard;
    }
@ -119,7 +120,6 @@ public class TaskPatientDetailDO extends UuidIdentityEntityWithOperator implemen
        this.patientIdcard = patientIdcard;
    }
    @Convert(converter = StringFStringEncryptConverter.class)
    public String getPatientOpenid() {
        return patientOpenid;
    }

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

@ -3,11 +3,13 @@ package com.yihu.jw.dao;/**
 */
import com.yihu.jw.entity.health.bank.AccountDO;
import com.yihu.jw.entity.health.bank.ActivityRuleDO;
import com.yihu.jw.entity.health.bank.ActivityDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-05-10 11:15
@ -16,4 +18,10 @@ import org.springframework.data.repository.PagingAndSortingRepository;
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);
    @Query("select t from AccountDO t where t.patientId=?1 and t.status=1")
    List<AccountDO> selectsByPatientId(String patientId);
    @Query("select t from AccountDO t where t.patientId=?1")
    List<AccountDO> findByPatientId(String patientId);
}

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

@ -17,9 +17,14 @@ 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 patientOpenid = ?2")
    List<TaskPatientDetailDO> selectByTaskIdAndOpenid(String taskId,String openId);
    @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 taskId = ?1 and patientId =?2")
    List<TaskPatientDetailDO> selectByTaskIdAndPatientId2(String taskId,String patientId);
    @Query("select t from TaskPatientDetailDO t where activityId = ?1 and patientId =?2")
    TaskPatientDetailDO selectByActivityIdAndPatientId(String activityId,String patientId);

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

@ -9,11 +9,11 @@ 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.TaskRuleDO;
import com.yihu.jw.entity.util.AesEncryptUtils;
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.TransforSqlUtl;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
@ -131,6 +131,7 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
                buffer.deleteCharAt(buffer.length()-1);
                buffer.append(") ");
                String accountSql = "select * from wlyy_health_bank_account where patient_id in "+buffer;
                accountSql = TransforSqlUtl.wlyyHealthBankAccountAll(accountSql);
                List<AccountDO> accountDOSList = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper<>(AccountDO.class));
                if (accountDOSList != null && accountDOSList.size() !=0){
                    String sql2 = " SELECT " +
@ -171,19 +172,9 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
                            " ( " +
                            " SELECT " +
                            " ba.id AS id, " +
                            " ba.total /*+ COALESCE (bacd1.sum, 0)*/ AS sum " +
                            " ba.total AS sum " +
                            " FROM " +
                            " wlyy_health_bank_account ba " +
                            /*" LEFT JOIN ( " +
                            " SELECT " +
                            " COALESCE (SUM(bacd.integrate), 0) AS sum, " +
                            " bacd.account_id " +
                            "  FROM " +
                            " wlyy_health_bank_credits_detail bacd " +
                            " WHERE " +
                            " bacd.trade_direction = - 1 " +
                            " GROUP BY " +
                            " bacd.account_id ) bacd1 ON ba.id = bacd1.account_id "+*/
                            " WHERE " +
                            " ba.id IN " +buffer1+
                            " )ba1 WHERE ba1.sum > "+accountDO1.getSum();
@ -204,19 +195,9 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
                            " ( " +
                            " SELECT " +
                            " ba.id AS id, " +
                            " ba.total /*+ COALESCE (bacd1.sum, 0)*/ AS sum " +
                            " ba.total AS sum " +
                            " FROM " +
                            " wlyy_health_bank_account ba " +
                            /*" LEFT JOIN ( " +
                            " SELECT " +
                            " COALESCE (SUM(bacd.integrate), 0) AS sum, " +
                            " bacd.account_id " +
                            "  FROM " +
                            " wlyy_health_bank_credits_detail bacd " +
                            " WHERE " +
                            " bacd.trade_direction = - 1 " +
                            " GROUP BY " +
                            " bacd.account_id ) bacd1 ON ba.id = bacd1.account_id " +*/
                            " )ba1 WHERE ba1.sum > "+accountDO1.getSum();
                    List<Map<String,Object>> rstotal5 = jdbcTemplate.queryForList(sql4);
                    Integer Count2 = 0;
@ -251,8 +232,9 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
    public MixEnvelop<AccountDO, AccountDO> findByCondition1(JSONArray patients, String ruleId, Integer page, Integer size){
        for (int i=0;i<patients.size();i++){
            String patientId = patients.getJSONObject(i).getString("code");
            String sql = "select * from wlyy_health_bank_account where patient_id = '"+patientId+"'";
            List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
//            String sql = "select * from wlyy_health_bank_account where patient_id = '"+patientId+"'";
//            List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
            List<AccountDO> accountDOS = accountDao.findByPatientId(patientId);
            if (accountDOS == null || accountDOS.size() == 0) {
                AccountDO accountDO1 = new AccountDO();
                accountDO1.setPatientId(patientId);
@ -318,7 +300,7 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
        String sql =
                "SELECT ba1.patient_id AS patient_id," +
                        "AES_DECRYPT(from_base64(ba1.account_name,"+ AesEncryptUtils.KEY+") AS account_name," +
                        "ba1.account_name AS account_name," +
                        "ba1.hospital AS hospital," +
                        "ba1.total AS total," +
                        "ba1.create_time AS create_time," +
@ -349,6 +331,7 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
                        "LIMIT "+(page-1)*size+","+size +")ba1" +
                        " ORDER BY " +
                        " ba1.sum DESC";
        sql = TransforSqlUtl.accountName(sql);
        List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
        String sqlCount = "SELECT count(1) AS total"+
                " FROM " +
@ -384,8 +367,9 @@ public class AccountService extends BaseJpaService<AccountDO,AccountDao> {
     */
    public MixEnvelop<AccountDO, AccountDO> selectByPatient(String patient,String name,String hospital,String hospitalName,String idcard){
        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));
//        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));
        List<AccountDO> accountDOS = accountDao.selectsByPatientId(patient);
        if (accountDOS == null || accountDOS.size()==0){
            AccountDO accountDO = new AccountDO();
            accountDO.setTotal(0);

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

@ -12,6 +12,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.TransforSqlUtl;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
@ -170,75 +171,75 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
            accountDO = accountDao.save(accountDO);
        }
        ActivityDO activityDO = activityDao.selectByTemplateIdAndType(planCode,"健康计划");
       if (activityDO==null){
           activityDO = new ActivityDO();
           activityDO.setStatus(1);
           activityDO.setSaasId("dev");
           activityDO.setCreateTime(new Date());
           activityDO.setUpdateTime(new Date());
           activityDO.setOrganizer("SYSTEM");
           activityDO.setTitle(templateName);
           activityDO.setType("健康计划");
           activityDO.setDescription(templateName);
           activityDO.setGlobelTemplate(planCode);
           activityDO.setIntroduction(templateName);
           activityDO.setIsFlag(-1);
           activityDO.setDelFlag(1);
           activityDO =  activityDao.save(activityDO);
           TaskDO taskDO = new TaskDO();
           taskDO.setSaasId("dev");
           taskDO.setCreateTime(new Date());
           taskDO.setUpdateTime(new Date());
           taskDO.setTitle(templateName);
           taskDO.setType("ACTIVITY_TASK");
           taskDO.setTaskCode("ACTIVITY_PLAN");
           taskDO.setTransactionId(activityDO.getId());
           taskDO.setContent(templateName);
           taskDO.setStatus(1);
           taskDO = taskDao.save(taskDO);
           TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(taskDO.getId(),patient);
           if (taskPatientDetailDO==null){
               taskPatientDetailDO = new TaskPatientDetailDO();
               taskPatientDetailDO.setSaasId("dev");
               taskPatientDetailDO.setTaskId(taskDO.getId());
               taskPatientDetailDO.setActivityId(activityDO.getId());
               taskPatientDetailDO.setPatientIdcard(idcard);
               taskPatientDetailDO.setPatientId(patient);
               taskPatientDetailDO.setHospital(hospital);
               taskPatientDetailDO.setHospitalName(hospitalName);
               taskPatientDetailDO.setCreateTime(new Date());
               taskPatientDetailDO.setUpdateTime(new Date());
               taskPatientDetailDO.setTotal(0L);
               taskPatientDetailDO.setCouponTotal(0L);
               taskPatientDetailDO.setStatus(1);
               taskPatientDetailDao.save(taskPatientDetailDO);
           }
       }else {
           List<TaskDO> taskDOS = taskDao.selectByActivityId(activityDO.getId());
           if (taskDOS!=null&&taskDOS.size()!=0){
               TaskDO taskDO = taskDOS.get(0);
               TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(taskDO.getId(),patient);
               if (taskPatientDetailDO==null){
                   taskPatientDetailDO = new TaskPatientDetailDO();
                   taskPatientDetailDO.setSaasId("dev");
                   taskPatientDetailDO.setTaskId(taskDO.getId());
                   taskPatientDetailDO.setActivityId(activityDO.getId());
                   taskPatientDetailDO.setPatientIdcard(idcard);
                   taskPatientDetailDO.setPatientId(patient);
                   taskPatientDetailDO.setHospital(hospital);
                   taskPatientDetailDO.setHospitalName(hospitalName);
                   taskPatientDetailDO.setCreateTime(new Date());
                   taskPatientDetailDO.setUpdateTime(new Date());
                   taskPatientDetailDO.setTotal(0L);
                   taskPatientDetailDO.setCouponTotal(0L);
                   taskPatientDetailDO.setStatus(1);
                   taskPatientDetailDao.save(taskPatientDetailDO);
               }
           }
        if (activityDO==null){
            activityDO = new ActivityDO();
            activityDO.setStatus(1);
            activityDO.setSaasId("dev");
            activityDO.setCreateTime(new Date());
            activityDO.setUpdateTime(new Date());
            activityDO.setOrganizer("SYSTEM");
            activityDO.setTitle(templateName);
            activityDO.setType("健康计划");
            activityDO.setDescription(templateName);
            activityDO.setGlobelTemplate(planCode);
            activityDO.setIntroduction(templateName);
            activityDO.setIsFlag(-1);
            activityDO.setDelFlag(1);
            activityDO =  activityDao.save(activityDO);
            TaskDO taskDO = new TaskDO();
            taskDO.setSaasId("dev");
            taskDO.setCreateTime(new Date());
            taskDO.setUpdateTime(new Date());
            taskDO.setTitle(templateName);
            taskDO.setType("ACTIVITY_TASK");
            taskDO.setTaskCode("ACTIVITY_PLAN");
            taskDO.setTransactionId(activityDO.getId());
            taskDO.setContent(templateName);
            taskDO.setStatus(1);
            taskDO = taskDao.save(taskDO);
            TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(taskDO.getId(),patient);
            if (taskPatientDetailDO==null){
                taskPatientDetailDO = new TaskPatientDetailDO();
                taskPatientDetailDO.setSaasId("dev");
                taskPatientDetailDO.setTaskId(taskDO.getId());
                taskPatientDetailDO.setActivityId(activityDO.getId());
                taskPatientDetailDO.setPatientIdcard(idcard);
                taskPatientDetailDO.setPatientId(patient);
                taskPatientDetailDO.setHospital(hospital);
                taskPatientDetailDO.setHospitalName(hospitalName);
                taskPatientDetailDO.setCreateTime(new Date());
                taskPatientDetailDO.setUpdateTime(new Date());
                taskPatientDetailDO.setTotal(0L);
                taskPatientDetailDO.setCouponTotal(0L);
                taskPatientDetailDO.setStatus(1);
                taskPatientDetailDao.save(taskPatientDetailDO);
            }
        }else {
            List<TaskDO> taskDOS = taskDao.selectByActivityId(activityDO.getId());
            if (taskDOS!=null&&taskDOS.size()!=0){
                TaskDO taskDO = taskDOS.get(0);
                TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(taskDO.getId(),patient);
                if (taskPatientDetailDO==null){
                    taskPatientDetailDO = new TaskPatientDetailDO();
                    taskPatientDetailDO.setSaasId("dev");
                    taskPatientDetailDO.setTaskId(taskDO.getId());
                    taskPatientDetailDO.setActivityId(activityDO.getId());
                    taskPatientDetailDO.setPatientIdcard(idcard);
                    taskPatientDetailDO.setPatientId(patient);
                    taskPatientDetailDO.setHospital(hospital);
                    taskPatientDetailDO.setHospitalName(hospitalName);
                    taskPatientDetailDO.setCreateTime(new Date());
                    taskPatientDetailDO.setUpdateTime(new Date());
                    taskPatientDetailDO.setTotal(0L);
                    taskPatientDetailDO.setCouponTotal(0L);
                    taskPatientDetailDO.setStatus(1);
                    taskPatientDetailDao.save(taskPatientDetailDO);
                }
            }
       }
       envelop.setObj(activityDO);
       return envelop;
        }
        envelop.setObj(activityDO);
        return envelop;
    }
@ -274,10 +275,9 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
            activityDO1.setTotal(count);
            String taskSql1 = "select * from wlyy_health_bank_task_patient_detail btpd where activity_id = '"+activityDO1.getId()
                    +"' and (patient_idcard = '"+ AesEncryptUtils.encrypt(activityDO.getPatientIdcard())+"' OR union_id = '"+activityDO.getUnionId()+"')";
            taskSql1 = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(taskSql1);
            List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
            for (TaskPatientDetailDO taskPatientDetailDO : taskPatientDetailDOS){
                taskPatientDetailDO.setPatientIdcard(AesEncryptUtils.decrypt(taskPatientDetailDO.getPatientIdcard()));
            }
            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));
@ -534,31 +534,31 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
     */
    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);
        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;
    }
@ -795,7 +795,7 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
                " 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 " +
                " 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+"')" +
                " ORDER BY btpd1.sum desc "+
                " limit "+countTotal1+",1" ;

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

@ -11,6 +11,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.TransforSqlUtl;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.Logger;
@ -70,13 +71,13 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
    @Value("${account.initPassword}")
    private String initPassword;
   /**
    /**
     *  find creditsLogInfo
     *
     * @return
     * @throws ParseException
     */
   public MixEnvelop<CreditsDetailDO, CreditsDetailDO> findByCondition(CreditsDetailDO creditsDetailDO, Integer page, Integer size) throws ParseException {
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> findByCondition(CreditsDetailDO creditsDetailDO, Integer page, Integer size) throws ParseException {
        String sql = new ISqlUtils().getSql(creditsDetailDO,page,size,"*");
        List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
        for (CreditsDetailDO creditsDetailDO1 : creditsDetailDOS){
@ -248,20 +249,6 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
        return MixEnvelop.getSuccess(HealthBankMapping.api_success,accountDO);
    }
    /*
    public Envelop<Boolean> exchangeGoods(GoodsDO goodsDO){
        CreditsDetailDO creditsLogDetailDO = new CreditsDetailDO();
        Envelop<Boolean> envelop = new Envelop<>();
        envelop.setObj(true);
        return envelop;
    }
*/
    public MixEnvelop<AccountDO, AccountDO> selectByRanking(List<String> patientIds, Integer page, Integer size){
        StringBuffer buffer = new StringBuffer();
        buffer.append(" ba.patient_id in(");
@ -276,7 +263,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
        buffer.append(") ");
        String sql =
                "SELECT ba1.patient_id AS patient_id," +
                        "AES_DECRYPT(from_base64(ba1.account_name,"+ AesEncryptUtils.KEY+") AS account_name," +
                        "ba1.account_name AS account_name," +
                        "ba1.hospital AS hospital," +
                        "ba1.total AS total," +
                        "ba1.create_time AS create_time," +
@ -307,6 +294,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                        " ORDER BY " +
                        " ba1.total DESC"+
                        " LIMIT "+(page-1)*size+","+size ;
        sql = TransforSqlUtl.accountName(sql);
        List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
        String sqlCount = "SELECT count(1) AS total"+
                " FROM " +
@ -344,8 +332,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> insert(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));
//                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));
                List<AccountDO> accountDOList = accountDao.findByPatientId(creditsDetailDO.getPatientId());
                if (accountDOList != null && accountDOList.size() != 0){
                    creditsDetailDO.setAccountId(accountDOList.get(0).getId());
                }else {
@ -366,7 +355,8 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                    accountDO1.setCreateTime(new Date());
                    accountDO1.setUpdateTime(new Date());
                    accountDao.save(accountDO1);
                    List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
                    List<AccountDO> accountDOS = accountDao.findByPatientId(creditsDetailDO.getPatientId());
//                    List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
                    creditsDetailDO.setAccountId(accountDOS.get(0).getId());
                }
                TaskDO taskDO = new TaskDO();
@ -381,8 +371,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                TaskRuleDO taskRuleDO = taskRuleDOS.get(0);
                creditsDetailDO.setIntegrate(taskRuleDO.getIntegrate());
                creditsDetailDO.setTradeDirection(taskRuleDO.getTradeDirection());
                String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDOList.get(0).getId()+"' and patient_id = '" + creditsDetailDO.getPatientId() +"'";
                List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
//                String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDOList.get(0).getId()+"' and patient_id = '" + creditsDetailDO.getPatientId() +"'";
//                List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                List<TaskPatientDetailDO> taskPatientDetailDOS = taskPatientDetailDao.selectByTaskIdAndPatientId2(taskDOList.get(0).getId(),creditsDetailDO.getPatientId());
                if (taskPatientDetailDOS == null || taskPatientDetailDOS.size() ==0){
                    TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
                    taskPatientDetailDO.setTaskId(creditsDetailDO.getTransactionId());
@ -400,6 +391,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                }else if (taskPatientDetailDOS != null && taskDOList.get(0).getPeriod() == 0){
                    String taskSql1 = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDOList.get(0).getId()+
                            "' and patient_id = '"+creditsDetailDO.getPatientId()+"' and create_time > '" + DateUtils.getDayBegin() +"' and create_time < '"+ DateUtils.getDayEnd() +"'";
                    taskSql1 = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(taskSql1);
                    List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                    if (taskPatientDetailDOS1 == null || taskPatientDetailDOS1.size() == 0){
                        TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
@ -508,8 +500,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                " ORDER BY btpd1.total DESC "+" LIMIT " + (page-1)*size+","+size;
        List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
        for (TaskPatientDetailDO taskPatientDetailDO : taskPatientDetailDOS){
            String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
            List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
//            String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
//            List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
            List<AccountDO> accountDOS = accountDao.findByPatientId(taskPatientDetailDO.getPatientId());
            taskPatientDetailDO.setAccountDO(accountDOS.get(0));
        }
        String sqlCount =  "SELECT " +
@ -632,28 +625,10 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
        logger.info(taskPatientDetailDOS.toString()+""+taskPatientDetailDOS.size());
        for (int i = 0;taskPatientDetailDOS != null&&taskPatientDetailDOS.size()!=0 && i<taskPatientDetailDOS.size();i++){
            TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDOS.get(i);
            String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
            List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
//            String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
//            List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
            List<AccountDO> accountDOS = accountDao.findByPatientId(taskPatientDetailDO.getPatientId());
            if (taskPatientDetailDOS.get(i).getPatientId().equalsIgnoreCase(patientId)){
                /*String taskSql = "select count(1)+1 as total from (" +
                        "select *  from (SELECT " +
                        " SUM(ptpd.total) AS total, " +
                        " ptpd.patient_openid AS patient_openid, " +
                        " ptpd.task_id AS task_id, " +
                        " ptpd.activity_id AS activity_id, " +
                        " ptpd.create_time as create_time, " +
                        " ptpd.patient_id AS patient_id " +
                        " FROM " +
                        " wlyy_health_bank_task_patient_detail ptpd " +
                        " WHERE " +
                        " activity_id = '" + activityId + "')ptpd1 where" +
                        " ptpd1.patient_id = '"+patientId+"' AND ptpd1.total > "+taskPatientDetailDOS.get(i).getTotal()+") ptpd2";
                List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(taskSql);
                Long count = 0L;
                if(rstotal1!=null&&rstotal1.size()>0){
                    count = (Long) rstotal1.get(0).get("total");
                }
                accountDOS.get(0).setActivityRanking(count);*/
                taskPatientDetailDO.setIsFlag(1);
            }else {
                taskPatientDetailDO.setIsFlag(0);
@ -730,25 +705,28 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                taskDO1 = taskDOList.get(0);
            }
            if (taskRuleDO.getPeriod() == 1){
                    String sql = "select * from wlyy_health_bank_task_patient_detail where patient_id = '"+patientId+"'AND task_id ='"+taskDO1.getId()+"'";
                    List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                    if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
                        throw new Exception("已奖励过");
                    }
//                    String sql = "select * from wlyy_health_bank_task_patient_detail where patient_id = '"+patientId+"'AND task_id ='"+taskDO1.getId()+"'";
//                    List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                List<TaskPatientDetailDO> taskPatientDetailDOS = taskPatientDetailDao.selectByTaskIdAndPatientId2(taskDO1.getId(),patientId);
                if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
                    throw new Exception("已奖励过");
                }
            }else if (taskRuleDO.getPeriod() == 0){
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = new Date();
                    String date1 = dateFormat.format(date);
                    String begin = DateUtils.getMinMonthDate(date1);
                    String end = DateUtils.getMaxMonthDate(date1);
                    String sql = "select * from wlyy_health_bank_task_patient_detail where patient_id = '"+patientId+"'AND task_id ='"+taskDO1.getId()+"' AND create_time > '"+begin+"' AND create_time < '"+end+"'";
                    List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                    if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
                        throw new Exception("已奖励过");
                    }
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date date = new Date();
                String date1 = dateFormat.format(date);
                String begin = DateUtils.getMinMonthDate(date1);
                String end = DateUtils.getMaxMonthDate(date1);
                String sql = "select * from wlyy_health_bank_task_patient_detail where patient_id = '"+patientId+"'AND task_id ='"+taskDO1.getId()+"' AND create_time > '"+begin+"' AND create_time < '"+end+"'";
                sql = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(sql);
                List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
                    throw new Exception("已奖励过");
                }
            }
            String sql1 = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+"' " +
                    "AND patient_idcard = '"+AesEncryptUtils.encrypt(idCard)+"' AND patient_openid = '"+openId+"' AND union_id = '"+unionId+"'";
                    "AND patient_idcard = '"+ AesEncryptUtils.decrypt(idCard) +"' AND patient_openid = '"+openId+"' AND union_id = '"+unionId+"'";
            sql1 = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(sql1);
            List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
            TaskPatientDetailDO taskPatientDetailDO1 = new TaskPatientDetailDO();
            if (taskPatientDetailDOS.isEmpty() && taskPatientDetailDOS.size() == 0){
@ -767,8 +745,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
            }else {
                taskPatientDetailDO1 = taskPatientDetailDOS.get(0);
            }
            String sql = "select * from wlyy_health_bank_account where patient_id = '"+patientId+"'";
            List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
//            String sql = "select * from wlyy_health_bank_account where patient_id = '"+patientId+"'";
//            List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
            List<AccountDO> accountDOS = accountDao.findByPatientId(patientId);
            if (taskRuleDO.getTradeDirection() == -1 && 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'))";
@ -849,46 +828,12 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
        return envelop;
    }
    /**
     * 固定数据
     *
     * @param
     * @return
     *//*
    public List<TaskDO> getTasks(String patientId){
        List<TaskDO> taskDOList = new ArrayList<>();
        TaskDO taskDO = new TaskDO();
        *//*taskDO.setPatientId(patientId);*//*
        taskDO.setTaskCode("BIND");
        taskDO.setPeriod(1);
        taskDO.setTaskTitle("首次绑定");
        taskDO.setTaskContent("(绑定社区登记发放的设备,可获得各类型设备的首绑奖励。)");
        taskDO.setTradeType("activity");
        taskDO.setTransactionId("402885e96324a409016324c0a45a0006");
        taskDO.setCreateTime(new Date());
        taskDO.setUpdateTime(new Date());
        taskDOList.add(taskDO);
        TaskDO taskDO1 = new TaskDO();
        *//*taskDO1.setPatientId(patientId);*//*
        taskDO1.setTaskCode("MEASURE");
        taskDO1.setPeriod(0);
        taskDO1.setTaskTitle("每日测量");
        taskDO1.setTaskContent("(使用社区发放的已关联您身份信息的设备,绑定后每天完成测量)");
        taskDO1.setTradeType("activity");
        taskDO1.setTransactionId("402885e96324a409016324c0a45a0006");
        taskDO1.setCreateTime(new Date());
        taskDO1.setUpdateTime(new Date());
        taskDOList.add(taskDO1);
        return taskDOList;
    }
*/
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> stepAddIntegrate(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));
//                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));
                List<AccountDO> accountDOList = accountDao.findByPatientId(creditsDetailDO.getPatientId());
                if (accountDOList != null && accountDOList.size() != 0){
                    creditsDetailDO.setAccountId(accountDOList.get(0).getId());
                }else {
@ -910,11 +855,13 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                    accountDO1.setCreateTime(new Date());
                    accountDO1.setUpdateTime(new Date());
                    accountDao.save(accountDO1);
                    List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
                    List<AccountDO> accountDOS = accountDao.findByPatientId(creditsDetailDO.getPatientId());
//                    List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
                    creditsDetailDO.setAccountId(accountDOS.get(0).getId());
                }
                String sql1 = "select *  from wlyy_health_bank_task_patient_detail where "+
                        " patient_idcard = '"+AesEncryptUtils.encrypt(creditsDetailDO.getIdCard())+"' AND union_id = '"+creditsDetailDO.getUnionId()+"' AND task_id = '"+creditsDetailDO.getTransactionId()+"'";
                        " patient_idcard = '"+ AesEncryptUtils.encrypt(creditsDetailDO.getIdCard()) +"' AND union_id = '"+creditsDetailDO.getUnionId()+"' AND task_id = '"+creditsDetailDO.getTransactionId()+"'";
                sql1 = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(sql1);
                List<TaskPatientDetailDO> taskPatientDetailDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                if(taskPatientDetailDOList == null || taskPatientDetailDOList.size()==0){
                    throw new Exception("该居民参与活动查不到!");
@ -988,100 +935,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                        }
                    }
                }
          /*  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());
                    if (creditsDetailDO.getStepNumber() < step1 && creditsDetailDO.getStepNumber() >0){
                        creditsDetailDO1.setIntegrate(0);
                        creditsDetailDO1.setTradeDirection(1);
                        CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
                        AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
                        accountDO.setTotal(accountDO.getTotal()+creditsDetailDO2.getIntegrate());
                        AccountDO accountDO1 = accountDao.save(accountDO);
                        creditsDetailDO2.setTotal(accountDO1.getTotal());
                        taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+creditsDetailDO2.getIntegrate());
                        taskPatientDetailDao.save(taskPatientDetailDO);
                        creditsDetailDOS.clear();
                        creditsDetailDOS.add(creditsDetailDO2);
                    }else if (creditsDetailDO.getStepNumber() >= step1 && creditsDetailDO.getStepNumber() < step2){
                        creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+1);
                        creditsDetailDO1.setTradeDirection(1);
                        CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
                        AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
                        accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()));
                        AccountDO accountDO1 = accountDao.save(accountDO);
                        creditsDetailDO2.setTotal(accountDO1.getTotal());
                        taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()));
                        taskPatientDetailDao.save(taskPatientDetailDO);
                        creditsDetailDOS.clear();
                        creditsDetailDOS.add(creditsDetailDO2);
                    }else if (creditsDetailDO.getStepNumber() >= step2){
                        if (creditsDetailDO1.getIntegrate() == 1){
                            creditsDetailDO1.setIntegrate(2);
                            creditsDetailDO1.setTradeDirection(1);
                            CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
                            AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
                            accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
                            AccountDO accountDO1 = accountDao.save(accountDO);
                            creditsDetailDO2.setTotal(accountDO1.getTotal());
                            taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
                            taskPatientDetailDao.save(taskPatientDetailDO);
                            creditsDetailDOS.clear();
                            creditsDetailDOS.add(creditsDetailDO2);
                        }*//*else if(creditsDetailDO1.getIntegrate() == 3){
                            creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+5);
                            creditsDetailDO1.setTradeDirection(1);
                            CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
                            AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
                            accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()-3));
                            AccountDO accountDO1 = accountDao.save(accountDO);
                            creditsDetailDO2.setTotal(accountDO1.getTotal());
                            taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()-3));
                            taskPatientDetailDao.save(taskPatientDetailDO);
                            creditsDetailDOS.clear();
                            creditsDetailDOS.add(creditsDetailDO2);
                        }*//*
                    }
                }else{
                    CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
                    if (creditsDetailDO.getStepNumber() < step1 && creditsDetailDO.getStepNumber() >0){
                        creditsDetailDO1.setIntegrate(0);
                        creditsDetailDO1.setTradeDirection(1);
                    }else if (creditsDetailDO.getStepNumber() >= step1 && creditsDetailDO.getStepNumber() < step2){
                        creditsDetailDO1.setIntegrate(1);
                        creditsDetailDO1.setTradeDirection(1);
                    }else if (creditsDetailDO.getStepNumber() >=step2){
                        creditsDetailDO1.setIntegrate(2);
                        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);
                }*/
              /*  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){
@ -1103,8 +957,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
        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));
//        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));
        List<AccountDO> accountDOs = accountDao.findByPatientId(patientId);
        AccountDO accountDO = null;
        if("add".equals(type)&&(accountDOs==null||accountDOs.size()==0)){
            //新建账户
@ -1130,106 +985,91 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
            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 (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("add".equals(type)){
           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{
           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);
        String sql = ""
        String step1 = systemDictDao.
        logger.info("数据库的数据:"+step1);
        if (step != null && step.equalsIgnoreCase(step1)){
            JSONObject jsonObject = JSONObject.parseObject(step);
            logger.info("数据不一致:"+jsonObject.toString());
            return jsonObject;
        }else {
            JSONObject jsonObject = JSONObject.parseObject(step);
            redisTemplate.opsForValue().set(STEP,step1);
            logger.info("数据一致:"+jsonObject.toString());
            return jsonObject;
        if("add".equals(type)){
            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{
            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 MixEnvelop<CreditsDetailDO, CreditsDetailDO> weekReward(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));
//                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));
                List<AccountDO> accountDOList = accountDao.findByPatientId(creditsDetailDO.getPatientId());
                if (accountDOList != null && accountDOList.size() != 0) {
                    creditsDetailDO.setAccountId(accountDOList.get(0).getId());
                }
@ -1460,8 +1300,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
    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));
//                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));
                List<AccountDO> accountDOList = accountDao.findByPatientId(creditsDetailDO.getPatientId());
                if (accountDOList != null && accountDOList.size() != 0) {
                    creditsDetailDO.setAccountId(accountDOList.get(0).getId());
                }
@ -1530,8 +1371,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                Boolean isShare = jsonObject.getBoolean("isshare");
                if (isShare){
                    JSONObject object = jsonObject.getJSONObject("shareData");
                    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));
//                    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));
                    List<AccountDO> accountDOList = accountDao.findByPatientId(creditsDetailDO.getPatientId());
                    CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
                    if (accountDOList != null && accountDOList.size() != 0) {
                        creditsDetailDO1.setAccountId(accountDOList.get(0).getId());
@ -1667,8 +1509,9 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
    public MixEnvelop<CreditsDetailDO, CreditsDetailDO> weekRewardAndIntegrate(CreditsDetailDO creditsDetailDO,Integer flag) {
        synchronized (creditsDetailDO.getPatientId()) {
            MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
            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));
//            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));
            List<AccountDO> accountDOList = accountDao.findByPatientId(creditsDetailDO.getPatientId());
            if (accountDOList != null && accountDOList.size() != 0) {
                creditsDetailDO.setAccountId(accountDOList.get(0).getId());
            }
@ -1804,7 +1647,7 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
                List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql1);
                String idcard = null;
                if (maps!=null&&maps.size()!=0){
                    idcard = AesEncryptUtils.decrypt(maps.get(0).get("idcard").toString());
                    idcard = maps.get(0).get("idcard").toString();
                    accountDO.setIdCard(idcard);
                }
                TaskDO taskDO = taskDao.selectById("5e5d857d684d77f201684d7f58b3000a132");

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

@ -11,6 +11,7 @@ import com.yihu.jw.entity.util.AesEncryptUtils;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.util.ISqlUtils;
import com.yihu.jw.util.TransforSqlUtl;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -77,8 +78,9 @@ public class TaskPatientDtailService extends BaseJpaService<TaskPatientDetailDO,
        taskPatientDetailDO.setCreateTime(new Date());
        taskPatientDetailDO.setUpdateTime(new Date());
        taskPatientDetailDO.setStatus(Integer.parseInt("0"));
        String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
        List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
//        String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
//        List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
        List<AccountDO> accountDOS = accountDao.findByPatientId(taskPatientDetailDO.getPatientId());
        if (accountDOS == null || accountDOS.size() ==0){
            AccountDO accountDO = new AccountDO();
            accountDO.setSaasId("dev");
@ -153,6 +155,7 @@ public class TaskPatientDtailService extends BaseJpaService<TaskPatientDetailDO,
        String sql ="select * from wlyy_health_bank_task_patient_detail where " +
                " (patient_idcard = '"+ AesEncryptUtils.encrypt(idCard)+"' OR union_id ='"+unionId+"') AND task_id IN " +
                "(select id from wlyy_health_bank_task where task_code = '"+taskCode+"' )";
        sql = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(sql);
        List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
        logger.info("参与信息:"+taskPatientDetailDOS);
        if (taskPatientDetailDOS!=null&&taskPatientDetailDOS.size()!=0){
@ -168,6 +171,7 @@ public class TaskPatientDtailService extends BaseJpaService<TaskPatientDetailDO,
        String sql ="select * from wlyy_health_bank_task_patient_detail where " +
                " (patient_idcard = '"+AesEncryptUtils.encrypt(idCard)+"' OR union_id ='"+unionId+"') AND task_id = '"+taskId+"'" ;
        sql = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(sql);
        List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
        logger.info("参与信息:"+taskPatientDetailDOS);
        return taskPatientDetailDOS.get(0);
@ -184,6 +188,7 @@ public class TaskPatientDtailService extends BaseJpaService<TaskPatientDetailDO,
    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;
        sql = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(sql);
        List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(TaskPatientDetailDO.class));
        for (TaskPatientDetailDO taskPatientDetailDO : taskPatientDetailDOS){
            ActivityDO activityDO = activityDao.selectById(taskPatientDetailDO.getActivityId());

+ 82 - 78
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/TaskService.java

@ -13,6 +13,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.TransforSqlUtl;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
@ -96,41 +97,42 @@ public class TaskService extends BaseJpaService<TaskDO,TaskDao> {
     * @param size 分页大小
     * @return
     */
   public MixEnvelop<TaskDO, TaskDO> selectByCondition(TaskDO taskDO, Integer page, Integer size){
       TaskDO taskDO2 = new TaskDO();
       String sql = new ISqlUtils().getSql(taskDO,page,size,"*");
       List<TaskDO> taskDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskDO.class));
       for (TaskDO taskDO1:taskDOS){
           if (taskDO1.getType()!= null && taskDO1.getType().equalsIgnoreCase("ACTIVITY_TASK")){
               ActivityDO activityDO = activityDao.findOne(taskDO1.getTransactionId());
               taskDO1.setActivityDO(activityDO);
           }
           TaskRuleDO taskRuleDO = taskRuleDao.findOne(taskDO1.getRuleCode());
           taskDO1.setRuleName(taskRuleDO.getName());
           //参与活动的详情
           String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+
                   "' and patient_openid = '"+taskDO.getOpenId()+"'";
           List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
           taskDO1.setTaskPatientDetailDOS(taskPatientDetailDOS);
           //参与人数
           String taskSql1 = "select count(1) as total from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+"'";
           List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(taskSql1);
           Long count = 0L;
           if(rstotal!=null&&rstotal.size()>0){
               count = (Long) rstotal.get(0).get("total");
           }
           taskDO1.setTotal(count);
           taskDO1.setPatientId(taskDO.getPatientId());
    public MixEnvelop<TaskDO, TaskDO> selectByCondition(TaskDO taskDO, Integer page, Integer size){
        TaskDO taskDO2 = new TaskDO();
        String sql = new ISqlUtils().getSql(taskDO,page,size,"*");
        List<TaskDO> taskDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskDO.class));
        for (TaskDO taskDO1:taskDOS){
            if (taskDO1.getType()!= null && taskDO1.getType().equalsIgnoreCase("ACTIVITY_TASK")){
                ActivityDO activityDO = activityDao.findOne(taskDO1.getTransactionId());
                taskDO1.setActivityDO(activityDO);
            }
            TaskRuleDO taskRuleDO = taskRuleDao.findOne(taskDO1.getRuleCode());
            taskDO1.setRuleName(taskRuleDO.getName());
            //参与活动的详情
//           String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+
//                   "' and patient_openid = '"+taskDO.getOpenId()+"'";
//           List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
            List<TaskPatientDetailDO> taskPatientDetailDOS = taskPatientDetailDao.selectByTaskIdAndOpenid(taskDO1.getId(),taskDO.getOpenId());
            taskDO1.setTaskPatientDetailDOS(taskPatientDetailDOS);
            //参与人数
            String taskSql1 = "select count(1) as total from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+"'";
            List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(taskSql1);
            Long count = 0L;
            if(rstotal!=null&&rstotal.size()>0){
                count = (Long) rstotal.get(0).get("total");
            }
            taskDO1.setTotal(count);
            taskDO1.setPatientId(taskDO.getPatientId());
       }
       String sqlcount = new ISqlUtils().getSql(taskDO,0,0,"count");
       List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
       Long count = 0L;
       if(rstotal!=null&&rstotal.size()>0){
           count = (Long) rstotal.get(0).get("total");
       }
       return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, taskDOS,page,size,count);
   }
        }
        String sqlcount = new ISqlUtils().getSql(taskDO,0,0,"count");
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, taskDOS,page,size,count);
    }
    /**
     * 查看当前的任务
@ -140,50 +142,52 @@ public class TaskService extends BaseJpaService<TaskDO,TaskDao> {
     * @param size 分页大小
     * @return
     */
   public MixEnvelop<TaskDO, TaskDO> selectByTask(JSONArray array, String patientId, Integer page, Integer size){
       StringBuffer buffer = new StringBuffer();
       List<String> taskCodes = new ArrayList<>();
       for (int i=0;i<array.size();i++){
           taskCodes.add(array.getString(i));
       }
       buffer.append(" bt.task_code in(");
       if (taskCodes == null || taskCodes.size() == 0){
           buffer.append("''");
       }else {
           for (int i=0;i<taskCodes.size();i++){
               buffer.append("'"+taskCodes.get(i)+"'").append(",");
           }
           buffer.deleteCharAt(buffer.length()-1);
       }
       buffer.append(") ");
       String sql = "select * from wlyy_health_bank_task bt where "+buffer +" ORDER BY update_time DESC LIMIT "+(page-1)*size+","+size;
       List<TaskDO> taskDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskDO.class));
       for (TaskDO taskDO:taskDOList){
           if (taskDO.getType().equalsIgnoreCase("ACTIVITY_TASK")){
               ActivityDO activityDO = activityDao.findOne(taskDO.getTransactionId());
               taskDO.setActivityDO(activityDO);
           }
           if (taskDO.getPeriod() == 1){
               String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO.getId()+
                       "' and patient_id = '"+patientId+"'";
               List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
               taskDO.setTaskPatientDetailDOS(taskPatientDetailDOS);
           }else if (taskDO.getPeriod() == 0){
               String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO.getId()+
                       "' and patient_id = '"+patientId+"' and create_time > '" + DateUtils.getDayBegin() +"' and create_time < '"+ DateUtils.getDayEnd() +"'";
               List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
               taskDO.setTaskPatientDetailDOS(taskPatientDetailDOS);
           }
           taskDO.setPatientId(patientId);
       }
       String sqlcount = "select COUNT(1) AS  total from wlyy_health_bank_task bt where "+buffer ;
       List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
       Long count = 0L;
       if(rstotal!=null&&rstotal.size()>0){
           count = (Long) rstotal.get(0).get("total");
       }
       return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, taskDOList,page,size,count);
   }
    public MixEnvelop<TaskDO, TaskDO> selectByTask(JSONArray array, String patientId, Integer page, Integer size){
        StringBuffer buffer = new StringBuffer();
        List<String> taskCodes = new ArrayList<>();
        for (int i=0;i<array.size();i++){
            taskCodes.add(array.getString(i));
        }
        buffer.append(" bt.task_code in(");
        if (taskCodes == null || taskCodes.size() == 0){
            buffer.append("''");
        }else {
            for (int i=0;i<taskCodes.size();i++){
                buffer.append("'"+taskCodes.get(i)+"'").append(",");
            }
            buffer.deleteCharAt(buffer.length()-1);
        }
        buffer.append(") ");
        String sql = "select * from wlyy_health_bank_task bt where "+buffer +" ORDER BY update_time DESC LIMIT "+(page-1)*size+","+size;
        List<TaskDO> taskDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskDO.class));
        for (TaskDO taskDO:taskDOList){
            if (taskDO.getType().equalsIgnoreCase("ACTIVITY_TASK")){
                ActivityDO activityDO = activityDao.findOne(taskDO.getTransactionId());
                taskDO.setActivityDO(activityDO);
            }
            if (taskDO.getPeriod() == 1){
//               String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO.getId()+
//                       "' and patient_id = '"+patientId+"'";
//               List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                List<TaskPatientDetailDO> taskPatientDetailDOS = taskPatientDetailDao.selectByTaskIdAndPatientId2(taskDO.getId(),patientId);
                taskDO.setTaskPatientDetailDOS(taskPatientDetailDOS);
            }else if (taskDO.getPeriod() == 0){
                String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO.getId()+
                        "' and patient_id = '"+patientId+"' and create_time > '" + DateUtils.getDayBegin() +"' and create_time < '"+ DateUtils.getDayEnd() +"'";
                taskSql = TransforSqlUtl.wlyyHealthBankTaskPatientDetailAll(taskSql);
                List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
                taskDO.setTaskPatientDetailDOS(taskPatientDetailDOS);
            }
            taskDO.setPatientId(patientId);
        }
        String sqlcount = "select COUNT(1) AS  total from wlyy_health_bank_task bt where "+buffer ;
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, taskDOList,page,size,count);
    }
   /* public List<TaskDO> getTasks(String patientId){
       List<TaskDO> taskDOList = new ArrayList<>();
       TaskDO taskDO = new TaskDO();

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

@ -0,0 +1,21 @@
package com.yihu.jw.util;
/**
 * Created by yeshijie on 2021/2/4.
 */
public class TransforSqlUtl {
    public static String accountName(String sql){
        return sql.replaceAll("ba1.account_name","CAST(AES_DECRYPT(from_base64(ba1.account_name),'jkzl2021ZJXL*#%a')AS char)");
    }
    public static String wlyyHealthBankAccountAll(String sql){
        String str = "*,CAST(AES_DECRYPT(from_base64(account_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS account_name ";
        return sql.replace("*",str);
    }
    public static String wlyyHealthBankTaskPatientDetailAll(String sql){
        String str = "*,CAST(AES_DECRYPT(from_base64(patient_idcard),'jkzl2021ZJXL*#%a') AS CHAR ) AS patient_idcard ";
        return sql.replace("*",str);
    }
}