Commit 18ea215a authored by muhong's avatar muhong

修改 小程序去除kl_data

parent 776c8d18
...@@ -261,7 +261,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -261,7 +261,7 @@ public class FavoritesServiceImpl implements FavoritesService {
// 设置是否收藏或是否是自己发布的 // 设置是否收藏或是否是自己发布的
vo.setIsCollected(0); vo.setIsCollected(0);
vo.setIsMine(0); vo.setIsMine(0);
if (dto.getUserId() != 0L) { if (Objects.nonNull(dto.getUserId()) && dto.getUserId() != 0L) {
vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), relation.getItemId()) ? 1 : 0); vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), relation.getItemId()) ? 1 : 0);
vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0); vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
} }
......
...@@ -37,7 +37,6 @@ import java.io.ByteArrayInputStream; ...@@ -37,7 +37,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.System;
import java.net.URL; import java.net.URL;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -70,27 +69,25 @@ public class ItemServiceImpl implements ItemService { ...@@ -70,27 +69,25 @@ public class ItemServiceImpl implements ItemService {
public Result nameList(ItemRequestDto dto) { public Result nameList(ItemRequestDto dto) {
try { try {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
if (StringUtils.isNotBlank(dto.getName())) { EsSearchRequestDto esSearchRequestDto = new EsSearchRequestDto();
EsSearchRequestDto esSearchRequestDto = new EsSearchRequestDto(); esSearchRequestDto.setContent(dto.getName());
esSearchRequestDto.setContent(dto.getName()); esSearchRequestDto.setSize(16);
esSearchRequestDto.setSize(16); List<ItemOfEs> list = itemEsDao.getCuewords(esSearchRequestDto);
List<ItemOfEs> list = itemEsDao.getCuewords(esSearchRequestDto); if (CollectionUtils.isNotEmpty(list)) {
if (CollectionUtils.isNotEmpty(list)) { names = list.stream()
names = list.stream() .map(ItemOfEs::getName).collect(Collectors.toList());
.map(ItemOfEs::getName).collect(Collectors.toList()); for (String name : names) {
for (String name : names) { // 处理特殊字符
// 处理特殊字符 name = name.replaceAll("\\s*|\r|\n|\t", "");
name = name.replaceAll("\\s*|\r|\n|\t", ""); name = name.replaceAll("/P", "");
name = name.replaceAll("/P", ""); name = name.replaceAll(",", "");
name = name.replaceAll(",", ""); // 超过15个字的15个字符
// 超过15个字的15个字符 if (name.length() > 15) {
if (name.length() > 15) { int index = name.indexOf(dto.getName());
int index = name.indexOf(dto.getName()); if (index + dto.getName().length() > 15) {
if (index + dto.getName().length() > 15) { name = name.substring(index + dto.getName().length() - 15, index + dto.getName().length());
name = name.substring(index + dto.getName().length() - 15, index + dto.getName().length()); } else {
} else { name = name.substring(0, 15);
name = name.substring(0, 15);
}
} }
} }
} }
...@@ -141,7 +138,7 @@ public class ItemServiceImpl implements ItemService { ...@@ -141,7 +138,7 @@ public class ItemServiceImpl implements ItemService {
// 设置是否收藏和是否是自己发布的 // 设置是否收藏和是否是自己发布的
vo.setIsCollected(0); vo.setIsCollected(0);
vo.setIsMine(0); vo.setIsMine(0);
if (!dto.getUserId().equals(0L)) { if (Objects.nonNull(dto.getUserId()) && !dto.getUserId().equals(0L)) {
vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), es.getId()) ? 1 : 0); vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), es.getId()) ? 1 : 0);
vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), es.getId()) ? 1 : 0); vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), es.getId()) ? 1 : 0);
} }
...@@ -223,7 +220,8 @@ public class ItemServiceImpl implements ItemService { ...@@ -223,7 +220,8 @@ public class ItemServiceImpl implements ItemService {
try { try {
Item item = itemDao.findById(dto.getId()); Item item = itemDao.findById(dto.getId());
if (Objects.isNull(item)) { if (Objects.isNull(item)) {
if (!dto.getUserId().equals(0L)) { //TODO 足迹如果删除如何处理
if (Objects.nonNull(dto.getUserId()) && !dto.getUserId().equals(0L)) {
// 如果当前用户已收藏该藏品,则删除收藏关联 // 如果当前用户已收藏该藏品,则删除收藏关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId()); favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
} }
...@@ -263,7 +261,7 @@ public class ItemServiceImpl implements ItemService { ...@@ -263,7 +261,7 @@ public class ItemServiceImpl implements ItemService {
// 设置是否收藏或是否是自己发布的 // 设置是否收藏或是否是自己发布的
itemResponseVo.setIsCollected(0); itemResponseVo.setIsCollected(0);
itemResponseVo.setIsMine(0); itemResponseVo.setIsMine(0);
if (!dto.getUserId().equals(0L)) { if (Objects.nonNull(dto.getUserId()) && !dto.getUserId().equals(0L)) {
FavoritesItemsRelation favoritesItemsRelation = favoritesItemsRelationDao.selectByUserIdItemId(dto.getUserId(), item.getId()); FavoritesItemsRelation favoritesItemsRelation = favoritesItemsRelationDao.selectByUserIdItemId(dto.getUserId(), item.getId());
if (Objects.nonNull(favoritesItemsRelation)) { if (Objects.nonNull(favoritesItemsRelation)) {
itemResponseVo.setIsCollected(1); itemResponseVo.setIsCollected(1);
...@@ -311,7 +309,7 @@ public class ItemServiceImpl implements ItemService { ...@@ -311,7 +309,7 @@ public class ItemServiceImpl implements ItemService {
@Override @Override
public Result collect(ItemRequestDto dto) { public Result collect(ItemRequestDto dto) {
try { try {
if (dto.getUserId().equals(0L)) { if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
return Result.failed("您尚未登录,请先登录"); return Result.failed("您尚未登录,请先登录");
} }
Item item = itemDao.findById(dto.getId()); Item item = itemDao.findById(dto.getId());
...@@ -353,7 +351,7 @@ public class ItemServiceImpl implements ItemService { ...@@ -353,7 +351,7 @@ public class ItemServiceImpl implements ItemService {
@Override @Override
public Result cancel(ItemRequestDto dto) { public Result cancel(ItemRequestDto dto) {
try { try {
if (dto.getUserId().equals(0L)) { if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
return Result.failed("您尚未登录,请先登录"); return Result.failed("您尚未登录,请先登录");
} }
Item item = itemDao.findById(dto.getId()); Item item = itemDao.findById(dto.getId());
......
package com.wwdz.ch.wx.web; package com.wwdz.ch.wx.web;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.entity.request.CategoryRequestDto; import com.wwdz.ch.wx.entity.request.CategoryRequestDto;
import com.wwdz.ch.wx.entity.request.KlDataRequestDto;
import com.wwdz.ch.wx.service.CategoryService; import com.wwdz.ch.wx.service.CategoryService;
import com.xxdxxs.utils.JsonUtils;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -15,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -15,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
@RestController @RestController
@RequestMapping("/wx/category") @RequestMapping("/wx/category")
public class WxCategoryController { public class WxCategoryController {
...@@ -25,41 +25,27 @@ public class WxCategoryController { ...@@ -25,41 +25,27 @@ public class WxCategoryController {
@ApiOperation(value = "分类分页") @ApiOperation(value = "分类分页")
@PostMapping(value = "/top") @PostMapping(value = "/top")
public Result top(@RequestBody KlDataRequestDto klDataRequestDto) { public Result top(@RequestBody CategoryRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】查询分类列表,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】查询分类列表,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getLevel())) {
String level = JsonUtils.getValueByPath(json, "level");
String page = JsonUtils.getValueByPath(json, "page");
String size = JsonUtils.getValueByPath(json, "size");
if (StringUtils.isBlank(level)) {
return Result.failed("分类级别不能为空"); return Result.failed("分类级别不能为空");
} }
if (StringUtils.isBlank(page)) { if (Objects.isNull(dto.getPage())) {
return Result.failed("当前页不能为空"); return Result.failed("当前页不能为空");
} }
if (StringUtils.isBlank(size)) { if (Objects.isNull(dto.getSize())) {
return Result.failed("页面大小不能为空"); return Result.failed("页面大小不能为空");
} }
CategoryRequestDto dto = new CategoryRequestDto();
dto.setLevel(Integer.parseInt(level));
dto.setPage(Integer.parseInt(page));
dto.setSize(Integer.parseInt(size));
return categoryService.top(dto); return categoryService.top(dto);
} }
@ApiOperation(value = "子分类") @ApiOperation(value = "子分类")
@PostMapping(value = "/child") @PostMapping(value = "/child")
public Result child(@RequestBody KlDataRequestDto klDataRequestDto) { public Result child(@RequestBody CategoryRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】查询子分类列表,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】查询子分类列表,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("分类id不能为空"); return Result.failed("分类id不能为空");
} }
CategoryRequestDto dto = new CategoryRequestDto();
dto.setId(Integer.parseInt(id));
return categoryService.child(dto); return categoryService.child(dto);
} }
......
package com.wwdz.ch.wx.web; package com.wwdz.ch.wx.web;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.FavoritesRequestDto; import com.wwdz.ch.db.dto.request.FavoritesRequestDto;
import com.wwdz.ch.wx.entity.request.ItemRequestDto; 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.wwdz.ch.wx.service.FavoritesService;
import com.xxdxxs.utils.JsonUtils;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -16,9 +16,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -16,9 +16,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays; import java.util.Objects;
import java.util.List;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/wx/favorites") @RequestMapping("/wx/favorites")
...@@ -30,255 +28,159 @@ public class WxFavoritesController { ...@@ -30,255 +28,159 @@ public class WxFavoritesController {
@ApiOperation(value = "分页查询") @ApiOperation(value = "分页查询")
@PostMapping("/page") @PostMapping("/page")
public Result page(@RequestBody KlDataRequestDto klDataRequestDto) { public Result page(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册分页查询,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册分页查询,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
String userId = JsonUtils.getValueByPath(json, "userId");
String page = JsonUtils.getValueByPath(json, "page");
String size = JsonUtils.getValueByPath(json, "size");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空"); return Result.failed("用户id不能为空");
} }
if (StringUtils.isBlank(page)) { if (Objects.isNull(dto.getPage())) {
return Result.failed("当前页不能为空"); return Result.failed("当前页不能为空");
} }
if (StringUtils.isBlank(size)) { if (Objects.isNull(dto.getSize())) {
return Result.failed("页面大小不能为空"); return Result.failed("页面大小不能为空");
} }
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setUserId(Long.parseLong(userId));
dto.setPage(Integer.parseInt(page));
dto.setSize(Integer.parseInt(size));
return favoritesService.page(dto); return favoritesService.page(dto);
} }
@ApiOperation(value = "列表查询") @ApiOperation(value = "列表查询")
@PostMapping("/list") @PostMapping("/list")
public Result list(@RequestBody KlDataRequestDto klDataRequestDto) { public Result list(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册分页查询,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册分页查询,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
String userId = JsonUtils.getValueByPath(json, "userId");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空"); return Result.failed("用户id不能为空");
} }
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setUserId(Long.parseLong(userId));
return favoritesService.list(dto); return favoritesService.list(dto);
} }
@ApiOperation(value = "新增") @ApiOperation(value = "新增")
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody KlDataRequestDto klDataRequestDto) { public Result add(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册新增,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册新增,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
String userId = JsonUtils.getValueByPath(json, "userId");
String title = JsonUtils.getValueByPath(json, "title");
String description = JsonUtils.getValueByPath(json, "description");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空"); return Result.failed("用户id不能为空");
} }
if (StringUtils.isBlank(title)) { if (StringUtils.isBlank(dto.getTitle())) {
return Result.failed("标题不能为空"); return Result.failed("标题不能为空");
} }
if (title.length() > 20) { if (dto.getTitle().length() > 20) {
return Result.failed("标题的字数不能大于20字"); return Result.failed("标题的字数不能大于20字");
} }
if (StringUtils.isNotBlank(description) && description.length() > 200) { if (StringUtils.isNotBlank(dto.getDescription()) && dto.getDescription().length() > 200) {
return Result.failed("描述的字数不能大于200字"); return Result.failed("描述的字数不能大于200字");
} }
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setUserId(Long.parseLong(userId));
dto.setTitle(title);
dto.setDescription(description);
return favoritesService.add(dto); return favoritesService.add(dto);
} }
@ApiOperation(value = "修改") @ApiOperation(value = "修改")
@PostMapping("/update") @PostMapping("/update")
public Result update(@RequestBody KlDataRequestDto klDataRequestDto) { public Result update(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册修改,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册修改,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String id = JsonUtils.getValueByPath(json, "id");
String userId = JsonUtils.getValueByPath(json, "userId");
String title = JsonUtils.getValueByPath(json, "title");
String description = JsonUtils.getValueByPath(json, "description");
if (StringUtils.isBlank(id)) {
return Result.failed("id不能为空"); return Result.failed("id不能为空");
} }
if (StringUtils.isBlank(userId)) { if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
return Result.failed("用户id不能为空"); return Result.failed("用户id不能为空");
} }
if (StringUtils.isBlank(title)) { if (StringUtils.isBlank(dto.getTitle())) {
return Result.failed("标题不能为空"); return Result.failed("标题不能为空");
} }
if (title.length() > 20) { if (dto.getTitle().length() > 20) {
return Result.failed("标题的字数不能大于20字"); return Result.failed("标题的字数不能大于20字");
} }
if (StringUtils.isNotBlank(description) && description.length() > 200) { if (StringUtils.isNotBlank(dto.getDescription()) && dto.getDescription().length() > 200) {
return Result.failed("描述的字数不能大于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);
return favoritesService.update(dto); return favoritesService.update(dto);
} }
@ApiOperation(value = "详情") @ApiOperation(value = "详情")
@PostMapping("/info") @PostMapping("/info")
public Result info(@RequestBody KlDataRequestDto klDataRequestDto) { public Result info(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册详情查询,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册详情查询,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("收藏册id不能为空"); return Result.failed("收藏册id不能为空");
} }
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setId(Long.parseLong(id));
return favoritesService.info(dto); return favoritesService.info(dto);
} }
@ApiOperation(value = "收藏册下藏品列表") @ApiOperation(value = "收藏册下藏品列表")
@PostMapping("/itemList") @PostMapping("/itemList")
public Result itemList(@RequestBody KlDataRequestDto klDataRequestDto) { public Result itemList(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册下藏品列表分页查询,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册下藏品列表分页查询,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String id = JsonUtils.getValueByPath(json, "id");
String userId = JsonUtils.getValueByPath(json, "userId");
String page = JsonUtils.getValueByPath(json, "page");
String size = JsonUtils.getValueByPath(json, "size");
if (StringUtils.isBlank(id)) {
return Result.failed("收藏册id不能为空"); return Result.failed("收藏册id不能为空");
} }
if (StringUtils.isBlank(page)) { if (Objects.isNull(dto.getPage())) {
return Result.failed("当前页不能为空"); return Result.failed("当前页不能为空");
} }
if (StringUtils.isBlank(size)) { if (Objects.isNull(dto.getSize())) {
return Result.failed("页面大小不能为空"); return Result.failed("页面大小不能为空");
} }
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setId(Long.parseLong(id));
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId));
}
dto.setPage(Integer.parseInt(page));
dto.setSize(Integer.parseInt(size));
return favoritesService.itemList(dto); return favoritesService.itemList(dto);
} }
@ApiOperation(value = "单个删除") @ApiOperation(value = "单个删除")
@PostMapping("/delete") @PostMapping("/delete")
public Result delete(@RequestBody KlDataRequestDto klDataRequestDto) { public Result delete(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册单个删除,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册单个删除,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("收藏册id不能为空"); return Result.failed("收藏册id不能为空");
} }
FavoritesRequestDto dto = new FavoritesRequestDto();
dto.setId(Long.parseLong(id));
return favoritesService.delete(dto); return favoritesService.delete(dto);
} }
@ApiOperation(value = "批量删除") @ApiOperation(value = "批量删除")
@PostMapping("/batchDelete") @PostMapping("/batchDelete")
public Result batchDelete(@RequestBody KlDataRequestDto klDataRequestDto) { public Result batchDelete(@RequestBody FavoritesRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册批量删除,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册批量删除,请求参数,kl_data:{}", json); if (CollectionUtils.isEmpty(dto.getIds())) {
String ids = JsonUtils.getValueByPath(json, "ids");
if (StringUtils.isBlank(ids)) {
return Result.failed("收藏册id不能为空"); 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); return favoritesService.batchDelete(dto);
} }
@ApiOperation(value = "收藏") @ApiOperation(value = "收藏")
@PostMapping("/addItem") @PostMapping("/addItem")
public Result addItem(@RequestBody KlDataRequestDto klDataRequestDto) { public Result addItem(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册收藏,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册收藏,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getFavoritesId())) {
String favoritesId = JsonUtils.getValueByPath(json, "favoritesId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(favoritesId)) {
return Result.failed("收藏册id不能为空"); return Result.failed("收藏册id不能为空");
} }
if (StringUtils.isBlank(id)) { if (Objects.isNull(dto.getId())) {
return Result.failed("请选择藏品"); return Result.failed("请选择藏品");
} }
ItemRequestDto dto = new ItemRequestDto();
dto.setFavoritesId(Long.parseLong(favoritesId));
dto.setId(Long.parseLong(id));
return favoritesService.addItem(dto); return favoritesService.addItem(dto);
} }
@ApiOperation(value = "取消收藏") @ApiOperation(value = "取消收藏")
@PostMapping("/removeItem") @PostMapping("/removeItem")
public Result removeItem(@RequestBody KlDataRequestDto klDataRequestDto) { public Result removeItem(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册取消收藏,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册取消收藏,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
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不能为空"); return Result.failed("用户id不能为空");
} }
if (StringUtils.isBlank(favoritesId)) { if (Objects.isNull(dto.getFavoritesId())) {
return Result.failed("收藏册id不能为空"); return Result.failed("收藏册id不能为空");
} }
if (StringUtils.isBlank(itemIds)) { if (CollectionUtils.isEmpty(dto.getItemIds())) {
return Result.failed("请选择藏品"); 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); return favoritesService.removeItem(dto);
} }
@ApiOperation(value = "移动藏品") @ApiOperation(value = "移动藏品")
@PostMapping("/moveItem") @PostMapping("/moveItem")
public Result moveItem(@RequestBody KlDataRequestDto klDataRequestDto) { public Result moveItem(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】收藏册移动藏品,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】收藏册移动藏品,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getBeforeFavoritesId())) {
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("原收藏册不能为空"); return Result.failed("原收藏册不能为空");
} }
if (StringUtils.isBlank(afterFavoritesId)) { if (Objects.isNull(dto.getAfterFavoritesId())) {
return Result.failed("现收藏册不能为空"); return Result.failed("现收藏册不能为空");
} }
if (StringUtils.isBlank(itemIds)) { if (CollectionUtils.isEmpty(dto.getItemIds())) {
return Result.failed("请选择藏品"); 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); return favoritesService.moveItem(dto);
} }
} }
package com.wwdz.ch.wx.web; package com.wwdz.ch.wx.web;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.entity.request.ItemRequestDto; import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.entity.request.KlDataRequestDto;
import com.wwdz.ch.wx.service.ItemService; import com.wwdz.ch.wx.service.ItemService;
import com.wwdz.ch.wx.service.WxLoginService; import com.wwdz.ch.wx.service.WxLoginService;
import com.xxdxxs.utils.JsonUtils;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -32,43 +31,24 @@ public class WxItemController { ...@@ -32,43 +31,24 @@ public class WxItemController {
@ApiOperation(value = "藏品名称联想") @ApiOperation(value = "藏品名称联想")
@PostMapping("/findNames") @PostMapping("/findNames")
public Result findNames(@RequestBody KlDataRequestDto klDataRequestDto) { public Result findNames(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】藏品名称联想,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】藏品名称联想,请求参数,kl_data:{}", json); if (StringUtils.isBlank(dto.getName())) {
String name = JsonUtils.getValueByPath(json, "name");
if (StringUtils.isBlank(name)) {
return Result.success(new ArrayList<>()); return Result.success(new ArrayList<>());
} }
ItemRequestDto dto = new ItemRequestDto();
dto.setName(name);
return itemService.nameList(dto); return itemService.nameList(dto);
} }
@ApiOperation(value = "分页查询") @ApiOperation(value = "分页查询")
@PostMapping("/page") @PostMapping("/page")
public Result page(@RequestBody KlDataRequestDto klDataRequestDto) { public Result page(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】藏品列表首页,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】藏品列表首页,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getPage())) {
String userId = JsonUtils.getValueByPath(json, "userId");
String name = JsonUtils.getValueByPath(json, "name");
String page = JsonUtils.getValueByPath(json, "page");
String size = JsonUtils.getValueByPath(json, "size");
if (StringUtils.isBlank(page)) {
return Result.failed("当前页不能为空"); return Result.failed("当前页不能为空");
} }
if (StringUtils.isBlank(size)) { if (Objects.isNull(dto.getSize())) {
return Result.failed("页面大小不能为空"); return Result.failed("页面大小不能为空");
} }
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId));
}
dto.setPage(Integer.parseInt(page));
dto.setSize(Integer.parseInt(size));
dto.setName(name);
return itemService.page(dto); return itemService.page(dto);
} }
...@@ -80,154 +60,82 @@ public class WxItemController { ...@@ -80,154 +60,82 @@ public class WxItemController {
@ApiOperation(value = "新增") @ApiOperation(value = "新增")
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody KlDataRequestDto klDataRequestDto) { public Result add(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】藏品发布,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】藏品发布,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
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 videos = JsonUtils.getValueByPath(json, "videos");
String favoritesId = JsonUtils.getValueByPath(json, "favoritesId");
String price = JsonUtils.getValueByPath(json, "price");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空"); return Result.failed("用户id不能为空");
} }
if (StringUtils.isBlank(cid)) { if (Objects.isNull(dto.getCid())) {
return Result.failed("分类id不能为空"); return Result.failed("分类id不能为空");
} }
if (StringUtils.isBlank(name)) { if (StringUtils.isBlank(dto.getName())) {
return Result.failed("标题不能为空"); return Result.failed("标题不能为空");
} }
if (StringUtils.isBlank(images)) { if (StringUtils.isBlank(dto.getImages())) {
return Result.failed("请至少上传一张图片"); return Result.failed("请至少上传一张图片");
} }
if (StringUtils.isBlank(favoritesId)) { if (Objects.isNull(dto.getFavoritesId())) {
return Result.failed("收藏册id不能为空"); return Result.failed("收藏册id不能为空");
} }
dto.setPrice(StringUtils.isBlank(dto.getPrice()) ? "0" : dto.getPrice());
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.setVideos(videos);
if (StringUtils.isBlank(price)) {
price = "0";
}
dto.setPrice(price);
return itemService.add(dto); return itemService.add(dto);
} }
@ApiOperation(value = "修改") @ApiOperation(value = "修改")
@PostMapping("/update") @PostMapping("/update")
public Result update(@RequestBody KlDataRequestDto klDataRequestDto) { public Result update(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】藏品发布,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】藏品发布,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String id = JsonUtils.getValueByPath(json, "id");
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 videos = JsonUtils.getValueByPath(json, "videos");
String favoritesId = JsonUtils.getValueByPath(json, "favoritesId");
String price = JsonUtils.getValueByPath(json, "price");
if (StringUtils.isBlank(id)) {
return Result.failed("id不能为空"); return Result.failed("id不能为空");
} }
if (StringUtils.isBlank(userId)) { if (Objects.isNull(dto.getUserId()) || dto.getUserId().equals(0L)) {
return Result.failed("用户id不能为空"); return Result.failed("用户id不能为空");
} }
if (StringUtils.isBlank(cid)) { if (Objects.isNull(dto.getCid())) {
return Result.failed("分类id不能为空"); return Result.failed("分类id不能为空");
} }
if (StringUtils.isBlank(name)) { if (StringUtils.isBlank(dto.getName())) {
return Result.failed("标题不能为空"); return Result.failed("标题不能为空");
} }
if (StringUtils.isBlank(images)) { if (StringUtils.isBlank(dto.getImages())) {
return Result.failed("请至少上传一张图片"); return Result.failed("请至少上传一张图片");
} }
if (StringUtils.isBlank(favoritesId)) { if (Objects.isNull(dto.getFavoritesId())) {
return Result.failed("收藏册id不能为空"); return Result.failed("收藏册id不能为空");
} }
dto.setDetail(StringUtils.isBlank(dto.getDetail()) ? "" : dto.getDetail());
ItemRequestDto dto = new ItemRequestDto(); dto.setVideos(StringUtils.isBlank(dto.getVideos()) ? "" : dto.getVideos());
dto.setId(Long.parseLong(id)); dto.setPrice(StringUtils.isBlank(dto.getPrice()) ? "0" : dto.getPrice());
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.setVideos(videos);
if (StringUtils.isBlank(price)) {
price = "0";
}
dto.setPrice(price);
return itemService.update(dto); return itemService.update(dto);
} }
@ApiOperation(value = "详情") @ApiOperation(value = "详情")
@PostMapping("/info") @PostMapping("/info")
public Result info(@RequestBody KlDataRequestDto klDataRequestDto) { public Result info(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】藏品详情查询,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】藏品详情查询,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("藏品id不能为空"); return Result.failed("藏品id不能为空");
} }
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId));
}
dto.setId(Long.parseLong(id));
return itemService.info(dto); return itemService.info(dto);
} }
@ApiOperation(value = "收藏") @ApiOperation(value = "收藏")
@PostMapping("/collect") @PostMapping("/collect")
public Result collect(@RequestBody KlDataRequestDto klDataRequestDto) { public Result collect(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】首页收藏,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】首页收藏,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("藏品id不能为空"); return Result.failed("藏品id不能为空");
} }
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId));
}
dto.setId(Long.parseLong(id));
return itemService.collect(dto); return itemService.collect(dto);
} }
@ApiOperation(value = "取消收藏") @ApiOperation(value = "取消收藏")
@PostMapping("/cancel") @PostMapping("/cancel")
public Result cancel(@RequestBody KlDataRequestDto klDataRequestDto) { public Result cancel(@RequestBody ItemRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】首页取消收藏,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】首页取消收藏,请求参数,kl_data:{}", json); if (Objects.isNull(dto.getId())) {
String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("藏品id不能为空"); return Result.failed("藏品id不能为空");
} }
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId));
}
dto.setId(Long.parseLong(id));
return itemService.cancel(dto); return itemService.cancel(dto);
} }
......
...@@ -4,10 +4,8 @@ package com.wwdz.ch.wx.web; ...@@ -4,10 +4,8 @@ package com.wwdz.ch.wx.web;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.constant.CacheCodeConstants; import com.wwdz.ch.wx.constant.CacheCodeConstants;
import com.wwdz.ch.wx.entity.request.KlDataRequestDto;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.wx.entity.request.UserRequestDto;
import com.wwdz.ch.wx.service.UserService; import com.wwdz.ch.wx.service.UserService;
import com.xxdxxs.utils.JsonUtils;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -36,64 +34,43 @@ public class WxUserController { ...@@ -36,64 +34,43 @@ public class WxUserController {
@ApiOperation(value = "微信登录") @ApiOperation(value = "微信登录")
@PostMapping("/loginByWx") @PostMapping("/loginByWx")
public Result loginByWx(@RequestBody KlDataRequestDto klDataRequestDto, HttpServletRequest request) { public Result loginByWx(@RequestBody UserRequestDto dto, HttpServletRequest request) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】微信登录,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】微信登录,请求参数,kl_data:{}", json); if (StringUtils.isBlank(dto.getCode())) {
String code = JsonUtils.getValueByPath(json, "code");
if (StringUtils.isBlank(code)) {
return Result.failed("授权码不能为空"); return Result.failed("授权码不能为空");
} }
if (!json.contains("type")) { if (Objects.isNull(dto.getType())) {
return Result.failed("版本类型不能为空"); return Result.failed("版本类型不能为空");
} }
Integer type = Integer.parseInt(JsonUtils.getValueByPath(json, "type")); if (dto.getType() == 2) {
if (StringUtils.isBlank(dto.getEncryptedData()) || StringUtils.isBlank(dto.getIv())) {
UserRequestDto dto = new UserRequestDto();
dto.setCode(code);
dto.setType(type);
if (type == 2) {
if (!json.contains("encryptedData") || !json.contains("iv")) {
return Result.failed("encryptedData或iv不能为空"); return Result.failed("encryptedData或iv不能为空");
} }
dto.setEncryptedData(JsonUtils.getValueByPath(json, "encryptedData"));
dto.setIv(JsonUtils.getValueByPath(json, "iv"));
} }
return userService.loginByWx(dto, request); return userService.loginByWx(dto, request);
} }
@ApiOperation(value = "登录手机验证码") @ApiOperation(value = "登录手机验证码")
@PostMapping("/loginRegCaptcha") @PostMapping("/loginRegCaptcha")
public Object registerCaptcha(@RequestBody KlDataRequestDto klDataRequestDto) { public Object registerCaptcha(@RequestBody UserRequestDto dto) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】请求登录手机验证码,请求参数:{}", JSON.toJSONString(dto));
logger.info("【请求开始】请求登录手机验证码,请求参数,kl_data:{}", json); if (StringUtils.isBlank(dto.getMobile())) {
String mobile = JsonUtils.getValueByPath(json, "mobile");
if (StringUtils.isBlank(mobile)) {
return Result.failed("手机号不能为空"); return Result.failed("手机号不能为空");
} }
UserRequestDto dto = new UserRequestDto();
dto.setMobile(mobile);
dto.setSmsType(CacheCodeConstants.SmsTypeEnum.LOGIN.getCode()); dto.setSmsType(CacheCodeConstants.SmsTypeEnum.LOGIN.getCode());
return userService.regCaptcha(dto); return userService.regCaptcha(dto);
} }
@ApiOperation(value = "手机验证码登录") @ApiOperation(value = "手机验证码登录")
@PostMapping("/loginByMobile") @PostMapping("/loginByMobile")
public Result loginByMobile(@RequestBody KlDataRequestDto klDataRequestDto, HttpServletRequest request) { public Result loginByMobile(@RequestBody UserRequestDto dto, HttpServletRequest request) {
String json = klDataRequestDto.getKl_data(); logger.info("【请求开始】手机号登录,请求参数,kl_data:{}", JSON.toJSONString(dto));
logger.info("【请求开始】手机号登录,请求参数,kl_data:{}", json); if (StringUtils.isBlank(dto.getMobile())) {
String mobile = JsonUtils.getValueByPath(json, "mobile");
String smsCode = JsonUtils.getValueByPath(json, "smsCode");
if (StringUtils.isBlank(mobile)) {
return Result.failed("手机号不能为空"); return Result.failed("手机号不能为空");
} }
if (StringUtils.isBlank(smsCode)) { if (StringUtils.isBlank(dto.getSmsCode())) {
return Result.failed("验证码不能为空"); return Result.failed("验证码不能为空");
} }
UserRequestDto dto = new UserRequestDto();
dto.setMobile(mobile);
dto.setSmsCode(smsCode);
return userService.loginByMobile(dto, request); return userService.loginByMobile(dto, request);
} }
......
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