Jelajahi Sumber

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

夏文涛 2 tahun lalu
induk
melakukan
d755adfb81

+ 10 - 0
src/main/java/com/template/api/SmartAttendanceControllerAPI.java

@@ -112,4 +112,14 @@ public interface SmartAttendanceControllerAPI {
     @ApiOperation(value = "学生考勤统计", notes = "学生考勤统计", httpMethod = "GET")
     CommonResult studentHistoricalAttendance(@RequestParam String dateTime);
 
+
+    /**
+     * 领导驾驶舱——考勤管理——班级考勤数据
+     * @param dateTime
+     * @return
+     */
+    @GetMapping(value = "/classHistoricalAttendance")
+    @ApiOperation(value = "班级考勤统计", notes = "班级考勤统计", httpMethod = "GET")
+    CommonResult classHistoricalAttendance(@RequestParam String dateTime,@RequestParam int currentPage, @RequestParam int pageCount,String className);
+
 }

+ 77 - 0
src/main/java/com/template/controller/SmartAttendanceController.java

@@ -3,7 +3,11 @@ package com.template.controller;
 
 import com.alibaba.druid.sql.visitor.functions.If;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.seewo.open.sdk.DefaultSeewoClient;
 import com.seewo.open.sdk.SeewoClient;
@@ -31,6 +35,7 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
@@ -83,6 +88,9 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
     @Autowired
     SmartAskForLeaveConfigService smartAskForLeaveConfigService;
 
+    @Autowired
+    SmartClassService smartClassService;
+
     @Override
     @DESRespondSecret(validated = true)
     public CommonResult insertSmartAttendance(SmartAttendance smartApply, BindingResult bindingResult) {
@@ -532,6 +540,75 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
         return CommonResult.ok(historicalAttendanceVo);
     }
 
+    @Override
+    @DESRespondSecret(validated = true)
+    public CommonResult classHistoricalAttendance(String dateTime, int currentPage, int pageCount, String className) {
+
+        LambdaQueryWrapper<SmartClass> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ObjectUtils.isNotEmpty(className), SmartClass::getName, className);
+        IPage<SmartClass> page = smartClassService.page(new Page<>(currentPage, pageCount), wrapper);
+
+
+        LocalDateTime now = LocalDateTime.now();
+        Date startTime = null;
+        Date endTime = null;
+        if ("1".equals(dateTime)) {
+//        本学期
+            SmartSemester smartSemester = smartSemesterService.getSemester(now);
+            if (ObjectUtils.isEmpty(smartSemester)) {
+                return CommonResult.ok("不存在该学期");
+            }
+            startTime = smartSemester.getStartTime();
+            endTime = smartSemester.getEndTime();
+
+
+        } else if ("2".equals(dateTime)) {
+//        近1个月
+            LocalDateTime localDateTime = now.minusMonths(1);
+            startTime = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+            endTime = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
+
+        } else if ("3".equals(dateTime)) {
+//        近一周
+            LocalDateTime localDateTime = now.minusDays(7);
+            startTime = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+            endTime = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
+        }
+
+
+        List<SmartClass> records = page.getRecords();
+        ArrayList<ClassHistoricalAttendanceVo> vos = new ArrayList<>();
+        for (SmartClass record : records) {
+            ClassHistoricalAttendanceVo historicalAttendanceVo = new ClassHistoricalAttendanceVo();
+            historicalAttendanceVo.setClassName(record.getName());
+            List<ClasAttendanceVo> list = smartAttendanceService.getClassHistoricalAttendance(startTime, endTime, record.getId());
+            for (ClasAttendanceVo clasAttendanceVo : list) {
+                Integer status = clasAttendanceVo.getStatus();
+                Integer count = clasAttendanceVo.getCount();
+
+                if (0 == status) {
+                    historicalAttendanceVo.setPunctuality(count);
+                } else if (1 == status) {
+                    historicalAttendanceVo.setBeLate(count);
+                } else if (3 == status) {
+                    historicalAttendanceVo.setNotClockingIn(count);
+                } else if (7 == status) {
+                    historicalAttendanceVo.setClockOut(count);
+                }
+            }
+//        请假的单独弄
+            Integer count = smartAttendanceService.getClassAckHistoricalAttendance(6, startTime, endTime,record.getId());
+            historicalAttendanceVo.setAskForLeave(count);
+            vos.add(historicalAttendanceVo);
+        }
+
+        Page<ClassHistoricalAttendanceVo> objectPage = new Page<>();
+        BeanUtils.copyProperties(page, objectPage);
+        objectPage.setRecords(vos);
+
+        return CommonResult.ok(objectPage);
+    }
+
     public PersonalLeaveListSchoolPeriodRecordsResult getXwAttendance(String startDate, String endDate, Integer currentPage, Integer pageSize) {
         //初始化客户端
         SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));

+ 3 - 0
src/main/java/com/template/mapper/SmartAttendanceMapper.java

@@ -6,10 +6,12 @@ import com.template.model.pojo.SmartAttendance;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.template.model.vo.AskForLeaveScreenVo;
 import com.template.model.vo.AskForLeaveVo;
+import com.template.model.vo.ClasAttendanceVo;
 import com.template.model.vo.SmartAttendanceVo;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -33,5 +35,6 @@ public interface SmartAttendanceMapper extends BaseMapper<SmartAttendance> {
 
     IPage<AskForLeaveScreenVo> askForLeaveScreenPage(Page<AskForLeaveScreenVo> page, @Param("cardNo") String cardNo, @Param("ifVerification") String ifVerification);
 
+    List<ClasAttendanceVo> getClassHistoricalAttendance(@Param("startTime") Date startTime,@Param("endTime") Date endTime,@Param("id") Integer id);
 }
 

