|
|
@@ -5,10 +5,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
|
|
|
import com.izouma.walkchina.constant.AppConstants;
|
|
|
import com.izouma.walkchina.constant.Strings;
|
|
|
-import com.izouma.walkchina.domain.Message;
|
|
|
-import com.izouma.walkchina.domain.TeamMember;
|
|
|
-import com.izouma.walkchina.domain.UserInfo;
|
|
|
-import com.izouma.walkchina.domain.WalkData;
|
|
|
+import com.izouma.walkchina.domain.*;
|
|
|
import com.izouma.walkchina.dto.UserDTO;
|
|
|
import com.izouma.walkchina.exception.ServiceException;
|
|
|
import com.izouma.walkchina.repo.*;
|
|
|
@@ -16,6 +13,7 @@ import com.izouma.walkchina.utils.ImageUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
@@ -36,25 +34,28 @@ import static java.time.temporal.ChronoUnit.DAYS;
|
|
|
@Slf4j
|
|
|
public class TeamService {
|
|
|
@Autowired
|
|
|
- private TeamMemberRepository teamMemberRepository;
|
|
|
+ private TeamMemberRepository teamMemberRepository;
|
|
|
@Autowired
|
|
|
- private UserInfoRepository userInfoRepository;
|
|
|
+ private UserInfoRepository userInfoRepository;
|
|
|
@Autowired
|
|
|
- private MessageRepository messageRepository;
|
|
|
+ private MessageRepository messageRepository;
|
|
|
@Autowired
|
|
|
- private WalkDataRepository walkDataRepository;
|
|
|
+ private WalkDataRepository walkDataRepository;
|
|
|
@Autowired
|
|
|
- private FriendInfoRepository friendInfoRepository;
|
|
|
+ private FriendInfoService friendInfoService;
|
|
|
@Autowired
|
|
|
- private CoinService coinService;
|
|
|
+ private CoinService coinService;
|
|
|
@Autowired
|
|
|
- private WxMaService wxMaService;
|
|
|
+ private WxMaService wxMaService;
|
|
|
@Autowired
|
|
|
- private FormIdService formIdService;
|
|
|
+ private FormIdService formIdService;
|
|
|
@Autowired
|
|
|
- private UserInfoService userInfoService;
|
|
|
+ private UserInfoService userInfoService;
|
|
|
+ @Autowired
|
|
|
+ private RewardRecordRepository rewardRecordRepository;
|
|
|
|
|
|
public void hire(Long userId, Long target) {
|
|
|
+ friendInfoService.saveFriend(userId, target);
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
|
|
|
UserInfo targetUserInfo = userInfoRepository.findById(target).orElseThrow(new ServiceException("用户不存在"));
|
|
|
@@ -81,7 +82,7 @@ public class TeamService {
|
|
|
messageRepository.save(grabMsg);
|
|
|
}
|
|
|
|
|
|
- BigDecimal price = Optional.ofNullable(userInfo.getPrice()).orElse(AppConstants.MIN_PRICE);
|
|
|
+ BigDecimal price = Optional.ofNullable(targetUserInfo.getPrice()).orElse(AppConstants.MIN_PRICE);
|
|
|
BigDecimal balance = Optional.ofNullable(userInfo.getCoin()).orElse(BigDecimal.ZERO);
|
|
|
if (balance.compareTo(price) < 0) {
|
|
|
throw new ServiceException("雇佣失败,商城币不足");
|
|
|
@@ -103,6 +104,15 @@ public class TeamService {
|
|
|
teamMemberRepository.save(newTeamMember);
|
|
|
|
|
|
userInfoService.updateUserPrice(targetUserInfo);
|
|
|
+
|
|
|
+ Message grabMsg = Message.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .type(AppConstants.MessageType.NORMAL)
|
|
|
+ .content(String.format(Strings.MSG_HIRE, price, targetUserInfo.getNickname()))
|
|
|
+ .active(true)
|
|
|
+ .isRead(false)
|
|
|
+ .build();
|
|
|
+ messageRepository.save(grabMsg);
|
|
|
}
|
|
|
|
|
|
public boolean canHire(Long userId, Long target) {
|
|
|
@@ -116,7 +126,7 @@ public class TeamService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public List<UserDTO> userTeam(Long userId) {
|
|
|
+ public List<UserDTO> userTeam(Long userId, boolean queryReward) {
|
|
|
List<UserDTO> list = teamMemberRepository.findUserTeam(userId);
|
|
|
for (UserDTO userDTO : list) {
|
|
|
WalkData walkData = walkDataRepository.findByUserIdAndDate(userDTO.getUserId(), LocalDate.now());
|
|
|
@@ -126,13 +136,21 @@ public class TeamService {
|
|
|
userDTO.setTodaySteps(0L);
|
|
|
userDTO.setShouldWake(true);
|
|
|
}
|
|
|
+ if (queryReward) {
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ RewardRecord rewardRecord = new RewardRecord();
|
|
|
+ rewardRecord.setUserId(userId);
|
|
|
+ rewardRecord.setTargetUserId(userDTO.getUserId());
|
|
|
+ rewardRecord.setDate(now);
|
|
|
+ userDTO.setCanReward(rewardRecordRepository.findAll(Example.of(rewardRecord)).size() == 0);
|
|
|
+ }
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public List<UserDTO> userFriend(Long userId) {
|
|
|
LocalDate now = LocalDate.now();
|
|
|
- List<UserDTO> list = friendInfoRepository.findUserFriend(userId);
|
|
|
+ List<UserDTO> list = friendInfoService.findUserFriend(userId);
|
|
|
for (UserDTO userDTO : list) {
|
|
|
WalkData walkData = walkDataRepository.findByUserIdAndDate(userDTO.getUserId(), now);
|
|
|
if (walkData != null) {
|
|
|
@@ -190,7 +208,7 @@ public class TeamService {
|
|
|
ImageUtils.drawCenteredString(g, userInfo.getNickname(), new Rectangle(0, 230 * 3, shareImg.getWidth(), 20 * 3), nicknameFont);
|
|
|
|
|
|
Font walkDataFont = pingFangMedium.deriveFont(17f * 3);
|
|
|
- ImageUtils.drawCenteredString(g, DAYS.between(userInfo.getCreatedAt(), LocalDateTime.now()) + 1 + "", new Rectangle(20 * 3, 295 * 3, 295 * 3 / 2, 24 * 3), walkDataFont);
|
|
|
+ ImageUtils.drawCenteredString(g, DAYS.between(userInfo.getCreatedAt().toLocalDate(), LocalDate.now()) + 1 + "", new Rectangle(20 * 3, 295 * 3, 295 * 3 / 2, 24 * 3), walkDataFont);
|
|
|
ImageUtils.drawCenteredString(g, String.valueOf(userInfo.getWalkCities()), new Rectangle(295 * 3 / 2 + 20 * 3, 295 * 3, 295 * 3 / 2, 24 * 3), walkDataFont);
|
|
|
ImageUtils.drawCenteredString(g, String.valueOf(userInfo.getTotalSteps()), new Rectangle(20 * 3, 353 * 3, 295 * 3 / 2, 24 * 3), walkDataFont);
|
|
|
ImageUtils.drawCenteredString(g, coinService.totalAward(userId).toString(), new Rectangle(295 * 3 / 2 + 20 * 3, 353 * 3, 295 * 3 / 2, 24 * 3), walkDataFont);
|
|
|
@@ -257,5 +275,13 @@ public class TeamService {
|
|
|
teamMemberRepository.save(newTeamMember);
|
|
|
|
|
|
userInfoService.updateUserPrice(targetUserInfo);
|
|
|
+
|
|
|
+ messageRepository.save(Message.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .content(String.format(Strings.MSG_RECRUIT, targetUserInfo.getNickname()))
|
|
|
+ .type(AppConstants.MessageType.NORMAL)
|
|
|
+ .active(true)
|
|
|
+ .isRead(false)
|
|
|
+ .build());
|
|
|
}
|
|
|
}
|