Przeglądaj źródła

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 2 lat temu
rodzic
commit
4af0c5ed4e

+ 57 - 47
src/main/java/com/template/controller/SmartAttendanceController.java

@@ -110,13 +110,14 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
 
     @Resource
     private ScheduleConfig scheduleConfig;
+
     /**
      * 每一小时获取请假信息
-      */
+     */
     @Async
     @Scheduled(cron = "0 0 0/1 * * ? ")
-    public void get(){
-        if(scheduleConfig.getIsOpen().equals("1")){
+    public void get() {
+        if (scheduleConfig.getIsOpen().equals("1")) {
             queryLeaveRecords();
         }
 
@@ -136,12 +137,14 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
             return CommonResult.fail(result.getResponseBody().getMessage());
         }
         SmartAskForLeaveConfig list = smartAskForLeaveConfigService.getList();
-        Integer IfVerification=0;
-        if (ObjectUtils.isNotEmpty(list)&&ObjectUtils.isNotEmpty(list.getConfig())) {
+        Integer IfVerification = 0;
+        if (ObjectUtils.isNotEmpty(list) && ObjectUtils.isNotEmpty(list.getConfig())) {
             IfVerification = list.getConfig();
         }
+//        当前集合的数量
+        Integer resultCount = result.getResponseBody().getData().getResult().size();
         List<SmartAttendance> attendances = new ArrayList<>();
-        for (int i = 0; i < result.getResponseBody().getData().getTotalCount(); i++) {
+        for (int i = 0; i < resultCount; i++) {
             if (result.getResponseBody().getData().getResult().get(i).getLeaveStatus().intValue() == eXwApproveStatu.Passed.getValue()) {
                 SmartAttendance attendance = new SmartAttendance();
                 attendance.setXwuid(result.getResponseBody().getData().getResult().get(i).getUid());
@@ -161,10 +164,17 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
             }
         }
         //如果总条数大于第二条 那说明还有第二页
-        if (result.getResponseBody().getData().getTotalCount().intValue() > result.getResponseBody().getData().getTotalCount().intValue()) {
-            int totalCount = result.getResponseBody().getData().getTotalCount().intValue();
-            int pageSize = result.getResponseBody().getData().getPageSize().intValue();
-            int totalPage = (totalCount + pageSize - 1) / pageSize;
+//        总数
+        int totalCount = result.getResponseBody().getData().getTotalCount().intValue();
+//        当前分页数
+        Integer page = result.getResponseBody().getData().getPage();
+//        当前页面展示数
+        int pageSize = result.getResponseBody().getData().getPageSize().intValue();
+
+        Integer count = page * pageSize;
+
+        if (totalCount > count) {
+            Integer totalPage = totalCount / pageSize + 1;
             for (int i = 2; i <= totalPage; i++) {
                 PersonalLeaveListSchoolPeriodRecordsResult nextResult = getXwAttendance(TimeExchange.getDate(), TimeExchange.getDate(), i, findPageSize);
                 if (nextResult == null) {
@@ -174,7 +184,7 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
                 if (!nextResult.getResponseBody().getCode().equals("000000")) {
                     return CommonResult.fail(result.getResponseBody().getMessage());
                 }
-                for (int j = 0; j < result.getResponseBody().getData().getTotalCount(); j++) {
+                for (int j = 0; j < result.getResponseBody().getData().getResult().size(); j++) {
                     if (result.getResponseBody().getData().getResult().get(j).getLeaveStatus().intValue() == eXwApproveStatu.Passed.getValue()) {
                         SmartAttendance attendance = new SmartAttendance();
                         attendance.setXwuid(result.getResponseBody().getData().getResult().get(j).getUid());
@@ -297,7 +307,7 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
         jsonobject.put("schoolno", schoolno);
         jsonobject.put("timestamp", timestamp);
 
-        String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + student.getBsStudentNo() + "\",\"grade_no\":\"" + student.getBsGradeNo()  + "\",\"classtab_no\":\"" + student.getBsClassNo() + "\",\"leavebill_content\":\"" + reason + "\",\"leavebill_begindate\":\"" + request.getStartTime()  + "\",\"leavebill_enddate\":\"" + request.getEndTime() + "\",\"leavebill_remark\":\"" + "" + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
+        String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + student.getBsStudentNo() + "\",\"grade_no\":\"" + student.getBsGradeNo() + "\",\"classtab_no\":\"" + student.getBsClassNo() + "\",\"leavebill_content\":\"" + reason + "\",\"leavebill_begindate\":\"" + request.getStartTime() + "\",\"leavebill_enddate\":\"" + request.getEndTime() + "\",\"leavebill_remark\":\"" + "" + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
         String sign = CommonUtil.MD5(md5Str);
         //sign签名
         jsonobject.put("sign", sign);
@@ -327,7 +337,7 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
 
         LocalDateTime now = LocalDateTime.now();
         Date startTime = null;
-        Date endTime= null;
+        Date endTime = null;
         HistoricalAttendanceVo historicalAttendanceVo = new HistoricalAttendanceVo();
         if ("1".equals(dateTime)) {
 //        本学期
@@ -352,19 +362,19 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
             endTime = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
         }
 
-         List<Integer> statusList=smartAttendanceService.getGroup();
+        List<Integer> statusList = smartAttendanceService.getGroup();
 
         for (Integer status : statusList) {
-            List<SmartAttendance> smartAttendances =smartAttendanceService.getHistoricalAttendance(userId,status,startTime,endTime);
-            if (0==status) {
+            List<SmartAttendance> smartAttendances = smartAttendanceService.getHistoricalAttendance(userId, status, startTime, endTime);
+            if (0 == status) {
                 historicalAttendanceVo.setPunctuality(smartAttendances.size());
-            }else if (1==status){
+            } else if (1 == status) {
                 historicalAttendanceVo.setBeLate(smartAttendances.size());
-            }else if (3==status){
+            } else if (3 == status) {
                 historicalAttendanceVo.setNotClockingIn(smartAttendances.size());
-            }else if (6==status){
+            } else if (6 == status) {
                 historicalAttendanceVo.setAskForLeave(smartAttendances.size());
-            }else if (7==status){
+            } else if (7 == status) {
                 historicalAttendanceVo.setClockOut(smartAttendances.size());
             }
         }
@@ -374,8 +384,8 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
 
     @Override
     @DESRespondSecret(validated = true)
-    public CommonResult askForLeavePage(int currentPage, int pageCount, String name, String cardNo, String startTime, String endTime,String ifVerification,String classId) {
-        PageUtils<AskForLeaveVo> result=smartAttendanceService.askForLeavePage(currentPage,pageCount,name,cardNo,startTime,endTime,ifVerification,classId);
+    public CommonResult askForLeavePage(int currentPage, int pageCount, String name, String cardNo, String startTime, String endTime, String ifVerification, String classId) {
+        PageUtils<AskForLeaveVo> result = smartAttendanceService.askForLeavePage(currentPage, pageCount, name, cardNo, startTime, endTime, ifVerification, classId);
         return CommonResult.ok(result);
 
     }
@@ -383,7 +393,7 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
     @Override
     @DESRespondSecret(validated = true)
     public CommonResult queryPage(int currentPage, int pageCount, Integer gradeId, Integer classId, String status, String studentNo, String name, String startTime, String endTime) {
-        PageUtils<SmartAttendanceVo> result= smartAttendanceService.queryPage(currentPage,pageCount,gradeId,classId,status,studentNo,name,startTime,endTime);
+        PageUtils<SmartAttendanceVo> result = smartAttendanceService.queryPage(currentPage, pageCount, gradeId, classId, status, studentNo, name, startTime, endTime);
         return CommonResult.ok(result);
     }
 
@@ -421,15 +431,15 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
 
         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         //        默认前一天的
-        if (ObjectUtils.isEmpty(startTime)||ObjectUtils.isEmpty(endTime)) {
+        if (ObjectUtils.isEmpty(startTime) || ObjectUtils.isEmpty(endTime)) {
             LocalDateTime end = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
             LocalDateTime now = end.minusDays(1);
-            startTime=now.format(dateTimeFormatter);
-            endTime=end.format(dateTimeFormatter);
+            startTime = now.format(dateTimeFormatter);
+            endTime = end.format(dateTimeFormatter);
         }
 
         //获取学生考勤记录
-        List<SmartAttendanceVo> vos=smartAttendanceService.queryExpor(gradeId,classId,status,studentNo,name,startTime,endTime);
+        List<SmartAttendanceVo> vos = smartAttendanceService.queryExpor(gradeId, classId, status, studentNo, name, startTime, endTime);
 
         for (int i = 0; i < vos.size(); i++) {
             SmartAttendanceVo vo = vos.get(i);
@@ -445,17 +455,17 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
             dataRow.createCell(7).setCellValue(vo.getInitiateTime());
 //            状态
             Integer status1 = vo.getStatus();
-            String type="";
-            if (0==status1) {
-                type="准时";
-            }else if(1==status1) {
-                type="迟到";
-            }else if(3==status1) {
-                type="缺卡";
-            }else if(6==status1) {
-                type="请假";
-            }else if(7==status1) {
-                type="超时打卡";
+            String type = "";
+            if (0 == status1) {
+                type = "准时";
+            } else if (1 == status1) {
+                type = "迟到";
+            } else if (3 == status1) {
+                type = "缺卡";
+            } else if (6 == status1) {
+                type = "请假";
+            } else if (7 == status1) {
+                type = "超时打卡";
             }
             dataRow.createCell(8).setCellValue(type);
         }
@@ -467,7 +477,7 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
     @Override
     @DESRespondSecret(validated = true)
     public CommonResult askForLeaveScreenPage(int currentPage, int pageCount, String cardNo, String ifVerification) {
-        PageUtils<AskForLeaveScreenVo> result= smartAttendanceService.askForLeaveScreenPage(currentPage,pageCount,cardNo,ifVerification);
+        PageUtils<AskForLeaveScreenVo> result = smartAttendanceService.askForLeaveScreenPage(currentPage, pageCount, cardNo, ifVerification);
 
         return CommonResult.ok(result);
     }
@@ -477,7 +487,7 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
     public CommonResult studentHistoricalAttendance(String dateTime) {
         LocalDateTime now = LocalDateTime.now();
         Date startTime = null;
-        Date endTime= null;
+        Date endTime = null;
         HistoricalAttendanceVo historicalAttendanceVo = new HistoricalAttendanceVo();
         if ("1".equals(dateTime)) {
 //        本学期
@@ -502,19 +512,19 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
             endTime = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
         }
 
-        List<Integer> statusList=smartAttendanceService.getGroup();
+        List<Integer> statusList = smartAttendanceService.getGroup();
 
         for (Integer status : statusList) {
-           Integer count =smartAttendanceService.getStudentHistoricalAttendance(status,startTime,endTime);
-            if (0==status) {
+            Integer count = smartAttendanceService.getStudentHistoricalAttendance(status, startTime, endTime);
+            if (0 == status) {
                 historicalAttendanceVo.setPunctuality(count);
-            }else if (1==status){
+            } else if (1 == status) {
                 historicalAttendanceVo.setBeLate(count);
-            }else if (3==status){
+            } else if (3 == status) {
                 historicalAttendanceVo.setNotClockingIn(count);
-            }else if (6==status){
+            } else if (6 == status) {
                 historicalAttendanceVo.setAskForLeave(count);
-            }else if (7==status){
+            } else if (7 == status) {
                 historicalAttendanceVo.setClockOut(count);
             }
         }

+ 66 - 0
src/main/java/com/template/controller/Wx.java

@@ -0,0 +1,66 @@
+package com.template.controller;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.baomidou.mybatisplus.extension.api.R;
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/api/getWxArticle")
+public class Wx {
+    private static final String APP_ID = "wxa46ef222053a1047"; // 换成自己的公众号的AppID
+    private static final String APP_SECRET = "16f74a1265c314fd79fdf90670173467"; // 换成自己的公众号的AppSecret
+    private static final String API_URL = "https://api.weixin.qq.com/cgi-bin/";
+    private static final String ACCESS_TOKEN_URL = API_URL + "token?grant_type=client_credential&appid=" + APP_ID + "&secret=" + APP_SECRET; // 获取access_token
+    private static final String ARTICLELiST_URL = API_URL + "freepublish/batchget?access_token="; //获取成功发布文章的列表
+
+    /**
+     * 获取微信公众号发布的文章,用于互联网+作展示
+     */
+    @GetMapping("/get")
+    public R<JSONArray> getArticleList() {
+        // 获取ACCESS_TOKEN
+        String accessToken = getAccessToken();
+
+        // 获取文章列表信息
+        JSONArray articles = getArticles(accessToken);
+        JSONArray articleList = new JSONArray();
+
+        articles.forEach(item -> {
+            JSONObject wz = new JSONObject();
+            JSONObject article = (JSONObject) item;
+            JSONObject content = article.getJSONObject("content");
+            JSONObject newsItem = content.getJSONArray("news_item").getJSONObject(0);
+            wz.put("title", newsItem.getStr("title"));
+            wz.put("url", newsItem.getStr("url"));
+            wz.put("createTime", content.getStr("create_time"));
+            articleList.add(wz);
+        });
+        return R.ok(articleList);
+    }
+
+    private static String getAccessToken() {
+        String response = HttpUtil.get(ACCESS_TOKEN_URL);
+        JSONObject json = new JSONObject(response);
+        return json.getStr("access_token");
+    }
+
+    private static JSONArray getArticles(String accessToken) {
+        JSONObject params = new JSONObject();
+        params.put("offset", 0);
+        params.put("count", 20);
+        String response = HttpUtil.post(ARTICLELiST_URL + accessToken, params.toString());
+        JSONObject json = new JSONObject(response);
+
+        return json.getJSONArray("item");
+    }
+
+}