package com.mcwl.web.controller.communityCenter;

import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.resource.domain.request.PlatForm;
import com.mcwl.resource.service.PlatFormService;
import com.mcwl.web.controller.common.OssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 官方app
 * @Author：ChenYan
 * @Project：mcwl-ai
 * @Package：com.mcwl.web.controller.communityCenter
 * @Filename：PlaFormController
 * @Description TODO
 * @Date：2025/3/4 16:36
 */
@Api(tags = "官方app")
@RestController
@RequestMapping("app")
public class PlaFormController extends BaseController {

    @Autowired
    private PlatFormService platFormService;


    /**
     * 平台官方联系列表
     */
    @ApiOperation(value = "官方连接方式二维码列表")
    @GetMapping("/list")
    public R<List<PlatForm>> list() {

        return R.ok(platFormService.listplatForm());
    }

    /***
     *
     * url
     * @param file
     * @return
     */
    @ApiOperation(value = "官方二维码文件")
    @PostMapping("/UrlFile")
    public AjaxResult zipUrlFile(@RequestParam MultipartFile file) {
        String s = OssUtil.uploadMultipartFile(file);
        return AjaxResult.success("上传成功", s);
    }
    /**
     * 添加平台官方联系
     */
    @ApiOperation(value = "添加")
    @PostMapping("/insert")
    public R<Boolean> add(@RequestBody PlatForm platForm) {
        boolean save = platFormService.save(platForm);
        return R.ok(save);
    }

    /**
     * 修改平台官方联系
     */
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public AjaxResult updateModel(@RequestBody PlatForm platForm) {

        platFormService.updateById(platForm);

        return AjaxResult.success("修改成功");
    }

    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询平台app详情")
    @GetMapping("/selectModelById")
    public R<PlatForm> selectModelById(@Valid @NotNull(message = "id不能为空") @RequestParam Long id) {
        PlatForm byId = platFormService.getById(id);
        return R.ok(byId);
    }

    /**
     * 删除联系
     */
    @ApiOperation(value = "删除联系")
    @GetMapping("delete")
    public AjaxResult delete(@Valid @NotNull(message = "id不能为空") @RequestParam Long id) {
        platFormService.removeById(id);
        return AjaxResult.success();
    }



}
