|
@ -2,24 +2,35 @@ package com.yihu.iot.service.device;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.yihu.elasticsearch.ElasticSearchHelper;
|
|
import com.yihu.elasticsearch.ElasticSearchHelper;
|
|
|
|
import com.yihu.iot.dao.device.IotDeviceDao;
|
|
|
|
import com.yihu.iot.dao.device.IotDeviceOverhaulDao;
|
|
import com.yihu.iot.dao.device.IotPatientDeviceDao;
|
|
import com.yihu.iot.dao.device.IotPatientDeviceDao;
|
|
import com.yihu.iot.datainput.util.ConstantUtils;
|
|
import com.yihu.iot.datainput.util.ConstantUtils;
|
|
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
|
|
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
|
|
|
|
import com.yihu.iot.service.dict.IotSystemDictService;
|
|
import com.yihu.jw.device.LocationDataDO;
|
|
import com.yihu.jw.device.LocationDataDO;
|
|
|
|
import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO;
|
|
import com.yihu.jw.entity.iot.device.IotPatientDeviceDO;
|
|
import com.yihu.jw.entity.iot.device.IotPatientDeviceDO;
|
|
|
|
import com.yihu.jw.entity.iot.dict.IotSystemDictDO;
|
|
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
|
|
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
|
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
|
import com.yihu.jw.rm.base.BaseRequestMapping;
|
|
|
|
import com.yihu.jw.rm.iot.IotRequestMapping;
|
|
import com.yihu.jw.util.common.LatitudeUtils;
|
|
import com.yihu.jw.util.common.LatitudeUtils;
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
import io.searchbox.client.JestResult;
|
|
import io.searchbox.client.JestResult;
|
|
import iot.device.LocationDataVO;
|
|
import iot.device.LocationDataVO;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@ -37,17 +48,48 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
|
|
private ElasticSearchHelper elasticSearchHelper;
|
|
private ElasticSearchHelper elasticSearchHelper;
|
|
@Autowired
|
|
@Autowired
|
|
private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
|
|
private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
|
|
|
|
@Autowired
|
|
|
|
private IotDeviceDao iotDeviceDao;
|
|
|
|
@Autowired
|
|
|
|
private JdbcTemplate jdbcTempalte;
|
|
|
|
@Autowired
|
|
|
|
private IotSystemDictService iotSystemDictService;
|
|
|
|
@Autowired
|
|
|
|
private IotDeviceOverhaulDao deviceOverhaulDao;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 新增
|
|
* 新增
|
|
* @param patientDevice
|
|
* @param patientDevice
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
|
|
@Transactional
|
|
public IotPatientDeviceDO create(IotPatientDeviceDO patientDevice) {
|
|
public IotPatientDeviceDO create(IotPatientDeviceDO patientDevice) {
|
|
|
|
|
|
patientDevice.setSaasId(getCode());
|
|
patientDevice.setSaasId(getCode());
|
|
patientDevice.setDel(1);
|
|
patientDevice.setDel(1);
|
|
return iotPatientDeviceDao.save(patientDevice);
|
|
|
|
|
|
IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.save(patientDevice);
|
|
|
|
//更新设备绑定状态,减库存
|
|
|
|
iotDeviceDao.updateIsGrantById(patientDevice.getDeviceId(), 1);
|
|
|
|
|
|
|
|
//生成一年检修记录
|
|
|
|
List<IotSystemDictDO> systemDictDOS = iotSystemDictService.getListByDictName("OVERHAUL_FREQUENCY");//获取设备检修时间
|
|
|
|
if(systemDictDOS.size() == 1){
|
|
|
|
List<IotDeviceOverhaulDO> deviceOverhaulDOS = new ArrayList<>();
|
|
|
|
int day = Integer.parseInt(systemDictDOS.get(0).getValue());//检修间隔天数
|
|
|
|
int count = 365/day;
|
|
|
|
for(int i = 0 ; i< count; i++){
|
|
|
|
IotDeviceOverhaulDO deviceOverhaulDO = new IotDeviceOverhaulDO();
|
|
|
|
deviceOverhaulDO.setSaasId(getCode());
|
|
|
|
deviceOverhaulDO.setPatientDeviceId(patientDeviceDO.getId());
|
|
|
|
deviceOverhaulDO.setStatus(0);
|
|
|
|
deviceOverhaulDO.setTime(DateUtil.dateToStr(DateUtil.getNextDay1(new Date(), day*(i+1)), "yyyy年MM月dd日"));
|
|
|
|
deviceOverhaulDO.setCreateTime(new Date());
|
|
|
|
deviceOverhaulDO.setUpdateTime(new Date());
|
|
|
|
deviceOverhaulDOS.add(deviceOverhaulDO);
|
|
|
|
}
|
|
|
|
deviceOverhaulDao.save(deviceOverhaulDOS);
|
|
|
|
}
|
|
|
|
return patientDeviceDO;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@ -274,4 +316,125 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
|
|
count = result.getTotal();
|
|
count = result.getTotal();
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 新增编辑维修记录
|
|
|
|
* @param deviceSn
|
|
|
|
* @param status
|
|
|
|
* @param damageDescription
|
|
|
|
* @param damageImages
|
|
|
|
* @param repairDescription
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<IotPatientDeviceVO> createRepairDevice(String deviceSn, Integer status, String damageDescription, String damageImages, String repairDescription) {
|
|
|
|
List<IotPatientDeviceDO> patientDeviceDOList = iotPatientDeviceDao.findByDeviceSn(deviceSn);
|
|
|
|
for(IotPatientDeviceDO patientDeviceDO : patientDeviceDOList){
|
|
|
|
patientDeviceDO.setStatus(status);
|
|
|
|
if(StringUtils.isNotBlank(damageDescription)) {
|
|
|
|
patientDeviceDO.setDamageDescription(damageDescription);
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(damageImages)) {
|
|
|
|
patientDeviceDO.setDamageImages(damageImages);
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(repairDescription)) {
|
|
|
|
patientDeviceDO.setRepairDescription(repairDescription);
|
|
|
|
}
|
|
|
|
patientDeviceDO.setUpdateTime(new Date());
|
|
|
|
}
|
|
|
|
iotPatientDeviceDao.save(patientDeviceDOList);
|
|
|
|
List<IotPatientDeviceVO> patientDeviceVOS = new ArrayList<>();
|
|
|
|
return convertToModels(patientDeviceDOList, patientDeviceVOS, IotPatientDeviceVO.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据设备码获取相关厂商信息
|
|
|
|
* @param deviceSn
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<IotPatientDeviceVO> getDeviceInfoByDeviceSn(String deviceSn) {
|
|
|
|
String sql = "SELECT p.id,p.device_sn,p.device_id,p.device_name, GROUP_CONCAT(p.patient_name) as patientName,p.idcard,p.mobile,d.manufacturer_id, c.`name` manufacturerName,c.contacts_name, c.contacts_mobile " +
|
|
|
|
"FROM `iot_patient_device` p, iot_device d LEFT JOIN iot_company c on d.manufacturer_id = c.id and c.status = 1 " +
|
|
|
|
"where p.device_sn = '" + deviceSn + "' and p.del = 1 and p.device_id= d.id GROUP BY p.device_sn ";
|
|
|
|
List<IotPatientDeviceVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class));
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取设备维修记录
|
|
|
|
* @param deviceSn
|
|
|
|
* @param status
|
|
|
|
* @param manufacturerId
|
|
|
|
* @param page
|
|
|
|
* @param pageSize
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public MixEnvelop<IotPatientDeviceVO, IotPatientDeviceVO> getRepairDeviceList(String deviceSn, Integer status, String manufacturerId, Integer page, Integer pageSize) {
|
|
|
|
String sql ="SELECT p.device_sn,p.device_id,p.device_name,GROUP_CONCAT(p.patient_name) as patientName,p.idcard,p.mobile,p.`status`,p.damage_description,p.damage_images,p.repair_description,d.manufacturer_id, c.`name` manufacturerName,c.contacts_name, c.contacts_mobile " +
|
|
|
|
"FROM `iot_patient_device` p, iot_device d LEFT JOIN iot_company c on d.manufacturer_id = c.id and c.status = 1 " +
|
|
|
|
"where p.del = 1 and p.`status` is not null and p.`status` > 0 and p.device_id= d.id ";
|
|
|
|
if(StringUtils.isNotBlank(deviceSn)){
|
|
|
|
sql += " and p.device_sn like '%" + deviceSn + "%' ";
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(manufacturerId)){
|
|
|
|
sql +=" and d.manufacturer_id = '" +manufacturerId + "' ";
|
|
|
|
}
|
|
|
|
if(status != null){
|
|
|
|
sql += " and p.status = " +status;
|
|
|
|
}else if(StringUtils.isNotBlank(manufacturerId)){
|
|
|
|
sql +=" and p.status in (2,3,4) ";//厂商只展示三种维修状态
|
|
|
|
}
|
|
|
|
|
|
|
|
sql +=" GROUP BY p.device_sn ORDER BY p.update_time desc ";
|
|
|
|
if (page != null && pageSize != null) {
|
|
|
|
String sqlCount = "SELECT count(DISTINCT p.device_sn) " + sql.substring(sql.indexOf("FROM"), sql.length());
|
|
|
|
Long count = jdbcTemplate.queryForObject(sqlCount, Long.class);
|
|
|
|
sql += "limit " +(page-1)* pageSize + "," +pageSize;
|
|
|
|
List<IotPatientDeviceVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class));
|
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Device.message_success_find, list,page, pageSize,count);
|
|
|
|
}
|
|
|
|
List<IotPatientDeviceVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class));
|
|
|
|
return MixEnvelop.getSuccessList(IotRequestMapping.Device.message_success_find, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteRepairDevice(String deviceSn) {
|
|
|
|
List<IotPatientDeviceDO> patientDeviceDOList = iotPatientDeviceDao.findByDeviceSn(deviceSn);
|
|
|
|
for(IotPatientDeviceDO patientDeviceDO : patientDeviceDOList){
|
|
|
|
patientDeviceDO.setStatus(0);
|
|
|
|
patientDeviceDO.setUpdateTime(new Date());
|
|
|
|
}
|
|
|
|
iotPatientDeviceDao.save(patientDeviceDOList);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
public void delPatientDevice(String id, Integer del) {
|
|
|
|
IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.findOne(id);
|
|
|
|
patientDeviceDO.setDel(del);
|
|
|
|
iotPatientDeviceDao.save(patientDeviceDO);
|
|
|
|
//更新设备绑定状态,加库存
|
|
|
|
iotDeviceDao.updateIsGrantById(patientDeviceDO.getDeviceId(), 0);
|
|
|
|
if(del == -1){
|
|
|
|
//核销设备
|
|
|
|
iotDeviceDao.updateDelById(patientDeviceDO.getDeviceId(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public MixEnvelop<IotPatientDeviceVO,IotPatientDeviceVO> getOverhaulDeviceList(String deviceSn, String patientName, Integer page, Integer pageSize) {
|
|
|
|
String sql = "SELECT DISTINCT d.* FROM `iot_patient_device` d , iot_device_overhaul o where d.del= 1 and d.id = o.patient_device_id ";
|
|
|
|
if(StringUtils.isNotBlank(deviceSn)){
|
|
|
|
sql += "and d.device_sn like '%" + deviceSn + "'% ";
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(patientName)){
|
|
|
|
sql += "and d.patientName like '%" + patientName + "'% ";
|
|
|
|
}
|
|
|
|
//判断是否需要分页
|
|
|
|
if (page != null && pageSize != null) {
|
|
|
|
Long count = Long.valueOf(jdbcTempalte.queryForList(sql).size());
|
|
|
|
sql += "limit " + (page - 1) * pageSize + "," + pageSize;
|
|
|
|
List<IotPatientDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class));
|
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find, deviceVOList, page, pageSize, count);
|
|
|
|
} else {
|
|
|
|
List<IotPatientDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class));
|
|
|
|
return MixEnvelop.getSuccessList(IotRequestMapping.Common.message_success_find, deviceVOList);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|