Bläddra i källkod

更新预约表

Administrator 1 år sedan
förälder
incheckning
a31fe33cf5

+ 2 - 2
ruoyi-admin/src/main/resources/application-prod.yml

@@ -179,9 +179,9 @@ sms:
     #请求地址 默认为 dysmsapi.aliyuncs.com 如无特殊改变可以不用设置
     requestUrl: dysmsapi.aliyuncs.com
     #阿里云的accessKey
-    accessKeyId: xxxxxxx
+    accessKeyId: LTAI5tNA2fcBJH6EWRH6Pxr6
     #阿里云的accessKeySecret
-    accessKeySecret: xxxxxxx
+    accessKeySecret: 5WdaPEOvC3u9LC7pwy2DQ9pgmJvgUr
     #短信签名
     signature: 测试
   tencent:

+ 12 - 0
ruoyi-modules/ruoyi-system/pom.xml

@@ -96,6 +96,18 @@
             <version>2.0.25</version>
         </dependency>
 
+        <!--二维码-->
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>core</artifactId>
+            <version>3.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>javase</artifactId>
+            <version>3.1.0</version>
+        </dependency>
+
     </dependencies>
     <properties>
         <maven.compiler.source>17</maven.compiler.source>

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/reservat/XiaoyuanReservatController.java

