package com.microservices.pms.common.controller;

import com.microservices.common.core.utils.html.EscapeUtil;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.pms.product.domain.vo.ProductUserReqInputVo;
import com.microservices.pms.product.service.IPmsProductRequirementService;
import com.microservices.pms.specialArea.service.SoftwareFactStatisticsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author otto
 */
@RestController
@Api(tags = "项目管理-公开接口")
@RequestMapping("/open")
@RefreshScope
public class OpenController extends BaseController {

    @Value("${http.gitLinkUrl}")
    public String gitLinkUrl;

    @Autowired
    private SoftwareFactStatisticsServiceImpl softwareFactStatisticsService;

    @Autowired
    private IPmsProductRequirementService pmsProductRequirementService;
    /**
     * 查询项目管理企业列表
     */
    @GetMapping("/loginUrl")
    @ApiOperation(value = "获取登录地址")
    public AjaxResult loginUrl() {
        return success(
                (Object) EscapeUtil.removeExtraSlashOfUrl(gitLinkUrl + "/login")
        );
    }

    @ApiOperation(value = "获取指定组织的项目研发状态")
    @GetMapping("/{enterpriseIdentifier}/specialArea/softwareFact/statis/projectSituation")
    public AjaxResult theEnterpriseProjectSituation(@PathVariable String enterpriseIdentifier) {
        return AjaxResult.success(softwareFactStatisticsService.projectSituation(enterpriseIdentifier));
    }

    @ApiOperation(value = "获取指定组织的产品里程碑状态")
    @GetMapping("/{enterpriseIdentifier}/specialArea/softwareFact/statis/productPlanSituation")
    public AjaxResult theEnterpriseProductPlanSituation(@PathVariable String enterpriseIdentifier) {
        return AjaxResult.success(softwareFactStatisticsService.productPlanSituation(enterpriseIdentifier));
    }

    @ApiOperation(value = "今日工作态势")
    @GetMapping("/specialArea/softwareFact/statis/todayWorkSituation")
    public AjaxResult todayWorkSituation(){
        return AjaxResult.success(softwareFactStatisticsService.todayWorkSituation());
    }

    @ApiOperation(value = "周、月工作态势")
    @GetMapping("/specialArea/softwareFact/statis/weekMonthWorkSituation")
    public AjaxResult weekMonthWorkSituation(String type){
        return AjaxResult.success(softwareFactStatisticsService.weekMonthWorkSituation(type));
    }

    @ApiOperation(value = "项目研发状态")
    @GetMapping("/specialArea/softwareFact/statis/projectSituation")
    public AjaxResult projectSituation(){
        return AjaxResult.success(softwareFactStatisticsService.projectSituation());
    }


    /**
     * 新增需求
     */
    @Log(title = "需求", businessType = BusinessType.INSERT)
    @PostMapping("/{enterpriseIdentifier}/productUserRequirement")
    @ApiOperation(value = "新增需求")
    public AjaxResult add(@PathVariable String enterpriseIdentifier,
                          @RequestBody @Validated ProductUserReqInputVo productUserReqInputVo) {
        productUserReqInputVo.setEnterpriseIdentifier(enterpriseIdentifier);
        return success(pmsProductRequirementService.insertUserReqWithoutAuth(productUserReqInputVo));
    }
}
