package com.bonus.sgzb.app.controller;

import com.bonus.sgzb.app.domain.PurchaseCheckInfo;
import com.bonus.sgzb.app.domain.PurchaseMacodeInfo;
import com.bonus.sgzb.app.service.PurchaseInputService;
import com.bonus.sgzb.base.api.domain.MaInputVO;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 新购入库-app
 * @author bns_han
 */
@RestController
@RequestMapping("/base/purchaseInput")
public class PurchaseInputController extends BaseController {

    @Resource
    private PurchaseInputService purchaseInputService;

    /**
     * 新购入库列表
     *
     * @param bean 查询条件
     * @return AjaxResult对象
     */
    @Log(title = "新购入库列表", businessType = BusinessType.QUERY)
    @GetMapping("list")
    public AjaxResult getbackReceiveList(PurchaseCheckInfo bean) {
        try {
            List<PurchaseCheckInfo> list = new ArrayList<>();
            //判断该组织是否开启综合服务中心审核
            Long companyId = SecurityUtils.getLoginUser().getSysUser().getCompanyId();
            int re = purchaseInputService.selectExamineType(companyId);
            if (re>0){
                list = purchaseInputService.selectPutInListExamine(bean);
            }else {
                list =purchaseInputService.getList(bean);
            }
            return success(list);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 新购入库清单明细
     */
    @ApiOperation(value = "新购入库清单明细")
    @GetMapping(value = "/putinDetails")
    public AjaxResult putinDetails(PurchaseMacodeInfo purchaseMacodeInfo)
    {
        try {
            List<PurchaseMacodeInfo> list =purchaseInputService.selectPutinDetails(purchaseMacodeInfo);
            return success(list);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 审核
     */
    @ApiOperation(value = "修改编码管理的入库状态")
    @PostMapping("/manageStatus")
    @RequiresPermissions("warehousing:newTools:auditing")
    public AjaxResult modifyManageStatus(@RequestBody MaInputVO maInputVO) throws Exception {
        return toAjax(purchaseInputService.modifyManageStatus(maInputVO));
    }

}
