Administrator 1 년 전
부모
커밋
6c80a270e9

+ 60 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/BomanCommonController.java

@@ -0,0 +1,60 @@
+package com.ruoyi.web.controller.common;
+
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.system.domain.BomanReservatConfigTime;
+import com.ruoyi.system.service.IBomanReservatConfigTimeService;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @Author: tjf
+ * @Date: 2023/11/2 17:10
+ * @Describe:
+ */
+@RestController
+@RequestMapping("/boman/common")
+public class BomanCommonController extends BaseController {
+
+    @Autowired
+    private IBomanReservatConfigTimeService bomanReservatConfigTimeService;
+    @Autowired
+    private RedisCache redisCache;
+
+
+    /**
+     * H5时段信息 查询预约时段配置列表
+     */
+    @PostMapping("/reservatConfig/list")
+    public TableDataInfo list(@RequestBody BomanReservatConfigTime bomanReservatConfigTime)
+    {
+        //根据日期查询所有时段是否可约
+        List<BomanReservatConfigTime> list = bomanReservatConfigTimeService.selectBomanReservatConfigTimeList(bomanReservatConfigTime);
+        if (list != null && list.size() > 0){
+            for (BomanReservatConfigTime reservatConfigTime : list) {
+                //查询所有时段和最大人数
+                //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
+                String reservatConfigDate = bomanReservatConfigTime.getReservatConfigDate();
+                //以预约人数
+                Object  reservatNum= redisCache.getCacheObject(Constants.RESERVAT_NUM + reservatConfigDate + "_" + reservatConfigTime.getReservatConfigTimeId());
+                if (ObjectUtils.isNotEmpty(reservatNum)){
+                    //判断人数是否大于可预约人数
+                    //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
+                   if (NumberUtils.compare(reservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 0){
+                       reservatConfigTime.setReservatConfigStatus("Y");
+                   }
+                }
+            }
+        }
+        return getDataTable(list);
+    }
+}

+ 35 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SendSmsController.java

@@ -0,0 +1,35 @@
+package com.ruoyi.web.controller.common;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.SendSmsUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @Author: tjf
+ * @Date: 2023/10/13 17:15
+ * @Describe:
+ */
+@RestController
+@RequestMapping("/sendSms")
+public class SendSmsController {
+
+
+    /**
+     * 发送密码验证码短信
+     * @param
+     * @return
+     */
+    @GetMapping("/{phone}")
+    public AjaxResult sendSms(String phone) {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("code", SendSmsUtils.getCode(4));
+        SendSmsUtils.sendSms(phone,"SMS_219525380",jsonObject.toString());
+        return AjaxResult.success();
+    }
+
+
+
+}

+ 9 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/material/BomanMaterialController.java

@@ -77,7 +77,15 @@ public class BomanMaterialController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody BomanMaterial bomanMaterial)
     {
-        return toAjax(bomanMaterialService.insertBomanMaterial(bomanMaterial));
+        List<BomanMaterial> bomanMaterialList = bomanMaterial.getBomanMaterialList();
+        if (bomanMaterialList != null && bomanMaterialList.size() > 0){
+            for (BomanMaterial material : bomanMaterialList) {
+                material.setKeywords(bomanMaterial.getKeywords());
+                material.setReleaseTime(bomanMaterial.getReleaseTime());
+                material.setType(bomanMaterial.getType());
+            }
+        }
+        return toAjax(bomanMaterialService.insertBomanMaterial(bomanMaterialList));
     }
 
     /**

+ 6 - 0
ruoyi-common/pom.xml

@@ -17,6 +17,12 @@
 
     <dependencies>
 
+        <!--阿里短信服务-->
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>dysmsapi20170525</artifactId>
+            <version>2.0.23</version>
+        </dependency>
         <!-- Spring框架基本的核心工具 -->
         <dependency>
             <groupId>org.springframework</groupId>

+ 5 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@@ -144,4 +144,9 @@ public class Constants
      */
     public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
             "org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config" };
+
+    /**
+     * 日期+对应时段id的预约人数
+     */
+    public static final String RESERVAT_NUM = "reservat_num:";
 }

+ 134 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/SendSmsUtils.java

