进出日志后台查询;小程序端进门;导出表格时日期转换
This commit is contained in:
		@@ -0,0 +1,185 @@
 | 
			
		||||
package com.cxyxiaomo.epp.access.controller;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.fastjson2.JSONArray;
 | 
			
		||||
import com.alibaba.fastjson2.JSONObject;
 | 
			
		||||
import com.cxyxiaomo.epp.PageTable.enums.AddType;
 | 
			
		||||
import com.cxyxiaomo.epp.PageTable.enums.EditType;
 | 
			
		||||
import com.cxyxiaomo.epp.PageTable.enums.FieldType;
 | 
			
		||||
import com.cxyxiaomo.epp.PageTable.enums.SearchType;
 | 
			
		||||
import com.cxyxiaomo.epp.PageTable.query.PageQuery;
 | 
			
		||||
import com.cxyxiaomo.epp.PageTable.utils.FieldBuilder;
 | 
			
		||||
import com.cxyxiaomo.epp.PageTable.utils.FieldMapperBuilder;
 | 
			
		||||
import com.cxyxiaomo.epp.access.rpc.UserServiceFeign;
 | 
			
		||||
import com.cxyxiaomo.epp.access.service.AccessLogService;
 | 
			
		||||
import com.cxyxiaomo.epp.access.service.GateService;
 | 
			
		||||
import com.cxyxiaomo.epp.common.pojo.AccessLog;
 | 
			
		||||
import com.cxyxiaomo.epp.common.pojo.Gate;
 | 
			
		||||
import com.cxyxiaomo.epp.common.pojo.User;
 | 
			
		||||
import com.cxyxiaomo.epp.common.query.AccessLogQuery;
 | 
			
		||||
import com.cxyxiaomo.epp.common.response.Res;
 | 
			
		||||
import com.cxyxiaomo.epp.common.vo.AccessLogVO;
 | 
			
		||||
import com.cxyxiaomo.epp.common.vo.GateVO;
 | 
			
		||||
import com.github.pagehelper.PageHelper;
 | 
			
		||||
import com.github.pagehelper.PageInfo;
 | 
			
		||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.ResponseBody;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/access/access-log")
 | 
			
		||||
public class AccessLogController {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    GateService gateService;
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    UserServiceFeign userService;
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    AccessLogService accessLogService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 进入进出记录(小程序端)
 | 
			
