package com.yihu.jw.dict.service;

import com.yihu.jw.entity.hospital.manage.BaseDeptHomepageBannerDO;
import com.yihu.jw.entity.hospital.manage.BaseDeptHomepageBannerDO;
import com.yihu.jw.hospital.dict.BaseDeptHomepageBannerDao;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

import static com.yihu.jw.util.common.BeanUtils.getNullPropertyNames;

@Service
public class DeptHomepageBannerService extends BaseJpaService<BaseDeptHomepageBannerDO, BaseDeptHomepageBannerDao> {

    @Autowired
    private BaseDeptHomepageBannerDao deptHomepageBannerDao;

    public BaseDeptHomepageBannerDO updateDeptHomepageBanner(BaseDeptHomepageBannerDO deptHomepageBannerDO) {
        //判断新增或编辑
        if (deptHomepageBannerDO.getId() == null) {
            deptHomepageBannerDO.setCreateTime(new Date());
            deptHomepageBannerDO.setDel(1);
            return deptHomepageBannerDao.save(deptHomepageBannerDO);
        } else {
            BaseDeptHomepageBannerDO oldDeptHomepageBanner = deptHomepageBannerDao.findOne(deptHomepageBannerDO.getId());
            BeanUtils.copyProperties(deptHomepageBannerDO, oldDeptHomepageBanner, getNullPropertyNames(deptHomepageBannerDO));
            return deptHomepageBannerDao.save(oldDeptHomepageBanner);
        }
    }

    public void delDeptHomepageBanner(Integer id) {
        deptHomepageBannerDao.delete(id);
    }
}
