Browse Source

网站管理

chenlei1231 5 months ago
parent
commit
e0584d5dda

+ 5 - 0
jeecg-module-system/jeecg-system-biz/pom.xml

@@ -39,6 +39,11 @@
 			<artifactId>drag-free-springboot3</artifactId>
 			<version>1.1.2</version>
 		</dependency>
+		<dependency>
+			<groupId>cn.hutool</groupId>
+			<artifactId>hutool-parent</artifactId>
+			<version>5.8.25</version>
+		</dependency>
 	<!-- 积木报表 mongo redis 支持包 
 		<dependency>
 			<groupId>org.jeecgframework.jimureport</groupId>

+ 60 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/constant/NumConstant.java

@@ -0,0 +1,60 @@
+package org.jeecg.modules.adweb.constant;
+
+public class NumConstant {
+
+    public static final Integer MINUS_ONE = -1;
+
+    public static final Integer ZERO = 0;
+
+    public static final Integer ONE = 1;
+
+    public static final Integer TWO = 2;
+
+    public static final Integer THREE = 3;
+
+    public static final Integer FOUR = 4;
+
+    public static final Integer FIVE = 5;
+
+    public static final Integer SIX = 6;
+
+    public static final Integer SEVEN = 7;
+
+    public static final Integer EIGHT = 8;
+
+    public static final Integer NINE = 9;
+
+    public static final Integer TEN = 10;
+
+    public static final Integer ELEVEN = 11;
+
+    public static final Integer TWELF = 12;
+
+    public static final Integer THIRTEEN = 13;
+
+    public static final Integer FOURTEEN = 14;
+
+    public static final Integer FIFTEEN = 15;
+
+    public static final Integer EIGHTEEN = 18;
+
+    public static final Integer TWENTY = 20;
+
+    public static final Integer THRITY = 30;
+
+    public static final Integer CONS_50 = 50;
+
+    public static final Integer CONS_80 = 80;
+
+    public static final Integer CONS_100 = 100;
+
+    public static final Integer CONS_443 = 443;
+
+    public static final Integer SIXTY = 60;
+
+    public static final Integer ONEHUNDREDTWENTY = 120;
+
+    public static final Integer HUGE = 99999;
+
+    public static final Integer MILLION = 1000000;
+}

+ 14 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/constant/WordPressConstants.java

@@ -0,0 +1,14 @@
+package org.jeecg.modules.adweb.constant;
+
+public class WordPressConstants {
+    public static final String SSO_RES_KEY_NAME = "Adweb_Wordpress_ssoResKey";
+
+    // dev-ci1
+    public static final String DEV_CI1 = "52.83.52.93";
+
+    // dev-ci2
+    public static final String DEV_CI2 = "52.83.132.56";
+
+    //prod-server-wp
+    public static final String PROD_WP_SERVER_IP = "44.227.32.118";
+}

+ 43 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/controller/AdwebSiteManageController.java

@@ -0,0 +1,43 @@
+package org.jeecg.modules.adweb.site.controller;
+
+
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.adweb.site.dto.WordPressConfig;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.modules.adweb.site.entity.AdwebSite;
+import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
+
+/**
+ * @Description: adweb_site
+ * @Author: jeecg-boot
+ * @Date: 2020-12-24
+ * @Version: V1.0
+ */
+@Tag(name="adweb站点配置表单")
+@RestController
+@RequestMapping("/adweb/adwebSiteManage")
+@Slf4j
+public class AdwebSiteManageController extends JeecgController<AdwebSite, IAdwebSiteService> {
+
+    @Autowired
+    private IAdwebSiteService adwebSiteManageService;
+
+
+    /**
+     * 查询wordpress站点配置
+     * @param wordPressConfig
+     * @return
+     */
+    @PostMapping(value = "/queryWordPressConfig")
+    public Result<?> queryWordPressConfig(@RequestBody WordPressConfig wordPressConfig) {
+        WordPressConfig config = this.adwebSiteManageService.queryWordPressConfig(wordPressConfig.getSiteCode());
+        return Result.OK(config);
+    }
+}

+ 70 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/dto/WordPressConfig.java

@@ -0,0 +1,70 @@
+package org.jeecg.modules.adweb.site.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description: wordpress 配置信息
+ * @Author:
+ * @date
+ */
+@Data
+public class WordPressConfig implements Serializable {
+
+    /**
+     * 站点code
+     */
+    private String siteCode;
+
+    /**
+     * wp站点域名
+     */
+    private String domain;
+
+    /**
+     * 物料模块是否嵌入WordPress,0:否;1:是
+     */
+    private Integer wordpressSwitch;
+
+    /**
+     * WordPress登录账户
+     */
+    private String wordpressName;
+
+    /**
+     * WordPress登录token
+     */
+    private String wordpressToken;
+
+    /**
+     * WordPress站点状态
+     */
+    private Integer status;
+
+    /**
+     * ssoResKey
+     */
+    private String ssoResKey;
+
+    /**
+     * wordpress配置
+     */
+    private String wordpressSetting;
+
+    /**
+     * openSetting
+     */
+    private List<String> openSetting;
+
+    /**
+     * productType   WP中产品类型
+     */
+    private String productType;
+
+    /**
+     * 是否按用户划分
+     */
+    private Integer userAccount;
+}

+ 75 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/entity/AdwebUserWpsite.java

@@ -0,0 +1,75 @@
+package org.jeecg.modules.adweb.site.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.jeecg.common.aspect.annotation.Dict;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @Description: adweb_user_wpsite
+ * @Author: jeecg-boot
+ * @Date:   2023-08-18
+ * @Version: V1.0
+ */
+@Data
+@TableName("adweb_user_wpsite")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@Schema(description="adweb_user_wpsite")
+public class AdwebUserWpsite implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+	/**id*/
+	@TableId(type = IdType.ASSIGN_ID)
+    @Schema(description = "id")
+    private String id;
+	/**站点id*/
+	@Excel(name = "站点id", width = 15)
+    @Schema(description = "站点id")
+    @Dict(dictTable = "adweb_site",dicCode = "id",dicText = "name")
+    private Integer siteId;
+	/**用户id*/
+	@Excel(name = "用户id", width = 15)
+    @Schema(description = "用户id")
+    @Dict(dictTable = "sys_user",dicCode = "id",dicText = "realname")
+    private String uid;
+	/**用户账户名*/
+	@Excel(name = "用户账户名", width = 15)
+    @Schema(description = "用户账户名")
+    private String username;
+	/**加密后用户账户名(md5)*/
+	@Excel(name = "加密后用户账户名(md5)", width = 15)
+    @Schema(description = "加密后用户账户名(md5)")
+    private String wpUsername;
+	/**wp密码*/
+	@Excel(name = "wp密码", width = 15)
+    @Schema(description = "wp密码")
+    private String wpUserpwd;
+	/**wp用户角色*/
+	@Excel(name = "wp用户角色", width = 15)
+    @Schema(description = "wp用户角色")
+    private String wpUserrole;
+
+    /**
+     * 状态 0:已删除 1:正常
+     */
+	private Integer status;
+
+    /**
+     * 更新时间
+     */
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "更新时间")
+    private Date updateTime;
+}

+ 15 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/mapper/AdwebUserWpsiteMapper.java

@@ -0,0 +1,15 @@
+package org.jeecg.modules.adweb.site.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.adweb.site.entity.AdwebUserWpsite;
+
+
+/**
+ * @Description: adweb_user_wpsite
+ * @Author: jeecg-boot
+ * @Date:   2023-08-18
+ * @Version: V1.0
+ */
+public interface AdwebUserWpsiteMapper extends BaseMapper<AdwebUserWpsite> {
+
+}

+ 5 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/mapper/xml/AdwebUserWpsiteMapper.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.site.mapper.AdwebUserWpsiteMapper">
+
+</mapper>

+ 7 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/service/IAdwebSiteService.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.adweb.site.service;
 
 import org.jeecg.modules.adweb.site.entity.AdwebSite;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.adweb.site.dto.WordPressConfig;
 
 /**
  * @Description: adweb站点配置表单
@@ -11,4 +12,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IAdwebSiteService extends IService<AdwebSite> {
 
+
+    /**
+     * 查询wordpress站点配置
+     * @param siteCode
+     */
+    public WordPressConfig queryWordPressConfig(String siteCode);
 }

+ 33 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/service/IAdwebUserWpsiteService.java

