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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
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 org.mohrss.leaf.core.framework.util.CurrentUser;
import com.zjrs.ggfw.portal.blo.SxblBLO;
import com.zjrs.ggfw.portal.blo.UserBLO;
import com.zjrs.ggfw.portal.dto.*;
import com.zjrs.ggfw.portal.entity.*;
import com.zjrs.ggfw.portal.po.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

import static org.mohrss.leaf.core.framework.util.SecurityUtils.getCurrentUser;

@Service
public class SxblBLOImpl extends BLOImpl implements SxblBLO {
	private static final Logger LOG = LoggerFactory.getLogger(SxblBLOImpl.class);

	@Resource
	VRsWbBjListMapper vRsWbBjListMapper;
	
	@Resource
	VRsSxConfigMapper vRsSxConfigMapper;
	
	@Resource
	VRsSxConfigFileMapper vRsSxConfigFileMapper;
	
	@Resource
	VRsWbBjMapper vRsWbBjMapper;
	
	@Resource
	VRsWbCkslxxHjMapper vRsWbCkslxxHjMapper;
	
	@Resource
	VRsSlxxJbxxMapper vRsSlxxJbxxMapper;
	
	@Resource
	VRsWbZfxxysqgkMapper vRsWbZfxxysqgkMapper;
	
	@Resource
	VRsWbXfsxtcMapper vRsWbXfsxtcMapper;
	
	@Resource
	VRsSxZllbMapper vRsSxZllbMapper;
	
	@Resource
	VRsWbClfjMapper vRsWbClfjMapper;
	
	@Resource
	VRsWbBjZllbMapper vRsWbBjZllbMapper;
	
	@Resource
	VRsZjGccrcSqMapper vRsZjGccrcSqMapper;
	
	@Resource
	VRsXxzxShbzkxxMapper vRsXxzxShbzkxxMapper;
	
	@Resource
	VRsXxzxShbzkxxJkrzMapper vRsXxzxShbzkxxJkrzMapper;
	
	@Resource
	VRsPsamYwxxSqbMapper vRsPsamYwxxSqbMapper;
	
	@Resource
	VRsPsamAzjgxxMapper vRsPsamAzjgxxMapper;
	
	@Resource
	VRsPsamAzfkxxbMapper vRsPsamAzfkxxbMapper;
	
	@Resource
	VRsPsamRkxxbMapper vRsPsamRkxxbMapper;
	
	@Resource
	Ab33Mapper ab33Mapper;
	
	@Resource
	VRsJkHcpMapper vRsJkHcpMapper;

	@Resource
	VRsSxblFjMapper vRsSxblFjMapper;

	@Resource
	VRsWbDazdMapper vRsWbDazdMapper;

	@Resource
	VRsWbDyclzdMapper vRsWbDyclzdMapper;

	@Resource
	RsJcQxksclSqMapper rsJcQxksclSqMapper;

	@Resource
	VRsGgfwUserMapper vRsGgfwUserMapper;
	@Resource
	VRsWbBjListForGrMapper vRsWbBjListForGrMapper;
	@Resource
	RsSlxxJglqMapper rsSlxxJglqMapper;
	@Resource
	EMSMapper emsMapper;
	@Resource
	RsWbBjSubMapper rsWbBjSubMapper;

	@Resource
	private UserBLO userBLO;

	@Override
	public PageResult getBjList(SxblQueryDTO dto) {
		VRsGgfwUser user = this.vRsGgfwUserMapper.selectById(dto.getYhid());
		if(user.getFwdx().equals("2")){
			return getBjListDw(dto);
		}
		return getBjListGr(dto);
	}
	/**
	 * 办件列表条件
	 * @param dto
	 * @return
	 */
	private QueryWrapper getBjListGetWhere(SxblQueryDTO dto){
		//查询条件
		QueryWrapper queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("yhid", dto.getYhid());
		//受理编号
		if(StringUtils.isNotBlank(dto.getSlbh())) {
			queryWrapper.like("slbh", dto.getSlbh());
		}
		//申请日期起
		if(StringUtils.isNotBlank(dto.getSqrqq())) {
			queryWrapper.ge("sqsj", dto.getSqrqq()+" 00:00:00");
		}
		//申请日期至
		if(StringUtils.isNotBlank(dto.getSqrqz())) {
			queryWrapper.le("sqsj", dto.getSqrqz()+" 23:59:59");
		}
		return queryWrapper;
	}

