1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

较多改动,暂存

This commit is contained in:
2023-04-04 01:06:22 +08:00
parent ac885fb06b
commit a68307b9f9
44 changed files with 2467 additions and 649 deletions

View File

@@ -0,0 +1,322 @@
package com.cxyxiaomo.epp.shop.controller;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.cxyxiaomo.epp.PageTable.enums.AddType;
import com.cxyxiaomo.epp.PageTable.enums.EditType;
import com.cxyxiaomo.epp.PageTable.enums.FieldType;
import com.cxyxiaomo.epp.PageTable.enums.SearchType;
import com.cxyxiaomo.epp.PageTable.query.PageQuery;
import com.cxyxiaomo.epp.PageTable.utils.FieldBuilder;
import com.cxyxiaomo.epp.PageTable.utils.FieldMapperBuilder;
import com.cxyxiaomo.epp.PageTable.utils.FieldRuleBuilder;
import com.cxyxiaomo.epp.PageTable.utils.FieldRuleListBuilder;
import com.cxyxiaomo.epp.TencentCloud.QCloudCosStsClient;
import com.cxyxiaomo.epp.TencentCloud.TmpCredential;
import com.cxyxiaomo.epp.common.pojo.Good;
import com.cxyxiaomo.epp.common.pojo.GoodCategory;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import com.cxyxiaomo.epp.shop.service.GoodService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/shop/good")
public class GoodController {
@Resource
GoodService goodService;
/**
* 小程序端商品列表
*
* @return
*/
@GetMapping("/miniprogram/list")
public Res list(@RequestParam(value = "cateId", required = false) Integer cateId,
@RequestParam(value = "searchText", required = false) String searchText) {
if (cateId != null && cateId <= 0) {
cateId = null;
}
if (searchText != null) {
searchText = searchText.trim();
if (searchText.contains("%") || searchText.contains("_")) {
searchText = searchText
.replaceAll("[_%]", "");
}
if ("".equals(searchText)) {
searchText = null;
}
}
List<GoodVO> list = goodService.list(cateId, searchText);
return Res.success(list);
}
/**
* 小程序端商品详情
*
* @return
*/
@GetMapping("/miniprogram/detail")
public Res detail(@RequestParam("id") Long id) {
GoodVO goodVO = goodService.getById(id);
return Res.success(goodVO);
}
/**
* 小程序端商品分类列表
*
* @return
*/
@GetMapping("/miniprogram/cateList")
public Res cateList() {
List<GoodCategoryVO> list = goodService.cateListVO();
return Res.success(list);
}
/**
* 获取商品列表
*
* @return
*/
@GetMapping("/manage/getGoodList")
@ResponseBody
public Res getGoodList(PageQuery pageQuery, GoodVO goodVO) {
// 查询分页数据
PageHelper.startPage(pageQuery.getPageIndex(), pageQuery.getPageSize());
List<Good> goodList = goodService.getGoodList(goodVO);
PageInfo<Good> goodPageInfo = new PageInfo<>(goodList);
List<Good> list = goodPageInfo.getList();
List<GoodVO> voList = GoodVO.convertFrom(list);
// 分类列表
List<GoodCategory> cateList = goodService.getCateList();
String cateListForMock = JSONArray.from(cateList.stream().map(i -> i.getId()).collect(Collectors.toList())).toString();
// id列 字段名区分大小写以VO中的变量名为准
// 新增、修改弹窗时,使用该列作为主键列进行操作
String idFieldName = "id";
// 当前管理页面
String pageName = "商品管理";
// 指定前端表格显示列
JSONArray columns = FieldBuilder.create()
.add("picUrl", "picUrl", "商品图片", "https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/jpg",
FieldType.IMAGE, SearchType.CAN_NOT_SEARCH, AddType.IMAGE, EditType.IMAGE,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"商品图片", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create(),
"IMG 120x120,随机图片"
)
.add("goodsName", "goodsName", "商品名称", "",
FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.CAN_NOT_EDIT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"商品名称", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("商品名称").required())
.add(FieldRuleBuilder.create("商品名称").minMax(6, 20)),
"DPD @cword(6, 20)"
)
.add("categoryId", "categoryName", "所属分类", "",
FieldType.TEXT, SearchType.SELECT, AddType.SELECT, EditType.SELECT,
"商品分类",
"商品分类", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("商品分类").required()),
"DPD @pick(" + cateListForMock + "])"
)
.add("brand", "brand", "商品品牌", "",
FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"商品品牌", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("商品品牌").required())
.add(FieldRuleBuilder.create("商品品牌").minMax(6, 20)),
"DPD @cword(6, 15)"
)
.add("brief", "brief", "商品简介", "暂无简介",
FieldType.HIDDEN, SearchType.INPUT, AddType.INPUT, EditType.INPUT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"商品简介", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("商品简介").required())
.add(FieldRuleBuilder.create("商品简介").minMax(6, 30)),
"DPD @cword(15, 30)"
)
.add("isOnSale", "isOnSale", "状态", true,
FieldType.TEXT, SearchType.SELECT, AddType.SELECT, EditType.SELECT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"状态", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("状态").required()),
"DPD @pick(['true', 'false'])"
)
.add("sortOrder", "sortOrder", "排序", "",
FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"排序", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create(),
"DTD /^\\d+?$/"
)
.add("unit", "unit", "商品单位", "",
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.INPUT, EditType.INPUT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"商品单位", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("商品单位").required()),
"DPD @cword(1, 2)"
)
.add("counterPrice", "counterPrice", "专柜价格", "",
FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT,
"专柜价/原价/划线价",
"专柜价格 / 原价 / 划线价", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("专柜价格").required()),
"DTD /^\\d+?(\\.?\\d+?)?$/"
)
.add("retailPrice", "retailPrice", "零售价格", "",
FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT,
"零售价/售价/未划线价",
"零售价 / 售价 / 未划线价", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("零售价格").required()),
"DTD /^\\d+?(\\.?\\d+?)?$/"
)
.add("detail", "detail", "商品详细介绍", "暂无商品详细介绍",
FieldType.LONG_TEXT, SearchType.INPUT, AddType.TEXTAREA, EditType.TEXTAREA,
"详细介绍",
"商品详细介绍", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create(),
"DPD @csentence(20, 200)"
)
.build();
// 指定需要翻译的字段
HashMap cateMap = new HashMap(cateList.size());
for (GoodCategory category : cateList) {
cateMap.put(category.getId(), category.getCategoryName());
}
HashMap<Object, Object> stateMap = new HashMap<>(2);
stateMap.put(true, "上架");
stateMap.put(false, "下架");
// build
JSONArray fieldMapper = FieldMapperBuilder.create()
.add("categoryId", "categoryName", cateMap)
.add("isOnSale", "isOnSale", stateMap)
.build();
// 拼装返回结果
JSONObject map = new JSONObject(2);
map.put("total", goodPageInfo.getTotal());
map.put("list", voList);
map.put("columns", columns);
map.put("fieldMapper", fieldMapper);
map.put("idFieldName", idFieldName);
map.put("pageName", pageName);
// 返回结果
return Res.success(map);
}
/**
* 新增 / 编辑商品
*
* @return
*/
@PostMapping("/manage/editGood")
@ResponseBody
public Res editGood(@ModelAttribute GoodVO goodVO) {
Good good = GoodVO.convertTo(goodVO);
// 先查询商品是否存在
Good existGood = goodService.getGoodById(good.getId());
if (good.getId() == null || good.getId() < 1) {
// 新增商品
if (existGood != null) {
return Res.error("商品名已存在,操作失败");
}
// if (password == null || "".equals(password)) {
// return Res.error("密码不能为空");
// }
good.setId(null);
goodService.addGood(good);
} else {
// 修改商品
if (existGood == null) {
return Res.error("商品不存在,操作失败");
}
goodService.updateGood(good);
}
return Res.success(true);
}
/**
* 删除商品
*
* @param id
* @return
*/
@PostMapping("/manage/deleteGood")
@ResponseBody
public Res deleteGood(Long id) {
if (id == null || id <= 0) {
return Res.error("商品不存在,删除失败");
}
// 先查询商品名是否存在
Good existGood = goodService.getGoodById(id);
if (existGood == null) {
return Res.error("商品不存在,删除失败");
}
boolean b = goodService.deleteGood(existGood.getId());
return Res.success(b);
}
/**
* 导出商品列表
*
* @return
*/
@GetMapping("/manage/exportGoodList")
@ResponseBody
public Res exportGoodList(GoodVO goodVO) {
List<Good> goodList = goodService.getGoodList(goodVO);
List<GoodVO> goodVOList = GoodVO.convertFrom(goodList);
// 当前时间
Date now = Calendar.getInstance().getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
String dateTime = format.format(now);
HashMap<String, Object> map = new HashMap<>();
map.put("list", goodVOList);
map.put("sheetName", "商品表-" + System.currentTimeMillis());
map.put("fileName", "商品表_导出时间_" + dateTime);
return Res.success(map);
}
@GetMapping("/manage/imageUpload/getTmpCosCredential")
@ResponseBody
public Res getTmpCosCredential(@RequestParam(required = true) String ext) {
// 生成一个随机文件名
UUID uuid = UUID.randomUUID();
String objectKey = "good/" + uuid + "." + ext;
// 创建一个临时密钥
TmpCredential credential = QCloudCosStsClient.getCredential(objectKey);
// 返回结果
return Res.success(credential);
}
}

