package com.bzd.system.service.gxhpz;

import com.bzd.common.config.dao.DaoBase;
import com.bzd.common.config.dao.DaoSupport;
import com.bzd.common.config.dao.PageData;
import com.bzd.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

import static com.bzd.common.utils.ShiroUtils.getSysUser;

@Service
public class HospitalListService {
    @Autowired
    private DaoBase dao;
    @Resource(name = "daoSupport")
    private DaoSupport daoSupport;

    /**
     * 查询列表
     * @param pd
     * @return
     * @throws Exception
     */
    public List<PageData> findForList(final PageData pd) throws Exception {
        return (List<PageData>) daoSupport.findForList("hospitalMapper.selectHospital", pd);
    }

    /**
     * 添加
     * @param pd
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public int save(final PageData pd) throws Exception {
        pd.put("createTime", DateUtils.getTime());
        pd.put("createBy", getSysUser().getUserName());
        return  daoSupport.save("hospitalMapper.insertHospital", pd);
    }

    /**
     * 删除
     * @param ids
     * @return
     * @throws Exception
     */
    public Integer del(List<String> ids) throws Exception {
        return daoSupport.delete("hospitalMapper.deleteHospital", ids);
    }

    /**
     * 修改配置
     * @param pd
     * @return
     * @throws Exception
     */
    public Integer update(PageData pd) throws Exception {
        pd.put("updateTime", DateUtils.getTime());
        pd.put("updateBy", getSysUser().getUserName());
        return daoSupport.update("hospitalMapper.updateHospital", pd);
    }

}
