| | |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | |
| | | import java.util.UUID; |
| | | |
| | | import static com.google.common.io.Files.getFileExtension; |
| | | import static sun.font.CreatedFontTracker.MAX_FILE_SIZE; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api/supplier") |
| | |
| | | @Slf4j |
| | | public class SupplierController extends BaseController { |
| | | |
| | | private static final R ALLOWED_CONTENT_TYPES = R.valueOf("jpg"); |
| | | private final SupplierService supplierService; |
| | | |
| | | public SupplierController(SupplierService supplierService) { |
| | |
| | | return returnData(R.SUCCESS.getCode(),null); |
| | | } |
| | | |
| | | @PostMapping("/operation/update") |
| | | @ApiOperation(value = "运营修改", notes = "运营修改") |
| | | public ResponseEntity<ReturnDataDTO> operationUpdate( |
| | | @RequestParam("nickname") String nickname, |
| | | @RequestParam(value = "avatar", required = false) MultipartFile avatar |
| | | ) { |
| | | try { |
| | | String avatarUrl = null; |
| | | if (avatar != null && !avatar.isEmpty()) { |
| | | // 1. 检查文件大小 |
| | | if (avatar.getSize() > MAX_FILE_SIZE) { |
| | | throw new ValidationException("文件大小不能超过5MB"); |
| | | } |
| | | |
| | | // 2. 检查文件类型 |
| | | String contentType = avatar.getContentType(); |
| | | if (!ALLOWED_CONTENT_TYPES.contains(contentType)) { |
| | | throw new ValidationException("不支持的文件类型"); |
| | | } |
| | | |
| | | // 3. 生成文件名 |
| | | String fileName = "avatar/" + UUID.randomUUID().toString() + |
| | | getFileExtension(avatar.getOriginalFilename()); |
| | | |
| | | // 4. 上传到 OSS |
| | | //avatarUrl = ossService.uploadFile(fileName, avatar.getInputStream()); |
| | | } |
| | | |
| | | // 5. 更新用户信息 |
| | | //supplierService.operationUpdate(nickname, avatarUrl); |
| | | |
| | | return returnData(R.SUCCESS.getCode(),null); |
| | | } catch (Exception e) { |
| | | log.error("更新用户信息失败", e); |
| | | return returnData(R.RUNTIME_EXCEPTION.getCode(),null); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @ApiOperation(value = "运营端-供应商分页查询", notes = "运营端-供应商分页查询") |
| | | public ResponseEntity<ReturnDataDTO<Page<SupplierDTO>>> querySupplier(QuerySupplierDTO dto, Page page) { |
| | |
| | | return returnData(R.SUCCESS.getCode(),supplierService.findSupplierDetail(id)); |
| | | } |
| | | |
| | | @GetMapping("/info/{phone}") |
| | | @ApiOperation(value = "用户详情", notes = "用户详情") |
| | | public ResponseEntity<ReturnDataDTO<SupplierDTO>> findSupplierByPhone(@PathVariable("phone") String phone) { |
| | | return returnData(R.SUCCESS.getCode(),supplierService.findSupplierByPhone(phone)); |
| | | } |
| | | |
| | | @PostMapping("/audit") |
| | | @ApiOperation(value = "运营端-供应商审核", notes = "运营端-供应商审核") |
| | | public ResponseEntity<ReturnDataDTO> auditSupplier(@Validated @RequestBody AuditSupplierDTO dto) { |