package org.jeecg.modules.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.jeecg.modules.stm.compliane.info.entity.StComplianeLable;
import org.jeecg.modules.stm.compliane.info.mapper.StComplianeLableMapper;
import org.jeecg.modules.stm.compliane.info.service.IStComplianeLableService;
import org.jeecg.modules.stm.utils.StmConstans;
import org.jeecg.modules.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);
    }
}
