1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

社区大门 增删改查完成

This commit is contained in:
程序员小墨 2023-04-15 19:25:52 +08:00
parent 6203e43465
commit 7f8a0f8d60
12 changed files with 494 additions and 20 deletions

View File

@ -0,0 +1,16 @@
package com.cxyxiaomo.epp.common.pojo;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@NoArgsConstructor
@Accessors(chain = true) // 链式写法
public class Gate implements Serializable {
private Long id;
private String name;
private Boolean open;
}

View File

@ -0,0 +1,65 @@
package com.cxyxiaomo.epp.common.vo;
import com.cxyxiaomo.epp.common.pojo.Gate;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
// 数据库关系映射
@Data
@NoArgsConstructor
@Accessors(chain = true) // 链式写法
// 微服务必须要实现Serializable
public class GateVO implements Serializable {
private String id;
private String name;
private Boolean open;
public static GateVO convertFrom(Gate gate) {
if (gate == null) {
return null;
}
GateVO gateVO = new GateVO();
BeanUtils.copyProperties(gate, gateVO);
if (Objects.nonNull(gate.getId())) {
gateVO.setId(String.valueOf(gate.getId()));
}
return gateVO;
}
public static List<GateVO> convertFrom(List<Gate> gateList) {
if (gateList == null) {
return null;
}
List<GateVO> gateVOList = gateList.stream()
.map(GateVO::convertFrom).collect(Collectors.toList());
return gateVOList;
}
public static Gate convertTo(GateVO gateVO) {
if (gateVO == null) {
return null;
}
Gate gate = new Gate();
BeanUtils.copyProperties(gateVO, gate);
try {
if (Objects.nonNull(gateVO.getId())) {
Long gateId = Long.valueOf(gateVO.getId());
gate.setId(gateId);
} else {
gate.setId(null);
}
} catch (Exception e) {
gate.setId(null);
}
return gate;
}
}

View File

@ -0,0 +1,194 @@
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.PageTable.utils.FieldRuleBuilder;
import com.cxyxiaomo.epp.PageTable.utils.FieldRuleListBuilder;
import com.cxyxiaomo.epp.access.service.GateService;
import com.cxyxiaomo.epp.common.pojo.Gate;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.common.vo.GateVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("/access/gate")
public class GateController {
@Resource
GateService gateService;
/**
* 获取大门列表门禁端
*
* @return
*/
@GetMapping("/guard-client/getGateList")
@ResponseBody
public Res getAllGateList() {
GateVO gateVO = new GateVO();
List<Gate> gateList = gateService.getGateList(gateVO);
List<GateVO> gateVOList = GateVO.convertFrom(gateList);
return Res.success(gateVOList);
}
/**
* 获取大门列表
*
* @return
*/
@GetMapping("/manage/getGateList")
@ResponseBody
public Res getGateList(PageQuery pageQuery, GateVO gateVO) {
// 查询分页数据
PageHelper.startPage(pageQuery.getPageIndex(), pageQuery.getPageSize());
List<Gate> gateList = gateService.getGateList(gateVO);
PageInfo<Gate> gatePageInfo = new PageInfo<>(gateList);
List<Gate> list = gatePageInfo.getList();
List<GateVO> voList = GateVO.convertFrom(list);
// id列 字段名区分大小写以VO中的变量名为准
// 新增修改弹窗时使用该列作为主键列进行操作
String idFieldName = "id";
// 当前管理页面
String pageName = "大门管理";
// 指定前端表格显示列
JSONArray columns = FieldBuilder.create()
.add("name", "name", "大门名称", "",
FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"大门名称", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("大门名称").required())
.add(FieldRuleBuilder.create("大门名称").minMax(2, 15)),
"DPD @cword(2, 15)"
)
.add("open", "open", "状态", true,
FieldType.TEXT, SearchType.SELECT, AddType.SELECT, EditType.SELECT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"状态", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("状态").required()),
"DPD @pick(['true', 'false'])"
)
.build();
// 指定需要翻译的字段
HashMap<Object, Object> stateMap = new HashMap<>(2);
stateMap.put(true, "允许通行");
stateMap.put(false, "禁止通行");
// build
JSONArray fieldMapper = FieldMapperBuilder.create()
.add("open", "open", stateMap)
.build();
// 拼装返回结果
JSONObject map = new JSONObject(6);
map.put("total", gatePageInfo.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
*/
@PostMapping("/manage/editGate")
@ResponseBody
public Res editGate(@ModelAttribute GateVO gateVO) throws Exception {
Gate gate = GateVO.convertTo(gateVO);
// 先查询大门是否存在
Gate existGate = gateService.getGateById(gate.getId());
if (gate.getId() == null || gate.getId() < 1) {
// 新增大门
if (existGate != null) {
return Res.error("大门已存在,操作失败");
}
if (gate.getName() == null || "".equals(gate.getName())) {
return Res.error("大门名称不能为空");
}
gate.setId(null);
gateService.addGate(gate);
} else {
// 修改大门
if (existGate == null) {
return Res.error("大门不存在,操作失败");
}
gateService.updateGate(gate);
}
return Res.success(true);
}
/**
* 删除大门
*
* @param id
* @return
*/
@PostMapping("/manage/deleteGate")
@ResponseBody
public Res deleteGate(Long id) {
if (id == null || id <= 0) {
return Res.error("大门不存在,删除失败");
}
// 先查询大门是否存在
Gate existGate = gateService.getGateById(id);
if (existGate == null) {
return Res.error("大门不存在,删除失败");
}
boolean b = gateService.deleteGate(existGate.getId());
return Res.success(b);
}
/**
* 导出大门列表
*
* @return
*/
@GetMapping("/manage/exportGateList")
@ResponseBody
public Res exportGateList(GateVO gateVO) {
List<Gate> gateList = gateService.getGateList(gateVO);
List<GateVO> gateVOList = GateVO.convertFrom(gateList);
// 当前时间
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", gateVOList);
map.put("sheetName", "社区大门表-" + System.currentTimeMillis());
map.put("fileName", "社区大门表_导出时间_" + dateTime);
return Res.success(map);
}
}

