| package com.xzx.gc.shop.controller; | 
|   | 
| import cn.hutool.core.collection.CollUtil; | 
| import cn.hutool.core.convert.Convert; | 
| import cn.hutool.core.util.ObjectUtil; | 
| 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.ScoreGoods; | 
| import com.xzx.gc.model.JsonResult; | 
| import com.xzx.gc.shop.dto.*; | 
| import com.xzx.gc.shop.mapper.ScoreGoodsMapper; | 
| import com.xzx.gc.shop.service.GoodsService; | 
| import com.xzx.gc.shop.vo.QueryGoodsListVo; | 
| import com.xzx.gc.shop.vo.ViewGoodsVo; | 
| import io.swagger.annotations.Api; | 
| import io.swagger.annotations.ApiOperation; | 
| import io.swagger.annotations.ApiResponse; | 
| import io.swagger.annotations.ApiResponses; | 
| 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 AdminGoodsController extends BaseController { | 
|   | 
|     @Resource | 
|     private GoodsService goodsService; | 
|   | 
|     @Resource | 
|     private ScoreGoodsMapper scoreGoodsMapper; | 
|     /** | 
|      * 查询商品列表 | 
|      * xzx_score_goods 积分商品表 | 
|      */ | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/queryGoodsList.json") | 
|     @ApiResponses({@ApiResponse( code = 200, message = "success", response = QueryGoodsListVo.class)}) | 
|     @ApiOperation(value = "商品管理-商品列表", notes = "test: 仅0有正确返回") | 
|     public JsonResult<Map<String, Object>> queryGoodsList(@RequestBody QueryGoodsListDto model) { | 
|         Map<String, Object> result = goodsService.queryGoodsList(model); | 
|         return JsonResult.success(result); | 
|     } | 
|   | 
|     /** | 
|      * 添加商品 | 
|      */ | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/addGoods.json") | 
|     @ApiOperation(value = "商品管理-添加商品", notes = "test: 仅0有正确返回") | 
|     public JsonResult<String> addGoods(@RequestBody AddGoodsDto model, HttpServletRequest request) { | 
|         List<ScoreGoodsStyleDto> scoreGoodsStyles = model.getScoreGoodsStyles(); | 
|         if(CollUtil.isEmpty(scoreGoodsStyles)){ | 
|             return JsonResult.failMessage("样式不能为空!"); | 
|         } | 
|         model.setCreatedBy(getAdminName(request)); | 
|         model.setCreatedTime(new Date()); | 
|         Long scoreGoodsId = goodsService.addGoods(model); | 
|         if(scoreGoodsId > 0){ | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request)) | 
|                     .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-添加商品-" + scoreGoodsId).build(); | 
|             mqUtil.sendApp(build); | 
|             return  JsonResult.success("操作成功!"); | 
|         }else{ | 
|             return  JsonResult.failMessage("操作失败!"); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 删除商品 | 
|      */ | 
|   | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/deleteGoods.json") | 
|     @ApiOperation(value="商品管理-删除商品", notes="test: 仅0有正确返回") | 
|     public JsonResult deleteGoods(@RequestBody DeleteGoodsDto model, HttpServletRequest request) { | 
|         long id = model.getId(); | 
|         ScoreGoods scoreGoods = scoreGoodsMapper.selectByPrimaryKey(id); | 
|         if(ObjectUtil.isEmpty(scoreGoods)){ | 
|             return JsonResult.failMessage("商品不存在!"); | 
|         } | 
|         //下架商品才能删除 | 
|         Integer isSale = scoreGoods.getIsSale(); | 
|         if(ScoreGoods.ISSALE_YES == isSale){ | 
|             return JsonResult.failMessage("只允许删除下架商品!"); | 
|         } | 
|         goodsService.deleteGoods(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("操作成功!"); | 
|     } | 
|   | 
|     /** | 
|      * 查看商品详情 | 
|      */ | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/viewGoods.json") | 
|     @ApiResponses({@ApiResponse( code = 200, message = "success", response = ViewGoodsVo.class)}) | 
|     @ApiOperation(value="商品管理-查看商品详情", notes="test: 仅0有正确返回") | 
|     public JsonResult<ViewGoodsVo> viewGoods(@RequestBody ViewGoodsDto viewGoodsDto) { | 
|         Long id = viewGoodsDto.getId(); | 
|         ViewGoodsVo viewGoodsVo = goodsService.viewGoods(id); | 
|         return JsonResult.success(viewGoodsVo); | 
|     } | 
|   | 
|     /** | 
|      * 更新商品 | 
|      * @param model | 
|      * @return | 
|      */ | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/updateGoods.json") | 
|     @ApiOperation(value="商品管理-更新商品", notes="test: 仅0有正确返回") | 
|     public JsonResult updateGoods(@RequestBody UpdateGoodsDto model, HttpServletRequest request) { | 
|         long id = model.getId(); | 
|         ScoreGoods scoreGoods = scoreGoodsMapper.selectByPrimaryKey(id); | 
|         if(ObjectUtil.isEmpty(scoreGoods)){ | 
|             return JsonResult.failMessage("商品不存在!"); | 
|         } | 
|         //下架商品才能更新 | 
|         Integer isSale = scoreGoods.getIsSale(); | 
|         if(ScoreGoods.ISSALE_YES == isSale){ | 
|             return JsonResult.failMessage("请先下架商品!"); | 
|         } | 
|         List<ScoreGoodsStyleDto> scoreGoodsStyles = model.getScoreGoodsStyles(); | 
|         if(CollUtil.isEmpty(scoreGoodsStyles)){ | 
|             return JsonResult.failMessage("样式不能为空!"); | 
|         } | 
|         goodsService.updateGoods(model); | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request)) | 
|                 .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-更新商品-" + id).build(); | 
|         mqUtil.sendApp(build); | 
|         return  JsonResult.success("操作成功!"); | 
|     } | 
|   | 
|     /** | 
|      * 商品上下架 | 
|      */ | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/saleGoods.json") | 
|     @ApiOperation(value="商品管理-商品上下架", notes="test: 仅0有正确返回") | 
|     public JsonResult saleGoods(@RequestBody SaleGoodsDto model, HttpServletRequest request) { | 
|         long id = model.getId(); | 
|         ScoreGoods scoreGoods = scoreGoodsMapper.selectById(id); | 
|         if(ObjectUtil.isEmpty(scoreGoods)){ | 
|             return JsonResult.failMessage("商品不存在!"); | 
|         } | 
|         short delFlag = scoreGoods.getDelFlag(); | 
|         if(Convert.toShort(Constants.DEL_FLAG) == delFlag){ | 
|             return JsonResult.failMessage("当前商品已删除!"); | 
|         } | 
|         goodsService.saleGoods(id, model.getIsSale()); | 
|         String upDown = ""; | 
|         if(model.getIsSale() == ScoreGoods.ISSALE_YES){ | 
|             upDown = "上"; | 
|         }else{ | 
|             upDown = "下"; | 
|         } | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request)) | 
|                 .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-商品"+upDown+"架-"+id).build(); | 
|         mqUtil.sendApp(build); | 
|         return new JsonResult().success("操作成功!"); | 
|     } | 
|   | 
|     /** | 
|      * 商品开始抢购开关 | 
|      */ | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/snapUpGoods.json") | 
|     @ApiOperation(value="商品管理-商品开始抢购开关", notes="test: 仅0有正确返回") | 
|     public JsonResult snapUpGoods(@RequestBody SnapUpGoodsDto model, HttpServletRequest request) { | 
|         long id = model.getId(); | 
|         ScoreGoods scoreGoods = scoreGoodsMapper.selectById(id); | 
|         if(ObjectUtil.isEmpty(scoreGoods)){ | 
|             return JsonResult.failMessage("商品不存在!"); | 
|         } | 
|         short delFlag = scoreGoods.getDelFlag(); | 
|         if(Convert.toShort(Constants.DEL_FLAG) == delFlag){ | 
|             return JsonResult.failMessage("当前商品已删除!"); | 
|         } | 
|         goodsService.snapUpGoods(model); | 
|         String upDown = ""; | 
|         if(model.getIsQg() == ScoreGoods.ISQG_YES){ | 
|             upDown = "开始"; | 
|         }else{ | 
|             upDown = "结束"; | 
|         } | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request)) | 
|                 .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-商品"+upDown+"抢购-"+id).build(); | 
|         mqUtil.sendApp(build); | 
|         return new JsonResult().success("操作成功!"); | 
|     } | 
| } |