仰望星空〃 hai 8 meses
pai
achega
55945c4cf1
Modificáronse 27 ficheiros con 946 adicións e 83 borrados
  1. 5 0
      bus-biz/pom.xml
  2. 2 1
      bus-biz/src/main/java/bus/JobConfig.java
  3. 66 0
      bus-biz/src/main/java/bus/RedisConfig.java
  4. 21 0
      bus-biz/src/main/java/bus/mapper/BAdvertMapper.java
  5. 53 0
      bus-biz/src/main/java/bus/service/BAdvertService.java
  6. 1 1
      bus-biz/src/main/java/bus/service/CommonService.java
  7. 2 0
      bus-biz/src/main/java/bus/service/WChatUserService.java
  8. 101 0
      bus-biz/src/main/java/bus/service/impl/BAdvertServiceImpl.java
  9. 1 1
      bus-biz/src/main/java/bus/service/impl/CommonServiceImpl.java
  10. 42 2
      bus-biz/src/main/java/bus/service/impl/WChatUserServiceImpl.java
  11. 40 0
      bus-biz/src/main/resources/mapper/BAdvertMapper.xml
  12. 1 1
      bus-boot/src/main/java/bus/Application.java
  13. 8 5
      bus-boot/src/main/resources/bootstrap-dev.yaml
  14. 3 3
      bus-boot/src/test/java/bus/CodeGenerateTest.java
  15. 0 5
      bus-common/pom.xml
  16. 1 1
      bus-common/src/main/java/bus/model/BaseEntity.java
  17. 301 0
      bus-common/src/main/java/bus/model/RedisUtil.java
  18. 45 0
      bus-common/src/main/java/bus/model/dto/BAdvertDto.java
  19. 44 0
      bus-common/src/main/java/bus/model/dto/BAdvertPageDto.java
  20. 1 1
      bus-common/src/main/java/bus/model/dto/CommonLoginDto.java
  21. 36 0
      bus-common/src/main/java/bus/model/po/BAdvertPo.java
  22. 45 0
      bus-common/src/main/java/bus/model/vo/BAdvertVo.java
  23. 95 0
      bus-web/src/main/java/bus/controller/biz/BAdvertController.java
  24. 1 1
      bus-web/src/main/java/bus/controller/biz/CommonController.java
  25. 9 37
      bus-web/src/main/java/bus/controller/biz/WChatUserController.java
  26. 1 3
      bus-web/src/main/java/bus/controller/biz/config/GlobalHandler.java
  27. 21 21
      bus-web/src/main/java/bus/controller/biz/job/DemoesTask.java

+ 5 - 0
bus-biz/pom.xml

@@ -41,6 +41,11 @@
 			<artifactId>spring-boot-starter-data-redis</artifactId>
 			<scope>provided</scope>
 		</dependency>
+		<dependency>
+			<groupId>com.xuxueli</groupId>
+			<artifactId>xxl-job-core</artifactId>
+			<version>2.2.0</version>
+		</dependency>
 	</dependencies>
 
 </project>

+ 2 - 1
bus-boot/src/main/java/bus/config/JobConfig.java → bus-biz/src/main/java/bus/JobConfig.java

@@ -1,4 +1,5 @@
-package bus.config;
+package bus;
+
 
 import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
 import lombok.extern.slf4j.Slf4j;

+ 66 - 0
bus-biz/src/main/java/bus/RedisConfig.java

@@ -0,0 +1,66 @@
+package bus;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
+import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.connection.RedisPassword;
+import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import java.time.Duration;
+
+@Configuration
+public class RedisConfig {
+
+    @Bean
+    public LettuceConnectionFactory redisConnectionFactory(RedisProperties redisProperties) {
+        RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
+        config.setHostName(redisProperties.getHost());
+        config.setPort(redisProperties.getPort());
+        config.setPassword(RedisPassword.of(redisProperties.getPassword()));
+        config.setDatabase(redisProperties.getDatabase());
+
+        LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
+                .commandTimeout(Duration.ofMillis(20000))
+                .build();
+
+        return new LettuceConnectionFactory(config, clientConfig);
+    }
+
+    @Bean
+    public RedisTemplate<String, Object> redisTemplate1(RedisConnectionFactory connectionFactory) {
+        RedisTemplate<String, Object> template = new RedisTemplate<>();
+        template.setConnectionFactory(connectionFactory);
+
+        // 配置序列化方式
+        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
+        ObjectMapper objectMapper = new ObjectMapper();
+        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+        objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance,
+                ObjectMapper.DefaultTyping.NON_FINAL);
+        jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
+
+        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
+
+        // key采用String的序列化方式
+        template.setKeySerializer(stringRedisSerializer);
+        // hash的key也采用String的序列化方式
+        template.setHashKeySerializer(stringRedisSerializer);
+        // value序列化方式采用jackson
+        template.setValueSerializer(jackson2JsonRedisSerializer);
+        // hash的value序列化方式采用jackson
+        template.setHashValueSerializer(jackson2JsonRedisSerializer);
+
+        template.afterPropertiesSet();
+        return template;
+    }
+}

+ 21 - 0
bus-biz/src/main/java/bus/mapper/BAdvertMapper.java

@@ -0,0 +1,21 @@
+package bus.mapper;
+
+
+
+import bus.model.dto.BAdvertPageDto;
+import bus.model.po.*;
+import org.apache.ibatis.annotations.Mapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import java.util.List;
+
+/**
+ * @Program: bus
+ * @Description: 描述
+ * @Author: zy
+ * @Date: 2025-03-06 22:43:32
+ **/
+@Mapper
+public interface BAdvertMapper extends BaseMapper<BAdvertPo> {
+
+    List<BAdvertPo> list(BAdvertPageDto dto);
+}

+ 53 - 0
bus-biz/src/main/java/bus/service/BAdvertService.java

@@ -0,0 +1,53 @@
+package bus.service;
+
+import bus.model.dto.BAdvertDto;
+import bus.model.dto.BAdvertPageDto;
+import bus.model.po.BAdvertPo;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+/**
+ * @Program: bus
+ * @Description: 描述
+ * @Author: zy
+ * @Date: 2025-03-06 22:43:32
+ **/
+public interface BAdvertService extends IService<BAdvertPo> {
+
+
+    /**
+     * 详情
+     * @param id
+     * @return
+     */
+    BAdvertPo getDetailById(String id);
+
+	/**
+     * 保存
+     * @param dto
+     * @return
+     */
+    void save(BAdvertDto dto);
+
+    /**
+    * 列表
+    * @param dto
+    * @return
+    */
+    List<BAdvertPo> list(BAdvertPageDto dto);
+
+	/**
+     * 修改
+     * @param dto
+     * @return
+     */
+    void update(BAdvertDto dto);
+
+	/**
+     * 删除
+     * @param id
+     * @return
+     */
+    void delete(String id);
+}

+ 1 - 1
bus-biz/src/main/java/bus/service/CommonService.java

@@ -14,7 +14,7 @@ import java.util.List;
 * @Program: bus
 * @Description: 描述
 * @Author: zy
-* @Date: 2025-03-02 19:56:32
+* @Date: 2025-03-06 22:43:32
 **/
 public interface CommonService {
 

+ 2 - 0
bus-biz/src/main/java/bus/service/WChatUserService.java

@@ -55,4 +55,6 @@ public interface WChatUserService {
      * @return
      */
     void delete(String id);
+
+     String getAccessToken(String appId, String secret);
 }

+ 101 - 0
bus-biz/src/main/java/bus/service/impl/BAdvertServiceImpl.java

@@ -0,0 +1,101 @@
+package bus.service.impl;
+
+import bus.mapper.BAdvertMapper;
+import bus.model.SnowflakeUtil;
+import bus.model.dto.BAdvertDto;
+import bus.model.dto.BAdvertPageDto;
+import bus.model.po.BAdvertPo;
+import bus.service.BAdvertService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.orcas.common.sso.model.ExtInfo;
+import com.orcas.iso.config.common.user.CurrentUserHolder;
+import org.springframework.stereotype.Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.BeanUtils;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Program: bus
+ * @Description: 描述
+ * @Author: zy
+ * @Date: 2025-03-06 22:43:32
+ **/
+@Service
+public class BAdvertServiceImpl extends ServiceImpl<BAdvertMapper, BAdvertPo> implements BAdvertService {
+
+    @Autowired
+    private BAdvertMapper bAdvertMapper;
+    @Resource
+    private SnowflakeUtil snowflakeUtil;
+
+	/**
+     * 详情
+     * @param id
+     * @return
+     */
+    @Override
+    public BAdvertPo getDetailById(String id){
+        return this.bAdvertMapper.selectById(id);
+    }
+
+	/**
+     * 保存
+     * @param dto
+     * @return
+     */
+    @Override
+	public void save(BAdvertDto dto){
+        BAdvertPo po = new BAdvertPo();
+        BeanUtils.copyProperties(dto,po);
+
+		this.bAdvertMapper.insert(po);
+        ExtInfo extInfo = CurrentUserHolder.get();
+        po.setId(snowflakeUtil.snowflakeId());
+        po.setCreateTime(new Date());
+        po.setUpdateTime(new Date());
+        po.setCreatorId(extInfo.getUserId());
+        po.setUpdaterId(extInfo.getUserId());
+        po.setCreatorName(extInfo.getUserName());
+        po.setUpdaterName(extInfo.getUserName());
+    }
+
+    /**
+    * 列表
+    * @param dto
+    * @return
+    */
+    @Override
+    public List<BAdvertPo> list(BAdvertPageDto dto){
+        return this.bAdvertMapper.list(dto);
+    }
+
+	/**
+     * 修改
+     * @param dto
+     * @return
+     */
+    @Override
+    public void update(BAdvertDto dto){
+        BAdvertPo po = new BAdvertPo();
+        BeanUtils.copyProperties(dto,po);
+        ExtInfo extInfo = CurrentUserHolder.get();
+        po.setId(snowflakeUtil.snowflakeId());
+        po.setUpdateTime(new Date());
+        po.setUpdaterId(extInfo.getUserId());
+        po.setUpdaterName(extInfo.getUserName());
+		bAdvertMapper.updateById(po);
+    }
+
+    /**
+     * 删除
+     * @param id
+     * @return
+     */
+    @Override
+    public void delete(String id){
+		bAdvertMapper.deleteById(id);
+    }
+}

+ 1 - 1
bus-biz/src/main/java/bus/service/impl/CommonServiceImpl.java

@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
 * @Program: bus
 * @Description: 描述
 * @Author: zy
-* @Date: 2025-03-02 19:56:32
+* @Date: 2025-03-06 22:43:32
 **/
 @Service
 @Transactional

+ 42 - 2
bus-biz/src/main/java/bus/service/impl/WChatUserServiceImpl.java

@@ -1,5 +1,6 @@
 package bus.service.impl;
 
+import bus.model.RedisUtil;
 import bus.model.SnowflakeUtil;
 import bus.model.dto.CommonLoginDto;
 import bus.model.dto.WChatUserDto;
@@ -12,6 +13,8 @@ import bus.service.CommonService;
 import bus.service.WChatUserService;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONObject;
 import com.jcraft.jsch.HASH;
 import com.orcas.common.sso.model.SsoUserAuthDto;
 import com.orcas.common.usercenter.entity.RoleEntity;
@@ -21,6 +24,7 @@ import com.orcas.common.usercenter.model.StaffRequest;
 import com.orcas.iso.service.RoleClient;
 import com.orcas.iso.service.StaffClient;
 import com.orcas.iso.service.UserClient;
+import com.qzwisdom.qzframework.core.tool.exception.BusinessException;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +37,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -64,11 +69,15 @@ public class WChatUserServiceImpl implements WChatUserService {
     private String productNo;
     @Resource
     private SnowflakeUtil snowflakeUtil;
+    @Resource
+    private RedisUtil redisUtil;
 
-    // Redis key
     private static final String WX_ACCESS_TOKEN_KEY = "wx:access_token";
     // access_token 有效期为 7200 秒,我们设置缓存时间为 7000 秒,留出一些余量
     private static final long ACCESS_TOKEN_EXPIRE = 7000L;
+    private static final int TIME_OUT  = 3000;
+
+    private static final String ERROR_CODE_STR = "errcode";
 
     @Override
     public SsoUserAuthDto wxLogin(HttpServletRequest request, HttpServletResponse response, WxLoginReq wxLoginReq) {
@@ -92,7 +101,7 @@ public class WChatUserServiceImpl implements WChatUserService {
             WChatUserDto dto = new WChatUserDto();
             dto.setMiniOpenId(dto.getMiniOpenId());
             dto.setLastLoginTime(new Date());
-            dto.setWxName(wxName);
+            dto.setWxName(mobile);
             dto.setWxPhone(mobile);
             save(dto);
         }
@@ -181,4 +190,35 @@ public class WChatUserServiceImpl implements WChatUserService {
     public void delete(String id) {
         wChatUserMapper.deleteById(id);
     }
+
+    @Override
+    public String getAccessToken(String appId, String appSecret)  {
+        // 先从Redis获取
+        String accessToken = redisUtil.get(WX_ACCESS_TOKEN_KEY);
+        if (StrUtil.isNotBlank(accessToken)) {
+            return accessToken;
+        }
+        // Redis中不存在,则从微信服务器获取
+        String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token" +
+                "?grant_type=client_credential" +
+                "&appid=" + appId +
+                "&secret=" + appSecret;
+
+        String tokenJson = HttpUtil.get(accessTokenUrl, TIME_OUT);
+        JSONObject tokenObj = new JSONObject(tokenJson);
+        if (tokenObj.get(ERROR_CODE_STR) != null && tokenObj.get(ERROR_CODE_STR, Integer.class) != 0) {
+            throw new BusinessException("获取access_token失败");
+        }
+
+        // 获取新的access_token
+        accessToken = tokenObj.getStr("access_token");
+        // 存入Redis并设置过期时间
+        redisUtil.set(
+                WX_ACCESS_TOKEN_KEY,
+                accessToken,
+                ACCESS_TOKEN_EXPIRE,
+                TimeUnit.SECONDS
+        );
+        return accessToken;
+    }
 }

+ 40 - 0
bus-biz/src/main/resources/mapper/BAdvertMapper.xml

@@ -0,0 +1,40 @@
+<?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="bus.mapper.BAdvertMapper">
+
+ <select id="list" parameterType="bus.model.dto.BAdvertPageDto" resultType="bus.model.po.BAdvertPo">
+   select
+   id,
+   pic_url,
+   sort,
+   title,
+   min_title,
+   content,
+   jump,
+   create_time,
+   update_time,
+   creator_id,
+   updater_id,
+   creator_name,
+   updater_name,
+   is_delete
+   from
+   b_advert
+   <where>
+     is_delete = 0
+     <if test="id != null and id != ''">
+       and id = #{id}
+     </if>
+     <if test="picUrl != null and picUrl != ''">
+       and pic_url = #{picUrl}
+     </if>
+     <if test="sort != null and sort != ''">
+       and sort = #{sort}
+     </if>
+     <if test="title != null and title != ''">
+       and title = #{title}
+     </if>
+   </where>
+ </select>
+
+</mapper>

+ 1 - 1
bus-boot/src/main/java/bus/Application.java

@@ -10,8 +10,8 @@ import com.qzwisdom.qzframework.core.boot.annotation.BootApplication;
  * @Author: bus
  * @Date: 2025-02-24 14:39:32
  **/
-@BootApplication(scanBasePackages = {"bus"})
 @MapperScan(value = "bus.mapper")
+@BootApplication(scanBasePackages = {"bus","com.orcas"})
 public class Application {
 
     public static void main(String[] args) {

+ 8 - 5
bus-boot/src/main/resources/bootstrap-dev.yaml

@@ -9,6 +9,11 @@ spring:
     url: jdbc:mysql://metapixels.top:13306/bus_allot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
     username: root
     password: 9a41012499f38251
+  redis:
+    host: 58.221.153.58
+    port: 46379
+    password: orcas@2024
+    database: 5
 
 mybatis-plus:
   enabled-auto-fill: true
@@ -33,16 +38,14 @@ orcas:
   redis:
     host: 58.221.153.58
     port: 46379
-    database: 5
     password: orcas@2024
-    expire:
-      minute: 30
+    database: 5
   sso:
     server: http://58.221.153.58:48989/api-gateway/iso-server
     logout:
       path: /logout
     excluded:
-      paths: /swagger-ui.html,/webjars/**,/swagger-resources/**,/v2/api-docs,/doc.html,/wChatUser/auto/login
+      paths: /swagger-ui.html,/webjars/**,/swagger-resources/**,/v2/api-docs,/doc.html,/wChatUser/auto/login,/wChatUser/encryptedData,/wChatUser/getPhoneNumber,/wChatUser/getXcxOpenId
 
 file-store:
   go-fastdfs:
@@ -56,7 +59,7 @@ xxl:
     executor:
       appname: demo-executor
       address: ""
-      ip: "matrix34.tpddns.cn"
+      ip: "metapixels.top"
       port: 60066
       logpath: logs
       logretentiondays: 15

+ 3 - 3
bus-boot/src/test/java/bus/CodeGenerateTest.java

@@ -30,15 +30,15 @@ public class CodeGenerateTest {
 		projectInfo.setProjectName("bus");
 		generateConfig.setProjectInfo(projectInfo);
 		//获取数据源信息
-		generateConfig.getDataSourceInfo().setJdbcUrl("jdbc:mysql://matrix34.tpddns.cn:13306/bus_allot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
+		generateConfig.getDataSourceInfo().setJdbcUrl("jdbc:mysql://metapixels.top:13306/bus_allot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
 		generateConfig.getDataSourceInfo().setJdbcUserName("root");
 		generateConfig.getDataSourceInfo().setJdbcPassword("9a41012499f38251");
 		generateConfig.getDataSourceInfo().setJdbcDriverName("com.mysql.cj.jdbc.Driver");
 		//设置生成的表
 		List<TableInfo> tables = new ArrayList<>();
 		TableInfo tableInfo = new TableInfo();
-		tableInfo.setTableName("b_course_bus");
-		tableInfo.setTableAlias("BCourseBus");
+		tableInfo.setTableName("b_advert");
+		tableInfo.setTableAlias("bAdvert");
 		tables.add(tableInfo);
 		generateConfig.setTableInfos(tables);
 		//生成代码

+ 0 - 5
bus-common/pom.xml

@@ -31,11 +31,6 @@
 			<groupId>com.qzwisdom.qzframework</groupId>
 			<artifactId>qzframework-core-boot</artifactId>
 		</dependency>
-		<dependency>
-			<groupId>com.xuxueli</groupId>
-			<artifactId>xxl-job-core</artifactId>
-			<version>2.2.0</version>
-		</dependency>
 	</dependencies>
 
 </project>

+ 1 - 1
bus-common/src/main/java/bus/model/BaseEntity.java

@@ -5,7 +5,7 @@ import lombok.Data;
 * @Program: bus
 * @Description: 描述
 * @Author: zy
-* @Date: 2025-03-02 19:56:33
+* @Date: 2025-03-06 22:43:33
 **/
 @Data
 public class BaseEntity {

+ 301 - 0
bus-common/src/main/java/bus/model/RedisUtil.java

@@ -0,0 +1,301 @@
+package bus.model;
+
+import org.springframework.data.redis.core.ListOperations;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.SetOperations;
+import org.springframework.data.redis.core.ZSetOperations;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * +----------------------------------------------------------------------
+ * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ * +----------------------------------------------------------------------
+ * | Author: CRMEB Team <admin@crmeb.com>
+ * +----------------------------------------------------------------------
+ * redis工具类
+ */
+
+@Component
+public class RedisUtil {
+
+    @Resource
+    private RedisTemplate<String, Object> redisTemplate;
+
+//    private static RedisTemplate<String, Object> redisTemplate = SpringUtil.getBean("redisTemplate", RedisTemplate.class);
+
+    // =============== common ==========================
+    /**
+     * 指定缓存失效时间
+     * @param key 键
+     * @param time 时间(秒)
+     * @return boolean
+     */
+    public boolean expire(String key, long time) {
+        try {
+            if (time > 0) {
+                redisTemplate.expire(key, time, TimeUnit.SECONDS);
+            }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 根据key 获取过期时间
+     * @param key 键 不能为null
+     * @return 时间(秒) 返回0代表为永久有效 失效时间为负数,说明该主键未设置失效时间(失效时间默认为-1)
+     */
+    public long getExpire(String key) {
+        return redisTemplate.getExpire(key, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 判断key是否存在
+     * @param key 键
+     * @return true 存在 false 不存在
+     */
+    public boolean exists(String key){
+        try {
+            return redisTemplate.hasKey(key);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 删除对应的value
+     * @param key string key
+     */
+    public void delete(String key) {
+        if (exists(key)) {
+            redisTemplate.delete(key);
+        }
+    }
+
+    // =============== string ==========================
+    /**
+     * 写入缓存
+     * @param key string key
+     * @param value string value
+     */
+    public boolean set(String key, Object value) {
+        try {
+            redisTemplate.opsForValue().set(key, value);
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 写入缓存带有效期(默认时间单位:秒)
+     * @param key string key
+     * @param value string value
+     * @param expireTime Long 过期时间
+     * @return boolean
+     */
+    public boolean set(String key, Object value, Long expireTime) {
+        try {
+            if (expireTime > 0) {
+                redisTemplate.opsForValue().set(key, value, expireTime, TimeUnit.SECONDS);
+            } else {
+                set(key, value);
+            }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 写入缓存带有效期
+     * @param key string key
+     * @param value string value
+     * @param expireTime Long 过期时间
+     * @param timeUnit TimeUnit 时间格式
+     * @return boolean
+     */
+    public boolean set(String key, Object value, Long expireTime, TimeUnit timeUnit) {
+        try {
+            redisTemplate.opsForValue().set(key, value, expireTime, timeUnit);
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 读取缓存
+     * @param key string key
+     * @return T
+     */
+    @SuppressWarnings("unchecked")
+    public <T> T get(String key) {
+        return (T) redisTemplate.opsForValue().get(key);
+    }
+
+    /**
+     * 哈希添加
+     * @param key string key
+     * @param hashKey Object hashKey
+     * @param value Object value
+     */
+
+    public void hmSet(String key, Object hashKey, Object value) {
+        redisTemplate.opsForHash().put(key, hashKey, value);
+    }
+
+    /**
+     * 哈希删除
+     * @param key string key
+     * @param hashKey Object hashKey
+     */
+
+    public void hmDelete(String key, Object hashKey) {
+        redisTemplate.opsForHash().delete(key, hashKey);
+    }
+
+    /**
+     * 哈希获取数据
+     * @param key string key
+     * @param hashKey Object hashKey
+     */
+    public Object hmGet(String key, Object hashKey) {
+        return redisTemplate.opsForHash().get(key, hashKey);
+    }
+
+    /**
+     * 哈希数量
+     * @param key string key
+     */
+    public Long getHashSize(String key) {
+        return redisTemplate.opsForHash().size(key);
+    }
+
+    /**
+     * 列表添加左边添加
+     * @param k string key
+     * @param v Object v
+     * @author Mr.Zhang
+     * @since 2020-04-13
+     */
+    public void lPush(String k, Object v) {
+        ListOperations<String, Object> list = redisTemplate.opsForList();
+        list.leftPush(k, v);
+    }
+
+    /**
+     * 从右边拿出来一个
+     * @param k string key
+     * @param t Long 超时秒数
+     */
+    public Object getRightPop(String k, Long t){
+        return redisTemplate.opsForList().rightPop(k, t, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 列表获取数量
+     * @param k string key
+     * @return Long
+     */
+    public Long getListSize(String k) {
+        return redisTemplate.opsForList().size(k);
+    }
+
+    /**
+     * 列表获取
+     * @param k string key
+     * @param l long l
+     * @param l1 long l1
+     * @return List<Object>
+     */
+    public List<Object> lRange(String k, long l, long l1) {
+        ListOperations<String, Object> list = redisTemplate.opsForList();
+        return list.range(k, l, l1);
+    }
+
+    /**
+     * 集合添加
+     * @param key string key
+     * @param value Object value
+     */
+    public void add(String key, Object value) {
+        SetOperations<String, Object> set = redisTemplate.opsForSet();
+        set.add(key, value);
+    }
+
+    /**
+     * 集合获取
+     * @param key string key
+     * @return Set<Object>
+     */
+    public Set<Object> setMembers(String key) {
+        SetOperations<String, Object> set = redisTemplate.opsForSet();
+        return set.members(key);
+    }
+
+    /**
+     * 有序集合添加    排行榜使用
+     * @param key string key
+     * @param value Object value
+     * @param score double scoure
+     */
+    public void zAdd(String key, Object value, double score) {
+        ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();
+        zset.add(key, value, score);
+    }
+
+
+    /**
+     * 有序集合获取    排行榜使用
+     * @param key string key
+     * @param score double scoure
+     * @return Set<Object>
+     */
+    public Set<Object> rangeByScore(String key, double score, double score1) {
+        ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();
+        return zset.rangeByScore(key, score, score1);
+    }
+
+    /**
+     * 递增
+     * @param key 键
+     * @return long
+     */
+    public long incrAndCreate(String key){
+        if (!exists(key)) {
+            set(key, 1);
+            return 1;
+        }
+        return incr(key, 1L);
+    }
+
+    /**
+     * 递增
+     * @param key 键
+     * @param delta 要增加几(大于0)
+     * @return long
+     */
+    public long incr(String key, long delta){
+        if (delta < 0) {
+            throw new RuntimeException("递增因子必须大于0");
+        }
+        return redisTemplate.opsForValue().increment(key, delta);
+    }
+
+}

+ 45 - 0
bus-common/src/main/java/bus/model/dto/BAdvertDto.java

@@ -0,0 +1,45 @@
+package bus.model.dto;
+
+import lombok.Data;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.Date;
+import java.util.Date;
+/**
+* @Program: bus
+* @Description: 描述
+* @Author: zy
+* @Date: 2025-03-06 22:43:33
+**/
+@Data
+public class BAdvertDto{
+    @ApiModelProperty("ID")
+    private String id;
+    @ApiModelProperty("轮播图")
+    private String picUrl;
+    @ApiModelProperty("排序")
+    private Integer sort;
+    @ApiModelProperty("标题")
+    private String title;
+    @ApiModelProperty("副标题")
+    private String minTitle;
+    @ApiModelProperty("状态 0警用 1启用")
+    private String status;
+    @ApiModelProperty("类容")
+    private String content;
+    @ApiModelProperty("跳转地址")
+    private String jump;
+    @ApiModelProperty("记录创建时间")
+    private Date createTime;
+    @ApiModelProperty("记录更新时间")
+    private Date updateTime;
+    @ApiModelProperty("创建人id")
+    private String creatorId;
+    @ApiModelProperty("修改人id")
+    private String updaterId;
+    @ApiModelProperty("创建人姓名")
+    private String creatorName;
+    @ApiModelProperty("修改人姓名")
+    private String updaterName;
+    @ApiModelProperty("是否删除")
+    private Integer isDelete;
+}

+ 44 - 0
bus-common/src/main/java/bus/model/dto/BAdvertPageDto.java

@@ -0,0 +1,44 @@
+package bus.model.dto;
+
+import bus.model.BaseEntity;
+import lombok.Data;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.Date;
+import java.util.Date;
+/**
+* @Program: bus
+* @Description: 描述
+* @Author: zy
+* @Date: 2025-03-06 22:43:33
+**/
+@Data
+public class BAdvertPageDto extends BaseEntity{
+    @ApiModelProperty("ID")
+    private String id;
+    @ApiModelProperty("轮播图")
+    private String picUrl;
+    @ApiModelProperty("排序")
+    private Integer sort;
+    @ApiModelProperty("标题")
+    private String title;
+    @ApiModelProperty("副标题")
+    private String minTitle;
+    @ApiModelProperty("类容")
+    private String content;
+    @ApiModelProperty("跳转地址")
+    private String jump;
+    @ApiModelProperty("记录创建时间")
+    private Date createTime;
+    @ApiModelProperty("记录更新时间")
+    private Date updateTime;
+    @ApiModelProperty("创建人id")
+    private String creatorId;
+    @ApiModelProperty("修改人id")
+    private String updaterId;
+    @ApiModelProperty("创建人姓名")
+    private String creatorName;
+    @ApiModelProperty("修改人姓名")
+    private String updaterName;
+    @ApiModelProperty("是否删除")
+    private Integer isDelete;
+}

+ 1 - 1
bus-common/src/main/java/bus/model/dto/CommonLoginDto.java

@@ -8,7 +8,7 @@ import lombok.Data;
 * @Program: bus
 * @Description: 描述
 * @Author: zy
-* @Date: 2025-03-02 19:56:33
+* @Date: 2025-03-06 22:43:33
 **/
 @ApiModel(description = "账户登陆请求实体")
 @Data

+ 36 - 0
bus-common/src/main/java/bus/model/po/BAdvertPo.java

@@ -0,0 +1,36 @@
+package bus.model.po;
+
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import lombok.Data;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.util.Date;
+import java.util.Date;
+
+/**
+* @Program: bus
+* @Description: 
+* @Author: zy
+* @Date: 2025-03-06 22:43:33
+**/
+@Data
+@TableName("b_advert")
+public class BAdvertPo{
+    @TableId
+    private String id;
+    private String picUrl;
+    private Integer sort;
+    private String title;
+    private String status;
+    private String minTitle;
+    private String content;
+    private String jump;
+    private Date createTime;
+    private Date updateTime;
+    private String creatorId;
+    private String updaterId;
+    private String creatorName;
+    private String updaterName;
+    @TableLogic
+    private Integer isDelete;
+}

+ 45 - 0
bus-common/src/main/java/bus/model/vo/BAdvertVo.java

@@ -0,0 +1,45 @@
+package bus.model.vo;
+
+import lombok.Data;
+import io.swagger.annotations.ApiModelProperty;
+import com.qzwisdom.qzframework.core.tool.base.vo.AbstractBaseVO;
+import java.util.Date;
+import java.util.Date;
+
+/**
+* @Program: bus
+* @Description: 描述
+* @Author: zy
+* @Date: 2025-03-06 22:43:33
+**/
+@Data
+public class BAdvertVo extends AbstractBaseVO{
+    @ApiModelProperty("ID")
+    private String id;
+    @ApiModelProperty("轮播图")
+    private String picUrl;
+    @ApiModelProperty("排序")
+    private Integer sort;
+    @ApiModelProperty("标题")
+    private String title;
+    @ApiModelProperty("副标题")
+    private String minTitle;
+    @ApiModelProperty("类容")
+    private String content;
+    @ApiModelProperty("跳转地址")
+    private String jump;
+    @ApiModelProperty("记录创建时间")
+    private Date createTime;
+    @ApiModelProperty("记录更新时间")
+    private Date updateTime;
+    @ApiModelProperty("创建人id")
+    private String creatorId;
+    @ApiModelProperty("修改人id")
+    private String updaterId;
+    @ApiModelProperty("创建人姓名")
+    private String creatorName;
+    @ApiModelProperty("修改人姓名")
+    private String updaterName;
+    @ApiModelProperty("是否删除")
+    private Integer isDelete;
+}

+ 95 - 0
bus-web/src/main/java/bus/controller/biz/BAdvertController.java

@@ -0,0 +1,95 @@
+package bus.controller.biz;
+
+import bus.model.dto.BAdvertDto;
+import bus.model.dto.BAdvertPageDto;
+import bus.model.po.BAdvertPo;
+import bus.service.BAdvertService;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageSerializable;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import com.qzwisdom.qzframework.core.tool.base.controller.BaseController;
+
+
+
+/**
+ * @Program: bus
+ * @Description: 描述
+ * @Author: zy
+ * @Date: 2025-03-06 22:43:31
+ **/
+@Slf4j
+@CrossOrigin
+@RestController
+@Api(tags = "广告管理接口")
+@RequestMapping(value="/bAdvert")
+public class BAdvertController implements BaseController {
+
+    @Autowired
+    private BAdvertService bAdvertService;
+
+
+
+    /**
+     * 详情
+     * @param id
+     * @return
+     */
+    @ApiOperation("详情")
+    @GetMapping(value = "getDetailById")
+    public BAdvertPo getDetailById(@RequestParam String id){
+        return bAdvertService.getDetailById(id);
+    }
+
+	/**
+     * 保存
+     * @param dto
+     * @return
+     */
+    @ApiOperation("保存")
+    @PostMapping(value = "save")
+    public String save(@RequestBody BAdvertDto dto){
+		bAdvertService.save(dto);
+        return "保存成功";
+    }
+
+    /**
+    * 列表
+    * @param dto
+    * @return
+    */
+    @ApiOperation("列表")
+    @PostMapping(value = "list")
+    public PageSerializable<BAdvertPo> list(@RequestBody BAdvertPageDto dto){
+       PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
+       return new PageSerializable<>(bAdvertService.list(dto));
+    }
+
+	/**
+     * 修改
+     * @param dto
+     * @return
+     */
+    @ApiOperation("修改")
+    @PostMapping(value = "update")
+    public String update(@RequestBody BAdvertDto dto){
+		bAdvertService.update(dto);
+        return "修改成功";
+    }
+
+	/**
+     * 删除
+     * @param id
+     * @return
+     */
+    @ApiOperation("删除")
+    @GetMapping(value = "deleteById")
+    public String deleteById(@RequestParam String id){
+		bAdvertService.delete(id);
+        return "删除成功";
+    }
+
+}

+ 1 - 1
bus-web/src/main/java/bus/controller/biz/CommonController.java

@@ -33,7 +33,7 @@ import java.util.Map;
 * @Program: bus
 * @Description: 描述
 * @Author: zy
-* @Date: 2025-03-02 19:56:31
+* @Date: 2025-03-06 22:43:31
 **/
 @RestController
 @RequestMapping("/common")

+ 9 - 37
bus-web/src/main/java/bus/controller/biz/WChatUserController.java

@@ -1,5 +1,6 @@
 package bus.controller.biz;
 
+import bus.model.RedisUtil;
 import bus.model.dto.req.WxLoginReq;
 import bus.model.vo.WXDecrypt;
 import bus.model.vo.WxEncryptedData;
@@ -27,6 +28,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.web.bind.annotation.*;
 import com.qzwisdom.qzframework.core.tool.base.controller.BaseController;
 
+import javax.annotation.Resource;
 import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
@@ -54,49 +56,19 @@ public class WChatUserController implements BaseController {
     @Autowired
     private WChatUserService wChatUserService;
 
-    private static final String appId = "wx93b327996c5a3839";
-    private static final String appSecret = "491d369f6ca0bc6b9b49ec2e61c3ef4b";
+   // private static final String appId = "wx93b327996c5a3839";
+    private static final String appId = "wxf562a20ee4297f2d";
+
+   // private static final String appSecret = "491d369f6ca0bc6b9b49ec2e61c3ef4b";
+    private static final String appSecret = "ef150b4d2fe3f11d748f21d67823bae9";
     private static  final String OPENID_URL = "https://api.weixin.qq.com/sns/jscode2session";
     private static final int TIME_OUT  = 3000;
 
     private static final String ERROR_CODE_STR = "errcode";
 
-    @Autowired
-    private  StringRedisTemplate stringRedisTemplate;
 
-    private static final String WX_ACCESS_TOKEN_KEY = "wx:access_token";
-    // access_token 有效期为 7200 秒,我们设置缓存时间为 7000 秒,留出一些余量
-    private static final long ACCESS_TOKEN_EXPIRE = 7000L;
 
-    private String getAccessToken() {
-        // 先从Redis获取
-        String accessToken = stringRedisTemplate.opsForValue().get(WX_ACCESS_TOKEN_KEY);
-        if (StrUtil.isNotBlank(accessToken)) {
-            return accessToken;
-        }
-        // Redis中不存在,则从微信服务器获取
-        String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token" +
-                "?grant_type=client_credential" +
-                "&appid=" + appId +
-                "&secret=" + appSecret;
-
-        String tokenJson = HttpUtil.get(accessTokenUrl, TIME_OUT);
-        JSONObject tokenObj = new JSONObject(tokenJson);
-        if (tokenObj.get(ERROR_CODE_STR) != null && tokenObj.get(ERROR_CODE_STR, Integer.class) != 0) {
-            throw new BusinessException("获取access_token失败");
-        }
 
-        // 获取新的access_token
-        accessToken = tokenObj.getStr("access_token");
-        // 存入Redis并设置过期时间
-        stringRedisTemplate.opsForValue().set(
-                WX_ACCESS_TOKEN_KEY,
-                accessToken,
-                ACCESS_TOKEN_EXPIRE,
-                TimeUnit.SECONDS
-        );
-        return accessToken;
-    }
 
     @RequestMapping(value = "/auto/login", method = RequestMethod.POST)
     @ApiOperation(value = "小程序登陆调用")
@@ -142,7 +114,7 @@ public class WChatUserController implements BaseController {
             throw new BusinessException("code不能为空");
         }
 
-        String accessToken = getAccessToken();
+        String accessToken = wChatUserService.getAccessToken(appId,appSecret);
         String phoneUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber" +
                 "?access_token=" + accessToken;
 
@@ -152,7 +124,7 @@ public class WChatUserController implements BaseController {
 
         JSONObject phoneObj = new JSONObject(phoneJson);
         if (phoneObj.get(ERROR_CODE_STR) != null && phoneObj.get(ERROR_CODE_STR, Integer.class) != 0) {
-            throw new BusinessException("获取手机号失败");
+             throw new BusinessException("获取手机号失败:"+phoneJson);
         }
         return phoneJson;
     }

+ 1 - 3
bus-web/src/main/java/bus/controller/biz/config/GlobalExceptionHandler.java → bus-web/src/main/java/bus/controller/biz/config/GlobalHandler.java

@@ -8,13 +8,11 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.ConstraintViolationException;
-import javax.xml.transform.Result;
 import java.util.List;
 import java.util.stream.Collectors;
 
 @RestControllerAdvice
-public class GlobalExceptionHandler {
-    
+public class GlobalHandler {
     @ExceptionHandler(MethodArgumentNotValidException.class)
     public JsonResponse handleValidationException(MethodArgumentNotValidException ex) {
         List<String> errors = ex.getBindingResult()

+ 21 - 21
bus-web/src/main/java/bus/controller/biz/job/DemoesTask.java

@@ -1,21 +1,21 @@
-package bus.controller.biz.job;
-
-
-import com.xxl.job.core.biz.model.ReturnT;
-import com.xxl.job.core.handler.annotation.XxlJob;
-import org.springframework.stereotype.Component;
-
-@Component
-public class  DemoesTask {
-
-    @XxlJob("demoJobHandler")
-    public ReturnT<String> demoJobHandler(String param) {
-        try {
-            System.out.println("定时任务执行-参数:" + param);
-            System.out.println(1111);
-        } catch (Exception e) {
-            return ReturnT.FAIL;
-        }
-        return ReturnT.SUCCESS;
-    }
-}
+//package bus.controller.biz.job;
+//
+//
+//import com.xxl.job.core.biz.model.ReturnT;
+//import com.xxl.job.core.handler.annotation.XxlJob;
+//import org.springframework.stereotype.Component;
+//
+//@Component
+//public class  DemoesTask {
+//
+//    @XxlJob("demoJobHandler")
+//    public ReturnT<String> demoJobHandler(String param) {
+//        try {
+//            System.out.println("定时任务执行-参数:" + param);
+//            System.out.println(1111);
+//        } catch (Exception e) {
+//            return ReturnT.FAIL;
+//        }
+//        return ReturnT.SUCCESS;
+//    }
+//}