package com.cpxt.biz.service.impl;

import java.awt.*;
import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cpxt.biz.domain.BizOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cpxt.biz.mapper.BizOrderSubMapper;
import com.cpxt.biz.domain.BizOrderSub;
import com.cpxt.biz.service.IBizOrderSubService;

/**
 * 订单子单Service业务层处理
 * 
 * @author YIN
 * @date 2024-12-16
 */
@Service
public class BizOrderSubServiceImpl implements IBizOrderSubService 
{
    @Autowired
    private BizOrderSubMapper bizOrderSubMapper;

    /**
     * 查询订单子单
     * 
     * @param id 订单子单主键
     * @return 订单子单
     */
    @Override
    public BizOrderSub selectBizOrderSubById(Long id)
    {
        return bizOrderSubMapper.selectById(id);
    }

    /**
     * 查询订单子单列表
     * 
     * @param bizOrderSub 订单子单
     * @return 订单子单
     */
    @Override
    public List<BizOrderSub> selectBizOrderSubList(BizOrderSub bizOrderSub)
    {
        LambdaQueryWrapper<BizOrderSub> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(bizOrderSub.getOrderSn())) {
            queryWrapper.like(BizOrderSub::getOrderSn, bizOrderSub.getOrderSn());
        }
        return bizOrderSubMapper.selectList(queryWrapper);
    }

    /**
     * 新增订单子单
     * 
     * @param bizOrderSub 订单子单
     * @return 结果
     */
    @Override
    public int insertBizOrderSub(BizOrderSub bizOrderSub)
    {
        return bizOrderSubMapper.insert(bizOrderSub);
    }

    /**
     * 修改订单子单
     * 
     * @param bizOrderSub 订单子单
     * @return 结果
     */
    @Override
    public int updateBizOrderSub(BizOrderSub bizOrderSub)
    {
        return bizOrderSubMapper.updateById(bizOrderSub);
    }

    /**
     * 批量删除订单子单
     * 
     * @param ids 需要删除的订单子单主键
     * @return 结果
     */
    @Override
    public int deleteBizOrderSubByIds(Long[] ids)
    {
        UpdateWrapper<BizOrderSub> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", (Object) ids);
        updateWrapper.set("status","2"); //状态改为删除
        return bizOrderSubMapper.update(null,updateWrapper);
    }

    /**
     * 删除订单子单信息
     * 
     * @param id 订单子单主键
     * @return 结果
     */
    @Override
    public int deleteBizOrderSubById(Long id)
    {
        UpdateWrapper<BizOrderSub> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("status","2"); //状态改为删除
        return bizOrderSubMapper.update(null,updateWrapper);
    }
}
