Commit 3c8f7551 authored by 赵啸非's avatar 赵啸非

添加产品升级功能

parent 61dc3b0a
......@@ -30,6 +30,21 @@ export default {
toView(row) {
this.$refs.drawerform.view(row);
},
selectDeviceVersiion(row) {
this.$post("/product/upGrade", {
id: row.id,
})
.then((res) => {
if (res.code == 1) {
this.$message.success("产品升级命令下发成功!");
}
})
.catch((error) => {
this.$message.error(error.message);
});
},
},
// beforeRouteEnter(to, from, next) {next(vm => {
// // 通过 `vm` 访问组件实例
......@@ -68,6 +83,7 @@ export default {
width: 240,
formatter: (row) => {
return (
<div>
<table-buttons
noAdd
row={row}
......@@ -75,6 +91,18 @@ export default {
onView={this.toView}
onDel={this.toDel}
/>
<span> </span>
<el-button
size="mini"
type="text"
icon="el-icon-open"
onClick={() => {
this.selectDeviceVersiion(row);
}}
>
升级
</el-button>
</div>
);
},
},
......
......@@ -428,12 +428,11 @@ public class DeviceApiController {
DeviceResp deviceResp = new DeviceResp();
try {
DeviceEntity deviceEntity = checkDeviceExist(req);
//查找版本号最大的.
ProductVersionQuery productVersionQuery = new ProductVersionQuery();
productVersionQuery.setProductId(deviceEntity.getProductId());
productVersionQuery.setOrderColList(Arrays.asList(new OrderCol("version")));
productVersionQuery.setOrderKind(OrderCol.ASCENDING);
productVersionQuery.setOrderKind(OrderCol.DESCENDING);
ProductVersionEntity productVersionEntity = productVersionService.selectOne(productVersionQuery);
if (ObjectUtils.isEmpty(productVersionEntity))
......
......@@ -479,7 +479,6 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override
public List<DeviceMapEntity> deviceMap(DeviceEntity query, Context context) {
Rest<SitePdu> info = siteFeign.info(query.getSiteId());
if (info.getCode() == YesNoEnum.YES.getValue()) {
SitePdu sitePdu = info.getData();
......
package com.mortals.xhx.module.product.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.product.model.ProductEntity;
/**
......@@ -11,4 +12,6 @@ import com.mortals.xhx.module.product.model.ProductEntity;
*/
public interface ProductService extends ICRUDService<ProductEntity,Long>{
void upGrade(Long productId, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.product.service.impl;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlPath;
import cn.hutool.core.util.URLUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.rsp.ProductVersionInfo;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.common.utils.BeanUtil;
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.service.PlatformService;
import com.mortals.xhx.module.product.model.ProductQuery;
import com.mortals.xhx.module.product.model.ProductVersionEntity;
import com.mortals.xhx.module.product.model.ProductVersionQuery;
import com.mortals.xhx.module.product.service.ProductVersionService;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import com.mortals.xhx.queue.TopicPartitionInfo;
import com.sun.jndi.toolkit.url.UrlUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.product.dao.ProductDao;
......@@ -16,36 +36,49 @@ import com.mortals.xhx.module.product.service.ProductService;
import org.springframework.util.ObjectUtils;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_HTTP_URL;
import static com.mortals.xhx.common.key.ErrorCode.DEVICE_VERSION_UNEXIST;
import static com.mortals.xhx.common.key.ErrorCode.DEVICE_VERSION_UNEXIST_CONTENT;
/**
* ProductService
* 产品 service实现
*
* @author zxfei
* @date 2022-06-27
*/
* ProductService
* 产品 service实现
*
* @author zxfei
* @date 2022-06-27
*/
@Service("productService")
public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, ProductEntity, Long> implements ProductService {
@Autowired
private ProductVersionService productVersionService;
@Autowired
private DeviceService deviceService;
@Autowired
private MessageService messageService;
@Autowired
private PlatformService platformService;
@Override
protected void saveBefore(ProductEntity entity, Context context) throws AppException {
//新增产品编码不能重复
ProductEntity productEntity = this.selectOne(new ProductQuery().productCode(entity.getProductCode()));
if(!ObjectUtils.isEmpty(productEntity))throw new AppException("当前产品编码已存在!");
if (!ObjectUtils.isEmpty(productEntity)) throw new AppException("当前产品编码已存在!");
//默认时,需拼接homeUrl
updateDeviceHomeUrl(entity);
super.saveBefore(entity, context);
}
@Override
protected void updateBefore(ProductEntity entity, Context context) throws AppException {
ProductEntity productEntity = this.get(entity.getId());
if(!productEntity.getProductCode().equals(entity.getProductCode())){
if (!productEntity.getProductCode().equals(entity.getProductCode())) {
ProductEntity productEntity1 = this.selectOne(new ProductQuery().productCode(entity.getProductCode()));
if(!ObjectUtils.isEmpty(productEntity1))throw new AppException("当前产品编码已存在!");
if (!ObjectUtils.isEmpty(productEntity1)) throw new AppException("当前产品编码已存在!");
}
updateDeviceHomeUrl(entity);
super.updateBefore(entity, context);
......@@ -53,7 +86,7 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
private void updateDeviceHomeUrl(ProductEntity entity) {
if (!ObjectUtils.isEmpty(entity.getSkinName())) {
String path = UrlPath.of(Constant.DEVICE_BASEHOME_PATH,Charset.defaultCharset())
String path = UrlPath.of(Constant.DEVICE_BASEHOME_PATH, Charset.defaultCharset())
.add(entity.getProductCode())
.add(entity.getSkinName())
.toString();
......@@ -62,19 +95,48 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
}
public static void main(String[] args) {
//String path = URLUtil.completeUrl("http://192.168.0.98:11091/homeDeviceUrl", "pdj");
//System.out.println("path:"+path);
String path =UrlBuilder.create().setHost("http").setHost("192.168.0.98").setPort(11091).addPath("pdj").build();
@Override
public void upGrade(Long productId, Context context) {
ProductVersionQuery productVersionQuery = new ProductVersionQuery();
productVersionQuery.setProductId(productId);
productVersionQuery.setOrderColList(Arrays.asList(new OrderCol("version")));
productVersionQuery.setOrderKind(OrderCol.DESCENDING);
ProductVersionEntity productVersionEntity = productVersionService.selectOne(productVersionQuery);
if (ObjectUtils.isEmpty(productVersionEntity))
throw new AppException(DEVICE_VERSION_UNEXIST, DEVICE_VERSION_UNEXIST_CONTENT);
//查询设备 构建下发信息
ProductEntity productEntity = this.get(productVersionEntity.getProductId());
if (ObjectUtils.isEmpty(productEntity)) {
throw new AppException("当前设备未配置所属产品,请在后台配置后再激活!");
}
PlatformEntity platformEntity = platformService.get(productEntity.getPlatformId());
if (ObjectUtils.isEmpty(platformEntity)) {
throw new AppException("当前设备未配置所属系统平台,请在后台配置后再激活!");
}
String exchangeName = platformEntity.getPlatformSn() + Constant.EXCHANGE_SPLIT + productEntity.getProductCode();
List<DeviceEntity> deviceList = deviceService.find(new DeviceQuery().productId(productId));
deviceList.forEach(deviceEntity -> {
TopicPartitionInfo info = TopicPartitionInfo.builder().exchangeName(exchangeName).topic(Constant.DOWN_TOPIC + deviceEntity.getDeviceCode()).build();
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, Constant.MESSAGETYPE_UPGREAD);
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode());
ProductVersionInfo productVersionInfo = new ProductVersionInfo();
BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity));
buildDownloadUrl(productVersionEntity,productVersionInfo);
deviceService.sendDeviceMessage(deviceEntity, info, header, JSON.toJSONString(productVersionInfo), null, null);
});
path = UrlPath.of("homeDeviceUrl", Charset.defaultCharset()).add("pdj").toString();
}
private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo) {
String download = "";
System.out.println("path:"+path);
if (!ObjectUtils.isEmpty(productVersionEntity.getFilePath())) {
download = productVersionEntity.getFilePath();
}
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091");
productVersionInfo.setDownloadUrl(UrlBuilder.of(domain).addPath(download).toString());
}
}
\ No newline at end of file
......@@ -10,11 +10,15 @@ import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.skin.SkinBasePdu;
import com.mortals.xhx.feign.skin.ISkinBaseFeign;
import com.mortals.xhx.module.device.model.DeviceEntity;
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.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -30,6 +34,7 @@ import java.util.stream.Collectors;
*/
@RestController
@RequestMapping("product")
@Slf4j
public class ProductController extends BaseCRUDJsonBodyMappingController<ProductService, ProductEntity, Long> {
@Autowired
......@@ -46,7 +51,7 @@ public class ProductController extends BaseCRUDJsonBodyMappingController<Product
//获取所有产品皮肤 分组显示
Rest<RespData<List<SkinBasePdu>>> resp = skinBaseFeign.list(new SkinBasePdu());
if (resp.getCode() == YesNoEnum.YES.getValue()) {
Map<String, Map<String, String>> skinProductCodeMap = resp.getData().getData().stream().collect(Collectors.groupingBy(x -> x.getProductCode(), Collectors.toMap(a -> a.getImageResolution()==null?"":a.getImageResolution(), b -> b.getImageResolutionValue()==null?"":b.getImageResolutionValue(),(o,n)->n)));
Map<String, Map<String, String>> skinProductCodeMap = resp.getData().getData().stream().collect(Collectors.groupingBy(x -> x.getProductCode(), Collectors.toMap(a -> a.getImageResolution() == null ? "" : a.getImageResolution(), b -> b.getImageResolutionValue() == null ? "" : b.getImageResolutionValue(), (o, n) -> n)));
this.addDict(model, "skinProductCodeMap", skinProductCodeMap);
}
......@@ -55,6 +60,24 @@ public class ProductController extends BaseCRUDJsonBodyMappingController<Product
super.init(model, context);
}
/**
* 产品升级版本
*/
@PostMapping(value = "upGrade")
public Rest<Void> upGrade(@RequestBody ProductEntity productEntity) {
log.info("产品升级版本:{}", productEntity.getProductName());
String busiDesc = this.getModuleDesc() + "升级版本";
Rest<Void> rest = Rest.ok(busiDesc + " 【成功】");
try {
this.service.upGrade(productEntity.getId(), getContext());
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error("产品升级版本", e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
public static void main(String[] args) {
System.out.println(IdUtil.objectId());
......
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