package com.emr.service.emrUserReader;

import com.emr.dao.emrUserReader.Emr_User_ReaderMapper;
import com.emr.entity.Power_User;
import com.emr.entity.emrUserReader.Emr_User_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 EmrUserReaderServiceImpl implements EmrUserRearderService {
    @Autowired
    private Emr_User_ReaderMapper userReaderMapper;
    @Autowired
    private CommomService commomService;
    @Override
    public int insert(Emr_User_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.setUpdater(creater);
        record.setUpdateTime(fmt.format(new Date()));
        return userReaderMapper.insert(record);
    }

    @Override
    public void deleteReaderByUserId(Integer userId) {
        userReaderMapper.deleteReaderByUserId(userId);
    }

    @Override
    public void SimpleInsert(List<Emr_User_Reader> list) {
        commomService.simpleInsert("emr_user_reader",userReaderMapper,list);
    }
}
