package com.zcloud.service.onlinexxks.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.dsno3.task.StudytaskSignMapper;
import com.zcloud.service.onlinexxks.StudytaskSignService;
import com.zcloud.util.Tools;
import com.zcloud.util.UuidUtil;

/**
 * 说明：任务-签字信息
 * 作者：luoxiaobao
 * 时间：2022-02-24
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class StudytaskSignServiceImpl implements StudytaskSignService {

	@Autowired
	private StudytaskSignMapper studytasksignMapper;

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

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

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

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

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

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

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		studytasksignMapper.deleteAll(ArrayDATA_IDS);
	}
	/**新增 任务新增的时候
	 * @param pd
	 * @throws Exception
	 */
	public void saveByStudyTask(PageData pd)throws Exception{
		if(!Tools.isEmpty(pd.getString("RECORDERUSERIDS"))){
			String[] userIds = pd.getString("RECORDERUSERIDS").split(",");
			for (int i = 0; i < userIds.length; i++) {
				PageData c = new PageData();
				c.put("STUDYTASKSIGN_ID", UuidUtil.get32UUID());
				c.put("USER_ID", userIds[i]);    // 人员id
				c.put("CREATOR", pd.getString("CREATOR"));    //添加人
				c.put("CREATTIME", pd.getString("CREATTIME"));    //添加时间
				c.put("OPERATOR", pd.getString("OPERATOR"));    //修改人
				c.put("OPERATTIME", pd.getString("OPERATTIME"));    //修改时间
				c.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));    //企业ID
				c.put("STUDYTASK_ID", pd.getString("STUDYTASK_ID"));    //任务id
				c.put("TYPE", "1");    //记录人员：1；安全生产机构负责：2
				this.save(c);
			}
		}
		if(!Tools.isEmpty(pd.getString("CHARGEUSERIDS"))){
			String[] userIds = pd.getString("CHARGEUSERIDS").split(",");
			for (int i = 0; i < userIds.length; i++) {
				PageData c = new PageData();
				c.put("STUDYTASKSIGN_ID", UuidUtil.get32UUID());
				c.put("USER_ID", userIds[i]);    // 人员id
				c.put("CREATOR", pd.getString("CREATOR"));    //添加人
				c.put("CREATTIME", pd.getString("CREATTIME"));    //添加时间
				c.put("OPERATOR", pd.getString("OPERATOR"));    //修改人
				c.put("OPERATTIME", pd.getString("OPERATTIME"));    //修改时间
				c.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));    //企业ID
				c.put("STUDYTASK_ID", pd.getString("STUDYTASK_ID"));    //任务id
				c.put("TYPE", "2");    //记录人员：1；安全生产机构负责：2
				this.save(c);
			}
		}
	}

	/**根据任务id获取签字信息
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> getListByStudytaskID(PageData pd)throws Exception{
		return studytasksignMapper.getListByStudytaskID(pd);
	}
}

