package com.gyee.frame.service.impl.ticket;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.frame.common.exception.TicketException;
import com.gyee.frame.model.ticket.Ibsidgen;
import com.gyee.frame.model.ticket.Woadditionsafemeasure;
import com.gyee.frame.mapper.ticket.WoadditionsafemeasureMapper;
import com.gyee.frame.service.ticket.IbsidgenService;
import com.gyee.frame.service.ticket.WoadditionsafemeasureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenmh
 * @since 2020-06-08
 */
@Service
public class WoadditionsafemeasureServiceImpl extends ServiceImpl<WoadditionsafemeasureMapper, Woadditionsafemeasure> implements WoadditionsafemeasureService {

    @Autowired
    IbsidgenService ibsidgenService;

    @Override
    public void insertSafeMeasure(Woadditionsafemeasure obj) {
        Ibsidgen gen = ibsidgenService.selectId("WOADDITIONSAFEMEASURE");
        double id = gen.getIdvalue() + 1;
        ibsidgenService.updateGen(gen, id);

        obj.setId(id);
        int result = baseMapper.insert(obj);

        if (result== 0)
            throw new TicketException("数据添加失败");
    }

    @Override
    public List<Woadditionsafemeasure> getListSafeMeasure(String woNum) {
        QueryWrapper<Woadditionsafemeasure> wrapper = new QueryWrapper<>();
        wrapper.eq("WONUM", woNum);

        List<Woadditionsafemeasure> list = baseMapper.selectList(wrapper);

        return list;
    }

    @Override
    public Integer deleteSafeMeasure(List<Double> list) {
        int result = baseMapper.deleteBatchIds(list);
        return result;
    }
}
