dev798
wxy 2024-04-07 20:18:58 +08:00
parent 07d9843c32
commit d7a0c6d420
17 changed files with 360 additions and 33 deletions

View File

@ -5,6 +5,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: wangxinyuan
* @Date: 2024/3/29 16:58
@ -55,4 +57,13 @@ public class ProductTypeAttr extends BaseEntity {
@ApiModelProperty(value = "手动新增0-是1-否")
private Integer manualOperation;
@ApiModelProperty(value = "类型名称")
private String typeName;
@ApiModelProperty(value = "类型集合")
private List<TypeAttrs> typeAttrs;
@ApiModelProperty(value = "tavId")
private Integer tavId;
}

View File

@ -2,6 +2,7 @@ package com.muyu.product.domain.DTO;
import com.muyu.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
@ -13,7 +14,8 @@ import lombok.Data;
@ApiModel(value = "TypeAttrs")
public class TypeAttrs extends BaseEntity {
@ApiModelProperty(value = "Id")
private Integer typeAttrValueId;
@ApiModelProperty(value = "名称")
private String typeAttrValueName;
}

View File

@ -1,4 +1,4 @@
package com.macro.mall.model;
package com.muyu.product.domain;
import java.math.BigDecimal;
import java.util.ArrayList;

View File

@ -0,0 +1,63 @@
package com.muyu.product.domain.req;
import com.muyu.common.core.domain.BaseEntity;
import com.muyu.product.domain.DTO.ProductTypeAttrValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: wangxinyuan
* @Date: 2024/4/7 19:05
*/
@Data
@ApiModel(value = "ProductTypeAttrReq", description = "商品类型添加值")
public class ProductTypeAttrReq extends BaseEntity {
@ApiModelProperty(value = "ID")
private Integer id;
@ApiModelProperty(value = "商品类型ID")
private Integer productTypeId;
@ApiModelProperty(value = "属性名称")
private String attrName;
@ApiModelProperty(value = "是否支持多选0-是1-否")
private Integer multipleChoice;
@ApiModelProperty(value = "录入方式0-列表选择1-手动")
private Integer inputMethod;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "分类标识0-属性1-参数")
private Integer flag;
@ApiModelProperty(value = "筛选0-普通1-颜色")
private Integer screen;
@ApiModelProperty(value = "检索1-不需要2-关键字3-范围检索")
private Integer search;
@ApiModelProperty(value = "商品属性关联1-是2-否")
private Integer association;
@ApiModelProperty(value = "属性是否可选1-唯一2-单选3-复选")
private Integer stats;
@ApiModelProperty(value = "属性值的录入方式1-手工录入2-从列表中选择")
private Integer input;
@ApiModelProperty(value = "属性值可选值列表")
private String selection;
@ApiModelProperty(value = "手动新增0-是1-否")
private Integer manualOperation;
@ApiModelProperty(value = "添加类型得具体值")
private List<ProductTypeAttrValue> productTypeAttrValueList;
}

View File

