电子围栏

pull/4/head
dearlin 2024-01-30 15:16:04 +08:00
parent bc49136400
commit fbb99198ca
7 changed files with 603 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package com.zcloud.controller.app;
import com.alibaba.fastjson.JSON;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.PageData;
import com.zcloud.service.electronicFence.ElectronicFenceService;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.ReturnMap;
import com.zcloud.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* TODO
* wangxuan
* www.zcloudchina.com
*/
@Controller
@RequestMapping("/app/electronicFence")
public class AppElectronicFenceController extends BaseController {
@Autowired
private ElectronicFenceService electronicFenceService;
/**
* @Description:
* @Author: dearLin
* @Date: 2024/1/30/030 9:38
* @Param: [com.zcloud.entity.Page] [page]
* @Return: java.lang.Object
*/
@RequestMapping(value = "/listTree")
@ResponseBody
public Object listTree() {
PageData pd = this.getPageData();
return ReturnMap.ok().put("zTreeNodes", JSON.toJSONString(electronicFenceService.listTree(pd)));
}
}

View File

@ -0,0 +1,135 @@
package com.zcloud.controller.electronicFence;
import com.alibaba.fastjson.JSON;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.service.electronicFence.ElectronicFenceService;
import com.zcloud.util.InitPageDataUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.ReturnMap;
import com.zcloud.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
*
* wangxuan
* www.zcloudchina.com
*/
@Controller
@RequestMapping("/electronicfence")
public class ElectronicFenceController extends BaseController {
@Autowired
private ElectronicFenceService electronicFenceService;
@Autowired
private InitPageDataUtil initPageDataUtil;
/**
* @Description:
* @Author: dearLin
* @Date: 2024/1/30/030 9:38
* @Param: [com.zcloud.entity.Page] [page]
* @Return: java.lang.Object
*/
@RequestMapping(value = "/list")
@ResponseBody
public Object list(Page page) {
PageData pd = this.getPageData();
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
pd.put("PARENT_ID", pd.getString("ELECTRONIC_FENCE_AREA_ID"));
pd.remove("ELECTRONIC_FENCE_AREA_ID");
page.setPd(pd);
return ReturnMap.ok().put("varList", electronicFenceService.list(page)).put("page", page);
}
/**
* @Description:
* @Author: dearLin
* @Date: 2024/1/30/030 9:38
* @Param: [com.zcloud.entity.Page] [page]
* @Return: java.lang.Object
*/
@RequestMapping(value = "/listTree")
@ResponseBody
public Object listTree() {
PageData pd = this.getPageData();
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
return ReturnMap.ok().put("zTreeNodes", JSON.toJSONString(electronicFenceService.listTree(pd)));
}
/**
* @Description:
* @Author: dearLin
* @Date: 2024/1/30/030 9:38
* @Param: [com.zcloud.entity.Page] [page]
* @Return: java.lang.Object
*/
@RequestMapping(value = "/goEdit")
@ResponseBody
public Object goEdit() {
PageData pd = this.getPageData();
return ReturnMap.ok().put("pd", electronicFenceService.findById(pd));
}
/**
* @Description:
* @Author: dearLin
* @Date: 2024/1/30/030 9:38
* @Param: [] []
* @Return: java.lang.Object
*/
@RequestMapping(value = "/save")
@ResponseBody
public Object save() {
PageData pd = this.getPageData();
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
initPageDataUtil.initSave(pd, "ELECTRONIC_FENCE_AREA_ID");
electronicFenceService.save(pd);
return ReturnMap.ok();
}
/**
* @Description:
* @Author: dearLin
* @Date: 2024/1/30/030 9:38
* @Param: [] []
* @Return: java.lang.Object
*/
@RequestMapping(value = "/edit")
@ResponseBody
public Object edit() {
PageData pd = this.getPageData();
initPageDataUtil.initEdit(pd);
electronicFenceService.edit(pd);
return ReturnMap.ok();
}
/**
* @Description:
* @Author: dearLin
* @Date: 2024/1/30/030 9:38
* @Param: [] []
* @Return: java.lang.Object
*/
@RequestMapping(value = "/removeByIds")
@ResponseBody
public Object removeByIds() {
PageData pd = this.getPageData();
// 判断一下当前要删除的是否有下级 有下级 禁止删除
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
if (electronicFenceService.hasChild(pd)) return ReturnMap.error("该区域下有子区域,禁止删除,请先删除子区域后删除该区域。");
initPageDataUtil.initEdit(pd);
electronicFenceService.removeByIds(pd);
return ReturnMap.ok();
}
}

