yeshijie 4 سال پیش
والد
کامیت
4b9188e519

+ 52 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/common/OrgUserService.java

@ -0,0 +1,52 @@
package com.yihu.iot.service.common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * Created by yeshijie on 2020/7/29.
 */
@Service
public class OrgUserService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 获取当前登录者的机构权限
     * @param userId
     * @return
     */
    public List<String> getUserOrgNameById(String userId){
        String sql = "SELECT h.name from `iot-base`.base_org_user o,iot_hospital h WHERE o.org_code = h.saas_id and o.user_id = '"+userId+"' ";
        return jdbcTemplate.queryForList(sql,String.class);
    }
    /**
     * 获取当前登录者的机构权限
     * @param userId
     * @return
     */
    public List<String> getUserOrgById(String userId){
        String sql = "SELECT org_code from `iot-base`.base_org_user WHERE user_id = '"+userId+"' ";
        return jdbcTemplate.queryForList(sql,String.class);
    }
    /**
     *
     * @param list
     * @return
     */
    public String getUserOrg(List<String> list){
        String res = "'";
        for (String s:list){
            res +=s+"'";
        }
        if(res.length()==1){
            res +="'";
        }
        return res;
    }
}

+ 11 - 2
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -9,6 +9,7 @@ import com.yihu.iot.dao.device.IotDeviceSimDao;
import com.yihu.iot.dao.device.IotPatientDeviceDao;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
import com.yihu.iot.service.common.OrgUserService;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.iot.util.excel.HibenateUtils;
@ -31,7 +32,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.provider.HibernateUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -69,6 +69,9 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
    private IotCompanyDao iotCompanyDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private OrgUserService orgUserService;
    /**
     * 新增
@ -524,7 +527,8 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
        }
    }
    public MixEnvelop<IotPatientDeviceVO,IotPatientDeviceVO> getPatientDeviceList(String deviceSn, String deviceName, String categoryCode, String patientName, String hospitalName, Integer isDel, Integer page, Integer pageSize) {
    public MixEnvelop<IotPatientDeviceVO,IotPatientDeviceVO> getPatientDeviceList(String deviceSn, String deviceName,
        String categoryCode, String patientName, String hospitalName, Integer isDel, Integer page, Integer pageSize) {
        String sql = "SELECT DISTINCT d.* FROM `iot_patient_device` d  where 1=1  ";
        if(isDel != null &&isDel == 1){
            sql += "and d.del != 1 ";
@ -544,6 +548,11 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
        if(StringUtils.isNotBlank(hospitalName)){
            sql += "and d.hospital_name like '%" + hospitalName + "%' ";
        }
        List<String> list = orgUserService.getUserOrgById(userAgent.getUID());
        if(!list.contains(userAgent.commonHospital)){
            sql += " and d.hospital in ("+orgUserService.getUserOrg(list)+") ";
        }
        sql += "order by d.update_time desc ";
        //判断是否需要分页
        if (page != null && pageSize != null) {

+ 3 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/useragent/UserAgent.java

@ -16,6 +16,9 @@ import javax.servlet.http.HttpServletRequest;
@Component
public class UserAgent {
    public String commonHospital = "iot-hospital";
    public String commonHospitalName = "物联网通用机构";
    /**
     * 获取当前登录人ID
     * @return