zhujie
9 天以前 19428a49b4c07b14097615d48a7a72dbf941c4e7
src/main/java/com/mzl/flower/web/supplier/SupplierController.java
@@ -9,11 +9,15 @@
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.supplier.*;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.entity.customer.Customer;
import com.mzl.flower.service.TosService;
import com.mzl.flower.service.customer.CustomerService;
import com.mzl.flower.service.supplier.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -35,6 +39,12 @@
//    private static final R ALLOWED_CONTENT_TYPES = R.valueOf("jpg");
    private final SupplierService supplierService;
    @Autowired
    private CustomerService customerService;
    @Autowired
    private TosService tosService;
    public SupplierController(SupplierService supplierService) {
        this.supplierService = supplierService;
@@ -79,15 +89,24 @@
//                }
                // 3. 生成文件名
                String fileName = "avatar/" + UUID.randomUUID().toString() +
                        getFileExtension(avatar.getOriginalFilename());
                String originalFilename = avatar.getOriginalFilename(); // 原始文件名可能没有后缀
                String contentType = avatar.getContentType();           // 例如 image/jpeg
                String extension = getExtensionFromContentType(contentType); // 我们下面实现这个方法
                String newFileName = originalFilename + (extension != null ? extension : "");
                // 4. 上传到 OSS
                //avatarUrl = ossService.uploadFile(fileName, avatar.getInputStream());
                avatarUrl = tosService.uploadFile( avatar.getInputStream(),newFileName);
            }
            // 5. 更新用户信息
            //supplierService.operationUpdate(nickname, avatarUrl);
//            supplierService.operationUpdate(nickname, avatarUrl);
            String userId = SecurityUtils.getUserId();
            Customer customer=new Customer();
            customer.setUserId(userId);
            customer.setCover(avatarUrl);
            customer.setName(nickname);
            customerService.updateMemberInfoByUserId(customer);
            return returnData(R.SUCCESS.getCode(),null);
        } catch (Exception e) {
@@ -96,6 +115,27 @@
        }
    }
    private String getExtensionFromContentType(String contentType) {
        if (contentType == null) return null;
        switch (contentType) {
            case "image/jpeg":
                return ".jpg";
            case "image/png":
                return ".png";
            case "image/gif":
                return ".gif";
            case "image/webp":
                return ".webp";
            case "image/bmp":
                return ".bmp";
            default:
                return ".png";
        }
    }
    @GetMapping("/page")
    @ApiOperation(value = "运营端-供应商分页查询", notes = "运营端-供应商分页查询")
    public ResponseEntity<ReturnDataDTO<Page<SupplierDTO>>> querySupplier(QuerySupplierDTO dto, Page page) {