liu 2 лет назад
Родитель
Сommit
ea6218e792

+ 8 - 1
src/main/java/com/template/api/SmartAttendanceControllerAPI.java

@@ -9,6 +9,8 @@ import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * @Author: binguo
  * @Date: 2023/3/30 星期四 17:28
@@ -85,10 +87,15 @@ public interface SmartAttendanceControllerAPI {
     CommonResult askForLeavePage(@RequestParam int currentPage, @RequestParam int pageCount,String name,String cardNo,String startTime,String endTime,String ifVerification,String classId);
 
     @GetMapping(value = "/queryPage")
-    @ApiOperation(value = "学生考勤纪律", notes = "学生考勤纪律", httpMethod = "GET")
+    @ApiOperation(value = "学生考勤记录", notes = "学生考勤记录", httpMethod = "GET")
     CommonResult queryPage(@RequestParam int currentPage, @RequestParam int pageCount,Integer gradeId,Integer classId,String status,String studentNo ,String name,String startTime,String endTime);
 
     @GetMapping(value = "/verification")
     @ApiOperation(value = "核销", notes = "核销", httpMethod = "GET")
     CommonResult verification(@RequestParam String id);
+
+    @GetMapping(value = "/queryPageExport")
+    @ApiOperation(value = "学生考勤记录导出", notes = "学生考勤记录导出", httpMethod = "GET")
+    void queryPageExport(HttpServletResponse response, Integer gradeId, Integer classId, String status, String studentNo , String name, @RequestParam String startTime, @RequestParam String endTime);
+
 }

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

@@ -12,11 +12,9 @@ import com.template.annotation.DESRespondSecret;
 import com.template.api.SmartAttendanceControllerAPI;
 import com.template.common.utils.*;
 import com.template.config.ControlConfig;
+import com.template.config.ScheduleConfig;
 import com.template.config.SeewoConfig;
-import com.template.model.enumModel.eAttendanceStatu;
-import com.template.model.enumModel.eIdentityStatu;
-import com.template.model.enumModel.eIfVerification;
-import com.template.model.enumModel.eXwApproveStatu;
+import com.template.model.enumModel.*;
 import com.template.model.evaluate.student.SmartEvaluateStudent;
 import com.template.model.pojo.*;
 import com.template.model.request.askForLeaveRequest;
@@ -27,6 +25,10 @@ import com.template.model.seewo.PersonalLeaveListSchoolPeriodRecordsRequest;
 import com.template.model.seewo.PersonalLeaveListSchoolPeriodRecordsResult;
 import com.template.model.vo.*;
 import com.template.services.*;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+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.factory.annotation.Autowired;
@@ -39,10 +41,12 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -103,13 +107,19 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
         return null;
     }
 
+
+    @Resource
+    private ScheduleConfig scheduleConfig;
     /**
      * 每一小时获取请假信息
       */
     @Async
     @Scheduled(cron = "0 0 0/1 * * ? ")
     public void get(){
-        queryLeaveRecords();
+        if(scheduleConfig.getIsOpen().equals("1")){
+            queryLeaveRecords();
+        }
+
     }
 
     @Override
@@ -392,6 +402,68 @@ public class SmartAttendanceController implements SmartAttendanceControllerAPI {
         return CommonResult.fail();
     }
 
+    @Override
+    public void queryPageExport(HttpServletResponse response, Integer gradeId, Integer classId, String status, String studentNo, String name, String startTime, String endTime) {
+
+        //导出
+        Workbook workbook = new XSSFWorkbook();
+        Sheet sheet = workbook.createSheet("学生考勤记录");
+        Row headerRow = sheet.createRow(0);
+        headerRow.createCell(0).setCellValue("序号");
+        headerRow.createCell(1).setCellValue("姓名");
+        headerRow.createCell(2).setCellValue("年级");
+        headerRow.createCell(3).setCellValue("班级");
+        headerRow.createCell(4).setCellValue("学号");
+        headerRow.createCell(5).setCellValue("头像");
+        headerRow.createCell(6).setCellValue("打卡时间");
+        headerRow.createCell(7).setCellValue("请假时间");
+        headerRow.createCell(8).setCellValue("考勤状态");
+
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        //        默认前一天的
+        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);
+        }
+
+        //获取学生考勤记录
+        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);
+
+            Row dataRow = sheet.createRow(i + 1);
+            dataRow.createCell(0).setCellValue(i + 1);
+            dataRow.createCell(1).setCellValue(vo.getName());
+            dataRow.createCell(2).setCellValue(vo.getGradeName());
+            dataRow.createCell(3).setCellValue(vo.getClassName());
+            dataRow.createCell(4).setCellValue(vo.getCardNo());
+            dataRow.createCell(5).setCellValue(vo.getHeadImage());
+            dataRow.createCell(6).setCellValue(vo.getAttendTime());
+            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="超时打卡";
+            }
+            dataRow.createCell(8).setCellValue(type);
+        }
+
+        // 将工作簿写入文件
+        ExcelUtils.excelDownload(workbook, "学生考勤.xlsx", response);
+    }
+
     public PersonalLeaveListSchoolPeriodRecordsResult getXwAttendance(String startDate, String endDate, Integer currentPage, Integer pageSize) {
         //初始化客户端
         SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));

+ 6 - 2
src/main/java/com/template/mapper/SmartAttendanceMapper.java

