hxd hai 4 meses
pai
achega
8fec047e59

+ 11 - 10
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/GroupController.java

@@ -20,68 +20,69 @@ import java.util.List;
 @CatchAndLog
 @Api(tags = "群组相关")
 @Slf4j
+@RequestMapping("/wap/group")
 public class GroupController {
 
     @Autowired
     private GroupGateway groupGateway;
 
-    @PostMapping("/wap/group/addGroup")
+    @PostMapping("/addGroup")
     @ApiOperation(value = "添加群组")
     public ApiResult<Boolean> addGroup(@RequestBody @Valid GroupAddParams request){
         return ApiResult.success(groupGateway.addGroup(request));
     }
 
 
-    @DeleteMapping("/wap/group/deleteGroup")
+    @DeleteMapping("/deleteGroup")
     @ApiOperation(value = "删除群组")
     public ApiResult<Boolean> deleteGroup(@RequestParam("group_id") Long groupId){
         return ApiResult.success(groupGateway.deleteGroup(groupId));
     }
 
-    @PostMapping("/wap/group/updateGroup")
+    @PostMapping("/updateGroup")
     @ApiOperation(value = "更新群组")
     public ApiResult<Boolean> updateGroup(@RequestBody @Valid GroupUpdateParams params){
         return ApiResult.success(groupGateway.updateGroup(params));
     }
 
-    @GetMapping("/wap/group/groupLits")
+    @GetMapping("/groupLits")
     @ApiOperation(value = "获取群组列表")
     public ApiResult<List<GroupDTO>> GroupList(@RequestBody @Valid GroupListParams request){
         return ApiResult.success(groupGateway.queryGroupList(request));
     }
 
-    @GetMapping("/wap/group/queryGroupById")
+    @GetMapping("/queryGroupById")
     @ApiOperation(value = "获取群组设备列表")
     public ApiResult<List<DeviceDTO>> queryGroupById(@RequestParam("group_id") Long groupId){
         return ApiResult.success(groupGateway.queryGroupDeviceInfoById(groupId));
     }
 
 
-    @PostMapping("/wap/group/addDeviceToGroup")
+    @PostMapping("/addDeviceToGroup")
     @ApiOperation(value = "添加设备到群组")
     public ApiResult<Boolean> addDeviceToGroup(@RequestBody @Valid AddDeviceToGroupParams request) {
         return ApiResult.success(groupGateway.addDeviceToGroup(request));
     }
 
-    @DeleteMapping("/wap/group/deleteDeviceFromGroup")
+    @DeleteMapping("/deleteDeviceFromGroup")
     @ApiOperation(value = "删除设备从群组")
     public ApiResult<Boolean> deleteDeviceFromGroup(@RequestBody @Valid DeleteDeviceFromGroupParams request){
         return ApiResult.success(groupGateway.deleteDeviceFromGroup(request));
     }
 
-    @PostMapping("/wap/group/shareGroup")
+    @PostMapping("/shareGroup")
     @ApiOperation(value = "通过链接分享群组")
     public ApiResult<Boolean> shareGroup(@RequestBody @Valid ShareGroupParams request){
         return ApiResult.success(groupGateway.shareGroup(request));
     }
 
-    @PostMapping("/wap/group/GroupShareConfirm")
+    @PostMapping("/GroupShareConfirm")
     @ApiOperation(value = "群组分享确认")
     public ApiResult<Boolean> GroupShareConfirm(@RequestBody @Valid GroupShareConfirmParams request){
         return ApiResult.success(groupGateway.groupShareConfirm(request));
     }
 
-    @PostMapping("/wap/group/groupShareHandle")
+    @PostMapping("/groupShareHandle")
     @ApiOperation(value = "群组分享处理")
     public ApiResult<Boolean> groupShareHandle(@RequestBody @Valid GroupShareHandleParams request){
         return ApiResult.success(groupGateway.groupShareHandle(request));

+ 25 - 5
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/HomeController.java

@@ -1,32 +1,52 @@
 package com.hfln.portal.application.controller.wap;
 
-
 import cn.hfln.framework.catchlog.CatchAndLog;
 import cn.hfln.framework.dto.ApiResult;
 import com.hfln.portal.common.dto.data.home.HomeInfoDTO;
+import com.hfln.portal.common.dto.data.oss.OssFileDTO;
 import com.hfln.portal.domain.gateway.DeviceGateway;
+import com.hfln.portal.domain.gateway.UserGateway;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.validation.Valid;
+import java.io.IOException;
+import java.util.List;
 
 @RestController
 @CatchAndLog
 @Api(tags = "首页相关")
 @Slf4j
+@RequestMapping("/wap/home")
 public class HomeController {
 
     @Autowired
     private DeviceGateway deviceGateway;
 
-    @GetMapping("wap/home/homeInfo")
+    @Autowired
+    private UserGateway userGateway;
+
+    @GetMapping("/homeInfo")
     @ApiOperation(value = "获取个人首页信息")
     public ApiResult<HomeInfoDTO> homeInfo(@RequestParam Long userId) {
         return ApiResult.success(deviceGateway.queryHomeInfo(userId));
     }
 
+    @PostMapping(value = "/uploadCarousel")
+    @ApiOperation(value = "上传轮播图", notes = "上传轮播图片文件,支持PNG和JPEG格式")
+    public ApiResult<Void> uploadCarousel(@Valid @RequestParam MultipartFile file) throws IOException {
+        userGateway.uploadCarousel(file);
+        return ApiResult.success();
+    }
+
+    @GetMapping("/getCarouselList")
+    @ApiOperation(value = "获取轮播图列表", notes = "获取所有轮播图的信息,包含访问地址")
+    public ApiResult<List<OssFileDTO>> getCarouselList() {
+        return ApiResult.success(userGateway.getCarouselList());
+    }
 
 }

+ 1 - 1
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/UserController.java

@@ -51,7 +51,7 @@ public class UserController {
         return ApiResult.failed("微信登录失败!");
     }
 
-    @GetMapping("/loginByPhone")
+    @PostMapping("/loginByPhone")
     @ApiOperation(value = "用户手机号码一键登录注册")
     public ApiResult<String> loginByPhone(@Valid @RequestBody PhoneLoginParams params) {
 

+ 3 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/user/PhoneLoginParams.java

@@ -26,4 +26,7 @@ public class PhoneLoginParams extends BaseVO {
     @ApiModelProperty("unionId")
     private String unionId;
 
+    @ApiModelProperty("用户微信头像")
+    private String avatarUrl;
+
 }

+ 18 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/UserGateway.java

@@ -1,9 +1,14 @@
 package com.hfln.portal.domain.gateway;
 
+import com.hfln.portal.common.dto.data.oss.OssFileDTO;
 import com.hfln.portal.common.dto.data.user.UserDto;
 import com.hfln.portal.common.request.user.*;
 import com.hfln.portal.common.request.user.*;
 import com.hfln.portal.common.response.user.UserInfoWxRes;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
 
 public interface UserGateway {
 
@@ -44,4 +49,17 @@ public interface UserGateway {
     String callback(String code);
 
     boolean checkPhone(String phone, String code);
+
+    /**
+     * 上传轮播图
+     * @param file 图片文件
+     * @throws IOException IO异常
+     */
+    void uploadCarousel(MultipartFile file) throws IOException;
+
+    /**
+     * 获取轮播图列表
+     * @return 轮播图文件信息列表
+     */
+    List<OssFileDTO> getCarouselList();
 }

+ 89 - 6
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/UserGatewayImpl.java

@@ -9,22 +9,22 @@ import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.hfln.portal.common.constant.redis.RedisCacheConstant;
+import com.hfln.portal.common.dto.data.oss.OssFileDTO;
 import com.hfln.portal.common.dto.data.user.UserDto;
 import com.hfln.portal.common.request.user.*;
 import com.hfln.portal.common.response.user.UserInfoWxRes;
+import com.hfln.portal.domain.customer.OssBusiType;
 import com.hfln.portal.domain.customer.util.PasswordUtil;
 import com.hfln.portal.domain.exception.ErrorEnum;
 import com.hfln.portal.domain.gateway.UserGateway;
-import com.hfln.portal.infrastructure.po.DevGroup;
-import com.hfln.portal.infrastructure.po.DevInfo;
-import com.hfln.portal.infrastructure.po.DevShare;
-import com.hfln.portal.infrastructure.po.GroupShare;
-import com.hfln.portal.infrastructure.po.UserInfo;
-import com.hfln.portal.infrastructure.po.WxRelation;
+import com.hfln.portal.infrastructure.oss.OssClient;
+import com.hfln.portal.infrastructure.oss.OssUtils;
+import com.hfln.portal.infrastructure.po.*;
 import com.hfln.portal.infrastructure.service.DevGroupService;
 import com.hfln.portal.infrastructure.service.DevInfoService;
 import com.hfln.portal.infrastructure.service.DevShareService;
 import com.hfln.portal.infrastructure.service.GroupShareService;
+import com.hfln.portal.infrastructure.service.OssFileService;
 import com.hfln.portal.infrastructure.service.UserService;
 import com.hfln.portal.infrastructure.service.WxRelationService;
 import lombok.SneakyThrows;
@@ -44,9 +44,14 @@ import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -88,6 +93,11 @@ public class UserGatewayImpl implements UserGateway {
     @Autowired
     private WxRelationService wxRelationService;
 
+    @Autowired
+    private OssClient ossClient;
+
+    @Autowired
+    private OssFileService ossFileService;
 
     public static String WXX_CX_ACCESS_TOKEN = "";
 
@@ -147,6 +157,7 @@ public class UserGatewayImpl implements UserGateway {
         userInfo.setOpenid(params.getOpenId());
         userInfo.setPhone(params.getPhone());
         userInfo.setUnionId(params.getUnionId());
+        userInfo.setAvatarUrl(params.getAvatarUrl());
         userService.save(userInfo);
         return true;
     }
@@ -416,4 +427,76 @@ public class UserGatewayImpl implements UserGateway {
         // 4. 如果不存在,返回false表示该号码未注册
         return false;
     }
+
+    @Override
+    public void uploadCarousel(MultipartFile file) throws IOException {
+        // 校验文件非空
+        if (file.isEmpty()) {
+            throw new BizException(ErrorEnum.FILE_IS_EMPTY.getErrorCode(), ErrorEnum.FILE_IS_EMPTY.getErrorMessage());
+        }
+
+        // 校验文件类型
+        String contentType = file.getContentType();
+        if (contentType == null || (!contentType.equalsIgnoreCase("image/png") && !contentType.equalsIgnoreCase("image/jpeg"))) {
+            throw new BizException(ErrorEnum.FILE_ONLY_PNG_JPG.getErrorCode(), ErrorEnum.FILE_ONLY_PNG_JPG.getErrorMessage());
+        }
+
+        // 校验文件头
+        byte[] fileHeader = new byte[8];
+        try (InputStream is = file.getInputStream()) {
+            int readBytes = is.read(fileHeader);
+            if (readBytes < 8) {
+                throw new BizException(ErrorEnum.FILE_NOT_COMPLETE.getErrorCode(), ErrorEnum.FILE_NOT_COMPLETE.getErrorMessage());
+            }
+        }
+        boolean isPng = checkPngMagicNumber(fileHeader);
+        boolean isJpeg = checkJpegMagicNumber(fileHeader);
+
+        if (!isPng && !isJpeg) {
+            throw new BizException(ErrorEnum.FILE_ONLY_PNG_JPG02.getErrorCode(), ErrorEnum.FILE_ONLY_PNG_JPG02.getErrorMessage());
+        }
+
+        // 生成OSS对象名称
+        String objectName = OssUtils.getObjectName(OssBusiType.CAROUSEL.getCode(), file.getOriginalFilename());
+        
+        // 上传文件到OSS
+        ossClient.upload(file.getInputStream(), OssUtils.BUCKET_NAME, objectName);
+
+        // 保存文件记录到数据库
+        TblOssFile ossFile = new TblOssFile();
+        ossFile.setBusiType(OssBusiType.CAROUSEL.getCode());
+        ossFile.setBusiKey("0");
+        ossFile.setFileName(file.getOriginalFilename());
+        ossFile.setOssUrl(OssUtils.BUCKET_NAME + "/" + objectName);
+        ossFileService.save(ossFile);
+    }
+
+    @Override
+    public List<OssFileDTO> getCarouselList() {
+        // 查询所有轮播图文件记录
+        List<TblOssFile> ossFiles = ossFileService.queryFile(OssBusiType.CAROUSEL.getCode(), null);
+        
+        // 转换为DTO并获取可访问的URL
+        return ossFiles.stream()
+                .map(ossFile -> {
+                    OssFileDTO dto = new OssFileDTO();
+                    dto.setFileId(ossFile.getFileId());
+                    dto.setBusiType(ossFile.getBusiType());
+                    dto.setFileName(ossFile.getFileName());
+                    // 获取可访问的URL
+                    dto.setFileUrl(ossClient.getDownloadUrl(ossFile.getOssUrl()));
+                    return dto;
+                })
+                .collect(Collectors.toList());
+    }
+
+    private boolean checkPngMagicNumber(byte[] fileHeader) {
+        byte[] pngMagicNumber = {(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
+        return Arrays.equals(Arrays.copyOfRange(fileHeader, 0, 8), pngMagicNumber);
+    }
+
+    private boolean checkJpegMagicNumber(byte[] fileHeader) {
+        byte[] jpegMagicNumber = {(byte) 0xFF, (byte) 0xD8, (byte) 0xFF};
+        return Arrays.equals(Arrays.copyOfRange(fileHeader, 0, 3), jpegMagicNumber);
+    }
 }