feat(): 增加规则规格修改功能
parent
79681ab469
commit
7b0eb509c9
|
@ -51,6 +51,11 @@ public class RuleInfo extends BaseEntity {
|
|||
@ApiModelProperty(name = "规格状态", value = "规格状态")
|
||||
private String status;
|
||||
|
||||
/** 规格状态 */
|
||||
@Excel(name = "规格描述")
|
||||
@ApiModelProperty(name = "规格描述", value = "规格描述")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 查询构造器
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.product.domain.req;
|
||||
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.product.domain.model.RuleAttrAddModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -8,6 +10,8 @@ import lombok.experimental.SuperBuilder;
|
|||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格对象 rule_info
|
||||
*
|
||||
|
@ -31,4 +35,14 @@ public class RuleInfoEditReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "规格状态", value = "规格状态")
|
||||
private String status;
|
||||
|
||||
/** 规格状态 */
|
||||
@Excel(name = "规格描述")
|
||||
@ApiModelProperty(name = "规格描述", value = "规格描述")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 规格属性集合
|
||||
*/
|
||||
private List<RuleAttrAddModel> ruleAttrList;
|
||||
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public class AttributeGroupPageResp extends BaseEntity {
|
|||
.attributeInfoList(attributeInfos)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static AttributeGroupPageResp groupFunBuild (AttributeGroup attributeGroup, Function<Long,List<AttributeInfo> > function) {
|
||||
return AttributeGroupPageResp.builder()
|
||||
.id(attributeGroup.getId())
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.product.domain.resp;
|
||||
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 修改回显的详细信息
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AttributeGroupUpdResp {
|
||||
|
||||
/** 属性组编号 */
|
||||
private Long id;
|
||||
|
||||
/** 组名称 */
|
||||
private String name;
|
||||
|
||||
/** 状态 */
|
||||
private String states;
|
||||
|
||||
/**
|
||||
* 属性ID集合
|
||||
*/
|
||||
private List<AttributeInfo> attributeList;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
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
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RuleInfoUpdResp {
|
||||
|
||||
/** 主键 */
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
@ApiModelProperty(name = "主键", value = "主键")
|
||||
private Long id;
|
||||
|
||||
/** 规格名称 */
|
||||
@Excel(name = "规格名称")
|
||||
@ApiModelProperty(name = "规格名称", value = "规格名称")
|
||||
private String name;
|
||||
|
||||
/** 规格状态 */
|
||||
@Excel(name = "规格状态")
|
||||
@ApiModelProperty(name = "规格状态", value = "规格状态")
|
||||
private String status;
|
||||
|
||||
/** 规格状态 */
|
||||
@Excel(name = "规格描述")
|
||||
@ApiModelProperty(name = "规格描述", value = "规格描述")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 规格属性集合
|
||||
*/
|
||||
private List<RuleAttrAddModel> ruleAttrList;
|
||||
}
|
|
@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||
import com.muyu.product.domain.resp.AttributeGroupPageResp;
|
||||
import com.muyu.product.domain.resp.AttributeGroupUpdResp;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -74,8 +75,8 @@ public class AttributeGroupController extends BaseController {
|
|||
@RequiresPermissions("product:attributeGroup:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<AttributeGroup> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(attributeGroupService.getById(id));
|
||||
public Result<AttributeGroupUpdResp> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(attributeGroupService.getUpdById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.product.domain.model.RuleInfoAddModel;
|
||||
import com.muyu.product.domain.resp.RuleInfoResp;
|
||||
import com.muyu.product.domain.resp.RuleInfoUpdResp;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -77,8 +78,8 @@ public class RuleInfoController extends BaseController {
|
|||
@RequiresPermissions("product:rule:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<RuleInfo> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(ruleInfoService.getById(id));
|
||||
public Result<RuleInfoUpdResp> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(ruleInfoService.getUpdById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +101,8 @@ public class RuleInfoController extends BaseController {
|
|||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改商品规格")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody RuleInfoEditReq ruleInfoEditReq) {
|
||||
return toAjax(ruleInfoService.updateById(RuleInfo.editBuild(id,ruleInfoEditReq)));
|
||||
// return toAjax(ruleInfoService.updateById(RuleInfo.editBuild(id,ruleInfoEditReq)));
|
||||
return toAjax(ruleInfoService.updateById(id, ruleInfoEditReq));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||
import com.muyu.product.domain.resp.AttributeGroupPageResp;
|
||||
import com.muyu.product.domain.resp.AttributeGroupUpdResp;
|
||||
|
||||
/**
|
||||
* 属性组Service接口
|
||||
|
@ -39,4 +40,10 @@ public interface AttributeGroupService extends IService<AttributeGroup> {
|
|||
*/
|
||||
public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel);
|
||||
|
||||
/**
|
||||
* 根据ID查询属性组的修改
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
AttributeGroupUpdResp getUpdById(Long id);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,10 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
import com.muyu.product.domain.RuleInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
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.resp.RuleInfoResp;
|
||||
import com.muyu.product.domain.resp.RuleInfoUpdResp;
|
||||
|
||||
/**
|
||||
* 商品规格Service接口
|
||||
|
@ -32,4 +34,19 @@ public interface RuleInfoService extends IService<RuleInfo> {
|
|||
public boolean save(RuleInfoAddModel ruleInfoAddModel);
|
||||
|
||||
TableDataInfo<RuleInfoResp> queryList (RuleInfoQueryReq ruleInfoQueryReq);
|
||||
|
||||
/**
|
||||
* 通过规格ID获取规格修改详细信息
|
||||
* @param id 规格ID
|
||||
* @return
|
||||
*/
|
||||
RuleInfoUpdResp getUpdById(Long id);
|
||||
|
||||
/**
|
||||
* 通过ID修改规格属性
|
||||
* @param id ID
|
||||
* @param ruleInfoEditReq 请求对象
|
||||
* @return
|
||||
*/
|
||||
boolean updateById(Long id, RuleInfoEditReq ruleInfoEditReq);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.muyu.product.domain.AttributeGroup;
|
|||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||
import com.muyu.product.domain.resp.AttributeGroupPageResp;
|
||||
import com.muyu.product.domain.resp.AttributeGroupUpdResp;
|
||||
import com.muyu.product.mapper.AttributeGroupMapper;
|
||||
import com.muyu.product.service.AsAttributeGroupService;
|
||||
import com.muyu.product.service.AttributeGroupService;
|
||||
|
@ -20,8 +21,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 属性组Service业务层处理
|
||||
|
@ -34,7 +33,7 @@ import java.util.stream.Stream;
|
|||
public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper, AttributeGroup> implements AttributeGroupService {
|
||||
|
||||
@Autowired
|
||||
private AsAttributeGroupService attributeGroupService;
|
||||
private AsAttributeGroupService asAttributeGroupService;
|
||||
|
||||
@Autowired
|
||||
private AttributeInfoService attributeInfoService;
|
||||
|
@ -100,11 +99,31 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
|
|||
Long attributeGroupId = attributeGroup.getId();
|
||||
List<Long> attributeIdList = attributeGroupSaveModel.getAttributeIdList();
|
||||
|
||||
attributeGroupService.saveBatch(
|
||||
asAttributeGroupService.saveBatch(
|
||||
attributeIdList.stream()
|
||||
.map(attributeId -> AsAttributeGroup.buildGroup(attributeGroupId, attributeId))
|
||||
.toList()
|
||||
);
|
||||
return save;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeGroupUpdResp getUpdById(Long id) {
|
||||
AttributeGroup attributeGroup = this.getById(id);
|
||||
|
||||
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AsAttributeGroup::getGroupId, id);
|
||||
List<AsAttributeGroup> asAttributeGroupList = asAttributeGroupService.list(queryWrapper);
|
||||
List<Long> attributeIdList = asAttributeGroupList.stream()
|
||||
.map(AsAttributeGroup::getAttributeId)
|
||||
.toList();
|
||||
List<AttributeInfo> attributeInfoList = attributeInfoService.listByIds(attributeIdList);
|
||||
|
||||
return AttributeGroupUpdResp.builder()
|
||||
.id(attributeGroup.getId())
|
||||
.name(attributeGroup.getName())
|
||||
.states(attributeGroup.getStates())
|
||||
.attributeList(attributeInfoList)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.model.RuleAttrAddModel;
|
||||
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.resp.RuleInfoResp;
|
||||
import com.muyu.product.domain.resp.RuleInfoUpdResp;
|
||||
import com.muyu.product.service.RuleAttrInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -107,4 +110,35 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo>
|
|||
.total(isPage ? new PageInfo<>(list).getTotal() : 0)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleInfoUpdResp getUpdById(Long id) {
|
||||
RuleInfo ruleInfo = this.getById(id);
|
||||
LambdaQueryWrapper<RuleAttrInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(RuleAttrInfo::getRuleId, id);
|
||||
List<RuleAttrInfo> ruleAttrInfoList = this.ruleAttrInfoService.list(queryWrapper);
|
||||
return RuleInfoUpdResp.builder()
|
||||
.id(ruleInfo.getId())
|
||||
.name(ruleInfo.getName())
|
||||
.status(ruleInfo.getStatus())
|
||||
.remark(ruleInfo.getRemark())
|
||||
.ruleAttrList(ruleAttrInfoList.stream().map(RuleAttrAddModel::infoBuild).toList())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateById(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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue