gc-core/src/main/java/com/xzx/gc/common/constant/Constants.java
@@ -193,6 +193,7 @@ public static final String SYS_MODUL_NAME="消息模块"; public static final String PAY_MODUL_NAME="支付模块"; public static final String ROLE_MODUL_NAME="权限模块"; public static final String SCORESHOP_MODUL_NAME="积分商城模块"; //最小正常文件大小 gc-core/src/main/java/com/xzx/gc/common/entity/BaseEntity.java
@@ -1,19 +1,23 @@ package com.xzx.gc.common.entity; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import java.io.Serializable; import java.util.Date; @Data public class BaseEntity { public class BaseEntity implements Serializable { private static final long serialVersionUID = 1L; private String createBy; private String createdBy; private Date createTime; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date createdTime; private String delFlag; gc-core/src/main/java/com/xzx/gc/model/admin/GoodsCategoryModel.java
New file @@ -0,0 +1,29 @@ package com.xzx.gc.model.admin; import com.alibaba.fastjson.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.util.Date; import java.util.List; @Data public class GoodsCategoryModel implements Serializable { private long id ; @ApiModelProperty(value="分类名称",required=true) private String name; @ApiModelProperty(value="类别标识",required=true) private String categoryIden; @ApiModelProperty(value="父分类",required=true) private Long parentId; @JSONField(format="yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value="创建时间") private Date createdTime; private String createdBy; int page; int limit; } gc-shop/src/main/java/com/xzx/gc/shop/controller/GoodsController.java
New file @@ -0,0 +1,175 @@ package com.xzx.gc.shop.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.xzx.gc.common.constant.CommonEnum; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.dto.log.OperationAppLog; import com.xzx.gc.common.request.BaseController; import com.xzx.gc.entity.ScoreGoodsCategory; import com.xzx.gc.model.JsonResult; import com.xzx.gc.model.admin.GoodsCategoryModel; import com.xzx.gc.shop.dto.AddGoodsCategoryDto; import com.xzx.gc.shop.dto.DeleteGoodsCategoryDto; import com.xzx.gc.shop.dto.QueryGoodsCategoryListDto; import com.xzx.gc.shop.dto.UpdateGoodsCategoryDto; import com.xzx.gc.shop.mapper.ScoreGoodsCategoryMapper; import com.xzx.gc.shop.service.GoodsService; import com.xzx.gc.shop.vo.QueryGoodsCategoryListVo; import com.xzx.gc.shop.vo.ViewGoodsCategoryVo; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; import java.util.Map; @RestController @Api(tags = {"积分商城--商品管理"}) @Slf4j public class GoodsController extends BaseController { @Resource private GoodsService goodsService; @Resource private ScoreGoodsCategoryMapper scoreGoodsCategoryMapper; /** * 查询商品分类列表 * xzx_score_goods_category商品分类 */ @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/queryGoodsCategoryList.json") @ApiResponses({@ApiResponse( code = 200, message = "success", response = QueryGoodsCategoryListVo.class)}) @ApiOperation(value = "商品分类管理-商品分类列表", notes = "test: 仅0有正确返回") public JsonResult<Map<String, Object>> queryGoodsCategoryList(@RequestBody QueryGoodsCategoryListDto model) { Map<String, Object> result = goodsService.queryGoodsCategoryList(model); return JsonResult.success(result); } /** * 添加商品分类 */ @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/addGoodsCategory.json") @ApiOperation(value = "商品分类管理-添加商品分类", notes = "test: 仅0有正确返回") public JsonResult<String> addGoodsCategory(@RequestBody AddGoodsCategoryDto model, HttpServletRequest request) { String name = model.getName(); if(StrUtil.isEmpty(name)){ return JsonResult.failMessage("分类名称不能为空!"); } String categoryIden = model.getCategoryIden(); if(StrUtil.isEmpty(categoryIden)){ return JsonResult.failMessage("分类代码不能为空!"); } Long parentId = model.getParentId(); if(StrUtil.isEmpty(parentId.toString())){ return JsonResult.failMessage("父类不能为空!"); } GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel(); goodsCategoryModel.setName(name); goodsCategoryModel.setCategoryIden(categoryIden); goodsCategoryModel.setParentId(parentId); List<QueryGoodsCategoryListVo> maps = scoreGoodsCategoryMapper.queryGoodsCategoryList(goodsCategoryModel); if(CollUtil.isNotEmpty(maps)){ return JsonResult.failMessage("分类不能重复添加!"); } goodsCategoryModel.setCreatedBy(getAdminName(request)); goodsCategoryModel.setCreatedTime(new Date()); Long scoreGoodsCategoryId = goodsService.addGoodsCategory(goodsCategoryModel); if(scoreGoodsCategoryId > 0){ OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request)) .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-添加商品分类-" + scoreGoodsCategoryId).build(); mqUtil.sendApp(build); return JsonResult.success("操作成功!"); }else{ return JsonResult.failMessage("操作失败!"); } } /** * 删除添加商品分类 */ @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/deleteGoodsCategory.json") @ApiOperation(value="商品分类管理-删除添加商品分类", notes="test: 仅0有正确返回") public JsonResult deleteGoodsCategory(@RequestBody DeleteGoodsCategoryDto model, HttpServletRequest request) { long id = model.getId(); ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id); if(ObjectUtil.isEmpty(scoreGoodsCategory)){ return JsonResult.failMessage("分类不存在!"); } goodsService.deleteGoodsCategory(id); OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request)) .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-删除添加商品分类-"+id).build(); mqUtil.sendApp(build); return new JsonResult().success("操作成功!"); } /** * 查看商品分类详情 */ @GetMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/viewGoodsCategory/{id}") @ApiResponses({@ApiResponse( code = 200, message = "success", response = ViewGoodsCategoryVo.class)}) @ApiOperation(value="商品分类管理-查看商品分类详情", notes="test: 仅0有正确返回") public JsonResult<ViewGoodsCategoryVo> viewGoodsCategory(@PathVariable long id) { ViewGoodsCategoryVo viewGoodsCategoryVo = goodsService.viewGoodsCategoryById(id); return JsonResult.success(viewGoodsCategoryVo); } /** * 更新商品分类 * @param model * @return */ @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/updateGoodsCategory.json") @ApiOperation(value="商品分类管理-更新商品分类", notes="test: 仅0有正确返回") public JsonResult updateGoodsCategory(@RequestBody UpdateGoodsCategoryDto model, HttpServletRequest request) { long id = model.getId(); ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id); if(ObjectUtil.isEmpty(scoreGoodsCategory)){ return JsonResult.failMessage("分类不存在!"); } String name = model.getName(); if(StrUtil.isEmpty(name)){ return JsonResult.failMessage("分类名称不能为空!"); } if(!name.equals(scoreGoodsCategory.getName())){ scoreGoodsCategory.setName(name); } String categoryIden = model.getCategoryIden(); if(StrUtil.isEmpty(categoryIden)){ return JsonResult.failMessage("分类代码不能为空!"); } if(!categoryIden.equals(scoreGoodsCategory.getCategoryIden())){ scoreGoodsCategory.setCategoryIden(categoryIden); } Long parentId = model.getParentId(); if(StrUtil.isEmpty(parentId.toString())){ return JsonResult.failMessage("父类不能为空!"); } if(!parentId.equals(scoreGoodsCategory.getParentId())){ scoreGoodsCategory.setParentId(parentId); } GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel(); goodsCategoryModel.setName(name); goodsCategoryModel.setCategoryIden(categoryIden); goodsCategoryModel.setParentId(parentId); List<QueryGoodsCategoryListVo> maps = scoreGoodsCategoryMapper.queryGoodsCategoryList(goodsCategoryModel); if(CollUtil.isNotEmpty(maps)){ return JsonResult.failMessage("分类不能重复添加!"); } goodsCategoryModel.setId(id); goodsService.updateGoodsCategory(goodsCategoryModel); OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request)) .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-更新商品分类-" + id).build(); mqUtil.sendApp(build); return JsonResult.success("操作成功!"); } } gc-shop/src/main/java/com/xzx/gc/shop/dto/AddGoodsCategoryDto.java
New file @@ -0,0 +1,21 @@ package com.xzx.gc.shop.dto; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.util.Date; @Data public class AddGoodsCategoryDto implements Serializable { @ApiModelProperty(value="分类名称") private String name; @ApiModelProperty(value="类别标识") private String categoryIden; @ApiModelProperty(value="父分类") private Long parentId; } gc-shop/src/main/java/com/xzx/gc/shop/dto/DeleteGoodsCategoryDto.java
New file @@ -0,0 +1,8 @@ package com.xzx.gc.shop.dto; import lombok.Data; @Data public class DeleteGoodsCategoryDto { private long id; } gc-shop/src/main/java/com/xzx/gc/shop/dto/QueryGoodsCategoryListDto.java
New file @@ -0,0 +1,21 @@ package com.xzx.gc.shop.dto; import com.alibaba.fastjson.annotation.JSONField; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.util.Date; @Data public class QueryGoodsCategoryListDto implements Serializable { @ApiModelProperty(value="分类名称",required=true) private String name; @ApiModelProperty(value="第几页",required=true) private int page; @ApiModelProperty(value="每一页数量",required=true) private int limit; } gc-shop/src/main/java/com/xzx/gc/shop/dto/UpdateGoodsCategoryDto.java
New file @@ -0,0 +1,16 @@ package com.xzx.gc.shop.dto; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class UpdateGoodsCategoryDto { private long id; @ApiModelProperty(value="分类名称") private String name; @ApiModelProperty(value="类别标识") private String categoryIden; @ApiModelProperty(value="父分类") private Long parentId; } gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreGoodsCategoryMapper.java
@@ -1,7 +1,14 @@ package com.xzx.gc.shop.mapper; import com.xzx.gc.entity.ScoreGoodsCategory; import com.xzx.gc.model.admin.GoodsCategoryModel; import com.xzx.gc.shop.vo.QueryGoodsCategoryListVo; import com.xzx.gc.util.GcMapper; import java.util.List; public interface ScoreGoodsCategoryMapper extends GcMapper<ScoreGoodsCategory> { List<QueryGoodsCategoryListVo> queryGoodsCategoryList(GoodsCategoryModel goodsCategoryModel); } gc-shop/src/main/java/com/xzx/gc/shop/service/GoodsService.java
New file @@ -0,0 +1,92 @@ package com.xzx.gc.shop.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzx.gc.common.constant.CommonEnum; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.dto.log.OperationAppLog; import com.xzx.gc.common.utils.MqUtil; import com.xzx.gc.entity.CoreUser; import com.xzx.gc.entity.ScoreGoodsCategory; import com.xzx.gc.model.JsonResult; import com.xzx.gc.model.admin.GoodsCategoryModel; import com.xzx.gc.shop.dto.QueryGoodsCategoryListDto; import com.xzx.gc.shop.mapper.ScoreGoodsCategoryMapper; import com.xzx.gc.shop.vo.QueryGoodsCategoryListVo; import com.xzx.gc.shop.vo.ViewGoodsCategoryVo; import com.xzx.gc.util.SessionUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; @Service @Transactional @Slf4j public class GoodsService { @Resource ScoreGoodsCategoryMapper scoreGoodsCategoryMapper; @Autowired private MqUtil mqUtil; public Map<String, Object> queryGoodsCategoryList(QueryGoodsCategoryListDto model) { String name = model.getName(); GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel(); goodsCategoryModel.setName(name); PageHelper.startPage(model.getPage(), model.getLimit()); List<QueryGoodsCategoryListVo> maps = scoreGoodsCategoryMapper.queryGoodsCategoryList(goodsCategoryModel); PageInfo pageInfo = new PageInfo(maps); int count = Convert.toInt(pageInfo.getTotal()); Map<String, Object> map = new HashMap<>(); map.put("data", maps); map.put("count", count); map.put("code", 0); return map; } public Long addGoodsCategory(GoodsCategoryModel model) { ScoreGoodsCategory scoreGoodsCategory = new ScoreGoodsCategory(); scoreGoodsCategory.setName(model.getName()); scoreGoodsCategory.setCategoryIden(model.getCategoryIden()); scoreGoodsCategory.setParentId(model.getParentId()); scoreGoodsCategory.setCreatedBy(model.getCreatedBy()); scoreGoodsCategory.setCreatedTime(model.getCreatedTime()); scoreGoodsCategoryMapper.insert(scoreGoodsCategory); return scoreGoodsCategory.getId(); } public void deleteGoodsCategory(long id) { scoreGoodsCategoryMapper.deleteByPrimaryKey(id); } public ViewGoodsCategoryVo viewGoodsCategoryById(long id) { ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id); ViewGoodsCategoryVo viewGoodsCategoryVo = new ViewGoodsCategoryVo(); viewGoodsCategoryVo.setId(scoreGoodsCategory.getId()); viewGoodsCategoryVo.setName(scoreGoodsCategory.getName()); viewGoodsCategoryVo.setCategoryIden(scoreGoodsCategory.getCategoryIden()); viewGoodsCategoryVo.setParentId(scoreGoodsCategory.getParentId()); return viewGoodsCategoryVo; } public void updateGoodsCategory(GoodsCategoryModel model) { long id = model.getId(); ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id); scoreGoodsCategory.setName(model.getName()); scoreGoodsCategory.setCategoryIden(model.getCategoryIden()); scoreGoodsCategory.setParentId(model.getParentId()); scoreGoodsCategoryMapper.updateByPrimaryKey(scoreGoodsCategory); } } gc-shop/src/main/java/com/xzx/gc/shop/vo/QueryGoodsCategoryListVo.java
New file @@ -0,0 +1,30 @@ package com.xzx.gc.shop.vo; import com.alibaba.fastjson.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Date; @Data @ApiModel(value = "QueryGoodsCategoryListVo", description = "信息返回") public class QueryGoodsCategoryListVo { private long id ; @ApiModelProperty(value="分类名称") private String name; @ApiModelProperty(value="类别标识") private String categoryIden; @ApiModelProperty(value="父分类") private Long parentId; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @ApiModelProperty(value="创建时间") private Date createdTime; @ApiModelProperty(value="创建人") private String createdBy; } gc-shop/src/main/java/com/xzx/gc/shop/vo/ViewGoodsCategoryVo.java
New file @@ -0,0 +1,17 @@ package com.xzx.gc.shop.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @ApiModel(value = "ViewGoodsCategoryVo", description = "返回") public class ViewGoodsCategoryVo { private long id ; @ApiModelProperty(value="分类名称") private String name; @ApiModelProperty(value="类别标识") private String categoryIden; @ApiModelProperty(value="父分类") private Long parentId; } gc-shop/src/main/resources/mapper/shop/ScoreGoodsCategoryMapper.xml
New file @@ -0,0 +1,23 @@ <?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.ScoreGoodsCategoryMapper"> <select id="queryGoodsCategoryList" resultType="com.xzx.gc.shop.vo.QueryGoodsCategoryListVo"> SELECT * FROM xzx_score_goods_category a WHERE 1 = 1 <if test="name != null and name != ''"> and a.name=#{name} </if> <if test="categoryIden != null and categoryIden != ''"> and a.category_iden=#{categoryIden} </if> <if test="parentId != null and parentId != ''"> and a.parent_id=#{parentId} </if> order by a.CREATED_TIME desc </select> </mapper> pom.xml
@@ -23,6 +23,7 @@ <module>gc-sys</module> <module>gc-pay</module> <module>gc-role</module> <module>gc-shop</module> <!--<module>gc-admin</module>--> </modules> <packaging>pom</packaging>