package com.chinaweal.aiccs.aiccs.force.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterRes;
import com.chinaweal.aiccs.aiccs.force.entity.querydto.ForceDeregisterSpeQueryDto;
import com.chinaweal.aiccs.aiccs.force.mapper.XrForceDeregisterResMapper;
import com.chinaweal.aiccs.aiccs.force.service.IXrForceDeregisterResService;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery;
import org.springframework.stereotype.Service;


/**
 * 拟强制注销公告详细 服务实现类
 *
 * @author zhouxy
 * @since 2025/9/28
 */
@Service
public class XrForceDeregisterResServiceImpl extends ServiceImpl<XrForceDeregisterResMapper, XrForceDeregisterRes> implements IXrForceDeregisterResService {


    @Override
    public IPage<XrForceDeregisterRes> pageForceResByRegOrg(BaseQuery<ForceDeregisterSpeQueryDto> query, AICUser user) {
        ForceDeregisterSpeQueryDto entity = query.getEntity(ForceDeregisterSpeQueryDto.class);
        IPage<XrForceDeregisterRes> forceDeregisterResPage = new Page<>();
        String userRegOrg = StringUtils.substring(user.getRegionID(), 0, 6);
        String entName = entity.getEntName();
        String searchUscc = entity.getSearchUscc();

        Page<XrForceDeregisterRes> page = new Page<>(query.getCurrent(), query.getSize());
        LambdaQueryWrapper<XrForceDeregisterRes> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(XrForceDeregisterRes::getRegOrg, userRegOrg); //只查正在进行拟强制注销公告
        if(StringUtils.isNotBlank(entName)){
            wrapper.like(XrForceDeregisterRes::getEntName, entName);
        }
        if(StringUtils.isNotBlank(searchUscc)){
            wrapper.and(w -> w.eq(XrForceDeregisterRes::getUniscId, searchUscc)
                    .or().eq(XrForceDeregisterRes::getRegno, searchUscc));
        }

        forceDeregisterResPage = this.page(page, wrapper);
        return forceDeregisterResPage;
    }

}
