package com.zcloud.service.bus.impl;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.dsno2.bus.NoticeRegulatoryMapper;
import com.zcloud.service.bus.NoticeRegulatoryService;
import com.zcloud.service.bus.NoticeRegulatoryUserService;
import com.zcloud.util.DateUtil;
import com.zcloud.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 说明：监管端站内信
 * 作者：luoxiaobao
 * 时间：2022-08-23
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class NoticeRegulatoryServiceImpl implements NoticeRegulatoryService {

	@Autowired
	private NoticeRegulatoryMapper noticeregulatoryMapper;
	@Autowired
	private NoticeRegulatoryUserService noticeRegulatoryUserService;

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

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

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

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

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

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

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		noticeregulatoryMapper.deleteAll(ArrayDATA_IDS);
	}
	/**列表
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> listByUserId(Page page)throws Exception{
		return noticeregulatoryMapper.listByUserIddatalistPage(page);
	}

	/**发站内信
	 * @param pd
	 * @throws Exception
	 */
	public void sendMessage(PageData pd)throws Exception{
		PageData pd1 = new PageData();
		pd1.put("NOTICEREGULATORY_ID", UuidUtil.get32UUID());
		pd1.put("USERNAME",pd.getString("SENDER_NAME"));
		pd1.put("CREATOR", pd.getString("SENDER_ID"));	//添加人
		pd1.put("CREATTIME", DateUtil.date2Str(new Date()));	//添加时间
		pd1.put("SYNOPSIS",pd.getString("SYNOPSIS"));
		pd1.put("CONTENT","<p>"+pd.getString("CONTENT")+"</p>");
		pd1.put("ISALL","yes");
		pd1.put("ISREPLY",0);
		pd1.put("ISDELETE",0);
		pd1.put("ISTOP",0);
		pd1.put("STATUS",1);
//		pd1.put("CORP_INFO_ID",pd.getString("CORPINFO_ID"));
		noticeregulatoryMapper.save(pd1);
		pd1.put("NOTICEREGULATORYUSER_ID",UuidUtil.get32UUID());
		pd1.put("USER_ID",pd.getString("RECEIVER_ID"));
		pd1.put("TYPE",0);
		noticeRegulatoryUserService.save(pd1);
	}
}