@@ -24,7 +24,11 @@ public interface SmartAttendanceMapper extends BaseMapper<SmartAttendance> {
 
     List<Integer> getGroup();
 
-    IPage<AskForLeaveVo> askForLeavePage(Page<AskForLeaveVo> page, @Param("name") String name,@Param("cardNo") String cardNo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("ifVerification")String ifVerification,@Param("classId")String classId);
+    IPage<AskForLeaveVo> askForLeavePage(Page<AskForLeaveVo> page, @Param("name") String name, @Param("cardNo") String cardNo, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("ifVerification") String ifVerification, @Param("classId") String classId);
+
+    IPage<SmartAttendanceVo> queryPage(Page<SmartAttendanceVo> page, @Param("gradeId") Integer gradeId, @Param("classId") Integer classId, @Param("status") String status, @Param("studentNo") String studentNo, @Param("name") String name, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    List<SmartAttendanceVo> queryExpor(@Param("gradeId") Integer gradeId, @Param("classId") Integer classId, @Param("status") String status, @Param("studentNo") String studentNo, @Param("name") String name, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
-    IPage<SmartAttendanceVo> queryPage(Page<SmartAttendanceVo> page,@Param("gradeId") Integer gradeId,@Param("classId") Integer classId,@Param("status") String status,@Param("studentNo") String studentNo,@Param("name") String name,@Param("startTime") String startTime,@Param("endTime") String endTime);
 }
+

+ 2 - 2
src/main/java/com/template/model/vo/SmartAttendanceVo.java

@@ -25,10 +25,10 @@ public class SmartAttendanceVo {
     private String headImage;
 
     @ApiModelProperty(value = "签到时间")
-    private Date attendTime;
+    private String attendTime;
 
     @ApiModelProperty(value = "希沃发起时间")
-    private Date initiateTime;
+    private String initiateTime;
 
     @ApiModelProperty(value = "考勤状态 准时:0 迟到:1 缺卡:3 请假:6 超时打卡:7")
     private Integer status;

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

@@ -38,4 +38,6 @@ public interface SmartAttendanceService extends IService<SmartAttendance> {
     PageUtils<SmartAttendanceVo> queryPage(int currentPage, int pageCount, Integer gradeId, Integer classId, String status, String studentNo, String name, String startTime, String endTime);
 
     List<SmartAttendance> duplicatesList(Date startTime, Date endTime, Date initiateTime);
+
+    List<SmartAttendanceVo> queryExpor(Integer gradeId, Integer classId, String status, String studentNo, String name, String startTime, String endTime);
 }

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

@@ -125,4 +125,10 @@ public class SmartAttendanceServiceImpl extends ServiceImpl<SmartAttendanceMappe
 
         return list;
     }
+
+    @Override
+    public List<SmartAttendanceVo> queryExpor(Integer gradeId, Integer classId, String status, String studentNo, String name, String startTime, String endTime) {
+        List<SmartAttendanceVo> vos =smartAttendanceMapper.queryExpor(gradeId,classId,status,studentNo,name,startTime,endTime);
+        return vos;
+    }
 }

+ 40 - 2
src/main/resources/mapper/template/SmartAttendanceMapper.xml

@@ -28,7 +28,7 @@
         sa.`status` = 6
         AND sa.deleted = 0
         <if test="name != null and name != ''">
-            and sa.xw_user_name = #{name}
+            and sa.xw_user_name like '%' #{name} '%'
         </if>
         <if test="cardNo != null and cardNo != ''">
             and su.card_no = #{cardNo}
@@ -75,7 +75,45 @@
             and su.card_no = #{studentNo}
         </if>
         <if test="name != null and name != ''">
-            and sa.xw_user_name = #{name}
+            and sa.xw_user_name like '%' #{name} '%'
+        </if>
+        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+            and sa.attend_time &gt;= #{startTime} and sa.attend_time &lt;= #{endTime}
+        </if>
+        ORDER BY sa.create_time desc
+    </select>
+
+    <select id="queryExpor" resultType="com.template.model.vo.SmartAttendanceVo">
+        SELECT
+        sa.id,
+        sa.xw_user_name as name,
+        sc.`name` as className,
+        sg.`name` as gradeName,
+        su.card_no as cardNo,
+        su.head_image as headImage,
+        sa.attend_time as attendTime,
+        sa.initiate_time as initiateTime,
+        sa.`status`
+        FROM
+        `smart_attendance` sa
+        LEFT JOIN smart_class sc on sa.class_id=sc.id
+        LEFT JOIN smart_grade sg on sc.grade_id=sg.id
+        LEFT JOIN smart_user su on sa.user_id=su.id
+        where sa.deleted = 0
+        <if test="gradeId != null and gradeId != ''">
+            and sc.grade_id=#{gradeId}
+        </if>
+        <if test="classId != null and classId != ''">
+            and sa.class_id = #{classId}
+        </if>
+        <if test="status != null and status != ''">
+            and sa.`status` = #{status}
+        </if>
+        <if test="studentNo != null and studentNo != ''">
+            and su.card_no = #{studentNo}
+        </if>
+        <if test="name != null and name != ''">
+            and sa.xw_user_name like '%' #{name} '%'
         </if>
         <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
             and sa.attend_time &gt;= #{startTime} and sa.attend_time &lt;= #{endTime}