Compare commits

...

10 Commits

Author SHA1 Message Date
wxy 217b0e6c87 更新 2024-04-23 15:07:23 +08:00
wxy 810b36b9db 更新 2024-04-23 15:03:29 +08:00
wxy 247196734f 更新 2024-04-23 15:00:54 +08:00
wxy 383519a2d7 更新 2024-04-12 19:32:58 +08:00
wxy 3febf38dc4 更新 2024-04-11 11:44:25 +08:00
wxy 1f6c718fed 更新 2024-04-11 10:54:10 +08:00
wxy 2d2b0541ff 更新 2024-04-10 21:31:49 +08:00
wxy 48e58bea7c 更新 2024-04-09 21:23:35 +08:00
wxy 8296126d9f 更新 2024-04-09 20:35:13 +08:00
wxy 88de15ced1 更新 2024-04-09 14:26:37 +08:00
47 changed files with 535 additions and 541 deletions

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -138,6 +138,9 @@
</dependencies>
</project>

View File

@ -0,0 +1,216 @@
package com.muyu.common.core.web.domain;
import java.util.HashMap;
import java.util.Objects;
import com.muyu.common.core.constant.HttpStatus;
import com.muyu.common.core.utils.StringUtils;
/**
*
*
* @author ruoyi
*/
public class AjaxResult extends HashMap<String, Object>
{
private static final long serialVersionUID = 1L;
/** 状态码 */
public static final String CODE_TAG = "code";
/** 返回内容 */
public static final String MSG_TAG = "msg";
/** 数据对象 */
public static final String DATA_TAG = "data";
/**
* AjaxResult 使
*/
public AjaxResult()
{
}
/**
* AjaxResult
*
* @param code
* @param msg
*/
public AjaxResult(int code, String msg)
{
super.put(CODE_TAG, code);
super.put(MSG_TAG, msg);
}
/**
* AjaxResult
*
* @param code
* @param msg
* @param data
*/
public AjaxResult(int code, String msg, Object data)
{
super.put(CODE_TAG, code);
super.put(MSG_TAG, msg);
if (StringUtils.isNotNull(data))
{
super.put(DATA_TAG, data);
}
}
/**
*
*
* @return
*/
public static AjaxResult success()
{
return AjaxResult.success("操作成功");
}
/**
*
*
* @return
*/
public static AjaxResult success(Object data)
{
return AjaxResult.success("操作成功", data);
}
/**
*
*
* @param msg
* @return
*/
public static AjaxResult success(String msg)
{
return AjaxResult.success(msg, null);
}
/**
*
*
* @param msg
* @param data
* @return
*/
public static AjaxResult success(String msg, Object data)
{
return new AjaxResult(HttpStatus.SUCCESS, msg, data);
}
/**
*
*
* @param msg
* @return
*/
public static AjaxResult warn(String msg)
{
return AjaxResult.warn(msg, null);
}
/**
*
*
* @param msg
* @param data
* @return
*/
public static AjaxResult warn(String msg, Object data)
{
return new AjaxResult(HttpStatus.WARN, msg, data);
}
/**
*
*
* @return
*/
public static AjaxResult error()
{
return AjaxResult.error("操作失败");
}
/**
*
*
* @param msg
* @return
*/
public static AjaxResult error(String msg)
{
return AjaxResult.error(msg, null);
}
/**
*
*
* @param msg
* @param data
* @return
*/
public static AjaxResult error(String msg, Object data)
{
return new AjaxResult(HttpStatus.ERROR, msg, data);
}
/**
*
*
* @param code
* @param msg
* @return
*/
public static AjaxResult error(int code, String msg)
{
return new AjaxResult(code, msg, null);
}
/**
*
*
* @return
*/
public boolean isSuccess()
{
return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
}
/**
*
*
* @return
*/
public boolean isWarn()
{
return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
}
/**
*
*
* @return
*/
public boolean isError()
{
return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
}
/**
* 便
*
* @param key
* @param value
* @return
*/
@Override
public AjaxResult put(String key, Object value)
{
super.put(key, value);
return this;
}
}

View File

@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit;
public class RedisService {
@Autowired
public RedisTemplate redisTemplate;
/**
* IntegerString
*

View File

@ -27,4 +27,6 @@
muyu-common通用模块
</description>
</project>

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -25,4 +25,5 @@
</dependency>
</dependencies>
</project>

View File

@ -3,7 +3,9 @@ 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.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ -13,29 +15,34 @@ import javax.validation.constraints.NotNull;
* @Date: 2024/3/29 16:57
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "产品实体类")
public class Product extends BaseEntity {
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "名称")
@ApiModelProperty(value = "名称",required = true)
@NotEmpty(message = "名称不能为空")
private String productName;
@ApiModelProperty(value = "货号")
@ApiModelProperty(value = "货号",required = true)
@NotNull(message = "货号不能为空")
private Integer productNumber;
private String productNumber;
@ApiModelProperty(value = "审核状态 (1:通过, 2:驳回)")
private Integer productExamine;
@ApiModelProperty(value = "品牌")
@ApiModelProperty(value = "分类",required = true)
@NotNull(message = "分类不能不选择")
private Integer categoryId;
@ApiModelProperty(value = "品牌",required = true)
@NotNull(message = "品牌不能不选择")
private Integer brandId;
@ApiModelProperty(value = "商品类型")
@NotNull(message = "商品类型不能不选择")
@ApiModelProperty(value = "商品类型",required = true)
private Integer typeId;
@ApiModelProperty(value = "副标题")
@ -51,10 +58,10 @@ public class Product extends BaseEntity {
private Double productWeight;
@ApiModelProperty(value = "排序")
private String productSort;
private Integer productSort;
@ApiModelProperty(value = "促销表id")
private Integer promotionId;
@ApiModelProperty(value = "市场价")
private Integer marketPrice;
@ApiModelProperty(value = "积分")
private Integer productPoints;
@ -102,5 +109,6 @@ public class Product extends BaseEntity {
@ApiModelProperty(value = "PC端信息")
private String pcInformation;
private Integer sales;
}

View File

@ -19,7 +19,7 @@ public class ProductSkuAttr extends BaseEntity {
private Integer id;
@ApiModelProperty(value = "SKU ID")
private BigInteger skuId;
private long skuId;
@ApiModelProperty(value = "属性ID")
private Integer attrId;

View File

@ -57,13 +57,11 @@ 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;
private List<TypeAttrs> typeAttrs;
}

View File

@ -3,13 +3,19 @@ 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.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @Author: wangxinyuan
* @Date: 2024/3/29 16:59
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "ProductTypeAttrValue", description = "产品类型属性值信息")
public class ProductTypeAttrValue extends BaseEntity {
@ -20,9 +26,17 @@ public class ProductTypeAttrValue extends BaseEntity {
private Integer typeAttrId;
@ApiModelProperty(value = "属性值详情")
private Integer typeAttrValue;
private String typeAttrValue;
@ApiModelProperty(value = "录入方式0-自动1-手动")
private Integer inputMethod;
// 添加集合属性及其getter方法
private List<ProductTypeAttrValue> productTypeAttrValueList;
public List<ProductTypeAttrValue> getProductTypeAttrValueList() {
return productTypeAttrValueList;
}
}

View File

@ -34,6 +34,6 @@ public class QueryProductReq {
private Integer pageNum = 1;
@ApiModelProperty(value = "分页参数")
private Integer pageSize = 5;
private Integer pageSize = 10;
}

View File

@ -0,0 +1,52 @@
package com.muyu.product.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author: wangxinyuan
* @Date: 2024/4/10 8:47
*/
@Data
@ApiModel(value = "ProductVo")
@AllArgsConstructor
@NoArgsConstructor
public class ProductVo {
@ApiModelProperty(value = "产品id")
private Integer id;
@ApiModelProperty(value = "产品名称")
private String productName;
@ApiModelProperty(value = "产品信息")
private String productInformation;
@ApiModelProperty(value = "详情标题")
private String detailsTitle;
@ApiModelProperty(value = "详情信息")
private String detailsInformation;
@ApiModelProperty(value = "品牌名称")
private String brandName;
@ApiModelProperty(value = "销售价格")
private Double salePrice;
@ApiModelProperty(value = "促销价格")
private Double promotionPrice;
@ApiModelProperty(value = "图片链接")
private String imagesUrl;
@ApiModelProperty(value = "服务名称")
private String serviceName;
@ApiModelProperty(value = "类型名称")
private String typeName;
}

View File

@ -12,6 +12,7 @@ import com.muyu.product.domain.Resp.ProductResp;
import com.muyu.product.domain.req.ProductReq;
import com.muyu.product.domain.req.QueryProductReq;
import com.muyu.common.core.domain.R;
import com.muyu.product.domain.vo.ProductVo;
import com.muyu.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
@ -50,9 +51,10 @@ public class ProductController {
return success(list);
}
@ApiOperation("添加商品")
@PostMapping("/productInsert")
public R<Product>productInsert(@Valid @RequestBody ProductReq productReq){
public R productInsert(@Valid @RequestBody ProductReq productReq){
productService.productInsert(productReq);
return R.ok(null,"添加成功");
}
@ -95,4 +97,11 @@ public class ProductController {
}
return error("上传图片异常,请联系管理员");
}
@ApiOperation("测试商品信息")
@GetMapping("/queryProductDetails/{id}")
public R<ProductVo> queryProductDetails(@PathVariable Integer id){
ProductVo productVo = productService.queryProductDetails(id);
return R.ok(productVo);
}
}

View File

@ -2,8 +2,8 @@ package com.muyu.product.mapper;
import com.muyu.product.domain.DTO.Product;
import com.muyu.product.domain.Resp.ProductResp;
import com.muyu.product.domain.req.ProductReq;
import com.muyu.product.domain.req.QueryProductReq;
import com.muyu.product.domain.vo.ProductVo;
import java.util.List;
@ -15,11 +15,14 @@ public interface ProductMapper {
List<ProductResp> queryProduct(QueryProductReq productReq);
void insertProduct(Product product);
Integer insertProduct(Product product);
void updateMothodId(Integer id);
Integer findProductNumber(ProductReq productReq);
Integer findProductNumber(String productNumber);
Integer deleteProduct(Integer id);
ProductVo queryProductDetails(Integer id);
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.mapper;
import com.muyu.product.domain.DTO.ProductSku;
import com.muyu.product.domain.DTO.ProductSkuAttr;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -12,10 +13,11 @@ import java.util.List;
*/
@Mapper
public interface ProductSkuMapper {
void insertProductSku(List<ProductSku> productSkuList);
void insertProductSkuAttr(List<ProductSkuAttr> productSkuAttrs);
void insertProductSkuAttr(@Param("productSkuAttrs") List<ProductSkuAttr> productSkuAttrs);
Integer findSkuId(List<ProductSku> productSkus);
void insertProductSku(@Param("productSkus") List<ProductSku> productSkus, @Param("id") Integer id, @Param("createBy") String createBy);
Integer findSkuId(@Param("productSkus") List<ProductSku> productSkus);
}

View File

@ -1,6 +1,7 @@
package com.muyu.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -11,5 +12,5 @@ import java.util.List;
@Mapper
public interface ServicesMapper {
int insertProductServicep(Integer productId, List<Integer> serviceIds);
int insertProductService(@Param("id") Integer id, @Param("serviceIds") List<Integer> serviceIds);
}

View File

@ -18,23 +18,24 @@ import java.util.List;
public interface TypeMapper {
List<ProductTypeResp> queryTypeAll();
List<ProductTypeAttr> queryType(@Param("flag") Integer flag, @Param("id") Integer id);
List<ProductTypeResp> queryTypeAll();
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 deleteTypeAttr(Integer id);
Integer updateAttr(ProductTypeAttrReq productTypeAttrReq);
void deleteTypeAttrValue(Integer typeId);
void insertTypeValue(ProductTypeAttrValue productTypeAttrValue);
}

View File

@ -7,6 +7,7 @@ import com.muyu.product.domain.DTO.ProductSkuAttr;
import com.muyu.product.domain.Resp.ProductResp;
import com.muyu.product.domain.req.ProductReq;
import com.muyu.product.domain.req.QueryProductReq;
import com.muyu.product.domain.vo.ProductVo;
/**
* @Author: wangxinyuan
@ -21,4 +22,6 @@ public interface ProductService {
Integer deleteProduct(Integer id);
void productUpdate(ProductReq productReq);
ProductVo queryProductDetails(Integer id);
}

View File

@ -7,5 +7,6 @@ import java.util.List;
* @Date: 2024/3/29 17:05
*/
public interface ServiceService {
int insertProductService(Integer id, List<Integer> serviceIds);
int insertProductService(Integer productId,List<Integer> serviceIds);
}

View File

@ -1,5 +1,5 @@
package com.muyu.product.service.impl;
import com.alibaba.fastjson.JSONObject; // 导入 FastJSON 的 JSONObject 类
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageHelper; // 导入 PageHelper 类
import com.github.pagehelper.PageInfo; // 导入 PageInfo 类
import com.muyu.common.security.utils.SecurityUtils;
@ -10,7 +10,9 @@ import com.muyu.product.domain.DTO.*;
import com.muyu.product.domain.DTO.Number;
import com.muyu.product.domain.Resp.ProductResp;
import com.muyu.product.domain.req.ProductReq;
import com.muyu.product.domain.req.ProductSkuNew;
import com.muyu.product.domain.req.QueryProductReq;
import com.muyu.product.domain.vo.ProductVo;
import com.muyu.product.mapper.ProductMapper;
import com.muyu.product.mapper.ProductSkuMapper;
import com.muyu.product.mapper.PromotionMapper;
@ -34,10 +36,6 @@ import java.util.concurrent.Executors;
@Log4j2
public class ProductServiceImpl implements ProductService {
private final Integer min = 0;
private final Integer max = 5;
@Resource
private ProductMapper productMapper;
@ -53,33 +51,51 @@ public class ProductServiceImpl implements ProductService {
private ExecutorService executor = Executors.newFixedThreadPool(3);
public void checkProductParams(ProductReq productReq){
CompletableFuture<ValidationResult>methodTypeFuture =
CompletableFuture.supplyAsync(() -> checkMethodType(productReq),executor);
CompletableFuture<ValidationResult>skuIdFuture =
CompletableFuture.supplyAsync(() -> findSkuId(productReq),executor);
CompletableFuture<ValidationResult>productNumberFuture =
CompletableFuture.supplyAsync(() -> checkProductNumber(productReq),executor);
CompletableFuture<String>allValidFuture =
methodTypeFuture.thenCombine(skuIdFuture,
(methodTypeResult,skuIdResult)->
methodTypeResult.isValid()&& skuIdResult.isValid())
.thenCombine(productNumberFuture,(previousResult,productNumberResult)
->previousResult&&productNumberResult.isValid())
.thenApply(allValid->allValid ? "所有检查通过":"存在检查未通过")
.exceptionally(throwable -> "检验过程发送异常" + throwable.getMessage());
// 检查产品参数
public void checkProductParams(ProductReq productReq) {
allValidFuture.thenAccept(System.out::println);
}
private ValidationResult checkProductNumber(ProductReq productReq) {
Integer productNumber = productMapper.findProductNumber(productReq);
if(productNumber>=Integer.valueOf(Number.zero.getValue())){
return new ValidationResult(false,"productNumber不能重复");
try {
// 异步执行方法类型检查
CompletableFuture<ValidationResult> methodTypeFuture =
CompletableFuture.supplyAsync(() -> checkMethodType(productReq), executor);
// 异步执行查找skuId检查
CompletableFuture<ValidationResult> skuIdFuture =
CompletableFuture.supplyAsync(() -> findSkuId(productReq), executor);
// 异步执行产品编号检查
CompletableFuture<ValidationResult> productNumberFuture =
CompletableFuture.supplyAsync(() -> checkProductNumber(productReq), executor);
// 组合所有的异步任务,判断是否所有检查通过
CompletableFuture<String> allValidFuture =
CompletableFuture.allOf(methodTypeFuture, skuIdFuture, productNumberFuture)
.thenApply(ignored -> {
boolean allValid = methodTypeFuture.join().isValid()
&& skuIdFuture.join().isValid()
&& productNumberFuture.join().isValid();
return allValid ? "所有检查通过" : "存在检查未通过";
})
.exceptionally(throwable -> "校验过程发生异常: " + throwable.getMessage());
// 输出结果
allValidFuture.thenAccept(System.out::println);
} catch (Exception e) {
System.err.println("校验过程发生异常: " + e.getMessage());
}
return new ValidationResult(true,"通过");
}
// 检查产品编号
private ValidationResult checkProductNumber(ProductReq productReq) {
try {
Integer productNumber = productMapper.findProductNumber(String.valueOf(productReq.getProduct().getProductNumber()));
if (productNumber < Integer.valueOf(Number.zero.getValue())) {
return new ValidationResult(false, "productNumber不能重复");
}
return new ValidationResult(true, "productNumber检查通过");
} catch (Exception e) {
return new ValidationResult(false, "检查产品编号时发生异常:" + e.getMessage());
}
}
private ValidationResult findSkuId(ProductReq productReq) {
Integer skuId = productSkuMapper.findSkuId(productReq.getProductSkus());
if(skuId>=Integer.valueOf(Number.zero.getValue())){
@ -117,7 +133,7 @@ public class ProductServiceImpl implements ProductService {
insertProductPromotion(productReq);
insertProductSku(productReq);
// insertProductSku(productReq);
log.info("耗时:{}",(System.currentTimeMillis()-start));
@ -134,36 +150,41 @@ public class ProductServiceImpl implements ProductService {
}
@Override
public ProductVo queryProductDetails(Integer id) {
return productMapper.queryProductDetails(id);
}
private void insertProductSku(ProductReq productReq) {
List<ProductSku> productSkuList = productReq.getProductSkus();
int productId = productReq.getProduct().getId();
// 设置商品ID
productSkuList.forEach(productSku -> productSku.setProductId(productId));
// 批量添加 productSku
productSkuMapper.insertProductSku(productSkuList);
// 添加 skuAttr
List<ProductSkuAttr> productSkuAttrs = new ArrayList<>();
productSkuList.forEach(productSku -> {
// 获取 sku 的属性值
Map<String, Integer> attributes = productSku.getAttributes();
// 构造 ProductSkuAttr 对象
attributes.forEach((key, value) -> {
String createBy = SecurityUtils.getUsername();
//批量添加
productSkuMapper.insertProductSku(productSkuList,productReq.getProduct().getId(),createBy);
//添加skuAttr除实体类以外的字段
ArrayList<ProductSkuAttr> productSkuAttrs = new ArrayList<>();
productSkuList.forEach(productSkusReq -> {
//获取id
//productSkusReq.setProductId(productReq.getProduct().getId());
//获取map的属性值
ProductSkuNew productSkuNew = com.alibaba.fastjson2.JSONObject.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(productSkusReq), ProductSkuNew.class);
HashMap hashMap = com.alibaba.fastjson2.JSONObject.parseObject(JSONObject.toJSONString(productSkuNew), HashMap.class);
Set skuReq = productSkusReq.keySet();
Set sku = hashMap.keySet();
//添加一个新的set
Set set = skuReq;
//去重
set.removeAll(sku);
//格属性赋值
set.forEach(key ->{
ProductSkuAttr productSkuAttr = new ProductSkuAttr();
productSkuAttr.setSkuId(productSku.getId());
productSkuAttr.setAttrId(Integer.valueOf(key));
productSkuAttr.setAttrValueId(value);
productSkuAttr.setSkuId(productSkuNew.getId());
productSkuAttr.setAttrId(Integer.valueOf(key.toString()));
productSkuAttr.setAttrValueId(Integer.valueOf(productSkusReq.get(key).toString()));
productSkuAttr.setFlag(Integer.valueOf(Number.zero.getValue()));
productSkuAttrs.add(productSkuAttr);
});
});
log.info("productSkuAttrs 中的数据为:{}", JSONObject.toJSONString(productSkuAttrs));
// 批量添加 productSkuAttr
//批量添加productSkuAttr
productSkuMapper.insertProductSkuAttr(productSkuAttrs);
}
@ -214,6 +235,7 @@ public class ProductServiceImpl implements ProductService {
serviceService.insertProductService(id,serviceIds);
}
private void insertProduct(Product product) {
product.setCreateBy(SecurityUtils.getUsername());
productMapper.insertProduct(product);

View File

@ -18,6 +18,6 @@ public class ServiceServiceImpl implements ServiceService {
private ServicesMapper servicesMapper;
@Override
public int insertProductService(Integer productId, List<Integer> serviceIds) {
return servicesMapper.insertProductServicep(productId,serviceIds);
return servicesMapper.insertProductService(productId,serviceIds);
}
}

View File

@ -31,13 +31,13 @@ public class TypeServiceImpl implements TypeService {
@Override
public List<ProductTypeAttr> queryType(Integer flag, Integer id) {
return typeMapper.queryType(flag,id);
return typeMapper.queryType(flag, id);
}
@Override
public Integer deleteType(Integer typeId) {
String name = SecurityUtils.getUsername();
return typeMapper.deleteType(typeId,name);
return typeMapper.deleteType(typeId, name);
}
@Override
@ -62,13 +62,18 @@ public class TypeServiceImpl implements TypeService {
public Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq) {
productTypeAttrReq.setCreateBy(SecurityUtils.getUsername());
Integer res = typeMapper.insertTypeAttr(productTypeAttrReq);
if(res >0 && productTypeAttrReq.getProductTypeAttrValueList().size()>0){
String[] split = productTypeAttrReq.getProductTypeAttrValueList().split(",");
if (res > 0) {
Integer typeAttrId = productTypeAttrReq.getId();
for (ProductTypeAttrValue productTypeAttrValue : productTypeAttrReq.getProductTypeAttrValueList()) {
ProductTypeAttrValue productTypeAttrValue = new ProductTypeAttrValue();
for (String s : split) {
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
productTypeAttrValue.setTypeAttrId(typeAttrId);
productTypeAttrValue.setTypeAttrValue(s);
typeMapper.insertTypeValue(productTypeAttrValue);
}
typeMapper.insertTypeValue(productTypeAttrReq.getProductTypeAttrValueList());
}
return res;
}
@ -78,12 +83,16 @@ public class TypeServiceImpl implements TypeService {
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()) {
String[] split = productTypeAttrReq.getProductTypeAttrValueList().split(",");
if (res > 0) {
Integer typeAttrId = productTypeAttrReq.getId();
ProductTypeAttrValue productTypeAttrValue = new ProductTypeAttrValue();
for (String s : split) {
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
productTypeAttrValue.setTypeAttrId(productTypeAttrReq.getId());
productTypeAttrValue.setTypeAttrId(typeAttrId);
productTypeAttrValue.setTypeAttrValue(s);
typeMapper.insertTypeValue(productTypeAttrValue);
}
typeMapper.insertTypeValue(productTypeAttrReq.getProductTypeAttrValueList());
}
return res;
}

View File

@ -6,7 +6,7 @@ server:
spring:
application:
# 应用名称
name: muyu-product
name: muyu-product-wxy
profiles:
# 环境配置
active: dev
@ -14,10 +14,13 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
server-addr: 43.142.117.78:8848
namespace: 9facbf7b-873b-4e11-b54f-00627208906d
ip: 111.231.174.71
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -12,14 +12,14 @@
product_recommended,details_title,details_information,details_key_word,details_remark,
method_type,t_product_brand.brand_name,t_product_type.type_name,sale_price,images_url,sales
</sql>
<insert id="insertProduct">
INSERT INTO `product`.`t_Product` (
<insert id="insertProduct" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `t_product` (
`product_name`,
`product_number`,
`brand_id`,
`type_id`,
`product_subheading`,
`product_examine`,
`product_information`,
`product_unit`,
`product_weight`,
@ -28,7 +28,7 @@
`product_growth`,
`product_max_points`,
`product_foreknow`,
`product_staus`,
`product_status`,
`product_new`,
`product_recommended`,
`details_title`,
@ -37,13 +37,15 @@
`details_remark`,
`method_type`,
`create_by`,
`create_time`
`create_time`,
`sales`
) VALUES (
#{productName},
#{productNumber},
#{brandId},
#{typeId},
#{productSubheading},
#{productExamine},
#{productInformation},
#{productUnit},
#{productWeight},
@ -61,12 +63,12 @@
#{detailsRemark},
#{methodType},
#{createBy},
NOW()
);
NOW(),
#{sales}
)
</insert>
<update id="updateMothodId">
update t_product set method_id =#{methodId} where id = #{id}
</update>
@ -105,13 +107,29 @@
</where>
order by product_sort
</select>
<select id="findProductNumber" resultType="java.lang.Integer">
<select id="findProductNumber" resultType="java.lang.Integer">
select count(id) from t_product where id_delete = 1 and product_number = #{productNumber}
</select>
<select id="queryProductDetails" resultType="com.muyu.product.domain.vo.ProductVo">
SELECT
p.id,
product_name,
p.product_information,
details_title,
details_information,
brand_name,
sale_price,
promotion_price,
images_url,
GROUP_CONCAT( service_name ) service_name ,
type_name
FROM
t_product p
</select>
<!-- 添加其他操作方法如插入、更新、删除等 -->
</mapper>

View File

@ -9,9 +9,16 @@
<!-- 添加其他操作方法如插入、更新、删除等 -->
<insert id="insertProductSku">
insert t_product_sku (id,sale_price,promotion_price,stock,stock_alert
,product_id,bg_img,create_time,create_by)
insert t_product_sku (
id,
sale_price,
promotion_price,
stock,
stock_alert,
product_id,
bg_img,
create_time
)
values
<foreach collection="productSkus" item="productSku" separator=",">
(
@ -20,17 +27,16 @@
#{productSku.promotionPrice},
#{productSku.stock},
#{productSku.stockAlert},
#{productSku.productId},
${id},
#{productSku.bgImg},
#{productSku.createTime},
#{productSku.createBy}
now()
)
</foreach>
</insert>
<insert id="insertProductSkuAttr">
INSERT INTO `product`.`t_product_sku_attr` (
INSERT INTO `t_product_sku_attr` (
`sku_id`, `attr_id`, `attr_value_id`, `attr_value`, `flag`, `create_time`, `create_by`
) VALUES
<foreach collection="productSkuAttrs" separator="," item="productSkuAttr">
@ -45,12 +51,14 @@
)
</foreach>
</insert>
<select id="findSkuId" resultType="java.lang.Integer">
select count(id) from t_product_sku where id in
select count(id) from t_product_sku where id_delete = 1 and id in
<foreach collection="productSkus" separator="," open="(" close=")" item="id">
#{id}
</foreach>
</select>
<select id="querySku" resultType="com.muyu.product.domain.DTO.ProductSku">
select * from t_product_sku
</select>

View File

@ -20,7 +20,14 @@
( #{memberGold},#{memberSilver},#{memberDiamond},now(),#{createBy} )
</insert>
<insert id="insertLadder">
INSERT INTO `t_product_ladder` ( `ladder_num`, `ladder_discount`, `create_time`, `create_by` )
VALUES
(
#{ladderNum},
#{ladderDiscount},
now(),
#{createBy}
)
</insert>
<insert id="insertPrice">

View File

@ -8,11 +8,9 @@
<!-- 添加其他操作方法如插入、更新、删除等 -->
<insert id="insertProductServicep">
insert t_product_service_middle(product_id,service_id)
values
<foreach collection="serviceIds" item="ids" separator=",">
(#{id},#{ids})
</foreach>
<insert id="insertProductService">
insert into t_product_service_middle(product_id, service_id) values (1, 2);
</insert>
</mapper>

View File

@ -3,9 +3,11 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.product.mapper.TypeMapper">
<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 `product`.`t_product_type_attr` (
`product_type_id`,
@ -29,7 +31,7 @@
#{productTypeId},
#{attrName},
#{multipleChoice},
#{inputMethod},
#{input},
#{sort},
#{flag},
#{screen},
@ -46,22 +48,23 @@
<insert id="insertTypeValue">
INSERT INTO `product`.`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}
#{typeAttrId},
#{typeAttrValue},
#{inputMethod},
now(),
#{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 `product`.`t_product_type_attr`
SET `product_type_id` = #{productTypeId},
@ -136,6 +139,7 @@
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,

View File

@ -16,7 +16,6 @@
<module>muyu-product-commo</module>
<module>muyu-product-remote</module>
<module>muyu-product-server</module>
<module>muyu-product-server</module>
</modules>
<properties>

View File

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu</artifactId>
<version>3.6.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>muyu-rabbit</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.23</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,32 +0,0 @@
package com.muyu.rabbit.Consumer;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @Author: wangxinyuan
* @Date: 2024/4/8 21:02
*/
@Component
public class MessageReceiver {
@RabbitListener(queues = "DxQueue")
public void receiveMessage(@Payload String message) {
try {
// 手动添加异常代码,模拟消费时的异常情况
if (message.contains("error")) {
throw new RuntimeException("Simulated error");
}
System.out.println("Received message: " + message);
// 模拟消费成功打印ack成功日志
System.out.println("ACK: Message processed successfully");
} catch (Exception e) {
// 消费异常,打印失败日志
System.err.println("Failed to process message: " + e.getMessage());
// 可以选择进行消息的重试或者将消息进行持久化等操作
}
}
}

View File

@ -1,22 +0,0 @@
package com.muyu.rabbit.Consumer;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @Author: wangxinyuan
* @Date: 2024/4/8 21:02
*/
@Component
public class MessageSender {
@Autowired
private AmqpTemplate amqpTemplate;
public void sendMessage(String message){
amqpTemplate.convertAndSend("exchange", "routingKey", message);
}
}

View File

@ -1,15 +0,0 @@
package com.muyu.rabbit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Author: wangxinyuan
* @Date: 2024/4/8 15:06
*/
@SpringBootApplication
public class RabbitApplication {
public static void main(String[] args) {
SpringApplication.run(RabbitApplication.class);
}
}

View File

@ -1,53 +0,0 @@
package com.muyu.rabbit.util;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* RabbitAdminRabbitMQJavaRabbitMQRabbitMQ
*/
@Configuration
public class RabbitAdminConfig {
@Value("${spring.rabbitmq.host}")
private String host;
@Value("${spring.rabbitmq.username}")
private String username;
@Value("${spring.rabbitmq.password}")
private String password;
@Value("${spring.rabbitmq.virtualhost}")
private String virtualhost;
/**
* RabbitMQ
* @return
*/
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setAddresses(host);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost(virtualhost);
// 配置发送确认回调时次配置必须配置否则即使在RabbitTemplate配置了ConfirmCallback也不会生效
connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
connectionFactory.setPublisherReturns(true);
return connectionFactory;
}
/**
* RabbitAdmin
* @param connectionFactory
* @return
*/
@Bean
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
rabbitAdmin.setAutoStartup(true);
return rabbitAdmin;
}
}

View File

@ -1,79 +0,0 @@
package com.muyu.rabbit.util.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* @CLassName MqConfig
* @Description
* @Author Meng.Wang
* @Date 2023/11/24 21:15
*/
@Configuration
@Log4j2
public class MqConfig implements RabbitTemplate.ReturnsCallback,RabbitTemplate.ConfirmCallback{
public static final String DXQUEUE = "DxQueue";
public static final String DXEXCHANGE = "DxExchange";
public static final String ROUTINGKEY = "RoutingKey";
private RabbitTemplate rabbitTemplate;
//创建消息转换器
@Bean
public MessageConverter messageConverter(){
return new Jackson2JsonMessageConverter();
}
//创建队列
@Bean
public Queue queue(){
return new Queue(DXQUEUE,true);
}
//创建交换机
@Primary
@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
this.rabbitTemplate = rabbitTemplate;
rabbitTemplate.setMessageConverter(messageConverter());
rabbitTemplate();
return rabbitTemplate;
}
@Bean("DxExchange")
public DirectExchange directExchange(){
return new DirectExchange(DXEXCHANGE);
}
public void rabbitTemplate(){
rabbitTemplate.setConfirmCallback(this);
rabbitTemplate.setReturnsCallback(this);
}
@Bean
public Binding binding(){
return BindingBuilder.bind(queue()).to(directExchange()).with(ROUTINGKEY);
}
@Override
public void confirm(CorrelationData correlationData, boolean b, String s) {
if(b){
log.info("{}消息到达交换机",correlationData.getId());
}else {
log.error("{}消息丢失",correlationData.getId());
}
}
@Override
public void returnedMessage(ReturnedMessage returnedMessage) {
log.error("{}消息未到达队列",returnedMessage.getMessage().getMessageProperties().getMessageId());
}
}

View File

@ -1,32 +0,0 @@
package com.muyu.rabbit.util.config;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.sql.Connection;
/**
* @Author: wangxinyuan
* @Date: 2024/4/8 20:23
*/
@Configuration
@EnableRabbit
public class RabbitConfig {
@Bean
public AmqpTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
return new RabbitTemplate(connectionFactory);
}
}

View File

@ -1,18 +0,0 @@
package com.muyu.rabbit.util.config;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Author: wangxinyuan
* @Date: 2024/4/8 21:00
*/
@Configuration
public class RabbitMQConfig {
@Bean
public Queue queue() {
return new Queue("queue");
}
}

View File

@ -1,65 +0,0 @@
server:
port: 9197
spring:
datasource:
druid:
stat-view-servlet:
enabled: true
loginUsername: admin
loginPassword: 123456
dynamic:
druid:
initial-size: 5
min-idle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,slf4j
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
# 主库数据源
master:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://111.231.174.71:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: wxy@123
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:
main:
allow-bean-definition-overriding: true
application:
name: muyu-rabbit
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
serverAddr: 111.231.174.71:8848
config:
serverAddr: 111.231.174.71:8848
fileExtension: yml
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
rabbitmq:
username: guest
password: guest
virtualHost: /
port: 5672
host: 111.231.174.71
listener:
simple:
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
publisher-returns: true #确认消息已发送到队列(Queue)

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -13,8 +13,10 @@
<module>muyu-gen</module>
<module>muyu-job</module>
<module>muyu-file</module>
<module>muyu-product</module>
</modules>
<artifactId>muyu-modules</artifactId>
<packaging>pom</packaging>
@ -22,4 +24,6 @@
muyu-modules业务模块
</description>
</project>

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
config:
# 配置中心地址
server-addr: 111.231.174.71:8848
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
# 配置文件格式
file-extension: yml
# 共享配置

21
pom.xml
View File

@ -215,8 +215,6 @@
<module>muyu-visual</module>
<module>muyu-modules</module>
<module>muyu-common</module>
<module>muyu-modules/muyu-product</module>
<module>muyu-modules/muyu-rabbit</module>
</modules>
<packaging>pom</packaging>
@ -255,22 +253,7 @@
</executions>
</plugin>
<!-- 要将源码放上去,需要加入这个插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
@ -308,4 +291,6 @@
</pluginRepository>
</pluginRepositories>
</project>