| | |
| | | import com.yeshi.buwan.service.manager.GoldCornManager; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | @Resource |
| | | private GoldCornManager goldCornManager; |
| | | Logger logger = LoggerFactory.getLogger(SignInService.class); |
| | | |
| | | @Override |
| | | public Integer signIn(String uid) throws LoginUserException, SignInException { |
| | |
| | | goldCornManager.addGoldCorn(uid, CodeCornGetSourceType.signIn, goldCorn, "签到", String.format("连续%s天签到", (dayCount + 1))); |
| | | return goldCorn; |
| | | } catch (GoldUserException e) { |
| | | logger.error("签到出错:", e); |
| | | throw new LoginUserException(e.getCode(), e.getMsg()); |
| | | } catch (GoldAppException e) { |
| | | logger.error("签到出错:", e); |
| | | throw new SignInException(1, "服务器内部出错"); |
| | | } catch (GoldTradeException e) { |
| | | logger.error("签到出错:", e); |
| | | throw new SignInException(e.getCode(), e.getMsg()); |
| | | } catch (Exception e) { |
| | | logger.error("签到出错:", e); |
| | | e.printStackTrace(); |
| | | throw new SignInException(1, "服务器内部出错"); |
| | | } |
| | | |
| | |
| | | list.add(dateData); |
| | | } |
| | | int dayCount = 0; |
| | | Map<String, Integer> dayCountMap = new HashMap<>(); |
| | | //填充用户数据 |
| | | if (!StringUtil.isNullOrEmpty(uid)) { |
| | | try { |
| | | List<GoldCornRecord> recordList = goldCornManager.getRecordList(query, uid); |
| | | Map<Integer, Integer> dayCountMap = getContinueSignDayCountMap(recordList); |
| | | dayCountMap = getContinueSignDayCountMap(recordList); |
| | | dayCount = dayCountMap.size() == 6 ? 6 : dayCountMap.size() % 6; |
| | | |
| | | //设置金币与选中 |
| | | for (int i = 0; i < dayCount; i++) { |
| | | list.get(i).setGoldCorn("+" + dayCountMap.get(dayCount - i - 1)); |
| | | list.get(i).setSelected(true); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | |
| | | for (int i = 0; i < list.size(); i++) { |
| | | list.get(i).setDate(TimeUtil.getGernalTime(now - (dayCount - i - (isTodaySigned ? 1 : 0)) * 1000 * 60 * 60 * 24L, "M.d")); |
| | | |
| | | //设置金币与选中 |
| | | if (dayCountMap.get(list.get(i).getDate()) != null) { |
| | | list.get(i).setGoldCorn("+" + dayCountMap.get(list.get(i).getDate())); |
| | | list.get(i).setSelected(true); |
| | | } |
| | | |
| | | if (i == dayCount - (isTodaySigned ? 1 : 0)) { |
| | | list.get(i).setDate("今天"); |
| | | } |
| | | |
| | | } |
| | | |
| | | return list; |
| | |
| | | } |
| | | |
| | | |
| | | private Map<Integer, Integer> getContinueSignDayCountMap(List<GoldCornRecord> recordList) { |
| | | Map<Integer, Integer> map = new TreeMap<>(); |
| | | int position = 0; |
| | | private Map<String, Integer> getContinueSignDayCountMap(List<GoldCornRecord> recordList) { |
| | | Map<String, Integer> map = new TreeMap<>(); |
| | | long lastTime = TimeUtil.convertGernalTime(TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"), "yyyy-MM-dd"); |
| | | if (recordList != null) |
| | | for (int i = 0; i < recordList.size(); i++) { |
| | | String day = TimeUtil.getGernalTime(recordList.get(i).getCreateTime().getTime(), "M.d"); |
| | | long time = TimeUtil.convertGernalTime(TimeUtil.getGernalTime(recordList.get(i).getCreateTime().getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"); |
| | | if (lastTime - time == 1000 * 60 * 60 * 24L) { |
| | | position++; |
| | | lastTime = time; |
| | | map.put(position, recordList.get(i).getGoldCorn()); |
| | | map.put(day, recordList.get(i).getGoldCorn()); |
| | | } else if (lastTime - time < 1000 * 60 * 60 * 24L) { |
| | | map.put(position, recordList.get(i).getGoldCorn()); |
| | | map.put(day, recordList.get(i).getGoldCorn()); |
| | | continue; |
| | | } else { |
| | | break; |