	/**
	 * 办件列表-单位账号
	 * @param dto
	 * @return
	 */
	private PageResult getBjListDw(SxblQueryDTO dto) {
		List<String> list = new ArrayList();
		if (StringUtils.isNotBlank(dto.getSqzt())) {
			list = Arrays.asList(dto.getSqzt().split(","));
		}
		Page<VRsWbBjList> page = new Page<>(dto.getPagenum(), dto.getPagesize());
		Page<VRsWbBjList> pageResult = (Page) this.vRsWbBjListMapper.getBjListDw(page, dto, list);
		PageResult result = PageUtil.PageResult(pageResult);
		return result;
	}

	/**
	 * 办件列表-个人账号
	 * @param dto
	 * @return
	 */
	private PageResult getBjListGr(SxblQueryDTO dto) {
		Page<VRsWbBjListForGr> page = new Page<>(dto.getPagenum(), dto.getPagesize());
		List<String> list = new ArrayList();
		if (StringUtils.isNotBlank(dto.getSqzt())) {
			list = Arrays.asList(dto.getSqzt().split(","));
		}
		Page<VRsWbBjListForGr> pageResult = (Page) this.vRsWbBjListForGrMapper.getBjListGr(page, dto,list);
		PageResult result = PageUtil.PageResult(pageResult);
		return result;
	}

	@Override
	public PageResult getZzzdBjList(BjjdZzzdQueryDTO dto) {
		//查询条件
        QueryWrapper<VRsWbBjList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ztid", dto.getZtid());
		//按最后修改时间倒序
        queryWrapper.orderByDesc("zhxgsj");
        
        Page<VRsWbBjList> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<VRsWbBjList> pageResult = (Page) this.vRsWbBjListMapper.selectPage(page, queryWrapper);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
	}
	
	@Override
	public Map<String,Object> getSlxxHj(SlxxHjQueryDTO dto){
		Map<String,Object> returnMap = new HashMap<>();
		QueryWrapper<VRsWbCkslxxHj> queryWrapper = new QueryWrapper<>();
		//查询办件状态
		QueryWrapper<VRsWbBjListForGr> wbBjListForGrQueryWrapper = new QueryWrapper<>();
		//受理流水号
        if(StringUtils.isNotBlank(dto.getSllsh())) {
        	queryWrapper.eq("sllsh", dto.getSllsh());
        	//查询物流信息
			QueryWrapper<SlxxEMSOrderPO> wlxxQueryWrapper = new QueryWrapper<SlxxEMSOrderPO>();
			SlxxEMSOrderPO slxxEMSOrderPO = emsMapper.selectOne(wlxxQueryWrapper);
			//查询结果领取信息
			QueryWrapper<SlxxJglqPO> slxxQueryWrapper = new QueryWrapper<SlxxJglqPO>();
			slxxQueryWrapper.select("lqr","lqrq","bz");
			SlxxJglqPO slxxJglqPO = rsSlxxJglqMapper.selectOne(slxxQueryWrapper);
			returnMap.put("jglq",slxxJglqPO);
			wbBjListForGrQueryWrapper.eq("SLLSH",dto.getSllsh());
        }
        queryWrapper.orderByDesc("jbsj");//按经办时间倒序
		VRsWbBjListForGr vRsWbBjListForGr = vRsWbBjListForGrMapper.selectOne(wbBjListForGrQueryWrapper);
		returnMap.put("bjxx",vRsWbBjListForGr);
		return returnMap;
	}
	
	@Override
	public VRsSxConfig getRsSxConfig(String sxbm) {
		return vRsSxConfigMapper.selectById(sxbm);
	}
	
	@Override
	public PageResult getRsSxConfigFile(SxConfigFileQueryDTO dto) {
		QueryWrapper<VRsSxConfigFile> queryWrapper = new QueryWrapper<>();
		Page<VRsSxConfigFile> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<VRsSxConfigFile> pageResult = (Page) this.vRsSxConfigFileMapper.selectPage(page, queryWrapper);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
	}
	
