/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.mdjfxj.djXj.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.commons.lang3.StringUtils;
import org.springblade.common.cache.DictBizCache;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.modules.mdjfdj.vo.MdjfDjVO;
import org.springblade.modules.mdjfxj.djXj.entity.DjXjEntity;
import org.springblade.modules.mdjfxj.djXj.excel.DjXjExcel;
import org.springblade.modules.mdjfxj.djXj.mapper.DjXjMapper;
import org.springblade.modules.mdjfxj.djXj.service.IDjXjService;
import org.springblade.modules.mdjfxj.djXj.vo.DjXjVO;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 矛盾纠纷巡警登记表 服务实现类
 *
 * @author BladeX
 * @since 2024-04-10
 */
@Service
public class DjXjServiceImpl extends BaseServiceImpl<DjXjMapper, DjXjEntity> implements IDjXjService {

	private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@Override
	public IPage<DjXjVO> selectDjXjPage(IPage<DjXjVO> page, Map<String, Object> params) {
		return page.setRecords(baseMapper.selectDjXjPage(page, params));
	}


	@Override
	public List<DjXjExcel> exportDjXj(Wrapper<DjXjEntity> queryWrapper) {
		List<DjXjExcel> djXjList = baseMapper.exportDjXj(queryWrapper);
		//djXjList.forEach(djXj -> {
		//	djXj.setTypeName(DictCache.getValue(DictEnum.YES_NO, DjXj.getType()));
		//});
		return djXjList;
	}

