package org.jeecg.modules.qyxx.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.qyxx.entity.CsPtQyxx;
import org.jeecg.modules.qyxx.mapper.CsPtQyxxMapper;
import org.jeecg.modules.qyxx.service.ICsPtQyxxService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 企业信息
 * @Author: jeecg-boot
 * @Date: 2023-08-19
 * @Version: V1.0
 */
@Service
public class CsPtQyxxServiceImpl extends ServiceImpl<CsPtQyxxMapper, CsPtQyxx> implements ICsPtQyxxService {

    @Override
    public List<CsPtQyxx> selectQyxxByKpzd(String zdlx) {
        return this.baseMapper.selectQyxxByKpzd(zdlx);
    }

    @Override
    public CsPtQyxx getByNsrsbh(String nsrsbh) {
        CsPtQyxx csPtQyxx = this.lambdaQuery().eq(CsPtQyxx::getNsrsbh, nsrsbh).one();
        if (csPtQyxx == null) {
            throw new JeecgBootException("企业税号不存在:" + nsrsbh);
        }
        return csPtQyxx;
    }

    @Override
    @DS(CommonConstant.DS_CWGX)
    public void syncData(CsPtQyxx qyxx) {
        List<CsPtQyxx> list = this.lambdaQuery()
                .eq(CsPtQyxx::getNsrsbh, qyxx.getNsrsbh())
                .list();
        for (CsPtQyxx item : list) {
            qyxx.setId(item.getId());
            this.updateById(qyxx);
        }
    }
}
