package com.sy.coinage.workshop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.sy.coinage.sys.model.Dict;
import com.sy.coinage.sys.service.IDictService;
import com.sy.coinage.workshop.vo.LogisticsVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sy.coinage.workshop.dao.LogisticsDao;
import com.sy.coinage.workshop.model.*;
import com.sy.coinage.workshop.service.ILogisticsService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * -入库表主表ServiceImpl
 */
@Service
public class LogisticsServiceImpl extends ServiceImpl<LogisticsDao, Logistics> implements ILogisticsService {
    @Autowired
    private IDictService dictService;

    @Override
    @Transactional
    public void add(String rfid, String serialNumber, Integer wareId, String wareCn, Integer status, Integer checkId,
                    String checker, Integer operatorId, String operator, String crownBetween, String addressCn) {
        this.addHalfBind(rfid, serialNumber, wareId, wareCn, status, checkId,
                checker, operatorId, operator, crownBetween, addressCn, null);
    }

    @Override
    public void addHalfBind(String rfid, String serialNumber, Integer wareId, String wareCn, Integer status, Integer checkId, String checker, Integer operatorId, String operator, String crownBetween, String addressCn, String rfidSrc) {
        Logistics model = new Logistics();
        model.setRfid(rfid);
        model.setSerialNumber(serialNumber);
        model.setChecker(checker);
        model.setCheckId(checkId);
        model.setOperatorId(operatorId);
        model.setOperator(operator);
        model.setCrownBetween(crownBetween);
        model.setAddressCn(addressCn);
        model.setRfidSrc(rfidSrc);
        // 生命周期状态:1初始登记 2:车间入库 3:车间出库 4:总库入库 5:主库抽检出库 6.车间抽检入库确认 7.车间抽检出库
        // 8 主库抽检返回确认 9返检总库出库 10:返检车间确认 11拆包 12：已发货 13：返回机台
        model.setStatus(status);
        // 新拍绑定 仓库id为空
        if (wareId != null) {
            model.setWareId(wareId);
            if (StringUtils.isBlank(wareCn)) {
                Dict dict = this.dictService.getByVal("wareOpt", wareId, null);
                if (dict == null) {
                    dict = dictService.getByVal("shopWareOpt", wareId, null);
                }
                model.setWareCn(dict.getName());
            } else {
                model.setWareCn(wareCn);
            }
        }
        this.save(model);
    }

}