	@Override
	public VRsWbBjList getRsWbBj(BjQueryDTO dto) {
		QueryWrapper<VRsWbBjList> queryWrapper = new QueryWrapper<>();
		List<VRsWbBjList> vRsWbBjLists = vRsWbBjListMapper.selectList(queryWrapper);
		if (CollectionUtils.isEmpty(vRsWbBjLists)){
			return null;
		} else {
			return vRsWbBjLists.get(0);
		}
	}

	@Override
	public VRsWbBj getRsWbBjById(BjQueryDTO dto) {
		return vRsWbBjMapper.selectById(dto.getRsWbBjLsh());
	}
	
	@Override
	public VRsWbBjList getRsWbBjLchj(String sllsh,String rsWbBjLsh) {
		QueryWrapper<VRsWbBjList> queryWrapper = new QueryWrapper<>();
		return vRsWbBjListMapper.selectOne(queryWrapper);
	}
	
	@Override
	public VRsSlxxJbxx getRsSlxxJbxx(BjQueryDTO dto) {
		QueryWrapper<VRsSlxxJbxx> queryWrapper = new QueryWrapper<>();
		return vRsSlxxJbxxMapper.selectOne(queryWrapper);
	}
	
	@Override
	public VRsWbBj saveBj(VRsWbBj vRsWbBj) {
		if(StringUtils.isNotBlank(vRsWbBj.getRsWbBjLsh())) {
			vRsWbBjMapper.updateById(vRsWbBj);
		}else {
			vRsWbBj.setRsWbBjLsh(UUID.randomUUID().toString().replace("-", ""));
			vRsWbBjMapper.insert(vRsWbBj);
		}
		return vRsWbBj;
	}
	
	@Override
	public void saveRsSlxxJbxx(VRsSlxxJbxx vRsSlxxJbxx) {
		QueryWrapper<VRsSlxxJbxx> queryWrapper = new QueryWrapper<>();
		VRsSlxxJbxx vRsSlxxJbxxTemp = vRsSlxxJbxxMapper.selectOne(queryWrapper);
		if(vRsSlxxJbxxTemp != null) {
			vRsSlxxJbxx.setRsSlxxJbxxLsh(vRsSlxxJbxxTemp.getRsSlxxJbxxLsh());
			vRsSlxxJbxxMapper.updateById(vRsSlxxJbxx);
		}else {
			vRsSlxxJbxxMapper.insert(vRsSlxxJbxx);
		}
	}
	
	@Override
	public void saveGrZfxxysqgk(VRsWbZfxxysqgk vRsWbZfxxysqgk) {
		if(StringUtils.isNotBlank(vRsWbZfxxysqgk.getRsWbZfxxysqgkLsh())) {
			//防止非必录字段，清空后，无法更新到，先删除原纪录重新保存
			vRsWbZfxxysqgkMapper.deleteById(vRsWbZfxxysqgk.getRsWbZfxxysqgkLsh());
		}
		vRsWbZfxxysqgkMapper.insert(vRsWbZfxxysqgk);
	}
	
	@Override
	public void saveXfsxtc(VRsWbXfsxtc vRsWbXfsxtc) {
		if(StringUtils.isNotBlank(vRsWbXfsxtc.getRsWbXfsxtcLsh())) {
			//防止非必录字段，清空后，无法更新到，先删除原纪录重新保存
			vRsWbXfsxtcMapper.deleteById(vRsWbXfsxtc.getRsWbXfsxtcLsh());
		}
		vRsWbXfsxtcMapper.insert(vRsWbXfsxtc);
	}
	
	@Override
	public void saveGccrcrd(VRsZjGccrcSq vRsZjGccrcSq) {

		if(StringUtils.isNotBlank(vRsZjGccrcSq.getRsWbBjLsh())){
			QueryWrapper<VRsZjGccrcSq> queryWrapper = new QueryWrapper<>();
			VRsZjGccrcSq vRsZjGccrcSqtemp = this.vRsZjGccrcSqMapper.selectOne(queryWrapper);
			if(vRsZjGccrcSqtemp != null){
				vRsZjGccrcSq.setRsZjGccrcSqLsh(vRsZjGccrcSqtemp.getRsZjGccrcSqLsh());
			}
		}

		if(StringUtils.isNotBlank(vRsZjGccrcSq.getRsZjGccrcSqLsh())) {
			//防止非必录字段，清空后，无法更新到，先删除原纪录重新保存
			vRsZjGccrcSqMapper.deleteById(vRsZjGccrcSq.getRsZjGccrcSqLsh());
		}
		vRsZjGccrcSqMapper.insert(vRsZjGccrcSq);
	}
	
