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.Fjyk;
import com.gyee.frame.mapper.ticket.FjykMapper;
import com.gyee.frame.model.ticket.Ibsidgen;
import com.gyee.frame.service.ticket.FjykService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.frame.service.ticket.IbsidgenService;
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 FjykServiceImpl extends ServiceImpl<FjykMapper, Fjyk> implements FjykService {

    @Autowired
    IbsidgenService ibsidgenService;

    @Override
    public void insertRiskMeasure(Fjyk obj) {
        Ibsidgen gen = ibsidgenService.selectId("FJYK");
        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<Fjyk> getListOfRiskMeasure(String wonum, String type) {
        QueryWrapper<Fjyk> wrapper = new QueryWrapper<>();
        wrapper.eq("WONUM", wonum);
        wrapper.eq("TYPE", type);

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

        return list;
    }
}
