package com.bonus.sgzb.material.service.impl;

import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.material.domain.SecondaryWarehouse;
import com.bonus.sgzb.material.domain.SecondaryWarehouseVo;
import com.bonus.sgzb.material.domain.TeamLeaseInfo;
import com.bonus.sgzb.material.mapper.SecondaryWarehouseMapper;
import com.bonus.sgzb.material.service.SecondaryWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author c liu
 * @date 2024/2/29
 */
@Service
public class SecondaryWarehouseServiceImpl implements SecondaryWarehouseService {
    @Autowired
    private SecondaryWarehouseMapper mapper;


    @Override
    public List<SecondaryWarehouseVo> getList1(SecondaryWarehouseVo bean1) {
        List<SecondaryWarehouseVo> list = new ArrayList<>();
        if (bean1.getLeaseType().equals(1)){
            list = mapper.getList2(bean1);
            for (SecondaryWarehouseVo secondaryWarehouse : list) {
                Integer warehouse = mapper.selectStockNum1(secondaryWarehouse);
                if (warehouse == null) {
                    warehouse = 0;
                }
                secondaryWarehouse.setReceiveNum(warehouse);
                secondaryWarehouse.setStockNum(secondaryWarehouse.getNum() - secondaryWarehouse.getReceiveNum());
            }
        }else {
            list = mapper.getList2(bean1);
        }
        return list;
    }
    @Override
    public List<SecondaryWarehouse> getList(SecondaryWarehouse bean) {
        List<SecondaryWarehouse> list = new ArrayList<>();
        if (bean.getLeaseType().equals(1)){
          list = mapper.getList(bean);
            for (SecondaryWarehouse secondaryWarehouse : list) {
                Integer warehouse = mapper.selectStockNum(secondaryWarehouse);
                if (warehouse == null) {
                    warehouse = 0;
                }
                secondaryWarehouse.setReceiveNum(warehouse);
                secondaryWarehouse.setStockNum(secondaryWarehouse.getNum() - secondaryWarehouse.getReceiveNum());
            }
        }else {
            list = mapper.getList1(bean);
        }
        return list;
    }

//    @Override
//    public int addOperate(TeamLeaseInfo bean) {
//        Long userid = SecurityUtils.getLoginUser().getUserid();
//        bean.setCreateBy(String.valueOf(userid));
//        return mapper.addOperate(bean);
//    }

    @Override
    public List<TeamLeaseInfo> getOperateList(TeamLeaseInfo bean) {
        return mapper.getOperateList(bean);
    }

    @Override
    public List<TeamLeaseInfo> getRecords(TeamLeaseInfo bean) {
//        System.out.println(bean.getLeaseMan());
        return mapper.getNewRecords(bean);

    }

    @Override
    public int addNewOperate(TeamLeaseInfo bean) {
        Long userid = SecurityUtils.getLoginUser().getUserid();
        bean.setCreateBy(String.valueOf(userid));
        return mapper.addNewOperate(bean);
    }



//    @Override
//    public List<TeamLeaseInfo> getNewRecords(TeamLeaseInfo bean) {
//        List<TeamLeaseInfo> list = new ArrayList<>();
//        if (STRING_1.equals(bean.getQueryType())){
//            //进场数量
//            list = mapper.getRecordsOne(bean);
//        } else if (STRING_2.equals(bean.getQueryType())) {
//            //退场数量
//            list = mapper.getRecordsTwo(bean);
//        } else if (STRING_3.equals(bean.getQueryType())) {
//            //场内库存
//            list = mapper.getRecordsThree(bean);
//        } else if (STRING_4.equals(bean.getQueryType())) {
//            //已出库数量
//            list = mapper.getRecordsFour(bean);
//        } else if (STRING_5.equals(bean.getQueryType())) {
//            //已退库数量
//            list = mapper.getNewRecordsFive(bean);
//        } else {
//            throw new ServiceException("查询出错");
//        }
//        return list;
//    }
}