@@ -0,0 +1,33 @@
+package org.jeecg.modules.adweb.site.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.adweb.site.entity.AdwebUserWpsite;
+
+import java.util.List;
+
+/**
+ * @Description: adweb_user_wpsite
+ * @Author: jeecg-boot
+ * @Date:   2023-08-18
+ * @Version: V1.0
+ */
+public interface IAdwebUserWpsiteService extends IService<AdwebUserWpsite> {
+    List<AdwebUserWpsite> getSitesByUid(String uid);
+
+    /**
+     * 查找相同数据
+     * @param wpUsername
+     * @param siteId
+     * @return
+     */
+    List<AdwebUserWpsite> getByWpUsername(String wpUsername, Integer siteId);
+
+    List<AdwebUserWpsite> getByUserID(String userId);
+
+    /**
+     * 根据站点id获取wp站点用户信息
+     * @param siteId
+     * @return
+     */
+    public List<AdwebUserWpsite> getUserBySiteId(Integer siteId);
+}

+ 106 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/service/impl/AdwebSiteServiceImpl.java

@@ -1,11 +1,28 @@
 package org.jeecg.modules.adweb.site.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.FastJsonUtil;
+import org.jeecg.common.util.RedisUtil;
+import org.jeecg.modules.adweb.constant.NumConstant;
+import org.jeecg.modules.adweb.constant.WordPressConstants;
+import org.jeecg.modules.adweb.site.dto.WordPressConfig;
 import org.jeecg.modules.adweb.site.entity.AdwebSite;
+import org.jeecg.modules.adweb.site.entity.AdwebUserWpsite;
 import org.jeecg.modules.adweb.site.mapper.AdwebSiteMapper;
 import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
+import org.jeecg.modules.system.mapper.SysUserRoleMapper;
+import org.jeecg.modules.adweb.site.service.IAdwebUserWpsiteService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import jakarta.annotation.Resource;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: adweb站点配置表单
@@ -16,4 +33,92 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 @Service
 public class AdwebSiteServiceImpl extends ServiceImpl<AdwebSiteMapper, AdwebSite> implements IAdwebSiteService {
 
+
+    @Resource
+    private SysUserRoleMapper sysUserRoleMapper;
+
+    @Autowired
+    private IAdwebUserWpsiteService adwebUserWpsiteService;
+
+    private final RedisUtil redisUtil;
+
+    public AdwebSiteServiceImpl(RedisUtil redisUtil) {
+        this.redisUtil = redisUtil;
+    }
+
+    /**
+     * 查询wordpress站点配置
+     *
+     * @param siteCode
+     */
+    @Override
+    public WordPressConfig queryWordPressConfig(String siteCode) {
+        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        WordPressConfig config = new WordPressConfig();
+        if (StringUtils.isNotBlank(siteCode)) {
+            return config;
+        }
+        try {
+            List<AdwebSite> list = this.list(new LambdaQueryWrapper<AdwebSite>()
+                    .eq(AdwebSite::getCode, siteCode));
+            if (!list.isEmpty()) {
+                AdwebSite adwebSite = list.get(0);
+                BeanUtils.copyProperties(adwebSite, config);
+                // 开启WP&未上线站点
+                if (adwebSite.getStatus() == NumConstant.TWO.intValue() && adwebSite.getWordpressSwitch() == NumConstant.ONE.intValue()) {
+                    String domainDev = adwebSite.getDomainDev();
+                    domainDev = domainDev.replaceAll("https://", "").replaceAll("http://", "");
+                    domainDev = "https://" + domainDev;
+                    config.setDomain(domainDev);
+                }
+                config.setSiteCode(adwebSite.getCode());
+                String ssoResKeyName = WordPressConstants.SSO_RES_KEY_NAME + siteCode;
+                if (redisUtil.hasKey(ssoResKeyName)) {
+                    String ssoResKey = String.valueOf(redisUtil.get(ssoResKeyName));
+                    config.setSsoResKey(ssoResKey);
+                }
+
+                config.setWordpressName("adweb-user");
+                //处理WordPress配置数据
+                if (StringUtils.isNotBlank(adwebSite.getWordpressSetting())) {
+                    Map<String, Object> wordpressSettingMap = FastJsonUtil.parseObject(adwebSite.getWordpressSetting(), Map.class);
+                    int userAccount = 2;
+
+                    if (wordpressSettingMap.get("userAccount") != null) {
+                        userAccount = Integer.parseInt(wordpressSettingMap.get("userAccount").toString());
+                        if (userAccount == 1) {
+                            if (loginUser != null) {
+                                List<String> role = sysUserRoleMapper.getRoleByUserName(loginUser.getUsername());
+                                if (role.toString().contains("adweb_sub_vip") || role.toString().contains("adweb_vip")) {
+                                    List<AdwebUserWpsite> adwebUserWpsites = adwebUserWpsiteService.getSitesByUid(loginUser.getId());
+                                    config.setWordpressName(adwebUserWpsites.get(0).getWpUsername());
+                                } else if (role.toString().contains("admin") || role.toString().contains("adweb_seo_manager") || role.toString().contains("adweb_site_manager") || role.toString().contains("adweb_oem")) {
+                                    List<AdwebUserWpsite> sites = adwebUserWpsiteService.getSitesByUid(adwebSite.getUid());
+                                    config.setWordpressName(sites.get(0).getWpUsername());
+                                }
+                            }
+                        }
+                    }
+
+                    if (wordpressSettingMap.size() == 1) {
+                        config.setProductType(wordpressSettingMap.get("productType").toString());
+                    } else {
+                        config.setWordpressSetting(wordpressSettingMap.get("setting").toString());
+                        List<String> open = FastJsonUtil.parseList(wordpressSettingMap.get("open").toString(), String.class);
+                        if (!open.isEmpty()) {
+                            config.setOpenSetting(open);
+                        }
+                        if (wordpressSettingMap.size() > 2) {
+                            config.setProductType(wordpressSettingMap.get("productType").toString());
+                        }
+                    }
+
+                }
+
+            }
+        } catch (Exception e) {
+            log.error("查询wordpress站点配置失败", e);
+        }
+        return config;
+    }
 }