View File

@ -0,0 +1,30 @@
package com.zcloud.mapper.datasource.electronicFence;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import java.util.List;
import java.util.Map;
/**
*
* wangxuan
* www.zcloudchina.com
*/
public interface ElectronicFenceMapper {
List<PageData> datalistPage(Page page);
void save(PageData pd);
void edit(PageData pd);
void deleteAll(PageData pd);
PageData findById(PageData pd);
List<PageData> listAll(PageData pd);
List<Map<String, Object>> listTree(PageData pd);
List<PageData> findByPId(PageData pd);
}

View File

@ -0,0 +1,28 @@
package com.zcloud.service.electronicFence;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import java.util.List;
import java.util.Map;
/**
* TODO
* wangxuan
* www.zcloudchina.com
*/
public interface ElectronicFenceService {
List<PageData> list(Page page);
void save(PageData pd);
void edit(PageData pd);
void removeByIds(PageData pd);
PageData findById(PageData pd);
List<Map<String, Object>> listTree(PageData pd);
boolean hasChild(PageData pd);
}

View File

@ -0,0 +1,110 @@
package com.zcloud.service.electronicFence.impl;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.electronicFence.ElectronicFenceMapper;
import com.zcloud.service.electronicFence.ElectronicFenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* TODO
* wangxuan
* www.zcloudchina.com
*/
@Service
@Transactional
public class ElectronicFenceServiceImpl implements ElectronicFenceService {
@Autowired
private ElectronicFenceMapper electronicFenceMapper;
@Override
public List<PageData> list(Page page) {
return electronicFenceMapper.datalistPage(page);
}
@Override
public void save(PageData pd) {
electronicFenceMapper.save(pd);
}
@Override
public void edit(PageData pd) {
electronicFenceMapper.edit(pd);
}
@Override
public void removeByIds(PageData pd) {
electronicFenceMapper.deleteAll(pd);
}
@Override
public PageData findById(PageData pd) {
return electronicFenceMapper.findById(pd);
}
@Override
public List<Map<String, Object>> listTree(PageData pd) {
List<Map<String, Object>> dataList = electronicFenceMapper.listTree(pd);
return buildTree(dataList);
}
@Override
public boolean hasChild(PageData pd) {
return electronicFenceMapper.findByPId(pd).size() > 0 ;
}
public static void main(String[] args) {
List<Map<String,Object>> dataList = new ArrayList<>();
HashMap<String,Object> d1 = new HashMap();
d1.put("id","96acf1a16df646dda03592af042f3abc");
d1.put("name","卓云企业");
d1.put("pId","0");
d1.put("ELECTRONIC_FENCE_ID","1");
d1.put("ELECTRONIC_FENCE_NAME","电子围栏1");
HashMap<String,Object> d2 = new HashMap();
d2.put("id","e16f4020df5145bd8ada827ec1bf310f");
d2.put("name","开发部");
d2.put("pId","96acf1a16df646dda03592af042f3abc");
d2.put("ELECTRONIC_FENCE_ID","2");
d2.put("ELECTRONIC_FENCE_NAME","电子围栏2");
dataList.add(d1);
dataList.add(d2);
List<Map<String, Object>> maps = buildTree(dataList);
System.out.println(maps);
}
public static List<Map<String, Object>> buildTree(List<Map<String, Object>> dataList) {
Map<String, Map<String, Object>> idToNodeMap = new HashMap<>();
List<Map<String, Object>> rootNodes = new ArrayList<>();
// Map IDs to their nodes
for (Map<String, Object> data : dataList) {
String id = (String) data.get("id");
idToNodeMap.put(id, data);
}
// Find root nodes and attach children
for (Map.Entry<String, Map<String, Object>> entry : idToNodeMap.entrySet()) {
Map<String, Object> node = entry.getValue();
String pId = (String) node.get("pId");
if ("0".equals(pId)) {
rootNodes.add(node);
} else {
Map<String, Object> parentNode = idToNodeMap.get(pId);
if (parentNode != null) {
List<Map<String, Object>> children = (List<Map<String, Object>>) parentNode.getOrDefault("nodes", new ArrayList<>());
children.add(node);
parentNode.put("nodes", children);
}
}
}
return rootNodes;
}
}