	@Override
	public VRsXxzxShbzkxx saveShbzkxx(VRsXxzxShbzkxx vRsXxzxShbzkxx) {
		if(StringUtils.isNotBlank(vRsXxzxShbzkxx.getRsXxzxShbzkxxLsh())) {
			//防止非必录字段，清空后，无法更新到，先删除原纪录重新保存
			vRsXxzxShbzkxxMapper.deleteById(vRsXxzxShbzkxx.getRsXxzxShbzkxxLsh());
		}else {
			vRsXxzxShbzkxx.setRsXxzxShbzkxxLsh(UUID.randomUUID().toString().replace("-", ""));
		}
		vRsXxzxShbzkxxMapper.insert(vRsXxzxShbzkxx);
		return vRsXxzxShbzkxx;
	}
	
	@Override
	public void saveRsXxzxShbzkxxJkrz(VRsXxzxShbzkxxJkrz vRsXxzxShbzkxxJkrz) {
		vRsXxzxShbzkxxJkrzMapper.insert(vRsXxzxShbzkxxJkrz);
	}
	
	@Override
	public void savePsamYwxx(VRsPsamYwxxSqb vRsPsamYwxxSqb) {
		if(StringUtils.isNotBlank(vRsPsamYwxxSqb.getRsPsamYwxxSqbLsh())) {
			//防止非必录字段，清空后，无法更新到，先删除原纪录重新保存
			vRsPsamYwxxSqbMapper.deleteById(vRsPsamYwxxSqb.getRsPsamYwxxSqbLsh());
		}
		vRsPsamYwxxSqbMapper.insert(vRsPsamYwxxSqb);
	}
	
	@Override
	public VRsWbZfxxysqgk getZfxxysqgk(BjQueryDTO dto) {
		QueryWrapper<VRsWbZfxxysqgk> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("rs_wb_bj_lsh", dto.getRsWbBjLsh());
		return vRsWbZfxxysqgkMapper.selectOne(queryWrapper);
	}
	
	@Override
	public VRsWbXfsxtc getXfsxtc(BjQueryDTO dto) {
		QueryWrapper<VRsWbXfsxtc> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("rs_wb_bj_lsh", dto.getRsWbBjLsh());
		return vRsWbXfsxtcMapper.selectOne(queryWrapper);
	}
	
	@Override
	public VRsZjGccrcSq getGccrcSq(BjQueryDTO dto) {
		QueryWrapper<VRsZjGccrcSq> queryWrapper = new QueryWrapper<>();
		return vRsZjGccrcSqMapper.selectOne(queryWrapper);
	}
	
	@Override
	public VRsXxzxShbzkxx getRsXxzxShbzkxx(BjQueryDTO dto) {
		QueryWrapper<VRsXxzxShbzkxx> queryWrapper = new QueryWrapper<>();
		return vRsXxzxShbzkxxMapper.selectOne(queryWrapper);
	}
	
	@Override
	public List<VRsXxzxShbzkxxJkrz> getRsXxzxShbzkxxJkrz(BjQueryDTO dto){
		QueryWrapper<VRsXxzxShbzkxxJkrz> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("czjg", "1");//小程序、网办只显示成功记录，用户历史办件信息查看
		return vRsXxzxShbzkxxJkrzMapper.selectList(queryWrapper);
	}
	
	@Override
	public VRsPsamYwxxSqb getRsPsamYwxx(BjQueryDTO dto) {
		QueryWrapper<VRsPsamYwxxSqb> queryWrapper = new QueryWrapper<>();
		return vRsPsamYwxxSqbMapper.selectOne(queryWrapper);
	}

