package com.emr.service.emrCodeType;
import com.emr.dao.emrCodeType.Emr_Code_TypeMapper;
import com.emr.entity.Power_User;
import com.emr.entity.emrCodeType.Emr_Code_Type;
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/6/5 11:13
 * @UpdateUser: 曾文和
 * @UpdateDate: 2019/6/5 11:13
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */

@Service
@Transactional
public class EmrCodeTypeServiceImpl implements EmrCodeTypeService {
    @Autowired
    private Emr_Code_TypeMapper codeTypeMapper;

    @Override
    public List<Emr_Code_Type> selectAllByPatientId(String patientId) {
        return codeTypeMapper.selectAllByPatientId(patientId);
    }

    @Override
    public void addCodeType(Emr_Code_Type emrCodeType, HttpServletRequest request) {
        Power_User user = (Power_User)request.getSession().getAttribute("CURRENT_USER");
        String userName = user.getUserId().toString();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        emrCodeType.setCreater(userName);
        emrCodeType.setCreateTime(fmt.format(new Date()));
        emrCodeType.setUpdater(userName);
        emrCodeType.setUpdateTime(fmt.format(new Date()));
        codeTypeMapper.insert(emrCodeType);
    }

    @Override
    public void updateCodeType(Emr_Code_Type emrCodeType,HttpServletRequest request) {
        Power_User user = (Power_User)request.getSession().getAttribute("CURRENT_USER");
        String userName = user.getUserId().toString();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        emrCodeType.setUpdater(userName);
        emrCodeType.setUpdateTime(fmt.format(new Date()));
        codeTypeMapper.updateByPrimaryKeySelective(emrCodeType);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return codeTypeMapper.deleteByPrimaryKey(id);
    }
}