@@ -0,0 +1,134 @@
+package com.ruoyi.common.utils;
+
+
+import com.aliyun.dysmsapi20170525.models.SendBatchSmsRequest;
+import com.aliyun.dysmsapi20170525.models.SendBatchSmsResponse;
+import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
+import com.aliyun.tea.TeaException;
+import com.aliyun.teautil.models.RuntimeOptions;
+
+/**
+ * @author tjf
+ * @Date: 2021/07/15/10:21
+ */
+public class SendSmsUtils {
+    //短信参数
+    static final String ACCESS_KEY_ID = "LTAI5tNA2fcBJH6EWRH6Pxr6";
+    static final String ACCESS_KEY_SECRET = "5WdaPEOvC3u9LC7pwy2DQ9pgmJvgUr";
+
+
+    //生成X位验证码
+    public static String getCode(Integer num) {
+        String[] codes = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
+        StringBuilder code = new StringBuilder();
+        for (int i = 0; i < num; i++) {
+            int j = (int) (Math.random() * 10);
+            if (j <= 0) {
+                j = 1;
+            }
+            code.append(codes[j - 1]);
+
+        }
+        return code.toString();
+    }
+
+
+    /**
+     * 使用AK&SK初始化账号Client
+     *
+     * @return Client
+     * @throws Exception
+     */
+    public static com.aliyun.dysmsapi20170525.Client createClient() throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+            // 必填,您的 AccessKey ID
+            .setAccessKeyId(ACCESS_KEY_ID)
+            // 必填,您的 AccessKey Secret
+            .setAccessKeySecret(ACCESS_KEY_SECRET);
+        // 访问的域名
+        config.endpoint = "dysmsapi.aliyuncs.com";
+        return new com.aliyun.dysmsapi20170525.Client(config);
+    }
+
+
+    /**
+     * 发送短信消息
+     *
+     * @return
+     */
+    public static String sendSms(String phone, String templateCode, String smsCode) {
+        String code = "";
+        try {
+            // 工程代码泄露可能会导致AccessKey泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
+            com.aliyun.dysmsapi20170525.Client client = SendSmsUtils.createClient();
+
+            com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
+                //手机号码
+                .setPhoneNumbers(phone)
+                //短信签名名称。中新云
+                .setSignName("中新云")
+                //短信模板变量对应的实际值{"name": code}
+                .setTemplateParam(smsCode)
+                //短信模板CODE
+                .setTemplateCode(templateCode);
+            // 复制代码运行请自行打印 API 的返回值
+            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
+            code = sendSmsResponse.getBody().code;
+        } catch (Exception _error) {
+        }
+        return code;
+    }
+
+    /**
+     * 阿里云批量发送 短信接口,一次最多100个手机号码
+     *
+     * @return
+     * @throws
+     */
+    public static SendBatchSmsResponse sendBatchSms(SendBatchSmsRequest sendBatchSmsRequest){
+        try {
+            com.aliyun.dysmsapi20170525.Client client = SendSmsUtils.createClient();
+            RuntimeOptions runtime = new RuntimeOptions();
+            SendBatchSmsResponse sendBatchSmsResponse = client.sendBatchSmsWithOptions(sendBatchSmsRequest, runtime);
+            return sendBatchSmsResponse;
+            // 复制代码运行请自行打印 API 的返回值
+        } catch (TeaException error) {
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+        } catch (Exception _error) {
+            TeaException error = new TeaException(_error.getMessage(), _error);
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+        }
+        return null;
+    }
+
+    /**
+     * 发送注册的随机密码
+     *
+     * @return
+     */
+    public static String sendPassword(String password, String phone, String templateCode) {
+        String code = "";
+        try {
+            // 工程代码泄露可能会导致AccessKey泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
+            com.aliyun.dysmsapi20170525.Client client = SendSmsUtils.createClient();
+            String smsCode = "{\"password\":\"" + password + "\"}";
+            com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
+                //手机号码
+                .setPhoneNumbers(phone)
+                //短信签名名称。潜山市数据资源局
+                .setSignName("中新云")
+                //短信模板CODE
+                .setTemplateCode(templateCode)
+                //短信模板变量对应的实际值{"name": code}
+                .setTemplateParam(smsCode);
+            // 复制代码运行请自行打印 API 的返回值
+            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
+            code = sendSmsResponse.getBody().code;
+        } catch (Exception _error) {
+        }
+        return code;
+    }
+}
+

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage").permitAll()
+                .antMatchers("/login", "/register", "/captchaImage","/boman/common/**","/sendSms/**").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 33 - 12
ruoyi-system/src/main/java/com/ruoyi/system/domain/BomanMaterial.java

