Commit cea68f20 authored by 赵啸非's avatar 赵啸非

添加样表设备列表

parent 6f742a77
......@@ -13,9 +13,9 @@ import java.util.List;
/**
* 设备 Feign接口
* @author zxfei
* @date 2022-10-26
* @date 2023-02-25
*/
@FeignClient(name = "device-manager", path = "/m", fallbackFactory = DeviceFeignFallbackFactory.class)
@FeignClient(name = "sampleform-platform", path = "/sampleform", fallbackFactory = DeviceFeignFallbackFactory.class)
public interface IDeviceFeign extends IFeign {
......
This diff is collapsed.
......@@ -255,5 +255,35 @@ CREATE TABLE mortals_xhx_sample_bill(
,KEY `operTime` (`operTime`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='样报服务';
-- ----------------------------
-- 设备表
-- ----------------------------
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.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 设备来源(0.子设备,1.网关设备,2.直连设备)枚举类
*
* @author zxfei
*/
public enum DeviceSrcEnum {
子设备(0, "子设备"),
网关设备(1, "网关设备"),
直连设备(2, "直连设备");
private Integer value;
private String desc;
DeviceSrcEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static DeviceSrcEnum getByValue(Integer value) {
for (DeviceSrcEnum deviceSrcEnum : DeviceSrcEnum.values()) {
if (deviceSrcEnum.getValue() == value) {
return deviceSrcEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (DeviceSrcEnum item : DeviceSrcEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 设备状态 (0.未激活,1.离线,2.在线)枚举类
*
* @author zxfei
*/
public enum DeviceStatusEnum {
未激活(0, "未激活"),
离线(1, "离线"),
在线(2, "在线");
private Integer value;
private String desc;
DeviceStatusEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static DeviceStatusEnum getByValue(Integer value) {
for (DeviceStatusEnum deviceStatusEnum : DeviceStatusEnum.values()) {
if (deviceStatusEnum.getValue() == value) {
return deviceStatusEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (DeviceStatusEnum item : DeviceStatusEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
......@@ -4,13 +4,13 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* 事项来源 (0.政务网,1.自定义)枚举类
* 设备来源(0.旧设备,1.新设备)枚举类
*
* @author zxfei
*/
public enum SourceEnum {
政务网(0, "政务网"),
自定义(1, "自定义");
旧设备(0, "旧设备"),
新设备(1, "新设备");
private Integer value;
private String desc;
......
package com.mortals.xhx.daemon.task;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonAlias;
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.pdu.site.SiteMatterPdu;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.feign.device.IDeviceFeign;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.feign.site.ISiteMatterFeign;
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.sheet.model.SheetMatterEntity;
import com.mortals.xhx.module.sheet.model.SheetMatterQuery;
import com.mortals.xhx.module.sheet.service.SheetMatterService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
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("SyncSiteMatterTask")
public class SyncSiteDeviceTaskImpl implements ITaskExcuteService {
@Autowired
private ISiteFeign siteFeign;
@Autowired
private IDeviceFeign deviceFeign;
@Autowired
private DeviceService deviceService;
@Override
public void excuteTask(ITask task) throws AppException {
log.info("开始同步设备列表!");
SitePdu sitePdu = new SitePdu();
sitePdu.setId(1L);
Rest<List<SitePdu>> siteRest = siteFeign.getFlatSitesBySiteId(sitePdu);
if (siteRest.getCode() == YesNoEnum.YES.getValue()) {
log.info("总数量:{}", siteRest.getData().size());
siteRest.getData().forEach(site -> {
DevicePdu devicePdu = new DevicePdu();
devicePdu.setProductCode("ybj");
devicePdu.setSize(-1);
Rest<RespData<List<DevicePdu>>> deviceRest = deviceFeign.list(devicePdu);
if (YesNoEnum.YES.getValue() == deviceRest.getCode()) {
List<DevicePdu> devicePduList = deviceRest.getData().getData();
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));
List<DeviceEntity> updateDeviceLsit = newDeviceList.stream().map(item -> {
if (oldDeviceMap.containsKey(item.getDeviceCode())) {
item.setId(oldDeviceMap.get(item.getDeviceCode()).getId());
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.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
}
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);
}
}
} else {
log.info("设备列表查询异常,{}", JSON.toJSONString(deviceRest));
}
});
} else {
log.info("站点列表查询异常,{}", JSON.toJSONString(siteRest));
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
......@@ -2,14 +2,15 @@ package com.mortals.xhx.module.device.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
import java.util.List;
/**
* 设备Dao
* 设备 DAO接口
*
* @author zxfei
* @date 2022-06-27
* @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 org.springframework.stereotype.Repository;
import com.mortals.xhx.module.device.dao.DeviceDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
import org.springframework.stereotype.Repository;
import java.util.Date;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import java.util.List;
/**
* 设备DaoImpl DAO接口
*
* @author zxfei
* @date 2022-06-27
* @date 2023-02-25
*/
@Repository("deviceDao")
public class DeviceDaoImpl extends BaseCRUDDaoMybatis<DeviceEntity,Long> implements DeviceDao {
......
package com.mortals.xhx.module.device.model.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
import org.apache.poi.ss.usermodel.PictureData;
import com.mortals.xhx.module.device.model.DeviceEntity;
import java.util.ArrayList;
import java.util.List;
/**
* 设备视图对象
*
* @author zxfei
* @date 2022-07-01
* @date 2023-02-25
*/
@Data
public class DeviceVo extends BaseEntityLong {
/**
* 唯一标识
*/
private String token;
/**
* 平台编码
*/
private String platformCode;
/**
* 产品编码
*/
@Excel(name = "产品类型",cacheDict = "productDict" ,type = Excel.Type.IMPORT)
private String productCode;
/**
* 是否通知第三方
*/
private Boolean switchSend=true;
/**
* 设备图片附件
*/
@Excel(name = "设备图片", type = Excel.Type.IMPORT, cellType = Excel.ColumnType.IMAGE)
@JSONField(deserialize = false,serialize = false)
@JsonIgnore
private PictureData picObj;
/** 主键ID,主键,自增长列表 */
private List <Long> idList;
/**
* 产品列表
*/
private List <Long> productIdList;
private List <Integer> deviceStatusList;
}
\ 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 2022-03-09
* @date 2023-02-25
*/
public interface DeviceService extends ICRUDService<DeviceEntity,Long> {
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.ap.GlobalSysInfo;
import com.mortals.framework.common.Rest;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.Constant;
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.dao.DeviceDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* DeviceService
* 设备 service实现
*
* @author zxfei
* @date 2022-03-09
*/
* DeviceService
* 设备 service实现
*
* @author zxfei
* @date 2023-02-25
*/
@Service("deviceService")
@Slf4j
public class DeviceServiceImpl extends AbstractCRUDServiceImpl<DeviceDao, DeviceEntity, Long> implements DeviceService {
@Autowired
private IDeviceFeign deviceFeign;
@Override
public Result<DeviceEntity> find(DeviceEntity entity, PageInfo pageInfo, Context context) throws AppException {
Result<DeviceEntity> result = new Result();
DevicePdu devicePdu = new DevicePdu();
BeanUtils.copyProperties(entity, devicePdu, BeanUtil.getNullPropertyNames(entity));
String productName = GlobalSysInfo.getParamValue(Constant.PARAMS_PRODUCT_NAME, "样表机");
devicePdu.setProductName(productName);
Rest<RespData<List<DevicePdu>>> rest = deviceFeign.list(devicePdu);
if (rest.getCode().equals(YesNoEnum.YES.getValue())) {
List<DeviceEntity> collect = rest.getData().getData().stream().map(item -> {
DeviceEntity deviceEntity = new DeviceEntity();
BeanUtils.copyProperties(item, deviceEntity, BeanUtil.getNullPropertyNames(item));
return deviceEntity;
}).collect(Collectors.toList());
result.setList(collect);
result.setDict(rest.getDict());
}
return result;
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.web;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
* 设备
*
* @author zxfei
* @date 2022-06-27
*/
*
* 设备
*
* @author zxfei
* @date 2023-02-25
*/
@RestController
@RequestMapping("device")
@Slf4j
public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceService, DeviceEntity, Long> {
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
###登录
POST {{baseUrl}}/login/login
Content-Type: application/json
{
"loginName":"admin",
"password":"admin",
"securityCode":"8888"
}
> {%
client.global.set("SmsSet_id", JSON.parse(response.body).data.id);
client.global.set("authToken", JSON.parse(response.body).data.token);
%}
###设备列表
POST {{baseUrl}}/device/list
Authorization: {{authToken}}
Content-Type: application/json
{
"deviceId":157,
"deviceName":"1e0x2f",
"deviceCode":"kfttm3",
"deviceSrc":2,
"deviceStatus":848,
"page":1,
"size":10
}
###设备更新与保存
POST {{baseUrl}}/device/save
Authorization: {{authToken}}
Content-Type: application/json
{
"deviceId":213,
"deviceName":"o8f2uk",
"deviceCode":"hojug5",
"deviceMac":"qblxmm",
"siteId":624,
"siteCode":"vwcmg0",
"siteName":"1ezg8h",
"productCode":"gu9tca",
"productName":"wmia1a",
"deviceSrc":2,
"lon":"xw3n3b",
"lati":"296er9",
"leadingOfficial":"mrsrnp",
"leadingOfficialTelephone":"mh03sk",
"deviceStatus":402,
"deviceRemark":"ircxre",
"source":1,
}
> {%
client.global.set("Device_id", JSON.parse(response.body).data.id);
%}
###设备查看
GET {{baseUrl}}/device/info?id={{Device_id}}
Authorization: {{authToken}}
Accept: application/json
###设备编辑
GET {{baseUrl}}/device/edit?id={{Device_id}}
Authorization: {{authToken}}
Accept: application/json
###设备删除
GET {{baseUrl}}/device/delete?id={{Device_id}}
Authorization: {{authToken}}
Accept: application/json
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