package com.unis.base.server.domain;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.*;
import com.unis.base.server.dao.DjgjcDao;
import com.unis.base.server.dao.TzQylxDao;
import com.unis.base.server.dao.TzSlqyDao;
import com.unis.base.server.dao.TzYjqyDao;
import com.unis.base.server.entity.*;
import com.unis.common.utils.LsBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author zoujieli
 * @version 1.0
 * @date 2019/09/18 17点26分
 */
@Component
public class MoneyMonitorDomain {

	@Autowired
	private DjgjcDao jgjcDao;

	/**
	 * 价格监测-分页查询
	 * @author zoujieli
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public Map<String, Object> getMoneyMonitorList(Integer pageNum, Integer pageSize) {

		Map<String, Object> resultMap = new HashMap<>();
		List<MoneyMonitorVO> monitorVOList = new ArrayList<>();

		PageHelper.startPage(pageNum,pageSize);
		List<DjgjcDO> jgjcDOList = jgjcDao.getMoneyMonitorList();
		PageInfo<DjgjcDO> pageInfo = new PageInfo<>(jgjcDOList);

		if (jgjcDOList != null && !jgjcDOList.isEmpty()){
			for (DjgjcDO jgjcDO: jgjcDOList){
				MoneyMonitorVO moneyMonitorVO = new MoneyMonitorVO();
				LsBeanUtils.copyAllProperties(jgjcDO,moneyMonitorVO);
				monitorVOList.add(moneyMonitorVO);
			}
		}

		resultMap.put("total",pageInfo.getTotal());
		resultMap.put("monitorVOList",monitorVOList);
		return resultMap;
	}

	/**
	 * 价格监测-查询详情
	 * @author zoujieli
	 * @param jcdid
	 * @return
	 */
	public MoneyMonitorVO getMoneyMonitorDetail(String jcdid) {
		DjgjcDO djgjcDO = jgjcDao.getMoneyMonitorDetail(jcdid);
		MoneyMonitorVO moneyMonitorVO = new MoneyMonitorVO();
		if (djgjcDO != null){
			LsBeanUtils.copyAllProperties(djgjcDO,moneyMonitorVO);
		}
		return moneyMonitorVO;
	}

	/**
	 * 价格监测-编辑修改
	 * @author zoujieli
	 * @param moneyMonitorVO
	 */
	public void updateMoneyMonitor(MoneyMonitorVO moneyMonitorVO) {
		DjgjcDO djgjcDO = new DjgjcDO();
		LsBeanUtils.copyAllProperties(moneyMonitorVO,djgjcDO);
		jgjcDao.updateMoneyMonitor(moneyMonitorVO);
	}

	/**
	 * 价格监测-删除
	 * @author zoujieli
	 * @param jcdid
	 */
	public void deleteMoneyMonitor(String jcdid) {
		jgjcDao.deleteMoneyMonitor(jcdid);
	}

	/**
	 * 价格监测-新增
	 * @author zoujieli
	 * @param moneyMonitorVO
	 */
	public void insertMoneyMonitor(MoneyMonitorVO moneyMonitorVO) {
		DjgjcDO djgjcDO = new DjgjcDO();
		LsBeanUtils.copyAllProperties(moneyMonitorVO,djgjcDO);
		jgjcDao.insertMoneyMonitor(djgjcDO);
	}
}