@@ -1,6 +1,8 @@
 package com.ruoyi.system.domain;
 
 import java.util.Date;
+import java.util.List;
+
 import com.fasterxml.jackson.annotation.JsonFormat;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
@@ -29,13 +31,34 @@ public class BomanMaterial extends BaseEntity
 
     /** 关键字 */
     private String keywords;
+    /**
+     * 1:图片 2:视频
+     */
+    private String type;
 
     /** 发布时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "发布时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date releaseTime;
+    private List<BomanMaterial> bomanMaterialList;
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public List<BomanMaterial> getBomanMaterialList() {
+        return bomanMaterialList;
+    }
+
+    public void setBomanMaterialList(List<BomanMaterial> bomanMaterialList) {
+        this.bomanMaterialList = bomanMaterialList;
+    }
 
-    public void setMaterialId(Long materialId) 
+    public void setMaterialId(Long materialId)
     {
         this.materialId = materialId;
     }
@@ -83,16 +106,14 @@ public class BomanMaterial extends BaseEntity
 
     @Override
     public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("materialId", getMaterialId())
-            .append("materialUrl", getMaterialUrl())
-            .append("materialName", getMaterialName())
-            .append("keywords", getKeywords())
-            .append("releaseTime", getReleaseTime())
-            .append("createTime", getCreateTime())
-            .append("createBy", getCreateBy())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
-            .toString();
+        return "BomanMaterial{" +
+                "materialId=" + materialId +
+                ", materialUrl='" + materialUrl + '\'' +
+                ", materialName='" + materialName + '\'' +
+                ", keywords='" + keywords + '\'' +
+                ", type='" + type + '\'' +
+                ", releaseTime=" + releaseTime +
+                ", bomanMaterialList=" + bomanMaterialList +
+                '}';
     }
 }

+ 4 - 4
ruoyi-system/src/main/java/com/ruoyi/system/domain/BomanReservatConfigTime.java

@@ -25,13 +25,13 @@ public class BomanReservatConfigTime extends BaseEntity
     private String reservatConfigDate;
 
     /** 可预约时间开始 */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "可预约时间开始", width = 30, dateFormat = "yyyy-MM-dd")
+    @JsonFormat(pattern = "HH:mm:ss")
+    @Excel(name = "可预约时间开始", width = 30, dateFormat = "HH:mm:ss")
     private Date reservatConfigTimeBegin;
 
     /** 可预约时间结束 */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "可预约时间结束", width = 30, dateFormat = "yyyy-MM-dd")
+    @JsonFormat(pattern = "HH:mm:ss")
+    @Excel(name = "可预约时间结束", width = 30, dateFormat = "HH:mm:ss")
     private Date reservatConfigTimeEnd;
 
     /** 可预约次数 */

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BomanMaterialMapper.java

@@ -34,6 +34,7 @@ public interface BomanMaterialMapper
      * @return 结果
      */
     public int insertBomanMaterial(BomanMaterial bomanMaterial);
+    public int batchBomanMaterial(List<BomanMaterial> bomanMaterial);
 
     /**
      * 修改素材库

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/IBomanMaterialService.java

@@ -33,7 +33,7 @@ public interface IBomanMaterialService
      * @param bomanMaterial 素材库
      * @return 结果
      */
-    public int insertBomanMaterial(BomanMaterial bomanMaterial);
+    public int insertBomanMaterial(List<BomanMaterial> bomanMaterial);
 
     /**
      * 修改素材库

+ 3 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanMaterialServiceImpl.java

@@ -51,10 +51,10 @@ public class BomanMaterialServiceImpl implements IBomanMaterialService
      * @return 结果
      */
     @Override