@ -29,6 +29,12 @@ public class CategoryController {
return AjaxResult.success(list);
}
@ApiOperation("查询分类父级")
@GetMapping("/queryCategorParent")
public AjaxResult queryCategorParent(){
List<Category>list=categoryService.queryCategorParent();
return AjaxResult.success(list);
}
@DeleteMapping("{categoryId}")
@ApiOperation("分类删除")
public AjaxResult deleteCategory(@PathVariable Integer categoryId){

View File

@ -1,8 +1,11 @@
package com.muyu.product.controller;
import com.muyu.common.core.domain.AjaxResult;
import com.muyu.common.core.domain.R;
import com.muyu.product.domain.DTO.ProductType;
import com.muyu.product.domain.DTO.ProductTypeAttr;
import com.muyu.product.domain.Resp.ProductTypeResp;
import com.muyu.product.domain.req.ProductTypeAttrReq;
import com.muyu.product.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -25,6 +28,7 @@ public class TypeController {
@GetMapping("/queryTypeAll")
@ApiOperation("类型查询")
public AjaxResult queryTypeAll(){
List<ProductTypeResp> list =typeService.queryTypeAll();
return AjaxResult.success(list);
@ -49,6 +53,41 @@ public class TypeController {
return AjaxResult.success(res==1?"删除成功":"删除失败");
}
@ApiOperation("类型值删除")
@DeleteMapping("/deleteTypeAttr/{typeId}")
public R deleteTypeAttr(@PathVariable Integer typeId){
Integer res = typeService.deleteTypeAttr(typeId);
return R.ok(res==1?"删除成功":"删除失败");
}
@ApiOperation("类型添加")
@PostMapping("/insertType")
public R insertType(@RequestBody ProductType productType){
Integer res = typeService.insertType(productType);
return R.ok(res==1?"添加成功":"添加失败");
}
@ApiOperation("类型修改")
@PostMapping("updateType")
public R updateType(@RequestBody ProductType productType){
Integer res = typeService.updateType(productType);
return R.ok(res==1?"修改成功":"修改失败");
}
@ApiOperation("类型值添加")
@PostMapping("/insertTypeAttr")
public R insertTypeAttr(@RequestBody ProductTypeAttrReq productTypeAttrReq){
Integer res = typeService.insertTypeAttr(productTypeAttrReq);
return R.ok(res==1?"添加成功":"添加失败");
}
@ApiOperation("类型修改")
@PostMapping("/updateTypeAttr")
public R updateTypeAttr(@RequestBody ProductTypeAttrReq productTypeAttrReq){
Integer res = typeService.updateTypeAttr(productTypeAttrReq);
return R.ok(res==1?"修改成功":"修改失败");
}

View File

@ -18,4 +18,6 @@ public interface CategoryMapper {
Integer insertCategory(Category category);
Integer updateCategory(Category category);
List<Category> queryCategorParent();
}

View File

@ -1,7 +1,8 @@
package com.muyu.product.mapper;
import com.macro.mall.model.PmsSkuStockExample;
import com.muyu.product.domain.DTO.ProductSku;
import com.muyu.product.domain.PmsSkuStockExample;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

View File

@ -1,7 +1,10 @@
package com.muyu.product.mapper;
import com.muyu.product.domain.DTO.ProductType;
import com.muyu.product.domain.DTO.ProductTypeAttr;
import com.muyu.product.domain.DTO.ProductTypeAttrValue;
import com.muyu.product.domain.Resp.ProductTypeResp;
import com.muyu.product.domain.req.ProductTypeAttrReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -19,5 +22,19 @@ public interface TypeMapper {
List<ProductTypeAttr> queryType(@Param("flag") Integer flag, @Param("id") Integer id);
Integer deleteType(Integer typeId);
Integer deleteType(@Param("typeId") Integer typeId, @Param("name") String name);
void deleteTypeAttrValue(Integer typeId);
Integer deleteTypeAttr(Integer typeId);
Integer insertType(ProductType productType);
Integer updateType(ProductType productType);
Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq);
void insertTypeValue(@Param("productTypeAttrValueList") List<ProductTypeAttrValue> productTypeAttrValueList);
Integer updateAttr(ProductTypeAttrReq productTypeAttrReq);
}

View File

@ -16,4 +16,7 @@ public interface CategoryService {
Integer insertCategory(Category category);
Integer updateCategory(Category category);
List<Category> queryCategorParent();
}

View File

@ -1,7 +1,9 @@
package com.muyu.product.service;
import com.muyu.product.domain.DTO.ProductType;
import com.muyu.product.domain.DTO.ProductTypeAttr;
import com.muyu.product.domain.Resp.ProductTypeResp;
import com.muyu.product.domain.req.ProductTypeAttrReq;
import java.util.List;
@ -17,4 +19,14 @@ public interface TypeService {
List<ProductTypeAttr> queryType(Integer flag, Integer id);
Integer deleteType(Integer typeId);
Integer deleteTypeAttr(Integer typeId);
Integer insertType(ProductType productType);
Integer updateType(ProductType productType);
Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq);
Integer updateTypeAttr(ProductTypeAttrReq productTypeAttrReq);
}

View File

@ -39,4 +39,9 @@ public class CategoryServiceImpl implements CategoryService {
category.setCreateBy(SecurityUtils.getUsername());
return categoryMapper.updateCategory(category);
}
@Override
public List<Category> queryCategorParent() {
return categoryMapper.queryCategorParent();
}
}

View File

@ -1,6 +1,7 @@
package com.muyu.product.service.impl;
import com.muyu.product.domain.DTO.ProductSku;
import com.muyu.product.domain.PmsSkuStockExample;
import com.muyu.product.mapper.SkuMapper;
import com.muyu.product.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
@ -19,8 +20,8 @@ public class SkuServiceImpl implements SkuService {
private SkuMapper skuMapper;
@Override
public List<ProductSku> getList(Long pid, String keyword) {
com.macro.mall.model.PmsSkuStockExample example = new com.macro.mall.model.PmsSkuStockExample();
com.macro.mall.model.PmsSkuStockExample.Criteria criteria = example.createCriteria().andProductIdEqualTo(pid);
PmsSkuStockExample example = new PmsSkuStockExample();
PmsSkuStockExample.Criteria criteria = example.createCriteria().andProductIdEqualTo(pid);
return skuMapper.selectByExample(example);
}
}