+ 9 - 0
src/main/java/com/template/model/vo/ClasAttendanceVo.java

@@ -0,0 +1,9 @@
+package com.template.model.vo;
+
+import lombok.Data;
+
+@Data
+public class ClasAttendanceVo {
+    private Integer count;
+    private Integer status;
+}

+ 19 - 0
src/main/java/com/template/model/vo/ClassHistoricalAttendanceVo.java

@@ -0,0 +1,19 @@
+package com.template.model.vo;
+
+import lombok.Data;
+
+@Data
+public class ClassHistoricalAttendanceVo {
+    //  准时
+    private Integer punctuality;
+    //    请假
+    private Integer askForLeave;
+    //    迟到
+    private Integer beLate;
+    //   超时打卡
+    private Integer clockOut;
+    //    未打卡
+    private Integer notClockingIn;
+//    班级
+    private String className;
+}

+ 5 - 0
src/main/java/com/template/services/SmartAttendanceService.java

@@ -6,6 +6,7 @@ import com.template.model.pojo.SmartVisitor;
 import com.template.model.result.PageUtils;
 import com.template.model.vo.AskForLeaveScreenVo;
 import com.template.model.vo.AskForLeaveVo;
+import com.template.model.vo.ClasAttendanceVo;
 import com.template.model.vo.SmartAttendanceVo;
 
 import java.util.Date;
@@ -45,4 +46,8 @@ public interface SmartAttendanceService extends IService<SmartAttendance> {
     PageUtils<AskForLeaveScreenVo> askForLeaveScreenPage(int currentPage, int pageCount, String cardNo, String ifVerification);
 
     Integer getStudentHistoricalAttendance(Integer status, Date startTime, Date endTime);
+
+    List<ClasAttendanceVo> getClassHistoricalAttendance(Date startTime, Date endTime, Integer id);
+
+    Integer getClassAckHistoricalAttendance(int i, Date startTime, Date endTime, Integer id);
 }

+ 16 - 0
src/main/java/com/template/services/impl/SmartAttendanceServiceImpl.java

@@ -11,6 +11,7 @@ import com.template.model.pojo.SmartVisitor;
 import com.template.model.result.PageUtils;
 import com.template.model.vo.AskForLeaveScreenVo;
 import com.template.model.vo.AskForLeaveVo;
+import com.template.model.vo.ClasAttendanceVo;
 import com.template.model.vo.SmartAttendanceVo;
 import com.template.services.SmartAttendanceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -156,4 +157,19 @@ public class SmartAttendanceServiceImpl extends ServiceImpl<SmartAttendanceMappe
         Integer count = this.count(queryWrapper);
         return count;
     }
+
+    @Override
+    public  List<ClasAttendanceVo> getClassHistoricalAttendance(Date startTime, Date endTime, Integer id) {
+        return smartAttendanceMapper.getClassHistoricalAttendance(startTime,endTime,id);
+    }
+
+    @Override
+    public Integer getClassAckHistoricalAttendance(int i, Date startTime, Date endTime, Integer id) {
+        LambdaQueryWrapper<SmartAttendance> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.between(SmartAttendance::getInitiateTime,startTime,endTime);
+        queryWrapper.eq(SmartAttendance::getStatus,i);
+        queryWrapper.eq(SmartAttendance::getClassId,id);
+        Integer count = this.count(queryWrapper);
+        return count;
+    }
 }

+ 27 - 14
src/main/resources/mapper/template/SmartAttendanceMapper.xml

@@ -122,22 +122,22 @@
     </select>
     <select id="askForLeaveScreenPage" resultType="com.template.model.vo.AskForLeaveScreenVo">
         SELECT
-            sa.id,
-            su.head_image as headImage,
-            su.`name` as name,
-            sc.`name` as className,
-            su.card_no as cardNo,
-            sa.start_time as startTime,
-            sa.end_time as endTime,
-            sa.reason,
-            sa.if_verification as ifVerification
+        sa.id,
+        su.head_image as headImage,
+        su.`name` as name,
+        sc.`name` as className,
+        su.card_no as cardNo,
+        sa.start_time as startTime,
+        sa.end_time as endTime,
+        sa.reason,
+        sa.if_verification as ifVerification
         FROM
-            `smart_attendance` sa
-                LEFT JOIN smart_user su ON sa.user_id = su.id
-                LEFT JOIN smart_class sc ON sa.class_id = sc.id
+        `smart_attendance` sa
+        LEFT JOIN smart_user su ON sa.user_id = su.id
+        LEFT JOIN smart_class sc ON sa.class_id = sc.id
         WHERE
-            sa.deleted = 0
-          AND sa.`status` =6
+        sa.deleted = 0
+        AND sa.`status` =6
         <if test="cardNo != null and cardNo != ''">
             and su.card_no like '%' #{cardNo} '%'
         </if>
@@ -146,4 +146,17 @@
         </if>
         ORDER BY sa.initiate_time desc
     </select>
+    <select id="getClassHistoricalAttendance" resultType="com.template.model.vo.ClasAttendanceVo">
+        SELECT COUNT(*) AS count,
+	        `status`
+        FROM
+            `smart_attendance`
+        WHERE
+            deleted=0
+          AND class_id = #{id}
+          AND attend_time >= #{startTime}
+          AND #{endTime} >= attend_time
+        GROUP BY
+            `status`
+    </select>
 </mapper>