Browse Source

门禁通行记录导出

liu 2 năm trước cách đây
mục cha
commit
a050bcc707

+ 8 - 0
src/main/java/com/template/api/SmartAccessControllerAPI.java

@@ -6,10 +6,18 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import javax.servlet.http.HttpServletResponse;
+
 @RequestMapping("/api/smartAccess")
 public interface SmartAccessControllerAPI {
 
     @GetMapping("/getPage")
     @ApiOperation(value = "门禁通行记录", notes = "门禁通行记录", httpMethod = "GET")
     CommonResult getPage(@RequestParam Integer currentPage, @RequestParam Integer pageCount,String keyWord,Integer gradeId,Integer classId,Integer departmentId,Integer openType,Integer resultStatus,String startTime,String endTime);
+
+    @GetMapping("/getPageExport")
+    @ApiOperation(value = "门禁通行记录导出", notes = "门禁通行记录导出", httpMethod = "GET")
+    void getPageExport(HttpServletResponse response, String keyWord, Integer gradeId, Integer classId, Integer departmentId, Integer openType, Integer resultStatus, String startTime, String endTime);
+
+
 }

+ 96 - 0
src/main/java/com/template/controller/SmartAccessController.java

@@ -1,18 +1,30 @@
 package com.template.controller;
 
 
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.template.annotation.DESRespondSecret;
 import com.template.api.SmartAccessControllerAPI;
+import com.template.common.utils.ExcelUtils;
 import com.template.model.pojo.SmartAccess;
 import com.template.model.result.CommonResult;
 import com.template.model.result.PageUtils;
 import com.template.model.vo.SmartAccessVo;
+import com.template.model.vo.SmartAttendanceVo;
 import com.template.services.SmartAccessService;
