|
|
@@ -4,12 +4,14 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
import com.izouma.walkchina.constant.AppConstants;
|
|
|
+import com.izouma.walkchina.constant.Strings;
|
|
|
import com.izouma.walkchina.domain.FriendInfo;
|
|
|
import com.izouma.walkchina.domain.MonthWalkData;
|
|
|
import com.izouma.walkchina.domain.UserInfo;
|
|
|
import com.izouma.walkchina.dto.RankInfo;
|
|
|
import com.izouma.walkchina.dto.UserWalkStats;
|
|
|
import com.izouma.walkchina.event.SendJoinAwardEvent;
|
|
|
+import com.izouma.walkchina.event.SendMsgEvent;
|
|
|
import com.izouma.walkchina.event.UpdateLevelEvent;
|
|
|
import com.izouma.walkchina.event.UpdatePriceEvent;
|
|
|
import com.izouma.walkchina.exception.ServiceException;
|
|
|
@@ -27,6 +29,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@@ -71,6 +74,7 @@ public class UserInfoService {
|
|
|
.password(new BCryptPasswordEncoder().encode(password))
|
|
|
.nickname("用户" + RandomStringUtils.randomAlphabetic(6))
|
|
|
.avatar(AppConstants.DEFAULT_AVATAR)
|
|
|
+ .isNew(true)
|
|
|
.coin(BigDecimal.ZERO)
|
|
|
.active(true)
|
|
|
.authorities(Collections.singletonList(authorityRepository.findByName(AuthorityName.ROLE_USER)))
|
|
|
@@ -98,6 +102,7 @@ public class UserInfoService {
|
|
|
.coin(BigDecimal.ZERO)
|
|
|
.price(AppConstants.MIN_PRICE)
|
|
|
.active(true)
|
|
|
+ .isNew(true)
|
|
|
.sessionKey(sessionKey)
|
|
|
.authorities(Collections.singletonList(authorityRepository.findByName(AuthorityName.ROLE_USER)))
|
|
|
.build();
|
|
|
@@ -147,6 +152,7 @@ public class UserInfoService {
|
|
|
.coin(BigDecimal.ZERO)
|
|
|
.price(AppConstants.MIN_PRICE)
|
|
|
.active(true)
|
|
|
+ .isNew(true)
|
|
|
.authorities(Collections.singletonList(authorityRepository.findByName(AuthorityName.ROLE_USER)))
|
|
|
.build();
|
|
|
userInfo = userInfoRepository.save(userInfo);
|
|
|
@@ -192,12 +198,16 @@ public class UserInfoService {
|
|
|
|
|
|
private void uploadUserMarker(UserInfo userInfo) {
|
|
|
try {
|
|
|
- storageService.uploadFromInputStream(ImageUtils.getInputStream(ImageUtils.makeMarker("user", userInfo
|
|
|
- .getAvatar()), "png"), "marker/user/" + userInfo.getId() + ".png");
|
|
|
- storageService.uploadFromInputStream(ImageUtils.getInputStream(ImageUtils.makeMarker("location", userInfo
|
|
|
- .getAvatar()), "png"), "marker/location/" + userInfo.getId() + ".png");
|
|
|
+ String path = ImageUtils.makeMarker("user", userInfo.getAvatar());
|
|
|
+ storageService.uploadFromInputStream(new FileInputStream(path), "marker/user/" + userInfo.getId() + ".png");
|
|
|
} catch (Exception e) {
|
|
|
- log.error("upload marker", e);
|
|
|
+ log.error("uploadUserMarker", e);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String path = ImageUtils.makeMarker("location", userInfo.getAvatar());
|
|
|
+ storageService.uploadFromInputStream(new FileInputStream(path), "marker/location/" + userInfo.getId() + ".png");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("uploadUserMarker", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -245,11 +255,10 @@ public class UserInfoService {
|
|
|
userInfoRepository.save(userInfo);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Async
|
|
|
@EventListener
|
|
|
public void updateUserPrice(UpdatePriceEvent event) {
|
|
|
- UserInfo userInfo = (UserInfo) event.getSource();
|
|
|
+ UserInfo userInfo = userInfoRepository.findById(event.getUserId()).orElseThrow(new ServiceException("用户不存在"));
|
|
|
MonthWalkData monthWalkData = monthWalkDataRepository.findByUserId(userInfo.getId()).orElse(null);
|
|
|
BigDecimal price = BigDecimal.ZERO;
|
|
|
if (monthWalkData != null) {
|
|
|
@@ -273,13 +282,16 @@ public class UserInfoService {
|
|
|
userInfo.setPrice(price);
|
|
|
userInfoRepository.save(userInfo);
|
|
|
if (userInfo.getIsNew() != null && userInfo.getIsNew()) {
|
|
|
- applicationContext.publishEvent(new SendJoinAwardEvent(null, userInfo.getId(), price));
|
|
|
+ applicationContext.publishEvent(new SendJoinAwardEvent(this, userInfo.getId(), price));
|
|
|
+ }
|
|
|
+ if (event.getHirer() != null) {
|
|
|
+ applicationContext.publishEvent(new SendMsgEvent(this, event.getUserId(), null, String.format(Strings.MSG_HIRED, event.getHirer(), price), AppConstants.MessageType.NORMAL));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@EventListener
|
|
|
public void updateUserLevel(UpdateLevelEvent event) {
|
|
|
- UserInfo userInfo = (UserInfo) event.getSource();
|
|
|
+ UserInfo userInfo = event.getUserInfo();
|
|
|
int walkCities = Optional.ofNullable(userInfo.getWalkCities()).orElse(0);
|
|
|
int level;
|
|
|
if (walkCities < 4) {
|