package com.zcloud.service.check.impl;

import com.alibaba.fastjson.JSONObject;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.check.ListCheckItemMapper;
import com.zcloud.mapper.datasource.check.ListManagerMapper;
import com.zcloud.service.check.ListManagerService;
import com.zcloud.util.HttpClientUtil;
import com.zcloud.util.Warden;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 说明：清单管理
 * 作者：luoxiaobao
 * 时间：2020-12-30
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class ListManagerServiceImpl implements ListManagerService {

	@Autowired
	private ListManagerMapper listmanagerMapper;

    @Autowired
    private ListCheckItemMapper listCheckItemMapper;

	/**新增
	 * @param pd
	 * @throws Exception
	 */
	public void save(PageData pd)throws Exception{
		listmanagerMapper.save(pd);
	}

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

	/**禁用
	 * @param pd
	 * @throws Exception
	 */
	public void remove(PageData pd)throws Exception{
		listmanagerMapper.remove(pd);
	}
	/**彻底删除
	 * @param pd
	 * @throws Exception
	 */
	public void deleted(PageData pd)throws Exception{
		listmanagerMapper.deleted(pd);
	}

	/**启用
	 * @param pd
	 * @throws Exception
	 */
	public void enable(PageData pd)throws Exception{
		listmanagerMapper.enable(pd);
	}

	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
		listmanagerMapper.edit(pd);
	}

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

	public List<PageData> stoplist(Page page)throws Exception{
		return listmanagerMapper.stopdatalistPage(page);
	}

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

	/** APP用——风险管控排查与隐患排查列表
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> queryHiddenDangerList(PageData pd)throws Exception{
		return listmanagerMapper.listAllForApp(pd);
	}

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

	/**清单检查分页
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> checklistPage(Page page)throws Exception{
		return listmanagerMapper.checklistPage(page);
	}

	/**清单检查分页
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> riskStandardCheckList(Page page)throws Exception{
		return listmanagerMapper.riskStandardChecklistPage(page);
	}

	/**查询部门清单
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listListByDep(PageData pd)throws Exception{
		return listmanagerMapper.listListByDep(pd);
	}

	/**查询人员清单
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listListByUser(PageData pd)throws Exception{
		return listmanagerMapper.listListByUser(pd);
	}

	public List<PageData> getListByCorplistPage(Page page)throws Exception{
		return listmanagerMapper.getListByCorplistPage(page);
	}

	/**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listRecordAll(Page page)throws Exception{
		return listmanagerMapper.listRecordAll(page);
	}

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

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		listmanagerMapper.deleteAll(ArrayDATA_IDS);
	}

	/**清单全部风险
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAllRisk(PageData pd)throws Exception{
		return listmanagerMapper.listAllRisk(pd);
	}

	/**部门清单列表
	 * 	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> recordList(Page page)throws Exception{
		return listmanagerMapper.recordlistPage(page);
	}

	/**部门清单列表
	 * 	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> riskStandardRecordList(Page page)throws Exception{
		return listmanagerMapper.riskStandardRecordlistPage(page);
	}

	/**待检查清单数量
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> listExaminedNum(PageData pd) throws Exception {
		return listmanagerMapper.listExaminedNum(pd);
	}
	/**待检查清单数量
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> listExaminedNumJjr(PageData pd) throws Exception {
		return listmanagerMapper.listExaminedNumJjr(pd);
	}
	/**人员负责清单数
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> countListByUser(PageData pd) throws Exception {
		return listmanagerMapper.countListByUser(pd);
	}



	/**查询所有可发送短信的企业的清单
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> listAllByCorpMsm(PageData pd)throws Exception {
		return listmanagerMapper.listAllByCorpMsm(pd);
	}

	/**查询所有清单清单
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> getAllList(PageData pd)throws Exception{
		return listmanagerMapper.getAllList(pd);
	}
	/**首页获取折线图
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> goIndexCount(PageData pd)throws Exception{
		return listmanagerMapper.goIndexCount(pd);
	}

	/**
	 * 查询公司清单总数
	 * @param pd
	 * @return
	 */
	public int getListCount(PageData pd)throws Exception{
		return listmanagerMapper.getListCount(pd);
	}

	/**
	 * 查询公司检查过清单的总数
	 * @param pd
	 * @return
	 */
	public int getWorkedListCount(PageData pd)throws Exception{
		return listmanagerMapper.getWorkedListCount(pd);
	}

	/**
	 * 根据分类统计清单
	 * @param pd
	 * @return
	 */
	public List<PageData> countListByType(PageData pd)throws Exception{
		return listmanagerMapper.countListByType(pd);
	}

	/**上期超期未检查的清单
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> overTimeRecord(PageData pd)throws Exception{
		return listmanagerMapper.overTimeRecord(pd);
	}

	/**上期超期未检查的清单（每日使用）
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> overTimeRecordDay(PageData pd)throws Exception{
		return listmanagerMapper.overTimeRecordDay(pd);
	}

	/**节假日超期未检查的清单
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> overTimeRecordJjr(PageData pd)throws Exception{
		return listmanagerMapper.overTimeRecordJjr(pd);
	}

	/**查询今日待处理清单数
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> getListToday(PageData pd)throws Exception{
		return listmanagerMapper.getListToday(pd);
	}

	public List<PageData> listAllForDiagnosis(PageData pd)throws Exception{
		return listmanagerMapper.listAllForDiagnosis(pd);
	}

	public List<PageData> thisMonthListmanager(PageData pd)throws Exception{
		return listmanagerMapper.thisMonthListmanager(pd);
	}

	public List<PageData> listAllPlan(PageData pd)throws Exception{
		return listmanagerMapper.listAllPlan(pd);
	}
	public List<PageData> listAllForPlan(PageData pd)throws Exception{
		return listmanagerMapper.listAllForPlan(pd);
	}

	public List<PageData> mergeListAllForPlan(PageData pd)throws Exception{
		return listmanagerMapper.mergeListAllForPlan(pd);
	}

	public List<PageData> getCountNumBi(PageData pd)throws Exception{
		return listmanagerMapper.getCountNumBi(pd);
	}

	@Override
	@Transactional
    public void saveBaoBaoType(PageData pd) throws Exception {
        List<PageData> itemList = Warden.getList(pd.getString("list"));
        for (PageData dto : itemList) {
            PageData condition = new PageData();
            condition.put("LISTCHECKITEM_ID",dto.get("LISTCHECKITEM_ID"));
            PageData entity = listCheckItemMapper.findById(condition);
            entity.put("BAO_BAO_NUM",dto.get("BAO_BAO_NUM"));
			listCheckItemMapper.edit(entity);
        }
    }

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

	/**部门清单列表全部
	 * 	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> recordListAll(Page page)throws Exception{
		return listmanagerMapper.recordAlllistPage(page);
	}

	@Override
	public List<PageData> getDailyInspectionList(PageData pd) throws Exception {
		return listmanagerMapper.getDailyInspectionList(pd);
	}
}