View File

@ -1,7 +1,11 @@
package com.muyu.product.service.impl;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.DTO.ProductType;
import com.muyu.product.domain.DTO.ProductTypeAttr;
import com.muyu.product.domain.DTO.ProductTypeAttrValue;
import com.muyu.product.domain.Resp.ProductTypeResp;
import com.muyu.product.domain.req.ProductTypeAttrReq;
import com.muyu.product.mapper.TypeMapper;
import com.muyu.product.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
@ -32,6 +36,55 @@ public class TypeServiceImpl implements TypeService {
@Override
public Integer deleteType(Integer typeId) {
return typeMapper.deleteType(typeId);
String name = SecurityUtils.getUsername();
return typeMapper.deleteType(typeId,name);
}
@Override
public Integer deleteTypeAttr(Integer typeId) {
typeMapper.deleteTypeAttrValue(typeId);
return typeMapper.deleteTypeAttr(typeId);
}
@Override
public Integer insertType(ProductType productType) {
productType.setCreateBy(SecurityUtils.getUsername());
return typeMapper.insertType(productType);
}
@Override
public Integer updateType(ProductType productType) {
productType.setCreateBy(SecurityUtils.getUsername());
return typeMapper.updateType(productType);
}
@Override
public Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq) {
productTypeAttrReq.setCreateBy(SecurityUtils.getUsername());
Integer res = typeMapper.insertTypeAttr(productTypeAttrReq);
if(res >0 && productTypeAttrReq.getProductTypeAttrValueList().size()>0){
Integer typeAttrId = productTypeAttrReq.getId();
for (ProductTypeAttrValue productTypeAttrValue : productTypeAttrReq.getProductTypeAttrValueList()) {
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
productTypeAttrValue.setTypeAttrId(typeAttrId);
}
typeMapper.insertTypeValue(productTypeAttrReq.getProductTypeAttrValueList());
}
return res;
}
@Override
public Integer updateTypeAttr(ProductTypeAttrReq productTypeAttrReq) {
productTypeAttrReq.setCreateBy(SecurityUtils.getUsername());
typeMapper.deleteTypeAttrValue(productTypeAttrReq.getId());
Integer res = typeMapper.updateAttr(productTypeAttrReq);
if(res >0 && productTypeAttrReq.getProductTypeAttrValueList().size()>0){
for (ProductTypeAttrValue productTypeAttrValue : productTypeAttrReq.getProductTypeAttrValueList()) {
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
productTypeAttrValue.setTypeAttrId(productTypeAttrReq.getId());
}
typeMapper.insertTypeValue(productTypeAttrReq.getProductTypeAttrValueList());
}
return res;
}
}

View File

@ -69,6 +69,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="queryCategory" resultType="com.muyu.product.domain.DTO.Category">
select <include refid="sqlCategory"></include> from t_product_category
select <include refid="sqlCategory"></include> from t_product_category where id_delete =1
</select>
<select id="queryCategorParent" resultType="com.muyu.product.domain.DTO.Category">
select <include refid="sqlCategory"></include> from t_product_category where id_delete =1 and parent_Id =0
</select>
</mapper>

View File

@ -5,7 +5,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.muyu.product.mapper.SkuMapper">
<select id="selectByExample" resultType="com.muyu.product.domain.DTO.ProductSku">
select
*
from t_product_sku
</select>
</mapper>

View File

