xiaoyong931011
2021-06-29 7e536551c09cea3b50c773308fb80d90d98d472a
20210629 商品搜索
5 files added
3 files modified
143 ■■■■■ changed files
gc-core/src/main/java/com/xzx/gc/entity/ScoreGoodsSearch.java 28 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiGoodsController.java 29 ●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/dto/GoodsSearchDto.java 11 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/dto/XcxGoodsListDto.java 3 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreGoodsSearchMapper.java 14 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/service/GoodsService.java 24 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/vo/GoodsSearchVo.java 20 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/ScoreGoodsSearchMapper.xml 14 ●●●●● patch | view | raw | blame | history
gc-core/src/main/java/com/xzx/gc/entity/ScoreGoodsSearch.java
New file
@@ -0,0 +1,28 @@
package com.xzx.gc.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Data
@Table(name = "xzx_score_goods_search")
public class ScoreGoodsSearch {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;
    private String userId;
    private String contents;
}
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiGoodsController.java
@@ -6,16 +6,11 @@
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.service.BaseAccountService;
import com.xzx.gc.shop.dto.AddGoodsOrderDto;
import com.xzx.gc.shop.dto.XcxGoodsListDto;
import com.xzx.gc.shop.dto.XcxScoreDetailsDto;
import com.xzx.gc.shop.dto.*;
import com.xzx.gc.shop.service.GoodsService;
import com.xzx.gc.shop.service.OrderService;
import com.xzx.gc.shop.service.ScoreDetailsService;
import com.xzx.gc.shop.vo.GoodsCategoryVo;
import com.xzx.gc.shop.vo.XcxGoodsDetailVo;
import com.xzx.gc.shop.vo.XcxGoodsListVo;
import com.xzx.gc.shop.vo.XcxScoreDetailsVo;
import com.xzx.gc.shop.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
@@ -51,6 +46,8 @@
    )
    @PostMapping(value = "/goods/goodsList")
    public JsonResult<PageInfo<XcxGoodsListVo>> goodsList(@RequestBody XcxGoodsListDto xcxGoodsListDto, HttpServletRequest request) {
        String userId = getUserId(request);
        xcxGoodsListDto.setUserId(userId);
        return JsonResult.success(goodsService.findGoodsListInPage(xcxGoodsListDto));
    }
@@ -63,4 +60,22 @@
        return JsonResult.success(goodsService.findGoodsDetails(id));
    }
    @ApiOperation("商品搜索历史记录")
    @ApiResponses(
            @ApiResponse(code = 200, message = "success", response = GoodsSearchVo.class)
    )
    @PostMapping(value = "/goods/goodsSearch")
    public JsonResult<List<GoodsSearchVo>> goodsSearch(@RequestBody GoodsSearchDto goodsSearchDto, HttpServletRequest request) {
        String userId = getUserId(request);
        goodsSearchDto.setUserId(userId);
        return JsonResult.success(goodsService.goodsSearch(goodsSearchDto));
    }
    @ApiOperation("商品搜索历史记录--删除")
    @PostMapping(value = "/goods/delGoodsSearch/{id}")
    public Result<String> delGoodsSearch (@PathVariable("id") Long id, HttpServletRequest request) {
        goodsService.delGoodsSearch(id, getUserId(request));
        return Result.success();
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/dto/GoodsSearchDto.java
New file
@@ -0,0 +1,11 @@
package com.xzx.gc.shop.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class GoodsSearchDto {
    @ApiModelProperty(hidden = true)
    private String userId;
}
gc-shop/src/main/java/com/xzx/gc/shop/dto/XcxGoodsListDto.java
@@ -32,4 +32,7 @@
    @ApiModelProperty(value="每页显示记录数")
    private int pageSize=10;
    @ApiModelProperty(hidden = true)
    private String userId;
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreGoodsSearchMapper.java
New file
@@ -0,0 +1,14 @@
package com.xzx.gc.shop.mapper;
import com.xzx.gc.entity.ScoreGoodsSearch;
import com.xzx.gc.shop.dto.GoodsSearchDto;
import com.xzx.gc.shop.vo.GoodsSearchVo;
import com.xzx.gc.util.GcMapper;
import java.util.List;
public interface ScoreGoodsSearchMapper extends GcMapper<ScoreGoodsSearch> {
    List<GoodsSearchVo> goodsSearch(GoodsSearchDto goodsSearchDto);
}
gc-shop/src/main/java/com/xzx/gc/shop/service/GoodsService.java
@@ -3,9 +3,11 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
@@ -42,6 +44,8 @@
    ScoreGoodsImagesMapper scoreGoodsImagesMapper;
    @Resource
    ScoreGoodsStyleMapper scoreGoodsStyleMapper;
    @Resource
    ScoreGoodsSearchMapper scoreGoodsSearchMapper;
    @Autowired
    private MqUtil mqUtil;
@@ -313,7 +317,13 @@
        PageHelper.startPage(xcxGoodsListDto.getPageNo(), xcxGoodsListDto.getPageSize());
        List<XcxGoodsListVo> data = scoreGoodsMapper.selectXcxGoodsList(xcxGoodsListDto);
        if(StrUtil.isNotEmpty(xcxGoodsListDto.getName())){
            ScoreGoodsSearch scoreGoodsSearch = new ScoreGoodsSearch();
            scoreGoodsSearch.setUserId(xcxGoodsListDto.getUserId());
            scoreGoodsSearch.setContents(xcxGoodsListDto.getName());
            scoreGoodsSearch.setCreatedTime(new DateTime());
            scoreGoodsSearchMapper.insert(scoreGoodsSearch);
        }
        return new PageInfo<>(data);
    }
@@ -341,4 +351,16 @@
        }
        return data;
    }
    public List<GoodsSearchVo> goodsSearch(GoodsSearchDto goodsSearchDto) {
        return scoreGoodsSearchMapper.goodsSearch(goodsSearchDto);
    }
    public void delGoodsSearch(Long id, String userId) {
        Example exampleSearch = new Example(ScoreGoodsSearch.class);
        Example.Criteria criteriaSearch = exampleSearch.createCriteria();
        criteriaSearch.andEqualTo("id",id);
        criteriaSearch.andEqualTo("userId",userId);
        scoreGoodsSearchMapper.deleteByExample(exampleSearch);
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/vo/GoodsSearchVo.java
New file
@@ -0,0 +1,20 @@
package com.xzx.gc.shop.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "GoodsSearchVo", description = "小程序分类接口返回参数类")
public class GoodsSearchVo {
    private Long id;
    private String userId;
    @ApiModelProperty(value = "内容")
    private String contents;
    @ApiModelProperty(value = "创建时间")
    private String createTime;
}
gc-shop/src/main/resources/mapper/shop/ScoreGoodsSearchMapper.xml
New file
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xzx.gc.shop.mapper.ScoreGoodsSearchMapper">
    <select id="goodsSearch" resultType="com.xzx.gc.shop.vo.GoodsSearchVo">
        select a.id id,
               a.user_id userId,
               date_format(a.CREATED_TIME,'%Y-%m-%d') createTime,
               a.contents contents
        from xzx_score_goods_search a
        where a.user_id=#{record.userId}
    </select>
</mapper>