123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881 |
- package com.yihu.jw.service;/**
- * Created by nature of king on 2018/4/27.
- */
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- 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.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.BeanClassLoaderAware;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.jdbc.core.BeanPropertyRowMapper;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.util.StringUtils;
- import javax.persistence.Column;
- import javax.persistence.Table;
- import javax.print.DocFlavor;
- import javax.transaction.Transactional;
- import java.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * @author wangzhinan
- * @create 2018-04-27 16:53
- * @desc credits log info Service
- **/
- @Service
- @Transactional
- public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,CredittsLogDetailDao> {
- private Logger logger = LoggerFactory.getLogger(CreditsDetailService.class);
- private static String STEP = "health:blank:step";
- @Autowired
- private CredittsLogDetailDao credittsLogDetailDao;
- @Autowired
- private TaskDao taskDao;
- @Autowired
- private ActivityDao activityDao;
- @Autowired
- private JdbcTemplate jdbcTemplate;
- @Autowired
- private AccountDao accountDao;
- @Autowired
- private TaskPatientDetailDao taskPatientDetailDao;
- @Autowired
- private TaskRuleDao taskRuleDao;
- @Autowired
- private StringRedisTemplate redisTemplate;
- @Autowired
- private ActiveRecordService activeRecordService;
- @Autowired
- private ActivityRuleDao activityRuleDao;
- @Autowired
- private ExchangeGoodsDao exchangeGoodsDao;
- @Autowired
- private TaskGoodsDao taskGoodsDao;
- /**
- * find creditsLogInfo
- *
- * @return
- * @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){
- 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");
- 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, creditsDetailDOS,page,size,count);
- }
- /**
- * find creditsLogInfo
- * 带排序
- * @return
- * @throws ParseException
- */
- public MixEnvelop<CreditsDetailDO, CreditsDetailDO> findByConditionWithOrder(CreditsDetailDO creditsDetailDO, Integer orderType, Integer page, Integer size) throws ParseException {
- String sql = getCreditsLogInSqlWithOrder(creditsDetailDO,page,size,"*",orderType);
- List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
- for (CreditsDetailDO creditsDetailDO1 : creditsDetailDOS){
- 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 = getCreditsLogInSqlWithOrder(creditsDetailDO,0,0,"count",orderType);
- 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, creditsDetailDOS,page,size,count);
- }
- public String getCreditsLogInSqlWithOrder(Object object,Integer page,Integer size,String isFlag,Integer orderType){
- StringBuffer sb = new StringBuffer();
- Class c =object.getClass();
- Table table = (Table)c.getAnnotation(Table.class);
- String tableName = table.name();
- if (isFlag.equalsIgnoreCase("count")){
- sb.append("select count(1) AS total from ").append(tableName).append(" where 1=1 and status=1 ");
- }else if(isFlag.equalsIgnoreCase("*")){
- sb.append("select * from ").append(tableName).append(" where 1=1 and status=1 ");
- }
- JSONObject object1 = (JSONObject) JSONObject.toJSON(object);
- if (object1.getString("id") !=null){
- sb.append(" and id = '" + object1.getString("id")+"' ");
- }
- Field[] fArray= c.getDeclaredFields();
- for(Field f:fArray){
- //拿到字段后与实体类中的属性匹配,并得到其get方法,用来获取他的属性值
- String getMethodName ="";
- boolean isCExist =f.isAnnotationPresent(Column.class);
- if(isCExist){
- Column mc =f.getAnnotation(Column.class);
- String columeName =mc.name(); //字段对应数据库名字
- String name =f.getName(); //字段名字
- Class a= f.getType(); //字段类型
- Object value=null; //字段值
- getMethodName="get"+name.substring(0,1).toUpperCase()+name.substring(1);//拼接属性的get方法
- try {
- Method m =c.getMethod(getMethodName);
- value =(Object)m.invoke(object); //拿到属性的值
- if(value == null || "".equals(value)){ //如果属性没值,不拼接sql
- continue;
- }
- else if(value instanceof String){
- value ="'%"+value+"%'";
- sb.append(" and ").append(columeName +" like " ).append(value+"");
- }else if (value instanceof Integer){
- value = value;
- sb.append(" and ").append(columeName +" = " ).append(value+"");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- JSONObject jsonObject = (JSONObject) JSONObject.toJSON(object);
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date1 = jsonObject.getDate("startTime");
- Date date2 = jsonObject.getDate("endTime");
- String startTime = null;
- String endTime = null;
- if (date1 != null){
- startTime = sdf.format(date1);
- }
- if (date2 != null) {
- endTime = sdf.format(date2);
- }
- if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)&& org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
- sb.append(" and start_time >= '"+startTime+"' and end_time <='"+endTime+"'");
- } else if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)&&!org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)) {
- sb.append(" and start_time >= '"+startTime+"'");
- }else if (org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)&&!org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)){
- sb.append(" and end_time <= '"+endTime+"'");
- }
- if(isFlag.equalsIgnoreCase("*")){
- if(orderType==0){
- sb.append(" ORDER BY create_time DESC ").append("LIMIT ").append((page-1)*size+",").append(size);
- }
- else if(orderType==1){
- sb.append(" ORDER BY trade_direction ASC,create_time DESC ").append("LIMIT ").append((page-1)*size+",").append(size);
- }
- else if(orderType==2){
- sb.append(" ORDER BY trade_direction DESC,create_time DESC ").append("LIMIT ").append((page-1)*size+",").append(size);
- }
- }
- return sb.toString();
- }
- /**
- * 获取账户信息
- *
- * @param creditsDetailDO
- * @return
- */
- public MixEnvelop<AccountDO, AccountDO> findByTradeDirection(CreditsDetailDO creditsDetailDO){
- AccountDO accountDO1 = new AccountDO();
- accountDO1.setPatientId(creditsDetailDO.getPatientId());
- String sql1 = ISqlUtils.getAllSql(accountDO1);
- List<AccountDO> accountDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(AccountDO.class));
- if (accountDOS == null || accountDOS.size() == 0){
- accountDO1.setTotal(0);
- accountDO1.setAccountName(creditsDetailDO.getName());
- if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
- String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
- int random = (int)((Math.random()*9+1)*100000);
- accountDO1.setCardNumber(cardNumber+Integer.toString(random));
- }
- accountDO1.setHospital(creditsDetailDO.getHospital());
- accountDO1.setPassword("123456");
- accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
- accountDO1.setStatus(1);
- accountDO1.setSaasId("dev");
- accountDO1.setCreateTime(new Date());
- accountDO1.setUpdateTime(new Date());
- accountDao.save(accountDO1);
- }
- List<AccountDO> accountDOS1 = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(AccountDO.class));
- AccountDO accountDO = accountDOS1.get(0);
- String sql = "SELECT SUM(cd.integrate) as total FROM wlyy_health_bank_credits_detail cd where cd.trade_direction = "+creditsDetailDO.getTradeDirection() +" AND cd.patient_id = '" +creditsDetailDO.getPatientId()+"'";
- List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
- if (rstotal!= null && rstotal.size()>0){
- if (rstotal.get(0).get("total") == null){
- accountDO.setUsedTotal(0);
- }else {
- accountDO.setUsedTotal(Integer.parseInt(rstotal.get(0).get("total").toString()));
- }
- }
- 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(");
- if (patientIds == null || patientIds.size() == 0){
- buffer.append("''");
- }else {
- for (int i=0;i<patientIds.size();i++){
- buffer.append("'"+patientIds.get(i)+"'").append(",");
- }
- buffer.deleteCharAt(buffer.length()-1);
- }
- buffer.append(") ");
- String sql =
- "SELECT ba1.patient_id AS patient_id," +
- "ba1.account_name AS account_name," +
- "ba1.hospital AS hospital," +
- "ba1.total AS total," +
- "ba1.create_time AS create_time," +
- "ba1.sum AS sum" +
- " FROM" +
- "( SELECT " +
- "ba.patient_id AS patient_id," +
- "ba.account_name AS account_name," +
- "ba.hospital AS hospital," +
- "ba.total AS total," +
- "ba.create_time AS create_time," +
- " if(ba.total=0,ba.total,(ba.total +COALESCE((cd1.total),0))) AS sum" +
- " FROM" +
- " wlyy_health_bank_account ba" +
- " LEFT JOIN ( " +
- "SELECT" +
- " SUM(cd.integrate) AS total," +
- " cd.patient_id AS patient_id" +
- " FROM" +
- " wlyy_health_bank_credits_detail cd" +
- " WHERE " +
- "cd.trade_direction = - 1" +
- " GROUP BY " +
- " cd.patient_id ) cd1 ON cd1.patient_id = ba.patient_id " +
- " WHERE " + buffer +
- " ORDER BY" +
- " ba.create_time DESC )ba1" +
- " ORDER BY " +
- " ba1.total DESC"+
- " LIMIT "+(page-1)*size+","+size ;
- List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
- String sqlCount = "SELECT count(1) AS total"+
- " FROM " +
- " wlyy_health_bank_account ba LEFT JOIN " +
- " ( " +
- " SELECT " +
- " SUM(cd.integrate) AS total, " +
- " cd.patient_id AS patient_id " +
- " FROM " +
- " wlyy_health_bank_credits_detail cd " +
- " WHERE " +
- " cd.trade_direction = - 1 " +
- " GROUP BY " +
- " cd.patient_id " +
- " ) cd1 ON cd1.patient_id = ba.patient_id " +
- "WHERE " + buffer +
- " ORDER BY " +
- " ba.create_time, " +
- " (ba.total + COALESCE(cd1.total,0)) DESC ";
- 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, accountDOS,page,size,count);
- }
- /**
- * 添加积分
- *
- * @param creditsDetailDO
- * @return
- */
- 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));
- if (accountDOList != null && accountDOList.size() != 0){
- creditsDetailDO.setAccountId(accountDOList.get(0).getId());
- }else {
- 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());//截取两个数字之间的部分
- int random = (int)((Math.random()*9+1)*100000);
- accountDO1.setCardNumber(cardNumber+Integer.toString(random));
- }
- accountDO1.setHospital(creditsDetailDO.getHospital());
- accountDO1.setPassword("123456");
- accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
- accountDO1.setStatus(1);
- accountDO1.setCreateTime(new Date());
- accountDO1.setUpdateTime(new Date());
- accountDao.save(accountDO1);
- List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
- creditsDetailDO.setAccountId(accountDOS.get(0).getId());
- }
- TaskDO taskDO = new TaskDO();
- taskDO.setTaskCode(creditsDetailDO.getFlag());
- taskDO.setId(creditsDetailDO.getTransactionId());
- /*taskDO.setPatientId(creditsDetailDO.getPatientId());*/
- String sql = ISqlUtils.getSql(taskDO,1,1,"*");
- List<TaskDO> taskDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskDO.class));
- creditsDetailDO.setTransactionId(taskDOList.get(0).getId());
- String ruleSql = "SELECT * FROM wlyy_health_bank_task_rule WHERE id= '"+taskDOList.get(0).getRuleCode()+"'";
- List<TaskRuleDO> taskRuleDOS = jdbcTemplate.query(ruleSql,new BeanPropertyRowMapper(TaskRuleDO.class));
- 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));
- if (taskPatientDetailDOS == null || taskPatientDetailDOS.size() ==0){
- TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
- taskPatientDetailDO.setTaskId(creditsDetailDO.getTransactionId());
- taskPatientDetailDO.setSaasId(creditsDetailDO.getSaasId());
- taskPatientDetailDO.setPatientId(creditsDetailDO.getPatientId());
- taskPatientDetailDO.setPatientIdcard(creditsDetailDO.getIdCard());
- taskPatientDetailDO.setPatientOpenid(creditsDetailDO.getOpenId());
- taskPatientDetailDO.setUnionId(creditsDetailDO.getUnionId());
- taskPatientDetailDO.setStatus(Integer.parseInt("0"));
- taskPatientDetailDO.setCreateTime(new Date());
- taskPatientDetailDO.setUpdateTime(new Date());
- taskPatientDetailDO.setActivityId(taskDOList.get(0).getTransactionId());
- taskPatientDetailDO.setTotal(Long.parseLong("0"));
- taskPatientDetailDao.save(taskPatientDetailDO);
- }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() +"'";
- List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
- if (taskPatientDetailDOS1 == null || taskPatientDetailDOS1.size() == 0){
- TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
- taskPatientDetailDO.setTaskId(creditsDetailDO.getTransactionId());
- taskPatientDetailDO.setSaasId(creditsDetailDO.getSaasId());
- taskPatientDetailDO.setPatientId(creditsDetailDO.getPatientId());
- taskPatientDetailDO.setPatientIdcard(creditsDetailDO.getIdCard());
- taskPatientDetailDO.setPatientOpenid(creditsDetailDO.getOpenId());
- taskPatientDetailDO.setActivityId(taskDOList.get(0).getTransactionId());
- taskPatientDetailDO.setStatus(Integer.parseInt("0"));
- taskPatientDetailDO.setCreateTime(new Date());
- taskPatientDetailDO.setUpdateTime(new Date());
- taskPatientDetailDO.setTotal(Long.parseLong("0"));
- taskPatientDetailDao.save(taskPatientDetailDO);
- }
- }
- logger.info("uploadTime:"+creditsDetailDO.getUploadTime());
- if (creditsDetailDO.getUploadTime()!=null&&creditsDetailDO.getUploadTime()!=""){
- creditsDetailDO.setCreateTime(DateUtil.strToDateLong(creditsDetailDO.getUploadTime()));
- }else {
- creditsDetailDO.setCreateTime(new Date());
- }
- creditsDetailDO.setUpdateTime(new Date());
- CreditsDetailDO creditsDetailDO1 =credittsLogDetailDao.save(creditsDetailDO);
- creditsDetailDO1.setFlag(creditsDetailDO.getFlag());
- List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
- 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());
- }
- AccountDO accountDO1 = accountDao.save(accountDO);
- List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
- for (CreditsDetailDO creditsDetailDO2:creditsDetailDOList){
- creditsDetailDO2.setTotal(accountDO1.getTotal());
- creditsDetailDOS.add(creditsDetailDO2);
- }
- MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
- envelop.setDetailModelList(creditsDetailDOS);
- return envelop;
- }
- }catch (Exception e){
- e.printStackTrace();
- MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
- return envelop;
- }
- }
- /**
- * 活动排名
- *
- * @param activityId 活动id
- * @param ids 微信编码
- *
- * @param page 页码
- *
- * @param size 分页大小
- * @return
- */
- public MixEnvelop<TaskPatientDetailDO, TaskPatientDetailDO> selectByActivityRanking(String activityId, List<String> ids, Integer page, Integer size){
- StringBuffer buffer = new StringBuffer();
- buffer.append("(");
- if (ids == null || ids.size() == 0){
- buffer.append("''");
- }else {
- for (int i=0;i<ids.size();i++){
- buffer.append("'"+ids.get(i)+"'").append(",");
- }
- buffer.deleteCharAt(buffer.length()-1);
- }
- buffer.append(") ");
- String sql = "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 +
- "' GROUP BY " +
- " patient_id " +
- " ORDER BY ptpd.create_time DESC " +
- " )btpd1 " +
- " WHERE patient_id IN "+buffer+
- " 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));
- taskPatientDetailDO.setAccountDO(accountDOS.get(0));
- }
- String sqlCount = "SELECT " +
- " count(1) AS total " +
- "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+
- "' GROUP BY " +
- " patient_openid " +
- " ORDER BY ptpd.create_time DESC " +
- " )btpd1 " +
- "WHERE patient_openid IN "+buffer+
- " ORDER BY btpd1.total DESC ";
- 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, taskPatientDetailDOS,page,size,count);
- }
- /**
- * 根据活动查询积分
- *
- * @param activityId 活动id
- *
- * @param patientId 居民id
- *
- * @param page 页码
- *
- * @param size 分页大小
- * @return
- */
- public MixEnvelop<CreditsDetailDO, CreditsDetailDO> selectByActivity(String activityId, String patientId, Integer page, Integer size){
- String sql="SELECT * " +
- "FROM " +
- " wlyy_health_bank_credits_detail " +
- "WHERE" +
- " transaction_id IN ( " +
- " SELECT " +
- " bt.id " +
- " FROM " +
- " wlyy_health_bank_task bt " +
- " WHERE " +
- " transaction_id = '"+activityId +"' " +
- " ) " +
- " and patient_id = '" +patientId+
- "' LIMIT "+(page-1)*size +","+size;
- List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
- for (CreditsDetailDO creditsDetailDO : creditsDetailDOS){
- TaskDO taskDO = taskDao.findOne(creditsDetailDO.getTransactionId());
- creditsDetailDO.setTaskDO(taskDO);
- }
- String sqlcount = "SELECT count(1) AS" +
- " total FROM " +
- " wlyy_health_bank_credits_detail " +
- "WHERE" +
- " transaction_id IN ( " +
- " SELECT " +
- " bt.id " +
- " FROM " +
- " wlyy_health_bank_task bt " +
- " WHERE " +
- " transaction_id = '"+activityId +"' " +
- " ) " +
- " and patient_id = '" +patientId+
- "'";
- 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,creditsDetailDOS,page,size,count);
- }
- /**
- * 根据活动查找全部排行
- *
- * @param activityId 活动id
- * @param page 页码
- * @param size 分页大小
- * @return
- */
- public MixEnvelop<TaskPatientDetailDO, TaskPatientDetailDO> selectByActivityRanking1(String activityId, String patientId, Integer page, Integer size){
- String sql = "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 +
- "' GROUP BY " +
- " patient_openid " +
- " ORDER BY ptpd.create_time DESC " +
- " )btpd1 " +
- " ORDER BY btpd1.total DESC "+" LIMIT " + (page-1)*size+","+size;
- List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
- 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));
- 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);
- }
- taskPatientDetailDO.setAccountDO(accountDOS.get(0));
- }
- String sqlCount = "SELECT " +
- " count(1) AS total " +
- "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+
- "' GROUP BY " +
- " patient_openid " +
- " ORDER BY ptpd.create_time DESC " +
- " )btpd1 " +
- " ORDER BY btpd1.total DESC ";
- 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, taskPatientDetailDOS,page,size,count);
- }
- /**
- * 医生主动加分
- *
- * @param array 居民信息集合
- *
- * @param ruleId 规则id
- * @return
- */
- public MixEnvelop<Boolean, Boolean> doctorAddIntegrate(JSONArray array, String ruleId, String description) throws Exception {
- MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
- for (int i=0;i<array.size();i++){
- TaskRuleDO taskRuleDO = taskRuleDao.findOne(ruleId);
- JSONObject object = array.getJSONObject(i);
- String patientId = object.getString("code");
- String idCard = object.getString("idcard");
- String unionId = object.getString("unionid");
- String openId = object.getString("openid");
- String hospital = object.getString("hospital");
- String hospitalName = object.getString("hospitalName");
- String taskSql = "select * from wlyy_health_bank_task bt where type = 'RULE_TASK' AND transaction_id = '"+ruleId +"'";
- List<TaskDO> taskDOList = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskDO.class));
- TaskDO taskDO1 = new TaskDO();
- if (taskDOList.isEmpty() && taskDOList.size() == 0){
- TaskDO taskDO = new TaskDO();
- taskDO.setTransactionId(taskRuleDO.getId());
- taskDO.setTaskCode("RULE");
- taskDO.setStatus(1);
- taskDO.setRuleCode(taskRuleDO.getId());
- taskDO.setType("RULE_TASK");
- taskDO.setCreateTime(new Date());
- taskDO.setUpdateTime(new Date());
- taskDO.setPeriod(taskRuleDO.getPeriod());
- taskDO.setSaasId("dev");
- taskDO.setTitle(taskRuleDO.getDescription());
- taskDO.setContent(taskRuleDO.getDescription());
- taskDO1 = taskDao.save(taskDO);
- }else {
- 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("已奖励过");
- }
- }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("已奖励过");
- }
- }
- String sql1 = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+"' " +
- "AND patient_idcard = '"+idCard+"' AND patient_openid = '"+openId+"' AND union_id = '"+unionId+"'";
- List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
- TaskPatientDetailDO taskPatientDetailDO1 = new TaskPatientDetailDO();
- if (taskPatientDetailDOS.isEmpty() && taskPatientDetailDOS.size() == 0){
- TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
- taskPatientDetailDO.setStatus(1);
- taskPatientDetailDO.setTotal(Long.parseLong("0"));
- taskPatientDetailDO.setPatientId(patientId);
- taskPatientDetailDO.setPatientOpenid(openId);
- taskPatientDetailDO.setPatientIdcard(idCard);
- taskPatientDetailDO.setUnionId(unionId);
- taskPatientDetailDO.setSaasId("dev");
- taskPatientDetailDO.setCreateTime(new Date());
- taskPatientDetailDO.setUpdateTime(new Date());
- taskPatientDetailDO.setTaskId(taskDO1.getId());
- taskPatientDetailDO1 = taskPatientDetailDao.save(taskPatientDetailDO);
- }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));
- 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'))";
- 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){
- /* int total = accountDO.getTotal() - creditsDetailDO.getIntegrate();*/
- creditsDetailDO.setStatus(0);
- creditsDetailDO.setDescription(description);
- credittsLogDetailDao.save(creditsDetailDO);
- }
- }
- accountDO.setTotal(0);
- accountDao.save(accountDO);
- CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
- creditsDetailDO1.setStatus(1);
- creditsDetailDO1.setSaasId("dev");
- creditsDetailDO1.setAccountId(accountDOS.get(0).getId());
- creditsDetailDO1.setHospital(hospital);
- creditsDetailDO1.setHospitalName(hospitalName);
- creditsDetailDO1.setPatientId(patientId);
- creditsDetailDO1.setIntegrate(taskRuleDO.getIntegrate());
- creditsDetailDO1.setTradeDirection(taskRuleDO.getTradeDirection());
- creditsDetailDO1.setDescription(description);
- creditsDetailDO1.setCreateTime(new Date());
- creditsDetailDO1.setUpdateTime(new Date());
- creditsDetailDO1.setTransactionId(taskDO1.getId());
- creditsDetailDO1.setTradeType("ACTIVITY_TASK");
- credittsLogDetailDao.save(creditsDetailDO1);
- }else{
- CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
- creditsDetailDO.setStatus(1);
- creditsDetailDO.setSaasId("dev");
- creditsDetailDO.setAccountId(accountDOS.get(0).getId());
- creditsDetailDO.setHospital(hospital);
- creditsDetailDO.setHospitalName(hospitalName);
- creditsDetailDO.setPatientId(patientId);
- creditsDetailDO.setIntegrate(taskRuleDO.getIntegrate());
- creditsDetailDO.setTradeDirection(taskRuleDO.getTradeDirection());
- creditsDetailDO.setDescription(description);
- creditsDetailDO.setCreateTime(new Date());
- creditsDetailDO.setUpdateTime(new Date());
- creditsDetailDO.setTransactionId(taskDO1.getId());
- creditsDetailDO.setTradeType("ACTIVITY_TASK");
- creditsDetailDO = credittsLogDetailDao.save(creditsDetailDO);
- if (taskRuleDO.getTradeDirection() == -1){
- 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);
- accountDO.setTotal(accountDO.getTotal() + taskRuleDO.getIntegrate());
- accountDao.save(accountDO);
- }
- }
- }
- envelop.setObj(true);
- 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));
- if (accountDOList != null && accountDOList.size() != 0){
- creditsDetailDO.setAccountId(accountDOList.get(0).getId());
- }else {
- AccountDO accountDO1 = new AccountDO();
- 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());//截取两个数字之间的部分
- int random = (int)((Math.random()*9+1)*100000);
- accountDO1.setCardNumber(cardNumber+Integer.toString(random));
- }
- accountDO1.setHospital(creditsDetailDO.getHospital());
- accountDO1.setPassword("123456");
- accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
- accountDO1.setStatus(1);
- accountDO1.setCreateTime(new Date());
- accountDO1.setUpdateTime(new Date());
- accountDao.save(accountDO1);
- 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 = '"+creditsDetailDO.getIdCard()+"' AND union_id = '"+creditsDetailDO.getUnionId()+"' AND task_id = '"+creditsDetailDO.getTransactionId()+"'";
- List<TaskPatientDetailDO> taskPatientDetailDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
- if(taskPatientDetailDOList == null || taskPatientDetailDOList.size()==0){
- throw new Exception("该居民参与活动查不到!");
- }
- TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDOList.get(0);
- String sql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+creditsDetailDO.getPatientId()+"' AND " +
- "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));
- int integrate1=0;
- for (CreditsDetailDO detailDO:creditsDetailDOS){
- integrate1+= detailDO.getIntegrate();
- }
- ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(taskPatientDetailDO.getActivityId());
- logger.info("开始"+activityRuleDO.getValue1());
- logger.info("参数:"+creditsDetailDO.getIntegrate()+creditsDetailDO.getStepNumber());
- 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){
- creditsDetailDO.setIntegrate(creditsDetailDO.getIntegrate());
- creditsDetailDO.setTradeDirection(1);
- creditsDetailDO.setUpdateTime(new Date());
- creditsDetailDO.setCreateTime(new Date());
- creditsDetailDO.setTradeType("ACTIVITY_TASK");
- CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO);
- 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);
- 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);
- accountDao.save(accountDO);
- creditsDetailDO2.setTotal(accountDO.getTotal());
- creditsDetailDOS.add(creditsDetailDO2);
- break;
- }
- }
- }
- }
- /* 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){
- logger.error("插入活跃出错:"+e.getMessage());
- }
- MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
- envelop.setDetailModelList(creditsDetailDOS);
- return envelop;
- }
- }catch (Exception e){
- e.printStackTrace();
- MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
- return envelop;
- }
- }
- public MixEnvelop doctorDescreaseIntegrate(String ruleId,String patientId,String doctorId,String hospital,String hospitalName,Integer integrate,String reason,String type,String name,String idcard) 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 = null;
- if("add".equals(type)&&(accountDOs==null||accountDOs.size()==0)){
- //新建账户
- accountDO = new AccountDO();
- accountDO.setTotal(0);
- accountDO.setId(getCode());
- accountDO.setPatientId(patientId);
- accountDO.setAccountName(name);
- accountDO.setHospital(hospital);
- accountDO.setHospitalName(hospitalName);
- if(idcard.length()>=4){// 判断是否长度大于等于4
- String cardNumber=idcard.substring(idcard.length()- 4,idcard.length());//截取两个数字之间的部分
- int random = (int)((Math.random()*9+1)*100000);
- accountDO.setCardNumber(cardNumber+Integer.toString(random));
- }
- accountDO.setPassword("123456");
- accountDO.setSaasId("dev");
- accountDO.setStatus(1);
- accountDO.setCreateTime(new Date());
- accountDO.setUpdateTime(new Date());
- accountDO = accountDao.save(accountDO);
- }else{
- 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("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;
- }
- }*/
- 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));
- 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 " +
- "DATE_FORMAT(create_time,'%Y-%m-%d') IN " + creditsDetailDO.getWeekTimes()+" and description = '周奖励'";
- List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
- List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
- MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
- if (getWeekOfDate(new Date()).equalsIgnoreCase("星期五")||getWeekOfDate(new Date()).equalsIgnoreCase("星期六")||getWeekOfDate(new Date()).equalsIgnoreCase("星期日")){
- String sql = "select sum(integrate) as total from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and description = '周奖励'";
- List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
- Long count = 0L;
- if(rstotal!=null&&rstotal.size()>0){
- Object object = rstotal.get(0).get("total");
- if (object != null){
- count = Long.parseLong(object.toString());
- }
- }
- if (count > 12){
- envelop.setMessage("奖励积分已达到12分。不能再奖励了!");
- return envelop;
- }else{
- if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
- creditsDetailDO.setTradeType("ACTIVITY_TASK");
- 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);
- 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());
- }
- AccountDO accountDO1 = accountDao.save(accountDO);
- List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
- for (CreditsDetailDO creditsDetailDO2 : creditsDetailDOList) {
- creditsDetailDO2.setTotal(accountDO1.getTotal());
- creditsDetailDO2.setFlag("1");
- creditsDetailDOS.add(creditsDetailDO2);
- }
- envelop.setDetailModelList(creditsDetailDOS);
- }else {
- for (CreditsDetailDO creditsDetailDO1 : creditsDetailDOS1){
- creditsDetailDO1.setFlag("2");
- }
- envelop.setDetailModelList(creditsDetailDOS1);
- }
- return envelop;
- }
- }else{
- CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
- creditsDetailDO1.setFlag("0");
- creditsDetailDOList.add(creditsDetailDO1);
- envelop.setDetailModelList(creditsDetailDOList);
- return envelop;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
- return envelop;
- }
- }
- public String getWeekOfDate(Date dt) {
- String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
- Calendar cal = Calendar.getInstance();
- cal.setTime(dt);
- int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
- if (w < 0)
- w = 0;
- return weekDays[w];
- }
- /**
- * 健康问答添加积分
- *
- * @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+"' " +
- " AND btpd.activity_id = '"+taskDO.getTransactionId()+"' " +
- "GROUP BY btpd.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='"+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+"' " +
- " AND btpd.activity_id = '"+taskDO.getTransactionId()+"' "+
- "GROUP BY btpd.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='"+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;
- }
- }
- public List<CreditsDetailDO> share(CreditsDetailDO creditsDetailDO) throws Exception {
- synchronized (creditsDetailDO.getPatientId()) {
- String activityId= creditsDetailDO.getActivityId();
- ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(activityId);
- String sql = "select * from wlyy_health_bank_credits_detail where patient_id ='"+creditsDetailDO.getPatientId()+"' " +
- "and description ='分享' and status =1 AND transaction_id = '"+creditsDetailDO.getTransactionId()+"'";
- List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
- List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
- if (activityRuleDO != null){
- JSONObject jsonObject = JSONObject.parseObject(activityRuleDO.getValue1());
- 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));
- CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
- if (accountDOList != null && accountDOList.size() != 0) {
- creditsDetailDO1.setAccountId(accountDOList.get(0).getId());
- }
- if (creditsDetailDOS!=null&&creditsDetailDOS.size()>=object.getInteger("frequency")){
- throw new Exception("分享超过"+creditsDetailDOS.size()+"次");
- }else {
- creditsDetailDO1.setHospitalName(creditsDetailDO.getHospitalName());
- creditsDetailDO1.setHospital(creditsDetailDO.getHospital());
- creditsDetailDO1.setPatientId(creditsDetailDO.getPatientId());
- creditsDetailDO1.setTradeType("ACTIVITY_TASK");
- creditsDetailDO1.setDescription("分享");
- creditsDetailDO1.setSaasId("dev");
- creditsDetailDO1.setStatus(1);
- creditsDetailDO1.setCoupon(0);
- creditsDetailDO1.setTransactionId(creditsDetailDO.getTransactionId());
- creditsDetailDO1.setCreateTime(new Date());
- creditsDetailDO1.setUpdateTime(new Date());
- creditsDetailDO1.setTradeDirection(1);
- creditsDetailDO1.setIntegrate(object.getInteger("integrate"));
- CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
- creditsDetailDOList.add(creditsDetailDO2);
- 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() + creditsDetailDO2.getIntegrate());
- } else if (creditsDetailDO1.getTradeDirection() == -1) {
- taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() - creditsDetailDO2.getIntegrate());
- }
- taskPatientDetailDao.save(taskPatientDetailDO1);
- AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
- if (creditsDetailDO1.getTradeDirection() == 1) {
- accountDO.setTotal(accountDO.getTotal() + creditsDetailDO2.getIntegrate());
- } else if (creditsDetailDO1.getTradeDirection() == -1) {
- accountDO.setTotal(accountDO.getTotal() - creditsDetailDO2.getIntegrate());
- }
- accountDao.save(accountDO);
- }
- }
- }
- return creditsDetailDOList;
- }
- }
- /**
- * 商城积分支付
- * @param patient
- * @param total
- * @param hospital
- * @param hospitalName
- * @param array
- * @return
- * @throws Exception
- */
- public MixEnvelop<CreditsDetailDO,CreditsDetailDO> payIntegrate(String patient,Double total,String hospital,String hospitalName,JSONArray array) throws Exception {
- MixEnvelop<CreditsDetailDO,CreditsDetailDO> envelop = new MixEnvelop<>();
- AccountDO accountDO = accountDao.selectByPatientId(patient);
- Integer total1 = total.intValue();
- if (accountDO == null){
- envelop.setMessage("银行账户不存在!");
- throw new Exception("银行账户不存在!");
- }else {
- if (total1>accountDO.getTotal()){
- envelop.setMessage("积分余额不足!");
- throw new Exception("积分余额不足!");
- }else{
- for (int i=0;i<array.size();i++){
- JSONObject object = array.getJSONObject(i);
- CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
- creditsDetailDO.setPatientId(patient);
- creditsDetailDO.setAccountId(accountDO.getId());
- creditsDetailDO.setHospital(hospital);
- creditsDetailDO.setTradeType("SHOPPING_PAY");
- creditsDetailDO.setTradeDirection(-1);
- creditsDetailDO.setTransactionId(object.getString("orderId"));
- creditsDetailDO.setIntegrate(object.getDouble("integrate").intValue());
- creditsDetailDO.setCreateTime(new Date());
- creditsDetailDO.setUpdateTime(new Date());
- creditsDetailDO.setHospitalName(hospitalName);
- creditsDetailDO.setSaasId("dev");
- creditsDetailDO.setId(getCode());
- creditsDetailDO.setCoupon(0);
- creditsDetailDO.setStatus(1);
- credittsLogDetailDao.save(creditsDetailDO);
- }
- accountDO.setTotal(accountDO.getTotal()-total1);
- accountDao.save(accountDO);
- }
- }
- return envelop;
- }
- public MixEnvelop<CreditsDetailDO,CreditsDetailDO> refundIntegrate(JSONArray array) throws Exception {
- MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
- for (int i=0;i<array.size();i++){
- JSONObject object = array.getJSONObject(i);
- CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.selectByTransactionId(object.getString("orderId"),"SHOPPING_PAY");
- CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
- creditsDetailDO.setPatientId(creditsDetailDO1.getPatientId());
- creditsDetailDO.setAccountId(creditsDetailDO1.getAccountId());
- creditsDetailDO.setHospital(creditsDetailDO1.getHospital());
- creditsDetailDO.setTradeType("REFUND");
- creditsDetailDO.setTradeDirection(1);
- creditsDetailDO.setTransactionId(object.getString("orderId"));
- creditsDetailDO.setIntegrate(object.getDouble("integrate").intValue());
- creditsDetailDO.setCreateTime(new Date());
- creditsDetailDO.setUpdateTime(new Date());
- creditsDetailDO.setHospitalName(creditsDetailDO1.getHospitalName());
- creditsDetailDO.setSaasId("dev");
- creditsDetailDO.setId(getCode());
- creditsDetailDO.setCoupon(0);
- creditsDetailDO.setStatus(1);
- credittsLogDetailDao.save(creditsDetailDO);
- AccountDO accountDO = accountDao.selectByPatientId(creditsDetailDO1.getPatientId());
- accountDO.setTotal(accountDO.getTotal()+object.getDouble("integrate").intValue());
- accountDao.save(accountDO);
- }
- return envelop;
- }
- /**
- *
- * @param creditsDetailDO
- * @param flag 1连续2间断
- * @return
- */
- 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));
- if (accountDOList != null && accountDOList.size() != 0) {
- creditsDetailDO.setAccountId(accountDOList.get(0).getId());
- }
- if (flag == 1) {
- String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and " +
- "update_time >= '" + creditsDetailDO.getMonday() + "' AND update_time<='" + creditsDetailDO.getSunday() + "' and description = '周奖励-连续' AND transaction_id = '"+creditsDetailDO.getTransactionId()+"'";
- List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
- List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
- if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
- creditsDetailDO.setTradeType("ACTIVITY_TASK");
- creditsDetailDO.setSaasId("dev");
- creditsDetailDO.setStatus(1);
- creditsDetailDO.setTransactionId(creditsDetailDO.getTransactionId());
- creditsDetailDO.setCreateTime(new Date());
- creditsDetailDO.setUpdateTime(DateUtil.strToDateLong(creditsDetailDO.getSunday()));
- creditsDetailDO.setTradeDirection(1);
- creditsDetailDO.setDescription("周奖励-连续");
- creditsDetailDO.setCoupon(0);
- CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
- 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 (creditsDetailDO1.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 (creditsDetailDO1.getTradeDirection() == -1) {
- accountDO.setTotal(accountDO.getTotal() - creditsDetailDO1.getIntegrate());
- }
- AccountDO accountDO1 = accountDao.save(accountDO);
- List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
- for (CreditsDetailDO creditsDetailDO2 : creditsDetailDOList) {
- creditsDetailDO2.setTotal(accountDO1.getTotal());
- creditsDetailDO2.setFlag("1");
- creditsDetailDOS.add(creditsDetailDO2);
- }
- envelop.setDetailModelList(creditsDetailDOS);
- return envelop;
- }else {
- logger.info("居民:"+creditsDetailDO.getPatientId()+"已领取周奖励-连续");
- }
- }else if (flag==2){
- String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and " +
- "update_time >= '" +creditsDetailDO.getMonday()+"' AND update_time<='" +creditsDetailDO.getSunday() + "' and description = '周奖励-间断' AND transaction_id = '"+creditsDetailDO.getTransactionId()+"'";
- List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
- List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
- if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
- creditsDetailDO.setTradeType("ACTIVITY_TASK");
- creditsDetailDO.setSaasId("dev");
- creditsDetailDO.setStatus(1);
- creditsDetailDO.setTransactionId(creditsDetailDO.getTransactionId());
- creditsDetailDO.setCreateTime(new Date());
- creditsDetailDO.setUpdateTime(DateUtil.strToDateLong(creditsDetailDO.getSunday()));
- creditsDetailDO.setTradeDirection(1);
- creditsDetailDO.setDescription("周奖励-间断");
- CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
- 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());
- }
- AccountDO accountDO1 = accountDao.save(accountDO);
- List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
- for (CreditsDetailDO creditsDetailDO2 : creditsDetailDOList) {
- creditsDetailDO2.setTotal(accountDO1.getTotal());
- creditsDetailDO2.setFlag("1");
- creditsDetailDOS.add(creditsDetailDO2);
- }
- envelop.setDetailModelList(creditsDetailDOS);
- return envelop;
- }else {
- logger.info("居民:"+creditsDetailDO.getPatientId()+"已领取周奖励-间断");
- envelop.setMessage("居民:"+creditsDetailDO.getPatientId()+"已领取周奖励-间断");
- }
- }
- return envelop;
- }
- }
- public List<CreditsDetailDO> selectWeekReward(String patient,String taskId,String monday,String sunday){
- String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + patient + "' and " +
- "update_time >= '" +monday+"' AND update_time<='" + sunday+ "' and ( description = '周奖励-间断' OR description = '周奖励-连续') AND transaction_id = '"+taskId+"'";
- List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(creditsSql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
- return creditsDetailDOS;
- }
- public void reduceIntegrate(String hospital,String startTime,String endTime,Integer year){
- String sql ="SELECT hbcd.patient_id, " +
- "SUM(hbcd.integrate) AS total FROM wlyy_health_bank_credits_detail hbcd " +
- "WHERE hbcd.patient_id IN ( SELECT sf.patient AS patient FROM wlyy.wlyy_sign_family sf " +
- "WHERE sf.hospital = '"+hospital+"' AND sf. STATUS =- 4 AND sf.sign_year = "+year+" )AND hbcd.create_time < '"+endTime+"' " +
- "AND hbcd.trade_direction = 1 AND hbcd.transaction_id IN ('402885ed63debfcc0163dec956200002','402885ed63debfcc0163deca5ca90003','402885ed63debfcc0163decbba230004','402885ed63debfcc0163decc0a1a0005') GROUP BY hbcd.patient_id";
- List<Map<String,Object>> addIntegrate = jdbcTemplate.queryForList(sql);
- if (addIntegrate==null||addIntegrate.size()==0){
- logger.info("居民列表为空");
- }
- for (Map<String,Object> map:addIntegrate){
- String patient = map.get("patient_id").toString();
- Long reduceIntegrate = credittsLogDetailDao.selectTotalByPatient(patient);
- if (reduceIntegrate == null){
- reduceIntegrate = Long.parseLong("0");
- }
- Long total = Long.parseLong(map.get("total").toString());
- if (total <=reduceIntegrate){
- logger.info("居民code"+patient+"不需要扣减");
- }else {
- Long between = total - reduceIntegrate;
- AccountDO accountDO = accountDao.selectByPatientId(patient);
- String sql1 = "select p.idcard from wlyy.wlyy_patient p where p.code ='"+patient+"'";
- List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql1);
- String idcard = null;
- if (maps!=null&&maps.size()!=0){
- idcard = maps.get(0).get("idcard").toString();
- accountDO.setIdCard(idcard);
- }
- TaskDO taskDO = taskDao.selectById("5e5d857d684d77f201684d7f58b3000a132");
- TaskPatientDetailDO patientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId("5e5d857d684d77f201684d7f58b3000a132",patient);
- if (patientDetailDO == null){
- TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
- taskPatientDetailDO.setSaasId("dev");
- taskPatientDetailDO.setTaskId("5e5d857d684d77f201684d7f58b3000a132");
- taskPatientDetailDO.setPatientId(patient);
- taskPatientDetailDO.setDoctorId("system");
- taskPatientDetailDO.setPatientIdcard(idcard);
- taskPatientDetailDO.setCreateTime(new Date());
- taskPatientDetailDO.setUpdateTime(new Date());
- taskPatientDetailDO.setStatus(1);
- taskPatientDetailDao.save(taskPatientDetailDO);
- }
- CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
- creditsDetailDO.setAccountId(accountDO.getId());
- creditsDetailDO.setIdCard(accountDO.getIdCard());
- creditsDetailDO.setSaasId("dev");
- creditsDetailDO.setTradeType("ACTIVITY_TASK");
- creditsDetailDO.setTradeDirection(-1);
- creditsDetailDO.setIntegrate(between.intValue());
- creditsDetailDO.setDescription(taskDO.getTitle());
- creditsDetailDO.setStatus(1);
- creditsDetailDO.setHospital(hospital);
- creditsDetailDO.setCreateTime(new Date());
- creditsDetailDO.setUpdateTime(new Date());
- creditsDetailDO.setTransactionId(taskDO.getId());
- creditsDetailDO.setPatientId(patient);
- credittsLogDetailDao.save(creditsDetailDO);
- logger.info("===居民"+accountDO.getAccountName()+"("+patient+")失效"+creditsDetailDO.getIntegrate()+"===");
- accountDO.setTotal(accountDO.getTotal()-between.intValue());
- accountDao.save(accountDO);
- }
- }
- }
- public CreditsDetailDO completePlan(String planCode,String patient,String idcard,Integer integrate,String hospital,String hospitalName) throws Exception {
- ActivityDO activityDO = activityDao.selectByTemplateIdAndType(planCode,"健康计划");
- CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
- if (activityDO!=null){
- List<TaskDO> taskDOS = taskDao.selectByActivityId(activityDO.getId());
- AccountDO accountDO = accountDao.selectByPatientId(patient);
- if (taskDOS!=null&&taskDOS.size()!=0){
- creditsDetailDO.setSaasId("dev");
- creditsDetailDO.setPatientId(patient);
- creditsDetailDO.setIdCard(idcard);
- creditsDetailDO.setIntegrate(integrate);
- creditsDetailDO.setStatus(1);
- creditsDetailDO.setTradeDirection(1);
- creditsDetailDO.setTradeType("ACTIVITY_TASK");
- creditsDetailDO.setAccountId(accountDO.getId());
- creditsDetailDO.setHospital(hospital);
- creditsDetailDO.setHospitalName(hospitalName);
- creditsDetailDO.setTransactionId(taskDOS.get(0).getId());
- creditsDetailDO.setUpdateTime(new Date());
- creditsDetailDO.setCreateTime(new Date());
- credittsLogDetailDao.save(creditsDetailDO);
- TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(taskDOS.get(0).getId(),patient);
- if (taskPatientDetailDO!=null){
- taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+integrate);
- }
- taskPatientDetailDao.save(taskPatientDetailDO);
- accountDO.setTotal(accountDO.getTotal()+integrate);
- accountDao.save(accountDO);
- }
- }else {
- throw new Exception("暂不能获取积分!");
- }
- return creditsDetailDO;
- }
- }
|