package com.emr.service.emrRoleReader;

import com.emr.dao.emrRoleReader.Emr_Role_ReaderMapper;
import com.emr.entity.Power_User;
import com.emr.entity.emrRoleReader.Emr_Role_Reader;
import com.emr.service.CommomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ProjectName:
 * @Description:
 * @Param 传输参数
 * @Return
 * @Author: 曾文和
 * @CreateDate: 2019/7/9 16:53
 * @UpdateUser: 曾文和
 * @UpdateDate: 2019/7/9 16:53
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Service
@Transactional
public class EmrRoleReaderServiceImpl implements EmrRoleRearderService{
    @Autowired
    private Emr_Role_ReaderMapper roleReaderMapper;
    @Autowired
    private CommomService commomService;
    @Override
    public int insert(Emr_Role_Reader record, HttpServletRequest request) {
        Power_User user = (Power_User)request.getSession().getAttribute("CURRENT_USER");
        String creater = user.getUserName();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        record.setCreater(creater);
        record.setCreateTime(fmt.format(new Date()));
        record.setUpater(creater);
        record.setUpdateTime(fmt.format(new Date()));
        return roleReaderMapper.insert(record);
    }

    @Override
    public void deleteReaderByRoleId(Integer roleId) {
        roleReaderMapper.deleteReaderByRoleId(roleId);
    }

    @Override
    public List<Emr_Role_Reader> selectAllByRoleId(Integer roleId) {
        return roleReaderMapper.selectAllByRoleId(roleId);
    }

    @Override
    public void SimpleInsert(List<Emr_Role_Reader> list) {
        commomService.simpleInsert("emr_role_reader",roleReaderMapper,list);
    }
}
