|
@@ -8,25 +8,19 @@ import cn.qinys.platform.mobile.mapper.WishingTreeMapper;
|
|
|
import cn.qinys.platform.mobile.req.WishCreateReq;
|
|
import cn.qinys.platform.mobile.req.WishCreateReq;
|
|
|
import cn.qinys.platform.mobile.req.WishPageReq;
|
|
import cn.qinys.platform.mobile.req.WishPageReq;
|
|
|
import cn.qinys.platform.mobile.resp.WishDetailResp;
|
|
import cn.qinys.platform.mobile.resp.WishDetailResp;
|
|
|
-import cn.qinys.platform.mobile.resp.WishListResp;
|
|
|
|
|
import cn.qinys.platform.mobile.resp.WishPageResp;
|
|
import cn.qinys.platform.mobile.resp.WishPageResp;
|
|
|
import cn.qinys.platform.mobile.service.UserWishService;
|
|
import cn.qinys.platform.mobile.service.UserWishService;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
-import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
-public class UserWishServiceImpl implements UserWishService {
|
|
|
|
|
|
|
+public class UserWishServiceImpl extends AbstractUserWishService implements UserWishService {
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private UserWishMapper wishMapper;
|
|
private UserWishMapper wishMapper;
|
|
@@ -59,29 +53,26 @@ public class UserWishServiceImpl implements UserWishService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public WishDetailResp getDetail(Long id) {
|
|
|
|
|
- UserWish wish = wishMapper.selectById(id);
|
|
|
|
|
- return wish != null ? toDetailResp(wish) : null;
|
|
|
|
|
|
|
+ public WishDetailResp getDetail(Integer id) {
|
|
|
|
|
+ return wishMapper.selectWishDetail(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public WishDetailResp create(WishCreateReq req) {
|
|
|
|
|
|
|
+ public void create(WishCreateReq req) {
|
|
|
WishingTree tree = treeMapper.selectById(req.getTreeId());
|
|
WishingTree tree = treeMapper.selectById(req.getTreeId());
|
|
|
-
|
|
|
|
|
UserWish wish = new UserWish();
|
|
UserWish wish = new UserWish();
|
|
|
wish.setTreeId(req.getTreeId());
|
|
wish.setTreeId(req.getTreeId());
|
|
|
wish.setTreeName(tree != null ? tree.getName() : "");
|
|
wish.setTreeName(tree != null ? tree.getName() : "");
|
|
|
wish.setUserId(CurrentUtils.getCurrentUserId());
|
|
wish.setUserId(CurrentUtils.getCurrentUserId());
|
|
|
wish.setContent(req.getContent());
|
|
wish.setContent(req.getContent());
|
|
|
- wish.setImages(toJson(req.getImages()));
|
|
|
|
|
|
|
+ wish.setImages(JSON.toJSONString(req.getImages()));
|
|
|
wish.setLongitude(req.getLng());
|
|
wish.setLongitude(req.getLng());
|
|
|
wish.setLatitude(req.getLat());
|
|
wish.setLatitude(req.getLat());
|
|
|
wish.setAddress(req.getAddress());
|
|
wish.setAddress(req.getAddress());
|
|
|
wish.setIsPublic(req.getIsPublic() != null && req.getIsPublic() ? 1 : 0);
|
|
wish.setIsPublic(req.getIsPublic() != null && req.getIsPublic() ? 1 : 0);
|
|
|
- wish.setTags(toJson(req.getTags()));
|
|
|
|
|
-
|
|
|
|
|
|
|
+ wish.setTags(JSON.toJSONString(req.getTags()));
|
|
|
wishMapper.insert(wish);
|
|
wishMapper.insert(wish);
|
|
|
- return toDetailResp(wish);
|
|
|
|
|
|
|
+ this.treeWishesCounter(req.getTreeId(), wish.getIsPublic());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -105,43 +96,5 @@ public class UserWishServiceImpl implements UserWishService {
|
|
|
return wish.getLikes();
|
|
return wish.getLikes();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private WishDetailResp toDetailResp(UserWish wish) {
|
|
|
|
|
- WishDetailResp resp = new WishDetailResp();
|
|
|
|
|
- resp.setId(wish.getId());
|
|
|
|
|
- resp.setTreeId(wish.getTreeId());
|
|
|
|
|
- resp.setTreeName(wish.getTreeName());
|
|
|
|
|
- resp.setUserId(wish.getUserId());
|
|
|
|
|
- resp.setContent(wish.getContent());
|
|
|
|
|
- resp.setImages(parseJsonList(wish.getImages()));
|
|
|
|
|
- resp.setLng(wish.getLongitude());
|
|
|
|
|
- resp.setLat(wish.getLatitude());
|
|
|
|
|
- resp.setAddress(wish.getAddress());
|
|
|
|
|
- resp.setIsPublic(wish.getIsPublic() != null && wish.getIsPublic() == 1);
|
|
|
|
|
- resp.setTags(parseJsonList(wish.getTags()));
|
|
|
|
|
- resp.setLikes(wish.getLikes());
|
|
|
|
|
- resp.setStatus(wish.getStatus());
|
|
|
|
|
- resp.setCreatedAt(wish.getCreatedAt());
|
|
|
|
|
- return resp;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private String toJson(List<String> list) {
|
|
|
|
|
- if (list == null || list.isEmpty()) return "[]";
|
|
|
|
|
- try {
|
|
|
|
|
- return OBJECT_MAPPER.writeValueAsString(list);
|
|
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
|
|
- log.error("toJson error", e);
|
|
|
|
|
- return "[]";
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private List<String> parseJsonList(String json) {
|
|
|
|
|
- if (json == null || json.isBlank()) return new ArrayList<>();
|
|
|
|
|
- try {
|
|
|
|
|
- return OBJECT_MAPPER.readValue(json, new TypeReference<List<String>>() {
|
|
|
|
|
- });
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("parseJsonList error", e);
|
|
|
|
|
- return new ArrayList<>();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|