	@Override
	public List<VRsPsamAzjgxx> getRsPsamAzjgList(){
		QueryWrapper<VRsPsamAzjgxx> queryWrapper = new QueryWrapper<>();
    	queryWrapper.eq("ts_scbs", "0");
    	return vRsPsamAzjgxxMapper.selectList(queryWrapper);
	}
	
	@Override
	public VRsPsamRkxxb getRsPsamRkxxByBh(String psamBh) {
		QueryWrapper<VRsPsamRkxxb> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("psambh",psamBh);
		queryWrapper.eq("rownum", 1);
		return vRsPsamRkxxbMapper.selectOne(queryWrapper);
	}
	
	@Override
	public PageResult getSxclList(SxZllbQueryDTO dto) {
        QueryWrapper<VRsSxZllb> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("orderno");
        
        Page<VRsSxZllb> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<VRsSxZllb> pageResult = (Page) this.vRsSxZllbMapper.selectPage(page, queryWrapper);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
	}
	
	@Override
	public PageResult getSxSdzlList(BjZllbQueryDTO dto) {
		QueryWrapper<VRsWbBjZllb> queryWrapper = new QueryWrapper<>();
		//判断是否属于子项及获取子项事项编码
		queryWrapper.orderByAsc("orderno");
        Page<VRsWbBjZllb> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<VRsWbBjZllb> pageResult = (Page) this.vRsWbBjZllbMapper.selectPage(page, queryWrapper);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
	}
	
	@Override
	public PageResult getBjSxclList(ClfjQueryDTO dto) {
		QueryWrapper<VRsWbClfj> queryWrapper = new QueryWrapper<>();
		queryWrapper.orderByDesc("cjsj");
		
		Page<VRsWbClfj> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<VRsWbClfj> pageResult = (Page) this.vRsWbClfjMapper.selectPage(page, queryWrapper);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
	}
	
	@Override
	public void saveClfj(VRsWbClfj vRsWbClfj) {
		vRsWbClfjMapper.insert(vRsWbClfj);
	}
	
	@Override
	public void delClfj(ClfjDelDTO dto) {
		UpdateWrapper<VRsWbClfj> updateWrapper = new UpdateWrapper<>();
		String fjids = dto.getRsWbClfjLsh();
    	//更新有效标志
		VRsWbClfj vRsWbClfj = new VRsWbClfj();
		vRsWbClfj.setTsYxbz("0");
		vRsWbClfjMapper.update(vRsWbClfj, updateWrapper);
	}
	
	@Override
	public boolean isSxsh(String sxbm,String userid) {
		boolean isSxsh = false;
		QueryWrapper<VRsWbBjList> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("sbsx", sxbm);
		int cnt = vRsWbBjListMapper.selectCount(queryWrapper);
		if(cnt > 0) {
			isSxsh = true;
		}
		return isSxsh;
	}
	
	@Override
	public boolean isUploadAllClfj(String rsWbBjLsh) {
		CurrentUser currentUser = getCurrentUser();
		String userid = currentUser.getUsername() == null ? "" : currentUser.getUsername().trim();

		QueryWrapper<VRsGgfwUser> userQueryWrapper = new QueryWrapper<>();
		userQueryWrapper.eq("userid", userid);
		VRsGgfwUser user = vRsGgfwUserMapper.selectOne(userQueryWrapper);

		boolean isUploadAllClfj = true;
		QueryWrapper<VRsWbBjZllb> queryWrapper = new QueryWrapper<>();
		queryWrapper.like("sydx", user.getFwdx());	// 服务对象
		//判断是否属于子项及获取子项事项编码
		String sbsxS = rsWbBjSubMapper.getSubBjSbsx(rsWbBjLsh);
		if (StringUtils.isNotBlank(sbsxS)) {
			String[] split = sbsxS.split(",");
			queryWrapper.and(wrapper->{
						for (int i = 0; i < split.length; i++) {
							wrapper.like("sysx",split[i]);
							if (i != split.length){
								wrapper.or();
							}
						}
						return wrapper;
					}
			);
		}
        int cnt = vRsWbBjZllbMapper.selectCount(queryWrapper);
		if(cnt > 0) {
			isUploadAllClfj = false;
		}
		return isUploadAllClfj;
	}
	
