1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882 |
- 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.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.date.DateUtil;
- import com.yihu.mysql.query.BaseJpaService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.jdbc.core.BeanPropertyRowMapper;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Service;
- import javax.persistence.Column;
- import javax.persistence.Table;
- 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;
- @Value("${account.initPassword}")
- private String initPassword;
- /**
- * 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(initPassword);
- 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," +
- "AES_DECRYPT(from_base64(ba1.account_name,"+ AesEncryptUtils.KEY+") 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(initPassword);
- 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 = '"+AesEncryptUtils.encrypt(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(initPassword);
- 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 = '"+AesEncryptUtils.encrypt(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(initPassword);
- 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 = AesEncryptUtils.decrypt(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;
- }
- }
|