View File

@ -0,0 +1,68 @@
package com.zcloud.util;
import com.zcloud.entity.PageData;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @author zhangyue
* @date 2023/2/2/002 10:09
*/
@Component
public class InitPageDataUtil {
/**
*
*
* @param pd
* @return
*/
public void initSave(PageData pd) {
pd.put("CREATOR", Jurisdiction.getUSER_ID()); //添加人
pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
pd.put("ISDELETE", "0"); //是否删除(0:有效 1删除)
}
public void initSave(PageData pd, String PRIMARY_KEY) {
pd.put("CREATOR", Jurisdiction.getUSER_ID()); //添加人
pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
pd.put("ISDELETE", "0"); //是否删除(0:有效 1删除)
pd.put(PRIMARY_KEY, UuidUtil.get32UUID()); //是否删除(0:有效 1删除)
}
/**
*
*
* @param pd
* @return
*/
public void initEdit(PageData pd) {
pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
}
public void initSaveApp(PageData pd, String OPERATOR) {
pd.put("CREATOR", OPERATOR); //添加人
pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
pd.put("OPERATOR", OPERATOR); //修改人
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
pd.put("ISDELETE", "0"); //是否删除(0:有效 1删除)
}
public void initSaveApp(PageData pd, String OPERATOR,String PRIMARY_KEY) {
pd.put("CREATOR", OPERATOR); //添加人
pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
pd.put("OPERATOR", OPERATOR); //修改人
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
pd.put("ISDELETE", "0"); //是否删除(0:有效 1删除)
pd.put(PRIMARY_KEY, UuidUtil.get32UUID()); //是否删除(0:有效 1删除)
}
public void initEditApp(PageData pd, String OPERATOR) {
pd.put("OPERATOR", OPERATOR); //修改人
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
}
}

View File