View File

@@ -1,68 +0,0 @@
package com.cxyxiaomo.epp.shop.controller;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import com.cxyxiaomo.epp.shop.service.GoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/shop/good")
public class GoodsController {
@Resource
GoodsService goodsService;
/**
* 小程序端商品列表
*
* @return
*/
@GetMapping("/miniprogram/list")
public Res list(@RequestParam(value = "cateId", required = false) Integer cateId,
@RequestParam(value = "searchText", required = false) String searchText) {
if (cateId != null && cateId <= 0) {
cateId = null;
}
if (searchText != null) {
searchText = searchText.trim();
if (searchText.contains("%") || searchText.contains("_")) {
searchText = searchText
.replaceAll("[_%]", "");
}
if ("".equals(searchText)) {
searchText = null;
}
}
List<GoodVO> list = goodsService.list(cateId, searchText);
return Res.success(list);
}
/**
* 小程序端商品详情
*
* @return
*/
@GetMapping("/miniprogram/detail")
public Res detail(@RequestParam("id") Long id) {
GoodVO goodVO = goodsService.getById(id);
return Res.success(goodVO);
}
/**
* 小程序端商品分类列表
*
* @return
*/
@GetMapping("/miniprogram/cateList")
public Res cateList() {
List<GoodCategoryVO> list = goodsService.cateList();
return Res.success(list);
}
}

