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.*; import com.xzx.gc.shop.mapper.ScoreGoodsCategoryMapper; import com.xzx.gc.shop.service.GoodsService; import com.xzx.gc.shop.vo.*; 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 AdminGoodsCategoryController 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> queryGoodsCategoryList(@RequestBody QueryGoodsCategoryListDto model) { Map result = goodsService.queryGoodsCategoryList(model); return JsonResult.success(result); } /** * 查询商品分类--所有一级分类 * xzx_score_goods_category商品分类 */ @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/viewGoodsCategoryList.json") @ApiResponses({@ApiResponse( code = 200, message = "success", response = ViewGoodsCategoryListVo.class)}) @ApiOperation(value = "商品分类管理--所有一级分类", notes = "test: 仅0有正确返回") public JsonResult> viewGoodsCategoryList(@RequestBody ViewGoodsCategoryListDto viewGoodsCategoryListDto) { List result = goodsService.viewGoodsCategoryList(viewGoodsCategoryListDto); return JsonResult.success(result); } /** * 添加商品分类 */ @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/addGoodsCategory.json") @ApiOperation(value = "商品分类管理-添加商品分类", notes = "test: 仅0有正确返回") public JsonResult 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 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 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); } if(parentId.equals(id)){ return JsonResult.failMessage("父类不能为自己!"); } GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel(); goodsCategoryModel.setName(name); goodsCategoryModel.setCategoryIden(categoryIden); goodsCategoryModel.setParentId(parentId); List 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("操作成功!"); } }