场景自动填充时间的handler,添加与收藏商品完成,导出新的sql文件

This commit is contained in:
hupeng committed 2019-09-10 10:29:22 +08:00
1 parent fe2d6ebeea
commit eb4e6a3e49
6 files changed
+3753 -15

No files matched your search

@@ -33,8 +33,6 @@ public class LightSecurityExceptionHandler {
//@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
public R error(HttpServletRequest request, LightSecurityException exception, HttpServletResponse response) {
//System.out.println(request.getMethod());
//System.out.println(exception.getMessage());
String str1 = "com.itmuch.lightsecurity.exception.LightSecurityException: 没有找到名为Authorization的header";
String str2 = "com.itmuch.lightsecurity.exception.LightSecurityException: Token invalided.";
if (exception.getMessage().equals(str1) || exception.getMessage().equals(str2)) {
@@ -0,0 +1,25 @@
package com.ruoyi.app.common.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @ClassName MyMetaHandler
* @Author hupeng <610796224@qq.com>
* @Date 2019/9/10
**/
@Component
public class MyMetaHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("addTime", new Date(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
}
}
@@ -1,11 +1,9 @@
package com.ruoyi.app.common.persistence.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
@@ -38,8 +36,8 @@ public class StoreGoodsCollect extends Model<StoreGoodsCollect> {
/**
* 添加时间
*/
@TableField("add_time")
private Integer addTime;
@TableField(value = "add_time",fill = FieldFill.INSERT)
private Date addTime;
public Integer getCollectId() {
@@ -66,11 +64,11 @@ public class StoreGoodsCollect extends Model<StoreGoodsCollect> {
this.goodsId = goodsId;
}
public Integer getAddTime() {
public Date getAddTime() {
return addTime;
}
public void setAddTime(Integer addTime) {
public void setAddTime(Date addTime) {
this.addTime = addTime;
}
@@ -89,11 +89,28 @@ public class MallController {
}
@PostMapping("/shop/mall-add-collect")
@ApiOperation(value = "添加商品收藏",notes = "添加商品收藏")
public R addCollect(@Validated @RequestBody CollectVO collectVO){
int userId = userOperator.getUser().getId();
//throw new BadRequestException("已经收藏过");
goodsService.addOrCancelCollect(collectVO.getGoodsId(),userId,1);
boolean result = goodsService.addOrCancelCollect(collectVO.getGoodsId(),userId,1);
return null;
if(result){
return R.success("操作成功");
}else{
return R.error(4000,"操作失败");
}
}
@PostMapping("/shop/mall-cancel-collect")
@ApiOperation(value = "取消商品收藏",notes = "取消商品收藏")
public R cancelCollect(@Validated @RequestBody CollectVO collectVO){
int userId = userOperator.getUser().getId();
boolean result = goodsService.addOrCancelCollect(collectVO.getGoodsId(),userId,2);
if(result){
return R.success("操作成功");
}else{
return R.error(4000,"操作失败");
}
}
}
@@ -142,13 +142,29 @@ public class GoodsServiceImpl extends ServiceImpl<StoreGoodsMapper, StoreGoods>
}
/**
* 添加或者取消收藏
* @param goodsId
* @param userId
* @param type
* @return
*/
@Override
public boolean addOrCancelCollect(int goodsId, int userId, int type) {
if(type == 1){//1-添加 2-取消
boolean isCollect = isCollect(goodsId,userId);
if(isCollect) throw new LightSecurityException("已经收藏过");
System.out.println("======");
StoreGoodsCollect storeGoodsCollect = new StoreGoodsCollect();
storeGoodsCollect.setGoodsId(goodsId);
storeGoodsCollect.setUserId(userId);
storeGoodsCollectMapper.insert(storeGoodsCollect);
return true;
}else{
QueryWrapper<StoreGoodsCollect> wrapper = new QueryWrapper<>();
wrapper.eq("goods_id",goodsId).eq("user_id",userId);
int result = storeGoodsCollectMapper.delete(wrapper);
if(result > 0) return true;
return false;
}
return false;
}
}
File diff suppressed because it is too large. Load diff