View File

@@ -9,7 +9,7 @@ import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import com.cxyxiaomo.epp.common.vo.OrderDetailVO;
import com.cxyxiaomo.epp.common.vo.OrderVO;
import com.cxyxiaomo.epp.shop.service.GoodsService;
import com.cxyxiaomo.epp.shop.service.GoodService;
import com.cxyxiaomo.epp.shop.service.OrderService;
import org.springframework.web.bind.annotation.*;
@@ -25,7 +25,7 @@ public class OrderController {
OrderService orderService;
@Resource
GoodsService goodsService;
GoodService goodService;
/**
* 小程序端创建订单
@@ -103,7 +103,7 @@ public class OrderController {
return Long.parseLong(goodId);
}).collect(Collectors.toList());
List<GoodVO> goodVOList = goodsService.listByIds(goodIdList);
List<GoodVO> goodVOList = goodService.listByIds(goodIdList);
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("order", OrderVO.convertFrom(order));
resultMap.put("orderItem", orderDetailVOList);

View File

@@ -8,7 +8,7 @@ import java.util.List;
@Mapper
@Repository
public interface GoodsCategoryDao {
public interface GoodCategoryDao {
List<GoodCategory> list();

View File

@@ -1,6 +1,7 @@
package com.cxyxiaomo.epp.shop.dao;
import com.cxyxiaomo.epp.common.pojo.Good;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@@ -9,7 +10,7 @@ import java.util.List;
@Mapper
@Repository
public interface GoodsDao {
public interface GoodDao {
List<Good> list(@Param("cateId") Integer cateId, @Param("searchText") String searchText);
@@ -24,4 +25,22 @@ public interface GoodsDao {
Integer update(Good good);
Integer deleteById(Integer id);
public boolean addGood(Good good);
public boolean updateGood(Good good);
public Good getGoodById(Long id);
public List<Good> getGoodList(GoodVO goodVO);
public boolean deleteGoodById(Long goodId);
}

View File

@@ -0,0 +1,82 @@
package com.cxyxiaomo.epp.shop.service;
import com.cxyxiaomo.epp.common.pojo.Good;
import com.cxyxiaomo.epp.common.pojo.GoodCategory;
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import com.cxyxiaomo.epp.shop.dao.GoodCategoryDao;
import com.cxyxiaomo.epp.shop.dao.GoodDao;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class GoodService {
@Resource
GoodDao goodDao;
@Resource
GoodCategoryDao goodCategoryDao;
public List<GoodVO> list(Integer cateId, String searchText) {
List<Good> list = goodDao.list(cateId, searchText);
List<GoodVO> goodVOS = GoodVO.convertFrom(list);
return goodVOS;
}
public GoodVO getById(Long id) {
Good good = goodDao.getById(id);
GoodVO goodVO = GoodVO.convertFrom(good);
return goodVO;
}
public List<GoodCategoryVO> cateListVO() {
List<GoodCategory> list = goodCategoryDao.list();
List<GoodCategoryVO> goodCategoryVOList = GoodCategoryVO.convertFrom(list);
return goodCategoryVOList;
}
public List<GoodVO> listByIds(List<Long> goodIdList) {
if (goodIdList == null || goodIdList.size() == 0) {
return new ArrayList<>();
}
List<Good> list = goodDao.listByIds(goodIdList);
List<GoodVO> goodVOList = GoodVO.convertFrom(list);
return goodVOList;
}
public List<GoodCategory> getCateList() {
List<GoodCategory> list = goodCategoryDao.list();
return list;
}
public Good getGoodById(Long id) {
if (id == null) {
return null;
}
return goodDao.getGoodById(id);
}
public List<Good> getGoodList(GoodVO goodVO) {
List<Good> goodList = goodDao.getGoodList(goodVO);
return goodList;
}
public boolean addGood(Good good) {
good.setId(null);
return goodDao.addGood(good);
}
public boolean updateGood(Good good) {
return goodDao.updateGood(good);
}
public boolean deleteGood(Long goodId) {
return goodDao.deleteGoodById(goodId);
}
}

View File

@@ -1,50 +0,0 @@
package com.cxyxiaomo.epp.shop.service;
import com.cxyxiaomo.epp.common.pojo.Good;
import com.cxyxiaomo.epp.common.pojo.GoodCategory;
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import com.cxyxiaomo.epp.shop.dao.GoodsCategoryDao;
import com.cxyxiaomo.epp.shop.dao.GoodsDao;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class GoodsService {
@Resource
GoodsDao goodsDao;
@Resource
GoodsCategoryDao goodsCategoryDao;
public List<GoodVO> list(Integer cateId, String searchText) {
List<Good> list = goodsDao.list(cateId, searchText);
List<GoodVO> goodVOS = GoodVO.convertFrom(list);
return goodVOS;
}
public GoodVO getById(Long id) {
Good good = goodsDao.getById(id);
GoodVO goodVO = GoodVO.convertFrom(good);
return goodVO;
}
public List<GoodCategoryVO> cateList() {
List<GoodCategory> list = goodsCategoryDao.list();
List<GoodCategoryVO> goodCategoryVOList = GoodCategoryVO.convertFrom(list);
return goodCategoryVOList;
}
public List<GoodVO> listByIds(List<Long> goodIdList) {
if (goodIdList == null || goodIdList.size() == 0) {
return new ArrayList<>();
}
List<Good> list = goodsDao.listByIds(goodIdList);
List<GoodVO> goodVOList = GoodVO.convertFrom(list);
return goodVOList;
}
}

View File

@@ -6,7 +6,7 @@ import com.cxyxiaomo.epp.common.pojo.Order;
import com.cxyxiaomo.epp.common.pojo.OrderDetail;
import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
import com.cxyxiaomo.epp.common.vo.OrderDetailVO;
import com.cxyxiaomo.epp.shop.dao.GoodsDao;
import com.cxyxiaomo.epp.shop.dao.GoodDao;
import com.cxyxiaomo.epp.shop.dao.OrderDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -21,7 +21,7 @@ import java.util.List;
public class OrderService {
@Resource
private GoodsDao goodsDao;
private GoodDao goodDao;
@Resource
private OrderDao orderDao;
@@ -59,7 +59,7 @@ public class OrderService {
}
// 查询商品价格
Good good = goodsDao.selectById(orderItem.getGoodId());
Good good = goodDao.selectById(orderItem.getGoodId());
if (good == null || good.getDeleted() || good.getRetailPrice() == null) {
throw new IllegalArgumentException("商品已删除或状态异常,无法下单");
}

View File

@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodsCategoryDao">
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodCategoryDao">
<select id="list" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
SELECT * FROM goods_category
WHERE 1 = 1

View File

@@ -0,0 +1,221 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodDao">
<resultMap id="GoodsResultMap" type="com.cxyxiaomo.epp.common.pojo.Good">
<id column="id" property="id" />
<result column="goods_name" property="goodsName" />
<result column="category_id" property="categoryId" />
<result column="brand" property="brand" />
<result column="gallery" property="gallery" />
<result column="brief" property="brief" />
<result column="is_on_sale" property="isOnSale" />
<result column="sort_order" property="sortOrder" />
<result column="pic_url" property="picUrl" />
<result column="type" property="type" />
<result column="unit" property="unit" />
<result column="counter_price" property="counterPrice" />
<result column="retail_price" property="retailPrice" />
<result column="detail" property="detail" />
<result column="deleted" property="deleted" />
</resultMap>
<!--<insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Good">-->
<!-- INSERT INTO report (`user_id`, `name`, `address`, `time`, `temperature`)-->
<!-- VALUES (#{userId}, #{name}, #{address}, #{time}, #{temperature})-->
<!--</insert>-->
<select id="list" resultType="com.cxyxiaomo.epp.common.pojo.Good">
SELECT *
FROM goods
WHERE 1 = 1
<if test="cateId != null">
AND category_id = #{cateId}
</if>
<if test="searchText != null">
AND goods_name LIKE concat('%',#{searchText,jdbcType=VARCHAR},'%')
</if>
order by `sort_order` asc
</select>
<select id="getById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.Good">
SELECT *
FROM goods
WHERE id = #{id}
order by `sort_order` asc
</select>
<select id="selectById" resultMap="GoodsResultMap">
SELECT *
FROM goods
WHERE id = #{id}
</select>
<select id="listByIds" parameterType="java.util.List" resultType="com.cxyxiaomo.epp.common.pojo.Good">
SELECT *
FROM goods
<where>
<if test="list != null and list.size > 0">
AND id IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
AND deleted = 0
</where>
</select>
<!--<select id="selectByCategoryId" resultMap="GoodsResultMap">-->
<!-- SELECT *-->
<!-- FROM goods-->
<!-- WHERE category_id = #{categoryId}-->
<!--</select>-->
<!--<select id="selectAll" resultMap="GoodsResultMap">-->
<!-- SELECT *-->
<!-- FROM goods-->
<!--</select>-->
<insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Good" useGeneratedKeys="true" keyProperty="id">
INSERT INTO goods (goods_name, category_id, brand, gallery, brief, is_on_sale, sort_order, pic_url, type, unit, counter_price, retail_price, detail, deleted)
VALUES (#{goodsName}, #{categoryId}, #{brand}, #{gallery}, #{brief}, #{isOnSale}, #{sortOrder}, #{picUrl}, #{type}, #{unit}, #{counterPrice}, #{retailPrice}, #{detail}, #{deleted})
</insert>
<update id="update" parameterType="com.cxyxiaomo.epp.common.pojo.Good">
UPDATE goods
SET goods_name = #{goodsName},
category_id = #{categoryId},
brand = #{brand},
gallery = #{gallery},
brief = #{brief},
is_on_sale = #{isOnSale},
sort_order = #{sortOrder},
pic_url = #{picUrl},
type = #{type},
unit = #{unit},
counter_price = #{counterPrice},
retail_price = #{retailPrice},
detail = #{detail},
deleted = #{deleted}
WHERE id = #{id}
</update>
<delete id="deleteById">
DELETE FROM goods
WHERE id = #{id}
</delete>
<!--<insert id="addGood" parameterType="com.cxyxiaomo.epp.common.pojo.Good">-->
<!-- INSERT INTO user (username, `password`, realname, id_number, phone_number, role_id, building_id, doorplate,-->
<!-- permission, permission_time)-->
<!-- VALUES (#{username}, #{password}, #{realname}, #{idNumber}, #{phoneNumber}, #{roleId}, #{buildingId},-->
<!-- #{doorplate}, #{permission}, #{permissionTime})-->
<!--</insert>-->
<!--<update id="updateGood" parameterType="com.cxyxiaomo.epp.common.pojo.Good">-->
<!-- UPDATE user-->
<!-- <set>-->
<!-- <if test="username != null and username != ''">-->
<!-- username = #{username},-->
<!-- </if>-->
<!-- <if test="password != null and password != ''">-->
<!-- `password` = #{password},-->
<!-- </if>-->
<!-- <if test="realname != null and realname != ''">-->
<!-- realname = #{realname},-->
<!-- </if>-->
<!-- <if test="idNumber != null and idNumber != ''">-->
<!-- id_number = #{idNumber},-->
<!-- </if>-->
<!-- <if test="phoneNumber != null and phoneNumber != ''">-->
<!-- phone_number = #{phoneNumber},-->
<!-- </if>-->
<!-- <if test="roleId != null">-->
<!-- role_id = #{roleId},-->
<!-- </if>-->
<!-- <if test="buildingId != null and buildingId != ''">-->
<!-- building_id = #{buildingId},-->
<!-- </if>-->
<!-- <if test="doorplate != null and doorplate != ''">-->
<!-- doorplate = #{doorplate},-->
<!-- </if>-->
<!-- <if test="permission != null">-->
<!-- permission = #{permission},-->
<!-- </if>-->
<!-- <if test="permissionTime != null">-->
<!-- permission_time = #{permissionTime},-->
<!-- </if>-->
<!-- </set>-->
<!-- WHERE id = #{id}-->
<!--</update>-->
<!--<select id="getGoodById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.Good">-->
<!-- SELECT *-->
<!-- FROM user-->
<!-- WHERE id = #{id}-->
<!--</select>-->
<select id="getGoodList" resultType="com.cxyxiaomo.epp.common.pojo.Good">
select *
from goods
where 1 = 1
<if test="id != null">
AND id = #{id}
</if>
<if test="goodsName != null &amp;&amp; goodsName != ''">
AND goods_name LIKE concat('%',#{goodsName,jdbcType=VARCHAR},'%')
</if>
<if test="categoryId != null">
AND category_id = #{categoryId}
</if>
<if test="brand != null &amp;&amp; brand != ''">
AND brand LIKE concat('%',#{brand,jdbcType=VARCHAR},'%')
</if>
<if test="gallery != null &amp;&amp; gallery != ''">
AND gallery LIKE concat('%',#{gallery,jdbcType=VARCHAR},'%')
</if>
<if test="brief != null &amp;&amp; brief != ''">
AND brief LIKE concat('%',#{brief,jdbcType=VARCHAR},'%')
</if>
<if test="isOnSale != null">
AND is_on_sale = #{isOnSale}
</if>
<if test="sortOrder != null">
AND sort_order = #{sortOrder}
</if>
<if test="picUrl != null &amp;&amp; picUrl != ''">
AND pic_url LIKE concat('%',#{picUrl,jdbcType=VARCHAR},'%')
</if>
<if test="type != null">
AND type = #{type}
</if>
<if test="unit != null &amp;&amp; unit != ''">
AND unit LIKE concat('%',#{unit,jdbcType=VARCHAR},'%')
</if>
<if test="counterPrice != null">
AND counter_price = #{counterPrice}
</if>
<if test="retailPrice != null">
AND retail_price = #{retailPrice}
</if>
</select>
<!--<delete id="deleteGoodById">-->
<!-- DELETE-->
<!-- FROM user-->
<!-- WHERE id = #{userId}-->
<!--</delete>-->
</mapper>

View File

@@ -1,106 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodsDao">
<resultMap id="GoodsResultMap" type="com.cxyxiaomo.epp.common.pojo.Good">
<id column="id" property="id" />
<result column="goods_name" property="goodsName" />
<result column="category_id" property="categoryId" />
<result column="brand" property="brand" />
<result column="gallery" property="gallery" />
<result column="brief" property="brief" />
<result column="is_on_sale" property="isOnSale" />
<result column="sort_order" property="sortOrder" />
<result column="pic_url" property="picUrl" />
<result column="type" property="type" />
<result column="unit" property="unit" />
<result column="counter_price" property="counterPrice" />
<result column="retail_price" property="retailPrice" />
<result column="detail" property="detail" />
<result column="deleted" property="deleted" />
</resultMap>
<!--<insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Good">-->
<!-- INSERT INTO report (`user_id`, `name`, `address`, `time`, `temperature`)-->
<!-- VALUES (#{userId}, #{name}, #{address}, #{time}, #{temperature})-->
<!--</insert>-->
<select id="list" resultType="com.cxyxiaomo.epp.common.pojo.Good">
SELECT *
FROM goods
WHERE 1 = 1
<if test="cateId != null">
AND category_id = #{cateId}
</if>
<if test="searchText != null">
AND goods_name LIKE concat('%',#{searchText,jdbcType=VARCHAR},'%')
</if>
order by `sort_order` asc
</select>
<select id="getById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.Good">
SELECT *
FROM goods
WHERE id = #{id}
order by `sort_order` asc
</select>
<select id="selectById" resultMap="GoodsResultMap">
SELECT *
FROM goods
WHERE id = #{id}
</select>
<select id="listByIds" parameterType="java.util.List" resultType="com.cxyxiaomo.epp.common.pojo.Good">
SELECT *
FROM goods
<where>
<if test="list != null and list.size > 0">
AND id IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
AND deleted = 0
</where>
</select>
<!--<select id="selectByCategoryId" resultMap="GoodsResultMap">-->
<!-- SELECT *-->
<!-- FROM goods-->
<!-- WHERE category_id = #{categoryId}-->
<!--</select>-->
<!--<select id="selectAll" resultMap="GoodsResultMap">-->
<!-- SELECT *-->
<!-- FROM goods-->
<!--</select>-->
<insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Good" useGeneratedKeys="true" keyProperty="id">
INSERT INTO goods (goods_name, category_id, brand, gallery, brief, is_on_sale, sort_order, pic_url, type, unit, counter_price, retail_price, detail, deleted)
VALUES (#{goodsName}, #{categoryId}, #{brand}, #{gallery}, #{brief}, #{isOnSale}, #{sortOrder}, #{picUrl}, #{type}, #{unit}, #{counterPrice}, #{retailPrice}, #{detail}, #{deleted})
</insert>
<update id="update" parameterType="com.cxyxiaomo.epp.common.pojo.Good">
UPDATE goods
SET goods_name = #{goodsName},
category_id = #{categoryId},
brand = #{brand},
gallery = #{gallery},
brief = #{brief},
is_on_sale = #{isOnSale},
sort_order = #{sortOrder},
pic_url = #{picUrl},
type = #{type},
unit = #{unit},
counter_price = #{counterPrice},
retail_price = #{retailPrice},
detail = #{detail},
deleted = #{deleted}
WHERE id = #{id}
</update>
<delete id="deleteById">
DELETE FROM goods
WHERE id = #{id}
</delete>
</mapper>