2024-11-14(属性组 商品规格)

backups
笨蛋 2024-11-14 19:14:00 +08:00
parent 50c1706b77
commit c4464794cc
8 changed files with 133 additions and 6 deletions

View File

@ -62,6 +62,8 @@ public class CategoryInfo extends TreeEntity {
@ApiModelProperty(name = "介绍", value = "介绍") @ApiModelProperty(name = "介绍", value = "介绍")
private String introduction; private String introduction;
/** /**
* *
*/ */

View File

@ -55,7 +55,6 @@ public class RuleAttrInfo extends BaseEntity {
@Excel(name = "规格值") @Excel(name = "规格值")
@ApiModelProperty(name = "规格值", value = "规格值") @ApiModelProperty(name = "规格值", value = "规格值")
private String attrValue; private String attrValue;
/** /**
* *
*/ */

View File

@ -51,6 +51,10 @@ public class RuleInfo extends BaseEntity {
@ApiModelProperty(name = "规格状态", value = "规格状态") @ApiModelProperty(name = "规格状态", value = "规格状态")
private String status; private String status;
/** 规格状态 */
@Excel(name = "规格描述")
@ApiModelProperty(name = "规格描述", value = "规格描述")
private String remark;
/** /**
* *
*/ */

View File

@ -1,5 +1,6 @@
package com.muyu.product.domain.req; package com.muyu.product.domain.req;
import com.muyu.product.domain.model.RuleAttrAddModel;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -7,6 +8,9 @@ import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
import org.springframework.beans.PropertyValues;
import java.util.List;
/** /**
* rule_info * rule_info
@ -30,5 +34,9 @@ public class RuleInfoEditReq extends BaseEntity {
/** 规格状态 */ /** 规格状态 */
@ApiModelProperty(name = "规格状态", value = "规格状态") @ApiModelProperty(name = "规格状态", value = "规格状态")
private String status; private String status;
/**
*
*/
@ApiModelProperty(name = "规格子集", value = "规格子集")
private List<RuleAttrAddModel> ruleAttrList;
} }

View File

@ -0,0 +1,38 @@
package com.muyu.product.domain.resp;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.muyu.common.core.annotation.Excel;
import com.muyu.product.domain.model.RuleAttrAddModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
/**
*
*/
public class RuleInfoUpdResp {
/** 主键 */
private Long id;
/** 规格名称 */
private String name;
/** 规格状态 */
private String status;
/** 规格描述*/
private String remark;
/**
*
*/
private List<RuleAttrAddModel> ruleAttrList;
}

View File

@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
import com.muyu.common.core.text.Convert; import com.muyu.common.core.text.Convert;
import com.muyu.product.domain.model.RuleInfoAddModel; import com.muyu.product.domain.model.RuleInfoAddModel;
import com.muyu.product.domain.resp.RuleInfoResp; import com.muyu.product.domain.resp.RuleInfoResp;
import com.muyu.product.domain.resp.RuleInfoUpdResp;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -77,8 +78,8 @@ public class RuleInfoController extends BaseController {
@RequiresPermissions("product:rule:query") @RequiresPermissions("product:rule:query")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class) @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
public Result<RuleInfo> getInfo(@PathVariable("id") Long id) { public Result<RuleInfoUpdResp> getInfo(@PathVariable("id") Long id) {
return Result.success(ruleInfoService.getById(id)); return Result.success(ruleInfoService.getUpdById(id));
} }
/** /**
@ -100,7 +101,7 @@ public class RuleInfoController extends BaseController {
@PutMapping("/{id}") @PutMapping("/{id}")
@ApiOperation("修改商品规格") @ApiOperation("修改商品规格")
public Result<String> edit(@PathVariable Long id, @RequestBody RuleInfoEditReq ruleInfoEditReq) { public Result<String> edit(@PathVariable Long id, @RequestBody RuleInfoEditReq ruleInfoEditReq) {
return toAjax(ruleInfoService.updateById(RuleInfo.editBuild(id,ruleInfoEditReq))); return toAjax(ruleInfoService.updateGoodsSpecifications(id,ruleInfoEditReq));
} }
/** /**

View File

@ -6,8 +6,10 @@ import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.product.domain.RuleInfo; import com.muyu.product.domain.RuleInfo;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.product.domain.model.RuleInfoAddModel; import com.muyu.product.domain.model.RuleInfoAddModel;
import com.muyu.product.domain.req.RuleInfoEditReq;
import com.muyu.product.domain.req.RuleInfoQueryReq; import com.muyu.product.domain.req.RuleInfoQueryReq;
import com.muyu.product.domain.resp.RuleInfoResp; import com.muyu.product.domain.resp.RuleInfoResp;
import com.muyu.product.domain.resp.RuleInfoUpdResp;
/** /**
* Service * Service
@ -32,4 +34,20 @@ public interface RuleInfoService extends IService<RuleInfo> {
public boolean save(RuleInfoAddModel ruleInfoAddModel); public boolean save(RuleInfoAddModel ruleInfoAddModel);
TableDataInfo<RuleInfoResp> queryList (RuleInfoQueryReq ruleInfoQueryReq); TableDataInfo<RuleInfoResp> queryList (RuleInfoQueryReq ruleInfoQueryReq);
/**
*
* @param id
* @return
*/
RuleInfoUpdResp getUpdById(Long id);
/**
*
* @param id
* @param ruleInfoEditReq
* @return
*/
boolean updateGoodsSpecifications(Long id, RuleInfoEditReq ruleInfoEditReq);
} }

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
@ -15,8 +16,10 @@ import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.RuleAttrInfo; import com.muyu.product.domain.RuleAttrInfo;
import com.muyu.product.domain.model.RuleAttrAddModel; import com.muyu.product.domain.model.RuleAttrAddModel;
import com.muyu.product.domain.model.RuleInfoAddModel; import com.muyu.product.domain.model.RuleInfoAddModel;
import com.muyu.product.domain.req.RuleInfoEditReq;
import com.muyu.product.domain.req.RuleInfoQueryReq; import com.muyu.product.domain.req.RuleInfoQueryReq;
import com.muyu.product.domain.resp.RuleInfoResp; import com.muyu.product.domain.resp.RuleInfoResp;
import com.muyu.product.domain.resp.RuleInfoUpdResp;
import com.muyu.product.service.RuleAttrInfoService; import com.muyu.product.service.RuleAttrInfoService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -51,6 +54,7 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo>
LambdaQueryWrapper<RuleInfo> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<RuleInfo> queryWrapper = new LambdaQueryWrapper<>();
if (ObjUtils.notNull(ruleInfo.getName())){ if (ObjUtils.notNull(ruleInfo.getName())){
queryWrapper.like(RuleInfo::getName, ruleInfo.getName()); queryWrapper.like(RuleInfo::getName, ruleInfo.getName());
} }
@ -79,7 +83,8 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo>
boolean save = this.save(ruleInfo); boolean save = this.save(ruleInfo);
ruleAttrInfoService.saveBatch( ruleAttrInfoService.saveBatch(
ruleInfoAddModel.getRuleAttrList().stream() ruleInfoAddModel.getRuleAttrList().stream()
.map(ruleAttrAddModel -> RuleAttrInfo.addModelBuild(ruleAttrAddModel, ruleInfo::getId, SecurityUtils::getUsername)) .map(ruleAttrAddModel -> RuleAttrInfo.addModelBuild(ruleAttrAddModel, ruleInfo::getId,
SecurityUtils::getUsername))
.toList() .toList()
); );
return save; return save;
@ -107,4 +112,56 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo>
.total(isPage ? new PageInfo<>(list).getTotal() : 0) .total(isPage ? new PageInfo<>(list).getTotal() : 0)
.build(); .build();
} }
/**
* wyz
* @param id
* @return
*/
@Override
public RuleInfoUpdResp getUpdById(Long id) {
RuleInfo ruleInfo = this.getById(id);
//查询规格
LambdaQueryWrapper<RuleAttrInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(RuleAttrInfo::getRuleId ,ruleInfo.getId());
List<RuleAttrInfo> infoList = this.ruleAttrInfoService.list(wrapper);
return RuleInfoUpdResp.builder()
.id(ruleInfo.getId())
.name(ruleInfo.getName())
.status(ruleInfo.getStatus())
.ruleAttrList(infoList.stream().map(RuleAttrAddModel::infoBuild).toList())
.remark(ruleInfo.getRemark())
.build();
}
/**
* wyz
* @return
*/
@Override
public boolean updateGoodsSpecifications(Long id, RuleInfoEditReq ruleInfoEditReq) {
//修改
boolean update = this.updateById(RuleInfo.editBuild(id, ruleInfoEditReq));
if (update){
LambdaQueryWrapper<RuleAttrInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(RuleAttrInfo::getRuleId,id);
//删除
this.ruleAttrInfoService.remove(queryWrapper);
//添加
ruleAttrInfoService.saveBatch(
ruleInfoEditReq.getRuleAttrList().stream()
.map(ruleAttrAddModel -> RuleAttrInfo.addModelBuild(ruleAttrAddModel,
() -> id,
SecurityUtils::getUsername))
.toList()
);
}
return update;
}
} }