package com.inkasso.factoring.creditmanagement.web;


import com.inkasso.adapter.interfaces.AvoidRepeatableCommit;
import com.inkasso.factoring.common.entity.ResponseJson;
import com.inkasso.factoring.creditmanagement.entity.ProjectInformation;
import com.inkasso.factoring.creditmanagement.service.IProjectInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 项目信息 前端控制器
 * </p>
 *
 * @author liutao
 * @since 2023-11-25
 */
@RestController
@RequestMapping("/projectInfo")
public class CProjectInformationController {

    @Autowired
    private IProjectInformationService projectInformationService;

    /**
     * 获取当前用户需要招投标且已通过的授信项目
     * @return
     */
    @GetMapping(value = "/getUserBiddingProjects")
    @ResponseBody
    public ResponseJson getUserBiddingProjects() {
        return new ResponseJson(projectInformationService.getUserBiddingProjects());
    }

    /**
     * 增加项目
     * @param projectInformation
     * @return
     */
    @RequestMapping("/addProject")
    @AvoidRepeatableCommit(key = "projectInfo/addProject")
    public ResponseJson addProject(@RequestBody ProjectInformation projectInformation){
        ProjectInformation result = projectInformationService.addProject(projectInformation);
        return new ResponseJson(result);
    }

    /**
     * 获取项目补充信息
     * @return
     */
    @RequestMapping("/getSuppplement")
    public ResponseJson getSuppplement(@RequestParam Long id){
        ProjectInformation projectInformation = projectInformationService.getSuppplement(id);
        return new ResponseJson(projectInformation);
    }

    /**
     * 补充信息
     * @return
     */
    @RequestMapping("supplement")
    @AvoidRepeatableCommit(key = "projectInfo/supplement")
    public ResponseJson supplement(@RequestBody ProjectInformation projectInformation){
        projectInformationService.supplement(projectInformation);
        return new ResponseJson();
    }

    /**
     * 查看详情
     * @param id
     * @return
     */
    @RequestMapping("getDetail")
    public ResponseJson getDetail(@RequestParam Long id){
        ProjectInformation projectInformation = projectInformationService.getDetail(id);
        return new ResponseJson(projectInformation);
    }

    /**
     * 根据供应商id获取该供应商下的全部项目
     * @param supplierId
     * @return
     */
    @RequestMapping("getProjectBySupplierId")
    public ResponseJson getProjectBySupplierId(@RequestParam Long supplierId){
        List<ProjectInformation> projectInformations = projectInformationService.getProjectBySupplierId(supplierId);
        return new ResponseJson(projectInformations);
    }

    /**
     * 获取当前用户下已完成采购合同的所有项目
     * @return
     */
    @RequestMapping("getLocalPurchCompletedProject")
    public ResponseJson getLocalPurchCompletedProject(){
        return new ResponseJson(projectInformationService.getLocalPurchCompletedProject());
    }

}