-    public int insertBomanMaterial(BomanMaterial bomanMaterial)
+    public int insertBomanMaterial(List<BomanMaterial> bomanMaterial)
     {
-        bomanMaterial.setCreateTime(DateUtils.getNowDate());
-        return bomanMaterialMapper.insertBomanMaterial(bomanMaterial);
+
+        return bomanMaterialMapper.batchBomanMaterial(bomanMaterial);
     }
 
     /**

+ 12 - 1
ruoyi-system/src/main/resources/mapper/system/BomanMaterialMapper.xml

@@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="materialUrl"    column="material_url"    />
         <result property="materialName"    column="material_name"    />
         <result property="keywords"    column="keywords"    />
+        <result property="type"    column="type"    />
         <result property="releaseTime"    column="release_time"    />
         <result property="createTime"    column="create_time"    />
         <result property="createBy"    column="create_by"    />
@@ -17,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectBomanMaterialVo">
-        select material_id, material_url, material_name, keywords, release_time, create_time, create_by, update_by, update_time from boman_material
+        select material_id, material_url,type, material_name, keywords, release_time, create_time, create_by, update_by, update_time from boman_material
     </sql>
 
     <select id="selectBomanMaterialList" parameterType="BomanMaterial" resultMap="BomanMaterialResult">
@@ -25,6 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <where>  
             <if test="materialUrl != null  and materialUrl != ''"> and material_url = #{materialUrl}</if>
             <if test="releaseTime != null "> and release_time = #{releaseTime}</if>
+            <if test="type != null "> and type = #{type}</if>
         </where>
     </select>
     
@@ -40,6 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="materialName != null">material_name,</if>
             <if test="keywords != null">keywords,</if>
             <if test="releaseTime != null">release_time,</if>
+            <if test="type != null">type,</if>
             <if test="createTime != null">create_time,</if>
             <if test="createBy != null">create_by,</if>
             <if test="updateBy != null">update_by,</if>
@@ -50,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="materialName != null">#{materialName},</if>
             <if test="keywords != null">#{keywords},</if>
             <if test="releaseTime != null">#{releaseTime},</if>
+            <if test="type != null">#{type},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="createBy != null">#{createBy},</if>
             <if test="updateBy != null">#{updateBy},</if>
@@ -57,6 +61,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
     </insert>
 
+    <insert id="batchBomanMaterial">
+        insert into boman_material(material_url, material_name,type,keywords,release_time,create_time) values
+        <foreach item="item" index="index" collection="list" separator=",">
+            (#{item.materialUrl},#{item.materialName},#{item.type},#{item.keywords},#{item.releaseTime},sysdate())
+        </foreach>
+    </insert>
     <update id="updateBomanMaterial" parameterType="BomanMaterial">
         update boman_material
         <trim prefix="SET" suffixOverrides=",">
@@ -64,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="materialName != null">material_name = #{materialName},</if>
             <if test="keywords != null">keywords = #{keywords},</if>
             <if test="releaseTime != null">release_time = #{releaseTime},</if>
+            <if test="type != null">type = #{type},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="createBy != null">create_by = #{createBy},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>

+ 1 - 3
ruoyi-system/src/main/resources/mapper/system/BomanReservatConfigTimeMapper.xml

@@ -26,14 +26,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectBomanReservatConfigTimeList" parameterType="BomanReservatConfigTime" resultMap="BomanReservatConfigTimeResult">
         <include refid="selectBomanReservatConfigTimeVo"/>
-        <where>  
-            <if test="reservatConfigDate != null  and reservatConfigDate != ''"> and reservat_config_date = #{reservatConfigDate}</if>
+        <where>
             <if test="reservatConfigTimeBegin != null "> and reservat_config_time_begin = #{reservatConfigTimeBegin}</if>
             <if test="reservatConfigTimeEnd != null "> and reservat_config_time_end = #{reservatConfigTimeEnd}</if>
             <if test="reservatConfigNum != null "> and reservat_config_num = #{reservatConfigNum}</if>
             <if test="reservatConfigType != null  and reservatConfigType != ''"> and reservat_config_type = #{reservatConfigType}</if>
             <if test="reservatConfigStatus != null  and reservatConfigStatus != ''"> and reservat_config_status = #{reservatConfigStatus}</if>
-            <if test="createDept != null "> and create_dept = #{createDept}</if>
         </where>
     </select>