Commit 481b195b authored by shiyu's avatar shiyu

Merge remote-tracking branch 'origin/master'

parents 5486ed29 d915aa46
...@@ -10,12 +10,9 @@ public interface FavoritesDao { ...@@ -10,12 +10,9 @@ public interface FavoritesDao {
int delete(Long id); int delete(Long id);
int update(Favorites record); int update(Favorites record);
Favorites info(Long id); Favorites info(Long id);
List<Favorites> listByUserId(Long userId); List<Favorites> listByUserId(Long userId);
PageInfo<Favorites> pageByUserId(Long userId, int page, int size); PageInfo<Favorites> pageByUserId(Long userId, int page, int size);
boolean isExisted(Long id, Long userId, String title); boolean isExisted(Long id, Long userId, String title);
int delete(Long id, List<Long> ids); int delete(Long id, List<Long> ids);
Favorites defaultFavorites(Long userId);
} }
...@@ -10,6 +10,7 @@ public interface FavoritesItemsRelationDao { ...@@ -10,6 +10,7 @@ public interface FavoritesItemsRelationDao {
int batchInsert(List<FavoritesItemsRelation> list); int batchInsert(List<FavoritesItemsRelation> list);
int deleteByFavoritesId(Long favoritesId, List<Long> favoritesIds); int deleteByFavoritesId(Long favoritesId, List<Long> favoritesIds);
int deleteByChosen(Long favoritesId, List<Long> itemIds); int deleteByChosen(Long favoritesId, List<Long> itemIds);
int deleteByUserIdItemId(Long userId, Long itemId);
List<FavoritesItemsRelation> listByFavoritesId(Long favoritesId, List<Long> favoritesIds); List<FavoritesItemsRelation> listByFavoritesId(Long favoritesId, List<Long> favoritesIds);
FavoritesItemsRelation selectByUserIdItemId(Long userId, Long itemId); FavoritesItemsRelation selectByUserIdItemId(Long userId, Long itemId);
PageInfo<FavoritesItemsRelation> pageByFavoritesId(Long favoritesId, int page, int size); PageInfo<FavoritesItemsRelation> pageByFavoritesId(Long favoritesId, int page, int size);
......
...@@ -59,6 +59,7 @@ public class FavoritesDaoImpl implements FavoritesDao { ...@@ -59,6 +59,7 @@ public class FavoritesDaoImpl implements FavoritesDao {
FavoritesExample.Criteria criteria = example.createCriteria(); FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId); criteria.andUserIdEqualTo(userId);
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
example.orderBy("add_time desc");
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
List<Favorites> list = favoritesMapper.selectByExampleWithBLOBs(example); List<Favorites> list = favoritesMapper.selectByExampleWithBLOBs(example);
return new PageInfo<>(list); return new PageInfo<>(list);
...@@ -88,4 +89,13 @@ public class FavoritesDaoImpl implements FavoritesDao { ...@@ -88,4 +89,13 @@ public class FavoritesDaoImpl implements FavoritesDao {
favorites.setUpdateTime(new Date()); favorites.setUpdateTime(new Date());
return favoritesMapper.updateByExampleSelective(favorites, example); return favoritesMapper.updateByExampleSelective(favorites, example);
} }
@Override
public Favorites defaultFavorites(Long userId) {
FavoritesExample example = new FavoritesExample();
FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andSortEqualTo(1);
return favoritesMapper.selectOneByExample(example);
}
} }
...@@ -2,6 +2,7 @@ package com.wwdz.ch.db.impl; ...@@ -2,6 +2,7 @@ package com.wwdz.ch.db.impl;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper; import com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper;
import com.wwdz.ch.db.domain.FavoritesItemsRelation; import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import com.wwdz.ch.db.domain.FavoritesItemsRelationExample; import com.wwdz.ch.db.domain.FavoritesItemsRelationExample;
...@@ -41,6 +42,16 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao ...@@ -41,6 +42,16 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao
criteria.andItemIdIn(itemIds); criteria.andItemIdIn(itemIds);
return favoritesItemsRelationMapper.deleteByExample(example); return favoritesItemsRelationMapper.deleteByExample(example);
} }
@Override
public int deleteByUserIdItemId(Long userId, Long itemId) {
FavoritesItemsRelationExample example = new FavoritesItemsRelationExample();
FavoritesItemsRelationExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andItemIdEqualTo(itemId);
return favoritesItemsRelationMapper.deleteByExample(example);
}
@Override @Override
public List<FavoritesItemsRelation> listByFavoritesId(Long favoritesId, List<Long> favoritesIds) { public List<FavoritesItemsRelation> listByFavoritesId(Long favoritesId, List<Long> favoritesIds) {
FavoritesItemsRelationExample example = new FavoritesItemsRelationExample(); FavoritesItemsRelationExample example = new FavoritesItemsRelationExample();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<mapper namespace="com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper"> <mapper namespace="com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper">
<resultMap id="BaseResultMap" type="com.wwdz.ch.db.domain.FavoritesItemsRelation"> <resultMap id="BaseResultMap" type="com.wwdz.ch.db.domain.FavoritesItemsRelation">
<result column="favorites_id" jdbcType="BIGINT" property="favoritesId" /> <result column="favorites_id" jdbcType="BIGINT" property="favoritesId" />
<result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="item_id" jdbcType="BIGINT" property="itemId" /> <result column="item_id" jdbcType="BIGINT" property="itemId" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" /> <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
</resultMap> </resultMap>
...@@ -65,7 +66,7 @@ ...@@ -65,7 +66,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
favorites_id, item_id, add_time favorites_id, user_id, item_id, add_time
</sql> </sql>
<select id="selectByExample" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelationExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelationExample" resultMap="BaseResultMap">
select select
...@@ -94,13 +95,13 @@ ...@@ -94,13 +95,13 @@
distinct distinct
</if> </if>
<choose> <choose>
<when test="selective != null and selective.length > 0"> <when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=","> <foreach collection="selective" item="column" separator=",">
${column.escapedColumnName} ${column.escapedColumnName}
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
favorites_id, item_id, add_time favorites_id, user_id, item_id, add_time
</otherwise> </otherwise>
</choose> </choose>
from favorites_items_relation from favorites_items_relation
...@@ -118,16 +119,16 @@ ...@@ -118,16 +119,16 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelation"> <insert id="insert" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelation">
insert into favorites_items_relation (favorites_id, item_id, add_time insert into favorites_items_relation (favorites_id, user_id, item_id,
) add_time)
values (#{favoritesId,jdbcType=BIGINT}, #{itemId,jdbcType=BIGINT}, #{addTime,jdbcType=TIMESTAMP} values (#{favoritesId,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT}, #{itemId,jdbcType=BIGINT},
) #{addTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="batchInsert" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelation"> <insert id="batchInsert" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelation">
insert into favorites_coins_relation (favorites_id, item_id, add_time) insert into favorites_items_relation (favorites_id, user_id, item_id,
values add_time)
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
(#{item.favoritesId,jdbcType=BIGINT}, #{item.itemId,jdbcType=BIGINT}, #{item.addTime,jdbcType=TIMESTAMP}) (#{item.favoritesId,jdbcType=BIGINT}, #{item.userId,jdbcType=BIGINT}, #{item.itemId,jdbcType=BIGINT}, #{item.addTime,jdbcType=TIMESTAMP})
</foreach> </foreach>
</insert> </insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelation"> <insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.FavoritesItemsRelation">
...@@ -136,6 +137,9 @@ ...@@ -136,6 +137,9 @@
<if test="favoritesId != null"> <if test="favoritesId != null">
favorites_id, favorites_id,
</if> </if>
<if test="userId != null">
user_id,
</if>
<if test="itemId != null"> <if test="itemId != null">
item_id, item_id,
</if> </if>
...@@ -147,6 +151,9 @@ ...@@ -147,6 +151,9 @@
<if test="favoritesId != null"> <if test="favoritesId != null">
#{favoritesId,jdbcType=BIGINT}, #{favoritesId,jdbcType=BIGINT},
</if> </if>
<if test="userId != null">
#{userId,jdbcType=BIGINT},
</if>
<if test="itemId != null"> <if test="itemId != null">
#{itemId,jdbcType=BIGINT}, #{itemId,jdbcType=BIGINT},
</if> </if>
...@@ -167,6 +174,9 @@ ...@@ -167,6 +174,9 @@
<if test="record.favoritesId != null"> <if test="record.favoritesId != null">
favorites_id = #{record.favoritesId,jdbcType=BIGINT}, favorites_id = #{record.favoritesId,jdbcType=BIGINT},
</if> </if>
<if test="record.userId != null">
user_id = #{record.userId,jdbcType=BIGINT},
</if>
<if test="record.itemId != null"> <if test="record.itemId != null">
item_id = #{record.itemId,jdbcType=BIGINT}, item_id = #{record.itemId,jdbcType=BIGINT},
</if> </if>
...@@ -181,6 +191,7 @@ ...@@ -181,6 +191,7 @@
<update id="updateByExample" parameterType="map"> <update id="updateByExample" parameterType="map">
update favorites_items_relation update favorites_items_relation
set favorites_id = #{record.favoritesId,jdbcType=BIGINT}, set favorites_id = #{record.favoritesId,jdbcType=BIGINT},
user_id = #{record.userId,jdbcType=BIGINT},
item_id = #{record.itemId,jdbcType=BIGINT}, item_id = #{record.itemId,jdbcType=BIGINT},
add_time = #{record.addTime,jdbcType=TIMESTAMP} add_time = #{record.addTime,jdbcType=TIMESTAMP}
<if test="_parameter != null"> <if test="_parameter != null">
...@@ -214,13 +225,13 @@ ...@@ -214,13 +225,13 @@
select select
'true' as QUERYID, 'true' as QUERYID,
<choose> <choose>
<when test="selective != null and selective.length > 0"> <when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=","> <foreach collection="selective" item="column" separator=",">
${column.escapedColumnName} ${column.escapedColumnName}
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
favorites_id, item_id, add_time favorites_id, user_id, item_id, add_time
</otherwise> </otherwise>
</choose> </choose>
from favorites_items_relation from favorites_items_relation
......
package com.wwdz.ch.wx.config; package com.wwdz.ch.wx.config;
import java.util.List;
import com.wwdz.ch.wx.annotation.support.LoginUserHandlerMethodArgumentResolver; import com.wwdz.ch.wx.annotation.support.LoginUserHandlerMethodArgumentResolver;
import com.wwdz.ch.wx.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration @Configuration
public class WxWebMvcConfiguration implements WebMvcConfigurer { public class WxWebMvcConfiguration implements WebMvcConfigurer {
@Bean
LoginInterceptor loginInterceptor() {
return new LoginInterceptor();
}
@Autowired @Autowired
private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver;
...@@ -17,4 +24,12 @@ public class WxWebMvcConfiguration implements WebMvcConfigurer { ...@@ -17,4 +24,12 @@ public class WxWebMvcConfiguration implements WebMvcConfigurer {
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(loginUserHandlerMethodArgumentResolver); argumentResolvers.add(loginUserHandlerMethodArgumentResolver);
} }
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/wx/user/loginByWx"
, "/wx/user/loginByMobile", "/wx/user/loginRegCaptcha", "/wx/user/updateRegCaptcha", "/wx/item/page", "/wx/item/info");
}
} }
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; package com.wwdz.ch.wx.entity.vo;
import com.xxdxxs.entity.Entity;
import lombok.Data; import lombok.Data;
@Data @Data
public class ItemResponseVo { public class ItemResponseVo implements Entity {
private Long id; private Long id;
private Long itemId; private Long itemId;
private Integer cid; private Integer cid;
......
...@@ -3,14 +3,8 @@ package com.wwdz.ch.wx.impl; ...@@ -3,14 +3,8 @@ package com.wwdz.ch.wx.impl;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.consts.CommonEnum; import com.wwdz.ch.core.consts.CommonEnum;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.CategoryDao; import com.wwdz.ch.db.dao.*;
import com.wwdz.ch.db.dao.FavoritesItemsRelationDao; import com.wwdz.ch.db.domain.*;
import com.wwdz.ch.db.dao.ItemDao;
import com.wwdz.ch.db.dao.UserItemsRelationDao;
import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.domain.UserItemsRelation;
import com.wwdz.ch.db.dto.request.CoinRequestDto; import com.wwdz.ch.db.dto.request.CoinRequestDto;
import com.wwdz.ch.wx.entity.request.ItemRequestDto; import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo; import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
...@@ -37,6 +31,10 @@ public class ItemServiceImpl implements ItemService { ...@@ -37,6 +31,10 @@ public class ItemServiceImpl implements ItemService {
private FavoritesItemsRelationDao favoritesItemsRelationDao; private FavoritesItemsRelationDao favoritesItemsRelationDao;
@Autowired @Autowired
private CategoryDao categoryDao; private CategoryDao categoryDao;
@Autowired
private FootPrintDao footPrintDao;
@Autowired
private FavoritesDao favoritesDao;
@Override @Override
...@@ -51,6 +49,7 @@ public class ItemServiceImpl implements ItemService { ...@@ -51,6 +49,7 @@ public class ItemServiceImpl implements ItemService {
result.setPageSize(page.getPageSize()); result.setPageSize(page.getPageSize());
result.setTotal(page.getTotal()); result.setTotal(page.getTotal());
result.setList(new ArrayList<>()); result.setList(new ArrayList<>());
result.setHasNextPage(page.isHasNextPage());
if (CollectionUtils.isEmpty(page.getList())) { if (CollectionUtils.isEmpty(page.getList())) {
return Result.success(result); return Result.success(result);
} }
...@@ -62,8 +61,17 @@ public class ItemServiceImpl implements ItemService { ...@@ -62,8 +61,17 @@ public class ItemServiceImpl implements ItemService {
vo.setImages(item.getImages()); vo.setImages(item.getImages());
vo.setPrice(String.valueOf(item.getPrice() * 100)); vo.setPrice(String.valueOf(item.getPrice() * 100));
vo.setDetail(item.getDetail()); vo.setDetail(item.getDetail());
vo.setIsCollected(0);
if (!dto.getUserId().equals(0L)) {
vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), item.getId()) ? 1 : 0); vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), item.getId()) ? 1 : 0);
vo.setCollectCount(favoritesItemsRelationDao.countByItemId(item.getId())); vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
}
long count = favoritesItemsRelationDao.countByItemId(item.getId());
if (item.getSourceType().equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
count --;
}
vo.setCollectCount(count);
vo.setSourceType(item.getSourceType());
AgentTranceResponseVo agentTranceResponseVo = new AgentTranceResponseVo(); AgentTranceResponseVo agentTranceResponseVo = new AgentTranceResponseVo();
agentTranceResponseVo.setAgentTraceInfo_(""); agentTranceResponseVo.setAgentTraceInfo_("");
...@@ -114,11 +122,15 @@ public class ItemServiceImpl implements ItemService { ...@@ -114,11 +122,15 @@ public class ItemServiceImpl implements ItemService {
// 新增收藏册和藏品关联记录 // 新增收藏册和藏品关联记录
FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation(); FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation();
favoritesItemsRelation.setUserId(dto.getUserId());
favoritesItemsRelation.setFavoritesId(dto.getFavoritesId()); favoritesItemsRelation.setFavoritesId(dto.getFavoritesId());
favoritesItemsRelation.setItemId(item.getId()); favoritesItemsRelation.setItemId(item.getId());
favoritesItemsRelation.setAddTime(now); favoritesItemsRelation.setAddTime(now);
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
return Result.success();
Map<String, Object> map = new HashMap<>();
map.put("id", item.getId());
return Result.success(map);
} catch (Exception e) { } catch (Exception e) {
logger.error("发布藏品失败,原因:" + e.getMessage(), e); logger.error("发布藏品失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
...@@ -145,6 +157,9 @@ public class ItemServiceImpl implements ItemService { ...@@ -145,6 +157,9 @@ public class ItemServiceImpl implements ItemService {
} }
itemResponseVo.setPrice(String.valueOf(item.getPrice() * 100)); itemResponseVo.setPrice(String.valueOf(item.getPrice() * 100));
itemResponseVo.setSourceType(item.getSourceType()); itemResponseVo.setSourceType(item.getSourceType());
itemResponseVo.setIsCollected(0);
itemResponseVo.setIsMine(0);
if (!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);
...@@ -153,6 +168,17 @@ public class ItemServiceImpl implements ItemService { ...@@ -153,6 +168,17 @@ public class ItemServiceImpl implements ItemService {
itemResponseVo.setIsCollected(0); itemResponseVo.setIsCollected(0);
} }
itemResponseVo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0); itemResponseVo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
// 添加用户足迹
Footprint footprint = new Footprint();
footprint.setUserId(dto.getUserId());
footprint.setItemId(item.getId());
Date now = new Date();
footprint.setAddTime(now);
footprint.setUpdateTime(now);
footprint.setDeleted(false);
footPrintDao.insert(footprint);
}
logger.info("【请求结束】查看藏品详情成功"); logger.info("【请求结束】查看藏品详情成功");
return Result.success(itemResponseVo); return Result.success(itemResponseVo);
} catch (Exception e) { } catch (Exception e) {
...@@ -165,36 +191,48 @@ public class ItemServiceImpl implements ItemService { ...@@ -165,36 +191,48 @@ public class ItemServiceImpl implements ItemService {
@Override @Override
public Result collect(ItemRequestDto dto) { public Result collect(ItemRequestDto dto) {
try { try {
Item item = itemDao.findDetails(dto.getId()); if (dto.getUserId().equals(0L)) {
if (null == item.getId()) { return Result.failed("您尚未登录,请先登录");
return Result.failed("数据异常,该藏品不存在"); }
// 查找默认收藏册
Favorites favorites = favoritesDao.defaultFavorites(dto.getUserId());
if (Objects.isNull(favorites)) {
return Result.failed("数据异常,查询不到用户的默认收藏册");
} }
item.setName(dto.getName());
item.setCid(dto.getCid());
item.setImages(dto.getImages());
item.setPrice(Long.parseLong(dto.getPrice()) / 100);
item.setDetail(dto.getDetail());
Date now = new Date();
item.setUpdateTime(now);
item.setSourceType(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode());
item.setIsDeleted(false);
itemDao.update(item);
// 删除藏品和原收藏册关联
List<Long> itemIds = new ArrayList<>();
itemIds.add(item.getId());
favoritesItemsRelationDao.deleteByChosen(dto.getBeforeFavoritesId(), itemIds);
// 新增藏品和新收藏册关联 // 新增藏品和新收藏册关联
FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation(); FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation();
favoritesItemsRelation.setUserId(dto.getUserId()); favoritesItemsRelation.setUserId(dto.getUserId());
favoritesItemsRelation.setFavoritesId(dto.getAfterFavoritesId()); favoritesItemsRelation.setFavoritesId(favorites.getId());
favoritesItemsRelation.setItemId(item.getId()); favoritesItemsRelation.setItemId(dto.getId());
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
Map<String, Object> map = new HashMap<>();
map.put("favoritesId", favorites.getId());
return Result.success(map);
} catch (Exception e) {
logger.error("首页收藏失败,原因:" + e.getMessage(), e);
return Result.failed("首页收藏失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Result cancel(ItemRequestDto dto) {
try {
if (dto.getUserId().equals(0L)) {
return Result.failed("您尚未登录,请先登录");
}
if (userItemsRelationDao.isExisted(dto.getUserId(), dto.getId())) {
return Result.failed("操作失败,无法取消收藏");
}
// 删除藏品和收藏册关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("修改藏品失败,原因:" + e.getMessage(), e); logger.error("首页取消收藏失败,原因:" + e.getMessage(), e);
return Result.failed("修改藏品失败"); return Result.failed("首页取消收藏失败");
} }
} }
...@@ -206,6 +244,18 @@ public class ItemServiceImpl implements ItemService { ...@@ -206,6 +244,18 @@ public class ItemServiceImpl implements ItemService {
return Result.failed("数据异常,该藏品不存在"); return Result.failed("数据异常,该藏品不存在");
} }
item.setName(dto.getName());
item.setCid(dto.getCid());
item.setImages(dto.getImages());
item.setPrice(Long.parseLong(dto.getPrice()) / 100);
item.setDetail(dto.getDetail());
Date now = new Date();
item.setUpdateTime(now);
itemDao.update(item);
// 删除原来藏品和收藏册关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
// 新增藏品和收藏册关联 // 新增藏品和收藏册关联
FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation(); FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation();
favoritesItemsRelation.setUserId(dto.getUserId()); favoritesItemsRelation.setUserId(dto.getUserId());
...@@ -214,8 +264,8 @@ public class ItemServiceImpl implements ItemService { ...@@ -214,8 +264,8 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("收藏藏品失败,原因:" + e.getMessage(), e); logger.error("修改藏品失败,原因:" + e.getMessage(), e);
return Result.failed("收藏藏品失败"); return Result.failed("修改藏品失败");
} }
} }
} }
package com.wwdz.ch.wx.interceptor;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.wx.service.UserTokenManager;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Component
public class LoginInterceptor implements HandlerInterceptor {
Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);
@Autowired
private UserTokenManager userTokenManager;
/***
* 在请求处理之前进行调用(Controller方法调用之前)
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
logger.info("-------------进入拦截器");
logger.info("请求头名称:" + JSON.toJSONString(request.getHeaderNames()));
String token = request.getHeader("Authorization");
logger.info("token的值是:" + token);
if (StringUtils.isBlank(token)) {
return true;
}
if (StringUtils.isNotBlank(token)) {
Long userId = userTokenManager.getUserId(token);
if (Objects.nonNull(userId)) {
return true;
}
}
Map<Object, Object> map = new HashMap<>();
map.put("code", 401);
map.put("success", false);
map.put("message", "未登录!");
map.put("result", null);
response.setContentType("application/json; charset=utf-8");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.getWriter().write(JSON.toJSONString(map));
return false;
}
/***
* 请求处理之后进行调用,但是在视图被渲染之前(Controller方法调用之后)
*/
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
/***
* 整个请求结束之后被调用,也就是在DispatchServlet渲染了对应的视图之后执行(主要用于进行资源清理工作)
*/
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
...@@ -21,6 +21,7 @@ public interface FavoritesService { ...@@ -21,6 +21,7 @@ public interface FavoritesService {
Result delete(FavoritesRequestDto dto); Result delete(FavoritesRequestDto dto);
Result batchDelete(FavoritesRequestDto dto); Result batchDelete(FavoritesRequestDto dto);
Result addItem(ItemRequestDto dto);
Result removeItem(ItemRequestDto dto); Result removeItem(ItemRequestDto dto);
......
...@@ -14,5 +14,7 @@ public interface ItemService { ...@@ -14,5 +14,7 @@ public interface ItemService {
Result collect(ItemRequestDto dto); Result collect(ItemRequestDto dto);
Result cancel(ItemRequestDto dto);
Result update(ItemRequestDto dto); Result update(ItemRequestDto dto);
} }
...@@ -11,8 +11,10 @@ import com.wwdz.ch.db.domain.Footprint; ...@@ -11,8 +11,10 @@ import com.wwdz.ch.db.domain.Footprint;
import com.wwdz.ch.db.domain.Item; import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.wx.annotation.LoginUser; import com.wwdz.ch.wx.annotation.LoginUser;
import com.wwdz.ch.wx.entity.request.FootPrintRequestDto; import com.wwdz.ch.wx.entity.request.FootPrintRequestDto;
import com.wwdz.ch.wx.entity.request.KlDataRequestDto;
import com.wwdz.ch.wx.service.FootPrintService; import com.wwdz.ch.wx.service.FootPrintService;
import org.apache.commons.collections.CollectionUtils; import com.xxdxxs.utils.JsonUtils;
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;
...@@ -20,6 +22,7 @@ import org.springframework.validation.annotation.Validated; ...@@ -20,6 +22,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 用户访问足迹服务 * 用户访问足迹服务
...@@ -126,28 +129,52 @@ public class WxFootprintController { ...@@ -126,28 +129,52 @@ public class WxFootprintController {
} }
@PostMapping("/page") @PostMapping("/page")
public Result page(@RequestBody FootPrintRequestDto dto) { public Result page(@RequestBody KlDataRequestDto klDataRequestDto) {
logger.info("【请求开始】用户足迹列表查询,请求参数,userId:{}", dto.getUserId()); String json = klDataRequestDto.getKl_data();
if (Objects.isNull(dto.getUserId())) { logger.info("【请求开始】用户足迹列表查询,请求参数,kl_data:{}", json);
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 (Objects.isNull(dto.getPage())) { if (StringUtils.isBlank(page)) {
return Result.failed("当前页不能为空"); return Result.failed("当前页不能为空");
} }
if (Objects.isNull(dto.getSize())) { if (StringUtils.isBlank(size)) {
return Result.failed("页面大小不能为空"); return Result.failed("页面大小不能为空");
} }
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(page)) {
return Result.failed("当前页不能为空");
}
if (StringUtils.isBlank(size)) {
return Result.failed("页面大小不能为空");
}
FootPrintRequestDto dto = new FootPrintRequestDto();
dto.setUserId(Long.parseLong(userId));
dto.setPage(Integer.parseInt(page));
dto.setSize(Integer.parseInt(size));
return footPrintService.page(dto); return footPrintService.page(dto);
} }
@PostMapping("/del") @PostMapping("/del")
public Result delete(@RequestBody FootPrintRequestDto dto) { public Result delete(@RequestBody KlDataRequestDto klDataRequestDto) {
logger.info("【请求开始】用户足迹删除,请求参数,ids:{}", dto.getIds()); String json = klDataRequestDto.getKl_data();
if (CollectionUtils.isEmpty(dto.getIds())) { logger.info("【请求开始】收藏册收藏,请求参数,kl_data:{}", json);
return Result.failed("请选择足迹"); 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());
FootPrintRequestDto dto = new FootPrintRequestDto();
dto.setIds(idss);
return footPrintService.delete(dto); return footPrintService.delete(dto);
} }
......
...@@ -27,13 +27,10 @@ public class WxItemController { ...@@ -27,13 +27,10 @@ public class WxItemController {
@PostMapping("/page") @PostMapping("/page")
public Result page(@RequestBody KlDataRequestDto klDataRequestDto) { public Result page(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data(); String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】藏品列表分页查询,请求参数,kl_data:{}", json); logger.info("【请求开始】藏品列表首页,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId"); String userId = JsonUtils.getValueByPath(json, "userId");
String page = JsonUtils.getValueByPath(json, "page"); String page = JsonUtils.getValueByPath(json, "page");
String size = JsonUtils.getValueByPath(json, "size"); String size = JsonUtils.getValueByPath(json, "size");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(page)) { if (StringUtils.isBlank(page)) {
return Result.failed("当前页不能为空"); return Result.failed("当前页不能为空");
} }
...@@ -42,7 +39,10 @@ public class WxItemController { ...@@ -42,7 +39,10 @@ public class WxItemController {
} }
ItemRequestDto dto = new ItemRequestDto(); ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId)); dto.setUserId(Long.parseLong(userId));
}
dto.setPage(Integer.parseInt(page)); dto.setPage(Integer.parseInt(page));
dto.setSize(Integer.parseInt(size)); dto.setSize(Integer.parseInt(size));
return itemService.page(dto); return itemService.page(dto);
...@@ -56,13 +56,90 @@ public class WxItemController { ...@@ -56,13 +56,90 @@ public class WxItemController {
@ApiOperation(value = "新增") @ApiOperation(value = "新增")
@PostMapping("/add") @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); return itemService.add(dto);
} }
@ApiOperation(value = "修改") @ApiOperation(value = "修改")
@PostMapping("/update") @PostMapping("/update")
public Result update(@RequestBody ItemRequestDto dto) { 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 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(id)) {
return Result.failed("id不能为空");
}
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.setId(Long.parseLong(id));
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.update(dto); return itemService.update(dto);
} }
...@@ -73,16 +150,56 @@ public class WxItemController { ...@@ -73,16 +150,56 @@ public class WxItemController {
logger.info("【请求开始】藏品详情查询,请求参数,kl_data:{}", json); logger.info("【请求开始】藏品详情查询,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId"); String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id"); String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(userId)) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(id)) { if (StringUtils.isBlank(id)) {
return Result.failed("当前页不能为空"); return Result.failed("藏品id不能为空");
} }
ItemRequestDto dto = new ItemRequestDto(); ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId)); dto.setUserId(Long.parseLong(userId));
}
dto.setId(Long.parseLong(id)); dto.setId(Long.parseLong(id));
return itemService.info(dto); return itemService.info(dto);
} }
@ApiOperation(value = "收藏")
@PostMapping("/collect")
public Result collect(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】首页收藏,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(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);
}
@ApiOperation(value = "取消收藏")
@PostMapping("/cancel")
public Result cancel(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】首页取消收藏,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(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);
}
} }
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