+ 63 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/service/impl/AdwebUserWpsiteServiceImpl.java

@@ -0,0 +1,63 @@
+package org.jeecg.modules.adweb.site.service.impl;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import jakarta.annotation.Resource;
+import org.jeecg.modules.adweb.site.entity.AdwebUserWpsite;
+import org.jeecg.modules.adweb.site.mapper.AdwebUserWpsiteMapper;
+import org.jeecg.modules.adweb.site.service.IAdwebUserWpsiteService;
+import org.springframework.stereotype.Service;
+import org.jeecg.modules.adweb.constant.NumConstant;
+
+import java.util.List;
+
+/**
+ * @Description: adweb_user_wpsite
+ * @Author: jeecg-boot
+ * @Date:   2023-08-18
+ * @Version: V1.0
+ */
+@Service
+public class AdwebUserWpsiteServiceImpl extends ServiceImpl<AdwebUserWpsiteMapper, AdwebUserWpsite> implements IAdwebUserWpsiteService {
+
+    @Resource
+    private AdwebUserWpsiteMapper adwebUserWpsiteMapper;
+    @Override
+    public List<AdwebUserWpsite> getSitesByUid(String uid) {
+        List<AdwebUserWpsite> adwebUserWpsites = adwebUserWpsiteMapper.selectList(new LambdaQueryWrapper<AdwebUserWpsite>()
+                .eq(AdwebUserWpsite::getUid,uid));
+        return adwebUserWpsites;
+    }
+
+    @Override
+    public List<AdwebUserWpsite> getByWpUsername(String wpUsername, Integer siteId) {
+        List<AdwebUserWpsite> adwebUserWpsites = adwebUserWpsiteMapper.selectList(new LambdaQueryWrapper<AdwebUserWpsite>()
+                .eq(AdwebUserWpsite::getWpUsername, wpUsername)
+                .eq(AdwebUserWpsite::getSiteId, siteId));
+        return adwebUserWpsites;
+    }
+
+    @Override
+    public List<AdwebUserWpsite> getByUserID(String userId) {
+        QueryWrapper<AdwebUserWpsite> adwebUserWpsiteQueryWrapper = new QueryWrapper<>();
+        adwebUserWpsiteQueryWrapper.eq("uid",userId);
+        adwebUserWpsiteQueryWrapper.eq("status", NumConstant.ONE);
+        List<AdwebUserWpsite> adwebUserWpsites = this.list(adwebUserWpsiteQueryWrapper);
+        return adwebUserWpsites;
+    }
+
+    /**
+     * 根据站点id获取wp站点用户信息
+     * @param siteId
+     * @return
+     */
+    @Override
+    public List<AdwebUserWpsite> getUserBySiteId(Integer siteId) {
+        QueryWrapper<AdwebUserWpsite> adwebUserWpsiteQueryWrapper = new QueryWrapper<>();
+        adwebUserWpsiteQueryWrapper.eq("site_id",siteId);
+        adwebUserWpsiteQueryWrapper.eq("status", NumConstant.ONE);
+        return this.list(adwebUserWpsiteQueryWrapper);
+    }
+}