更新了商品管理模块
This commit is contained in:
parent
2cda8e26c6
commit
6fa130e59d
|
@ -38,7 +38,7 @@ public class ClothesGradeController {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加服装等级
|
* Web端管理员添加服装等级
|
||||||
* @param clothesGradeAddRequest 服装等级添加请求体
|
* @param clothesGradeAddRequest 服装等级添加请求体
|
||||||
* @return 是否添加成功
|
* @return 是否添加成功
|
||||||
*/
|
*/
|
||||||
|
@ -60,7 +60,7 @@ public class ClothesGradeController {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新服装等级
|
* Web端管理员更新服装等级
|
||||||
* @param clothesGradeUpdateRequest 服装等级更新请求体
|
* @param clothesGradeUpdateRequest 服装等级更新请求体
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.cultural.heritage.controller.good;
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.cultural.heritage.annotation.AuthCheck;
|
import com.cultural.heritage.annotation.AuthCheck;
|
||||||
import com.cultural.heritage.common.BaseResponse;
|
import com.cultural.heritage.common.BaseResponse;
|
||||||
import com.cultural.heritage.common.ErrorCode;
|
import com.cultural.heritage.common.ErrorCode;
|
||||||
|
@ -138,7 +139,7 @@ public class CategoryController {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新商品类别
|
* Web端管理员更新商品类别
|
||||||
* @param categoryUpdateRequest 类别更新请求体
|
* @param categoryUpdateRequest 类别更新请求体
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
|
@ -149,11 +150,28 @@ public class CategoryController {
|
||||||
if (categoryUpdateRequest == null || categoryUpdateRequest.getId() <= 0) {
|
if (categoryUpdateRequest == null || categoryUpdateRequest.getId() <= 0) {
|
||||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||||
}
|
}
|
||||||
|
// 获取原有的类别名称
|
||||||
|
Long id = categoryUpdateRequest.getId();
|
||||||
|
Category originCategory = categoryService.getById(id);
|
||||||
|
String originTypeName = originCategory.getTypeName();
|
||||||
|
// 获取目标的类别名称
|
||||||
|
String targetTypeName = categoryUpdateRequest.getTypeName();
|
||||||
|
// 判空
|
||||||
|
if (StringUtils.isAnyBlank(originTypeName, targetTypeName)) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "类别参数错误");
|
||||||
|
}
|
||||||
|
// 更新商品类别
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
BeanUtils.copyProperties(categoryUpdateRequest, category);
|
BeanUtils.copyProperties(categoryUpdateRequest, category);
|
||||||
categoryService.validCategory(category, false);
|
categoryService.validCategory(category, false);
|
||||||
boolean result = categoryService.updateById(category);
|
boolean result = categoryService.updateById(category);
|
||||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "商品类别更新失败");
|
||||||
|
|
||||||
|
// 修改原有类别下所有商品的类名
|
||||||
|
UpdateWrapper<Good> goodUpdateWrapper = new UpdateWrapper<>();
|
||||||
|
goodUpdateWrapper.eq("type", originTypeName).set("type", targetTypeName);
|
||||||
|
boolean update = goodService.update(goodUpdateWrapper);
|
||||||
|
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "商品类名更新失败");
|
||||||
return ResultUtils.success(true, "类别更新成功");
|
return ResultUtils.success(true, "类别更新成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ package com.cultural.heritage.controller.good;
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.cultural.heritage.annotation.AuthCheck;
|
import com.cultural.heritage.annotation.AuthCheck;
|
||||||
|
@ -21,6 +22,7 @@ import com.cultural.heritage.model.dto.good.GoodQueryRequest;
|
||||||
import com.cultural.heritage.model.dto.good.GoodUpdateRequest;
|
import com.cultural.heritage.model.dto.good.GoodUpdateRequest;
|
||||||
import com.cultural.heritage.model.dto.good.service.ServiceGoodAddRequest;
|
import com.cultural.heritage.model.dto.good.service.ServiceGoodAddRequest;
|
||||||
import com.cultural.heritage.model.dto.good.service.ServiceGoodQueryRequest;
|
import com.cultural.heritage.model.dto.good.service.ServiceGoodQueryRequest;
|
||||||
|
import com.cultural.heritage.model.dto.good.service.ServiceGoodSingleUpdateRequest;
|
||||||
import com.cultural.heritage.model.dto.good.service.ServiceGoodUpdateRequest;
|
import com.cultural.heritage.model.dto.good.service.ServiceGoodUpdateRequest;
|
||||||
import com.cultural.heritage.model.dto.timeperiod.TimePeriodAddRequest;
|
import com.cultural.heritage.model.dto.timeperiod.TimePeriodAddRequest;
|
||||||
import com.cultural.heritage.model.entity.AppointmentDate;
|
import com.cultural.heritage.model.entity.AppointmentDate;
|
||||||
|
@ -549,7 +551,7 @@ public class GoodController {
|
||||||
// 校验
|
// 校验
|
||||||
goodService.validGood(good, true);
|
goodService.validGood(good, true);
|
||||||
boolean result = goodService.updateById(good);
|
boolean result = goodService.updateById(good);
|
||||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "商品不存在");
|
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "服务类商品信息更新失败");
|
||||||
|
|
||||||
// 删除当前商品关联的所有日期和时间段
|
// 删除当前商品关联的所有日期和时间段
|
||||||
CommonRequest commonRequest = new CommonRequest();
|
CommonRequest commonRequest = new CommonRequest();
|
||||||
|
@ -623,6 +625,59 @@ public class GoodController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web端管理员上(下)架服务类商品
|
||||||
|
* @param commonRequest 优惠券上架状态更新请求体
|
||||||
|
* @return 是否更新成功
|
||||||
|
*/
|
||||||
|
@PostMapping("/service/shelves")
|
||||||
|
@Operation(summary = "Web端管理员上(下)架服务类商品", description = "参数:优惠券上架状态更新请求体,权限:管理员(admin, boss),方法名:updateServiceGoodShelvesStatus")
|
||||||
|
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||||
|
public BaseResponse<Boolean> updateServiceGoodShelvesStatus(@RequestBody CommonRequest commonRequest) {
|
||||||
|
if (commonRequest == null || commonRequest.getId() <= 0) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||||
|
}
|
||||||
|
// 获取当前服务类商品的上(下)架状态
|
||||||
|
Long id = commonRequest.getId();
|
||||||
|
Good good = goodService.getById(id);
|
||||||
|
Integer status = good.getIsShelves() == 0 ? 1 : 0;
|
||||||
|
UpdateWrapper<Good> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("id", id);
|
||||||
|
updateWrapper.set("isShelves", status);
|
||||||
|
boolean update = goodService.update(updateWrapper);
|
||||||
|
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "上架状态更新失败");
|
||||||
|
return ResultUtils.success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web端管理员单独更新服务类商品
|
||||||
|
* @param serviceGoodSingleUpdateRequest 服务类商品更新请求体
|
||||||
|
* @return 是否更新成功
|
||||||
|
*/
|
||||||
|
@PostMapping("/service/single/update")
|
||||||
|
@Operation(summary = "Web端管理员单独更新服务类商品", description = "参数:服务类商品更新请求体,权限:管理员(admin, boss),方法名:updateServiceGoodSingleById")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||||
|
public BaseResponse<Boolean> updateServiceGoodSingleById(@RequestBody ServiceGoodSingleUpdateRequest serviceGoodSingleUpdateRequest) {
|
||||||
|
if (serviceGoodSingleUpdateRequest == null || serviceGoodSingleUpdateRequest.getId() <= 0) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||||
|
}
|
||||||
|
// 更新服务类商品的基本信息
|
||||||
|
Good good = new Good();
|
||||||
|
BeanUtils.copyProperties(serviceGoodSingleUpdateRequest, good);
|
||||||
|
good.setType("服务类");
|
||||||
|
good.setIsGoodType(0);
|
||||||
|
good.setInventory(1);
|
||||||
|
good.setFestivalOrder(0);
|
||||||
|
// 校验
|
||||||
|
goodService.validGood(good, true);
|
||||||
|
boolean result = goodService.updateById(good);
|
||||||
|
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "服务类商品信息更新失败");
|
||||||
|
|
||||||
|
return ResultUtils.success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.cultural.heritage.model.dto.good.service;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "服务类商品更新请求体", requiredProperties = {"id", "name", "price", "goodImg", "intro", "introDetail",
|
||||||
|
"detailImg", "label"})
|
||||||
|
public class ServiceGoodSingleUpdateRequest implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品id
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品id(id > 0)", example = "286")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品名
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品名", example = "非遗香囊")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品价格
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品价格", example = "20.00")
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品图片
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品图片", example = "https://xxx/xxx.jpg")
|
||||||
|
private String goodImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品简介
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品简介", example = "传承千年文化,守护健康美好")
|
||||||
|
private String intro;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品详情简介
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品详情简介", example = "精选药材:选用艾草、菖蒲、苍术、白芷等十多种纯天然中草药,科学配比,香气宜人,具有驱蚊、防疫、安神等多种功效。端午香囊,传承千年文化,守护健康美好。在这个端午节,让我们共同感受传统文化的魅力,为生活增添一抹色彩!")
|
||||||
|
private String introDetail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品详情图片
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品详情图片", example = "https://xxx/xxx.jpg")
|
||||||
|
private String detailImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品标签
|
||||||
|
*/
|
||||||
|
@Schema(description = "商品标签", example = "亲情;送礼;材料包")
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
|
@ -55,6 +55,12 @@ public class ClothesGradeServiceImpl extends ServiceImpl<ClothesGradeMapper, Clo
|
||||||
if (StringUtils.isAnyBlank(clothesType, image, brief)) {
|
if (StringUtils.isAnyBlank(clothesType, image, brief)) {
|
||||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||||
}
|
}
|
||||||
|
if (update) {
|
||||||
|
QueryWrapper<ClothesGrade> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.ne("id", id).eq("clothesType", clothesType);
|
||||||
|
Long count = this.baseMapper.selectCount(queryWrapper);
|
||||||
|
ThrowUtils.throwIf(count > 0, ErrorCode.OPERATION_ERROR, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user