package com.fjhx.victoriatourist.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fjhx.area.utils.CustomizeAreaUtil;
import com.fjhx.victoriatourist.entity.abnormal.po.AbnormalInfo;
import com.fjhx.victoriatourist.entity.purchase.po.PurchaseBack;
import com.fjhx.victoriatourist.entity.purchase.vo.PurchaseBackVo;
import com.fjhx.victoriatourist.service.abnormal.AbnormalInfoService;
import com.fjhx.victoriatourist.service.order.OrderInfoService;
import com.fjhx.victoriatourist.service.purchase.PurchaseBackService;
import com.fjhx.wms.entity.stock.dto.StockWaitDto;
import com.fjhx.wms.service.WmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WmsServiceImpl implements WmsService {
    @Autowired
    private OrderInfoService orderInfoService;
    @Autowired
    private AbnormalInfoService abnormalInfoService;
    @Autowired
    private PurchaseBackService purchaseBackService;

//    /**
//     * 销售订单出库
//     */
//    @Override
//    public void outbound(StockWaitDetailsDto stockWaitDetailsDto) {
//        orderInfoService.outbound(stockWaitDetailsDto);
//    }

    @Override
    public void outbounds(StockWaitDto stockWaitDto) {
        orderInfoService.outbounds(stockWaitDto);
    }

    @Override
    public void addEndInStockAbnormal(Long linkId, String linkCode) {
        AbnormalInfo abnormalInfo = new AbnormalInfo();
        abnormalInfo.setStatus(0);
        abnormalInfo.setId(IdWorker.getId());
        abnormalInfo.setType(50);//结束入库
        abnormalInfo.setLinkId(linkId);
        abnormalInfo.setLinkCode(linkCode);
        abnormalInfo.setTitle("入库数量差异");
        abnormalInfoService.save(abnormalInfo);
    }

    @Override
    public Object getPurchaseBackInfo(Long id) {
        PurchaseBack purchaseBack = purchaseBackService.getById(id);
        PurchaseBackVo purchaseBackVo = BeanUtil.copyProperties(purchaseBack, PurchaseBackVo.class);
        // 赋值国省市
        CustomizeAreaUtil.setAreaName(purchaseBackVo);
        return purchaseBackVo;
    }
}