@ -3,30 +3,117 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.product.mapper.TypeMapper">
<delete id="deleteType">
update t_product_type set id_delete = 0 where id = #{id}
<insert id="insertType">
insert t_product_type(type_name,create_by,create_time) value (#{typeName},#{createBy},now())
</insert>
<insert id="insertTypeAttr" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `cargo`.`t_product_type_attr` (
`product_type_id`,
`attr_name`,
`multiple_choice`,
`input_method`,
`sort`,
`flag`,
`screen`,
`search`,
`association`,
`stats`,
`input`,
`selection`,
`manual_operation`,
`create_time`,
`create_by`
)
VALUES
(
#{productTypeId},
#{attrName},
#{multipleChoice},
#{inputMethod},
#{sort},
#{flag},
#{screen},
#{search},
#{association},
#{stats},
#{input},
#{selection},
#{manualOperation},
now(),
#{createBy}
)
</insert>
<insert id="insertTypeValue">
INSERT INTO `cargo`.`t_product_type_attr_value` ( `type_attr_id`, `type_attr_value`, `input_method`, `create_time`, `create_by` )
VALUES
<foreach collection="productTypeAttrValueList" separator="," item="productTypeAttrValue">
(
#{productTypeAttrValue.typeAttrId},
#{productTypeAttrValue.typeAttrValue},
#{productTypeAttrValue.inputMethod},
now(),
#{productTypeAttrValue.createBy}
)
</foreach>
</insert>
<update id="deleteType">
update t_product_type set id_delete = 0,update_time = now(),create_by=#{name} where id = #{typeId}
</update>
<update id="updateType">
update t_product_type set type_name = #{typeName},update_time = now(),create_by=#{createBy} where id = #{id}
</update>
<update id="updateAttr">
UPDATE `cargo`.`t_product_type_attr`
SET `product_type_id` = #{productTypeId},
`attr_name` = #{attrName},
`multiple_choice` = #{multipleChoice},
`input_method` = #{inputMethod},
`sort` = #{sort},
`flag` = #{flag},
`screen` = #{screen},
`search` = #{search},
`association` = #{association},
`stats` = #{stats},
`input` = #{input},
`selection` = #{selection},
`manual_operation` = #{manualOperation},
`update_time` = now(),
`create_by` = #{createBy}
WHERE
`id` = #{id}
</update>
<delete id="deleteTypeAttr">
delete from t_product_type_attr where product_type_id = #{id}
</delete>
<!-- 添加其他操作方法如插入、更新、删除等 -->
<select id="queryTypeAll" resultType="com.muyu.product.domain.Resp.ProductTypeResp">
SELECT
t.id,
type_name,
(SELECT COUNT(id) FROM t_product_type_attr WHERE flag = 0 AND product_type_id = t.id) AS countNum,
(SELECT COUNT(id) FROM t_product_type_attr WHERE flag = 1 AND product_type_id = t.id) AS countParam
FROM
t_product_type t
INNER JOIN t_product_type_attr ta ON t.id = ta.product_type_id
INNER JOIN t_product_type_attr_value tav ON tav.type_attr_id = ta.id
GROUP BY
t.id, type_name;
</select>
<select id="queryType" resultType="com.muyu.product.domain.DTO.ProductTypeAttr">
<delete id="deleteTypeAttrValue">
delete from t_product_type_attr_value where type_attr_id = #{id}
</delete>
<resultMap id="productTypeAttrResultMap" type="com.muyu.product.domain.DTO.ProductTypeAttr">
<id column="id" property="id"/>
<result column="product_type_id" property="productTypeId"/>
<result column="attr_name" property="attrName"/>
<result column="multiple_choice" property="multipleChoice"/>
<result column="input_method" property="inputMethod"/>
<result column="sort" property="sort"/>
<result column="flag" property="flag"/>
<result column="screen" property="screen"/>
<result column="search" property="search"/>
<result column="association" property="association"/>
<result column="stats" property="stats"/>
<result column="input" property="input"/>
<result column="selection" property="selection"/>
<result column="manual_operation" property="manualOperation"/>
<result column="type_name" property="typeName"/>
<!-- 集合属性映射 -->
<collection property="typeAttrs" ofType="com.muyu.product.domain.DTO.TypeAttrs">
<result column="tavId" property="typeAttrValueId"/>
<result column="type_attr_value" property="typeAttrValueName"/>
</collection>
</resultMap>
<select id="queryType" resultMap="productTypeAttrResultMap">
SELECT
ta.id as id,
tav.id as tavId,
type_name,
ta.product_type_id,
attr_name,
@ -41,12 +128,29 @@
input,
selection,
manual_operation,
tav.type_attr_id
tav.id as tavId,
tav.type_attr_value
FROM
t_product_type t
INNER JOIN t_product_type_attr ta ON t.id = ta.product_type_id
INNER JOIN t_product_type_attr_value tav ON tav.type_attr_id = ta.id
where ta.id_delete=1 and ta.flag = #{flag} and t.id = #{id}
</select>
<select id="queryTypeAll" resultType="com.muyu.product.domain.Resp.ProductTypeResp">
SELECT
t.id,
t.type_name,
COALESCE(attr_counts.countNum, 0) AS countNum,
COALESCE(param_counts.countParam, 0) AS countParam
FROM
t_product_type t
LEFT JOIN
(SELECT product_type_id, COUNT(id) AS countNum FROM t_product_type_attr WHERE flag = 0 AND id_delete = 1 GROUP BY product_type_id) attr_counts
ON t.id = attr_counts.product_type_id
LEFT JOIN
(SELECT product_type_id, COUNT(id) AS countParam FROM t_product_type_attr WHERE flag = 1 AND id_delete = 1 GROUP BY product_type_id) param_counts
ON t.id = param_counts.product_type_id
</select>
</mapper>