package org.stm.compliane.info.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.stm.compliane.info.entity.StComplianeLable;
import org.stm.compliane.info.entity.StComplianeRangeCodes;
import org.stm.compliane.info.mapper.StComplianeLableMapper;
import org.stm.compliane.info.service.IStComplianeLableService;
import org.stm.utils.StmConstans;
import org.stm.utils.UserUtil;

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

@Service
public class StComplianeLableServiceImpl extends ServiceImpl<StComplianeLableMapper, StComplianeLable> implements IStComplianeLableService {
    @Override
    public void saveBatchCodes(List<String> lableCodes, String complianeNo) {
        QueryWrapper<StComplianeLable> wrapper = new QueryWrapper();
        wrapper.eq("COMPLIANE_NO",complianeNo);
        this.remove(wrapper);
        List<StComplianeLable> stComplianeLableList = new ArrayList<>();
        for(String code:lableCodes){
            StComplianeLable stComplianeLable = new StComplianeLable();
            stComplianeLable.setComplianeNo(complianeNo);
            stComplianeLable.setLableCode(code);
            stComplianeLable.setCreatedUser(UserUtil.getUserCode());
            stComplianeLable.setVaild(StmConstans.DEFAULT_VALID);
            stComplianeLable.setUpdatedUser(UserUtil.getUserCode());
            stComplianeLableList.add(stComplianeLable);
        }
        this.saveBatch(stComplianeLableList);
    }
}
