package org.springblade.modules.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.entity.CyryEntity;
import org.springblade.modules.entity.SyryEntity;
import org.springblade.modules.mapper.SyryMapper;
import org.springblade.modules.service.SyryService;
import org.springblade.modules.vo.*;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SyryServiceImpl extends ServiceImpl<SyryMapper, SyryEntity> implements SyryService {
	@Override
	public IPage<SyryEntity> getFwry(IPage<SyryEntity> page, Map<String, Object> params) {
		List<SyryEntity> fwry = baseMapper.getFwry(page, params);
		if(fwry.size()>0){
			for (int i = 0; i < fwry.size(); i++) {
				SyryEntity syjzryVOs = fwry.get(i);
				String dzbm = syjzryVOs.getDzbm();
				syjzryVOs.setDzXz(baseMapper.getFwxzByRkDzxx(dzbm));
			}
		}
		return page.setRecords(fwry);
	}

	@Override
	public CzrkVO fwryCzrkDetail(SyryEntity syryEntity) {
		CzrkVO czrkVO = baseMapper.fwryCzrkDetail(syryEntity);
		String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(czrkVO.getDzbm());
		czrkVO.setDzXz(fwxzByRkDzxx);
		return czrkVO;
	}

	@Override
	public JwrkVO fwryJwrkDetail(SyryEntity syryEntity) {
		JwrkVO jwrkVO = baseMapper.fwryJwrkDetail(syryEntity);
		String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(jwrkVO.getDzbm());
		jwrkVO.setDzXz(fwxzByRkDzxx);
		return jwrkVO;
	}

	@Override
	public JzrkVO fwryJzrkDetail(SyryEntity syryEntity) {
		JzrkVO jzrkVO = baseMapper.fwryJzrkDetail(syryEntity);
		String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(jzrkVO.getDzbm());
		jzrkVO.setDzXz(fwxzByRkDzxx);
		return jzrkVO;
	}

	@Override
	public WlrkVO fwryWlrkDetail(SyryEntity syryEntity) {
		WlrkVO wlrkVO = baseMapper.fwryWlrkDetail(syryEntity);
		String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(wlrkVO.getDzbm());
		wlrkVO.setDzXz(fwxzByRkDzxx);
		return wlrkVO;
	}

	@Override
	public ZzrkVO fwryZzrkDetail(SyryEntity syryEntity) {
		ZzrkVO zzrkVO = baseMapper.fwryZzrkDetail(syryEntity);
		String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(zzrkVO.getDzbm());
		zzrkVO.setDzXz(fwxzByRkDzxx);
		return zzrkVO;
	}

	@Override
	public String selectDictBiz(String tsrq) {
		return baseMapper.selectDictBiz(tsrq);
	}

	@Override
	public UserVO djxx(Long id) {
		return baseMapper.djxx(id);
	}

	@Override
	public void updateFwId(Long fwId, String dzbm, String ryType, Long ryId) {
		baseMapper.updateFwId(fwId, dzbm, ryType, ryId);
	}

	@Override
	public CzrkVO cyryCzrkDetail(String gmsfhm) {
		CzrkVO czrkVO = baseMapper.cyryCzrkDetail(gmsfhm);
		if (czrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(czrkVO.getDzbm());
			czrkVO.setDzXz(fwxzByRkDzxx);
			if (czrkVO.getRyTsLb() != null && !czrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = czrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				czrkVO.setRyTsLb(tsrqlb);
			}
		}
		return czrkVO;
	}

	@Override
	public JwrkVO cyryJwrkDetail(String gmsfhm) {
		JwrkVO jwrkVO = baseMapper.cyryJwrkDetail(gmsfhm);
		if (jwrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(jwrkVO.getDzbm());
			jwrkVO.setDzXz(fwxzByRkDzxx);
			if (jwrkVO.getRyTsLb() != null && !jwrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = jwrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				jwrkVO.setRyTsLb(tsrqlb);
			}
		}
		return jwrkVO;
	}

	@Override
	public JzrkVO cyryJzrkDetail(String gmsfhm) {
		JzrkVO jzrkVO = baseMapper.cyryJzrkDetail(gmsfhm);
		if (jzrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(jzrkVO.getDzbm());
			jzrkVO.setDzXz(fwxzByRkDzxx);
			if (jzrkVO.getRyTsLb() != null && !jzrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = jzrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				jzrkVO.setRyTsLb(tsrqlb);
			}
		}
		return jzrkVO;
	}

	@Override
	public WlrkVO cyryWlrkDetail(String gmsfhm) {
		WlrkVO wlrkVO = baseMapper.cyryWlrkDetail(gmsfhm);
		if (wlrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(wlrkVO.getDzbm());
			wlrkVO.setDzXz(fwxzByRkDzxx);
			if (wlrkVO.getRyTsLb() != null && !wlrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = wlrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				wlrkVO.setRyTsLb(tsrqlb);
			}
		}
		return wlrkVO;
	}

	@Override
	public ZzrkVO cyryZzrkDetail(String gmsfhm) {
		ZzrkVO zzrkVO = baseMapper.cyryZzrkDetail(gmsfhm);
		if (zzrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(zzrkVO.getDzbm());
			zzrkVO.setDzXz(fwxzByRkDzxx);
			if (zzrkVO.getRyTsLb() != null && !zzrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = zzrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				zzrkVO.setRyTsLb(tsrqlb);
			}
		}
		return zzrkVO;
	}

	@Override
	public CzrkVO cyrylsCzrkDetail(String gmsfhm, String dzbm) {
		CzrkVO czrkVO = baseMapper.cyrylsCzrkDetail(gmsfhm, dzbm);
		if (czrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(czrkVO.getDzbm());
			czrkVO.setDzXz(fwxzByRkDzxx);
			if (czrkVO.getRyTsLb() != null && !czrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = czrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				czrkVO.setRyTsLb(tsrqlb);
			}
		}
		return czrkVO;
	}

	@Override
	public JwrkVO cyrylsJwrkDetail(String gmsfhm, String dzbm) {
		JwrkVO jwrkVO = baseMapper.cyrylsJwrkDetail(gmsfhm, dzbm);
		if (jwrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(jwrkVO.getDzbm());
			jwrkVO.setDzXz(fwxzByRkDzxx);
			if (jwrkVO.getRyTsLb() != null && !jwrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = jwrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				jwrkVO.setRyTsLb(tsrqlb);
			}
		}
		return jwrkVO;
	}

	@Override
	public JzrkVO cyrylsJzrkDetail(String gmsfhm, String dzbm) {
		JzrkVO jzrkVO = baseMapper.cyrylsJzrkDetail(gmsfhm, dzbm);
		if (jzrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(jzrkVO.getDzbm());
			jzrkVO.setDzXz(fwxzByRkDzxx);
			if (jzrkVO.getRyTsLb() != null && !jzrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = jzrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				jzrkVO.setRyTsLb(tsrqlb);
			}
		}
		return jzrkVO;
	}

	@Override
	public WlrkVO cyrylsWlrkDetail(String gmsfhm, String dzbm) {
		WlrkVO wlrkVO = baseMapper.cyrylsWlrkDetail(gmsfhm, dzbm);
		if (wlrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(wlrkVO.getDzbm());
			wlrkVO.setDzXz(fwxzByRkDzxx);
			if (wlrkVO.getRyTsLb() != null && !wlrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = wlrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				wlrkVO.setRyTsLb(tsrqlb);
			}
		}
		return wlrkVO;
	}

	@Override
	public ZzrkVO cyrylsZzrkDetail(String gmsfhm, String dzbm) {
		ZzrkVO zzrkVO = baseMapper.cyrylsZzrkDetail(gmsfhm, dzbm);
		if (zzrkVO != null) {
			String fwxzByRkDzxx = baseMapper.getFwxzByRkDzxx(zzrkVO.getDzbm());
			zzrkVO.setDzXz(fwxzByRkDzxx);
			if (zzrkVO.getRyTsLb() != null && !zzrkVO.getRyTsLb().equals("")) {
				String tsrqlb = "";
				String[] split = zzrkVO.getRyTsLb().split(",");
				for (int i = 0; i < split.length; i++) {
					String s = split[i];
					String tsrq = baseMapper.selectDictBiz(s);
					tsrqlb += tsrq + ",";
				}
				if (tsrqlb.contains(",")){
					int index = tsrqlb.lastIndexOf(",");
					tsrqlb = tsrqlb.substring(0, index);
				}
				zzrkVO.setRyTsLb(tsrqlb);
			}
		}
		return zzrkVO;
	}

	@Override
	public CyryEntity cyryDetail(String gmsfhm) {
		return baseMapper.cyryDetail(gmsfhm);
	}

	@Override
	public List<SyryEntity> getMphxlhByLdphxlh(Map<String, Object> params) {
		return baseMapper.getMphxlhByLdphxlh(params);
	}

	@Override
	public SyryEntity selectFwInfo(Map<String, Object> params, String dzbm) {
		SyryEntity syry = baseMapper.selectFwInfo(params, dzbm);
		if (syry != null) {
			syry.setDzXz(baseMapper.getFwxzByRkDzxx(dzbm));
		}
		return syry;
	}
}
