package com.zjrs.ggfw.rlzysc.blo.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.mohrss.leaf.core.framework.domain.blo.impl.BLOImpl;
import org.mohrss.leaf.core.framework.persistens.PageResult;
import org.mohrss.leaf.core.framework.persistens.PageUtil;
import com.zjrs.ggfw.portal.blo.CommBLO;
import com.zjrs.ggfw.portal.po.VGgfwDict;
import com.zjrs.ggfw.rlzysc.blo.JxgwBLO;
import com.zjrs.ggfw.rlzysc.dto.JxgwCommDTO;
import com.zjrs.ggfw.rlzysc.dto.JxgwDTO;
import com.zjrs.ggfw.rlzysc.dto.JxgwQueryDTO;
import com.zjrs.ggfw.rlzysc.entity.VRsRlzyJxgwMapper;
import com.zjrs.ggfw.rlzysc.po.VRsRlzyJxgwPO;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class JxgwBLOimpl extends BLOImpl implements JxgwBLO {

    @Resource
    private VRsRlzyJxgwMapper vRsRlzyJxgwMapper;
    @Resource
    CommBLO commBLO;

    @Override
    public PageResult getList(JxgwQueryDTO dto) {
        Page<JxgwDTO> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<JxgwDTO> pageResult = (Page) vRsRlzyJxgwMapper.getList(page, dto);
        List<JxgwDTO> list = pageResult.getRecords();
        chargeSfyq(list);

        PageResult result = PageUtil.PageResult(pageResult);
        return result;
    }
    @Override
    public VRsRlzyJxgwPO getDetail(JxgwCommDTO dto){
        QueryWrapper<VRsRlzyJxgwPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("rs_rlzy_jxgw_lsh", dto.getId());
        VRsRlzyJxgwPO po = this.vRsRlzyJxgwMapper.selectOne(queryWrapper);
        //转换身份要求字典
        JxgwDTO jxgwDTO = new JxgwDTO();
        jxgwDTO.setSfyq(po.getSfyq());
        List<JxgwDTO> list= new ArrayList<>() ;
        list.add(jxgwDTO);
        po.setSfyq(list.get(0).getSfyq());

        return po;
    }
    //转换身份要求字典
    public void chargeSfyq(List<JxgwDTO> list){
        //取身份要求字典
        List<VGgfwDict> sfyqList = commBLO.getGgfwDict("RS_RLZY_JXGW_SFYQ");
        //字典转换
        for(JxgwDTO jxgw: list){
            String sfyq = jxgw.getSfyq();
            if(StringUtils.isNotBlank(sfyq)){
                String sfyqValue = "";                
                if(StringUtils.isNotBlank(sfyqValue)){
                    sfyqValue = sfyqValue.substring(0, sfyqValue.length() - 1);
                }
                jxgw.setSfyq(sfyqValue);
            }
        }
    }
}



