Commit fee6786d authored by muhong's avatar muhong

修改 小程序收藏册接口

parent 50618e8e
package com.wwdz.ch.wx.entity.vo;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.Date;
@Data
public class FavoritesResponseVo implements Entity {
private Long id;
private String title;
private String description;
private Integer sort;
private Date addTime;
private Date updateTime;
private Boolean deleted;
private String images;
private long count;
}
package com.wwdz.ch.wx.entity.vo;
import com.xxdxxs.entity.Entity;
import lombok.Data;
@Data
public class ItemResponseVo {
public class ItemResponseVo implements Entity {
private Long id;
private Long itemId;
private Integer cid;
......
......@@ -14,6 +14,7 @@ import com.wwdz.ch.db.dto.request.CoinRequestDto;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
import com.wwdz.ch.wx.entity.vo.FavoritesResponseVo;
import com.wwdz.ch.wx.entity.vo.ItemResponseVo;
import com.wwdz.ch.wx.service.FavoritesService;
import org.apache.commons.collections.CollectionUtils;
......@@ -72,6 +73,7 @@ public class FavoritesServiceImpl implements FavoritesService {
page.setTotal(0);
page.setList(new ArrayList<>());
PageInfo<Favorites> favoritesPage = favoritesDao.pageByUserId(dto.getUserId(), dto.getPage(), dto.getSize());
page.setHasNextPage(favoritesPage.isHasNextPage());
if (favoritesPage.getList().isEmpty()) {
return Result.success(page);
}
......@@ -95,7 +97,21 @@ public class FavoritesServiceImpl implements FavoritesService {
@Override
public Result list(FavoritesRequestDto dto) {
try {
return Result.success(favoritesDao.listByUserId(dto.getUserId()));
List<Favorites> list = favoritesDao.listByUserId(dto.getUserId());
List<FavoritesResponseVo> result = new ArrayList<>();
for (Favorites favorites : list) {
FavoritesResponseVo vo = new FavoritesResponseVo();
vo.setId(favorites.getId());
vo.setTitle(favorites.getTitle());
vo.setDescription(favorites.getDescription());
vo.setSort(favorites.getSort());
vo.setDeleted(favorites.getDeleted());
vo.setAddTime(favorites.getAddTime());
vo.setImages(favorites.getImages());
vo.setUpdateTime(favorites.getUpdateTime());
vo.setCount(favoritesItemsRelationDao.countByFavoritesId(favorites.getId()));
}
return Result.success(result);
} catch (Exception e) {
logger.error("获取收藏册列表失败,原因:" + e.getMessage(), e);
return Result.failed(-1, "获取收藏册列表失败");
......@@ -179,6 +195,7 @@ public class FavoritesServiceImpl implements FavoritesService {
page.setTotal(0L);
page.setList(new ArrayList<>());
PageInfo<FavoritesItemsRelation> relationPage = favoritesItemsRelationDao.pageByFavoritesId(dto.getId(), dto.getPage(), dto.getSize());
page.setHasNextPage(relationPage.isHasNextPage());
if (relationPage.getList().isEmpty()) {
return Result.success(page);
}
......
......@@ -51,6 +51,7 @@ public class ItemServiceImpl implements ItemService {
result.setPageSize(page.getPageSize());
result.setTotal(page.getTotal());
result.setList(new ArrayList<>());
result.setHasNextPage(result.isHasNextPage());
if (CollectionUtils.isEmpty(page.getList())) {
return Result.success(result);
}
......
......@@ -5,22 +5,20 @@ import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.entity.request.KlDataRequestDto;
import com.wwdz.ch.wx.service.FavoritesService;
import com.xxdxxs.support.Delete;
import com.xxdxxs.support.Select;
import com.xxdxxs.utils.JsonUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/wx/favorites")
......@@ -72,46 +70,83 @@ public class WxFavoritesController {
@ApiOperation(value = "新增")
@PostMapping("/add")
public Result add(@RequestBody FavoritesRequestDto dto) {
if (Objects.isNull(dto.getUserId())) {
public Result add(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册新增,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String title = JsonUtils.getValueByPath(json, "title");
String description = JsonUtils.getValueByPath(json, "description");
String images = JsonUtils.getValueByPath(json, "images");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(dto.getTitle())) {
if (StringUtils.isBlank(title)) {
return Result.failed("标题不能为空");
}
if (dto.getTitle().length() > 20) {
if (title.length() > 20) {
return Result.failed("标题的字数不能大于20字");
}
if (StringUtils.isNotBlank(dto.getDescription()) && dto.getDescription().length() > 200) {
if (StringUtils.isNotBlank(description) && description.length() > 200) {
return Result.failed("描述的字数不能大于200字");
}
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setUserId(Long.parseLong(userId));
dto.setTitle(title);
dto.setDescription(description);
dto.setImages(images);
return favoritesService.add(dto);
}
@ApiOperation(value = "修改")
@PostMapping("/update")
public Result update(@RequestBody FavoritesRequestDto dto) {
if (Objects.isNull(dto.getId())) {
public Result update(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册修改,请求参数,kl_data:{}", json);
String id = JsonUtils.getValueByPath(json, "id");
String userId = JsonUtils.getValueByPath(json, "userId");
String title = JsonUtils.getValueByPath(json, "title");
String description = JsonUtils.getValueByPath(json, "description");
String images = JsonUtils.getValueByPath(json, "images");
if (StringUtils.isBlank(id)) {
return Result.failed("id不能为空");
}
if (Objects.isNull(dto.getUserId())) {
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(dto.getTitle())) {
if (StringUtils.isBlank(title)) {
return Result.failed("标题不能为空");
}
if (dto.getTitle().length() > 20) {
if (title.length() > 20) {
return Result.failed("标题的字数不能大于20字");
}
if (StringUtils.isNotBlank(dto.getDescription()) && dto.getDescription().length() > 200) {
if (StringUtils.isNotBlank(description) && description.length() > 200) {
return Result.failed("描述的字数不能大于200字");
}
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setId(Long.parseLong(id));
dto.setUserId(Long.parseLong(userId));
dto.setTitle(title);
dto.setDescription(description);
dto.setImages(images);
return favoritesService.update(dto);
}
@ApiOperation(value = "详情")
@PostMapping("/info")
public Result info(@RequestBody @Validated(Select.class) FavoritesRequestDto dto) {
public Result info(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册详情查询,请求参数,kl_data:{}", json);
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("收藏册id不能为空");
}
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setId(Long.parseLong(id));
return favoritesService.info(dto);
}
......@@ -142,49 +177,87 @@ public class WxFavoritesController {
@ApiOperation(value = "单个删除")
@PostMapping("/delete")
public Result delete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
if (Objects.isNull(dto.getId())) {
return Result.failed("id不能为空");
public Result delete(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册单个删除,请求参数,kl_data:{}", json);
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("收藏册id不能为空");
}
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setId(Long.parseLong(id));
return favoritesService.delete(dto);
}
@ApiOperation(value = "批量删除")
@PostMapping("/batchDelete")
public Result batchDelete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
if (CollectionUtils.isEmpty(dto.getIds())) {
return Result.failed("请选择收藏册");
public Result batchDelete(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册批量删除,请求参数,kl_data:{}", json);
String ids = JsonUtils.getValueByPath(json, "ids");
if (StringUtils.isBlank(ids)) {
return Result.failed("收藏册id不能为空");
}
List<Long> idss = Arrays.stream(ids.substring(1, ids.length() - 1).split(","))
.map(Long::valueOf).collect(Collectors.toList());
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setIds(idss);
return favoritesService.batchDelete(dto);
}
@ApiOperation(value = "取消收藏")
@PostMapping("/removeItem")
public Result removeItem(@RequestBody ItemRequestDto dto) {
if (Objects.isNull(dto.getUserId())) {
public Result removeItem(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册取消收藏,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String favoritesId = JsonUtils.getValueByPath(json, "favoritesId");
String itemIds = JsonUtils.getValueByPath(json, "itemIds");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空");
}
if (Objects.isNull(dto.getFavoritesId())) {
return Result.failed("收藏册不能为空");
if (StringUtils.isBlank(favoritesId)) {
return Result.failed("收藏册id不能为空");
}
if (CollectionUtils.isEmpty(dto.getItemIds())) {
if (StringUtils.isBlank(itemIds)) {
return Result.failed("请选择藏品");
}
List<Long> itemIdss = Arrays.stream(itemIds.substring(1, itemIds.length() - 1).split(","))
.map(Long::valueOf).collect(Collectors.toList());
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(Long.parseLong(userId));
dto.setFavoritesId(Long.parseLong(favoritesId));
dto.setItemIds(itemIdss);
return favoritesService.removeItem(dto);
}
@ApiOperation(value = "移动藏品")
@PostMapping("/moveItem")
public Result moveItem(@RequestBody ItemRequestDto dto) {
if (Objects.isNull(dto.getBeforeFavoritesId())) {
public Result moveItem(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册移动藏品,请求参数,kl_data:{}", json);
String beforeFavoritesId = JsonUtils.getValueByPath(json, "beforeFavoritesId");
String afterFavoritesId = JsonUtils.getValueByPath(json, "afterFavoritesId");
String itemIds = JsonUtils.getValueByPath(json, "itemIds");
if (StringUtils.isBlank(beforeFavoritesId)) {
return Result.failed("原收藏册不能为空");
}
if (Objects.isNull(dto.getAfterFavoritesId())) {
if (StringUtils.isBlank(afterFavoritesId)) {
return Result.failed("现收藏册不能为空");
}
if (CollectionUtils.isEmpty(dto.getItemIds())) {
if (StringUtils.isBlank(itemIds)) {
return Result.failed("请选择藏品");
}
List<Long> itemIdss = Arrays.stream(itemIds.substring(1, itemIds.length() - 1).split(","))
.map(Long::valueOf).collect(Collectors.toList());
ItemRequestDto dto = new ItemRequestDto();
dto.setBeforeFavoritesId(Long.parseLong(beforeFavoritesId));
dto.setAfterFavoritesId(Long.parseLong(afterFavoritesId));
dto.setItemIds(itemIdss);
return favoritesService.moveItem(dto);
}
}
......@@ -27,7 +27,7 @@ public class WxItemController {
@PostMapping("/page")
public Result page(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】藏品列表分页查询,请求参数,kl_data:{}", json);
logger.info("【请求开始】藏品列表首页,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String page = JsonUtils.getValueByPath(json, "page");
String size = JsonUtils.getValueByPath(json, "size");
......@@ -56,7 +56,43 @@ public class WxItemController {
@ApiOperation(value = "新增")
@PostMapping("/add")
public Result add(@RequestBody ItemRequestDto dto) {
public Result add(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】藏品发布,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String cid = JsonUtils.getValueByPath(json, "cid");
String name = JsonUtils.getValueByPath(json, "name");
String detail = JsonUtils.getValueByPath(json, "detail");
String images = JsonUtils.getValueByPath(json, "images");
String favoritesId = JsonUtils.getValueByPath(json, "favoritesId");
String price = JsonUtils.getValueByPath(json, "price");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(cid)) {
return Result.failed("分类id不能为空");
}
if (StringUtils.isBlank(name)) {
return Result.failed("标题不能为空");
}
if (StringUtils.isBlank(price)) {
return Result.failed("价格不能为空");
}
if (StringUtils.isBlank(images)) {
return Result.failed("图片或视频不能为空");
}
if (StringUtils.isBlank(favoritesId)) {
return Result.failed("收藏册id不能为空");
}
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(Long.parseLong(userId));
dto.setName(name);
dto.setCid(Integer.parseInt(cid));
dto.setDetail(detail);
dto.setFavoritesId(Long.parseLong(favoritesId));
dto.setImages(images);
dto.setPrice(price);
return itemService.add(dto);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment