chenlei1231 4 месяцев назад
Родитель
Сommit
a39f484e82

+ 162 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/product/controller/AdwebProductController.java

@@ -0,0 +1,162 @@
+package org.jeecg.modules.adweb.product.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.modules.adweb.product.entity.AdwebProduct;
+import org.jeecg.modules.adweb.product.service.IAdwebProductService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
+
+import java.util.Arrays;
+
+/**
+ * @Description: wp站点产品
+ * @Author: jeecg-boot
+ * @Date: 2024-12-06
+ * @Version: V1.0
+ */
+@Tag(name = "wp站点产品")
+@RestController
+@RequestMapping("/adweb/adwebProduct")
+@Slf4j
+public class AdwebProductController extends JeecgController<AdwebProduct, IAdwebProductService> {
+    @Autowired
+    private IAdwebProductService adwebProductService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param adwebProduct
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    //@AutoLog(value = "wp站点产品-分页列表查询")
+    @Operation(summary = "wp站点产品-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<AdwebProduct>> queryPageList(AdwebProduct adwebProduct,
+                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                     HttpServletRequest req) {
+        QueryWrapper<AdwebProduct> queryWrapper = QueryGenerator.initQueryWrapper(adwebProduct, req.getParameterMap());
+        Page<AdwebProduct> page = new Page<AdwebProduct>(pageNo, pageSize);
+        IPage<AdwebProduct> pageList = adwebProductService.page(page, queryWrapper);
+        return Result.OK(pageList);
+    }
+
+    /**
+     * 添加
+     *
+     * @param adwebProduct
+     * @return
+     */
+    @AutoLog(value = "wp站点产品-添加")
+    @Operation(summary = "wp站点产品-添加")
+    @PreAuthorize("@jps.requiresPermissions('adweb:adweb_product:add')")
+    @PostMapping(value = "/add")
+    public Result<String> add(@RequestBody AdwebProduct adwebProduct) {
+        adwebProductService.save(adwebProduct);
+        return Result.OK("添加成功!");
+    }
+
+    /**
+     * 编辑
+     *
+     * @param adwebProduct
+     * @return
+     */
+    @AutoLog(value = "wp站点产品-编辑")
+    @Operation(summary = "wp站点产品-编辑")
+    @PreAuthorize("@jps.requiresPermissions('adweb:adweb_product:edit')")
+    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
+    public Result<String> edit(@RequestBody AdwebProduct adwebProduct) {
+        adwebProductService.updateById(adwebProduct);
+        return Result.OK("编辑成功!");
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "wp站点产品-通过id删除")
+    @Operation(summary = "wp站点产品-通过id删除")
+    @PreAuthorize("@jps.requiresPermissions('adweb:adweb_product:delete')")
+    @DeleteMapping(value = "/delete")
+    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
+        adwebProductService.removeById(id);
+        return Result.OK("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "wp站点产品-批量删除")
+    @Operation(summary = "wp站点产品-批量删除")
+    @PreAuthorize("@jps.requiresPermissions('adweb:adweb_product:deleteBatch')")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        this.adwebProductService.removeByIds(Arrays.asList(ids.split(",")));
+        return Result.OK("批量删除成功!");
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    //@AutoLog(value = "wp站点产品-通过id查询")
+    @Operation(summary = "wp站点产品-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<AdwebProduct> queryById(@RequestParam(name = "id", required = true) String id) {
+        AdwebProduct adwebProduct = adwebProductService.getById(id);
+        if (adwebProduct == null) {
+            return Result.error("未找到对应数据");
+        }
+        return Result.OK(adwebProduct);
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param adwebProduct
+     */
+    @PreAuthorize("@jps.requiresPermissions('adweb:adweb_product:exportXls')")
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, AdwebProduct adwebProduct) {
+        return super.exportXls(request, adwebProduct, AdwebProduct.class, "wp站点产品");
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @PreAuthorize("@jps.requiresPermissions('adweb:adweb_product:importExcel')")
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        return super.importExcel(request, response, AdwebProduct.class);
+    }
+
+}

+ 65 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/product/dto/ProductDTO.java

@@ -0,0 +1,65 @@
+package org.jeecg.modules.adweb.product.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @author chenpeiqing
+ */
+@Data
+public class ProductDTO {
+    /**
+     *
+     */
+    private Integer productId;
+
+    /**
+     * adwebpro or woocommerce
+     */
+    private String productType;
+
+    /**
+     * add, edit, delete
+     */
+    private String actionType;
+
+    @JsonFormat(shape = JsonFormat.Shape.STRING, timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date requestTime;
+    /**
+     *
+     */
+    private String productName;
+
+    /**
+     *
+     */
+    private String productNameZh;
+
+    /**
+     *
+     */
+    private String productImage;
+
+    /**
+     *
+     */
+    private String productGalleryImage;
+
+    /**
+     *
+     */
+    private String categoryName;
+
+    /**
+     *
+     */
+    private String authorName;
+
+    /**
+     * siteHost
+     */
+
+    private String siteHost;
+}

+ 126 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/product/entity/AdwebProduct.java

@@ -0,0 +1,126 @@
+package org.jeecg.modules.adweb.product.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+
+/**
+ * @Description: wp站点产品
+ * @Author: jeecg-boot
+ * @Date: 2024-12-06
+ * @Version: V1.0
+ */
+@Data
+@TableName("adweb_product")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@Schema(description = "wp站点产品")
+public class AdwebProduct implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(type = IdType.ASSIGN_ID)
+    @Schema(description = "主键")
+    private java.lang.String id;
+    /**
+     * 创建人
+     */
+    @Schema(description = "创建人")
+    private java.lang.String createBy;
+    /**
+     * 创建日期
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "创建日期")
+    private java.util.Date createTime;
+    /**
+     * 更新人
+     */
+    @Schema(description = "更新人")
+    private java.lang.String updateBy;
+    /**
+     * 更新日期
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "更新日期")
+    private java.util.Date updateTime;
+    /**
+     * 站点code
+     */
+    @Excel(name = "站点code", width = 15)
+    @Schema(description = "站点code")
+    private java.lang.String siteCode;
+    /**
+     * mq生产时间
+     */
+    @Excel(name = "mq生产时间", width = 15)
+    @Schema(description = "mq生产时间")
+    private java.lang.String requestTime;
+    /**
+     * wp产品ID
+     */
+    @Excel(name = "wp产品ID", width = 15)
+    @Schema(description = "wp产品ID")
+    private java.lang.Integer productId;
+    /**
+     * wp产品类型,adwebpro or woocommerce
+     */
+    @Excel(name = "wp产品类型,adwebpro or woocommerce", width = 15)
+    @Schema(description = "wp产品类型,adwebpro or woocommerce")
+    private java.lang.String productType;
+    /**
+     * wp产品操作类型, add, edit, delete
+     */
+    @Excel(name = "wp产品操作类型, add, edit, delete", width = 15)
+    @Schema(description = "wp产品操作类型, add, edit, delete")
+    private java.lang.String actionType;
+    /**
+     * wp产品名称
+     */
+    @Excel(name = "wp产品名称", width = 15)
+    @Schema(description = "wp产品名称")
+    private java.lang.String productName;
+    /**
+     * wp产品中文名称
+     */
+    @Excel(name = "wp产品中文名称", width = 15)
+    @Schema(description = "wp产品中文名称")
+    private java.lang.String productsNameZh;
+    /**
+     * wp产品封面图
+     */
+    @Excel(name = "wp产品封面图", width = 15)
+    @Schema(description = "wp产品封面图")
+    private java.lang.String productImage;
+    /**
+     * wp产品图库
+     */
+    @Excel(name = "wp产品图库", width = 15)
+    @Schema(description = "wp产品图库")
+    private java.lang.String productGalleryImage;
+    /**
+     * wp产品分类
+     */
+    @Excel(name = "wp产品分类", width = 15)
+    @Schema(description = "wp产品分类")
+    private java.lang.String categoryName;
+    /**
+     * wp产品作者
+     */
+    @Excel(name = "wp产品作者", width = 15)
+    @Schema(description = "wp产品作者")
+    private java.lang.String authorName;
+}

+ 14 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/product/mapper/AdwebProductMapper.java

@@ -0,0 +1,14 @@
+package org.jeecg.modules.adweb.product.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.adweb.product.entity.AdwebProduct;
+
+/**
+ * @Description: wp站点产品
+ * @Author: jeecg-boot
+ * @Date: 2024-12-06
+ * @Version: V1.0
+ */
+public interface AdwebProductMapper extends BaseMapper<AdwebProduct> {
+
+}

+ 5 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/product/mapper/xml/AdwebProductMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.adweb.product.mapper.AdwebProductMapper">
+
+</mapper>

+ 19 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/product/service/IAdwebProductService.java

@@ -0,0 +1,19 @@
+package org.jeecg.modules.adweb.product.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.adweb.product.dto.ProductDTO;
+import org.jeecg.modules.adweb.product.entity.AdwebProduct;
+import org.jeecg.modules.adweb.site.entity.AdwebSite;
+
+/**
+ * @Description: wp站点产品
+ * @Author: jeecg-boot
+ * @Date: 2024-12-06
+ * @Version: V1.0
+ */
+public interface IAdwebProductService extends IService<AdwebProduct> {
+
+    void addProduct(ProductDTO productDTO, AdwebSite adwebSites);
+
+    void updateProduct(ProductDTO productDTO, AdwebSite adwebSites);
+}

+ 44 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/product/service/impl/AdwebProductServiceImpl.java

@@ -0,0 +1,44 @@
+package org.jeecg.modules.adweb.product.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.modules.adweb.product.dto.ProductDTO;
+import org.jeecg.modules.adweb.product.entity.AdwebProduct;
+import org.jeecg.modules.adweb.product.mapper.AdwebProductMapper;
+import org.jeecg.modules.adweb.product.service.IAdwebProductService;
+import org.jeecg.modules.adweb.site.entity.AdwebSite;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Description: wp站点产品
+ * @Author: jeecg-boot
+ * @Date: 2024-12-06
+ * @Version: V1.0
+ */
+@Service
+public class AdwebProductServiceImpl extends ServiceImpl<AdwebProductMapper, AdwebProduct> implements IAdwebProductService {
+
+    /**
+     * @param productDTO
+     * @param adwebSites
+     */
+    @Override
+    public void addProduct(ProductDTO productDTO, AdwebSite adwebSites) {
+        AdwebProduct product = new AdwebProduct();
+        BeanUtil.copyProperties(productDTO, product);
+
+        product
+                .setSiteCode(adwebSites.getCode());
+
+        this.save(product);
+    }
+
+    /**
+     * @param productDTO
+     * @param adwebSites
+     */
+    @Override
+    public void updateProduct(ProductDTO productDTO, AdwebSite adwebSites) {
+
+    }
+}

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mq/EnquiryReceiver.java

@@ -81,7 +81,7 @@ public class EnquiryReceiver extends BaseRabbiMqHandler<EnquiryDTO> {
 
                         if (adwebSites.isEmpty()) {
                             log.error(
-                                    "站点:{} 不是adweb3的有效绑定站点,MQ消息确认失败: {}",
+                                    "站点:{} 不是adweb3的有效绑定站点,MQ消息确认失败",
                                     enquiry.getSiteHost());
                             return;
                         }

+ 80 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mq/ProductReceiver.java

@@ -0,0 +1,80 @@
+package org.jeecg.modules.mq;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
+import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
+import org.jeecg.common.annotation.RabbitComponent;
+import org.jeecg.modules.adweb.product.dto.ProductDTO;
+import org.jeecg.modules.adweb.product.service.IAdwebProductService;
+import org.jeecg.modules.adweb.site.entity.AdwebSite;
+import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.support.AmqpHeaders;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.messaging.handler.annotation.Header;
+
+import java.util.List;
+
+/**
+ * Rabbit MQ - 产品消息接收
+ *
+ * @author chenpeiqing
+ */
+@Slf4j
+@RabbitComponent(value = "productReceiver")
+public class ProductReceiver extends BaseRabbiMqHandler<ProductDTO> {
+
+    @Autowired
+    private IAdwebSiteService adwebSiteService;
+
+    @Autowired
+    private IAdwebProductService adwebProductService;
+
+    @RabbitHandler
+    // ackMode需要设置为MANUAL - BaseRabbiMqHandler.onMessage()有channel.basicAck()操作
+    @RabbitListener(queues = "site_product", ackMode = "MANUAL")
+    public void onMessage(
+            ProductDTO productDTO,
+            Channel channel,
+            @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
+        super.onMessage(
+                productDTO,
+                deliveryTag,
+                channel,
+                new MqListener<ProductDTO>() {
+                    @Override
+                    public void handler(ProductDTO productDTO, Channel channel) {
+                        // 业务处理
+                        log.info("收到MQ消息 {}", productDTO);
+
+                        // TODO 产品消息内容唯一性判断
+
+                        // 查看发布当前消息的站点是否是 adweb3 平台中绑定的是否是有效站点, 如果不是则直接确认消息,不做业务处理
+                        List<AdwebSite> adwebSites =
+                                adwebSiteService.list(
+                                        new LambdaQueryWrapper<AdwebSite>()
+                                                .like(AdwebSite::getDomain, productDTO.getSiteHost())
+                                                .ne(AdwebSite::getStatus, 0));
+
+                        if (adwebSites.isEmpty()) {
+                            log.error(
+                                    "站点:{} 不是adweb3的有效绑定站点,MQ消息确认失败",
+                                    productDTO.getSiteHost());
+                            return;
+                        }
+
+
+                        try {
+                            // 产品入库
+                            adwebProductService.addProduct(
+                                    productDTO, adwebSites.get(0));
+                        } catch (Exception e) {
+                            log.error("询盘入库异常:{}", e.getMessage());
+                        }
+                    }
+                });
+    }
+}