	@Override
	public Ab33 getAb33(String dwmc, String sxbm) {
		QueryWrapper<Ab33> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("bhb245", dwmc);
		return ab33Mapper.selectOne(queryWrapper);
	}
	
	@Override
	public List<VRsPsamAzfkxxb> getRsPsamAzfkList(PsamFkxxListQueryDTO dto) {
		QueryWrapper<VRsPsamAzfkxxb> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("sftj", "0");
		return vRsPsamAzfkxxbMapper.selectList(queryWrapper);
	}
	
	@Override
	public Map<String,Object> getRsPsamAzfkxx(PsamFkxxQueryDTO dto) {
		return vRsPsamAzfkxxbMapper.getRsPsamAzfkxx(dto);
	}
	
	@Override
	public void saveRsPsamAzfkxx(VRsPsamAzfkxxb vRsPsamAzfkxxb) {
		vRsPsamAzfkxxbMapper.updateById(vRsPsamAzfkxxb);
	}
	
	@Override
	public VRsPsamYwxxSqb getRsPsamYwxxSqbById(String rsPsamYwxxSqbLsh) {
		return vRsPsamYwxxSqbMapper.selectById(rsPsamYwxxSqbLsh);
	}
	
	@Override
	public VRsPsamAzjgxx getRsPsamAzjgxxById(String rsPsamAzjgxxLsh) {
		return vRsPsamAzjgxxMapper.selectById(rsPsamAzjgxxLsh);
	}
	
	@Override
	public void submitRsPsamAzfkxx(PsamFkxxListQueryDTO dto) {
		UpdateWrapper<VRsPsamAzfkxxb> updateWrapper = new UpdateWrapper<>();
		
		VRsPsamAzfkxxb vRsPsamAzfkxxb = new VRsPsamAzfkxxb();
		vRsPsamAzfkxxb.setSftj("1");
		
		vRsPsamAzfkxxbMapper.update(vRsPsamAzfkxxb, updateWrapper);
	}
	
	@Override
	public List<VRsWbBjList> getPsamBj(VRsWbBjList vRsWbBjList){
		QueryWrapper<VRsWbBjList> queryWrapper = new QueryWrapper<>();
		queryWrapper.in("sqzt", "1","2");//待审核、审核中
		return vRsWbBjListMapper.selectList(queryWrapper);
	}
	
	@Override
	public VRsPsamYwxxSqb getRsPsamBh(VRsWbBjList vRsWbBjList) {
		QueryWrapper<VRsPsamYwxxSqb> queryWrapper = new QueryWrapper<>();
		queryWrapper.select("psambh");
		return vRsPsamYwxxSqbMapper.selectOne(queryWrapper);
	}
	
	@Override
	public void saveRsJkHcp(VRsJkHcp vRsJkHcp) {
		//查询是否已评价
		QueryWrapper<VRsJkHcp> queryWrapper = new QueryWrapper<VRsJkHcp>();
		queryWrapper.eq("evalprocess", vRsJkHcp.getEvalprocess());
		int cnt = vRsJkHcpMapper.selectCount(queryWrapper);
		//若该阶段已评价，不保存数据
		if(cnt < 1) {
			vRsJkHcpMapper.insert(vRsJkHcp);
		}
	}
	
	@Override
	public List<VRsJkHcp> getRsJkHcp(SlxxHjQueryDTO dto){
		QueryWrapper<VRsJkHcp> queryWrapper = new QueryWrapper<>();
		queryWrapper.orderByAsc("evalprocess");
		return vRsJkHcpMapper.selectList(queryWrapper);
	}
	
	@Override
	public int getHcpBjCnt(String userid) {
		QueryWrapper<VRsWbBjListForGr> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("yhid", userid);
        queryWrapper.ge("sqzt", "1");//外网提交可评价
        //未评价
		return vRsWbBjListForGrMapper.selectCount(queryWrapper);
	}

	//办件信息结果附件
	@Override
	public PageResult getFjList(SxblFjDTO dto){
		Page<FjListDTO> page = new Page<>(dto.getPagenum(), dto.getPagesize());
		Page<FjListDTO> pageResult = (Page) this.vRsSxblFjMapper.getFjList(page,dto.getSllsh());
		PageResult result = PageUtil.PageResult(pageResult);
		return result;
	}

