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

修改设备导入功能

parent b36ac61e
......@@ -193,9 +193,6 @@ export default {
},
created() {
let today = new Date();
console.log("year:",today.getFullYear())
let query = {
year: today.getFullYear(),
month: today.getMonth()+1,
......@@ -208,7 +205,6 @@ export default {
if (res.code == 1) {
console.log("res", res);
this.statData = res.data.data[0];
console.log("statData", this.statData);
}
this.loading = false;
......
......@@ -10,7 +10,7 @@
<el-row>
<Field label="设备名称" prop="deviceName" v-model="form.deviceName" placeholder="请输入设备名称"/>
<Field label="SN码" prop="deviceCode" v-model="form.deviceCode" placeholder="请输入设备SN码"/>
<Field label="设备编码" prop="deviceCode" v-model="form.deviceCode" placeholder="请输入设备编码码"/>
<Field label="MAC地址" prop="deviceMac" v-model="form.deviceMac" placeholder="请输入设备的MAC地址"/>
<Field label="平台类型" prop="platformId" v-model="form.platformId" type="select" :enumData="dict.platformId" placeholder="请选择平台类型"/>
<Field label="产品类型" prop="productId" v-model="form.productId" type="select" :enumData="dict.productId" placeholder="请选择产品类型"/>
......@@ -77,6 +77,9 @@
{required: true,message: "请输入设备名称", trigger: "blur" },
{max: 20,message: "最多只能录入20个字符",trigger: "blur",},
],
deviceCode: [
{required: true,message: "请输入设备编码", trigger: "blur" },
],
platformId: [
{required: true,message: "请选择平台", trigger: "blur" },
],
......
......@@ -80,7 +80,7 @@
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport"
:action="upload.url + '?siteId=' + siteId"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
......@@ -154,7 +154,7 @@ export default {
/** 下载模板操作 */
downloadTemplate() {
this.isExport = true;
this.$download("/device/downloadTemplate", {}, { type: "excel" })
this.$download("/device/downloadTemplate", {}, { type: "excel",fileName:"设备导入模板" })
.then(() => (this.isExport = false))
.catch((error) => {
this.isExport = false;
......@@ -187,7 +187,7 @@ export default {
"deviceName": this.$route.query["deviceName"],
"siteId": this.$route.query["siteId"],
},
{ type: "excel" }
{ type: "excel" ,fileName:"设备表"}
)
.then(() => (this.isExport = false))
.catch((error) => {
......@@ -357,7 +357,7 @@ export default {
<div>
<table-buttons
noAdd
noEdit
row={row}
onEdit={this.toEdit}
onView={this.toView}
......
......@@ -149,7 +149,7 @@
content-class-name="contentClass"
>
<ImageUpload v-model="form.devicePhotoPath" prePath="/file/preview" />
<ImagePreview :src="form.devicePhotoPath" />
</el-descriptions-item>
......
......@@ -14,4 +14,11 @@ public class RedisKey {
*/
public static final String KEY_DEVICE_ONLINE_CACHE = "device:online:";
public static final String KEY_SITE_CACHE = "siteDict";
public static final String KEY_PLATFORM_CACHE = "platformDict";
public static final String KEY_PRODUCT_CACHE = "productDict";
}
package com.mortals.xhx.daemon.applicationservice;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.springcloud.service.IApplicationService;
import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.utils.SendTaskThreadPool;
import com.mortals.xhx.common.utils.SmsQueueManager;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.alarm.model.AlarmSmsSendEntity;
import com.mortals.xhx.module.platform.model.PlatformQuery;
import com.mortals.xhx.module.platform.service.PlatformService;
import com.mortals.xhx.module.product.model.ProductQuery;
import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.utils.IotThreadFactory;
import lombok.extern.slf4j.Slf4j;
......@@ -19,21 +29,31 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static com.mortals.xhx.common.key.RedisKey.*;
@Component
@Slf4j
public class DeviceStartService implements IApplicationService {
public class DeviceStartService implements IApplicationStartedService {
@Autowired
private SendTaskThreadPool sendTaskThreadPool;
protected Boolean stopped = false;
@Autowired
private ICacheService cacheService;
@Autowired
private ISiteFeign siteFeign;
@Autowired
private PlatformService platformService;
@Autowired
private ProductService productService;
@Override
public void start() {
log.info("初始化发送线程数量");
sendTaskThreadPool.init(20);
//启动短信发送响应更新线程
sendTaskThreadPool.execute(() -> {
int waitTime = 1000;
while (!stopped) {
......@@ -55,6 +75,27 @@ public class DeviceStartService implements IApplicationService {
});
//初始化站点缓存
String resp = siteFeign.list(new SitePdu());
JSONObject jsonObject = JSONObject.parseObject(resp);
if (jsonObject.getInteger("code") == 1) {
List<SitePdu> sitePduList = jsonObject.getJSONObject("data").getObject("data", new TypeReference<List<SitePdu>>() {
});
sitePduList.stream().forEach(sitePdu -> {
cacheService.hset(KEY_SITE_CACHE, sitePdu.getId().toString(), sitePdu.getSiteName());
});
}
productService.find(new ProductQuery()).stream().forEach(item -> {
cacheService.hset(KEY_PRODUCT_CACHE, item.getProductCode(), item.getProductName());
});
platformService.find(new PlatformQuery()).stream().forEach(item -> {
cacheService.hset(KEY_PLATFORM_CACHE, item.getPlatformSn(), item.getPlatformName());
});
log.info("开始服务..[配置已加载完成,但部分框架还未初始化,比如:Kafka]");
}
......@@ -63,4 +104,9 @@ public class DeviceStartService implements IApplicationService {
log.info("停止服务..");
}
@Override
public int getOrder() {
return 50;
}
}
......@@ -27,7 +27,7 @@ public class DeviceEntity extends DeviceVo {
/**
* 设备编码,SN码等,默认为MAC地址
*/
@Excel(name = "设备编码,SN码等,默认为MAC地址")
@Excel(name = "设备编码")
private String deviceCode;
/**
* 设备的MAC地址
......@@ -36,6 +36,7 @@ public class DeviceEntity extends DeviceVo {
/**
* 站点Id,来源基础服务平台
*/
//@Excel(name = "站点名称",cacheDict = "siteDict")
private Long siteId;
/**
* 站点编号,来源基础服务平台
......@@ -68,7 +69,6 @@ public class DeviceEntity extends DeviceVo {
/**
* 设备生产厂商名称
*/
@Excel(name = "设备生产厂商名称")
private String deviceFirmname;
/**
* 设备来源(0.子设备,1.网关设备,2.直连设备)
......@@ -114,6 +114,7 @@ public class DeviceEntity extends DeviceVo {
/**
* 设备图片
*/
@Excel(name = "设备图片",height = 90, type = Excel.Type.EXPORT, cellType = Excel.ColumnType.IMAGE)
private String devicePhotoPath;
/**
* 设备访问ip
......
package com.mortals.xhx.module.device.model.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.device.model.DeviceEntity;
import lombok.Data;
import org.apache.poi.ss.usermodel.PictureData;
import java.util.ArrayList;
import java.util.List;
......@@ -22,14 +26,13 @@ public class DeviceVo extends BaseEntityLong {
/**
* 平台编码
*/
@Excel(name = "平台编码",combo = {"排号系统"}, readConverterExp = "phxt=排号系统")
@Excel(name = "平台",cacheDict = "platformDict")
private String platformCode;
/**
* 产品编码
*/
@Excel(name = "产品编码",combo = {"排队机", "窗口屏", "呼叫器", "集中显示屏", "导视机", "评价器", "自助服务终端", "填单机", "样表机"}
, readConverterExp = "pdj=排队机,ckp=窗口屏,hjq=呼叫器,jzxsp=集中显示屏,dsj=导视机,pjq=评价器,zzfwzd=自助服务终端,tdj=填单机,ybj=样表机")
@Excel(name = "产品",cacheDict = "productDict")
private String productCode;
......@@ -37,4 +40,12 @@ public class DeviceVo extends BaseEntityLong {
* 是否通知第三方
*/
private Boolean switchSend=true;
/**
* 设备图片附件
*/
@Excel(name = "设备图片", type = Excel.Type.IMPORT, cellType = Excel.ColumnType.IMAGE)
@JSONField(deserialize = false,serialize = false)
@JsonIgnore
private PictureData picObj;
}
\ No newline at end of file
......@@ -19,8 +19,10 @@ 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.platform.model.PlatformEntity;
import com.mortals.xhx.module.platform.model.PlatformQuery;
import com.mortals.xhx.module.platform.service.PlatformService;
import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.model.ProductQuery;
import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.queue.*;
import lombok.extern.slf4j.Slf4j;
......@@ -283,13 +285,38 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override
protected void saveBefore(DeviceEntity entity, Context context) throws AppException {
if (ObjectUtils.isEmpty(entity.getDeviceCode())) {
throw new AppException("设备编码不能为空!");
}
entity.setDeviceCode(StrUtil.replace(entity.getDeviceCode(), ":", "-"));
if (ObjectUtils.isEmpty(entity.getDeviceMac())) {
entity.setDeviceMac(entity.getDeviceCode());
}
//产品编码唯一
DeviceEntity deviceEntity = this.selectOne(new DeviceQuery().deviceCode(entity.getDeviceCode()));
if (!ObjectUtils.isEmpty(deviceEntity)) {
throw new AppException("设备编码重复!");
}
entity.setDeviceCode(StrUtil.replace(entity.getDeviceCode(),":","-"));
if (!ObjectUtils.isEmpty(entity.getPlatformCode())) {
PlatformEntity platformEntity = platformService.selectOne(new PlatformQuery().platformSn(entity.getPlatformCode()));
if (!ObjectUtils.isEmpty(platformEntity)) {
entity.setPlatformId(platformEntity.getId());
entity.setPlatformName(platformEntity.getPlatformName());
}
}
if (!ObjectUtils.isEmpty(entity.getProductCode())) {
ProductEntity productEntity = productService.selectOne(new ProductQuery().productCode(entity.getProductCode()));
if (!ObjectUtils.isEmpty(productEntity)) {
entity.setProductId(productEntity.getId());
entity.setProductName(productEntity.getProductName());
}
}
super.saveBefore(entity, context);
......
package com.mortals.xhx.module.device.web;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.util.FileUtil;
import com.mortals.framework.utils.ReflectUtils;
import com.mortals.framework.utils.poi.ExcelUtil;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
......@@ -32,7 +37,10 @@ import com.mortals.xhx.queue.TopicPartitionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -60,6 +68,8 @@ public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceSe
private PlatformService platformService;
@Autowired
private MessageService messageService;
@Autowired
private UploadService uploadService;
public DeviceController() {
super.setModuleDesc("设备");
......@@ -244,4 +254,32 @@ public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceSe
return jsonObject.toJSONString();
}
@Override
public void doImportDataBefore(List<DeviceEntity> list, boolean updateSupport, Context context) throws AppException {
String siteId = request.getParameter("siteId");
if(!ObjectUtils.isEmpty(siteId)){
list.stream().forEach(item->item.setSiteId(Convert.toLong(siteId,0L)));
}
list.stream().peek(item -> {
if (!ObjectUtils.isEmpty(item.getPicObj())) {
String extension = item.getPicObj().suggestFileExtension();
String newName = "/file/uploadfile/" + new Date().getTime() + "." + extension;
String filePath = uploadService.getFilePath(newName);
try {
boolean bool = FileUtil.write(filePath, item.getPicObj().getData(), true, true);
if (bool) {
item.setDevicePhotoPath(newName);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
).count();
super.doImportDataBefore(list, updateSupport, 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