package com.zcloud.service.hiddenDangerCheckStandard.impl;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.bus.HiddenExamineMapper;
import com.zcloud.mapper.datasource.hiddenDangerCheckStandard.CustomHiddenExamineMapper;
import com.zcloud.service.bus.HiddenExamineService;
import com.zcloud.service.hiddenDangerCheckStandard.CustomHiddenExamineService;
import com.zcloud.util.DateUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.UuidUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 说明：隐患审核
 * 作者：luoxiaobao
 * 时间：2022-04-14
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class CustomHiddenExamineServiceImpl implements CustomHiddenExamineService {

	@Resource
	private CustomHiddenExamineMapper customHiddenExamineMapper;
	/**新增
	 * @param pd
	 * @throws Exception
	 */
	public PageData save(PageData pd)throws Exception{
		pd.put("HIDDENEXAMINE_ID", UuidUtil.get32UUID());
		pd.put("CREATOR", Jurisdiction.getUSER_ID());
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));
		pd.put("OPERATOR",Jurisdiction.getUSER_ID());
		pd.put("OPERATTIME",DateUtil.date2Str(new Date()));
		customHiddenExamineMapper.save(pd);
		return  pd;
	}

	/**手机端打回保存
	 * @param pd
	 * @throws Exception
	 */
	public void saverepulse(PageData pd)throws Exception{
		customHiddenExamineMapper.save(pd);
	}

	/**删除
	 * @param pd
	 * @throws Exception
	 */
	public void delete(PageData pd)throws Exception{
		customHiddenExamineMapper.delete(pd);
	}

	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
//		pd.put("OPERATOR",Jurisdiction.getUSER_ID());
//		pd.put("OPERATTIME",DateUtil.date2Str(new Date()));
		customHiddenExamineMapper.edit(pd);
	}

	/**修改确认打回的信息
	 * @param pd
	 * @throws Exception
	 */
	public void editrepulse(PageData pd)throws Exception{
		customHiddenExamineMapper.editrepulse(pd);
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> list(Page page)throws Exception{
		return customHiddenExamineMapper.datalistPage(page);
	}

	/**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAll(PageData pd)throws Exception{
		return customHiddenExamineMapper.listAll(pd);
	}

	/**查询隐患确认打回的数据
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> findByHiddenId(PageData pd)throws Exception{
		return customHiddenExamineMapper.findByHiddenId(pd);
	}

	/**通过id获取数据
	 * @param pd
	 * @throws Exception
	 */
	public PageData findById(PageData pd)throws Exception{
		return customHiddenExamineMapper.findById(pd);
	}

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		customHiddenExamineMapper.deleteAll(ArrayDATA_IDS);
	}
	public List<PageData> listAllByHiddenId(String hiddenId)throws Exception{
		PageData pd = new PageData();
		pd.put("HIDDEN_ID",hiddenId);
		return customHiddenExamineMapper.listAll(pd);
	}
	public void updateBySpecial(PageData pd)throws Exception{
		customHiddenExamineMapper.updateBySpecial(pd);
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> listAndHidden(Page page)throws Exception{
		return  customHiddenExamineMapper.listAndHiddendatalistPage(page);
	}
	/**通过id获取数据
	 * @param pd
	 * @throws Exception
	 */
	public PageData findByIdAndHidden(PageData pd)throws Exception{
		return  customHiddenExamineMapper.findByIdAndHidden(pd);
	}
	public PageData saveApp(PageData pd)throws Exception{
		pd.put("HIDDENEXAMINE_ID", UuidUtil.get32UUID());
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));
		pd.put("OPERATTIME",DateUtil.date2Str(new Date()));
		customHiddenExamineMapper.save(pd);
		return  pd;
	}

	public PageData appSave(PageData pd)throws Exception{
		pd.put("HIDDENEXAMINE_ID", UuidUtil.get32UUID());
		pd.put("CREATOR", pd.getString("CREATOR"));
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));
		pd.put("OPERATOR",pd.getString("OPERATOR"));
		pd.put("OPERATTIME",DateUtil.date2Str(new Date()));
		customHiddenExamineMapper.save(pd);
		return  pd;
	}

	public void deleteByHiddenId(PageData pd)throws Exception{
		customHiddenExamineMapper.deleteByHiddenId(pd);
	}
	/**
	 * pc的隐患确认信息初始化
	 *  需求：隐患确认之后，显示隐患发现人填入的隐患等级等信息
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	public PageData saveConfirm(PageData pd)throws Exception{

		PageData before = new PageData();// 添加隐患初始信息
		before.put("TYPE","0"); //.0.隐患开始数据;1.特殊审核;2.延期审核 3.验收打回。4.隐患确认记录,.5重大隐患修改，6确认时打回;
		before.put("STATE","2");//是否通过审核 ,1未通过。2通过 -1（初始）16隐患确认打回
		before.put("HIDDEN_ID",pd.get("HIDDEN_ID"));
		before.put("spare1",pd.getString("HIDDENLEVEL")); // 隐患级别
		before.put("spare2",pd.getString("RECTIFICATIONOR"));//整改负责人
		before.put("spare3",pd.getString("RECTIFICATIONDEADLINE")); //整改完成期限
		before.put("spare4",pd.getString("RECTIFICATIONDEPT")); //整改负责人部门

		before.put("HIDDENEXAMINE_ID", UuidUtil.get32UUID());
		before.put("CREATOR", Jurisdiction.getUSER_ID());
		before.put("CREATTIME", DateUtil.date2Str(new Date()));
		before.put("OPERATOR",Jurisdiction.getUSER_ID());
		before.put("OPERATTIME",DateUtil.date2Str(new Date()));

		customHiddenExamineMapper.save(before);
		return  pd;
	}
}

