CreditsDetailService.java 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. package com.yihu.jw.service;/**
  2. * Created by nature of king on 2018/4/27.
  3. */
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.yihu.base.mysql.query.BaseJpaService;
  7. import com.yihu.jw.dao.*;
  8. import com.yihu.jw.entity.health.bank.*;
  9. import com.yihu.jw.restmodel.common.Envelop;
  10. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  11. import com.yihu.jw.util.DateUtils;
  12. import com.yihu.jw.util.ISqlUtils;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.data.redis.core.StringRedisTemplate;
  18. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  19. import org.springframework.jdbc.core.JdbcTemplate;
  20. import org.springframework.stereotype.Service;
  21. import javax.transaction.Transactional;
  22. import java.text.ParseException;
  23. import java.text.SimpleDateFormat;
  24. import java.util.ArrayList;
  25. import java.util.Date;
  26. import java.util.List;
  27. import java.util.Map;
  28. /**
  29. * @author wangzhinan
  30. * @create 2018-04-27 16:53
  31. * @desc credits log info Service
  32. **/
  33. @Service
  34. @Transactional
  35. public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,CredittsLogDetailDao> {
  36. private Logger logger = LoggerFactory.getLogger(CreditsDetailService.class);
  37. private static String STEP = "health:blank:step";
  38. @Autowired
  39. private CredittsLogDetailDao credittsLogDetailDao;
  40. @Autowired
  41. private TaskDao taskDao;
  42. @Autowired
  43. private ActivityDao activityDao;
  44. @Autowired
  45. private JdbcTemplate jdbcTemplate;
  46. @Autowired
  47. private AccountDao accountDao;
  48. @Autowired
  49. private TaskPatientDetailDao taskPatientDetailDao;
  50. @Autowired
  51. private TaskRuleDao taskRuleDao;
  52. @Autowired
  53. private StringRedisTemplate redisTemplate;
  54. @Autowired
  55. private ActiveRecordService activeRecordService;
  56. /**
  57. * find creditsLogInfo
  58. *
  59. * @return
  60. * @throws ParseException
  61. */
  62. public Envelop<CreditsDetailDO> findByCondition(CreditsDetailDO creditsDetailDO, Integer page, Integer size) throws ParseException {
  63. String sql = new ISqlUtils().getSql(creditsDetailDO,page,size,"*");
  64. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  65. for (CreditsDetailDO creditsDetailDO1 : creditsDetailDOS){
  66. if (creditsDetailDO1.getTradeType() != null && creditsDetailDO1.getTradeType().equalsIgnoreCase("ACTIVITY_TASK")){
  67. TaskDO taskDO = taskDao.findOne(creditsDetailDO1.getTransactionId());
  68. creditsDetailDO1.setTaskDO(taskDO);
  69. }
  70. }
  71. String sqlcount = new ISqlUtils().getSql(creditsDetailDO,0,0,"count");
  72. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
  73. Long count = 0L;
  74. if(rstotal!=null&&rstotal.size()>0){
  75. count = (Long) rstotal.get(0).get("total");
  76. }
  77. return Envelop.getSuccessListWithPage(HealthBankMapping.api_success, creditsDetailDOS,page,size,count);
  78. }
  79. /**
  80. * 获取账户信息
  81. *
  82. * @param creditsDetailDO
  83. * @return
  84. */
  85. public Envelop<AccountDO> findByTradeDirection(CreditsDetailDO creditsDetailDO){
  86. AccountDO accountDO1 = new AccountDO();
  87. accountDO1.setPatientId(creditsDetailDO.getPatientId());
  88. String sql1 = ISqlUtils.getAllSql(accountDO1);
  89. List<AccountDO> accountDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(AccountDO.class));
  90. if (accountDOS == null || accountDOS.size() == 0){
  91. accountDO1.setTotal(0);
  92. accountDO1.setAccountName(creditsDetailDO.getName());
  93. if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
  94. String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
  95. int random = (int)((Math.random()*9+1)*100000);
  96. accountDO1.setCardNumber(cardNumber+Integer.toString(random));
  97. }
  98. accountDO1.setHospital(creditsDetailDO.getHospital());
  99. accountDO1.setPassword("123456");
  100. accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
  101. accountDO1.setStatus(1);
  102. accountDO1.setSaasId("dev");
  103. accountDO1.setCreateTime(new Date());
  104. accountDO1.setUpdateTime(new Date());
  105. accountDao.save(accountDO1);
  106. }
  107. List<AccountDO> accountDOS1 = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(AccountDO.class));
  108. AccountDO accountDO = accountDOS1.get(0);
  109. 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()+"'";
  110. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
  111. if (rstotal!= null && rstotal.size()>0){
  112. if (rstotal.get(0).get("total") == null){
  113. accountDO.setUsedTotal(0);
  114. }else {
  115. accountDO.setUsedTotal(Integer.parseInt(rstotal.get(0).get("total").toString()));
  116. }
  117. }
  118. return Envelop.getSuccess(HealthBankMapping.api_success,accountDO);
  119. }
  120. /*
  121. public Envelop<Boolean> exchangeGoods(GoodsDO goodsDO){
  122. CreditsDetailDO creditsLogDetailDO = new CreditsDetailDO();
  123. Envelop<Boolean> envelop = new Envelop<>();
  124. envelop.setObj(true);
  125. return envelop;
  126. }
  127. */
  128. public Envelop<AccountDO> selectByRanking(List<String> patientIds, Integer page, Integer size){
  129. StringBuffer buffer = new StringBuffer();
  130. buffer.append(" ba.patient_id in(");
  131. if (patientIds == null || patientIds.size() == 0){
  132. buffer.append("''");
  133. }else {
  134. for (int i=0;i<patientIds.size();i++){
  135. buffer.append("'"+patientIds.get(i)+"'").append(",");
  136. }
  137. buffer.deleteCharAt(buffer.length()-1);
  138. }
  139. buffer.append(") ");
  140. String sql =
  141. "SELECT ba1.patient_id AS patient_id," +
  142. "ba1.account_name AS account_name," +
  143. "ba1.hospital AS hospital," +
  144. "ba1.total AS total," +
  145. "ba1.create_time AS create_time," +
  146. "ba1.sum AS sum" +
  147. " FROM" +
  148. "( SELECT " +
  149. "ba.patient_id AS patient_id," +
  150. "ba.account_name AS account_name," +
  151. "ba.hospital AS hospital," +
  152. "ba.total AS total," +
  153. "ba.create_time AS create_time," +
  154. " if(ba.total=0,ba.total,(ba.total +COALESCE((cd1.total),0))) AS sum" +
  155. " FROM" +
  156. " wlyy_health_bank_account ba" +
  157. " LEFT JOIN ( " +
  158. "SELECT" +
  159. " SUM(cd.integrate) AS total," +
  160. " cd.patient_id AS patient_id" +
  161. " FROM" +
  162. " wlyy_health_bank_credits_detail cd" +
  163. " WHERE " +
  164. "cd.trade_direction = - 1" +
  165. " GROUP BY " +
  166. " cd.patient_id ) cd1 ON cd1.patient_id = ba.patient_id " +
  167. " WHERE " + buffer +
  168. " ORDER BY" +
  169. " ba.create_time DESC " +
  170. "LIMIT "+(page-1)*size+","+size +")ba1" +
  171. " ORDER BY " +
  172. " ba1.total DESC";
  173. List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
  174. String sqlCount = "SELECT count(1) AS total"+
  175. " FROM " +
  176. " wlyy_health_bank_account ba LEFT JOIN " +
  177. " ( " +
  178. " SELECT " +
  179. " SUM(cd.integrate) AS total, " +
  180. " cd.patient_id AS patient_id " +
  181. " FROM " +
  182. " wlyy_health_bank_credits_detail cd " +
  183. " WHERE " +
  184. " cd.trade_direction = - 1 " +
  185. " GROUP BY " +
  186. " cd.patient_id " +
  187. " ) cd1 ON cd1.patient_id = ba.patient_id " +
  188. "WHERE " + buffer +
  189. " ORDER BY " +
  190. " ba.create_time, " +
  191. " (ba.total + COALESCE(cd1.total,0)) DESC ";
  192. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount);
  193. Long count = 0L;
  194. if(rstotal!=null&&rstotal.size()>0){
  195. count = (Long) rstotal.get(0).get("total");
  196. }
  197. return Envelop.getSuccessListWithPage(HealthBankMapping.api_success, accountDOS,page,size,count);
  198. }
  199. /**
  200. * 添加积分
  201. *
  202. * @param creditsDetailDO
  203. * @return
  204. */
  205. public Envelop<CreditsDetailDO> insert(CreditsDetailDO creditsDetailDO){
  206. try {
  207. synchronized (creditsDetailDO.getPatientId()){
  208. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '"+creditsDetailDO.getPatientId() +"'";
  209. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  210. if (accountDOList != null && accountDOList.size() != 0){
  211. creditsDetailDO.setAccountId(accountDOList.get(0).getId());
  212. }else {
  213. AccountDO accountDO1 = new AccountDO();
  214. accountDO1.setPatientId(creditsDetailDO.getPatientId());
  215. accountDO1.setTotal(0);
  216. accountDO1.setAccountName(creditsDetailDO.getName());
  217. if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
  218. String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
  219. int random = (int)((Math.random()*9+1)*100000);
  220. accountDO1.setCardNumber(cardNumber+Integer.toString(random));
  221. }
  222. accountDO1.setHospital(creditsDetailDO.getHospital());
  223. accountDO1.setPassword("123456");
  224. accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
  225. accountDO1.setStatus(1);
  226. accountDO1.setCreateTime(new Date());
  227. accountDO1.setUpdateTime(new Date());
  228. accountDao.save(accountDO1);
  229. List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  230. creditsDetailDO.setAccountId(accountDOS.get(0).getId());
  231. }
  232. TaskDO taskDO = new TaskDO();
  233. taskDO.setTaskCode(creditsDetailDO.getFlag());
  234. taskDO.setId(creditsDetailDO.getTransactionId());
  235. /*taskDO.setPatientId(creditsDetailDO.getPatientId());*/
  236. String sql = ISqlUtils.getSql(taskDO,1,1,"*");
  237. List<TaskDO> taskDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskDO.class));
  238. creditsDetailDO.setTransactionId(taskDOList.get(0).getId());
  239. String ruleSql = "SELECT * FROM wlyy_health_bank_task_rule WHERE id= '"+taskDOList.get(0).getRuleCode()+"'";
  240. List<TaskRuleDO> taskRuleDOS = jdbcTemplate.query(ruleSql,new BeanPropertyRowMapper(TaskRuleDO.class));
  241. TaskRuleDO taskRuleDO = taskRuleDOS.get(0);
  242. creditsDetailDO.setIntegrate(taskRuleDO.getIntegrate());
  243. creditsDetailDO.setTradeDirection(taskRuleDO.getTradeDirection());
  244. String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDOList.get(0).getId()+"' and patient_id = '" + creditsDetailDO.getPatientId() +"'";
  245. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  246. if (taskPatientDetailDOS == null || taskPatientDetailDOS.size() ==0){
  247. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  248. taskPatientDetailDO.setTaskId(creditsDetailDO.getTransactionId());
  249. taskPatientDetailDO.setSaasId(creditsDetailDO.getSaasId());
  250. taskPatientDetailDO.setPatientId(creditsDetailDO.getPatientId());
  251. taskPatientDetailDO.setPatientIdcard(creditsDetailDO.getIdCard());
  252. taskPatientDetailDO.setPatientOpenid(creditsDetailDO.getOpenId());
  253. taskPatientDetailDO.setUnionId(creditsDetailDO.getUnionId());
  254. taskPatientDetailDO.setStatus(Integer.parseInt("0"));
  255. taskPatientDetailDO.setCreateTime(new Date());
  256. taskPatientDetailDO.setUpdateTime(new Date());
  257. taskPatientDetailDO.setActivityId(taskDOList.get(0).getTransactionId());
  258. taskPatientDetailDO.setTotal(Long.parseLong("0"));
  259. taskPatientDetailDao.save(taskPatientDetailDO);
  260. }else if (taskPatientDetailDOS != null && taskDOList.get(0).getPeriod() == 0){
  261. String taskSql1 = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDOList.get(0).getId()+
  262. "' and patient_id = '"+creditsDetailDO.getPatientId()+"' and create_time > '" + DateUtils.getDayBegin() +"' and create_time < '"+ DateUtils.getDayEnd() +"'";
  263. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  264. if (taskPatientDetailDOS1 == null || taskPatientDetailDOS1.size() == 0){
  265. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  266. taskPatientDetailDO.setTaskId(creditsDetailDO.getTransactionId());
  267. taskPatientDetailDO.setSaasId(creditsDetailDO.getSaasId());
  268. taskPatientDetailDO.setPatientId(creditsDetailDO.getPatientId());
  269. taskPatientDetailDO.setPatientIdcard(creditsDetailDO.getIdCard());
  270. taskPatientDetailDO.setPatientOpenid(creditsDetailDO.getOpenId());
  271. taskPatientDetailDO.setActivityId(taskDOList.get(0).getTransactionId());
  272. taskPatientDetailDO.setStatus(Integer.parseInt("0"));
  273. taskPatientDetailDO.setCreateTime(new Date());
  274. taskPatientDetailDO.setUpdateTime(new Date());
  275. taskPatientDetailDO.setTotal(Long.parseLong("0"));
  276. taskPatientDetailDao.save(taskPatientDetailDO);
  277. }
  278. }
  279. creditsDetailDO.setCreateTime(new Date());
  280. creditsDetailDO.setUpdateTime(new Date());
  281. CreditsDetailDO creditsDetailDO1 =credittsLogDetailDao.save(creditsDetailDO);
  282. creditsDetailDO1.setFlag(creditsDetailDO.getFlag());
  283. List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
  284. creditsDetailDOList.add(creditsDetailDO1);
  285. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  286. taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  287. taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
  288. String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
  289. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  290. TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
  291. if (creditsDetailDO1.getTradeDirection() == 1){
  292. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal()+creditsDetailDO1.getIntegrate());
  293. }else if (creditsDetailDO.getTradeDirection() == -1){
  294. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal()-creditsDetailDO1.getIntegrate());
  295. }
  296. taskPatientDetailDao.save(taskPatientDetailDO1);
  297. AccountDO accountDO = accountDao.findOne(creditsDetailDO1.getAccountId());
  298. if (creditsDetailDO1.getTradeDirection() == 1){
  299. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO1.getIntegrate());
  300. }else if (creditsDetailDO.getTradeDirection() == -1){
  301. accountDO.setTotal(accountDO.getTotal()-creditsDetailDO1.getIntegrate());
  302. }
  303. AccountDO accountDO1 = accountDao.save(accountDO);
  304. List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
  305. for (CreditsDetailDO creditsDetailDO2:creditsDetailDOList){
  306. creditsDetailDO2.setTotal(accountDO1.getTotal());
  307. creditsDetailDOS.add(creditsDetailDO2);
  308. }
  309. Envelop<CreditsDetailDO> envelop = new Envelop<>();
  310. envelop.setDetailModelList(creditsDetailDOS);
  311. return envelop;
  312. }
  313. }catch (Exception e){
  314. e.printStackTrace();
  315. Envelop<CreditsDetailDO> envelop = new Envelop<>();
  316. return envelop;
  317. }
  318. }
  319. /**
  320. * 活动排名
  321. *
  322. * @param activityId 活动id
  323. * @param ids 微信编码
  324. *
  325. * @param page 页码
  326. *
  327. * @param size 分页大小
  328. * @return
  329. */
  330. public Envelop<TaskPatientDetailDO> selectByActivityRanking(String activityId,List<String> ids,Integer page,Integer size){
  331. StringBuffer buffer = new StringBuffer();
  332. buffer.append("(");
  333. if (ids == null || ids.size() == 0){
  334. buffer.append("''");
  335. }else {
  336. for (int i=0;i<ids.size();i++){
  337. buffer.append("'"+ids.get(i)+"'").append(",");
  338. }
  339. buffer.deleteCharAt(buffer.length()-1);
  340. }
  341. buffer.append(") ");
  342. String sql = "SELECT " +
  343. " * " +
  344. "FROM " +
  345. " ( " +
  346. " SELECT " +
  347. " SUM(ptpd.total) AS total, " +
  348. " ptpd.patient_openid AS patient_openid, " +
  349. " ptpd.task_id AS task_id, " +
  350. " ptpd.activity_id AS activity_id, " +
  351. " ptpd.create_time as create_time, " +
  352. " ptpd.patient_id AS patient_id " +
  353. " FROM " +
  354. " wlyy_health_bank_task_patient_detail ptpd " +
  355. " WHERE " +
  356. " activity_id = '" + activityId +
  357. "' GROUP BY " +
  358. " patient_id " +
  359. " ORDER BY ptpd.create_time DESC " +
  360. " )btpd1 " +
  361. " WHERE patient_id IN "+buffer+
  362. " ORDER BY btpd1.total DESC "+" LIMIT " + (page-1)*size+","+size;
  363. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  364. for (TaskPatientDetailDO taskPatientDetailDO : taskPatientDetailDOS){
  365. String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
  366. List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
  367. taskPatientDetailDO.setAccountDO(accountDOS.get(0));
  368. }
  369. String sqlCount = "SELECT " +
  370. " count(1) AS total " +
  371. "FROM " +
  372. " ( " +
  373. " SELECT " +
  374. " SUM(ptpd.total) AS total, " +
  375. " ptpd.patient_openid AS patient_openid, " +
  376. " ptpd.task_id AS task_id, " +
  377. " ptpd.activity_id AS activity_id, " +
  378. " ptpd.create_time as create_time, " +
  379. " ptpd.patient_id AS patient_id " +
  380. " FROM " +
  381. " wlyy_health_bank_task_patient_detail ptpd " +
  382. " WHERE " +
  383. " activity_id = '" + activityId+
  384. "' GROUP BY " +
  385. " patient_openid " +
  386. " ORDER BY ptpd.create_time DESC " +
  387. " )btpd1 " +
  388. "WHERE patient_openid IN "+buffer+
  389. " ORDER BY btpd1.total DESC ";
  390. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount);
  391. Long count = 0L;
  392. if(rstotal!=null&&rstotal.size()>0){
  393. count = (Long) rstotal.get(0).get("total");
  394. }
  395. return Envelop.getSuccessListWithPage(HealthBankMapping.api_success, taskPatientDetailDOS,page,size,count);
  396. }
  397. /**
  398. * 根据活动查询积分
  399. *
  400. * @param activityId 活动id
  401. *
  402. * @param patientId 居民id
  403. *
  404. * @param page 页码
  405. *
  406. * @param size 分页大小
  407. * @return
  408. */
  409. public Envelop<CreditsDetailDO> selectByActivity(String activityId,String patientId,Integer page,Integer size){
  410. String sql="SELECT * " +
  411. "FROM " +
  412. " wlyy_health_bank_credits_detail " +
  413. "WHERE" +
  414. " transaction_id IN ( " +
  415. " SELECT " +
  416. " bt.id " +
  417. " FROM " +
  418. " wlyy_health_bank_task bt " +
  419. " WHERE " +
  420. " transaction_id = '"+activityId +"' " +
  421. " ) " +
  422. " and patient_id = '" +patientId+
  423. "' LIMIT "+(page-1)*size +","+size;
  424. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  425. for (CreditsDetailDO creditsDetailDO : creditsDetailDOS){
  426. TaskDO taskDO = taskDao.findOne(creditsDetailDO.getTransactionId());
  427. creditsDetailDO.setTaskDO(taskDO);
  428. }
  429. String sqlcount = "SELECT count(1) AS" +
  430. " total FROM " +
  431. " wlyy_health_bank_credits_detail " +
  432. "WHERE" +
  433. " transaction_id IN ( " +
  434. " SELECT " +
  435. " bt.id " +
  436. " FROM " +
  437. " wlyy_health_bank_task bt " +
  438. " WHERE " +
  439. " transaction_id = '"+activityId +"' " +
  440. " ) " +
  441. " and patient_id = '" +patientId+
  442. "'";
  443. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
  444. Long count = 0L;
  445. if(rstotal!=null&&rstotal.size()>0){
  446. count = (Long) rstotal.get(0).get("total");
  447. }
  448. return Envelop.getSuccessListWithPage(HealthBankMapping.api_success,creditsDetailDOS,page,size,count);
  449. }
  450. /**
  451. * 根据活动查找全部排行
  452. *
  453. * @param activityId 活动id
  454. * @param page 页码
  455. * @param size 分页大小
  456. * @return
  457. */
  458. public Envelop<TaskPatientDetailDO> selectByActivityRanking1(String activityId,String patientId,Integer page,Integer size){
  459. String sql = "SELECT " +
  460. " * " +
  461. "FROM " +
  462. " ( " +
  463. " SELECT " +
  464. " SUM(ptpd.total) AS total, " +
  465. " ptpd.patient_openid AS patient_openid, " +
  466. " ptpd.task_id AS task_id, " +
  467. " ptpd.activity_id AS activity_id, " +
  468. " ptpd.create_time as create_time, " +
  469. " ptpd.patient_id AS patient_id " +
  470. " FROM " +
  471. " wlyy_health_bank_task_patient_detail ptpd " +
  472. " WHERE " +
  473. " activity_id = '" + activityId +
  474. "' GROUP BY " +
  475. " patient_openid " +
  476. " ORDER BY ptpd.create_time DESC " +
  477. " )btpd1 " +
  478. " ORDER BY btpd1.total DESC "+" LIMIT " + (page-1)*size+","+size;
  479. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  480. logger.info(taskPatientDetailDOS.toString()+""+taskPatientDetailDOS.size());
  481. for (int i = 0;taskPatientDetailDOS != null&&taskPatientDetailDOS.size()!=0 && i<taskPatientDetailDOS.size();i++){
  482. TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDOS.get(i);
  483. String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
  484. List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
  485. if (taskPatientDetailDOS.get(i).getPatientId().equalsIgnoreCase(patientId)){
  486. /*String taskSql = "select count(1)+1 as total from (" +
  487. "select * from (SELECT " +
  488. " SUM(ptpd.total) AS total, " +
  489. " ptpd.patient_openid AS patient_openid, " +
  490. " ptpd.task_id AS task_id, " +
  491. " ptpd.activity_id AS activity_id, " +
  492. " ptpd.create_time as create_time, " +
  493. " ptpd.patient_id AS patient_id " +
  494. " FROM " +
  495. " wlyy_health_bank_task_patient_detail ptpd " +
  496. " WHERE " +
  497. " activity_id = '" + activityId + "')ptpd1 where" +
  498. " ptpd1.patient_id = '"+patientId+"' AND ptpd1.total > "+taskPatientDetailDOS.get(i).getTotal()+") ptpd2";
  499. List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(taskSql);
  500. Long count = 0L;
  501. if(rstotal1!=null&&rstotal1.size()>0){
  502. count = (Long) rstotal1.get(0).get("total");
  503. }
  504. accountDOS.get(0).setActivityRanking(count);*/
  505. taskPatientDetailDO.setIsFlag(1);
  506. }else {
  507. taskPatientDetailDO.setIsFlag(0);
  508. }
  509. taskPatientDetailDO.setAccountDO(accountDOS.get(0));
  510. }
  511. String sqlCount = "SELECT " +
  512. " count(1) AS total " +
  513. "FROM " +
  514. " ( " +
  515. " SELECT " +
  516. " SUM(ptpd.total) AS total, " +
  517. " ptpd.patient_openid AS patient_openid, " +
  518. " ptpd.task_id AS task_id, " +
  519. " ptpd.activity_id AS activity_id, " +
  520. " ptpd.create_time as create_time, " +
  521. " ptpd.patient_id AS patient_id " +
  522. " FROM " +
  523. " wlyy_health_bank_task_patient_detail ptpd " +
  524. " WHERE " +
  525. " activity_id = '" + activityId+
  526. "' GROUP BY " +
  527. " patient_openid " +
  528. " ORDER BY ptpd.create_time DESC " +
  529. " )btpd1 " +
  530. " ORDER BY btpd1.total DESC ";
  531. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount);
  532. Long count = 0L;
  533. if(rstotal!=null&&rstotal.size()>0){
  534. count = (Long) rstotal.get(0).get("total");
  535. }
  536. return Envelop.getSuccessListWithPage(HealthBankMapping.api_success, taskPatientDetailDOS,page,size,count);
  537. }
  538. /**
  539. * 医生主动加分
  540. *
  541. * @param array 居民信息集合
  542. *
  543. * @param ruleId 规则id
  544. * @return
  545. */
  546. public Envelop<Boolean> doctorAddIntegrate(JSONArray array, String ruleId, String description) throws Exception {
  547. Envelop<Boolean> envelop = new Envelop<>();
  548. for (int i=0;i<array.size();i++){
  549. TaskRuleDO taskRuleDO = taskRuleDao.findOne(ruleId);
  550. JSONObject object = array.getJSONObject(i);
  551. String patientId = object.getString("code");
  552. String idCard = object.getString("idcard");
  553. String unionId = object.getString("unionid");
  554. String openId = object.getString("openid");
  555. String hospital = object.getString("hospital");
  556. String hospitalName = object.getString("hospitalName");
  557. String taskSql = "select * from wlyy_health_bank_task bt where type = 'RULE_TASK' AND transaction_id = '"+ruleId +"'";
  558. List<TaskDO> taskDOList = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskDO.class));
  559. TaskDO taskDO1 = new TaskDO();
  560. if (taskDOList.isEmpty() && taskDOList.size() == 0){
  561. TaskDO taskDO = new TaskDO();
  562. taskDO.setTransactionId(taskRuleDO.getId());
  563. taskDO.setTaskCode("RULE");
  564. taskDO.setStatus(1);
  565. taskDO.setRuleCode(taskRuleDO.getId());
  566. taskDO.setType("RULE_TASK");
  567. taskDO.setCreateTime(new Date());
  568. taskDO.setUpdateTime(new Date());
  569. taskDO.setPeriod(taskRuleDO.getPeriod());
  570. taskDO.setSaasId("dev");
  571. taskDO.setTitle(taskRuleDO.getDescription());
  572. taskDO.setContent(taskRuleDO.getDescription());
  573. taskDO1 = taskDao.save(taskDO);
  574. }else {
  575. taskDO1 = taskDOList.get(0);
  576. }
  577. if (taskRuleDO.getPeriod() == 1){
  578. String sql = "select * from wlyy_health_bank_task_patient_detail where patient_id = '"+patientId+"'AND task_id ='"+taskDO1.getId()+"'";
  579. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  580. if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
  581. throw new Exception("已奖励过");
  582. }
  583. }else if (taskRuleDO.getPeriod() == 0){
  584. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  585. Date date = new Date();
  586. String date1 = dateFormat.format(date);
  587. String begin = DateUtils.getMinMonthDate(date1);
  588. String end = DateUtils.getMaxMonthDate(date1);
  589. 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+"'";
  590. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  591. if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
  592. throw new Exception("已奖励过");
  593. }
  594. }
  595. String sql1 = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+"' " +
  596. "AND patient_idcard = '"+idCard+"' AND patient_openid = '"+openId+"' AND union_id = '"+unionId+"'";
  597. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  598. TaskPatientDetailDO taskPatientDetailDO1 = new TaskPatientDetailDO();
  599. if (taskPatientDetailDOS.isEmpty() && taskPatientDetailDOS.size() == 0){
  600. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  601. taskPatientDetailDO.setStatus(1);
  602. taskPatientDetailDO.setTotal(Long.parseLong("0"));
  603. taskPatientDetailDO.setPatientId(patientId);
  604. taskPatientDetailDO.setPatientOpenid(openId);
  605. taskPatientDetailDO.setPatientIdcard(idCard);
  606. taskPatientDetailDO.setUnionId(unionId);
  607. taskPatientDetailDO.setSaasId("dev");
  608. taskPatientDetailDO.setCreateTime(new Date());
  609. taskPatientDetailDO.setUpdateTime(new Date());
  610. taskPatientDetailDO.setTaskId(taskDO1.getId());
  611. taskPatientDetailDO1 = taskPatientDetailDao.save(taskPatientDetailDO);
  612. }else {
  613. taskPatientDetailDO1 = taskPatientDetailDOS.get(0);
  614. }
  615. String sql = "select * from wlyy_health_bank_account where patient_id = '"+patientId+"'";
  616. List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
  617. if (taskRuleDO.getTradeDirection() == -1 && taskRuleDO.getIntegrate() == 0){
  618. String integrateSql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+patientId+"' " +
  619. "AND transaction_id IN (SELECT id FROM wlyy_health_bank_task WHERE task_code IN ('BP_BIND','GLU_BIND','BP_MEASURE','GLU_MEASURE','RULE'))";
  620. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(integrateSql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  621. for (CreditsDetailDO creditsDetailDO:creditsDetailDOS){
  622. if (creditsDetailDO.getTradeDirection()==1&&creditsDetailDO.getStatus()!=0){
  623. AccountDO accountDO = accountDOS.get(0);
  624. int total = accountDO.getTotal() - creditsDetailDO.getIntegrate();
  625. creditsDetailDO.setStatus(0);
  626. creditsDetailDO.setDescription(description);
  627. credittsLogDetailDao.save(creditsDetailDO);
  628. accountDO.setTotal(total);
  629. accountDao.save(accountDO);
  630. }
  631. }
  632. CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
  633. creditsDetailDO1.setStatus(1);
  634. creditsDetailDO1.setSaasId("dev");
  635. creditsDetailDO1.setAccountId(accountDOS.get(0).getId());
  636. creditsDetailDO1.setHospital(hospital);
  637. creditsDetailDO1.setHospitalName(hospitalName);
  638. creditsDetailDO1.setPatientId(patientId);
  639. creditsDetailDO1.setIntegrate(taskRuleDO.getIntegrate());
  640. creditsDetailDO1.setTradeDirection(taskRuleDO.getTradeDirection());
  641. creditsDetailDO1.setDescription(description);
  642. creditsDetailDO1.setCreateTime(new Date());
  643. creditsDetailDO1.setUpdateTime(new Date());
  644. creditsDetailDO1.setTransactionId(taskDO1.getId());
  645. creditsDetailDO1.setTradeType("ACTIVITY_TASK");
  646. credittsLogDetailDao.save(creditsDetailDO1);
  647. }else{
  648. CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
  649. creditsDetailDO.setStatus(1);
  650. creditsDetailDO.setSaasId("dev");
  651. creditsDetailDO.setAccountId(accountDOS.get(0).getId());
  652. creditsDetailDO.setHospital(hospital);
  653. creditsDetailDO.setHospitalName(hospitalName);
  654. creditsDetailDO.setPatientId(patientId);
  655. creditsDetailDO.setIntegrate(taskRuleDO.getIntegrate());
  656. creditsDetailDO.setTradeDirection(taskRuleDO.getTradeDirection());
  657. creditsDetailDO.setDescription(description);
  658. creditsDetailDO.setCreateTime(new Date());
  659. creditsDetailDO.setUpdateTime(new Date());
  660. creditsDetailDO.setTransactionId(taskDO1.getId());
  661. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  662. credittsLogDetailDao.save(creditsDetailDO);
  663. if (taskRuleDO.getTradeDirection() == -1){
  664. String integrateSql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+patientId+"' " +
  665. "AND transaction_id IN (SELECT id FROM wlyy_health_bank_task WHERE task_code IN ('BP_BIND','GLU_BIND','BP_MEASURE','GLU_MEASURE','RULE'))";
  666. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(integrateSql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  667. for (CreditsDetailDO creditsDetailDO1:creditsDetailDOS){
  668. if (creditsDetailDO1.getTradeDirection()==1&&creditsDetailDO1.getStatus()!=0){
  669. AccountDO accountDO = accountDOS.get(0);
  670. int total = accountDO.getTotal() - creditsDetailDO1.getIntegrate();
  671. creditsDetailDO1.setStatus(0);
  672. creditsDetailDO1.setDescription(description);
  673. credittsLogDetailDao.save(creditsDetailDO1);
  674. accountDO.setTotal(total);
  675. accountDao.save(accountDO);
  676. }
  677. }
  678. }else if (taskRuleDO.getTradeDirection() == 1){
  679. AccountDO accountDO = accountDOS.get(0);
  680. accountDO.setTotal(accountDO.getTotal() + taskRuleDO.getIntegrate());
  681. accountDao.save(accountDO);
  682. }
  683. }
  684. }
  685. envelop.setObj(true);
  686. return envelop;
  687. }
  688. /**
  689. * 固定数据
  690. *
  691. * @param
  692. * @return
  693. *//*
  694. public List<TaskDO> getTasks(String patientId){
  695. List<TaskDO> taskDOList = new ArrayList<>();
  696. TaskDO taskDO = new TaskDO();
  697. *//*taskDO.setPatientId(patientId);*//*
  698. taskDO.setTaskCode("BIND");
  699. taskDO.setPeriod(1);
  700. taskDO.setTaskTitle("首次绑定");
  701. taskDO.setTaskContent("(绑定社区登记发放的设备,可获得各类型设备的首绑奖励。)");
  702. taskDO.setTradeType("activity");
  703. taskDO.setTransactionId("402885e96324a409016324c0a45a0006");
  704. taskDO.setCreateTime(new Date());
  705. taskDO.setUpdateTime(new Date());
  706. taskDOList.add(taskDO);
  707. TaskDO taskDO1 = new TaskDO();
  708. *//*taskDO1.setPatientId(patientId);*//*
  709. taskDO1.setTaskCode("MEASURE");
  710. taskDO1.setPeriod(0);
  711. taskDO1.setTaskTitle("每日测量");
  712. taskDO1.setTaskContent("(使用社区发放的已关联您身份信息的设备,绑定后每天完成测量)");
  713. taskDO1.setTradeType("activity");
  714. taskDO1.setTransactionId("402885e96324a409016324c0a45a0006");
  715. taskDO1.setCreateTime(new Date());
  716. taskDO1.setUpdateTime(new Date());
  717. taskDOList.add(taskDO1);
  718. return taskDOList;
  719. }
  720. */
  721. public Envelop<CreditsDetailDO> stepAddIntegrate(CreditsDetailDO creditsDetailDO){
  722. try {
  723. synchronized (creditsDetailDO.getPatientId()){
  724. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '"+creditsDetailDO.getPatientId() +"'";
  725. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  726. if (accountDOList != null && accountDOList.size() != 0){
  727. creditsDetailDO.setAccountId(accountDOList.get(0).getId());
  728. }else {
  729. AccountDO accountDO1 = new AccountDO();
  730. accountDO1.setPatientId(creditsDetailDO.getPatientId());
  731. accountDO1.setSaasId("dev");
  732. accountDO1.setTotal(0);
  733. accountDO1.setAccountName(creditsDetailDO.getName());
  734. if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
  735. String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
  736. int random = (int)((Math.random()*9+1)*100000);
  737. accountDO1.setCardNumber(cardNumber+Integer.toString(random));
  738. }
  739. accountDO1.setHospital(creditsDetailDO.getHospital());
  740. accountDO1.setPassword("123456");
  741. accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
  742. accountDO1.setStatus(1);
  743. accountDO1.setCreateTime(new Date());
  744. accountDO1.setUpdateTime(new Date());
  745. accountDao.save(accountDO1);
  746. List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  747. creditsDetailDO.setAccountId(accountDOS.get(0).getId());
  748. }
  749. TaskDO taskDO = taskDao.findOne(creditsDetailDO.getTransactionId());
  750. String sql1 = "select * from wlyy_health_bank_task_patient_detail where patient_openid = '"+creditsDetailDO.getOpenId()+"' " +
  751. "AND patient_idcard = '"+creditsDetailDO.getIdCard()+"' AND union_id = '"+creditsDetailDO.getUnionId()+"' AND task_id = '"+creditsDetailDO.getTransactionId()+"'";
  752. List<TaskPatientDetailDO> taskPatientDetailDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  753. TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDOList.get(0);
  754. String sql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+creditsDetailDO.getPatientId()+"' AND " +
  755. "transaction_id = '"+creditsDetailDO.getTransactionId()+"' AND create_time > '"+DateUtils.getDayBegin() +"' AND" +
  756. " create_time < '"+DateUtils.getDayEnd()+"'";
  757. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
  758. String step = redisTemplate.opsForValue().get(STEP);
  759. if (StringUtils.isEmpty(step)){
  760. throw new Exception("获取步数失败!");
  761. }
  762. JSONObject object = JSONObject.parseObject(step);
  763. int step1 = object.getInteger("step1");
  764. int step2 = object.getInteger("step2");
  765. int step3 = object.getInteger("step3");
  766. if (creditsDetailDOS != null && creditsDetailDOS.size() != 0){
  767. CreditsDetailDO creditsDetailDO1 = creditsDetailDOS.get(0);
  768. TaskRuleDO taskRuleDO = taskRuleDao.findOne(taskDO.getRuleCode());
  769. if (creditsDetailDO.getStepNumber() == step1){
  770. creditsDetailDO1.setIntegrate(1);
  771. creditsDetailDO1.setTradeDirection(1);
  772. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  773. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  774. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO2.getIntegrate());
  775. AccountDO accountDO1 = accountDao.save(accountDO);
  776. creditsDetailDO2.setTotal(accountDO1.getTotal());
  777. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+creditsDetailDO2.getIntegrate());
  778. taskPatientDetailDao.save(taskPatientDetailDO);
  779. creditsDetailDOS.clear();
  780. creditsDetailDOS.add(creditsDetailDO2);
  781. }else if (creditsDetailDO.getStepNumber() == step2){
  782. creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+2);
  783. creditsDetailDO1.setTradeDirection(1);
  784. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  785. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  786. accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
  787. AccountDO accountDO1 = accountDao.save(accountDO);
  788. creditsDetailDO2.setTotal(accountDO1.getTotal());
  789. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
  790. taskPatientDetailDao.save(taskPatientDetailDO);
  791. creditsDetailDOS.clear();
  792. creditsDetailDOS.add(creditsDetailDO2);
  793. }else if (creditsDetailDO.getStepNumber() == step3){
  794. if (creditsDetailDO1.getIntegrate() == 1){
  795. creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+7);
  796. creditsDetailDO1.setTradeDirection(1);
  797. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  798. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  799. accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
  800. AccountDO accountDO1 = accountDao.save(accountDO);
  801. creditsDetailDO2.setTotal(accountDO1.getTotal());
  802. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
  803. taskPatientDetailDao.save(taskPatientDetailDO);
  804. creditsDetailDOS.clear();
  805. creditsDetailDOS.add(creditsDetailDO2);
  806. }else if(creditsDetailDO1.getIntegrate() == 3){
  807. creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+5);
  808. creditsDetailDO1.setTradeDirection(1);
  809. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  810. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  811. accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()-3));
  812. AccountDO accountDO1 = accountDao.save(accountDO);
  813. creditsDetailDO2.setTotal(accountDO1.getTotal());
  814. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()-3));
  815. taskPatientDetailDao.save(taskPatientDetailDO);
  816. creditsDetailDOS.clear();
  817. creditsDetailDOS.add(creditsDetailDO2);
  818. }
  819. }
  820. }else{
  821. CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
  822. if (creditsDetailDO.getStepNumber() == step1){
  823. creditsDetailDO1.setIntegrate(1);
  824. creditsDetailDO1.setTradeDirection(1);
  825. }else if (creditsDetailDO.getStepNumber() == step2){
  826. creditsDetailDO1.setIntegrate(3);
  827. creditsDetailDO1.setTradeDirection(1);
  828. }else if (creditsDetailDO.getStepNumber() == step3){
  829. creditsDetailDO1.setIntegrate(8);
  830. creditsDetailDO1.setTradeDirection(1);
  831. }
  832. creditsDetailDO1.setSaasId("dev");
  833. creditsDetailDO1.setTradeType("ACTIVITY_TASK");
  834. creditsDetailDO1.setPatientId(creditsDetailDO.getPatientId());
  835. creditsDetailDO1.setHospital(creditsDetailDO.getHospital());
  836. creditsDetailDO1.setHospitalName(creditsDetailDO.getHospitalName());
  837. creditsDetailDO1.setAccountId(creditsDetailDO.getAccountId());
  838. creditsDetailDO1.setStatus(1);
  839. creditsDetailDO1.setCreateTime(new Date());
  840. creditsDetailDO1.setUpdateTime(new Date());
  841. creditsDetailDO1.setTransactionId(taskPatientDetailDO.getTaskId());
  842. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  843. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  844. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO2.getIntegrate());
  845. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+creditsDetailDO2.getIntegrate());
  846. taskPatientDetailDao.save(taskPatientDetailDO);
  847. creditsDetailDO2.setTotal(accountDO.getTotal());
  848. creditsDetailDOS.add(creditsDetailDO2);
  849. }
  850. try{
  851. activeRecordService.insert("dev",creditsDetailDOS.get(0).getTransactionId(),null,null,null,creditsDetailDOS.get(0).getPatientId());
  852. }catch (Exception e){
  853. logger.error("插入活跃出错:"+e.getMessage());
  854. }
  855. Envelop<CreditsDetailDO> envelop = new Envelop<>();
  856. envelop.setDetailModelList(creditsDetailDOS);
  857. return envelop;
  858. }
  859. }catch (Exception e){
  860. e.printStackTrace();
  861. Envelop<CreditsDetailDO> envelop = new Envelop<>();
  862. return envelop;
  863. }
  864. }
  865. /* public JSONObject getStepNumber(){
  866. String step = redisTemplate.opsForValue().get(STEP);
  867. logger.info("redis数据:"+step);
  868. String sql = ""
  869. String step1 = systemDictDao.
  870. logger.info("数据库的数据:"+step1);
  871. if (step != null && step.equalsIgnoreCase(step1)){
  872. JSONObject jsonObject = JSONObject.parseObject(step);
  873. logger.info("数据不一致:"+jsonObject.toString());
  874. return jsonObject;
  875. }else {
  876. JSONObject jsonObject = JSONObject.parseObject(step);
  877. redisTemplate.opsForValue().set(STEP,step1);
  878. logger.info("数据一致:"+jsonObject.toString());
  879. return jsonObject;
  880. }
  881. }*/
  882. }