package com.bonus.sgzb.material.controller;

import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.material.domain.PurchaseCheckInfo;
import com.bonus.sgzb.material.domain.PurchaseInput;
import com.bonus.sgzb.material.domain.PurchaseMacodeInfo;
import com.bonus.sgzb.material.service.PurchaseCheckServiceCenterService;
import com.bonus.sgzb.base.api.domain.MaInputVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 新购--综合服务中心
 * 
 * @author bonus
 * @date 2023-12-10
 */
@RestController
@Api(value = "新购--综合服务中心")
@RequestMapping("/purchaseCheckServiceCenter")
public class PurchaseCheckServiceCenterController extends BaseController
{
    @Autowired
    private PurchaseCheckServiceCenterService purchaseCheckServiceCenterService;

    /**
     * 查询新购入库任务列表
     */
    @ApiOperation("查询新购入库任务列表")
    @GetMapping("/putInList")
    public TableDataInfo putInList(PurchaseCheckInfo purchaseCheckInfo)
    {
        startPage();
        List<PurchaseCheckInfo> list=new ArrayList<>();
        //判断该组织是否开启综合服务中心审核
        Long companyId = SecurityUtils.getLoginUser().getSysUser().getCompanyId();
        int re =purchaseCheckServiceCenterService.selectExamineType(companyId);
        if (re>0){
            list = purchaseCheckServiceCenterService.selectPutInListList(purchaseCheckInfo);
        }
        return getDataTable(list);
    }

    /**
     * 获取新购验收编号管理详细信息
     */
    @ApiOperation(value = "新购入库清单明细")
    @GetMapping(value = "/putinDetails")
    public TableDataInfo putinDetails(PurchaseMacodeInfo purchaseMacodeInfo)
    {
        startPage();
        return getDataTable(purchaseCheckServiceCenterService.selectPutinDetails(purchaseMacodeInfo));
    }

    /**
     * 审核-通过/不通过
     */
    @ApiOperation(value = "综合服务中心审核")
    @PutMapping("/manageStatus")
    public AjaxResult modifyManageStatus(@RequestBody MaInputVO maInputVO) throws Exception {
        return toAjax(purchaseCheckServiceCenterService.modifyManageStatus(maInputVO));
    }


    /**
     * 导出新购工机具入库
     */
    @ApiOperation("导出新购工机具入库")
    @Log(title = "导出新购工机具入库", businessType = BusinessType.EXPORT)
    @PostMapping("/putInExport")
    public void putInExport(HttpServletResponse response, PurchaseCheckInfo purchaseCheckInfo)
    {
        List<PurchaseInput> list = new ArrayList<>();
        //判断该组织是否开启综合服务中心审核
        Long companyId = SecurityUtils.getLoginUser().getSysUser().getCompanyId();
        int re =purchaseCheckServiceCenterService.selectExamineType(companyId);
        if (re>0){
            list=purchaseCheckServiceCenterService.putInExportList(purchaseCheckInfo);
        }
        ExcelUtil<PurchaseInput> util = new ExcelUtil<>(PurchaseInput.class);
        util.exportExcel(response, list, "新购工机具入库");
    }

}
