|
@@ -4,25 +4,31 @@ import com.bofeng.dao.*;
|
|
|
import com.bofeng.entity.*;
|
|
|
import com.bofeng.service.HomeService;
|
|
|
import com.bofeng.service.ScanService;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
-import com.yvan.platform.JsonWapper;
|
|
|
+import com.google.zxing.BarcodeFormat;
|
|
|
+import com.google.zxing.MultiFormatWriter;
|
|
|
+import com.google.zxing.WriterException;
|
|
|
+import com.google.zxing.client.j2se.MatrixToImageConfig;
|
|
|
+import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
|
+import com.google.zxing.common.BitMatrix;
|
|
|
+import com.yvan.mvc.Pd;
|
|
|
import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiImplicitParam;
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.Cleanup;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.text.DateFormat;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -30,6 +36,14 @@ import java.util.List;
|
|
|
@RestController
|
|
|
public class ScanController {
|
|
|
|
|
|
+ // 获取code
|
|
|
+ private static final String oauth2 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=";
|
|
|
+ private static final String moreUrl = "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
|
|
|
+ @Value("${yvan.wechat.appID}")
|
|
|
+ private String appId;
|
|
|
+ @Value("${yvan.wechat.domain}")
|
|
|
+ private String domain;
|
|
|
+
|
|
|
@Autowired
|
|
|
private HomeService homeService;
|
|
|
@Autowired
|
|
@@ -53,6 +67,13 @@ public class ScanController {
|
|
|
@Autowired
|
|
|
private OutScanEstateMapper outScanEstateMapper;
|
|
|
|
|
|
+ /**
|
|
|
+ * @param doorId 小区大门ID
|
|
|
+ * @param inType 1进入;2外出
|
|
|
+ * @param request
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation("进出扫码页面")
|
|
|
@GetMapping("/user/scan.html")
|
|
|
public ModelAndView scan(HttpServletRequest request, ModelMap model, @RequestParam(value = "doorId", required = false, defaultValue = "0") Long doorId,
|
|
@@ -138,6 +159,7 @@ public class ScanController {
|
|
|
model.put("errorMsg", "这是您今天第" + conut + "次出行,为了您的安全,请尽快回家。");
|
|
|
}
|
|
|
scanService.saveOutScanEstate(userOpen.getUserId());
|
|
|
+ model.put("img", "/scan/scanEstate_qr.png");
|
|
|
return new ModelAndView("/user/scanEstate.ftl", model);
|
|
|
}
|
|
|
}
|
|
@@ -164,4 +186,34 @@ public class ScanController {
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成进出门二维码
|
|
|
+ * @param doorId 小区大门ID
|
|
|
+ * @param inType 1进入;2外出
|
|
|
+ * @param response
|
|
|
+ * @throws IOException
|
|
|
+ * @throws WriterException
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/scan/scan_qr.png", produces = MediaType.IMAGE_PNG_VALUE)
|
|
|
+ public void scanQrImg(@Pd(name = "doorId") Long doorId, @Pd(name = "inType") Integer inType,
|
|
|
+ HttpServletResponse response) throws IOException, WriterException {
|
|
|
+ @Cleanup ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ BitMatrix matrix = new MultiFormatWriter().encode(oauth2 + appId + "&redirect_uri=" + domain +
|
|
|
+ "/user/scan.html?doorId=" + doorId + "&inType=" + inType + moreUrl, BarcodeFormat.QR_CODE, 256, 256);
|
|
|
+ MatrixToImageWriter.writeToStream(matrix, MediaType.IMAGE_PNG.getSubtype(), outputStream, new MatrixToImageConfig());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成校园巡逻二维码
|
|
|
+ * @throws IOException
|
|
|
+ * @throws WriterException
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/scan/scanEstate_qr.png", produces = MediaType.IMAGE_PNG_VALUE)
|
|
|
+ public void scanEstateQrImg(HttpServletResponse response) throws IOException, WriterException {
|
|
|
+ @Cleanup ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ BitMatrix matrix = new MultiFormatWriter().encode(oauth2 + appId + "&redirect_uri=" + domain +
|
|
|
+ "/user/scanEstate.html" + moreUrl, BarcodeFormat.QR_CODE, 256, 256);
|
|
|
+ MatrixToImageWriter.writeToStream(matrix, MediaType.IMAGE_PNG.getSubtype(), outputStream, new MatrixToImageConfig());
|
|
|
+ }
|
|
|
}
|