package com.zcloud.service.hiddenDangerCheckStandard.impl;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.check.ListCheckItemMapper;
import com.zcloud.mapper.datasource.hiddenDangerCheckStandard.CustomMapper;
import com.zcloud.service.hiddenDangerCheckStandard.CustomItemService;
import com.zcloud.service.hiddenDangerCheckStandard.CustomService;
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 CustomServiceImpl implements CustomService {

	@Autowired
	private CustomMapper customMapper;
	@Autowired
	private CustomItemService customItemService;


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

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

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

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

	/**禁用
	 * @param pd
	 * @throws Exception
	 */
	public void remove(PageData pd)throws Exception{
		customMapper.remove(pd);
	}

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

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


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

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


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

	/**获取用户的检查清单
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> getMyCheckList(PageData pd)throws Exception{
		return customMapper.getMyCheckList(pd);
	}

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

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

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

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

	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
		customMapper.edit(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("CUSTOM_ITEM_ID",dto.get("CUSTOM_ITEM_ID"));
			PageData entity = customItemService.findById(condition);
			entity.put("BAO_BAO_NUM",dto.get("BAO_BAO_NUM"));
			customItemService.edit(entity);
		}
	}

	@Override
	public List<PageData> listAllForDiagnosis(PageData pd) {
		return customMapper.listAllForDiagnosis(pd);
	}

	@Override
	public List<PageData> thisMonthListmanager(PageData pd) {
		return customMapper.thisMonthListmanager(pd);
	}
}