View File

@ -0,0 +1,23 @@
package com.cxyxiaomo.epp.access.dao;
import com.cxyxiaomo.epp.common.pojo.Gate;
import com.cxyxiaomo.epp.common.vo.GateVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface GateDao {
public boolean addGate(Gate gate);
public boolean updateGate(Gate gate);
public List<Gate> getGateList(GateVO gateVO);
public Gate getGateById(Long gateId);
public boolean deleteGateById(Long gateId);
}

View File

@ -0,0 +1,42 @@
package com.cxyxiaomo.epp.access.service;
import com.cxyxiaomo.epp.access.dao.GateDao;
import com.cxyxiaomo.epp.common.pojo.Gate;
import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
import com.cxyxiaomo.epp.common.vo.GateVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class GateService {
@Resource
GateDao gateDao;
public Gate getGateById(Long id) {
return gateDao.getGateById(id);
}
public List<Gate> getGateList(GateVO gateVO) {
return gateDao.getGateList(gateVO);
}
public boolean addGate(Gate gate) throws Exception {
// 创建订单编号
SnowflakeManager snowflakeManager = new SnowflakeManager(1L, 1L);
long orderId = snowflakeManager.nextValue();
gate.setId(orderId);
return gateDao.addGate(gate);
}
public boolean updateGate(Gate gate) {
return gateDao.updateGate(gate);
}
public boolean deleteGate(Long gateId) {
return gateDao.deleteGateById(gateId);
}
}

View File

@ -0,0 +1,43 @@
<?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.GateDao">
<insert id="addGate" parameterType="com.cxyxiaomo.epp.common.pojo.Gate">
INSERT INTO gate (id, name, open)
VALUES (#{id}, #{name}, #{open})
</insert>
<update id="updateGate" parameterType="com.cxyxiaomo.epp.common.pojo.Gate">
UPDATE gate
<set>
<if test="name != null">name = #{name},</if>
<if test="open != null">open = #{open},</if>
</set>
WHERE id = #{id}
</update>
<select id="getGateById" resultType="com.cxyxiaomo.epp.common.pojo.Gate">
SELECT * FROM gate WHERE id = #{id}
</select>
<select id="getGateList" resultType="com.cxyxiaomo.epp.common.pojo.Gate">
SELECT * FROM gate
<where>
<if test="id != null">
AND id = #{id}
</if>
<if test="name != null and name != ''">
AND name = #{name}
</if>
<if test="open != null">
AND open = #{open}
</if>
</where>
</select>
<delete id="deleteGateById">
DELETE FROM gate WHERE id = #{id}
</delete>
</mapper>

View File

@ -17,6 +17,23 @@
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for access_log
-- ----------------------------
DROP TABLE IF EXISTS `access_log`;
CREATE TABLE `access_log` (
`id` bigint(20) NOT NULL COMMENT '雪花id',
`time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '进出时间',
`user_id` int(11) NOT NULL COMMENT '用户id',
`user_real_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户真实姓名',
`gate_id` bigint(20) NOT NULL COMMENT '大门id',
`type` enum('IN','OUT') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '类型(进门 OR 出门)'
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '人员进出记录表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of access_log
-- ----------------------------
-- ----------------------------
-- Table structure for apply1
-- ----------------------------
@ -48,21 +65,6 @@ INSERT INTO `apply1` VALUES (10, 12, '1', '飞机', '1', '2022-06-15 10:53:00',
INSERT INTO `apply1` VALUES (11, 2, '1', '飞机', '1', '2022-10-23 16:17:00', '2022-10-23 18:17:00', 1, '');
INSERT INTO `apply1` VALUES (12, 13, '1', '飞机', '1', '2022-10-26 19:25:00', '2022-10-26 21:25:00', 1, '');
-- ----------------------------
-- Table structure for community_gate1
-- ----------------------------
DROP TABLE IF EXISTS `community_gate1`;
CREATE TABLE `community_gate1` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '雪花id',
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '大门显示名称',
`open` tinyint(1) NOT NULL DEFAULT 1 COMMENT '大门是否开放 1为开放 2为关闭',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '社区大门' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of community_gate1
-- ----------------------------
-- ----------------------------
-- Table structure for count1
-- ----------------------------
@ -102,6 +104,21 @@ INSERT INTO `feedback1` VALUES (3, '22', '33', '2022-02-14 10:20:29', 1, 'no');
INSERT INTO `feedback1` VALUES (4, '``', '11', '2022-02-14 10:22:12', 1, '111');
INSERT INTO `feedback1` VALUES (5, '123', '123456', '2022-03-28 19:34:04', 2, NULL);
-- ----------------------------
-- Table structure for gate
-- ----------------------------
DROP TABLE IF EXISTS `gate`;
CREATE TABLE `gate` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '雪花id',
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '大门显示名称',
`open` tinyint(1) NOT NULL DEFAULT 1 COMMENT '大门是否开放 1为开放 2为关闭',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '社区大门' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of gate
-- ----------------------------
-- ----------------------------
-- Table structure for goods
-- ----------------------------

View File

@ -0,0 +1,23 @@
CREATE TABLE `gate` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '雪花id',
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '大门显示名称',
`open` tinyint(1) NOT NULL DEFAULT 1 COMMENT '大门是否开放 1为开放 2为关闭',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '社区大门' ROW_FORMAT = DYNAMIC;
创建该表的 add update getList deleteById 的 Mybatils xml片段
(例如:<insert id="addGate"><update id="updateGate"><select id="getGateList"><delete id="deleteGateById">
实体类如下
public class Gate implements Serializable {
private Long id;
private String name;
private Boolean open;
}
以下是一些要求
parameterType="com.cxyxiaomo.epp.common.pojo.Gate"
where 条件所引用的Java变量都需要先判断是否为null或空
输出应该为一个 ```code``` 包起来的代码片段

51
frontend/src/api/gate.js Normal file
View File

@ -0,0 +1,51 @@
import send_request from '../utils/send_request';
/**
* 获取大门列表
* @returns
*/
export function getGateList(params) {
return send_request({
url: '/access/gate/manage/getGateList',
method: 'GET',
params: params,
});
};
/**
* 添加/修改大门信息
* @returns
*/
export function editGate(params) {
return send_request({
url: '/access/gate/manage/editGate',
method: 'POST',
useQS: true,
params: params,
});
};
/**
* 删除大门
* @returns
*/
export function deleteGate(params) {
return send_request({
url: '/access/gate/manage/deleteGate',
method: 'POST',
useQS: true,
params: params,
});
};
/**
* 导出大门列表
* @returns
*/
export function exportGateList(params) {
return send_request({
url: '/access/gate/manage/exportGateList',
method: 'GET',
params: params,
});
};

View File

@ -32,7 +32,7 @@
</div>
<!-- 表格 -->
<el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
<el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
<el-table-column prop="id" label="ID" align="center"></el-table-column>
<el-table-column v-for="(field, index) in tableFields" :prop="field.prop" :label="field.label" :key="index"
align="center">
<template #default="scope" v-if="field.type == 'image'">

View File

@ -1,11 +1,11 @@
<template>
<div class="container">
<manageList :list-func="shopGoodApi.getGoodList" :add-func="shopGoodApi.editGood" :edit-func="shopGoodApi.editGood"
:delete-func="shopGoodApi.deleteGood" :export-func="shopGoodApi.exportGoodList" edit-permiss="shop-good-setting" />
<manageList :list-func="gateApi.getGateList" :add-func="gateApi.editGate" :edit-func="gateApi.editGate"
:delete-func="gateApi.deleteGate" :export-func="gateApi.exportGateList" edit-permiss="access-gate-setting" />
</div>
</template>
<script setup lang="ts">
import manageList from '../components/manage-list.vue';
import * as shopGoodApi from '../api/shop-good';
import * as gateApi from '../api/gate';
</script>

View File

@ -1,7 +1,7 @@
<template>
<div class="container">
<manageList :list-func="reportApi.getReportList" :export-func="reportApi.exportReportList"
edit-permiss="privilege-user-setting" />
edit-permiss="access-log" />
</div>
</template>