		||||
     *
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping("/miniprogram/enterGate")
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    public Res enterAccessLog(Integer userId, String gateId, String type/*'IN','OUT'*/) throws Exception {
 | 
			
		||||
        if (Objects.isNull(type) || !("IN".equals(type) || "OUT".equals(type))) {
 | 
			
		||||
            return Res.error("参数错误");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Gate gate = gateService.getGateById(Long.valueOf(gateId));
 | 
			
		||||
        User user = userService.getUserById(userId);
 | 
			
		||||
        if (user == null || gate == null) {
 | 
			
		||||
            return Res.error("参数错误");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        AccessLog accessLog = new AccessLog();
 | 
			
		||||
        accessLog.setId(null);
 | 
			
		||||
        accessLog.setType(type);
 | 
			
		||||
        accessLog.setTime(new Date());
 | 
			
		||||
        accessLog.setUserId(user.getId());
 | 
			
		||||
        accessLog.setUserRealName(user.getRealname());
 | 
			
		||||
        accessLog.setGateId(gate.getId());
 | 
			
		||||
 | 
			
		||||
        boolean b = accessLogService.addAccessLog(accessLog);
 | 
			
		||||
        return Res.success(b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取进出记录列表
 | 
			
		||||
     *
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping("/manage/getAccessLogList")
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    public Res getAccessLogList(PageQuery pageQuery, AccessLogQuery accessLogQuery) {
 | 
			
		||||
        // 查询分页数据
 | 
			
		||||
        PageHelper.startPage(pageQuery.getPageIndex(), pageQuery.getPageSize());
 | 
			
		||||
        List<AccessLog> accessLogList = accessLogService.getAccessLogList(accessLogQuery);
 | 
			
		||||
        PageInfo<AccessLog> accessLogPageInfo = new PageInfo<>(accessLogList);
 | 
			
		||||
        List<AccessLog> list = accessLogPageInfo.getList();
 | 
			
		||||
        List<AccessLogVO> voList = AccessLogVO.convertFrom(list);
 | 
			
		||||
 | 
			
		||||
        // id列 字段名(区分大小写;以VO中的变量名为准)
 | 
			
		||||
        // 新增、修改弹窗时,使用该列作为主键列进行操作
 | 
			
		||||
        String idFieldName = "id";
 | 
			
		||||
 | 
			
		||||
        // 当前管理页面
 | 
			
		||||
        String pageName = "进出记录管理";
 | 
			
		||||
 | 
			
		||||
        // 指定前端表格显示列
 | 
			
		||||
        JSONArray columns = FieldBuilder.create()
 | 
			
		||||
                .add("timestamp", "timestamp", "打卡时间", "",
 | 
			
		||||
                        FieldType.DATETIME, SearchType.DATETIME_INTERVAL, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
 | 
			
		||||
                        FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
 | 
			
		||||
                        null, null, null, null
 | 
			
		||||
                )
 | 
			
		||||
                .add("userId", "userId", "用户id", "",
 | 
			
		||||
                        FieldType.TEXT, SearchType.INPUT, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
 | 
			
		||||
                        FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
 | 
			
		||||
                        null, null, null, null
 | 
			
		||||
                )
 | 
			
		||||
                .add("userRealName", "userRealName", "用户真实姓名", "",
 | 
			
		||||
                        FieldType.TEXT, SearchType.INPUT, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
 | 
			
		||||
                        FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
 | 
			
		||||
                        null, null, null, null
 | 
			
		||||
                )
 | 
			
		||||
                .add("gateId", "gateId", "大门id", "",
 | 
			
		||||
                        FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
 | 
			
		||||
                        FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
 | 
			
		||||
                        null, null, null, null
 | 
			
		||||
                )
 | 
			
		||||
                .add("gateId", "gateName", "大门名称", "",
 | 
			
		||||
                        FieldType.TEXT, SearchType.SELECT, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
 | 
			
		||||
                        "大门",
 | 
			
		||||
                        null, null, null, null
 | 
			
		||||
                )
 | 
			
		||||
                // .add("type", "typeStatus", "类型", true,
 | 
			
		||||
                //         FieldType.TEXT, SearchType.SELECT, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
 | 
			
		||||
                //         FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
 | 
			
		||||
                //         "状态", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
 | 
			
		||||
                //         FieldRuleListBuilder.create(),
 | 
			
		||||
                //         "DPD @pick(['true', 'false'])"
 | 
			
		||||
                // )
 | 
			
		||||
                .build();
 | 
			
		||||
 | 
			
		||||
        // 指定需要翻译的字段
 | 
			
		||||
        List<Gate> gateList = gateService.getGateList(new GateVO());
 | 
			
		||||
        HashMap gateMap = new HashMap();
 | 
			
		||||
        for (Gate gate : gateList) {
 | 
			
		||||
            gateMap.put(gate.getId(), gate.getName());
 | 
			
		||||
        }
 | 
			
		||||
        HashMap<Object, Object> stateMap = new HashMap<>(2);
 | 
			
		||||
        stateMap.put(true, "进入社区");
 | 
			
		||||
        stateMap.put(false, "离开社区");
 | 
			
		||||
        // build
 | 
			
		||||
        JSONArray fieldMapper = FieldMapperBuilder.create()
 | 
			
		||||
                .add("gateId", "gateName", gateMap)
 | 
			
		||||
                .add("type", "typeStatus", stateMap)
 | 
			
		||||
                .build();
 | 
			
		||||
 | 
			
		||||
        // 拼装返回结果
 | 
			
		||||
        JSONObject map = new JSONObject(6);
 | 
			
		||||
        map.put("total", accessLogPageInfo.getTotal());
 | 
			
		||||
        map.put("list", voList);
 | 
			
		||||
        map.put("columns", columns);
 | 
			
		||||
        map.put("fieldMapper", fieldMapper);
 | 
			
		||||
        map.put("idFieldName", idFieldName);
 | 
			
		||||
        map.put("pageName", pageName);
 | 
			
		||||
 | 
			
		||||
        // 返回结果
 | 
			
		||||
        return Res.success(map);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 导出进出记录列表
 | 
			
		||||
     *
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping("/manage/exportAccessLogList")
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    public Res exportAccessLogList(AccessLogQuery accessLogQuery) {
 | 
			
		||||
        List<AccessLog> accessLogList = accessLogService.getAccessLogList(accessLogQuery);
 | 
			
		||||
        List<AccessLogVO> accessLogVOList = AccessLogVO.convertFrom(accessLogList);
 | 
			
		||||
 | 
			
		||||
        // 当前时间
 | 
			
		||||
        Date now = Calendar.getInstance().getTime();
 | 
			
		||||
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
 | 
			
		||||
        String dateTime = format.format(now);
 | 
			
		||||
 | 
			
		||||
        HashMap<String, Object> map = new HashMap<>();
 | 
			
		||||
        map.put("list", accessLogVOList);
 | 
			
		||||
        map.put("sheetName", "社区进出记录表-" + System.currentTimeMillis());
 | 
			
		||||
        map.put("fileName", "社区进出记录表_导出时间_" + dateTime);
 | 
			
		||||
 | 
			
		||||
        return Res.success(map);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
package com.cxyxiaomo.epp.access.dao;
 | 
			
		||||
 | 
			
		||||
import com.cxyxiaomo.epp.common.pojo.AccessLog;
 | 
			
		||||
import com.cxyxiaomo.epp.common.query.AccessLogQuery;
 | 
			
		||||
import org.apache.ibatis.annotations.Mapper;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@Mapper
 | 
			
		||||
@Repository
 | 
			
		||||
public interface AccessLogDao {
 | 
			
		||||
 | 
			
		||||
    public boolean addAccessLog(AccessLog accessLog);
 | 
			
		||||
 | 
			
		||||
    public boolean updateAccessLog(AccessLog accessLog);
 | 
			
		||||
 | 
			
		||||
    public List<AccessLog> getAccessLogList(AccessLogQuery accessLogQuery);
 | 
			
		||||
 | 
			
		||||
    public boolean deleteAccessLogById(Long gateId);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,41 @@
 | 
			
		||||
package com.cxyxiaomo.epp.access.service;
 | 
			
		||||
 | 
			
		||||
import com.cxyxiaomo.epp.access.dao.AccessLogDao;
 | 
			
		||||
import com.cxyxiaomo.epp.common.pojo.AccessLog;
 | 
			
		||||
import com.cxyxiaomo.epp.common.query.AccessLogQuery;
 | 
			
		||||
import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class AccessLogService {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    AccessLogDao accessLogDao;
 | 
			
		||||
 | 
			
		||||
    public List<AccessLog> getAccessLogList(AccessLogQuery accessLogQuery) {
 | 
			
		||||
        if (Objects.nonNull(accessLogQuery.getType()) && "".equals(accessLogQuery.getType())) {
 | 
			
		||||
            accessLogQuery.setType(null);
 | 
			
		||||
        }
 | 
			
		||||
        return accessLogDao.getAccessLogList(accessLogQuery);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean addAccessLog(AccessLog accessLog) throws Exception {
 | 
			
		||||
        // 创建日志编号
 | 
			
		||||
        SnowflakeManager snowflakeManager = new SnowflakeManager(1L, 1L);
 | 
			
		||||
        long orderId = snowflakeManager.nextValue();
 | 
			
		||||
        accessLog.setId(orderId);
 | 
			
		||||
        return accessLogDao.addAccessLog(accessLog);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean updateAccessLog(AccessLog accessLog) {
 | 
			
		||||
        return accessLogDao.updateAccessLog(accessLog);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean deleteAccessLog(Long accessLogId) {
 | 
			
		||||
        return accessLogDao.deleteAccessLogById(accessLogId);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -28,7 +28,7 @@ public class GateService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean addGate(Gate gate) throws Exception {
 | 
			
		||||
        // 创建订单编号
 | 
			
		||||
        // 创建大门编号
 | 
			
		||||
        SnowflakeManager snowflakeManager = new SnowflakeManager(1L, 1L);
 | 
			
		||||
        long orderId = snowflakeManager.nextValue();
 | 
			
		||||
        gate.setId(orderId);
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,54 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
			
		||||
<!DOCTYPE mapper
 | 
			
		||||
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 | 
			
		||||
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
			
		||||
<mapper namespace="com.cxyxiaomo.epp.access.dao.AccessLogDao">
 | 
			
		||||
    <insert id="addAccessLog" parameterType="com.cxyxiaomo.epp.common.pojo.AccessLog">
 | 
			
		||||
        INSERT INTO access_log (id, time, user_id, user_real_name, gate_id, type)
 | 
			
		||||
        VALUES (#{id}, #{time}, #{userId}, #{userRealName}, #{gateId}, #{type})
 | 
			
		||||
    </insert>
 | 
			
		||||
 | 
			
		||||
    <update id="updateAccessLog" parameterType="com.cxyxiaomo.epp.common.pojo.AccessLog">
 | 
			
		||||
        UPDATE access_log
 | 
			
		||||
        <set>
 | 
			
		||||
            <if test="time != null">time = #{time},</if>
 | 
			
		||||
            <if test="userId != null">user_id = #{userId},</if>
 | 
			
		||||
            <if test="userRealName != null and userRealName != ''">user_real_name = #{userRealName},</if>
 | 
			
		||||
            <if test="gateId != null">gate_id = #{gateId},</if>
 | 
			
		||||
            <if test="type != null and type != ''">type = #{type}</if>
 | 
			
		||||
        </set>
 | 
			
		||||
        WHERE id = #{id}
 | 
			
		||||
    </update>
 | 
			
		||||
 | 
			
		||||
    <select id="getAccessLogList" resultType="com.cxyxiaomo.epp.common.pojo.AccessLog">
 | 
			
		||||
        SELECT * FROM access_log
 | 
			
		||||
        <where>
 | 
			
		||||
            1 = 1
 | 
			
		||||
            <if test="id != null">
 | 
			
		||||
                AND id = #{id}
 | 
			
		||||
            </if>
 | 
			
		||||
            <if test="startTime != null and endTime != null">
 | 
			
		||||
                AND time BETWEEN from_unixtime(#{startTime}/1000) AND from_unixtime(#{endTime}/1000)
 | 
			
		||||
            </if>
 | 
			
		||||
            <if test="userId != null">
 | 
			
		||||
                AND user_id = #{userId}
 | 
			
		||||
            </if>
 | 
			
		||||
            <if test="userRealName != null and userRealName != ''">
 | 
			
		||||
                AND user_real_name LIKE concat('%',#{userRealName},'%')
 | 
			
		||||
            </if>
 | 
			
		||||
            <if test="gateId != null">
 | 
			
		||||
                AND gate_id = #{gateId}
 | 
			
		||||
            </if>
 | 
			
		||||
            <if test="type != null and type != ''">
 | 
			
		||||
                AND type = #{type}
 | 
			
		||||
            </if>
 | 
			
		||||
        </where>
 | 
			
		||||
        order by time desc
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
    <delete id="deleteAccessLogById">
 | 
			
		||||
        DELETE
 | 
			
		||||
        FROM access_log
 | 
			
		||||
        WHERE id = #{id}
 | 
			
		||||
    </delete>
 | 
			
		||||
</mapper>
 | 
			
		||||
@@ -29,7 +29,7 @@
 | 
			
		||||
                AND id = #{id}
 | 
			
		||||
            </if>
 | 
			
		||||
            <if test="name != null and name != ''">
 | 
			
		||||
                AND name = #{name}
 | 
			
		||||
                AND name LIKE concat('%',#{name,jdbcType=VARCHAR},'%')
 | 
			
		||||
            </if>
 | 
			
		||||
            <if test="open != null">
 | 
			
		||||
                AND open = #{open}
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,7 @@ function updateQRCode() {
 | 
			
		||||
 | 
			
		||||
    if (i % refreshTime == 0) {
 | 
			
		||||
        // scene 最长支支持 32 位,所以这里不传入时间戳
 | 
			
		||||
        let scene = encodeURIComponent(`guard&${window.currentGate.id}`); // &${Date.now()}
 | 
			
		||||
        let scene = encodeURIComponent(`guard;${window.currentGate.id}`); // &${Date.now()}
 | 
			
		||||
        image.src = `${url}?page=${page}&scene=${scene}&envVersion=${envVersion}&width=${width}&autoColor=${autoColor}&isHyaline=${isHyaline}`
 | 
			
		||||
        console.log(image.src)
 | 
			
		||||
        refreshTimeCountDown.innerHTML = ` `
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user