package xn.hxp.ui.plan.already;

import com.blankj.utilcode.util.LogUtils;
import com.rc.httpcore.bean.BelongingPersonBean;
import com.rc.httpcore.bean.HxpChemicalVo;
import com.rc.httpcore.bean.TopicDataBean;

import java.util.List;

import xn.hxp.ui.plan.room.RoomTool;
import xn.hxp.ui.plan.room.bean.input_add.InventoryItemBean;
import xn.hxp.ui.plan.room.dao.HxpInventoryDAO;

public enum AlreadyTool {
    INSTANCE;

    public void updateHxpInventoryList(List<HxpChemicalVo> hxpChemicalVoList) {
        HxpInventoryDAO hxpInventoryDAO = RoomTool.getInstance().hxpInventoryDAO();
        for (int i = 0; i < hxpChemicalVoList.size(); i++) {
            HxpChemicalVo hxpChemicalVo = hxpChemicalVoList.get(i);
            // 清单Item
            InventoryItemBean inventoryItemBean = new InventoryItemBean(hxpChemicalVo.getCabinetId(), hxpChemicalVo.getDoorId(), hxpChemicalVo.getDoorLayers());
            inventoryItemBean.setWaitId(Long.parseLong(hxpChemicalVo.getWaitId()));
            inventoryItemBean.setSize(1);
            // 是否课题
            if (hxpChemicalVo.isTopicGroup()) {
                TopicDataBean topicDataBean = new TopicDataBean(String.valueOf(hxpChemicalVo.getTopicGroupId()), hxpChemicalVo.getTopicGroupName());
                inventoryItemBean.setTopicDataBean(topicDataBean);
            } else {
                // 归属人信息
                BelongingPersonBean belongingPersonBean = new BelongingPersonBean(String.valueOf(hxpChemicalVo.getApplyUserId()), hxpChemicalVo.getApplyUserName(), hxpChemicalVo.getBelongAccount(), hxpChemicalVo.getApplyUserPhone(), "");
                inventoryItemBean.setBelongingPersonBean(belongingPersonBean);
            }
            // 设置化学品
            inventoryItemBean.setHxpChemicalVo(hxpChemicalVo);

            hxpInventoryDAO.upsert(inventoryItemBean);
        }
        LogUtils.json(hxpInventoryDAO.getAll());
    }

}