@@ -123,7 +123,7 @@ public class XiaoyuanReservatController extends BaseController {
      * 根据教职工手机号查询可预约的时间
      */
     @PostMapping("/subscribe")
-    public AjaxResult subscribe(XiaoyuanReservatBo bo) {
+    public AjaxResult subscribe(@RequestBody XiaoyuanReservatBo bo) {
         return  xiaoyuanReservatService.subscribe(bo);
     }
 
@@ -131,7 +131,7 @@ public class XiaoyuanReservatController extends BaseController {
      * 预约首页统计
      */
     @PostMapping("/indexStatistics")
-    public AjaxResult indexStatistics(XiaoyuanReservatBo bo) {
+    public AjaxResult indexStatistics(@RequestBody XiaoyuanReservatBo bo) {
         return  xiaoyuanReservatService.indexStatistics(bo);
     }
 }

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/reservat/XiaoyuanReservatConfigServiceImpl.java

@@ -46,6 +46,7 @@ public class XiaoyuanReservatConfigServiceImpl implements IXiaoyuanReservatConfi
      */
     @Override
     public TableDataInfo<XiaoyuanReservatConfigVo> queryPageList(XiaoyuanReservatConfigBo bo, PageQuery pageQuery) {
+        bo.setTeacherPhone(LoginHelper.getUsername());
         LambdaQueryWrapper<XiaoyuanReservatConfig> lqw = buildQueryWrapper(bo);
         Page<XiaoyuanReservatConfigVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
         return TableDataInfo.build(result);

+ 45 - 27
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/reservat/XiaoyuanReservatServiceImpl.java

@@ -16,6 +16,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.RequiredArgsConstructor;
 import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.sms4j.api.SmsBlend;
+import org.dromara.sms4j.comm.utils.SmsUtil;
+import org.dromara.sms4j.core.factory.SmsFactory;
+import org.dromara.sms4j.provider.enumerate.SupplierType;
 import org.dromara.system.domain.reservat.XiaoyuanReservat;
 import org.dromara.system.domain.reservat.XiaoyuanReservatConfig;
 import org.dromara.system.domain.reservat.bo.XiaoyuanReservatBo;
@@ -152,38 +156,52 @@ public class XiaoyuanReservatServiceImpl implements IXiaoyuanReservatService {
         LambdaQueryWrapper<XiaoyuanReservatConfig> lqw = Wrappers.lambdaQuery();
         lqw.eq(StringUtils.isNotBlank(bo.getTeacherPhone()), XiaoyuanReservatConfig::getTeacherPhone, bo.getTeacherPhone());
         XiaoyuanReservatConfigVo xiaoyuanReservatConfigVo = xiaoyuanReservatConfigMapper.selectVoOne(lqw);
-        //获取预约的年月
-        String visitDate = bo.getVisitDate();
-        List<String> monthFullDay = DateUtils.getMonthFullDay(DateUtils.parseDate(visitDate));
-        LambdaQueryWrapper<XiaoyuanReservat> lqwr = Wrappers.lambdaQuery();
-        JSONArray jsonArray = new JSONArray();
-        if (monthFullDay.size() > 0){
-         //判断日期是星期几,是否可以预约
-            for (String date : monthFullDay) {
-                JSONObject jsonObject = new JSONObject();
-                int week = DateUtils.dayForWeek(date);
-                jsonObject.put("date",week);
-                jsonObject.put("title","不可约");
-                String reservatConfigDate = xiaoyuanReservatConfigVo.getReservatConfigDate();
-                if (String.valueOf(week).contains(reservatConfigDate)){
-                    jsonObject.put("title","可预约");
-                    //包含去查询改天是否被预约满
-                    lqwr.eq(StringUtils.isNotBlank(bo.getTeacherPhone()), XiaoyuanReservat::getTeacherPhone, bo.getTeacherPhone());
-                    lqwr.eq(XiaoyuanReservat::getVisitDate, week);
-                    List<XiaoyuanReservatVo> xiaoyuanReservatVos = baseMapper.selectVoList(lqwr);
-                    if (xiaoyuanReservatVos != null && xiaoyuanReservatVos.size() > 0){
-                        //判断是否大于次数
-                        Long reservatConfigNum = xiaoyuanReservatConfigVo.getReservatConfigNum();
-                        if (xiaoyuanReservatVos.size() > reservatConfigNum){
-                            //说明约满
-                            jsonObject.put("title","已约满");
+        Map map =new HashMap();
+        map.put("reservatConfigTimeAmBegin","");
+        map.put("reservatConfigTimeAmEnd","");
+        map.put("reservatConfigTimePmBegin","");
+        map.put("reservatConfigTimePmEnd","");
+        if (xiaoyuanReservatConfigVo != null){
+            map.put("reservatConfigTimeAmBegin",xiaoyuanReservatConfigVo.getReservatConfigTimeAmBegin());
+            map.put("reservatConfigTimeAmEnd",xiaoyuanReservatConfigVo.getReservatConfigTimeAmEnd());
+            map.put("reservatConfigTimePmBegin",xiaoyuanReservatConfigVo.getReservatConfigTimePmBegin());
+            map.put("reservatConfigTimePmEnd",xiaoyuanReservatConfigVo.getReservatConfigTimePmEnd());
+            //获取预约的年月
+            String visitDate = bo.getVisitDate();
+            List<String> monthFullDay = DateUtils.getMonthFullDay(DateUtils.parseDate(visitDate));
+            LambdaQueryWrapper<XiaoyuanReservat> lqwr = Wrappers.lambdaQuery();
+            JSONArray jsonArray = new JSONArray();
+            if (monthFullDay.size() > 0){
+                //判断日期是星期几,是否可以预约
+                for (String date : monthFullDay) {
+                    JSONObject jsonObject = new JSONObject();
+                    int week = DateUtils.dayForWeek(date);
+                    jsonObject.put("date",date);
+                    jsonObject.put("title","不可约");
+                    String reservatConfigDate = xiaoyuanReservatConfigVo.getReservatConfigDate();
+                    if (String.valueOf(week).contains(reservatConfigDate)){
+                        jsonObject.put("title","可预约");
+                        //包含去查询改天是否被预约满
+                        lqwr.eq(StringUtils.isNotBlank(bo.getTeacherPhone()), XiaoyuanReservat::getTeacherPhone, bo.getTeacherPhone());
+                        lqwr.eq(XiaoyuanReservat::getVisitDate, week);
+                        List<XiaoyuanReservatVo> xiaoyuanReservatVos = baseMapper.selectVoList(lqwr);
+                        if (xiaoyuanReservatVos != null && xiaoyuanReservatVos.size() > 0){
+                            //判断是否大于次数
+                            Long reservatConfigNum = xiaoyuanReservatConfigVo.getReservatConfigNum();
+                            if (xiaoyuanReservatVos.size() > reservatConfigNum){
+                                //说明约满
+                                jsonObject.put("title","已约满");
+                            }
                         }
                     }
+                    jsonArray.add(jsonObject);
                 }
-                jsonArray.add(jsonObject);
+                map.put("signList",jsonArray);
             }
+            return AjaxResult.success(map);
         }
-        return AjaxResult.success(jsonArray);
+        return AjaxResult.error("该用户暂不可预约");
+
     }
 
 

+ 241 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/utils/QRCodeUtils.java

@@ -0,0 +1,241 @@
+package org.dromara.system.utils;
+
+import cn.hutool.extra.qrcode.BufferedImageLuminanceSource;
+import com.google.zxing.*;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.HybridBinarizer;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+import org.dromara.common.core.utils.DateUtils;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.geom.RoundRectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.OutputStream;
+import java.util.Hashtable;
+import java.util.UUID;
+
+/**
+ * @Author: tjf
+ * @Date: 2023/9/13 14:44
+ * @Describe:
+ */
+public class QRCodeUtils {
+    private static final String CHARSET = "utf-8";
+    private static final String FORMAT_NAME = "JPG";
+    // 二维码尺寸
+    private static final int QRCODE_SIZE = 300;
+    // LOGO宽度
+    private static final int WIDTH = 60;
+    // LOGO高度
+    private static final int HEIGHT = 60;
+
+    private static BufferedImage createImage(String content, String imgPath,
+                                             boolean needCompress) throws Exception {
+        Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
+        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
+        hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
+        hints.put(EncodeHintType.MARGIN, 1);
+        BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
+            BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
+        int width = bitMatrix.getWidth();
+        int height = bitMatrix.getHeight();
+        BufferedImage image = new BufferedImage(width, height,
+            BufferedImage.TYPE_INT_RGB);
+        for (int x = 0; x < width; x++) {
+            for (int y = 0; y < height; y++) {
+                image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000
+                    : 0xFFFFFFFF);
+            }
+        }
+        if (imgPath == null || "".equals(imgPath)) {
+            return image;
+        }
+        // 插入图片
+        QRCodeUtils.insertImage(image, imgPath, needCompress);
+        return image;
+    }
+
+    /**
+     * 插入LOGO
+     *
+     * @param source       二维码图片
+     * @param imgPath      LOGO图片地址
+     * @param needCompress 是否压缩
+     * @throws Exception
+     */
+    private static void insertImage(BufferedImage source, String imgPath,
+                                    boolean needCompress) throws Exception {
+        File file = new File(imgPath);
+        if (!file.exists()) {
+            System.err.println("" + imgPath + "   该文件不存在!");
+            return;
+        }
+        Image src = ImageIO.read(new File(imgPath));
+        int width = src.getWidth(null);
+        int height = src.getHeight(null);
+        if (needCompress) { // 压缩LOGO
+            if (width > WIDTH) {
+                width = WIDTH;
+            }
+            if (height > HEIGHT) {
+                height = HEIGHT;
+            }
+            Image image = src.getScaledInstance(width, height,
+                Image.SCALE_SMOOTH);
+            BufferedImage tag = new BufferedImage(width, height,
+                BufferedImage.TYPE_INT_RGB);
+            Graphics g = tag.getGraphics();
+            g.drawImage(image, 0, 0, null); // 绘制缩小后的图
+            g.dispose();
+            src = image;
+        }
+        // 插入LOGO
+        Graphics2D graph = source.createGraphics();
+        int x = (QRCODE_SIZE - width) / 2;
+        int y = (QRCODE_SIZE - height) / 2;
+        graph.drawImage(src, x, y, width, height, null);
+        Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
+        graph.setStroke(new BasicStroke(3f));
+        graph.draw(shape);
+        graph.dispose();
+    }
+
+    /**
+     * 生成二维码(内嵌LOGO)
+     *
+     * @param content      内容
+     * @param imgPath      LOGO地址
+     * @param destPath     存放目录
+     * @param needCompress 是否压缩LOGO
+     * @throws Exception
+     */
+    public static String encode(String content, String imgPath, String destPath,
+                                boolean needCompress) throws Exception {
+        BufferedImage image = QRCodeUtils.createImage(content, imgPath,
+            needCompress);
+        String date = DateUtils.datePath();
+        destPath = destPath+"/" + date;
+        mkdirs(destPath);
+        String file = UUID.randomUUID() + ".jpg";
+        File fileQR = new File(destPath + "/" + file);
+        ImageIO.write(image, FORMAT_NAME, fileQR);
+        return "/profile/qrUpload/"+date+"/"+file;
+    }
+
+
+    /**
+     * 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
+     *
+     * @param destPath 存放目录
+     * @date 2013-12-11 上午10:16:36
+     */
+    public static void mkdirs(String destPath) {
+        File file = new File(destPath);
+        //当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
+        if (!file.exists() && !file.isDirectory()) {
+            file.mkdirs();
+        }
+    }
+
+    /**
+     * 生成二维码(内嵌LOGO)
+     *
+     * @param content  内容
+     * @param imgPath  LOGO地址
+     * @param destPath 存储地址
+     * @throws Exception
+     */
+    public static void encode(String content, String imgPath, String destPath)
+        throws Exception {
+        QRCodeUtils.encode(content, imgPath, destPath, false);
+    }
+
+    /**
+     * 生成二维码
+     *
+     * @param content      内容
+     * @param destPath     存储地址
+     * @param needCompress 是否压缩LOGO
+     * @throws Exception
+     */
+    public static void encode(String content, String destPath,
+                              boolean needCompress) throws Exception {
+        QRCodeUtils.encode(content, null, destPath, needCompress);
+    }
+
+    /**
+     * 生成二维码
+     *
+     * @param content  内容
+     * @param destPath 存储地址
+     * @throws Exception
+     */
+    public static void encode(String content, String destPath) throws Exception {
+        QRCodeUtils.encode(content, null, destPath, false);
+    }
+
+    /**
+     * 生成二维码(内嵌LOGO)
+     *
+     * @param content      内容
+     * @param imgPath      LOGO地址
+     * @param output       输出流
+     * @param needCompress 是否压缩LOGO
+     * @throws Exception
+     */
+    public static void encode(String content, String imgPath,
+                              OutputStream output, boolean needCompress) throws Exception {
+        BufferedImage image = QRCodeUtils.createImage(content, imgPath,
+            needCompress);
+        ImageIO.write(image, FORMAT_NAME, output);
+    }
+
+    /**
+     * 生成二维码
+     *
+     * @param content 内容
+     * @param output  输出流
+     * @throws Exception
+     */
+    public static void encode(String content, OutputStream output)
+        throws Exception {
+        QRCodeUtils.encode(content, null, output, false);
+    }
+
+    /**
+     * 解析二维码
+     *
+     * @param file 二维码图片
+     * @return
+     * @throws Exception
+     */
+    public static String decode(File file) throws Exception {
+        BufferedImage image;
+        image = ImageIO.read(file);
+        if (image == null) {
+            return null;
+        }
+        BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(
+            image);
+        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
+        Result result;
+        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
+        hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
+        result = new MultiFormatReader().decode(bitmap, hints);
+        String resultStr = result.getText();
+        return resultStr;
+    }
+
+    /**
+     * 解析二维码
+     *
+     * @param path 二维码图片地址
+     * @return
+     * @throws Exception
+     */
+    public static String decode(String path) throws Exception {
+        return QRCodeUtils.decode(new File(path));
+    }
+}