|
@ -2,16 +2,13 @@ package com.yihu.iot.service.device;
|
|
|
|
|
|
import com.yihu.base.fastdfs.FastDFSHelper;
|
|
|
import com.yihu.base.mysql.query.BaseJpaService;
|
|
|
import com.yihu.iot.dao.device.IotDeviceDao;
|
|
|
import com.yihu.iot.dao.device.IotDeviceImportRecordDao;
|
|
|
import com.yihu.iot.dao.device.IotOrderPurchaseDao;
|
|
|
import com.yihu.jw.iot.device.IotDeviceDO;
|
|
|
import com.yihu.jw.iot.device.IotDeviceImportRecordDO;
|
|
|
import com.yihu.jw.iot.device.IotOrderPurchaseDO;
|
|
|
import com.yihu.iot.dao.device.*;
|
|
|
import com.yihu.jw.iot.device.*;
|
|
|
import com.yihu.jw.restmodel.common.Envelop;
|
|
|
import com.yihu.jw.restmodel.common.base.BaseEnvelop;
|
|
|
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
|
|
|
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
|
|
|
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
|
|
|
import com.yihu.jw.rm.iot.IotRequestMapping;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -45,6 +42,10 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
private IotOrderPurchaseDao iotOrderPurchaseDao;
|
|
|
@Autowired
|
|
|
private IotDeviceImportRecordService importRecordService;
|
|
|
@Autowired
|
|
|
private IotPatientDeviceDao iotPatientDeviceDao;
|
|
|
@Autowired
|
|
|
private IotDeviceQualityInspectionPlanDao iotDeviceQualityInspectionPlanDao;
|
|
|
|
|
|
/**
|
|
|
* 新增
|
|
@ -53,6 +54,25 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
*/
|
|
|
public IotDeviceDO create(IotDeviceDO iotDevice) {
|
|
|
|
|
|
if(iotDevice.getPurchaseId()!=null){
|
|
|
IotOrderPurchaseDO purchaseDO = iotOrderPurchaseDao.findById(iotDevice.getPurchaseId());
|
|
|
iotDevice.setName(purchaseDO.getDeviceName());
|
|
|
iotDevice.setOrderNo(purchaseDO.getOrderNo());
|
|
|
iotDevice.setProductId(purchaseDO.getProductId());
|
|
|
iotDevice.setSupplierId(purchaseDO.getSupplierId());
|
|
|
iotDevice.setSupplierName(purchaseDO.getSupplierName());
|
|
|
iotDevice.setManufacturerId(purchaseDO.getManufacturerId());
|
|
|
iotDevice.setManufacturerName(purchaseDO.getManufacturerName());
|
|
|
iotDevice.setStatus(IotDeviceDO.DeviceStatus.normal.getValue());
|
|
|
iotDevice.setDeviceSource(IotDeviceDO.DeviceSource.purchaese.getValue());
|
|
|
|
|
|
//获取质检信息
|
|
|
IotDeviceQualityInspectionPlanDO planDO = iotDeviceQualityInspectionPlanDao.findLastByPurchaseId(iotDevice.getPurchaseId());
|
|
|
if(planDO!=null){
|
|
|
iotDevice.setNextQualityTime(planDO.getPlanTime());//下次质检时间
|
|
|
}
|
|
|
}
|
|
|
|
|
|
iotDevice.setSaasId(getCode());
|
|
|
iotDevice.setDel(1);
|
|
|
return iotDeviceDao.save(iotDevice);
|
|
@ -101,6 +121,114 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
this.batchInsert(iotDeviceDO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询
|
|
|
* @param sn
|
|
|
* @param hospital
|
|
|
* @param orderId
|
|
|
* @param purcharseId
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public Envelop<IotDeviceVO> queryPage(String sn,String hospital,String orderId,String purcharseId,Integer page,Integer size) throws Exception{
|
|
|
String filters = "";
|
|
|
String semicolon = "";
|
|
|
if(StringUtils.isNotBlank(orderId)){
|
|
|
filters += semicolon +"orderId="+orderId;
|
|
|
semicolon = ";";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(purcharseId)){
|
|
|
filters += semicolon +"purchaseId="+purcharseId;
|
|
|
semicolon = ";";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(hospital)){
|
|
|
filters += semicolon +"hospital="+hospital;
|
|
|
semicolon = ";";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(sn)){
|
|
|
filters = "deviceSn?"+sn+" g1;name?"+sn+" g1";
|
|
|
semicolon = ";";
|
|
|
}
|
|
|
if(StringUtils.isBlank(filters)){
|
|
|
filters+= semicolon + "del=1";
|
|
|
}
|
|
|
String sorts = "-updateTime";
|
|
|
//得到list数据
|
|
|
List<IotDeviceDO> list = search(null, filters, sorts, page, size);
|
|
|
//获取总数
|
|
|
long count = getCount(filters);
|
|
|
|
|
|
//DO转VO
|
|
|
List<IotDeviceVO> iotDeviceVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceVO.class);
|
|
|
iotDeviceVOList.forEach(one->{
|
|
|
String deviceSn = one.getDeviceSn();
|
|
|
List<IotPatientDeviceDO> deviceDOList = iotPatientDeviceDao.findByDeviceSn(deviceSn);
|
|
|
if(deviceDOList!=null&&deviceDOList.size()>0){
|
|
|
one.setIsBinding(1);
|
|
|
}else {
|
|
|
one.setIsBinding(2);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return Envelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,iotDeviceVOList, page, size,count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否绑定查询
|
|
|
* @param sn
|
|
|
* @param hospital
|
|
|
* @param orderId
|
|
|
* @param purcharseId
|
|
|
* @param isBinding
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public Envelop<IotDeviceVO> queryPage(String sn,String hospital,String orderId,String purcharseId,Integer isBinding,Integer page,Integer size){
|
|
|
StringBuffer sql = new StringBuffer("SELECT DISTINCT c.* from iot_device c ,iot_patient_device t WHERE c.del=1 and t.del=1 ");
|
|
|
StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_device c ,iot_patient_device t WHERE c.del=1 and t.del=1 ");
|
|
|
List<Object> args = new ArrayList<>();
|
|
|
|
|
|
if(StringUtils.isNotBlank(orderId)){
|
|
|
sql.append(" and c.order_id = ? ");
|
|
|
sqlCount.append(" and c.order_id = '").append(orderId).append("'");
|
|
|
args.add(orderId);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(purcharseId)){
|
|
|
sql.append(" and c.purcharse_id = ? ");
|
|
|
sqlCount.append(" and c.purcharse_id = '").append(purcharseId).append("'");
|
|
|
args.add(purcharseId);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(hospital)){
|
|
|
sql.append(" and c.hospital = ? ");
|
|
|
sqlCount.append(" and c.hospital = '").append(hospital).append("'");
|
|
|
args.add(hospital);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(sn)){
|
|
|
sql.append(" and (c.device_sn like ? or c.name like ?)");
|
|
|
sqlCount.append(" and (c.device_sn like '").append(sn).append("' or c.name like '").append(sn).append("')");
|
|
|
args.add(sn);
|
|
|
args.add(sn);
|
|
|
}
|
|
|
sql.append(" and c.device_sn = t.device_sn ");
|
|
|
sqlCount.append(" and c.device_sn = t.device_sn '");
|
|
|
|
|
|
sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
|
|
|
|
|
|
List<IotDeviceDO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotDeviceDO.class));
|
|
|
List<Map<String,Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
|
|
|
long count = Long.valueOf(countList.get(0).get("count").toString());
|
|
|
|
|
|
//DO转VO
|
|
|
List<IotDeviceVO> iotDeviceVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceVO.class);
|
|
|
iotDeviceVOList.forEach(one->{
|
|
|
one.setIsBinding(isBinding);
|
|
|
});
|
|
|
|
|
|
return Envelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,iotDeviceVOList, page, size,count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据设备序列号判断设备是否存在
|
|
|
* @param deviceSn
|