package com.hzs.scm.store.controller.manage;


import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.constant.msg.MemberMsgConstants;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.utils.TransactionUtils;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.scm.pub.controller.ScmController;
import com.hzs.scm.store.param.OrderQueryParam;
import com.hzs.scm.store.param.StoreHandNumParam;
import com.hzs.scm.store.service.IIcStoreHandNumService;
import com.hzs.scm.store.service.IIcStoreOutHService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 店铺出库单表头 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2024-05-11
 */
@RestController
@RequestMapping("/manage/store-out")
public class IcStoreOutController extends ScmController {

    @Autowired
    private IIcStoreOutHService storeOutService;

    @Autowired
    private IIcStoreHandNumService storeHandNumService;

    /**
     * 发货，公司发货发到店铺
     *
     * @param orderQueryParam 入参
     */
    @PostMapping("/send")
    @Log(module = EOperationModule.STORE_SEND, business = EOperationBusiness.STORE_SEND, method = EOperationMethod.SEND)
    public AjaxResult sendDeliverByCorp(@RequestBody OrderQueryParam orderQueryParam) {
        if(orderQueryParam.getItemIdList() == null || orderQueryParam.getPkStorehouse() == null){
            return AjaxResult.error(TransactionUtils.getContent(MemberMsgConstants.REQUIRED_NOT_EMPTY));
        }
        storeOutService.sendDeliverByCorp(orderQueryParam.getItemIdList(), orderQueryParam.getPkStorehouse(), SecurityUtils.getUserId());
        return AjaxResult.success();
    }

    /**
     * 查询列表,查询店铺现存量
     *
     * @return cubasdocParam 入参
     */
    @PostMapping("/list-store-hand")
    public TableDataInfo listStoreHandNum(@RequestBody StoreHandNumParam storeHandNumParam) {
        // 根据登录账号查询店铺
        startPage();
        storeHandNumParam.setPkCountry(SecurityUtils.getPkCountry());
        return getDataTable(storeHandNumService.queryIcStoreHandNumByCondition(storeHandNumParam));
    }
}