	@Override
	public IPage<DjXjVO> pageToApp(IPage<DjXjVO> page, Map<String, Object> params, String[] mdIds) {
		List<DjXjVO> mdjfDjVOS = baseMapper.pageToApp(page, params,mdIds);
		if(mdjfDjVOS.size()>0){
			for (int i = 0; i < mdjfDjVOS.size(); i++) {
				DjXjVO mdjfDjVO = mdjfDjVOS.get(i);
				String mdjbV = mdjfDjVO.getMdjbV();
				if(mdjfDjVO != null){
					int cscs = 0;
					if(mdjfDjVO.getDychf() == 2){
						cscs++;
					}
					if(mdjfDjVO.getDechf() == 2){
						cscs++;
					}
					if(mdjfDjVO.getDschf() == 2){
						cscs++;
					}
					mdjfDjVO.setCscs(cscs);
					if(StringUtils.isNotBlank(mdjfDjVO.getHfztNew())){
						mdjfDjVO.setHfztNewValve(DictBizCache.getValue("hfzt",mdjfDjVO.getHfztNew()));
					}
					if(StringUtils.isNotBlank(mdjfDjVO.getCszt())){
						mdjfDjVO.setCsztValue(DictBizCache.getValue("cszt",mdjfDjVO.getCszt()));
					}
					if(StringUtils.isNotBlank(mdjbV)){
						mdjfDjVO.setMdjbVVlaue(DictBizCache.getValue("mddj", mdjbV));
						if("0".equals(mdjfDjVO.getHfztNew()) || "1".equals(mdjfDjVO.getHfztNew())){
							if(mdjfDjVO.getHfjzsj() != null){
								mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj())+"前进行回访");
							}
							if("A".equals(mdjbV)){
								if(mdjfDjVO.getHfjzsj()!=null && mdjfDjVO.getHfjzsj2()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj2()) < 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj2())+"前进行回访");
									}
								}
								if(mdjfDjVO.getHfjzsj2()!=null && mdjfDjVO.getHfjzsj3()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj2()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj3()) < 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj3())+"前进行回访");
									}
								}
								if(mdjfDjVO.getHfjzsj3()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj3()) > 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj3())+"前进行回访");
									}
								}

							}
							if("B".equals(mdjbV)){
								if(mdjfDjVO.getHfjzsj()!=null && mdjfDjVO.getHfjzsj2()!=null) {
									if ((new Date()).compareTo(mdjfDjVO.getHfjzsj()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj2()) < 0) {
										mdjfDjVO.setTsnr("请于" + simpleDateFormat.format(mdjfDjVO.getHfjzsj2()) + "前进行回访");

									}
								}
								if(mdjfDjVO.getHfjzsj2()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj2()) > 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj2())+"前进行回访");
									}
								}
							}
						}
					}

				}
			}
		}
		return page.setRecords(mdjfDjVOS);
	}

	@Override
	public IPage<DjXjVO> getMdByPcs(IPage<DjXjVO> page, Map<String, Object> params) {
		List<DjXjVO> mdjfDjVOS = baseMapper.getMdByPcs(page, params);
		if(mdjfDjVOS.size()>0){
			for (int i = 0; i < mdjfDjVOS.size(); i++) {
				DjXjVO mdjfDjVO = mdjfDjVOS.get(i);
				String mdjbV = mdjfDjVO.getMdjbV();
				if(mdjfDjVO != null){
					int cscs = 0;
					if(mdjfDjVO.getDychf() == 2){
						cscs++;
					}
					if(mdjfDjVO.getDechf() == 2){
						cscs++;
					}
					if(mdjfDjVO.getDschf() == 2){
						cscs++;
					}
					mdjfDjVO.setCscs(cscs);
					if(StringUtils.isNotBlank(mdjfDjVO.getHfztNew())){
						mdjfDjVO.setHfztNewValve(DictBizCache.getValue("hfzt",mdjfDjVO.getHfztNew()));
					}
					if(StringUtils.isNotBlank(mdjfDjVO.getCszt())){
						mdjfDjVO.setCsztValue(DictBizCache.getValue("cszt",mdjfDjVO.getCszt()));
					}
					if(StringUtils.isNotBlank(mdjbV)){
						mdjfDjVO.setMdjbVVlaue(DictBizCache.getValue("mddj", mdjbV));
						if("0".equals(mdjfDjVO.getHfztNew()) || "1".equals(mdjfDjVO.getHfztNew())){
							if(mdjfDjVO.getHfjzsj() != null){
								mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj())+"前进行回访");
							}
							if("A".equals(mdjbV)){
								if(mdjfDjVO.getHfjzsj()!=null && mdjfDjVO.getHfjzsj2()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj2()) < 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj2())+"前进行回访");
									}
								}
								if(mdjfDjVO.getHfjzsj2()!=null && mdjfDjVO.getHfjzsj3()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj2()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj3()) < 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj3())+"前进行回访");
									}
								}
								if(mdjfDjVO.getHfjzsj3()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj3()) > 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj3())+"前进行回访");
									}
								}

							}
							if("B".equals(mdjbV)){
								if(mdjfDjVO.getHfjzsj()!=null && mdjfDjVO.getHfjzsj2()!=null) {
									if ((new Date()).compareTo(mdjfDjVO.getHfjzsj()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj2()) < 0) {
										mdjfDjVO.setTsnr("请于" + simpleDateFormat.format(mdjfDjVO.getHfjzsj2()) + "前进行回访");

									}
								}
								if(mdjfDjVO.getHfjzsj2()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj2()) > 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj2())+"前进行回访");
									}
								}
							}
						}
					}

				}
			}
		}
		return page.setRecords(mdjfDjVOS);
	}

	@Override
	public IPage<DjXjVO> getMdyjByPcs(IPage<DjXjVO> page, Map<String, Object> params) {
		List<DjXjVO> mdjfDjVOS = baseMapper.getMdyjByPcs(page, params);
		if(mdjfDjVOS.size()>0){
			for (int i = 0; i < mdjfDjVOS.size(); i++) {
				DjXjVO mdjfDjVO = mdjfDjVOS.get(i);
				String mdjbV = mdjfDjVO.getMdjbV();
				if(mdjfDjVO != null){
					int cscs = 0;
					if(mdjfDjVO.getDychf() == 2){
						cscs++;
					}
					if(mdjfDjVO.getDechf() == 2){
						cscs++;
					}
					if(mdjfDjVO.getDschf() == 2){
						cscs++;
					}
					mdjfDjVO.setCscs(cscs);
					if(StringUtils.isNotBlank(mdjfDjVO.getHfztNew())){
						mdjfDjVO.setHfztNewValve(DictBizCache.getValue("hfzt",mdjfDjVO.getHfztNew()));
					}
					if(StringUtils.isNotBlank(mdjfDjVO.getCszt())){
						mdjfDjVO.setCsztValue(DictBizCache.getValue("cszt",mdjfDjVO.getCszt()));
					}
					if(StringUtils.isNotBlank(mdjbV)){
						mdjfDjVO.setMdjbVVlaue(DictBizCache.getValue("mddj", mdjbV));
						if("0".equals(mdjfDjVO.getHfztNew()) || "1".equals(mdjfDjVO.getHfztNew())){
							if(mdjfDjVO.getHfjzsj() != null){
								mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj())+"前进行回访");
							}
							if("A".equals(mdjbV)){
								if(mdjfDjVO.getHfjzsj()!=null && mdjfDjVO.getHfjzsj2()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj2()) < 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj2())+"前进行回访");
									}
								}
								if(mdjfDjVO.getHfjzsj2()!=null && mdjfDjVO.getHfjzsj3()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj2()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj3()) < 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj3())+"前进行回访");
									}
								}
								if(mdjfDjVO.getHfjzsj3()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj3()) > 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj3())+"前进行回访");
									}
								}

							}
							if("B".equals(mdjbV)){
								if(mdjfDjVO.getHfjzsj()!=null && mdjfDjVO.getHfjzsj2()!=null) {
									if ((new Date()).compareTo(mdjfDjVO.getHfjzsj()) > 0 && (new Date()).compareTo(mdjfDjVO.getHfjzsj2()) < 0) {
										mdjfDjVO.setTsnr("请于" + simpleDateFormat.format(mdjfDjVO.getHfjzsj2()) + "前进行回访");

									}
								}
								if(mdjfDjVO.getHfjzsj2()!=null){
									if((new Date()).compareTo(mdjfDjVO.getHfjzsj2()) > 0){
										mdjfDjVO.setTsnr("请于"+simpleDateFormat.format(mdjfDjVO.getHfjzsj2())+"前进行回访");
									}
								}
							}
						}
					}

				}
			}
		}
		return page.setRecords(mdjfDjVOS);
	}
}
