package com.malk.lianxiang.controller;

import com.malk.lianxiang.service.LianxiangService;
import com.malk.server.common.McR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping
public class LianxiangController {

    @Autowired
    private LianxiangService lianxiangService;

    /**
     * 项目立项
     * @param map
     * @return
     */
    @PostMapping("/projectInitiation")
    public McR uploadFiles(@RequestBody Map<String,Object> map){
        if (Objects.nonNull(map.get("formInstId"))){
            String formInstId = map.get("formInstId").toString();
            return lianxiangService.projectInitiation(formInstId);
        }
        return McR.errorParam("实例id不能为空！");
    }

    /**
     * 项目文档上传
     * @param map
     * @return
     */
    @PostMapping("/uploadProjectFiles")
    public McR uploadProjectFiles(@RequestBody Map<String,Object> map){
        if (Objects.nonNull(map.get("formInstId")) && Objects.nonNull(map.get("type"))){
            String formInstId = map.get("formInstId").toString();
            String type = map.get("type").toString();
            return lianxiangService.uploadProjectFiles(formInstId,type);
        }
        return McR.errorParam("实例id不能为空！");
    }

    /**
     * 项目立项变更
     * @param map
     * @return
     */
    @PostMapping("/projectInitiationChange")
    public McR projectInitiationChange(@RequestBody Map<String,Object> map){
        if (Objects.nonNull(map.get("formInstId"))){
            String formInstId = map.get("formInstId").toString();
            return lianxiangService.projectInitiationChange(formInstId);
        }
        return McR.errorParam("实例id不能为空！");
    }
}
