CreditsDetailService.java 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  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.jw.dao.*;
  7. import com.yihu.jw.entity.health.bank.*;
  8. import com.yihu.jw.restmodel.web.MixEnvelop;
  9. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  10. import com.yihu.jw.util.DateUtils;
  11. import com.yihu.jw.util.ISqlUtils;
  12. import com.yihu.jw.util.date.DateUtil;
  13. import com.yihu.mysql.query.BaseJpaService;
  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 org.springframework.util.StringUtils;
  22. import javax.print.DocFlavor;
  23. import javax.transaction.Transactional;
  24. import java.text.ParseException;
  25. import java.text.SimpleDateFormat;
  26. import java.util.*;
  27. /**
  28. * @author wangzhinan
  29. * @create 2018-04-27 16:53
  30. * @desc credits log info Service
  31. **/
  32. @Service
  33. @Transactional
  34. public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,CredittsLogDetailDao> {
  35. private Logger logger = LoggerFactory.getLogger(CreditsDetailService.class);
  36. private static String STEP = "health:blank:step";
  37. @Autowired
  38. private CredittsLogDetailDao credittsLogDetailDao;
  39. @Autowired
  40. private TaskDao taskDao;
  41. @Autowired
  42. private ActivityDao activityDao;
  43. @Autowired
  44. private JdbcTemplate jdbcTemplate;
  45. @Autowired
  46. private AccountDao accountDao;
  47. @Autowired
  48. private TaskPatientDetailDao taskPatientDetailDao;
  49. @Autowired
  50. private TaskRuleDao taskRuleDao;
  51. @Autowired
  52. private StringRedisTemplate redisTemplate;
  53. @Autowired
  54. private ActiveRecordService activeRecordService;
  55. @Autowired
  56. private ActivityRuleDao activityRuleDao;
  57. @Autowired
  58. private ExchangeGoodsDao exchangeGoodsDao;
  59. @Autowired
  60. private TaskGoodsDao taskGoodsDao;
  61. /**
  62. * find creditsLogInfo
  63. *
  64. * @return
  65. * @throws ParseException
  66. */
  67. public MixEnvelop<CreditsDetailDO, CreditsDetailDO> findByCondition(CreditsDetailDO creditsDetailDO, Integer page, Integer size) throws ParseException {
  68. String sql = new ISqlUtils().getSql(creditsDetailDO,page,size,"*");
  69. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  70. for (CreditsDetailDO creditsDetailDO1 : creditsDetailDOS){
  71. if (creditsDetailDO1.getTradeType() != null && creditsDetailDO1.getTradeType().equalsIgnoreCase("ACTIVITY_TASK")){
  72. TaskDO taskDO = taskDao.findOne(creditsDetailDO1.getTransactionId());
  73. creditsDetailDO1.setTaskDO(taskDO);
  74. }else if (creditsDetailDO1.getTradeType()!=null&&creditsDetailDO1.getTradeType().equals("EXCHANGE_GOODS")){
  75. ExchangeGoodsDO exchangeGoodsDO =exchangeGoodsDao.findOne(creditsDetailDO1.getTransactionId());
  76. TaskGoodsDO taskGoodsDO = taskGoodsDao.selectById(exchangeGoodsDO.getActivityGoodsId());
  77. exchangeGoodsDO.setTaskGoodsDO(taskGoodsDO);
  78. creditsDetailDO1.setExchangeGoodsDO(exchangeGoodsDO);
  79. }
  80. }
  81. String sqlcount = new ISqlUtils().getSql(creditsDetailDO,0,0,"count");
  82. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
  83. Long count = 0L;
  84. if(rstotal!=null&&rstotal.size()>0){
  85. count = (Long) rstotal.get(0).get("total");
  86. }
  87. return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, creditsDetailDOS,page,size,count);
  88. }
  89. /**
  90. * 获取账户信息
  91. *
  92. * @param creditsDetailDO
  93. * @return
  94. */
  95. public MixEnvelop<AccountDO, AccountDO> findByTradeDirection(CreditsDetailDO creditsDetailDO){
  96. AccountDO accountDO1 = new AccountDO();
  97. accountDO1.setPatientId(creditsDetailDO.getPatientId());
  98. String sql1 = ISqlUtils.getAllSql(accountDO1);
  99. List<AccountDO> accountDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(AccountDO.class));
  100. if (accountDOS == null || accountDOS.size() == 0){
  101. accountDO1.setTotal(0);
  102. accountDO1.setAccountName(creditsDetailDO.getName());
  103. if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
  104. String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
  105. int random = (int)((Math.random()*9+1)*100000);
  106. accountDO1.setCardNumber(cardNumber+Integer.toString(random));
  107. }
  108. accountDO1.setHospital(creditsDetailDO.getHospital());
  109. accountDO1.setPassword("123456");
  110. accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
  111. accountDO1.setStatus(1);
  112. accountDO1.setSaasId("dev");
  113. accountDO1.setCreateTime(new Date());
  114. accountDO1.setUpdateTime(new Date());
  115. accountDao.save(accountDO1);
  116. }
  117. List<AccountDO> accountDOS1 = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(AccountDO.class));
  118. AccountDO accountDO = accountDOS1.get(0);
  119. 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()+"'";
  120. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
  121. if (rstotal!= null && rstotal.size()>0){
  122. if (rstotal.get(0).get("total") == null){
  123. accountDO.setUsedTotal(0);
  124. }else {
  125. accountDO.setUsedTotal(Integer.parseInt(rstotal.get(0).get("total").toString()));
  126. }
  127. }
  128. return MixEnvelop.getSuccess(HealthBankMapping.api_success,accountDO);
  129. }
  130. /*
  131. public Envelop<Boolean> exchangeGoods(GoodsDO goodsDO){
  132. CreditsDetailDO creditsLogDetailDO = new CreditsDetailDO();
  133. Envelop<Boolean> envelop = new Envelop<>();
  134. envelop.setObj(true);
  135. return envelop;
  136. }
  137. */
  138. public MixEnvelop<AccountDO, AccountDO> selectByRanking(List<String> patientIds, Integer page, Integer size){
  139. StringBuffer buffer = new StringBuffer();
  140. buffer.append(" ba.patient_id in(");
  141. if (patientIds == null || patientIds.size() == 0){
  142. buffer.append("''");
  143. }else {
  144. for (int i=0;i<patientIds.size();i++){
  145. buffer.append("'"+patientIds.get(i)+"'").append(",");
  146. }
  147. buffer.deleteCharAt(buffer.length()-1);
  148. }
  149. buffer.append(") ");
  150. String sql =
  151. "SELECT ba1.patient_id AS patient_id," +
  152. "ba1.account_name AS account_name," +
  153. "ba1.hospital AS hospital," +
  154. "ba1.total AS total," +
  155. "ba1.create_time AS create_time," +
  156. "ba1.sum AS sum" +
  157. " FROM" +
  158. "( SELECT " +
  159. "ba.patient_id AS patient_id," +
  160. "ba.account_name AS account_name," +
  161. "ba.hospital AS hospital," +
  162. "ba.total AS total," +
  163. "ba.create_time AS create_time," +
  164. " if(ba.total=0,ba.total,(ba.total +COALESCE((cd1.total),0))) AS sum" +
  165. " FROM" +
  166. " wlyy_health_bank_account ba" +
  167. " LEFT JOIN ( " +
  168. "SELECT" +
  169. " SUM(cd.integrate) AS total," +
  170. " cd.patient_id AS patient_id" +
  171. " FROM" +
  172. " wlyy_health_bank_credits_detail cd" +
  173. " WHERE " +
  174. "cd.trade_direction = - 1" +
  175. " GROUP BY " +
  176. " cd.patient_id ) cd1 ON cd1.patient_id = ba.patient_id " +
  177. " WHERE " + buffer +
  178. " ORDER BY" +
  179. " ba.create_time DESC )ba1" +
  180. " ORDER BY " +
  181. " ba1.total DESC"+
  182. " LIMIT "+(page-1)*size+","+size ;
  183. List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
  184. String sqlCount = "SELECT count(1) AS total"+
  185. " FROM " +
  186. " wlyy_health_bank_account ba LEFT JOIN " +
  187. " ( " +
  188. " SELECT " +
  189. " SUM(cd.integrate) AS total, " +
  190. " cd.patient_id AS patient_id " +
  191. " FROM " +
  192. " wlyy_health_bank_credits_detail cd " +
  193. " WHERE " +
  194. " cd.trade_direction = - 1 " +
  195. " GROUP BY " +
  196. " cd.patient_id " +
  197. " ) cd1 ON cd1.patient_id = ba.patient_id " +
  198. "WHERE " + buffer +
  199. " ORDER BY " +
  200. " ba.create_time, " +
  201. " (ba.total + COALESCE(cd1.total,0)) DESC ";
  202. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount);
  203. Long count = 0L;
  204. if(rstotal!=null&&rstotal.size()>0){
  205. count = (Long) rstotal.get(0).get("total");
  206. }
  207. return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, accountDOS,page,size,count);
  208. }
  209. /**
  210. * 添加积分
  211. *
  212. * @param creditsDetailDO
  213. * @return
  214. */
  215. public MixEnvelop<CreditsDetailDO, CreditsDetailDO> insert(CreditsDetailDO creditsDetailDO){
  216. try {
  217. synchronized (creditsDetailDO.getPatientId()){
  218. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '"+creditsDetailDO.getPatientId() +"'";
  219. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  220. if (accountDOList != null && accountDOList.size() != 0){
  221. creditsDetailDO.setAccountId(accountDOList.get(0).getId());
  222. }else {
  223. AccountDO accountDO1 = new AccountDO();
  224. accountDO1.setPatientId(creditsDetailDO.getPatientId());
  225. accountDO1.setTotal(0);
  226. accountDO1.setCouponTotal(0L);
  227. accountDO1.setAccountName(creditsDetailDO.getName());
  228. if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
  229. String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
  230. int random = (int)((Math.random()*9+1)*100000);
  231. accountDO1.setCardNumber(cardNumber+Integer.toString(random));
  232. }
  233. accountDO1.setHospital(creditsDetailDO.getHospital());
  234. accountDO1.setPassword("123456");
  235. accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
  236. accountDO1.setStatus(1);
  237. accountDO1.setCreateTime(new Date());
  238. accountDO1.setUpdateTime(new Date());
  239. accountDao.save(accountDO1);
  240. List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  241. creditsDetailDO.setAccountId(accountDOS.get(0).getId());
  242. }
  243. TaskDO taskDO = new TaskDO();
  244. taskDO.setTaskCode(creditsDetailDO.getFlag());
  245. taskDO.setId(creditsDetailDO.getTransactionId());
  246. /*taskDO.setPatientId(creditsDetailDO.getPatientId());*/
  247. String sql = ISqlUtils.getSql(taskDO,1,1,"*");
  248. List<TaskDO> taskDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskDO.class));
  249. creditsDetailDO.setTransactionId(taskDOList.get(0).getId());
  250. String ruleSql = "SELECT * FROM wlyy_health_bank_task_rule WHERE id= '"+taskDOList.get(0).getRuleCode()+"'";
  251. List<TaskRuleDO> taskRuleDOS = jdbcTemplate.query(ruleSql,new BeanPropertyRowMapper(TaskRuleDO.class));
  252. TaskRuleDO taskRuleDO = taskRuleDOS.get(0);
  253. creditsDetailDO.setIntegrate(taskRuleDO.getIntegrate());
  254. creditsDetailDO.setTradeDirection(taskRuleDO.getTradeDirection());
  255. String taskSql = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDOList.get(0).getId()+"' and patient_id = '" + creditsDetailDO.getPatientId() +"'";
  256. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  257. if (taskPatientDetailDOS == null || taskPatientDetailDOS.size() ==0){
  258. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  259. taskPatientDetailDO.setTaskId(creditsDetailDO.getTransactionId());
  260. taskPatientDetailDO.setSaasId(creditsDetailDO.getSaasId());
  261. taskPatientDetailDO.setPatientId(creditsDetailDO.getPatientId());
  262. taskPatientDetailDO.setPatientIdcard(creditsDetailDO.getIdCard());
  263. taskPatientDetailDO.setPatientOpenid(creditsDetailDO.getOpenId());
  264. taskPatientDetailDO.setUnionId(creditsDetailDO.getUnionId());
  265. taskPatientDetailDO.setStatus(Integer.parseInt("0"));
  266. taskPatientDetailDO.setCreateTime(new Date());
  267. taskPatientDetailDO.setUpdateTime(new Date());
  268. taskPatientDetailDO.setActivityId(taskDOList.get(0).getTransactionId());
  269. taskPatientDetailDO.setTotal(Long.parseLong("0"));
  270. taskPatientDetailDao.save(taskPatientDetailDO);
  271. }else if (taskPatientDetailDOS != null && taskDOList.get(0).getPeriod() == 0){
  272. String taskSql1 = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDOList.get(0).getId()+
  273. "' and patient_id = '"+creditsDetailDO.getPatientId()+"' and create_time > '" + DateUtils.getDayBegin() +"' and create_time < '"+ DateUtils.getDayEnd() +"'";
  274. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  275. if (taskPatientDetailDOS1 == null || taskPatientDetailDOS1.size() == 0){
  276. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  277. taskPatientDetailDO.setTaskId(creditsDetailDO.getTransactionId());
  278. taskPatientDetailDO.setSaasId(creditsDetailDO.getSaasId());
  279. taskPatientDetailDO.setPatientId(creditsDetailDO.getPatientId());
  280. taskPatientDetailDO.setPatientIdcard(creditsDetailDO.getIdCard());
  281. taskPatientDetailDO.setPatientOpenid(creditsDetailDO.getOpenId());
  282. taskPatientDetailDO.setActivityId(taskDOList.get(0).getTransactionId());
  283. taskPatientDetailDO.setStatus(Integer.parseInt("0"));
  284. taskPatientDetailDO.setCreateTime(new Date());
  285. taskPatientDetailDO.setUpdateTime(new Date());
  286. taskPatientDetailDO.setTotal(Long.parseLong("0"));
  287. taskPatientDetailDao.save(taskPatientDetailDO);
  288. }
  289. }
  290. if (creditsDetailDO.getUploadTime()!=null&&creditsDetailDO.getUploadTime()!=""){
  291. creditsDetailDO.setCreateTime(DateUtil.strToDateLong(creditsDetailDO.getUploadTime()));
  292. }else {
  293. creditsDetailDO.setCreateTime(new Date());
  294. }
  295. creditsDetailDO.setUpdateTime(new Date());
  296. CreditsDetailDO creditsDetailDO1 =credittsLogDetailDao.save(creditsDetailDO);
  297. creditsDetailDO1.setFlag(creditsDetailDO.getFlag());
  298. List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
  299. creditsDetailDOList.add(creditsDetailDO1);
  300. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  301. taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  302. taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
  303. String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
  304. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  305. TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
  306. if (creditsDetailDO1.getTradeDirection() == 1){
  307. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal()+creditsDetailDO1.getIntegrate());
  308. }else if (creditsDetailDO.getTradeDirection() == -1){
  309. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal()-creditsDetailDO1.getIntegrate());
  310. }
  311. taskPatientDetailDao.save(taskPatientDetailDO1);
  312. AccountDO accountDO = accountDao.findOne(creditsDetailDO1.getAccountId());
  313. if (creditsDetailDO1.getTradeDirection() == 1){
  314. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO1.getIntegrate());
  315. }else if (creditsDetailDO.getTradeDirection() == -1){
  316. accountDO.setTotal(accountDO.getTotal()-creditsDetailDO1.getIntegrate());
  317. }
  318. AccountDO accountDO1 = accountDao.save(accountDO);
  319. List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
  320. for (CreditsDetailDO creditsDetailDO2:creditsDetailDOList){
  321. creditsDetailDO2.setTotal(accountDO1.getTotal());
  322. creditsDetailDOS.add(creditsDetailDO2);
  323. }
  324. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  325. envelop.setDetailModelList(creditsDetailDOS);
  326. return envelop;
  327. }
  328. }catch (Exception e){
  329. e.printStackTrace();
  330. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  331. return envelop;
  332. }
  333. }
  334. /**
  335. * 活动排名
  336. *
  337. * @param activityId 活动id
  338. * @param ids 微信编码
  339. *
  340. * @param page 页码
  341. *
  342. * @param size 分页大小
  343. * @return
  344. */
  345. public MixEnvelop<TaskPatientDetailDO, TaskPatientDetailDO> selectByActivityRanking(String activityId, List<String> ids, Integer page, Integer size){
  346. StringBuffer buffer = new StringBuffer();
  347. buffer.append("(");
  348. if (ids == null || ids.size() == 0){
  349. buffer.append("''");
  350. }else {
  351. for (int i=0;i<ids.size();i++){
  352. buffer.append("'"+ids.get(i)+"'").append(",");
  353. }
  354. buffer.deleteCharAt(buffer.length()-1);
  355. }
  356. buffer.append(") ");
  357. String sql = "SELECT " +
  358. " * " +
  359. "FROM " +
  360. " ( " +
  361. " SELECT " +
  362. " SUM(ptpd.total) AS total, " +
  363. " ptpd.patient_openid AS patient_openid, " +
  364. " ptpd.task_id AS task_id, " +
  365. " ptpd.activity_id AS activity_id, " +
  366. " ptpd.create_time as create_time, " +
  367. " ptpd.patient_id AS patient_id " +
  368. " FROM " +
  369. " wlyy_health_bank_task_patient_detail ptpd " +
  370. " WHERE " +
  371. " activity_id = '" + activityId +
  372. "' GROUP BY " +
  373. " patient_id " +
  374. " ORDER BY ptpd.create_time DESC " +
  375. " )btpd1 " +
  376. " WHERE patient_id IN "+buffer+
  377. " ORDER BY btpd1.total DESC "+" LIMIT " + (page-1)*size+","+size;
  378. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  379. for (TaskPatientDetailDO taskPatientDetailDO : taskPatientDetailDOS){
  380. String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
  381. List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
  382. taskPatientDetailDO.setAccountDO(accountDOS.get(0));
  383. }
  384. String sqlCount = "SELECT " +
  385. " count(1) AS total " +
  386. "FROM " +
  387. " ( " +
  388. " SELECT " +
  389. " SUM(ptpd.total) AS total, " +
  390. " ptpd.patient_openid AS patient_openid, " +
  391. " ptpd.task_id AS task_id, " +
  392. " ptpd.activity_id AS activity_id, " +
  393. " ptpd.create_time as create_time, " +
  394. " ptpd.patient_id AS patient_id " +
  395. " FROM " +
  396. " wlyy_health_bank_task_patient_detail ptpd " +
  397. " WHERE " +
  398. " activity_id = '" + activityId+
  399. "' GROUP BY " +
  400. " patient_openid " +
  401. " ORDER BY ptpd.create_time DESC " +
  402. " )btpd1 " +
  403. "WHERE patient_openid IN "+buffer+
  404. " ORDER BY btpd1.total DESC ";
  405. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount);
  406. Long count = 0L;
  407. if(rstotal!=null&&rstotal.size()>0){
  408. count = (Long) rstotal.get(0).get("total");
  409. }
  410. return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, taskPatientDetailDOS,page,size,count);
  411. }
  412. /**
  413. * 根据活动查询积分
  414. *
  415. * @param activityId 活动id
  416. *
  417. * @param patientId 居民id
  418. *
  419. * @param page 页码
  420. *
  421. * @param size 分页大小
  422. * @return
  423. */
  424. public MixEnvelop<CreditsDetailDO, CreditsDetailDO> selectByActivity(String activityId, String patientId, Integer page, Integer size){
  425. String sql="SELECT * " +
  426. "FROM " +
  427. " wlyy_health_bank_credits_detail " +
  428. "WHERE" +
  429. " transaction_id IN ( " +
  430. " SELECT " +
  431. " bt.id " +
  432. " FROM " +
  433. " wlyy_health_bank_task bt " +
  434. " WHERE " +
  435. " transaction_id = '"+activityId +"' " +
  436. " ) " +
  437. " and patient_id = '" +patientId+
  438. "' LIMIT "+(page-1)*size +","+size;
  439. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  440. for (CreditsDetailDO creditsDetailDO : creditsDetailDOS){
  441. TaskDO taskDO = taskDao.findOne(creditsDetailDO.getTransactionId());
  442. creditsDetailDO.setTaskDO(taskDO);
  443. }
  444. String sqlcount = "SELECT count(1) AS" +
  445. " total FROM " +
  446. " wlyy_health_bank_credits_detail " +
  447. "WHERE" +
  448. " transaction_id IN ( " +
  449. " SELECT " +
  450. " bt.id " +
  451. " FROM " +
  452. " wlyy_health_bank_task bt " +
  453. " WHERE " +
  454. " transaction_id = '"+activityId +"' " +
  455. " ) " +
  456. " and patient_id = '" +patientId+
  457. "'";
  458. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
  459. Long count = 0L;
  460. if(rstotal!=null&&rstotal.size()>0){
  461. count = (Long) rstotal.get(0).get("total");
  462. }
  463. return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success,creditsDetailDOS,page,size,count);
  464. }
  465. /**
  466. * 根据活动查找全部排行
  467. *
  468. * @param activityId 活动id
  469. * @param page 页码
  470. * @param size 分页大小
  471. * @return
  472. */
  473. public MixEnvelop<TaskPatientDetailDO, TaskPatientDetailDO> selectByActivityRanking1(String activityId, String patientId, Integer page, Integer size){
  474. String sql = "SELECT " +
  475. " * " +
  476. "FROM " +
  477. " ( " +
  478. " SELECT " +
  479. " SUM(ptpd.total) AS total, " +
  480. " ptpd.patient_openid AS patient_openid, " +
  481. " ptpd.task_id AS task_id, " +
  482. " ptpd.activity_id AS activity_id, " +
  483. " ptpd.create_time as create_time, " +
  484. " ptpd.patient_id AS patient_id " +
  485. " FROM " +
  486. " wlyy_health_bank_task_patient_detail ptpd " +
  487. " WHERE " +
  488. " activity_id = '" + activityId +
  489. "' GROUP BY " +
  490. " patient_openid " +
  491. " ORDER BY ptpd.create_time DESC " +
  492. " )btpd1 " +
  493. " ORDER BY btpd1.total DESC "+" LIMIT " + (page-1)*size+","+size;
  494. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  495. logger.info(taskPatientDetailDOS.toString()+""+taskPatientDetailDOS.size());
  496. for (int i = 0;taskPatientDetailDOS != null&&taskPatientDetailDOS.size()!=0 && i<taskPatientDetailDOS.size();i++){
  497. TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDOS.get(i);
  498. String accountSql = "select * from wlyy_health_bank_account where patient_id = '"+taskPatientDetailDO.getPatientId()+"'";
  499. List<AccountDO> accountDOS = jdbcTemplate.query(accountSql,new BeanPropertyRowMapper(AccountDO.class));
  500. if (taskPatientDetailDOS.get(i).getPatientId().equalsIgnoreCase(patientId)){
  501. /*String taskSql = "select count(1)+1 as total from (" +
  502. "select * from (SELECT " +
  503. " SUM(ptpd.total) AS total, " +
  504. " ptpd.patient_openid AS patient_openid, " +
  505. " ptpd.task_id AS task_id, " +
  506. " ptpd.activity_id AS activity_id, " +
  507. " ptpd.create_time as create_time, " +
  508. " ptpd.patient_id AS patient_id " +
  509. " FROM " +
  510. " wlyy_health_bank_task_patient_detail ptpd " +
  511. " WHERE " +
  512. " activity_id = '" + activityId + "')ptpd1 where" +
  513. " ptpd1.patient_id = '"+patientId+"' AND ptpd1.total > "+taskPatientDetailDOS.get(i).getTotal()+") ptpd2";
  514. List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(taskSql);
  515. Long count = 0L;
  516. if(rstotal1!=null&&rstotal1.size()>0){
  517. count = (Long) rstotal1.get(0).get("total");
  518. }
  519. accountDOS.get(0).setActivityRanking(count);*/
  520. taskPatientDetailDO.setIsFlag(1);
  521. }else {
  522. taskPatientDetailDO.setIsFlag(0);
  523. }
  524. taskPatientDetailDO.setAccountDO(accountDOS.get(0));
  525. }
  526. String sqlCount = "SELECT " +
  527. " count(1) AS total " +
  528. "FROM " +
  529. " ( " +
  530. " SELECT " +
  531. " SUM(ptpd.total) AS total, " +
  532. " ptpd.patient_openid AS patient_openid, " +
  533. " ptpd.task_id AS task_id, " +
  534. " ptpd.activity_id AS activity_id, " +
  535. " ptpd.create_time as create_time, " +
  536. " ptpd.patient_id AS patient_id " +
  537. " FROM " +
  538. " wlyy_health_bank_task_patient_detail ptpd " +
  539. " WHERE " +
  540. " activity_id = '" + activityId+
  541. "' GROUP BY " +
  542. " patient_openid " +
  543. " ORDER BY ptpd.create_time DESC " +
  544. " )btpd1 " +
  545. " ORDER BY btpd1.total DESC ";
  546. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount);
  547. Long count = 0L;
  548. if(rstotal!=null&&rstotal.size()>0){
  549. count = (Long) rstotal.get(0).get("total");
  550. }
  551. return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success, taskPatientDetailDOS,page,size,count);
  552. }
  553. /**
  554. * 医生主动加分
  555. *
  556. * @param array 居民信息集合
  557. *
  558. * @param ruleId 规则id
  559. * @return
  560. */
  561. public MixEnvelop<Boolean, Boolean> doctorAddIntegrate(JSONArray array, String ruleId, String description) throws Exception {
  562. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  563. for (int i=0;i<array.size();i++){
  564. TaskRuleDO taskRuleDO = taskRuleDao.findOne(ruleId);
  565. JSONObject object = array.getJSONObject(i);
  566. String patientId = object.getString("code");
  567. String idCard = object.getString("idcard");
  568. String unionId = object.getString("unionid");
  569. String openId = object.getString("openid");
  570. String hospital = object.getString("hospital");
  571. String hospitalName = object.getString("hospitalName");
  572. String taskSql = "select * from wlyy_health_bank_task bt where type = 'RULE_TASK' AND transaction_id = '"+ruleId +"'";
  573. List<TaskDO> taskDOList = jdbcTemplate.query(taskSql,new BeanPropertyRowMapper(TaskDO.class));
  574. TaskDO taskDO1 = new TaskDO();
  575. if (taskDOList.isEmpty() && taskDOList.size() == 0){
  576. TaskDO taskDO = new TaskDO();
  577. taskDO.setTransactionId(taskRuleDO.getId());
  578. taskDO.setTaskCode("RULE");
  579. taskDO.setStatus(1);
  580. taskDO.setRuleCode(taskRuleDO.getId());
  581. taskDO.setType("RULE_TASK");
  582. taskDO.setCreateTime(new Date());
  583. taskDO.setUpdateTime(new Date());
  584. taskDO.setPeriod(taskRuleDO.getPeriod());
  585. taskDO.setSaasId("dev");
  586. taskDO.setTitle(taskRuleDO.getDescription());
  587. taskDO.setContent(taskRuleDO.getDescription());
  588. taskDO1 = taskDao.save(taskDO);
  589. }else {
  590. taskDO1 = taskDOList.get(0);
  591. }
  592. if (taskRuleDO.getPeriod() == 1){
  593. String sql = "select * from wlyy_health_bank_task_patient_detail where patient_id = '"+patientId+"'AND task_id ='"+taskDO1.getId()+"'";
  594. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  595. if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
  596. throw new Exception("已奖励过");
  597. }
  598. }else if (taskRuleDO.getPeriod() == 0){
  599. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  600. Date date = new Date();
  601. String date1 = dateFormat.format(date);
  602. String begin = DateUtils.getMinMonthDate(date1);
  603. String end = DateUtils.getMaxMonthDate(date1);
  604. 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+"'";
  605. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  606. if (taskPatientDetailDOS != null && taskPatientDetailDOS.size() != 0){
  607. throw new Exception("已奖励过");
  608. }
  609. }
  610. String sql1 = "select * from wlyy_health_bank_task_patient_detail where task_id = '"+taskDO1.getId()+"' " +
  611. "AND patient_idcard = '"+idCard+"' AND patient_openid = '"+openId+"' AND union_id = '"+unionId+"'";
  612. List<TaskPatientDetailDO> taskPatientDetailDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  613. TaskPatientDetailDO taskPatientDetailDO1 = new TaskPatientDetailDO();
  614. if (taskPatientDetailDOS.isEmpty() && taskPatientDetailDOS.size() == 0){
  615. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  616. taskPatientDetailDO.setStatus(1);
  617. taskPatientDetailDO.setTotal(Long.parseLong("0"));
  618. taskPatientDetailDO.setPatientId(patientId);
  619. taskPatientDetailDO.setPatientOpenid(openId);
  620. taskPatientDetailDO.setPatientIdcard(idCard);
  621. taskPatientDetailDO.setUnionId(unionId);
  622. taskPatientDetailDO.setSaasId("dev");
  623. taskPatientDetailDO.setCreateTime(new Date());
  624. taskPatientDetailDO.setUpdateTime(new Date());
  625. taskPatientDetailDO.setTaskId(taskDO1.getId());
  626. taskPatientDetailDO1 = taskPatientDetailDao.save(taskPatientDetailDO);
  627. }else {
  628. taskPatientDetailDO1 = taskPatientDetailDOS.get(0);
  629. }
  630. String sql = "select * from wlyy_health_bank_account where patient_id = '"+patientId+"'";
  631. List<AccountDO> accountDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
  632. if (taskRuleDO.getTradeDirection() == -1 && taskRuleDO.getIntegrate() == 0){
  633. String integrateSql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+patientId+"' " +
  634. "AND transaction_id IN (SELECT id FROM wlyy_health_bank_task WHERE task_code IN ('BP_BIND','GLU_BIND','BP_MEASURE','GLU_MEASURE','RULE'))";
  635. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(integrateSql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  636. AccountDO accountDO = accountDOS.get(0);
  637. for (CreditsDetailDO creditsDetailDO:creditsDetailDOS){
  638. if (creditsDetailDO.getTradeDirection()==1&&creditsDetailDO.getStatus()!=0){
  639. /* int total = accountDO.getTotal() - creditsDetailDO.getIntegrate();*/
  640. creditsDetailDO.setStatus(0);
  641. creditsDetailDO.setDescription(description);
  642. credittsLogDetailDao.save(creditsDetailDO);
  643. }
  644. }
  645. accountDO.setTotal(0);
  646. accountDao.save(accountDO);
  647. CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
  648. creditsDetailDO1.setStatus(1);
  649. creditsDetailDO1.setSaasId("dev");
  650. creditsDetailDO1.setAccountId(accountDOS.get(0).getId());
  651. creditsDetailDO1.setHospital(hospital);
  652. creditsDetailDO1.setHospitalName(hospitalName);
  653. creditsDetailDO1.setPatientId(patientId);
  654. creditsDetailDO1.setIntegrate(taskRuleDO.getIntegrate());
  655. creditsDetailDO1.setTradeDirection(taskRuleDO.getTradeDirection());
  656. creditsDetailDO1.setDescription(description);
  657. creditsDetailDO1.setCreateTime(new Date());
  658. creditsDetailDO1.setUpdateTime(new Date());
  659. creditsDetailDO1.setTransactionId(taskDO1.getId());
  660. creditsDetailDO1.setTradeType("ACTIVITY_TASK");
  661. credittsLogDetailDao.save(creditsDetailDO1);
  662. }else{
  663. CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
  664. creditsDetailDO.setStatus(1);
  665. creditsDetailDO.setSaasId("dev");
  666. creditsDetailDO.setAccountId(accountDOS.get(0).getId());
  667. creditsDetailDO.setHospital(hospital);
  668. creditsDetailDO.setHospitalName(hospitalName);
  669. creditsDetailDO.setPatientId(patientId);
  670. creditsDetailDO.setIntegrate(taskRuleDO.getIntegrate());
  671. creditsDetailDO.setTradeDirection(taskRuleDO.getTradeDirection());
  672. creditsDetailDO.setDescription(description);
  673. creditsDetailDO.setCreateTime(new Date());
  674. creditsDetailDO.setUpdateTime(new Date());
  675. creditsDetailDO.setTransactionId(taskDO1.getId());
  676. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  677. creditsDetailDO = credittsLogDetailDao.save(creditsDetailDO);
  678. if (taskRuleDO.getTradeDirection() == -1){
  679. if (taskRuleDO.getIntegrate() == 0){
  680. String integrateSql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+patientId+"' " +
  681. "AND transaction_id IN (SELECT id FROM wlyy_health_bank_task WHERE task_code IN ('BP_BIND','GLU_BIND','BP_MEASURE','GLU_MEASURE','RULE'))";
  682. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(integrateSql,new BeanPropertyRowMapper(CreditsDetailDO.class));
  683. AccountDO accountDO = accountDOS.get(0);
  684. for (CreditsDetailDO creditsDetailDO1:creditsDetailDOS){
  685. if (creditsDetailDO1.getTradeDirection()==1&&creditsDetailDO1.getStatus()!=0){
  686. int total = accountDO.getTotal() - creditsDetailDO1.getIntegrate();
  687. creditsDetailDO1.setStatus(0);
  688. creditsDetailDO1.setDescription(description);
  689. credittsLogDetailDao.save(creditsDetailDO1);
  690. }
  691. }
  692. accountDO.setTotal(0);
  693. accountDao.save(accountDO);
  694. }else if (taskRuleDO.getIntegrate()!=0){
  695. AccountDO accountDO = accountDOS.get(0);
  696. int total = accountDO.getTotal() - creditsDetailDO.getIntegrate();
  697. accountDO.setTotal(total);
  698. accountDao.save(accountDO);
  699. }
  700. }else if (taskRuleDO.getTradeDirection() == 1){
  701. AccountDO accountDO = accountDOS.get(0);
  702. accountDO.setTotal(accountDO.getTotal() + taskRuleDO.getIntegrate());
  703. accountDao.save(accountDO);
  704. }
  705. }
  706. }
  707. envelop.setObj(true);
  708. return envelop;
  709. }
  710. /**
  711. * 固定数据
  712. *
  713. * @param
  714. * @return
  715. *//*
  716. public List<TaskDO> getTasks(String patientId){
  717. List<TaskDO> taskDOList = new ArrayList<>();
  718. TaskDO taskDO = new TaskDO();
  719. *//*taskDO.setPatientId(patientId);*//*
  720. taskDO.setTaskCode("BIND");
  721. taskDO.setPeriod(1);
  722. taskDO.setTaskTitle("首次绑定");
  723. taskDO.setTaskContent("(绑定社区登记发放的设备,可获得各类型设备的首绑奖励。)");
  724. taskDO.setTradeType("activity");
  725. taskDO.setTransactionId("402885e96324a409016324c0a45a0006");
  726. taskDO.setCreateTime(new Date());
  727. taskDO.setUpdateTime(new Date());
  728. taskDOList.add(taskDO);
  729. TaskDO taskDO1 = new TaskDO();
  730. *//*taskDO1.setPatientId(patientId);*//*
  731. taskDO1.setTaskCode("MEASURE");
  732. taskDO1.setPeriod(0);
  733. taskDO1.setTaskTitle("每日测量");
  734. taskDO1.setTaskContent("(使用社区发放的已关联您身份信息的设备,绑定后每天完成测量)");
  735. taskDO1.setTradeType("activity");
  736. taskDO1.setTransactionId("402885e96324a409016324c0a45a0006");
  737. taskDO1.setCreateTime(new Date());
  738. taskDO1.setUpdateTime(new Date());
  739. taskDOList.add(taskDO1);
  740. return taskDOList;
  741. }
  742. */
  743. public MixEnvelop<CreditsDetailDO, CreditsDetailDO> stepAddIntegrate(CreditsDetailDO creditsDetailDO){
  744. try {
  745. synchronized (creditsDetailDO.getPatientId()){
  746. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '"+creditsDetailDO.getPatientId() +"'";
  747. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  748. if (accountDOList != null && accountDOList.size() != 0){
  749. creditsDetailDO.setAccountId(accountDOList.get(0).getId());
  750. }else {
  751. AccountDO accountDO1 = new AccountDO();
  752. accountDO1.setPatientId(creditsDetailDO.getPatientId());
  753. accountDO1.setSaasId("dev");
  754. accountDO1.setTotal(0);
  755. accountDO1.setCouponTotal(0L);
  756. accountDO1.setAccountName(creditsDetailDO.getName());
  757. if(creditsDetailDO.getIdCard().length()>=4){// 判断是否长度大于等于4
  758. String cardNumber=creditsDetailDO.getIdCard().substring(creditsDetailDO.getIdCard().length()- 4,creditsDetailDO.getIdCard().length());//截取两个数字之间的部分
  759. int random = (int)((Math.random()*9+1)*100000);
  760. accountDO1.setCardNumber(cardNumber+Integer.toString(random));
  761. }
  762. accountDO1.setHospital(creditsDetailDO.getHospital());
  763. accountDO1.setPassword("123456");
  764. accountDO1.setHospitalName(creditsDetailDO.getHospitalName());
  765. accountDO1.setStatus(1);
  766. accountDO1.setCreateTime(new Date());
  767. accountDO1.setUpdateTime(new Date());
  768. accountDao.save(accountDO1);
  769. List<AccountDO> accountDOS = jdbcTemplate.query(sqlAccount,new BeanPropertyRowMapper(AccountDO.class));
  770. creditsDetailDO.setAccountId(accountDOS.get(0).getId());
  771. }
  772. String sql1 = "select * from wlyy_health_bank_task_patient_detail where "+
  773. " patient_idcard = '"+creditsDetailDO.getIdCard()+"' AND union_id = '"+creditsDetailDO.getUnionId()+"' AND task_id = '"+creditsDetailDO.getTransactionId()+"'";
  774. List<TaskPatientDetailDO> taskPatientDetailDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  775. if(taskPatientDetailDOList == null || taskPatientDetailDOList.size()==0){
  776. throw new Exception("该居民参与活动查不到!");
  777. }
  778. TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDOList.get(0);
  779. String sql = "select * from wlyy_health_bank_credits_detail where patient_id = '"+creditsDetailDO.getPatientId()+"' AND " +
  780. "transaction_id = '"+creditsDetailDO.getTransactionId()+"' AND create_time > '"+DateUtils.getDayBegin() +"' AND" +
  781. " create_time < '"+DateUtils.getDayEnd()+"'AND ISNULL(description)";
  782. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
  783. ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(taskPatientDetailDO.getActivityId());
  784. if (activityRuleDO.getValue1() != null){
  785. JSONObject object = JSONObject.parseObject(activityRuleDO.getValue1());
  786. //获取步数
  787. JSONArray array = object.getJSONArray("healthStep");
  788. int j = array.size();
  789. int z= 0;
  790. for (int i = 0;i<=array.size();i++){
  791. JSONObject jsonObject = array.getJSONObject(i);
  792. Long step = jsonObject.getLong("step");
  793. int integrate = jsonObject.getInteger("integrate");
  794. if (creditsDetailDOS != null && creditsDetailDOS.size() != 0){
  795. CreditsDetailDO creditsDetailDO1 = creditsDetailDOS.get(0);
  796. if (creditsDetailDO.getStepNumber()>0 && creditsDetailDO.getStepNumber()<=step){
  797. int integrate1=creditsDetailDO1.getIntegrate();
  798. creditsDetailDO1.setIntegrate(creditsDetailDO.getIntegrate());
  799. creditsDetailDO1.setTradeDirection(1);
  800. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  801. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  802. accountDO.setTotal(accountDO.getTotal()-integrate1+creditsDetailDO2.getIntegrate());
  803. AccountDO accountDO1 = accountDao.save(accountDO);
  804. creditsDetailDO2.setTotal(accountDO1.getTotal());
  805. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()-integrate1+creditsDetailDO2.getIntegrate());
  806. taskPatientDetailDao.save(taskPatientDetailDO);
  807. creditsDetailDOS.clear();
  808. creditsDetailDOS.add(creditsDetailDO2);
  809. break;
  810. }
  811. }else {
  812. CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
  813. if (creditsDetailDO.getStepNumber()>0 && creditsDetailDO.getStepNumber()<=step){
  814. creditsDetailDO1.setIntegrate(creditsDetailDO.getIntegrate());
  815. creditsDetailDO1.setTradeDirection(1);
  816. creditsDetailDO1.setSaasId("dev");
  817. creditsDetailDO1.setTradeType("ACTIVITY_TASK");
  818. creditsDetailDO1.setPatientId(creditsDetailDO.getPatientId());
  819. creditsDetailDO1.setHospital(creditsDetailDO.getHospital());
  820. creditsDetailDO1.setHospitalName(creditsDetailDO.getHospitalName());
  821. creditsDetailDO1.setAccountId(creditsDetailDO.getAccountId());
  822. creditsDetailDO1.setStatus(1);
  823. creditsDetailDO1.setCreateTime(new Date());
  824. creditsDetailDO1.setUpdateTime(new Date());
  825. creditsDetailDO1.setTransactionId(taskPatientDetailDO.getTaskId());
  826. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  827. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  828. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO2.getIntegrate());
  829. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+creditsDetailDO2.getIntegrate());
  830. taskPatientDetailDao.save(taskPatientDetailDO);
  831. creditsDetailDO2.setTotal(accountDO.getTotal());
  832. creditsDetailDOS.add(creditsDetailDO2);
  833. break;
  834. }
  835. }
  836. }
  837. }
  838. /* for (int i = 0;i<array.size();i++){
  839. JSONObject jsonObject = array.getJSONObject(i);
  840. if (creditsDetailDOS != null && creditsDetailDOS.size() != 0){
  841. CreditsDetailDO creditsDetailDO1 = creditsDetailDOS.get(0);
  842. TaskRuleDO taskRuleDO = taskRuleDao.findOne(taskDO.getRuleCode());
  843. if (creditsDetailDO.getStepNumber() < step1 && creditsDetailDO.getStepNumber() >0){
  844. creditsDetailDO1.setIntegrate(0);
  845. creditsDetailDO1.setTradeDirection(1);
  846. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  847. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  848. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO2.getIntegrate());
  849. AccountDO accountDO1 = accountDao.save(accountDO);
  850. creditsDetailDO2.setTotal(accountDO1.getTotal());
  851. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+creditsDetailDO2.getIntegrate());
  852. taskPatientDetailDao.save(taskPatientDetailDO);
  853. creditsDetailDOS.clear();
  854. creditsDetailDOS.add(creditsDetailDO2);
  855. }else if (creditsDetailDO.getStepNumber() >= step1 && creditsDetailDO.getStepNumber() < step2){
  856. creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+1);
  857. creditsDetailDO1.setTradeDirection(1);
  858. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  859. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  860. accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()));
  861. AccountDO accountDO1 = accountDao.save(accountDO);
  862. creditsDetailDO2.setTotal(accountDO1.getTotal());
  863. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()));
  864. taskPatientDetailDao.save(taskPatientDetailDO);
  865. creditsDetailDOS.clear();
  866. creditsDetailDOS.add(creditsDetailDO2);
  867. }else if (creditsDetailDO.getStepNumber() >= step2){
  868. if (creditsDetailDO1.getIntegrate() == 1){
  869. creditsDetailDO1.setIntegrate(2);
  870. creditsDetailDO1.setTradeDirection(1);
  871. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  872. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  873. accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
  874. AccountDO accountDO1 = accountDao.save(accountDO);
  875. creditsDetailDO2.setTotal(accountDO1.getTotal());
  876. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()-1));
  877. taskPatientDetailDao.save(taskPatientDetailDO);
  878. creditsDetailDOS.clear();
  879. creditsDetailDOS.add(creditsDetailDO2);
  880. }*//*else if(creditsDetailDO1.getIntegrate() == 3){
  881. creditsDetailDO1.setIntegrate(creditsDetailDO1.getIntegrate()+5);
  882. creditsDetailDO1.setTradeDirection(1);
  883. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  884. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  885. accountDO.setTotal(accountDO.getTotal()+(creditsDetailDO2.getIntegrate()-3));
  886. AccountDO accountDO1 = accountDao.save(accountDO);
  887. creditsDetailDO2.setTotal(accountDO1.getTotal());
  888. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+(creditsDetailDO2.getIntegrate()-3));
  889. taskPatientDetailDao.save(taskPatientDetailDO);
  890. creditsDetailDOS.clear();
  891. creditsDetailDOS.add(creditsDetailDO2);
  892. }*//*
  893. }
  894. }else{
  895. CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
  896. if (creditsDetailDO.getStepNumber() < step1 && creditsDetailDO.getStepNumber() >0){
  897. creditsDetailDO1.setIntegrate(0);
  898. creditsDetailDO1.setTradeDirection(1);
  899. }else if (creditsDetailDO.getStepNumber() >= step1 && creditsDetailDO.getStepNumber() < step2){
  900. creditsDetailDO1.setIntegrate(1);
  901. creditsDetailDO1.setTradeDirection(1);
  902. }else if (creditsDetailDO.getStepNumber() >=step2){
  903. creditsDetailDO1.setIntegrate(2);
  904. creditsDetailDO1.setTradeDirection(1);
  905. }
  906. creditsDetailDO1.setSaasId("dev");
  907. creditsDetailDO1.setTradeType("ACTIVITY_TASK");
  908. creditsDetailDO1.setPatientId(creditsDetailDO.getPatientId());
  909. creditsDetailDO1.setHospital(creditsDetailDO.getHospital());
  910. creditsDetailDO1.setHospitalName(creditsDetailDO.getHospitalName());
  911. creditsDetailDO1.setAccountId(creditsDetailDO.getAccountId());
  912. creditsDetailDO1.setStatus(1);
  913. creditsDetailDO1.setCreateTime(new Date());
  914. creditsDetailDO1.setUpdateTime(new Date());
  915. creditsDetailDO1.setTransactionId(taskPatientDetailDO.getTaskId());
  916. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  917. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  918. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO2.getIntegrate());
  919. taskPatientDetailDO.setTotal(taskPatientDetailDO.getTotal()+creditsDetailDO2.getIntegrate());
  920. taskPatientDetailDao.save(taskPatientDetailDO);
  921. creditsDetailDO2.setTotal(accountDO.getTotal());
  922. creditsDetailDOS.add(creditsDetailDO2);
  923. }*/
  924. /* String step = redisTemplate.opsForValue().get(STEP);
  925. if (StringUtils.isEmpty(step)){
  926. throw new Exception("获取步数失败!");
  927. }
  928. JSONObject object = JSONObject.parseObject(step);
  929. int step1 = object.getInteger("step1");
  930. int step2 = object.getInteger("step2");
  931. */
  932. try{
  933. activeRecordService.insert("dev",creditsDetailDOS.get(0).getTransactionId(),null,null,null,creditsDetailDOS.get(0).getPatientId());
  934. }catch (Exception e){
  935. logger.error("插入活跃出错:"+e.getMessage());
  936. }
  937. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  938. envelop.setDetailModelList(creditsDetailDOS);
  939. return envelop;
  940. }
  941. }catch (Exception e){
  942. e.printStackTrace();
  943. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  944. return envelop;
  945. }
  946. }
  947. public MixEnvelop doctorDescreaseIntegrate(String ruleId,String patientId,String doctorId,String hospital,String hospitalName,Integer integrate,String reason) throws Exception {
  948. MixEnvelop envelop = new MixEnvelop<>();
  949. envelop.setObj(true);
  950. TaskDO taskDO = taskDao.selectByTaskRuleId(ruleId);
  951. String sql = "select * from wlyy_health_bank_account where status = 1 and patient_id = '"+patientId+"'";
  952. List<AccountDO> accountDOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
  953. AccountDO accountDO = accountDOs.get(0);
  954. if (taskDO == null){
  955. TaskRuleDO taskRuleDO = taskRuleDao.findByCode(ruleId);
  956. TaskDO taskDO1 = new TaskDO();
  957. taskDO1.setTitle(taskRuleDO.getName());
  958. taskDO1.setContent(taskRuleDO.getDescription());
  959. taskDO1.setSaasId("dev");
  960. taskDO1.setTaskCode("RULE");
  961. taskDO1.setType("RULE_TASK");
  962. taskDO1.setTransactionId(ruleId);
  963. taskDO1.setCreateTime(new Date());
  964. taskDO1.setUpdateTime(new Date());
  965. taskDO1.setRuleCode(taskRuleDO.getId());
  966. taskDO1.setStatus(1);
  967. taskDO = taskDao.save(taskDO1);
  968. }
  969. TaskPatientDetailDO patientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(taskDO.getId(),patientId);
  970. if (patientDetailDO == null){
  971. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  972. taskPatientDetailDO.setSaasId("dev");
  973. taskPatientDetailDO.setTaskId(taskDO.getId());
  974. taskPatientDetailDO.setPatientId(patientId);
  975. taskPatientDetailDO.setDoctorId(doctorId);
  976. taskPatientDetailDO.setPatientIdcard(accountDO.getIdCard());
  977. taskPatientDetailDO.setCreateTime(new Date());
  978. taskPatientDetailDO.setUpdateTime(new Date());
  979. taskPatientDetailDO.setStatus(1);
  980. taskPatientDetailDao.save(taskPatientDetailDO);
  981. }
  982. if (accountDO.getTotal().compareTo(integrate)>=0){
  983. CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
  984. creditsDetailDO.setAccountId(accountDO.getId());
  985. creditsDetailDO.setIdCard(accountDO.getIdCard());
  986. creditsDetailDO.setSaasId("dev");
  987. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  988. creditsDetailDO.setTradeDirection(-1);
  989. creditsDetailDO.setIntegrate(integrate);
  990. creditsDetailDO.setDescription(reason);
  991. creditsDetailDO.setStatus(1);
  992. creditsDetailDO.setHospital(hospital);
  993. creditsDetailDO.setHospitalName(hospitalName);
  994. creditsDetailDO.setCreateTime(new Date());
  995. creditsDetailDO.setUpdateTime(new Date());
  996. creditsDetailDO.setTransactionId(taskDO.getId());
  997. creditsDetailDO.setPatientId(patientId);
  998. creditsDetailDO.setHospitalName(hospitalName);
  999. credittsLogDetailDao.save(creditsDetailDO);
  1000. accountDO.setTotal(accountDO.getTotal()-integrate);
  1001. accountDao.save(accountDO);
  1002. }else {
  1003. envelop.setMessage("积分不足!");
  1004. throw new Exception("积分不足!");
  1005. }
  1006. return envelop;
  1007. }
  1008. /*public JSONObject getStepNumber(){
  1009. String step = redisTemplate.·().get(STEP);
  1010. logger.info("redis数据:"+step);
  1011. String sql = ""
  1012. String step1 = systemDictDao.
  1013. logger.info("数据库的数据:"+step1);
  1014. if (step != null && step.equalsIgnoreCase(step1)){
  1015. JSONObject jsonObject = JSONObject.parseObject(step);
  1016. logger.info("数据不一致:"+jsonObject.toString());
  1017. return jsonObject;
  1018. }else {
  1019. JSONObject jsonObject = JSONObject.parseObject(step);
  1020. redisTemplate.opsForValue().set(STEP,step1);
  1021. logger.info("数据一致:"+jsonObject.toString());
  1022. return jsonObject;
  1023. }
  1024. }*/
  1025. public MixEnvelop<CreditsDetailDO, CreditsDetailDO> weekReward(CreditsDetailDO creditsDetailDO) {
  1026. try {
  1027. synchronized (creditsDetailDO.getPatientId()) {
  1028. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '" + creditsDetailDO.getPatientId() + "'";
  1029. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount, new BeanPropertyRowMapper(AccountDO.class));
  1030. if (accountDOList != null && accountDOList.size() != 0) {
  1031. creditsDetailDO.setAccountId(accountDOList.get(0).getId());
  1032. }
  1033. String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and " +
  1034. "DATE_FORMAT(create_time,'%Y-%m-%d') IN " + creditsDetailDO.getWeekTimes()+" and description = '周奖励'";
  1035. List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
  1036. List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
  1037. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  1038. if (getWeekOfDate(new Date()).equalsIgnoreCase("星期五")||getWeekOfDate(new Date()).equalsIgnoreCase("星期六")||getWeekOfDate(new Date()).equalsIgnoreCase("星期日")){
  1039. String sql = "select sum(integrate) as total from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and description = '周奖励'";
  1040. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
  1041. Long count = 0L;
  1042. if(rstotal!=null&&rstotal.size()>0){
  1043. Object object = rstotal.get(0).get("total");
  1044. if (object != null){
  1045. count = Long.parseLong(object.toString());
  1046. }
  1047. }
  1048. if (count > 12){
  1049. envelop.setMessage("奖励积分已达到12分。不能再奖励了!");
  1050. return envelop;
  1051. }else{
  1052. if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
  1053. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  1054. creditsDetailDO.setSaasId("dev");
  1055. creditsDetailDO.setStatus(1);
  1056. creditsDetailDO.setTransactionId(creditsDetailDO.getTransactionId());
  1057. creditsDetailDO.setCreateTime(new Date());
  1058. creditsDetailDO.setUpdateTime(new Date());
  1059. creditsDetailDO.setTradeDirection(1);
  1060. CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
  1061. creditsDetailDOList.add(creditsDetailDO1);
  1062. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  1063. taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  1064. taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
  1065. String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
  1066. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1, new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  1067. TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
  1068. if (creditsDetailDO1.getTradeDirection() == 1) {
  1069. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() + creditsDetailDO1.getIntegrate());
  1070. } else if (creditsDetailDO.getTradeDirection() == -1) {
  1071. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() - creditsDetailDO1.getIntegrate());
  1072. }
  1073. taskPatientDetailDao.save(taskPatientDetailDO1);
  1074. AccountDO accountDO = accountDao.findOne(creditsDetailDO1.getAccountId());
  1075. if (creditsDetailDO1.getTradeDirection() == 1) {
  1076. accountDO.setTotal(accountDO.getTotal() + creditsDetailDO1.getIntegrate());
  1077. } else if (creditsDetailDO.getTradeDirection() == -1) {
  1078. accountDO.setTotal(accountDO.getTotal() - creditsDetailDO1.getIntegrate());
  1079. }
  1080. AccountDO accountDO1 = accountDao.save(accountDO);
  1081. List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
  1082. for (CreditsDetailDO creditsDetailDO2 : creditsDetailDOList) {
  1083. creditsDetailDO2.setTotal(accountDO1.getTotal());
  1084. creditsDetailDO2.setFlag("1");
  1085. creditsDetailDOS.add(creditsDetailDO2);
  1086. }
  1087. envelop.setDetailModelList(creditsDetailDOS);
  1088. }else {
  1089. for (CreditsDetailDO creditsDetailDO1 : creditsDetailDOS1){
  1090. creditsDetailDO1.setFlag("2");
  1091. }
  1092. envelop.setDetailModelList(creditsDetailDOS1);
  1093. }
  1094. return envelop;
  1095. }
  1096. }else{
  1097. CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
  1098. creditsDetailDO1.setFlag("0");
  1099. creditsDetailDOList.add(creditsDetailDO1);
  1100. envelop.setDetailModelList(creditsDetailDOList);
  1101. return envelop;
  1102. }
  1103. }
  1104. } catch (Exception e) {
  1105. e.printStackTrace();
  1106. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  1107. return envelop;
  1108. }
  1109. }
  1110. public String getWeekOfDate(Date dt) {
  1111. String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
  1112. Calendar cal = Calendar.getInstance();
  1113. cal.setTime(dt);
  1114. int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
  1115. if (w < 0)
  1116. w = 0;
  1117. return weekDays[w];
  1118. }
  1119. /**
  1120. * 健康问答添加积分
  1121. *
  1122. * @param creditsDetailDO
  1123. * @return
  1124. * @throws Exception
  1125. */
  1126. public MixEnvelop<CreditsDetailDO,CreditsDetailDO> patientGetInteger(CreditsDetailDO creditsDetailDO) throws Exception {
  1127. MixEnvelop<CreditsDetailDO,CreditsDetailDO> envelop = new MixEnvelop<>();
  1128. TaskDO taskDO = taskDao.selectById(creditsDetailDO.getTransactionId());
  1129. ActivityRuleDO ruleDO = activityRuleDao.selectByActivityId(taskDO.getTransactionId());
  1130. JSONObject object = JSONObject.parseObject(ruleDO.getValue1());
  1131. Integer type = object.getInteger("type");
  1132. AccountDO accountDO = accountDao.selectByPatientId(creditsDetailDO.getPatientId());
  1133. creditsDetailDO.setUpdateTime(new Date());
  1134. creditsDetailDO.setCreateTime(new Date());
  1135. creditsDetailDO.setStatus(1);
  1136. if (type == 2){
  1137. creditsDetailDO.setCoupon(creditsDetailDO.getCoupon());
  1138. creditsDetailDO.setIntegrate(null);
  1139. }else if (type==1){
  1140. creditsDetailDO.setIntegrate(creditsDetailDO.getCoupon());
  1141. creditsDetailDO.setCoupon(null);
  1142. }
  1143. creditsDetailDO.setSaasId("dev");
  1144. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  1145. creditsDetailDO.setTradeDirection(1);
  1146. creditsDetailDO.setAccountId(accountDO.getId());
  1147. CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
  1148. if (creditsDetailDO1 == null){
  1149. throw new Exception("积分添加失败!");
  1150. }
  1151. TaskPatientDetailDO patientDetailDO = taskPatientDetailDao.selectByTaskIdAndPatientId(creditsDetailDO.getTransactionId(),creditsDetailDO.getPatientId());
  1152. patientDetailDO.setUpdateTime(new Date());
  1153. patientDetailDO.setCreateTime(new Date());
  1154. if (type == 2){
  1155. patientDetailDO.setCouponTotal(patientDetailDO.getCouponTotal()+creditsDetailDO.getCoupon());
  1156. }else if (type==1||type==3){
  1157. patientDetailDO.setTotal(patientDetailDO.getTotal()+creditsDetailDO.getIntegrate());
  1158. }
  1159. patientDetailDO.setStatus(1);
  1160. TaskPatientDetailDO taskPatientDetailDO = taskPatientDetailDao.save(patientDetailDO);
  1161. if (taskPatientDetailDO == null){
  1162. throw new Exception("修改活动状态和积分失败!");
  1163. }
  1164. if (type == 2){
  1165. accountDO.setCouponTotal(accountDO.getCouponTotal()+creditsDetailDO.getCoupon());
  1166. }else if (type==1||type==3){
  1167. accountDO.setTotal(accountDO.getTotal()+creditsDetailDO.getIntegrate());
  1168. }
  1169. accountDO.setUpdateTime(new Date());
  1170. AccountDO accountDO1 = accountDao.save(accountDO);
  1171. if (accountDO1 == null){
  1172. throw new Exception("修改银行账户积分失败!");
  1173. }
  1174. envelop.setObj(creditsDetailDO);
  1175. return envelop;
  1176. }
  1177. /**
  1178. * 健康问答--获取当日积分
  1179. *
  1180. * @param patient
  1181. * @param transactionId
  1182. * @return
  1183. */
  1184. public MixEnvelop<CreditsDetailDO,CreditsDetailDO> selectByDate(String patient,String transactionId){
  1185. MixEnvelop<CreditsDetailDO,CreditsDetailDO> envelop = new MixEnvelop<>();
  1186. String sql ="select * from wlyy_health_bank_credits_detail where patient_id = '"+patient+"' and " +
  1187. "transaction_id = '"+transactionId+"' and create_time >='"+ DateUtils.getDayBegin()+"' and " +
  1188. "create_time <= '"+DateUtils.getDayEnd()+"'";
  1189. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
  1190. CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
  1191. if (creditsDetailDOS != null && creditsDetailDOS.size()!=0){
  1192. creditsDetailDO = creditsDetailDOS.get(0);
  1193. }
  1194. TaskDO taskDO = taskDao.selectById(transactionId);
  1195. ActivityRuleDO ruleDO = activityRuleDao.selectByActivityId(taskDO.getTransactionId());
  1196. //活动总积分排名
  1197. String rankingSql1 = "SELECT count(1)+1 AS total FROM (SELECT " +
  1198. " SUM(total) AS sum , " +
  1199. " patient_id, " +
  1200. " activity_id " +
  1201. "FROM " +
  1202. " wlyy_health_bank_task_patient_detail btpd WHERE btpd.patient_id !='"+patient+"' " +
  1203. "GROUP BY btpd.patient_id )btpd1 " +
  1204. "WHERE " +
  1205. " btpd1.activity_id = '"+taskDO.getTransactionId()+"' AND btpd1.sum >= (SELECT SUM(s.total) as total " +
  1206. "FROM wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND s.activity_id='"+taskDO.getTransactionId()+"')" ;
  1207. List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(rankingSql1);
  1208. Long count = 0L;
  1209. if(rstotal1!=null&&rstotal1.size()>0){
  1210. count = (Long) rstotal1.get(0).get("total");
  1211. }
  1212. //总活动劵的排名
  1213. String rankingSql2 = "SELECT count(1)+1 AS total FROM (SELECT " +
  1214. " SUM(coupon_total) AS sum , " +
  1215. " patient_id, " +
  1216. " activity_id " +
  1217. "FROM " +
  1218. " wlyy_health_bank_task_patient_detail btpd WHERE btpd.patient_id !='"+patient+"' "+
  1219. "GROUP BY btpd.patient_id )btpd1 " +
  1220. "WHERE " +
  1221. " btpd1.activity_id = '"+taskDO.getTransactionId()+"' AND btpd1.sum >= (SELECT SUM(s.coupon_total) as couponTotal " +
  1222. "FROM wlyy_health_bank_task_patient_detail s WHERE s.patient_id ='"+patient+"' AND s.activity_id='"+taskDO.getTransactionId()+"')" ;
  1223. List<Map<String,Object>> rstotal2 = jdbcTemplate.queryForList(rankingSql2);
  1224. Long count2 = 0L;
  1225. if(rstotal2!=null&&rstotal2.size()>0){
  1226. count2 = (Long) rstotal2.get(0).get("total");
  1227. }
  1228. JSONObject object = JSONObject.parseObject(ruleDO.getValue1());
  1229. Integer type = object.getInteger("type");
  1230. if (type == 2){
  1231. creditsDetailDO.setActivityRanking(count2);
  1232. creditsDetailDO.setMark(1);
  1233. }else if (type==1||type==3){
  1234. creditsDetailDO.setActivityRanking(count);
  1235. creditsDetailDO.setMark(2);
  1236. }
  1237. envelop.setObj(creditsDetailDO);
  1238. return envelop;
  1239. }
  1240. /**
  1241. * 分享获取积分
  1242. *
  1243. * @param creditsDetailDO
  1244. * @return
  1245. */
  1246. public MixEnvelop<CreditsDetailDO, CreditsDetailDO> shareIntegrate(CreditsDetailDO creditsDetailDO) {
  1247. try {
  1248. synchronized (creditsDetailDO.getPatientId()) {
  1249. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '" + creditsDetailDO.getPatientId() + "'";
  1250. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount, new BeanPropertyRowMapper(AccountDO.class));
  1251. if (accountDOList != null && accountDOList.size() != 0) {
  1252. creditsDetailDO.setAccountId(accountDOList.get(0).getId());
  1253. }
  1254. String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and description = '分享'";
  1255. List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
  1256. List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
  1257. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  1258. if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
  1259. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  1260. creditsDetailDO.setDescription("分享");
  1261. creditsDetailDO.setSaasId("dev");
  1262. creditsDetailDO.setStatus(1);
  1263. creditsDetailDO.setTransactionId(creditsDetailDO.getTransactionId());
  1264. creditsDetailDO.setCreateTime(new Date());
  1265. creditsDetailDO.setUpdateTime(new Date());
  1266. creditsDetailDO.setTradeDirection(1);
  1267. CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
  1268. creditsDetailDO1.setFlag("1");
  1269. creditsDetailDOList.add(creditsDetailDO1);
  1270. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  1271. taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  1272. taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
  1273. String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
  1274. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1, new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  1275. TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
  1276. if (creditsDetailDO1.getTradeDirection() == 1) {
  1277. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() + creditsDetailDO1.getIntegrate());
  1278. } else if (creditsDetailDO.getTradeDirection() == -1) {
  1279. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() - creditsDetailDO1.getIntegrate());
  1280. }
  1281. taskPatientDetailDao.save(taskPatientDetailDO1);
  1282. AccountDO accountDO = accountDao.findOne(creditsDetailDO1.getAccountId());
  1283. if (creditsDetailDO1.getTradeDirection() == 1) {
  1284. accountDO.setTotal(accountDO.getTotal() + creditsDetailDO1.getIntegrate());
  1285. } else if (creditsDetailDO.getTradeDirection() == -1) {
  1286. accountDO.setTotal(accountDO.getTotal() - creditsDetailDO1.getIntegrate());
  1287. }
  1288. accountDao.save(accountDO);
  1289. envelop.setDetailModelList(creditsDetailDOList);
  1290. }else {
  1291. for (CreditsDetailDO creditsDetailDO1:creditsDetailDOS1){
  1292. creditsDetailDO1.setFlag("2");
  1293. creditsDetailDOList.add(creditsDetailDO1);
  1294. }
  1295. envelop.setDetailModelList(creditsDetailDOList);
  1296. }
  1297. return envelop;
  1298. }
  1299. } catch (Exception e) {
  1300. e.printStackTrace();
  1301. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  1302. return envelop;
  1303. }
  1304. }
  1305. public List<CreditsDetailDO> share(CreditsDetailDO creditsDetailDO) throws Exception {
  1306. synchronized (creditsDetailDO.getPatientId()) {
  1307. String activityId= creditsDetailDO.getActivityId();
  1308. ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(activityId);
  1309. String sql = "select * from wlyy_health_bank_credits_detail where patient_id ='"+creditsDetailDO.getPatientId()+"' " +
  1310. "and description ='分享' and status =1 AND transaction_id = '"+creditsDetailDO.getTransactionId()+"'";
  1311. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
  1312. List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
  1313. if (activityRuleDO != null){
  1314. JSONObject jsonObject = JSONObject.parseObject(activityRuleDO.getValue1());
  1315. Boolean isShare = jsonObject.getBoolean("isshare");
  1316. if (isShare){
  1317. JSONObject object = jsonObject.getJSONObject("shareData");
  1318. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '" + creditsDetailDO.getPatientId() + "'";
  1319. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount, new BeanPropertyRowMapper(AccountDO.class));
  1320. CreditsDetailDO creditsDetailDO1 = new CreditsDetailDO();
  1321. if (accountDOList != null && accountDOList.size() != 0) {
  1322. creditsDetailDO1.setAccountId(accountDOList.get(0).getId());
  1323. }
  1324. if (creditsDetailDOS!=null&&creditsDetailDOS.size()>=object.getInteger("frequency")){
  1325. throw new Exception("分享超过"+creditsDetailDOS.size()+"次");
  1326. }else {
  1327. creditsDetailDO1.setHospitalName(creditsDetailDO.getHospitalName());
  1328. creditsDetailDO1.setHospital(creditsDetailDO.getHospital());
  1329. creditsDetailDO1.setPatientId(creditsDetailDO.getPatientId());
  1330. creditsDetailDO1.setTradeType("ACTIVITY_TASK");
  1331. creditsDetailDO1.setDescription("分享");
  1332. creditsDetailDO1.setSaasId("dev");
  1333. creditsDetailDO1.setStatus(1);
  1334. creditsDetailDO1.setCoupon(0);
  1335. creditsDetailDO1.setTransactionId(creditsDetailDO.getTransactionId());
  1336. creditsDetailDO1.setCreateTime(new Date());
  1337. creditsDetailDO1.setUpdateTime(new Date());
  1338. creditsDetailDO1.setTradeDirection(1);
  1339. creditsDetailDO1.setIntegrate(object.getInteger("integrate"));
  1340. CreditsDetailDO creditsDetailDO2 = credittsLogDetailDao.save(creditsDetailDO1);
  1341. creditsDetailDOList.add(creditsDetailDO2);
  1342. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  1343. taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  1344. taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
  1345. String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
  1346. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1, new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  1347. TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
  1348. if (creditsDetailDO1.getTradeDirection() == 1) {
  1349. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() + creditsDetailDO2.getIntegrate());
  1350. } else if (creditsDetailDO1.getTradeDirection() == -1) {
  1351. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() - creditsDetailDO2.getIntegrate());
  1352. }
  1353. taskPatientDetailDao.save(taskPatientDetailDO1);
  1354. AccountDO accountDO = accountDao.findOne(creditsDetailDO2.getAccountId());
  1355. if (creditsDetailDO1.getTradeDirection() == 1) {
  1356. accountDO.setTotal(accountDO.getTotal() + creditsDetailDO2.getIntegrate());
  1357. } else if (creditsDetailDO1.getTradeDirection() == -1) {
  1358. accountDO.setTotal(accountDO.getTotal() - creditsDetailDO2.getIntegrate());
  1359. }
  1360. accountDao.save(accountDO);
  1361. }
  1362. }
  1363. }
  1364. return creditsDetailDOList;
  1365. }
  1366. }
  1367. /**
  1368. * 商城积分支付
  1369. * @param patient
  1370. * @param total
  1371. * @param hospital
  1372. * @param hospitalName
  1373. * @param array
  1374. * @return
  1375. * @throws Exception
  1376. */
  1377. public MixEnvelop<CreditsDetailDO,CreditsDetailDO> payIntegrate(String patient,Double total,String hospital,String hospitalName,JSONArray array) throws Exception {
  1378. MixEnvelop<CreditsDetailDO,CreditsDetailDO> envelop = new MixEnvelop<>();
  1379. AccountDO accountDO = accountDao.selectByPatientId(patient);
  1380. Integer total1 = total.intValue();
  1381. if (accountDO == null){
  1382. envelop.setMessage("银行账户不存在!");
  1383. throw new Exception("银行账户不存在!");
  1384. }else {
  1385. if (total1>accountDO.getTotal()){
  1386. envelop.setMessage("积分余额不足!");
  1387. throw new Exception("积分余额不足!");
  1388. }else{
  1389. for (int i=0;i<array.size();i++){
  1390. JSONObject object = array.getJSONObject(i);
  1391. CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
  1392. creditsDetailDO.setPatientId(patient);
  1393. creditsDetailDO.setAccountId(accountDO.getId());
  1394. creditsDetailDO.setHospital(hospital);
  1395. creditsDetailDO.setTradeType("SHOPPING_PAY");
  1396. creditsDetailDO.setTradeDirection(-1);
  1397. creditsDetailDO.setTransactionId(object.getString("orderId"));
  1398. creditsDetailDO.setIntegrate(object.getDouble("integrate").intValue());
  1399. creditsDetailDO.setCreateTime(new Date());
  1400. creditsDetailDO.setUpdateTime(new Date());
  1401. creditsDetailDO.setHospitalName(hospitalName);
  1402. creditsDetailDO.setSaasId("dev");
  1403. creditsDetailDO.setId(getCode());
  1404. creditsDetailDO.setCoupon(0);
  1405. creditsDetailDO.setStatus(1);
  1406. credittsLogDetailDao.save(creditsDetailDO);
  1407. }
  1408. accountDO.setTotal(accountDO.getTotal()-total1);
  1409. accountDao.save(accountDO);
  1410. }
  1411. }
  1412. return envelop;
  1413. }
  1414. public MixEnvelop<CreditsDetailDO,CreditsDetailDO> refundIntegrate(JSONArray array) throws Exception {
  1415. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  1416. for (int i=0;i<array.size();i++){
  1417. JSONObject object = array.getJSONObject(i);
  1418. CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.selectByTransactionId(object.getString("orderId"),"SHOPPING_PAY");
  1419. CreditsDetailDO creditsDetailDO = new CreditsDetailDO();
  1420. creditsDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  1421. creditsDetailDO.setAccountId(creditsDetailDO1.getAccountId());
  1422. creditsDetailDO.setHospital(creditsDetailDO1.getHospital());
  1423. creditsDetailDO.setTradeType("REFUND");
  1424. creditsDetailDO.setTradeDirection(1);
  1425. creditsDetailDO.setTransactionId(object.getString("orderId"));
  1426. creditsDetailDO.setIntegrate(object.getDouble("integrate").intValue());
  1427. creditsDetailDO.setCreateTime(new Date());
  1428. creditsDetailDO.setUpdateTime(new Date());
  1429. creditsDetailDO.setHospitalName(creditsDetailDO1.getHospitalName());
  1430. creditsDetailDO.setSaasId("dev");
  1431. creditsDetailDO.setId(getCode());
  1432. creditsDetailDO.setCoupon(0);
  1433. creditsDetailDO.setStatus(1);
  1434. credittsLogDetailDao.save(creditsDetailDO);
  1435. AccountDO accountDO = accountDao.selectByPatientId(creditsDetailDO1.getPatientId());
  1436. accountDO.setTotal(accountDO.getTotal()+object.getDouble("integrate").intValue());
  1437. accountDao.save(accountDO);
  1438. }
  1439. return envelop;
  1440. }
  1441. /**
  1442. *
  1443. * @param creditsDetailDO
  1444. * @param flag 1连续2间断
  1445. * @return
  1446. */
  1447. public MixEnvelop<CreditsDetailDO, CreditsDetailDO> weekRewardAndIntegrate(CreditsDetailDO creditsDetailDO,Integer flag) {
  1448. synchronized (creditsDetailDO.getPatientId()) {
  1449. MixEnvelop<CreditsDetailDO, CreditsDetailDO> envelop = new MixEnvelop<>();
  1450. String sqlAccount = "select * from wlyy_health_bank_account ba where ba.patient_id = '" + creditsDetailDO.getPatientId() + "'";
  1451. List<AccountDO> accountDOList = jdbcTemplate.query(sqlAccount, new BeanPropertyRowMapper(AccountDO.class));
  1452. if (accountDOList != null && accountDOList.size() != 0) {
  1453. creditsDetailDO.setAccountId(accountDOList.get(0).getId());
  1454. }
  1455. if (flag == 1) {
  1456. String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and " +
  1457. "update_time >= '" + creditsDetailDO.getMonday() + "' AND update_time<='" + creditsDetailDO.getSunday() + "' and description = '周奖励-连续' AND transaction_id = '"+creditsDetailDO.getTransactionId()+"'";
  1458. List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
  1459. List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
  1460. if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
  1461. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  1462. creditsDetailDO.setSaasId("dev");
  1463. creditsDetailDO.setStatus(1);
  1464. creditsDetailDO.setTransactionId(creditsDetailDO.getTransactionId());
  1465. creditsDetailDO.setCreateTime(new Date());
  1466. creditsDetailDO.setUpdateTime(DateUtil.strToDateLong(creditsDetailDO.getSunday()));
  1467. creditsDetailDO.setTradeDirection(1);
  1468. creditsDetailDO.setDescription("周奖励-连续");
  1469. creditsDetailDO.setCoupon(0);
  1470. CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
  1471. creditsDetailDOList.add(creditsDetailDO1);
  1472. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  1473. taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  1474. taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
  1475. String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
  1476. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1, new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  1477. TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
  1478. if (creditsDetailDO1.getTradeDirection() == 1) {
  1479. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() + creditsDetailDO1.getIntegrate());
  1480. } else if (creditsDetailDO1.getTradeDirection() == -1) {
  1481. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() - creditsDetailDO1.getIntegrate());
  1482. }
  1483. taskPatientDetailDao.save(taskPatientDetailDO1);
  1484. AccountDO accountDO = accountDao.findOne(creditsDetailDO1.getAccountId());
  1485. if (creditsDetailDO1.getTradeDirection() == 1) {
  1486. accountDO.setTotal(accountDO.getTotal() + creditsDetailDO1.getIntegrate());
  1487. } else if (creditsDetailDO1.getTradeDirection() == -1) {
  1488. accountDO.setTotal(accountDO.getTotal() - creditsDetailDO1.getIntegrate());
  1489. }
  1490. AccountDO accountDO1 = accountDao.save(accountDO);
  1491. List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
  1492. for (CreditsDetailDO creditsDetailDO2 : creditsDetailDOList) {
  1493. creditsDetailDO2.setTotal(accountDO1.getTotal());
  1494. creditsDetailDO2.setFlag("1");
  1495. creditsDetailDOS.add(creditsDetailDO2);
  1496. }
  1497. envelop.setDetailModelList(creditsDetailDOS);
  1498. return envelop;
  1499. }else {
  1500. logger.info("居民:"+creditsDetailDO.getPatientId()+"已领取周奖励-连续");
  1501. }
  1502. }else if (flag==2){
  1503. String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + creditsDetailDO.getPatientId() + "' and " +
  1504. "update_time >= '" +creditsDetailDO.getMonday()+"' AND update_time<='" +creditsDetailDO.getSunday() + "' and description = '周奖励-间断' AND transaction_id = '"+creditsDetailDO.getTransactionId()+"'";
  1505. List<CreditsDetailDO> creditsDetailDOS1 = jdbcTemplate.query(creditsSql, new BeanPropertyRowMapper(CreditsDetailDO.class));
  1506. List<CreditsDetailDO> creditsDetailDOList = new ArrayList<>();
  1507. if (creditsDetailDOS1 == null || creditsDetailDOS1.size() == 0) {
  1508. creditsDetailDO.setTradeType("ACTIVITY_TASK");
  1509. creditsDetailDO.setSaasId("dev");
  1510. creditsDetailDO.setStatus(1);
  1511. creditsDetailDO.setTransactionId(creditsDetailDO.getTransactionId());
  1512. creditsDetailDO.setCreateTime(new Date());
  1513. creditsDetailDO.setUpdateTime(DateUtil.strToDateLong(creditsDetailDO.getSunday()));
  1514. creditsDetailDO.setTradeDirection(1);
  1515. creditsDetailDO.setDescription("周奖励-间断");
  1516. CreditsDetailDO creditsDetailDO1 = credittsLogDetailDao.save(creditsDetailDO);
  1517. creditsDetailDOList.add(creditsDetailDO1);
  1518. TaskPatientDetailDO taskPatientDetailDO = new TaskPatientDetailDO();
  1519. taskPatientDetailDO.setPatientId(creditsDetailDO1.getPatientId());
  1520. taskPatientDetailDO.setTaskId(creditsDetailDO1.getTransactionId());
  1521. String taskSql1 = ISqlUtils.getAllSql(taskPatientDetailDO);
  1522. List<TaskPatientDetailDO> taskPatientDetailDOS1 = jdbcTemplate.query(taskSql1, new BeanPropertyRowMapper(TaskPatientDetailDO.class));
  1523. TaskPatientDetailDO taskPatientDetailDO1 = taskPatientDetailDOS1.get(0);
  1524. if (creditsDetailDO1.getTradeDirection() == 1) {
  1525. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() + creditsDetailDO1.getIntegrate());
  1526. } else if (creditsDetailDO.getTradeDirection() == -1) {
  1527. taskPatientDetailDO1.setTotal(taskPatientDetailDO1.getTotal() - creditsDetailDO1.getIntegrate());
  1528. }
  1529. taskPatientDetailDao.save(taskPatientDetailDO1);
  1530. AccountDO accountDO = accountDao.findOne(creditsDetailDO1.getAccountId());
  1531. if (creditsDetailDO1.getTradeDirection() == 1) {
  1532. accountDO.setTotal(accountDO.getTotal() + creditsDetailDO1.getIntegrate());
  1533. } else if (creditsDetailDO.getTradeDirection() == -1) {
  1534. accountDO.setTotal(accountDO.getTotal() - creditsDetailDO1.getIntegrate());
  1535. }
  1536. AccountDO accountDO1 = accountDao.save(accountDO);
  1537. List<CreditsDetailDO> creditsDetailDOS = new ArrayList<>();
  1538. for (CreditsDetailDO creditsDetailDO2 : creditsDetailDOList) {
  1539. creditsDetailDO2.setTotal(accountDO1.getTotal());
  1540. creditsDetailDO2.setFlag("1");
  1541. creditsDetailDOS.add(creditsDetailDO2);
  1542. }
  1543. envelop.setDetailModelList(creditsDetailDOS);
  1544. return envelop;
  1545. }else {
  1546. logger.info("居民:"+creditsDetailDO.getPatientId()+"已领取周奖励-间断");
  1547. envelop.setMessage("居民:"+creditsDetailDO.getPatientId()+"已领取周奖励-间断");
  1548. }
  1549. }
  1550. return envelop;
  1551. }
  1552. }
  1553. public List<CreditsDetailDO> selectWeekReward(String patient,String taskId,String monday,String sunday){
  1554. String creditsSql = "select * from wlyy_health_bank_credits_detail where patient_id = '" + patient + "' and " +
  1555. "update_time >= '" +monday+"' AND update_time<='" + sunday+ "' and ( description = '周奖励-间断' OR description = '周奖励-连续') AND transaction_id = '"+taskId+"'";
  1556. List<CreditsDetailDO> creditsDetailDOS = jdbcTemplate.query(creditsSql,new BeanPropertyRowMapper<>(CreditsDetailDO.class));
  1557. return creditsDetailDOS;
  1558. }
  1559. }