package com.inkasso.factoring.biddingManagement.web;

import com.inkasso.factoring.biddingManagement.entity.CBiddingBasicInfo;
import com.inkasso.factoring.biddingManagement.entity.SearchBiddingBasic;
import com.inkasso.factoring.biddingManagement.service.ICBiddingBasicInfoService;
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.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description 招投标管理controller
 * @Author Yafan Wang
 * @Date 2023/11/27 15:45
 */
@Controller
@RequestMapping("/biddingManagement")
public class CBiddingBasicInfoController {

    @Autowired
    private ICBiddingBasicInfoService biddingBasicInfoService;
    @Autowired
    private IProjectInformationService projectInformationService;
    /**
     * 详情
     * @param id
     * @return
     */
    @RequestMapping("/getDeatail")
    @ResponseBody
    public ResponseJson getDeatail(Long id){
        return new ResponseJson(biddingBasicInfoService.getDetail(id));
    }

    /**
     * 提交
     * @param biddingBasicInfo
     * @return
     */
    @RequestMapping("/doAdd")
    @ResponseBody
    public ResponseJson doAdd(@RequestBody @Validated CBiddingBasicInfo biddingBasicInfo) {
        //占用项目
        projectInformationService.lambdaUpdate()
                .set(ProjectInformation::getAlreadyBidding,1)
                .eq(ProjectInformation::getBusinessNumber,biddingBasicInfo.getBusinessNumber())
                .update();
        if (biddingBasicInfo.getId() != null){

            biddingBasicInfoService.handleProcess(biddingBasicInfo);
        }else {
            biddingBasicInfoService.add(biddingBasicInfo);
        }

        return new ResponseJson("操作成功！");
    }

    @RequestMapping("/list")
    @ResponseBody
    public ResponseJson list(SearchBiddingBasic search) {
        return new ResponseJson(biddingBasicInfoService.findBySearch(search));
    }


}