	@Override
	public void saveDazd(VRsWbDazd vRsWbDazd) {
		QueryWrapper<VRsWbDazd> queryWrapper = new QueryWrapper<>();
		List<VRsWbDazd> list = this.vRsWbDazdMapper.selectList(queryWrapper);
		if (list.size() == 0){//新增
			this.vRsWbDazdMapper.insert(vRsWbDazd);
		}else{ //修改
			VRsWbDazd vRsWbDazd2 = new VRsWbDazd();
			vRsWbDazd2.setDddwmc(vRsWbDazd.getDddwmc());
			UpdateWrapper<VRsWbDazd> updateWrapper = new UpdateWrapper<>();
			updateWrapper.eq("RS_WB_BJ_LSH",vRsWbDazd.getRsWbBjLsh());
			this.vRsWbDazdMapper.update(vRsWbDazd2,updateWrapper);
		}

	}

	@Override
	public void saveDyclzd(VRsWbDyclzd vRsWbDyclzd) {
		QueryWrapper<VRsWbDyclzd> queryWrapper = new QueryWrapper<>();
		List<VRsWbDyclzd> list = this.vRsWbDyclzdMapper.selectList(queryWrapper);
		if (list.size() == 0){//新增
			this.vRsWbDyclzdMapper.insert(vRsWbDyclzd);
		}else{ //修改
			VRsWbDyclzd vRsWbDyclzd2 = new VRsWbDyclzd();
			vRsWbDyclzd2.setDddwmc(vRsWbDyclzd.getDddwmc());
			UpdateWrapper<VRsWbDyclzd> updateWrapper = new UpdateWrapper<>();
			updateWrapper.eq("RS_WB_BJ_LSH",vRsWbDyclzd.getRsWbBjLsh());
			this.vRsWbDyclzdMapper.update(vRsWbDyclzd2,updateWrapper);
		}
	}


	@Override
	public BjDTO getbjAddress(String sllsh) {
		BjDTO bjDTO	= this.vRsWbBjListMapper.getbjAddress(sllsh);
		return bjDTO;
	}

	@Override
	public void saveTempGccrcrd(VRsZjGccrcSq vRsZjGccrcSq) {

		if(StringUtils.isNotBlank(vRsZjGccrcSq.getRsWbBjLsh())){
			QueryWrapper<VRsZjGccrcSq> queryWrapper = new QueryWrapper<>();
			VRsZjGccrcSq vRsZjGccrcSqtemp = this.vRsZjGccrcSqMapper.selectOne(queryWrapper);
			if(vRsZjGccrcSqtemp != null){
				vRsZjGccrcSq.setRsZjGccrcSqLsh(vRsZjGccrcSqtemp.getRsZjGccrcSqLsh());
			}
		}

		if (StringUtils.isNotBlank(vRsZjGccrcSq.getRsZjGccrcSqLsh())) {
			UpdateWrapper<VRsZjGccrcSq> updateWrapper = new UpdateWrapper<>();
			this.vRsZjGccrcSqMapper.update(vRsZjGccrcSq,updateWrapper);
		} else {
			this.vRsZjGccrcSqMapper.insert(vRsZjGccrcSq);
		}
	}

	@Override
	public void saveQxxsfy(RsJcQxksclSqPO rsJcQxksclSqPO) {
		CurrentUser currentUser = getCurrentUser();
		String userid = currentUser.getUserid() == null ? "" : currentUser.getUserid().trim();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String dataString = dateFormat.format(date);
		rsJcQxksclSqPO.setTsxgsj(dataString);
		QueryWrapper<RsJcQxksclSqPO> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("RS_WB_BJ_LSH",rsJcQxksclSqPO.getRsWbBjLsh());
		List<RsJcQxksclSqPO> list = this.rsJcQxksclSqMapper.selectList(queryWrapper);
		if (list.isEmpty() || list.size() == 0){//新增
			rsJcQxksclSqPO.setTscjsj(dataString);
			this.rsJcQxksclSqMapper.insert(rsJcQxksclSqPO);
		}else{ //修改
			UpdateWrapper<RsJcQxksclSqPO> updateWrapper = new UpdateWrapper<>();
			this.rsJcQxksclSqMapper.update(rsJcQxksclSqPO,updateWrapper);
		}
	}

