package com.fs.hisStore.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.company.domain.CompanyUser;
import com.fs.framework.security.SecurityUtils;
import com.fs.hisStore.param.FsStoreOrderAuditParam;
import com.fs.hisStore.param.FsStoreOrderAuditReviewParam;
import com.fs.hisStore.service.IFsStoreOrderAuditScrmService;
import com.fs.hisStore.vo.FsStoreOrderAuditVO;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/store/store/storeOrderAudit")
@AllArgsConstructor
public class FsStoreOrderAuditScrmController extends BaseController {

    private final IFsStoreOrderAuditScrmService fsStoreOrderAuditService;

    @PreAuthorize("@ss.hasAnyPermi('store:storeOrderAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreOrderAuditParam param) {
        startPage();
        CompanyUser user = SecurityUtils.getLoginUser().getUser();
        param.setCompanyId(user.getCompanyId());
        List<FsStoreOrderAuditVO> list = fsStoreOrderAuditService.selectStoreOrderAuditVOList(param);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasAnyPermi('store:storeOrderAudit:audit')")
    @PostMapping("/audit")
    public AjaxResult audit(@Valid @RequestBody FsStoreOrderAuditReviewParam param) {
        CompanyUser user = SecurityUtils.getLoginUser().getUser();
        fsStoreOrderAuditService.audit(param, user.getUserId(), false);
        return AjaxResult.success();
    }
}
