package com.emr.service;

import com.emr.dao.Zd_AssortMapper;
import com.emr.entity.Power_User;
import com.emr.entity.Zd_Assort;
import com.emr.entity.recordType.Emr_Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

/**
 * @ProjectName:
 * @Description:
 * @Param 传输参数
 * @Return
 * @Author: 曾文和
 * @CreateDate: 2019/7/8 14:53
 * @UpdateUser: 曾文和
 * @UpdateDate: 2019/7/8 14:53
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Service
@Transactional
public class Zd_AssortServiceImpl{
    @Autowired
    private Zd_AssortMapper assortMapper;

    public int insert(Zd_Assort record) {
        //添加assortId
        UUID uuid = UUID.randomUUID();
        String assortId = uuid.toString().toUpperCase().replace("-", "");
        record.setAssortId(assortId);
        return assortMapper.insert(record);
    }

    public void updateByPrimaryKeySelective(Zd_Assort record) {
        assortMapper.updateByPrimaryKeySelective(record);
    }

    public void deleteAssortByAssortId(String assortId) {
        assortMapper.deleteAssortByAssortId(assortId);
    }

    /**
     * 按权限查询分段集合
     * */
    public List<Zd_Assort> selectAllByPower(Power_User user){
        if(user.getRoleId() == 0 || user.getRoleId() == -100){
            return assortMapper.selectAll(new Zd_Assort());
        }else{
            return assortMapper.selectAllAndUserReaderByUserIdAndRoleId(user.getUserId(),user.getRoleId());
        }
    }

    public  List<Emr_Type>selectEmrType(){
        return  assortMapper.selectEmrType();
    }
}
