Commit 7fda7aef authored by 赵啸非's avatar 赵啸非

添加基础设备同步

parent 9201a420
...@@ -102,3 +102,37 @@ INSERT INTO `mortals_xhx_resource` VALUES (null, '大厅窗口-菜单管理-维 ...@@ -102,3 +102,37 @@ INSERT INTO `mortals_xhx_resource` VALUES (null, '大厅窗口-菜单管理-维
-- ---------------------------- -- ----------------------------
ALTER TABLE mortals_sys_window ADD COLUMN `nameDesc` varchar (256) default "" COMMENT '名称描述' AFTER englishName; ALTER TABLE mortals_sys_window ADD COLUMN `nameDesc` varchar (256) default "" COMMENT '名称描述' AFTER englishName;
ALTER TABLE mortals_sys_window ADD COLUMN `englishNameDesc` varchar (256) default "" COMMENT '英文名称描述' AFTER nameDesc; ALTER TABLE mortals_sys_window ADD COLUMN `englishNameDesc` varchar (256) default "" COMMENT '英文名称描述' AFTER nameDesc;
-- ----------------------------
2023-5-06
-- ----------------------------
-- ----------------------------
-- 设备表
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_device`;
CREATE TABLE `mortals_xhx_device` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID,主键,自增长',
`deviceId` bigint(20) DEFAULT NULL COMMENT '设备id',
`deviceName` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备名称',
`deviceCode` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '设备编码',
`deviceMac` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '设备的MAC地址',
`siteId` bigint(20) DEFAULT NULL COMMENT '站点Id',
`siteCode` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '站点编号,来源基础服务平台',
`siteName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '站点名称',
`productCode` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '产品编码',
`productName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '产品名称',
`deviceSrc` tinyint(2) DEFAULT 2 COMMENT '设备来源(0.子设备,1.网关设备,2.直连设备)',
`lon` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '经度',
`lati` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '纬度',
`leadingOfficial` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '负责人',
`leadingOfficialTelephone` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '联系电话',
`deviceStatus` tinyint(2) DEFAULT NULL COMMENT '设备状态 (0.未激活,1.离线,2.在线)',
`deviceRemark` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '备注',
`source` tinyint(2) DEFAULT 1 COMMENT '设备来源(0.旧设备,1.新设备)',
`createUserId` bigint(20) NOT NULL COMMENT '创建用户',
`createTime` datetime NOT NULL COMMENT '创建时间',
`updateUserId` bigint(20) DEFAULT NULL COMMENT '更新用户',
`updateTime` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='设备';
package com.mortals.xhx.busiz;
import com.alibaba.fastjson.JSONObject;
import com.mortals.xhx.common.utils.EncryptionUtils;
import org.springframework.http.HttpMethod;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class SignDemo {
private static String getSortedParams(String methodName, Map<String, String> headerMap, Map<String, String> paramsMap, String body) {
TreeMap<String, Object> paramMap = new TreeMap<>();
// 获取query参数
if (!paramsMap.isEmpty()) {
for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
paramMap.put(entry.getKey(), entry.getValue());
}
}
// 获取body内容
if (HttpMethod.POST.name().equals(methodName)) {
paramMap.put("body", body);
}
paramMap.put("appId", headerMap.get("appId"));
paramMap.put("appKey", headerMap.get("appKey"));
paramMap.put("timeStamp", headerMap.get("timeStamp"));
paramMap.put("nonce", headerMap.get("nonce"));
paramMap.put("secretKey", headerMap.get("appSecret"));
StringBuilder signSb = new StringBuilder();
signSb.append("appId").append("=").append(paramMap.get("appId")).append("&");
signSb.append("appKey").append("=").append(paramMap.get("appKey")).append("&");
signSb.append("body").append("=").append(paramMap.get("body")).append("&");
signSb.append("timeStamp").append("=").append(paramMap.get("timeStamp")).append("&");
signSb.append("nonce").append("=").append(paramMap.get("nonce")).append("&");
signSb.append("secretKey").append("=").append(paramMap.get("secretKey")).append("&");
/* for (Map.Entry<String, Object> params : paramMap.entrySet()) {
signSb.append(params.getKey()).append("=").append(params.getValue() + "").append("&");
}*/
String signStr = signSb.substring(0, signSb.length() - 1);
System.out.println("SignDemo.签名源字符串: " + signStr);
String sign = EncryptionUtils.SHA256(signStr);
System.out.println("SignDemo.签名计算结果: " + sign);
return sign;
}
public static void main(String[] args) {
String methodName = "POST";
Map<String, String> headerMap = new HashMap<>();
headerMap.put("appId", "01C67D56D0630517");
headerMap.put("appKey", "a0b946c858aa8d06");
headerMap.put("timeStamp", "1677838709935");
headerMap.put("nonce", "894576350573");
headerMap.put("appSecret", "ad80c59e575a78ab");
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("param", "哈哈哈");
JSONObject object = new JSONObject();
object.put("test", "哈哈哈");
String body = object.toJSONString();
getSortedParams(methodName, headerMap, paramsMap, body);
}
}
package com.mortals.xhx.daemon;
import cn.hutool.http.HttpUtil;
import org.apache.commons.lang3.StringEscapeUtils;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.DomSerializer;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
public class DeptXMLXPathParser {
public static void main(String[] args) throws Exception {
String url = "http://www.sczwfw.gov.cn/jiq/front/channel/deptSwitch?areaCode=510116000000";
String exp = "//ul[@class='bm-list']//li";
String html = null;
try {
html= HttpUtil.get(url);
} catch (Exception e) {
e.printStackTrace();
}
HtmlCleaner hc = new HtmlCleaner();
TagNode tn = hc.clean(html);
Document dom = new DomSerializer(new CleanerProperties()).createDOM(tn);
XPath xPath = XPathFactory.newInstance().newXPath();
Object result;
result = xPath.evaluate(exp, dom, XPathConstants.NODESET);
if (result instanceof NodeList) {
NodeList nodeList = (NodeList) result;
// System.out.println(nodeList.getLength());
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
/**
* Node.getTextContent() 此属性返回此节点及其后代的文本内容。
* Node.getFirstChild() 此节点的第一个子节点。
* Node.getAttributes() 包含此节点的属性的 NamedNodeMap(如果它是 Element);否则为 null
* 如果想获取相应对象的相关属性,可以调用 getAttributes().getNamedItem("属性名") 方法
*/
System.out.println(node.getAttributes().getNamedItem("title").getNodeValue());
System.out.println(
node.getNodeValue() == null ? StringEscapeUtils.unescapeHtml4(node.getFirstChild().getAttributes().getNamedItem("href").getNodeValue()) : node.getNodeValue());
}
}
}
}
\ No newline at end of file
package com.mortals.xhx.daemon;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.DomSerializer;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.util.HashMap;
import java.util.Map;
/**
*事项抓取测试
* @author:
* @date: 2022/11/13 17:45
*/
public class MatterDetailXMLXPathParser {
public static void main(String[] args) throws Exception {
String url = "http://www.sczwfw.gov.cn/jiq/front/transition/ywTransToDetail?areaCode=510116000000&itemCode=511A0081000005-510116000000-000-11510122009212050T-1-00&taskType=1&deptCode=11510122009212050T";
String matterListExp = "//div[@class='sx_list']//div[class=\"sub_list1_main\"]";
String matterTotalExp = "//input[@id=\"result_count\"]";
String matterPageNumExp = "//input[@id=\"pageNum\"]";
//String baseInfoExp = "//div[@class=\"bigbox1\"]/div//table[1]//td";
String baseInfoExp = "//div[@class=\"section1\"]//table[1]//td";
String baseInfoExp1 = "//div[@class=\"section2\"]/table[1]//td";
String baseInfoExp2 = "//div[@class=\"section3\"]/table[1]//td";
String baseInfoExp3 = "//div[@class=\"section4\"]/table//td";
baseInfoExp+="|"+baseInfoExp1;
baseInfoExp+="|"+baseInfoExp2;
baseInfoExp+="|"+baseInfoExp3;
System.out.println(baseInfoExp);
Map<String, String> params = new HashMap<>();
JSONObject json = new JSONObject();
String html = null;
try {
html= HttpUtil.get(url);
//System.out.println(html);
} catch (Exception e) {
e.printStackTrace();
}
HtmlCleaner hc = new HtmlCleaner();
TagNode tn = hc.clean(html);
Document dom = new DomSerializer(new CleanerProperties()).createDOM(tn);
XPath xPath = XPathFactory.newInstance().newXPath();
Object result;
result = xPath.evaluate(baseInfoExp, dom, XPathConstants.NODESET);
if (result instanceof NodeList) {
NodeList nodeList = (NodeList) result;
for (int i = 0; i < nodeList.getLength(); i++) {
if(i%2==0){
continue;
}
Node node = nodeList.item(i);
if(i>0){
Node prenode = nodeList.item(i - 1);
params.put(prenode.getTextContent().trim(),node.getTextContent().trim());
json.put(prenode.getTextContent().trim(),node.getTextContent().trim());
}
}
}
System.out.println(JSON.toJSONString(json));
}
}
\ No newline at end of file
package com.mortals.xhx.daemon;
import cn.hutool.http.HttpUtil;
import org.apache.commons.lang3.StringEscapeUtils;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.DomSerializer;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
/**
*事项抓取测试
* @author:
* @date: 2022/11/13 17:45
*/
public class MatterXMLXPathParser {
public static void main(String[] args) throws Exception {
String url = "http://www.sczwfw.gov.cn/jiq/front/item/qlqd?areaCode=510116000000";
String matterListExp = "//div[@class='sx_list']//div[class=\"sub_list1_main\"]";
String matterTotalExp = "//input[@id=\"result_count\"] | //input[@id=\"pageNum\"]";
String matterPageNumExp = "//input[@id=\"pageNum\"]";
String html = null;
try {
html= HttpUtil.get(url);
System.out.println(html);
} catch (Exception e) {
e.printStackTrace();
}
HtmlCleaner hc = new HtmlCleaner();
TagNode tn = hc.clean(html);
Document dom = new DomSerializer(new CleanerProperties()).createDOM(tn);
XPath xPath = XPathFactory.newInstance().newXPath();
Object result;
result = xPath.evaluate(matterTotalExp, dom, XPathConstants.NODESET);
if (result instanceof NodeList) {
NodeList nodeList = (NodeList) result;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
System.out.println(node.getAttributes().getNamedItem("value").getNodeValue());
}
}
/* result = xPath.evaluate(matterPageNumExp, dom, XPathConstants.NODESET);
if (result instanceof NodeList) {
NodeList nodeList = (NodeList) result;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
System.out.println(node.getAttributes().getNamedItem("value").getNodeValue());
}
}*/
}
}
\ No newline at end of file
package com.mortals.xhx.daemon;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.http.HttpUtil;
import org.springframework.util.xml.SimpleNamespaceContext;
import org.w3c.dom.*;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPathConstants;
import java.util.stream.Collectors;
public class Test {
public static NamespaceContext buildNsByDocument(Document document) {
SimpleNamespaceContext ns = new SimpleNamespaceContext();
Element rootElement = XmlUtil.getRootElement(document);
NamedNodeMap namedNodeMap = rootElement.getAttributes();
// 遍历复制给firstMap存起来
for (int i = 0; i < namedNodeMap.getLength(); i++) {
Attr attr = (Attr) namedNodeMap.item(i);
if (attr.getName().startsWith("xmlns:")) {
ns.bindNamespaceUri(attr.getName().split(":")[1], attr.getValue());
}
}
return ns;
}
public static void main(String[] args) {
String rest = HttpUtil.get("http://www.sczwfw.gov.cn/jiq/front/channel/deptSwitch?areaCode=510116000000");
Document document = XmlUtil.readXML(rest);
// String xpath = "//ul[@class='bm-list']/ul";
// NodeList nodeList = XmlUtil.getNodeListByXPath(xpath, document);
//for(int i=0;i<nodeList.getLength();i++){
// Node item = nodeList.item(i);
// System.out.println(item.getTextContent() );
//}
System.out.println(rest);
}
}
package com.mortals.xhx.daemon.task;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.device.DevicePdu;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.feign.device.IDeviceFeign;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.site.model.SiteEntity;
import com.mortals.xhx.module.site.model.SiteQuery;
import com.mortals.xhx.module.site.service.SiteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 同步事项列表
*/
@Slf4j
@Service("SyncSiteDeviceTask")
public class SyncSiteDeviceTaskImpl implements ITaskExcuteService {
@Autowired
private IDeviceFeign deviceFeign;
@Autowired
private DeviceService deviceService;
@Autowired
private SiteService siteService;
@Override
public void excuteTask(ITask task) throws AppException {
log.info("开始同步设备列表!");
syncDevice();
log.info("结束同步设备列表!");
}
private void syncDevice() {
List<SiteEntity> siteEntities = siteService.find(new SiteQuery());
for (SiteEntity site : siteEntities) {
//List<SiteEntity> siteList = siteService.getFlatSitesBySiteId(siteEntity.getId(), null);
log.info("站点名称:{}", site.getSiteName());
DevicePdu devicePdu = new DevicePdu();
devicePdu.setSiteId(site.getId());
devicePdu.setSize(-1);
Rest<RespData<List<DevicePdu>>> deviceRest = deviceFeign.list(devicePdu);
log.info("deviceRest:{}", JSON.toJSONString(deviceRest));
if (YesNoEnum.YES.getValue() == deviceRest.getCode()) {
List<DevicePdu> devicePduList = deviceRest.getData().getData();
log.info("样表机总数量:{}", devicePduList.size());
if (!ObjectUtils.isEmpty(devicePduList)) {
List<DeviceEntity> newDeviceList = devicePduList.stream().map(newDevice -> {
DeviceEntity deviceEntity = new DeviceEntity();
deviceEntity.initAttrValue();
BeanUtils.copyProperties(newDevice, deviceEntity, BeanUtil.getNullPropertyNames(newDevice));
return deviceEntity;
}).collect(Collectors.toList());
List<DeviceEntity> oldDeviceList = deviceService.find(new DeviceQuery().siteId(site.getId()));
Map<String, DeviceEntity> oldDeviceMap = oldDeviceList.stream().collect(Collectors.toMap(x -> x.getDeviceCode(), y -> y, (o, n) -> n));
Map<String, DeviceEntity> newDeviceMap = newDeviceList.stream().collect(Collectors.toMap(x -> x.getDeviceCode(), y -> y, (o, n) -> n));
List<DeviceEntity> updateDeviceLsit = newDeviceList.stream().map(item -> {
if (oldDeviceMap.containsKey(item.getDeviceCode())) {
item.setId(oldDeviceMap.get(item.getDeviceCode()).getId());
item.setDeviceId(item.getId());
item.setProductCode(oldDeviceMap.get(item.getDeviceCode()).getProductCode());
item.setProductName(oldDeviceMap.get(item.getDeviceCode()).getProductName());
item.setUpdateTime(new Date());
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
List<DeviceEntity> saveDeviceList = newDeviceList.stream().map(item -> {
if (!oldDeviceMap.containsKey(item.getDeviceCode())) {
item.setDeviceId(item.getId());
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
//做差集
List<Long> delDeviceList = oldDeviceList.stream().map(item -> {
if (!newDeviceMap.containsKey(item.getDeviceCode())) {
return item.getId();
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(updateDeviceLsit)) {
log.info("设备更新,size:{}", updateDeviceLsit.size());
deviceService.update(updateDeviceLsit);
}
if (!ObjectUtils.isEmpty(saveDeviceList)) {
log.info("设备新增,size:{}", saveDeviceList.size());
deviceService.save(saveDeviceList);
}
if (!ObjectUtils.isEmpty(delDeviceList)) {
log.info("设备删除,size:{}", delDeviceList.size());
deviceService.remove(delDeviceList, null);
}
}
} else {
log.info("设备列表查询异常,{}", JSON.toJSONString(deviceRest));
}
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
package com.mortals.xhx.module.device.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
/**
* 设备Dao
* 设备 DAO接口
*
* @author zxfei
* @date 2023-02-25
*/
public interface DeviceDao extends ICRUDDao<DeviceEntity,Long>{
}
package com.mortals.xhx.module.device.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.xhx.module.device.dao.DeviceDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
import org.springframework.stereotype.Repository;
/**
* 设备DaoImpl DAO接口
*
* @author zxfei
* @date 2023-02-25
*/
@Repository("deviceDao")
public class DeviceDaoImpl extends BaseCRUDDaoMybatis<DeviceEntity,Long> implements DeviceDao {
}
package com.mortals.xhx.module.device.model;
import com.mortals.xhx.module.device.model.vo.DeviceVo;
/**
* 设备实体对象
*
* @author zxfei
* @date 2023-02-25
*/
public class DeviceEntity extends DeviceVo {
private static final long serialVersionUID = 1L;
/**
* 设备id
*/
private Long deviceId;
/**
* 设备名称
*/
private String deviceName;
/**
* 设备编码
*/
private String deviceCode;
/**
* 设备的MAC地址
*/
private String deviceMac;
/**
* 站点Id
*/
private Long siteId;
/**
* 站点编号,来源基础服务平台
*/
private String siteCode;
/**
* 站点名称
*/
private String siteName;
/**
* 产品编码
*/
private String productCode;
/**
* 产品名称
*/
private String productName;
/**
* 设备来源(0.子设备,1.网关设备,2.直连设备)
*/
private Integer deviceSrc;
/**
* 经度
*/
private String lon;
/**
* 纬度
*/
private String lati;
/**
* 负责人
*/
private String leadingOfficial;
/**
* 联系电话
*/
private String leadingOfficialTelephone;
/**
* 设备状态 (0.未激活,1.离线,2.在线)
*/
private Integer deviceStatus;
/**
* 备注
*/
private String deviceRemark;
/**
* 设备来源(0.旧设备,1.新设备)
*/
private Integer source;
public DeviceEntity(){}
/**
* 获取 设备id
* @return Long
*/
public Long getDeviceId(){
return deviceId;
}
/**
* 设置 设备id
* @param deviceId
*/
public void setDeviceId(Long deviceId){
this.deviceId = deviceId;
}
/**
* 获取 设备名称
* @return String
*/
public String getDeviceName(){
return deviceName;
}
/**
* 设置 设备名称
* @param deviceName
*/
public void setDeviceName(String deviceName){
this.deviceName = deviceName;
}
/**
* 获取 设备编码
* @return String
*/
public String getDeviceCode(){
return deviceCode;
}
/**
* 设置 设备编码
* @param deviceCode
*/
public void setDeviceCode(String deviceCode){
this.deviceCode = deviceCode;
}
/**
* 获取 设备的MAC地址
* @return String
*/
public String getDeviceMac(){
return deviceMac;
}
/**
* 设置 设备的MAC地址
* @param deviceMac
*/
public void setDeviceMac(String deviceMac){
this.deviceMac = deviceMac;
}
/**
* 获取 站点Id
* @return Long
*/
public Long getSiteId(){
return siteId;
}
/**
* 设置 站点Id
* @param siteId
*/
public void setSiteId(Long siteId){
this.siteId = siteId;
}
/**
* 获取 站点编号,来源基础服务平台
* @return String
*/
public String getSiteCode(){
return siteCode;
}
/**
* 设置 站点编号,来源基础服务平台
* @param siteCode
*/
public void setSiteCode(String siteCode){
this.siteCode = siteCode;
}
/**
* 获取 站点名称
* @return String
*/
public String getSiteName(){
return siteName;
}
/**
* 设置 站点名称
* @param siteName
*/
public void setSiteName(String siteName){
this.siteName = siteName;
}
/**
* 获取 产品编码
* @return String
*/
public String getProductCode(){
return productCode;
}
/**
* 设置 产品编码
* @param productCode
*/
public void setProductCode(String productCode){
this.productCode = productCode;
}
/**
* 获取 产品名称
* @return String
*/
public String getProductName(){
return productName;
}
/**
* 设置 产品名称
* @param productName
*/
public void setProductName(String productName){
this.productName = productName;
}
/**
* 获取 设备来源(0.子设备,1.网关设备,2.直连设备)
* @return Integer
*/
public Integer getDeviceSrc(){
return deviceSrc;
}
/**
* 设置 设备来源(0.子设备,1.网关设备,2.直连设备)
* @param deviceSrc
*/
public void setDeviceSrc(Integer deviceSrc){
this.deviceSrc = deviceSrc;
}
/**
* 获取 经度
* @return String
*/
public String getLon(){
return lon;
}
/**
* 设置 经度
* @param lon
*/
public void setLon(String lon){
this.lon = lon;
}
/**
* 获取 纬度
* @return String
*/
public String getLati(){
return lati;
}
/**
* 设置 纬度
* @param lati
*/
public void setLati(String lati){
this.lati = lati;
}
/**
* 获取 负责人
* @return String
*/
public String getLeadingOfficial(){
return leadingOfficial;
}
/**
* 设置 负责人
* @param leadingOfficial
*/
public void setLeadingOfficial(String leadingOfficial){
this.leadingOfficial = leadingOfficial;
}
/**
* 获取 联系电话
* @return String
*/
public String getLeadingOfficialTelephone(){
return leadingOfficialTelephone;
}
/**
* 设置 联系电话
* @param leadingOfficialTelephone
*/
public void setLeadingOfficialTelephone(String leadingOfficialTelephone){
this.leadingOfficialTelephone = leadingOfficialTelephone;
}
/**
* 获取 设备状态 (0.未激活,1.离线,2.在线)
* @return Integer
*/
public Integer getDeviceStatus(){
return deviceStatus;
}
/**
* 设置 设备状态 (0.未激活,1.离线,2.在线)
* @param deviceStatus
*/
public void setDeviceStatus(Integer deviceStatus){
this.deviceStatus = deviceStatus;
}
/**
* 获取 备注
* @return String
*/
public String getDeviceRemark(){
return deviceRemark;
}
/**
* 设置 备注
* @param deviceRemark
*/
public void setDeviceRemark(String deviceRemark){
this.deviceRemark = deviceRemark;
}
/**
* 获取 设备来源(0.旧设备,1.新设备)
* @return Integer
*/
public Integer getSource(){
return source;
}
/**
* 设置 设备来源(0.旧设备,1.新设备)
* @param source
*/
public void setSource(Integer source){
this.source = source;
}
@Override
public int hashCode() {
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof DeviceEntity) {
DeviceEntity tmp = (DeviceEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
}
}
return false;
}
public String toString(){
StringBuilder sb = new StringBuilder("");
sb.append(",deviceId:").append(getDeviceId());
sb.append(",deviceName:").append(getDeviceName());
sb.append(",deviceCode:").append(getDeviceCode());
sb.append(",deviceMac:").append(getDeviceMac());
sb.append(",siteId:").append(getSiteId());
sb.append(",siteCode:").append(getSiteCode());
sb.append(",siteName:").append(getSiteName());
sb.append(",productCode:").append(getProductCode());
sb.append(",productName:").append(getProductName());
sb.append(",deviceSrc:").append(getDeviceSrc());
sb.append(",lon:").append(getLon());
sb.append(",lati:").append(getLati());
sb.append(",leadingOfficial:").append(getLeadingOfficial());
sb.append(",leadingOfficialTelephone:").append(getLeadingOfficialTelephone());
sb.append(",deviceStatus:").append(getDeviceStatus());
sb.append(",deviceRemark:").append(getDeviceRemark());
sb.append(",source:").append(getSource());
return sb.toString();
}
public void initAttrValue(){
this.deviceId = null;
this.deviceName = null;
this.deviceCode = null;
this.deviceMac = null;
this.siteId = null;
this.siteCode = null;
this.siteName = null;
this.productCode = null;
this.productName = null;
this.deviceSrc = 2;
this.lon = null;
this.lati = null;
this.leadingOfficial = null;
this.leadingOfficialTelephone = null;
this.deviceStatus = null;
this.deviceRemark = null;
this.source = 1;
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.model.vo;
import com.mortals.framework.model.BaseEntityLong;
/**
* 设备视图对象
*
* @author zxfei
* @date 2023-02-25
*/
public class DeviceVo extends BaseEntityLong {
}
\ No newline at end of file
package com.mortals.xhx.module.device.service;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.device.model.DeviceEntity;
/**
* DeviceService
*
* 设备 service接口
*
* @author zxfei
* @date 2023-02-25
*/
public interface DeviceService extends ICRUDService<DeviceEntity,Long>{
}
\ No newline at end of file
package com.mortals.xhx.module.device.service.impl;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.dept.DeptPdu;
import com.mortals.xhx.feign.dept.IDeptFeign;
import com.mortals.xhx.module.device.dao.DeviceMatterDatumDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceMatterDatumEntity;
import com.mortals.xhx.module.device.model.DeviceMatterDatumQuery;
import com.mortals.xhx.module.device.service.DeviceMatterDatumService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.matter.model.MatterDatumEntity;
import com.mortals.xhx.module.matter.model.MatterDatumQuery;
import com.mortals.xhx.module.matter.model.MatterEntity;
import com.mortals.xhx.module.matter.service.MatterDatumService;
import com.mortals.xhx.module.matter.service.MatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
/**
* DeviceMatterDatumService
* 设备事项申请材料业务 service实现
*
* @author zxfei
* @date 2023-02-25
*/
@Service("deviceMatterDatumService")
public class DeviceMatterDatumServiceImpl extends AbstractCRUDServiceImpl<DeviceMatterDatumDao, DeviceMatterDatumEntity, Long> implements DeviceMatterDatumService {
@Autowired
private MatterService matterService;
@Autowired
private DeviceService deviceService;
@Autowired
private MatterDatumService matterDatumService;
@Autowired
private IDeptFeign deptFeign;
@Override
protected void findAfter(DeviceMatterDatumEntity params, PageInfo pageInfo, Context context, List<DeviceMatterDatumEntity> list) throws AppException {
//super.findAfter(params, pageInfo, context, list);
list.forEach(item->{
List<MatterDatumEntity> matterDatumEntities = matterDatumService.find(new MatterDatumQuery().matterId(item.getMatterId()));
if(!ObjectUtils.isEmpty(matterDatumEntities)){
item.setMatterDatumList(matterDatumEntities);
}else{
item.setMatterDatumList(new ArrayList<>());
}
});
}
@Override
protected void saveBefore(DeviceMatterDatumEntity entity, Context context) throws AppException {
super.saveBefore(entity, context);
int count = this.getDao().getCount(new DeviceMatterDatumQuery().deviceId(entity.getDeviceId()).matterId(entity.getMatterId()));
if(count>0){
throw new AppException("当前设备关联事项已存在,不能新增!");
}
if(!ObjectUtils.isEmpty(entity.getMatterId())){
MatterEntity matterEntity = matterService.get(entity.getMatterId());
if(!ObjectUtils.isEmpty(matterEntity)){
entity.setMatterCode(matterEntity.getMatterNo());
entity.setMatterName(matterEntity.getMatterName());
entity.setMateriaFullName(matterEntity.getMatterFullName());
entity.setIsRecommend(matterEntity.getIsRecommend());
entity.setSource(matterEntity.getSource());
entity.setSort(matterEntity.getSort());
entity.setDeptId(matterEntity.getDeptId());
DeptPdu deptPdu = new DeptPdu();
deptPdu.setDeptNumber(matterEntity.getDeptCode());
deptPdu.setSiteId(entity.getSiteId());
Rest<RespData<List<DeptPdu>>> rest = deptFeign.list(deptPdu);
if(YesNoEnum.YES.getValue()==rest.getCode()){
List<DeptPdu> data = rest.getData().getData();
if(!ObjectUtils.isEmpty(data)){
entity.setDeptId(data.get(0).getId());
}
}
entity.setDeptCode(matterEntity.getDeptCode());
entity.setDeptName(matterEntity.getDeptName());
}
}
if(!ObjectUtils.isEmpty(entity.getDeviceId())){
DeviceEntity deviceEntity = deviceService.get(entity.getDeviceId());
if(!ObjectUtils.isEmpty(deviceEntity)){
entity.setDeviceCode(deviceEntity.getDeviceCode());
entity.setDeviceName(deviceEntity.getDeviceName());
}
}
}
@Override
protected void updateBefore(DeviceMatterDatumEntity entity, Context context) throws AppException {
super.updateBefore(entity, context);
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.service.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.device.dao.DeviceDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.matter.service.MatterDatumService;
import com.mortals.xhx.module.matter.service.MatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* DeviceService
* 设备 service实现
*
* @author zxfei
* @date 2023-02-25
*/
@Service("deviceService")
public class DeviceServiceImpl extends AbstractCRUDServiceImpl<DeviceDao, DeviceEntity, Long> implements DeviceService {
@Autowired
private MatterService matterService;
@Autowired
private MatterDatumService matterDatumService;
@Override
protected void saveBefore(DeviceEntity entity, Context context) throws AppException {
super.saveBefore(entity, context);
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.web;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
*
* 设备
*
* @author zxfei
* @date 2023-02-25
*/
@RestController
@RequestMapping("device")
public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceService,DeviceEntity,Long> {
@Autowired
private ParamService paramService;
public DeviceController(){
super.setModuleDesc( "设备");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "deviceSrc", paramService.getParamBySecondOrganize("Device","deviceSrc"));
this.addDict(model, "deviceStatus", paramService.getParamBySecondOrganize("Device","deviceStatus"));
this.addDict(model, "source", paramService.getParamBySecondOrganize("Device","source"));
super.init(model, context);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment