Browse Source

合并代码

phoenix 1 năm trước cách đây
mục cha
commit
269937fdf8

+ 13 - 0
pom.xml

@@ -69,6 +69,8 @@
         <easy.captcha.version>1.6.2</easy.captcha.version>
         <paho.mqttv5.version>1.2.5</paho.mqttv5.version>
         <liteflow.version>2.11.2</liteflow.version>
+
+        <zxing.version>3.2.1</zxing.version>
     </properties>
 
     <dependencies>
@@ -501,6 +503,17 @@
             <scope>runtime</scope>
         </dependency>
 
+        <!-- 引入用于生成二维码的zxing-->
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>core</artifactId>
+            <version>${zxing.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>javase</artifactId>
+            <version>${zxing.version}</version>
+        </dependency>
 
     </dependencies>
 

+ 62 - 0
src/main/java/com/xjrsoft/common/utils/QrCodeUtil.java

@@ -0,0 +1,62 @@
+package com.xjrsoft.common.utils;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.MultiFormatWriter;
+import com.google.zxing.client.j2se.MatrixToImageWriter;
+import com.google.zxing.common.BitMatrix;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.HashMap;
+
+public class QrCodeUtil {
+
+	private static ByteArrayInputStream create(String url, int width, int height, int margin) throws Exception{
+        HashMap<EncodeHintType, Object> hints = new HashMap<>();
+        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
+		hints.put(EncodeHintType.MARGIN, margin);
+
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
+        
+        BitMatrix bitMatrix = new MultiFormatWriter().encode(url, BarcodeFormat.QR_CODE, width, height, hints);
+        MatrixToImageWriter.writeToStream(bitMatrix, "png", stream);
+
+		ByteArrayInputStream input = new ByteArrayInputStream(stream.toByteArray());
+        return input;
+	}
+
+	/**
+	 * @param url 链接地址
+	 * @param width 二维码的宽度
+	 * @param height 二维码的高度
+	 * @param margin 边距,只能是整数
+	 * @return 返回png格式的BufferedImage
+	 * @throws Exception
+	 */
+	public static BufferedImage createBufferedImage(String url, int width, int height, int margin) throws Exception{
+		ByteArrayInputStream input = create(url, width, height, margin);
+		return ImageIO.read(input);
+	}
+
+	/**
+	 * @param url 链接地址
+	 * @param width 二维码的宽度
+	 * @param height 二维码的高度
+	 * @param margin 边距,只能是整数
+	 * @return 返回png格式的Base64
+	 * @throws Exception
+	 */
+	public static String createBase64(String url, int width, int height, int margin) throws Exception{
+		ByteArrayInputStream input = create(url, width, height, margin);
+		byte[] bytes = new byte[1024];
+		input.read(bytes);
+		Base64.Encoder encoder = Base64.getEncoder();
+		String QRCodeBase64 = encoder.encodeToString(bytes);
+		return QRCodeBase64;
+	}
+}

+ 22 - 0
src/main/java/com/xjrsoft/module/textbook/controller/WfTextbookClaimController.java

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
+import com.xjrsoft.common.utils.QrCodeUtil;
+import com.xjrsoft.config.CommonPropertiesConfig;
 import com.xjrsoft.module.textbook.dto.AddWfTextbookClaimDto;
 import com.xjrsoft.module.textbook.dto.UpdateWfTextbookClaimDto;
 import com.xjrsoft.module.textbook.dto.WfTextbookClaimPageDto;
@@ -36,6 +38,8 @@ public class WfTextbookClaimController {
 
     private final IWfTextbookClaimService wfTextbookClaimService;
 
+    private final CommonPropertiesConfig commonPropertiesConfig;
+
     @GetMapping(value = "/page")
     @ApiOperation(value="教材申领列表(分页)")
     @SaCheckPermission("wftextbookclaim:detail")
@@ -85,4 +89,22 @@ public class WfTextbookClaimController {
 
     }
 
+    @GetMapping(value = "/info-qrcode")
+    @ApiOperation(value="教材领取-生成二维码")
+    @SaCheckPermission("wfstudenttextbookclaim:detail")
+    public RT<String> qrcode(@RequestParam Long id) throws Exception {
+        String url = commonPropertiesConfig.getDomainApp() + "/pages/material/grant?id=" + id;
+        int width = 200;
+        int height = 200;
+        int margin = 1;
+
+        try {
+            String base64 = QrCodeUtil.createBase64(url, width, height, margin);
+            return RT.ok(base64);
+        } catch (Exception e) {
+            throw e;
+        }
+
+    }
+
 }

+ 3 - 3
src/main/java/com/xjrsoft/module/textbook/service/impl/TextbookServiceImpl.java

@@ -232,7 +232,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
     public List<TextbookSubscriptionRecordVo> subscriptionList(Long id) {
         List<TextbookSubscriptionRecordVo> recordVos = textbookTextbookMapper.subscriptionList(id);
         for (TextbookSubscriptionRecordVo recordVo : recordVos) {
-            if (StrUtil.isEmpty(recordVo.getClassIds())) {
+            if(ObjectUtil.isNull(recordVo) || StrUtil.isEmpty(recordVo.getClassIds())){
                 continue;
             }
             String[] split = recordVo.getClassIds().split(",");
@@ -242,8 +242,8 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
             }
             List<TextbookSubscriptionClassVo> classInfo = textbookTextbookMapper.getClassInfo(ids);
             String useClass = "";
-            for (int i = 0; i < classInfo.size(); i++) {
-                if (i >= 1) {
+            for (int i = 0; i < classInfo.size(); i ++){
+                if(i >= 1){
                     useClass += ",";
                 }
                 TextbookSubscriptionClassVo classVo = classInfo.get(i);

+ 10 - 10
src/main/resources/mapper/textbook/TextbookMapper.xml

@@ -39,16 +39,16 @@
     </select>
 
     <select id="subscriptionList" resultType="com.xjrsoft.module.textbook.vo.TextbookSubscriptionRecordVo">
-        SELECT t2.create_date,t4.name AS applicant_user,t2.issn,t2.book_name,t2.publishing_house,
-        t2.editor_in_chief,t2.appraisal_price,t5.name AS is_textbook_plan_cn,t6.name AS course_name,
-        t2.student_subscription_number,t2.teacher_subscription_number,t2.teacher_reference_number,
-        t7.name AS is_support_resources_cn,t2.version, t2.class_ids FROM textbook_subscription_record t1
-        LEFT JOIN wf_textbook_subscription_item t2 ON t1.wf_textbook_subscription_id = t2.id
-        LEFT JOIN wf_textbook_subscription t3 ON t2.wf_textbook_subscription_id = t3.id
-        LEFT JOIN xjr_user t4 ON t3.applicant_user_id = t4.id
-        LEFT JOIN xjr_dictionary_detail t5 ON t2.is_textbook_plan = t5.code AND t5.item_id = 1737360269850038273
-        LEFT JOIN base_course_subject t6 ON t2.course_subject_id = t6.id
-        LEFT JOIN xjr_dictionary_detail t7 ON t2.is_support_resources = t7.code AND t7.item_id = 1737360269850038273
+        SELECT t2.create_date,t4.name AS applicant_user,t3.issn,t3.book_name,t3.publishing_house,
+        t3.editor_in_chief,t3.appraisal_price,t5.name AS is_textbook_plan_cn,t6.name AS course_name,
+        t3.student_subscription_number,t3.teacher_subscription_number,t3.teacher_reference_number,
+        t7.name AS is_support_resources_cn,t3.version, t3.class_ids FROM textbook_subscription_record t1
+        LEFT JOIN wf_textbook_subscription t2 ON t1.wf_textbook_subscription_id = t2.id
+        LEFT JOIN wf_textbook_subscription_item t3 ON t3.wf_textbook_subscription_id = t2.id
+        LEFT JOIN xjr_user t4 ON t2.applicant_user_id = t4.id
+        LEFT JOIN xjr_dictionary_detail t5 ON t3.is_textbook_plan = t5.code AND t5.item_id = 1737360269850038273
+        LEFT JOIN base_course_subject t6 ON t3.course_subject_id = t6.id
+        LEFT JOIN xjr_dictionary_detail t7 ON t3.is_support_resources = t7.code AND t7.item_id = 1737360269850038273
         WHERE t1.delete_mark = 0 AND t1.textbook_id = #{id}
     </select>