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.StComplianeRangeCodes;
import org.jeecg.modules.stm.compliane.info.mapper.StComplianeRangeCodesMapper;
import org.jeecg.modules.stm.compliane.info.service.IStComplianeRangeCodesService;
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 StComplianeRangeCodesServiceImpl extends ServiceImpl<StComplianeRangeCodesMapper, StComplianeRangeCodes> implements IStComplianeRangeCodesService {
    @Override
    public void saveBatchCodes(List<String> rangeCodes, String complianeNo) {
        QueryWrapper<StComplianeRangeCodes> wrapper = new QueryWrapper();
        wrapper.eq("COMPLIANE_NO",complianeNo);
        this.remove(wrapper);
        List<StComplianeRangeCodes> stComplianeRangeCodesList = new ArrayList<>();
        for(String code:rangeCodes){
            StComplianeRangeCodes stComplianeRangeCodes = new StComplianeRangeCodes();
            stComplianeRangeCodes.setComplianeNo(complianeNo);
            stComplianeRangeCodes.setApplyRangeCode(code);
            stComplianeRangeCodes.setCreatedUser(UserUtil.getUserCode());
            stComplianeRangeCodes.setVaild(StmConstans.DEFAULT_VALID);
            stComplianeRangeCodes.setUpdatedUser(UserUtil.getUserCode());
            stComplianeRangeCodesList.add(stComplianeRangeCodes);
        }
        this.saveBatch(stComplianeRangeCodesList);
    }
}
