package com.unis.base.server.domain;

import com.unis.base.common.vo.PriceMonitorQueryVo;
import com.unis.base.common.vo.PriceMonitorVO;
import com.unis.base.server.dao.TyJgjcxxbDao;
import com.unis.base.server.entity.TyJgjcxxbDO;
import com.unis.common.utils.DateUtil;
import com.unis.common.utils.LsBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
/**
 * @author zhaoyadong
 * @version 1.0
 * @Title TyJgjcxxbDomain
 * @ProjectName 持久化
 * @Description
 * @date 2019/8/24
 */
@Component
public class PriceMonitorDomain extends BaseDomain {
    @Autowired
    private TyJgjcxxbDao tyJgjcxxbDao;

    /**
     * 查询所有信息
     * @param priceMonitorQueryVo
     * @return
     */
    public List<PriceMonitorVO> getPriceMonitorList(PriceMonitorQueryVo priceMonitorQueryVo) {
        return tyJgjcxxbDao.getPriceMonitorList(priceMonitorQueryVo);
    }

    /**
     *根据id查询相对应的信息
     * @param jgjcxxid
     * @return
     */
    public PriceMonitorVO getPriceMonitorById(String jgjcxxid) {
        TyJgjcxxbDO tyJgjcxxbDO = tyJgjcxxbDao.getPriceMonitorInfo( jgjcxxid);
        if(tyJgjcxxbDO == null) {
            return null;
        }
        PriceMonitorVO priceMonitorVO = new PriceMonitorVO();
        LsBeanUtils.copyAllProperties(tyJgjcxxbDO,priceMonitorVO);
        return priceMonitorVO;
    }

    /**
     * 添加价格监测信息
     * @param tyJgjcxxbVO
     * @return
     */
    public Integer insert(PriceMonitorVO tyJgjcxxbVO) {
        //进行传递参数copy
        TyJgjcxxbDO tyJgjcxxbDO = new TyJgjcxxbDO();
        tyJgjcxxbDO.setStatus(1);
        String maxCodeById = tyJgjcxxbDao.getMaxCodeById(tyJgjcxxbVO.getLsxzbm());
        String  jgxxid = getMaxCodeById(maxCodeById,tyJgjcxxbVO.getLsxzbm(),3);
        String currentStringDate = DateUtil.getCurrentStringDate();
        String id = "JG"+currentStringDate+jgxxid;
        tyJgjcxxbVO.setJgxxid(id);
        LsBeanUtils.copyAllProperties(tyJgjcxxbVO,tyJgjcxxbDO);
        int insert = tyJgjcxxbDao.insert(tyJgjcxxbDO);
        return insert;
    }


    /**
     * 更新价格监测信息
     * @param tyJgjcxxbVO
     * @return
     */
    public int update(PriceMonitorVO tyJgjcxxbVO){
        //进行传递参数copy
        TyJgjcxxbDO tyJgjcxxbDO = new TyJgjcxxbDO();
        LsBeanUtils.copyAllProperties(tyJgjcxxbVO,tyJgjcxxbDO);
        return tyJgjcxxbDao.updateByPrimaryKey(tyJgjcxxbDO);
    }


    /**
     * 根据年份查询该年分的月报
     * @param priceMonitorQueryVo
     * @return PriceMonitorQueryVo
     */

    public List<PriceMonitorQueryVo> getLevelMonthlyReport(PriceMonitorQueryVo priceMonitorQueryVo){
        List<PriceMonitorQueryVo> levelMonthlyReport = tyJgjcxxbDao.getLevelMonthlyReport(priceMonitorQueryVo);
        System.out.println(levelMonthlyReport+"??????????????????????????1");
        return levelMonthlyReport;
    }
}