	@Override
	public RsJcQxksclSqPO getQxxsfy(BjQueryDTO dto) {
		QueryWrapper<RsJcQxksclSqPO> queryWrapper = new QueryWrapper<>();
		return rsJcQxksclSqMapper.selectOne(queryWrapper);
	}

	@Override
	public void saveYjsYwxx(YjsQueryDTO dto) {
			List<String> delList = new ArrayList<>();
			CurrentUser currentUser = getCurrentUser();
		VRsWbBj vRsWbBj = vRsWbBjMapper.selectById(dto.getRsWbBjLsh());
		String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
		dto.getParamsList().forEach(item -> {
				if (StringUtils.isBlank(item.getRsWbBjSubLsh())){ //新增
					item.setZtmc(vRsWbBj.getZtmc());
					item.setSbrxm(vRsWbBj.getSbrxm());
					item.setFwdx(vRsWbBj.getFwdx());
					item.setSjly(vRsWbBj.getSjly());
					item.setCjr(currentUser.getUsername());
					item.setCjsj(currentTime);
					rsWbBjSubMapper.insert(item);
					if (item.getSbsx().equals("4408006209")){ //保存档案转出业务信息
						VRsWbDazd vRsWbDazd = new VRsWbDazd();
						BeanUtils.copyProperties(item,vRsWbDazd);
						vRsWbDazd.setRsWbBjLsh(item.getRsWbBjSubLsh());
						saveDazd(vRsWbDazd);
					}
				} 
				delList.add(item.getSbsx());
			});
		//新增或者修改完之后，要把不在本次保存操作的记录置为无效
		UpdateWrapper<RsWbBjSub> updateWrapper = new UpdateWrapper<>();
		updateWrapper.notIn("SBSX",delList);
		updateWrapper.set("TS_YXBZ","0");
		rsWbBjSubMapper.update(null,updateWrapper);
	}

	@Override
	public List<RsWbBjSub> getYjsYwxx(YjsQueryDTO dto) {
		return rsWbBjSubMapper.getYjsYwxx(dto);
	}

	@Override
	public List<RsWbBjSub> getSubBjXx(String rsWbBjLsh) {
		QueryWrapper<RsWbBjSub> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("TS_YXBZ","1");
		return rsWbBjSubMapper.selectList(queryWrapper);
	}

	@Override
	public void updateSubBj(RsWbBjSub rsWbBjSub) {
		this.rsWbBjSubMapper.updateById(rsWbBjSub);
	}

	@Override
	public void checkCondition(String sxbm) {
		CurrentUser currentUser = getCurrentUser();
		String userid = currentUser.getUsername() == null ? "" : currentUser.getUsername().trim();
		VRsGgfwUser vRsGgfwUser = userBLO.getVRsGgfwUser(userid);
		String fwdx = vRsGgfwUser.getFwdx();//获取服务对象
		QueryWrapper<VRsSxConfig> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(VRsSxConfig::getSxbm,sxbm);	
	}

	@Override
	public VRsWbDazd getDazd(BjQueryDTO dto) {
		VRsWbDazd vRsWbDazd = new VRsWbDazd();
		QueryWrapper<VRsWbDazd> queryWrapper = new QueryWrapper<>();
		List<VRsWbDazd> list = vRsWbDazdMapper.selectList(queryWrapper);
		if (list.size() != 0){
			vRsWbDazd = list.get(0);
		}
		return vRsWbDazd;
	}

	@Override
	public VRsWbDyclzd getDyclzd(BjQueryDTO dto) {
		VRsWbDyclzd vRsWbDyclzd = new VRsWbDyclzd();
		QueryWrapper<VRsWbDyclzd> queryWrapper = new QueryWrapper<>();
		List<VRsWbDyclzd> vRsWbDyclzds = vRsWbDyclzdMapper.selectList(queryWrapper);
		if (vRsWbDyclzds.size() != 0){
			vRsWbDyclzd = vRsWbDyclzds.get(0);
		}
		return vRsWbDyclzd;
	}
}