ScaleLogServiceImpl.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.api.games.service.impl;
  2. import com.api.common.JSONUtils;
  3. import com.api.common.UtilFun;
  4. import com.api.config.ConstUser;
  5. import com.api.core.response.Result;
  6. import com.api.core.response.ResultGenerator;
  7. import com.api.core.service.AbstractService;
  8. import com.api.games.dao.GamePlayTimeMapper;
  9. import com.api.games.dao.PushLogMapper;
  10. import com.api.games.dao.ScaleLogMapper;
  11. import com.api.games.dao.UserConfigMapper;
  12. import com.api.games.model.GamePlayTime;
  13. import com.api.games.model.PushLog;
  14. import com.api.games.model.ScaleLog;
  15. import com.api.games.model.UserConfig;
  16. import com.api.games.service.ScaleLogService;
  17. import com.github.pagehelper.PageHelper;
  18. import com.github.pagehelper.PageInfo;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import tk.mybatis.mapper.entity.Condition;
  22. import javax.annotation.Resource;
  23. import java.util.Calendar;
  24. import java.util.Date;
  25. import java.util.List;
  26. import java.util.Map;
  27. /**
  28. * Created by wanghuiwen on 2020/02/23.
  29. */
  30. @Service
  31. @Transactional
  32. public class ScaleLogServiceImpl extends AbstractService<ScaleLog> implements ScaleLogService {
  33. @Resource
  34. private ScaleLogMapper scaleLogMapper;
  35. @Resource
  36. private UserConfigMapper userConfigMapper;
  37. @Resource
  38. private PushLogMapper pushLogMapper;
  39. @Resource
  40. private GamePlayTimeMapper gamePlayTimeMapper;
  41. @Override
  42. public void deletePlayGameId(Long id){
  43. gamePlayTimeMapper.deleteByPrimaryKey(id);
  44. }
  45. @Override
  46. public Result listOverDate(Long uid){
  47. Calendar calendar = Calendar.getInstance();
  48. calendar.add(Calendar.HOUR_OF_DAY, -2);
  49. return ResultGenerator.genSuccessResult(gamePlayTimeMapper.getScalePlayTime(uid, "2000-01-01 00:00:00", UtilFun.DateToString(calendar.getTime(), UtilFun.YYYYMMDDHHMMSS)));
  50. }
  51. @Override
  52. public void deleteByUid(Long id) {
  53. List<ScaleLog> scaleLogs = scaleLogMapper.listByUid(id);
  54. for (ScaleLog item : scaleLogs){
  55. deleteById(item.getId());
  56. }
  57. }
  58. @Override
  59. public Result list(String search, String ordermap, Integer page, Integer size) {
  60. Map<String, Object> params = JSONUtils.json2map(search);
  61. Map<String, Object> order = JSONUtils.json2map(ordermap);
  62. for (String key : order.keySet()) {
  63. if (order.get(key) != null && order.get(key).equals("ascending")) order.put(key, "asc");
  64. if (order.get(key) != null && order.get(key).equals("descending")) order.put(key, "desc");
  65. }
  66. PageHelper.startPage(page, size);
  67. List<Map<String, Object>> res = scaleLogMapper.list(params, order);
  68. PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(res);
  69. return ResultGenerator.genSuccessResult(pageInfo);
  70. }
  71. @Override
  72. public Result notPerformed() {
  73. List<ScaleLog> res = scaleLogMapper.notPerformed();
  74. if (res != null && res.size() > 0) save(res);
  75. return ResultGenerator.genSuccessResult();
  76. }
  77. @Override
  78. public List<Map<String, Object>> download(String search, String ordermap) {
  79. Map<String, Object> params = JSONUtils.json2map(search);
  80. Map<String, Object> order = JSONUtils.json2map(ordermap);
  81. for (String key : order.keySet()) {
  82. if (order.get(key) != null && order.get(key).equals("ascending")) order.put(key, "asc");
  83. if (order.get(key) != null && order.get(key).equals("descending")) order.put(key, "desc");
  84. }
  85. return scaleLogMapper.list(params, order);
  86. }
  87. @Override
  88. public Result date(Long id, Long msgId) {
  89. //修改推送记录状态
  90. if (msgId != null) {
  91. PushLog pushLog = pushLogMapper.selectByPrimaryKey(msgId);
  92. if (pushLog != null) {
  93. pushLog.setStatus(ConstUser.PUSH_ING);
  94. pushLogMapper.updateByPrimaryKeySelective(pushLog);
  95. }
  96. }
  97. Condition condition = new Condition(ScaleLog.class);
  98. condition.createCriteria().andEqualTo("schedule", 0).andEqualTo("userId", id);
  99. List<ScaleLog> scaleLogs = scaleLogMapper.selectByCondition(condition);
  100. return ResultGenerator.genSuccessResult(scaleLogs);
  101. }
  102. @Override
  103. public String sign(Long uid) {
  104. List<ScaleLog> logs = scaleLogMapper.listByUid(uid);
  105. return String.valueOf(logs == null ? 1 : logs.size() + 1);
  106. }
  107. }