package com.yiqi.order.service.impl;

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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yiqi.common.enums.ClothOrderFlowStatus;
import com.yiqi.common.utils.DateUtils;
import com.yiqi.common.utils.EnumUtils;
import com.yiqi.common.utils.OrderNoUtils;
import com.yiqi.common.utils.SecurityUtils;
import com.yiqi.order.domain.OrderClothAdjunct;
import com.yiqi.order.domain.OrderClothItem;
import com.yiqi.order.service.IOrderClothItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yiqi.order.mapper.OrderClothItemFlowRecordMapper;
import com.yiqi.order.domain.OrderClothItemFlowRecord;
import com.yiqi.order.service.IOrderClothItemFlowRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 洗衣订单衣服流程日志Service业务层处理
 *
 * @author xiaohei
 * @date 2023-12-05
 */
@Service
public class OrderClothItemFlowRecordServiceImpl extends ServiceImpl<OrderClothItemFlowRecordMapper, OrderClothItemFlowRecord>
        implements IOrderClothItemFlowRecordService {

    @Override
    public void addRecordBatch(List<OrderClothItem> orderClothItems, String flowStatus) {
        List<OrderClothItemFlowRecord> orderClothItemFlowRecords = new ArrayList<>();
        for (OrderClothItem orderClothItem : orderClothItems) {
            OrderClothItemFlowRecord orderClothItemFlowRecord = new OrderClothItemFlowRecord();
            orderClothItemFlowRecord.buildCreateData();
            orderClothItemFlowRecord.setOrderId(orderClothItem.getOrderId());
            orderClothItemFlowRecord.setOrderNo(orderClothItem.getOrderNo());
            orderClothItemFlowRecord.setOrderClothItemId(orderClothItem.getId());
            orderClothItemFlowRecord.setFlowStatus(flowStatus);
            orderClothItemFlowRecord.setFlowStatusName(EnumUtils.getEnumByType(flowStatus, ClothOrderFlowStatus.class).getInfo());
            orderClothItemFlowRecord.setWashCode(orderClothItem.getWashCode());
            orderClothItemFlowRecord.setClothId(orderClothItem.getClothItemId());
            orderClothItemFlowRecords.add(orderClothItemFlowRecord);
        }
        saveBatch(orderClothItemFlowRecords);
    }

    @Override
    public void addRecord(OrderClothItem orderClothItem, String flowStatus) {
        OrderClothItemFlowRecord orderClothItemFlowRecord = new OrderClothItemFlowRecord();
        orderClothItemFlowRecord.buildCreateData();
        orderClothItemFlowRecord.setOrderId(orderClothItem.getOrderId());
        orderClothItemFlowRecord.setOrderNo(orderClothItem.getOrderNo());
        orderClothItemFlowRecord.setOrderClothItemId(orderClothItem.getId());
        orderClothItemFlowRecord.setFlowStatus(flowStatus);
        orderClothItemFlowRecord.setFlowStatusName(EnumUtils.getEnumByType(flowStatus, ClothOrderFlowStatus.class).getInfo());
        orderClothItemFlowRecord.setWashCode(orderClothItem.getWashCode());
        orderClothItemFlowRecord.setClothId(orderClothItem.getClothItemId());
        save(orderClothItemFlowRecord);
    }

    @Override
    public void addAdjunctRecord(OrderClothAdjunct orderClothAdjunct, String flowStatus) {
        OrderClothItemFlowRecord orderClothItemFlowRecord = new OrderClothItemFlowRecord();
        orderClothItemFlowRecord.buildCreateData();
        orderClothItemFlowRecord.setOrderId(orderClothAdjunct.getOrderId());
        orderClothItemFlowRecord.setOrderClothItemId(orderClothAdjunct.getOrderClothId());
        orderClothItemFlowRecord.setFlowStatus(flowStatus);
        orderClothItemFlowRecord.setFlowStatusName("附件" + EnumUtils.getEnumByType(flowStatus, ClothOrderFlowStatus.class).getInfo());
        orderClothItemFlowRecord.setWashCode(orderClothAdjunct.getAdjunctNo());
        orderClothItemFlowRecord.setClothId(orderClothAdjunct.getOrderClothId());
        save(orderClothItemFlowRecord);
    }


}
