|
@@ -15,8 +15,10 @@ import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
import com.hfln.portal.common.dto.data.dic.DicDTO;
|
|
|
import com.hfln.portal.common.dto.data.menu.MenuListDTO;
|
|
|
import com.hfln.portal.common.dto.data.menu.MenuTreeDTO;
|
|
|
-import com.hfln.portal.common.dto.data.role.RoleListDTO;
|
|
|
+import com.hfln.portal.common.dto.data.news.NewsDTO;
|
|
|
+import com.hfln.portal.common.dto.data.oss.OssFileDTO;
|
|
|
import com.hfln.portal.common.dto.data.parameter.ParameterDTO;
|
|
|
+import com.hfln.portal.common.dto.data.role.RoleListDTO;
|
|
|
import com.hfln.portal.common.dto.data.rolemenu.MenuSimpleTreeDTO;
|
|
|
import com.hfln.portal.common.dto.data.rolemenu.RoleMenuTreeDTO;
|
|
|
import com.hfln.portal.common.request.device.DeviceListQueryReq;
|
|
@@ -50,7 +52,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -61,6 +62,9 @@ public class WebGatewayImpl implements WebGateway {
|
|
|
@Value("${oss.ota-download-url-pre}")
|
|
|
private String otaDownloadUrlPre;
|
|
|
|
|
|
+ @Value("${oss.download-url-pre}")
|
|
|
+ private String downloadUrlPre;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DevInfoService devInfoService;
|
|
|
|
|
@@ -112,6 +116,11 @@ public class WebGatewayImpl implements WebGateway {
|
|
|
@Autowired
|
|
|
private PersonInOutService personInOutService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TblIndustryNewsService tblIndustryNewsService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void upsertParameter(ParameterUpsertParam param) {
|
|
|
|
|
@@ -680,15 +689,12 @@ public class WebGatewayImpl implements WebGateway {
|
|
|
res.setRoleId(roleId);
|
|
|
|
|
|
// 查询角色已选菜单ID
|
|
|
- //TODO 查询前端传的roleId,显示这个角色所勾选的菜单
|
|
|
List<Long> selectedMenuId = tblRoleMenuMapService.queryMenuIdByRoleId(roleId);
|
|
|
res.setSelectedMenuId(selectedMenuId);
|
|
|
|
|
|
- // 查询所有菜单
|
|
|
- //TODO 查询redis中当前用户的roleId,显示为机构超管的所有菜单
|
|
|
- List<TblSystemMenu> allMenus = tblSystemMenuService.lambdaQuery()
|
|
|
- .eq(TblSystemMenu::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED)
|
|
|
- .list();
|
|
|
+ // 查询机构对应超管所有菜单id-- 从redis中取当前登陆者的roleIds,然后取菜单合集
|
|
|
+ List<Long> roleMenuId = tblRoleMenuMapService.queryMenuIdByRoleIds(UserContext.getRoleIds());
|
|
|
+ List<TblSystemMenu> allMenus = tblSystemMenuService.listByIds(roleMenuId);
|
|
|
|
|
|
// 转换为DTO
|
|
|
List<MenuSimpleTreeDTO> menuVOList = CopyUtils.copyList(allMenus, MenuSimpleTreeDTO.class);
|
|
@@ -796,6 +802,82 @@ public class WebGatewayImpl implements WebGateway {
|
|
|
tblDicItemService.removeById(tblDicItem);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void editNews(EditNewsParam param) {
|
|
|
+
|
|
|
+ if (param.getNewsId() != null) {
|
|
|
+ // 修改新闻逻辑
|
|
|
+ TblIndustryNews tblIndustryNews = tblIndustryNewsService.getById(param.getNewsId());
|
|
|
+ if (tblIndustryNews == null) {
|
|
|
+ throw new BizException(ErrorEnum.NEWS_NOT_EXIST.getErrorCode(), ErrorEnum.NEWS_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+ String fileType = "NEWS";
|
|
|
+ String busiKey = tblIndustryNews.getNewsId().toString();
|
|
|
+ try {
|
|
|
+ TblOssFile ossFile = ossFileService.uploadCommonFile(param.getNewsImage(), fileType, busiKey);
|
|
|
+ BeanUtils.copyProperties(param, tblIndustryNews, "newsImage");
|
|
|
+ tblIndustryNews.setNewsImageUrl(ossFile.getOssUrl());
|
|
|
+ tblIndustryNewsService.updateById(tblIndustryNews);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("上传新闻图片失败", e);
|
|
|
+ throw new BizException(ErrorEnum.FILE_UPLOAD_FAIL.getErrorCode(), ErrorEnum.FILE_UPLOAD_FAIL.getErrorMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 新增新闻逻辑
|
|
|
+ TblIndustryNews tblIndustryNews = new TblIndustryNews();
|
|
|
+ BeanUtils.copyProperties(param, tblIndustryNews, "newsImage");
|
|
|
+ tblIndustryNewsService.save(tblIndustryNews);
|
|
|
+ Long newsId = tblIndustryNews.getNewsId();
|
|
|
+ String fileType = "NEWS";
|
|
|
+ String busiKey = newsId.toString();
|
|
|
+ try {
|
|
|
+ TblOssFile ossFile = ossFileService.uploadCommonFile(param.getNewsImage(), fileType, busiKey);
|
|
|
+ tblIndustryNews.setNewsImageUrl(ossFile.getOssUrl());
|
|
|
+ tblIndustryNewsService.updateById(tblIndustryNews);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("上传新闻图片失败", e);
|
|
|
+ throw new BizException(ErrorEnum.FILE_UPLOAD_FAIL.getErrorCode(), ErrorEnum.FILE_UPLOAD_FAIL.getErrorMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteNews(DeleteNewsParam param) {
|
|
|
+ TblIndustryNews tblIndustryNews = tblIndustryNewsService.getById(param.getNewsId());
|
|
|
+ if (tblIndustryNews == null) {
|
|
|
+ throw new BizException(ErrorEnum.NEWS_NOT_EXIST.getErrorCode(), ErrorEnum.NEWS_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ tblIndustryNews.setIsDeleted(BasePO.DeleteFlag.DELETED);
|
|
|
+ tblIndustryNewsService.removeById(tblIndustryNews);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<NewsDTO> queryNewsList(QueryNewsListParam param) {
|
|
|
+ List<TblIndustryNews> tblIndustryNewsList = tblIndustryNewsService.queryNewsList(param);
|
|
|
+ return CopyUtils.copyList(tblIndustryNewsList, NewsDTO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public NewsDTO queryNewDetails(Long newsId) {
|
|
|
+
|
|
|
+ return CopyUtils.copy(tblIndustryNewsService.getById(newsId), NewsDTO.class);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public OssFileDTO uploadCommonFile(MultipartFile file, String fileType, String busiKey){
|
|
|
+ try {
|
|
|
+ TblOssFile ossFile = ossFileService.uploadCommonFile(file, fileType, busiKey);
|
|
|
+ return CopyUtils.copy(ossFile, OssFileDTO.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("上传文件失败", e);
|
|
|
+ throw new BizException(ErrorEnum.FILE_UPLOAD_FAIL.getErrorCode(), ErrorEnum.FILE_UPLOAD_FAIL.getErrorMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void OTAUpload(MultipartFile file) throws IOException {
|
|
@@ -806,12 +888,12 @@ public class WebGatewayImpl implements WebGateway {
|
|
|
|
|
|
// 校验文件类型 - OTA升级文件通常是固件文件,支持常见的固件格式
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
- if (originalFilename == null || !isValidOtaFile(originalFilename)) {
|
|
|
+ if (originalFilename == null || !ossFileService.isValidOtaFile(originalFilename)) {
|
|
|
throw new BizException(ErrorEnum.FILE_ONLY_BIN_HEX_FW.getErrorCode(), "仅支持固件文件格式(.bin, .hex, .fw等)!");
|
|
|
}
|
|
|
|
|
|
// 生成OTA专用的OSS对象名称,使用单独的文件夹
|
|
|
- String objectName = generateOtaObjectName(originalFilename);
|
|
|
+ String objectName = ossFileService.generateCommonObjectName("ota", originalFilename);
|
|
|
|
|
|
// 上传文件到OSS
|
|
|
ossClient.upload(file.getInputStream(), OssUtils.BUCKET_NAME, objectName);
|
|
@@ -829,41 +911,4 @@ public class WebGatewayImpl implements WebGateway {
|
|
|
log.info("OTA升级文件上传成功:文件名={}, OSS路径={}", originalFilename, objectName);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 校验是否为有效的OTA文件
|
|
|
- *
|
|
|
- * @param fileName 文件名
|
|
|
- * @return 是否为有效文件
|
|
|
- */
|
|
|
- private boolean isValidOtaFile(String fileName) {
|
|
|
- if (fileName == null) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- String lowerFileName = fileName.toLowerCase();
|
|
|
- // 支持常见的固件文件格式
|
|
|
- return lowerFileName.endsWith(".bin") ||
|
|
|
- lowerFileName.endsWith(".hex") ||
|
|
|
- lowerFileName.endsWith(".fw") ||
|
|
|
- lowerFileName.endsWith(".img") ||
|
|
|
- lowerFileName.endsWith(".tar.gz") ||
|
|
|
- lowerFileName.endsWith(".zip");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成OTA专用的OSS对象名称
|
|
|
- *
|
|
|
- * @param originalFilename 原始文件名
|
|
|
- * @return OSS对象名称
|
|
|
- */
|
|
|
- private String generateOtaObjectName(String originalFilename) {
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("ota/") // 使用单独的ota文件夹
|
|
|
- .append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")))
|
|
|
- .append("/")
|
|
|
- .append(UUID.randomUUID().toString().replace("-", ""))
|
|
|
- .append("_")
|
|
|
- .append(originalFilename); // 保留原始文件名以便识别
|
|
|
-
|
|
|
- return sb.toString();
|
|
|
- }
|
|
|
}
|