@ -0,0 +1,194 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zcloud.mapper.datasource.electronicFence.ElectronicFenceMapper">
<!--表名 -->
<sql id="tableName">
electronic_fence
</sql>
<!--数据字典表名 -->
<sql id="dicTableName">
SYS_DICTIONARIES
</sql>
<!-- 字段 -->
<sql id="Field">
f.ELECTRONIC_FENCE_AREA_ID,
f.ELECTRONIC_FENCE_AREA_NAME,
f.ELECTRONIC_FENCE_ID,
f.ELECTRONIC_FENCE_NAME,
f.HEADMAN,
f.TEL,
f.BZ,
f.PARENT_ID,
f.CORPINFO_ID,
f.ISDELETE,
f.OPERATOR,
f.OPERATTIME,
f.CREATTIME,
f.CREATOR
</sql>
<!-- 字段用于新增 -->
<sql id="Field2">
ELECTRONIC_FENCE_AREA_ID,
ELECTRONIC_FENCE_ID,
ELECTRONIC_FENCE_AREA_NAME,
ELECTRONIC_FENCE_NAME,
HEADMAN,
TEL,
BZ,
PARENT_ID,
CORPINFO_ID,
ISDELETE,
OPERATOR,
OPERATTIME,
CREATTIME,
CREATOR
</sql>
<!-- 字段值 -->
<sql id="FieldValue">
#{ELECTRONIC_FENCE_AREA_ID},
#{ELECTRONIC_FENCE_ID},
#{ELECTRONIC_FENCE_AREA_NAME},
#{ELECTRONIC_FENCE_NAME},
#{HEADMAN},
#{TEL},
#{BZ},
#{PARENT_ID},
#{CORPINFO_ID},
#{ISDELETE},
#{OPERATOR},
#{OPERATTIME},
#{CREATTIME},
#{CREATOR}
</sql>
<!-- 新增-->
<insert id="save" parameterType="pd">
insert into
<include refid="tableName"></include>
(
<include refid="Field2"></include>
) values (
<include refid="FieldValue"></include>
)
</insert>
<!-- 删除-->
<delete id="delete" parameterType="pd">
update
<include refid="tableName"></include>
set
ISDELETE = '1',
OPERATOR = #{OPERATOR},
OPERATTIME = #{OPERATTIME}
where
ELECTRONIC_FENCE_AREA_ID = #{ELECTRONIC_FENCE_AREA_ID}
</delete>
<!-- 修改 -->
<update id="edit" parameterType="pd">
update
<include refid="tableName"></include>
set
ELECTRONIC_FENCE_AREA_NAME = #{ELECTRONIC_FENCE_AREA_NAME},
HEADMAN = #{HEADMAN},
TEL = #{TEL},
BZ = #{BZ},
ELECTRONIC_FENCE_NAME = #{ELECTRONIC_FENCE_NAME},
ELECTRONIC_FENCE_ID = #{ELECTRONIC_FENCE_ID}
where
ELECTRONIC_FENCE_AREA_ID = #{ELECTRONIC_FENCE_AREA_ID}
</update>
<!-- 通过ID获取数据 -->
<select id="findById" parameterType="pd" resultType="pd">
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
f
where
f.ELECTRONIC_FENCE_AREA_ID = #{ELECTRONIC_FENCE_AREA_ID}
and ISDELETE = 0
</select>
<!-- 列表 -->
<select id="datalistPage" parameterType="page" resultType="pd">
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
f
where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
and
(
ELECTRONIC_FENCE_AREA_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
or
ELECTRONIC_FENCE_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
<!-- 根据需求自己加检索条件
字段1 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
or
字段2 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
-->
)
</if>
<if test="pd.PARENT_ID != null and pd.PARENT_ID != ''"><!-- 关键词检索 -->
and PARENT_ID = #{pd.PARENT_ID}
</if>
ORDER BY f.OPERATTIME DESC
</select>
<!-- 列表(全部) -->
<select id="listAll" parameterType="pd" resultType="pd">
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
f
where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID}
</select>
<select id="listTree" resultType="java.util.Map">
select
ELECTRONIC_FENCE_AREA_ID id,
ELECTRONIC_FENCE_ID,
ELECTRONIC_FENCE_NAME,
ELECTRONIC_FENCE_AREA_NAME name,
PARENT_ID pId
from
<include refid="tableName"></include>
f
where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID}
</select>
<select id="findByPId" resultType="com.zcloud.entity.PageData">
select
ELECTRONIC_FENCE_AREA_ID id,
ELECTRONIC_FENCE_ID,
ELECTRONIC_FENCE_NAME,
ELECTRONIC_FENCE_AREA_NAME name,
PARENT_ID pId
from
<include refid="tableName"></include>
f
where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID} and f.PARENT_ID = #{ELECTRONIC_FENCE_AREA_ID}
</select>
<!-- 批量删除 -->
<delete id="deleteAll" parameterType="pd">
update
<include refid="tableName"></include>
set
ISDELETE = '1',
OPERATOR = #{OPERATOR},
OPERATTIME = #{OPERATTIME}
where
ELECTRONIC_FENCE_AREA_ID = #{ELECTRONIC_FENCE_AREA_ID}
</delete>
</mapper>