+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.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
 /**
  * <p>
  *  前端控制器
@@ -34,5 +46,89 @@ public class SmartAccessController implements SmartAccessControllerAPI {
         PageUtils<SmartAccessVo> pageUtils=smartAccessService.getPage(currentPage,pageCount,keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
         return CommonResult.ok(pageUtils);
     }
+
+    @Override
+    public void getPageExport(HttpServletResponse response, String keyWord, Integer gradeId, Integer classId, Integer departmentId, Integer openType, Integer resultStatus, 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("识别分组");
+        headerRow.createCell(9).setCellValue("记录时间");
+        headerRow.createCell(10).setCellValue("出口类型");
+        headerRow.createCell(11).setCellValue("通行状态");
+
+
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        //        默认前一天的
+        if (ObjectUtils.isEmpty(startTime)||ObjectUtils.isEmpty(endTime)) {
+            LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
+            LocalDateTime end = now.plusDays(1);
+            startTime=now.format(dateTimeFormatter);
+            endTime=end.format(dateTimeFormatter);
+        }
+
+        List<SmartAccessVo> vos=smartAccessService.getPageExport(keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
+
+        for (int i = 0; i < vos.size(); i++) {
+            SmartAccessVo vo = vos.get(i);
+            Row dataRow = sheet.createRow(i + 1);
+            dataRow.createCell(0).setCellValue(i + 1);
+            dataRow.createCell(1).setCellValue(vo.getSn());
+            dataRow.createCell(2).setCellValue(vo.getType());
+            dataRow.createCell(3).setCellValue(vo.getDepartmentName());
+            dataRow.createCell(4).setCellValue(vo.getClassName());
+            dataRow.createCell(5).setCellValue(vo.getName());
+            dataRow.createCell(6).setCellValue(vo.getCardNo());
+            dataRow.createCell(7).setCellValue(vo.getImage());
+
+            Integer openType1 = vo.getOpenType();
+            String type="";
+            if (0==openType1) {
+                type="白名单比对";
+            }else if (1==openType1){
+                type="人证比对";
+            }else if (2==openType1){
+                type="IC卡比对";
+            }else if (5==openType1){
+                type="职工二维码比对";
+            }
+            dataRow.createCell(8).setCellValue(type);
+            dataRow.createCell(9).setCellValue(vo.getDateTime());
+            Integer access = vo.getAccess();
+            String accessSting="";
+            if (1==access) {
+                accessSting="入口";
+            }else if (0==openType1){
+                accessSting="出口";
+            }
+            dataRow.createCell(10).setCellValue(accessSting);
+
+            Integer resultStatus1 = vo.getResultStatus();
+            String result="";
+            if (1==resultStatus1) {
+                result="正常通行";
+            }else if (0==resultStatus1){
+                result="禁止通行";
+            }
+
+            dataRow.createCell(11).setCellValue(result);
+
+        }
+
+        // 将工作簿写入文件
+        ExcelUtils.excelDownload(workbook, "通行记录.xlsx", response);
+
+
+    }
 }
 

+ 6 - 1
src/main/java/com/template/mapper/SmartAccessMapper.java

@@ -9,6 +9,8 @@ import com.template.model.vo.VisitorPageVo;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -20,5 +22,8 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface SmartAccessMapper extends BaseMapper<SmartAccess> {
 
-    IPage<SmartAccessVo> getPage(Page<SmartAccessVo> page,@Param("keyWord") String keyWord,@Param("gradeId") Integer gradeId, @Param("classId") Integer classId,@Param("departmentId") Integer departmentId,@Param("openType") Integer openType,@Param("resultStatus") Integer resultStatus,@Param("startTime")String startTime,@Param("endTime")String endTime);
+    IPage<SmartAccessVo> getPage(Page<SmartAccessVo> page, @Param("keyWord") String keyWord, @Param("gradeId") Integer gradeId, @Param("classId") Integer classId, @Param("departmentId") Integer departmentId, @Param("openType") Integer openType, @Param("resultStatus") Integer resultStatus, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    List<SmartAccessVo> getPageExport(@Param("keyWord") String keyWord, @Param("gradeId") Integer gradeId, @Param("classId") Integer classId, @Param("departmentId") Integer departmentId, @Param("openType") Integer openType, @Param("resultStatus") Integer resultStatus, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
 }

+ 3 - 0
src/main/java/com/template/services/SmartAccessService.java

@@ -21,4 +21,7 @@ public interface SmartAccessService extends IService<SmartAccess> {
     List<SmartAccess> track(String stateTime, String endTime, Integer id);
 
     PageUtils<SmartAccessVo> getPage(Integer currentPage, Integer pageCount,String keyWord,Integer gradeId, Integer classId, Integer departmentId, Integer openType, Integer resultStatus,String startTime,String endTime);
+
+    List<SmartAccessVo> getPageExport(String keyWord, Integer gradeId, Integer classId, Integer departmentId, Integer openType, Integer resultStatus, String startTime, String endTime);
+
 }

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

@@ -48,4 +48,10 @@ public class SmartAccessServiceImpl extends ServiceImpl<SmartAccessMapper, Smart
         IPage<SmartAccessVo> datas = smartAccessMapper.getPage(page,keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
         return new PageUtils(datas);
     }
+
+    @Override
+    public List<SmartAccessVo> getPageExport(String keyWord, Integer gradeId, Integer classId, Integer departmentId, Integer openType, Integer resultStatus, String startTime, String endTime) {
+        List<SmartAccessVo> vos = smartAccessMapper.getPageExport(keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
+        return vos;
+    }
 }

+ 45 - 0
src/main/resources/mapper/template/SmartAccessMapper.xml

@@ -47,4 +47,49 @@
 
         ORDER BY sa.date_time DESC
     </select>
+
+    <select id="getPageExport" resultType="com.template.model.vo.SmartAccessVo">
+        SELECT
+        sa.id,
+        sa.name,
+        sa.sn,
+        sa.type,
+        sd.`name` as departmentName,
+        sc.`name` as className,
+        su.card_no as cardNo,
+        sa.image,
+        sa.open_type as openType,
+        sa.date_time as dateTime,
+        sa.in_out as access,
+        sa.result_status as resultStatus
+        FROM
+        `smart_access` sa
+        LEFT JOIN smart_user su on sa.user_id=su.id
+        LEFT JOIN smart_department sd on su.department_id=sd.id
+        LEFT JOIN smart_class sc on su.school_class=sc.id
+        LEFT JOIN smart_grade sg on sc.grade_id=sg.id
+        WHERE sa.deleted = 0
+        <if test="keyWord != null and keyWord != ''">
+            and (sa.name like '%' #{keyWord} '%' or su.card_no like '%' #{keyWord} '%')
+        </if>
+        <if test="gradeId != null and gradeId != ''">
+            and sc.grade_id= #{gradeId}
+        </if>
+        <if test="classId != null and classId != ''">
+            and su.school_class= #{classId}
+        </if>
+        <if test="departmentId != null and departmentId != ''">
+            and su.department_id= #{departmentId}
+        </if>
+        <if test="openType != null and openType != ''">
+            and sa.open_type= #{openType}
+        </if>
+        <if test="resultStatus != null and  resultStatus != ''">
+            and sa.result_status= #{resultStatus}
+        </if>
+        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+            and sa.date_time &gt;= #{startTime} and sa.date_time &lt;= #{endTime}
+        </if>
+        ORDER BY sa.date_time DESC
+    </select>
 </mapper>