|
@ -45,7 +45,7 @@ import java.util.Map;
|
|
|
* @author yeshijie on 2017/12/8.
|
|
|
*/
|
|
|
@Service
|
|
|
public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
public class IotDeviceService extends BaseJpaService<IotDeviceDO, IotDeviceDao> {
|
|
|
|
|
|
@Autowired
|
|
|
private IotDeviceDao iotDeviceDao;
|
|
@ -82,13 +82,14 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 新增
|
|
|
*
|
|
|
* @param iotDevice
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
public IotDeviceDO create(IotDeviceDO iotDevice) {
|
|
|
|
|
|
if(iotDevice.getPurchaseId()!=null){
|
|
|
if (iotDevice.getPurchaseId() != null) {
|
|
|
IotOrderPurchaseDO purchaseDO = iotOrderPurchaseDao.findById(iotDevice.getPurchaseId());
|
|
|
iotDevice.setName(purchaseDO.getDeviceName());
|
|
|
iotDevice.setOrderNo(purchaseDO.getOrderNo());
|
|
@ -103,14 +104,14 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
//获取质检信息
|
|
|
IotDeviceQualityInspectionPlanDO planDO = iotDeviceQualityInspectionPlanDao.findLastByPurchaseId(iotDevice.getPurchaseId());
|
|
|
if(planDO!=null){
|
|
|
if (planDO != null) {
|
|
|
iotDevice.setNextQualityTime(planDO.getPlanTime());//下次质检时间
|
|
|
}
|
|
|
|
|
|
//计算是否已经完成订单
|
|
|
Integer num = iotDeviceDao.countByPurchaseId(iotDevice.getPurchaseId());//订单已经采购的数量
|
|
|
Integer purchaseNum = iotOrderPurchaseDao.sumByOrderId(purchaseDO.getOrderId());//订单需采购的数量
|
|
|
if((num+1)>=purchaseNum){
|
|
|
if ((num + 1) >= purchaseNum) {
|
|
|
//采购订单已经完成
|
|
|
IotDeviceOrderDO iotDeviceOrderDO = iotDeviceOrderDao.findById(purchaseDO.getOrderId());
|
|
|
iotDeviceOrderDO.setOrderStatus(IotDeviceOrderDO.DeviceOrderStatus.completed.getValue());
|
|
@ -126,6 +127,7 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 按id查找
|
|
|
*
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
@ -135,16 +137,17 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 删除设备
|
|
|
*
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
public int delDevice(String id){
|
|
|
public int delDevice(String id) {
|
|
|
int re = 1;
|
|
|
IotDeviceDO deviceDO = iotDeviceDao.findById(id);
|
|
|
List<IotPatientDeviceDO> patientDeviceDOList = iotPatientDeviceDao.findByDeviceId(id);
|
|
|
if(patientDeviceDOList!=null&&patientDeviceDOList.size()>0){
|
|
|
if (patientDeviceDOList != null && patientDeviceDOList.size() > 0) {
|
|
|
re = -1;
|
|
|
}else {
|
|
|
} else {
|
|
|
deviceDO.setDel(0);
|
|
|
iotDeviceDao.save(deviceDO);
|
|
|
}
|
|
@ -153,10 +156,11 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 修改设备
|
|
|
*
|
|
|
* @param deviceVO
|
|
|
* @return
|
|
|
*/
|
|
|
public Envelop updDevice(IotDeviceVO deviceVO){
|
|
|
public Envelop updDevice(IotDeviceVO deviceVO) {
|
|
|
IotDeviceDO deviceDO = iotDeviceDao.findById(deviceVO.getId());
|
|
|
deviceDO.setSimNo(deviceVO.getSimNo());
|
|
|
deviceDO.setDeviceSn(deviceVO.getDeviceSn());
|
|
@ -168,6 +172,7 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 按sim卡号查找
|
|
|
*
|
|
|
* @param simNo
|
|
|
* @return
|
|
|
*/
|
|
@ -177,11 +182,12 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 修改sim卡号
|
|
|
*
|
|
|
* @param sim
|
|
|
* @param id
|
|
|
*/
|
|
|
public Envelop updSim(String sim, String id){
|
|
|
if(findBySimNo(sim)!=null){
|
|
|
public Envelop updSim(String sim, String id) {
|
|
|
if (findBySimNo(sim) != null) {
|
|
|
return Envelop.getError("sim卡号已存在");
|
|
|
}
|
|
|
|
|
@ -199,15 +205,17 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 设备注册及绑定
|
|
|
*
|
|
|
* @param iotDeviceDO
|
|
|
*/
|
|
|
@Transactional
|
|
|
public void bindUser(List<IotDeviceDO> iotDeviceDO){
|
|
|
public void bindUser(List<IotDeviceDO> iotDeviceDO) {
|
|
|
this.batchInsert(iotDeviceDO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询
|
|
|
*
|
|
|
* @param sn
|
|
|
* @param hospital
|
|
|
* @param orderId
|
|
@ -219,56 +227,56 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop<IotDeviceVO, IotDeviceVO> queryPage(String sn, String hospital, String hospitalName,String orderId, String purcharseId, String productId, String name, String categoryCode, String manufacturerId, Integer page, Integer size) throws Exception{
|
|
|
public MixEnvelop<IotDeviceVO, IotDeviceVO> queryPage(String sn, String hospital, String hospitalName, String orderId, String purcharseId, String productId, String name, String categoryCode, String manufacturerId, Integer page, Integer size) throws Exception {
|
|
|
StringBuffer sql = new StringBuffer("SELECT DISTINCT c.* from iot_device c WHERE c.del=1 ");
|
|
|
StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_device c WHERE c.del=1 ");
|
|
|
List<Object> args = new ArrayList<>();
|
|
|
|
|
|
if(StringUtils.isNotBlank(orderId)){
|
|
|
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)){
|
|
|
if (StringUtils.isNotBlank(purcharseId)) {
|
|
|
sql.append(" and c.purchase_id = ? ");
|
|
|
sqlCount.append(" and c.purchase_id = '").append(purcharseId).append("'");
|
|
|
args.add(purcharseId);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(hospital)){
|
|
|
if (StringUtils.isNotBlank(hospital)) {
|
|
|
sql.append(" and c.hospital = ? ");
|
|
|
sqlCount.append(" and c.hospital = '").append(hospital).append("'");
|
|
|
args.add(hospital);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(sn)){
|
|
|
sn = "%"+sn+"%";
|
|
|
if (StringUtils.isNotBlank(sn)) {
|
|
|
sn = "%" + sn + "%";
|
|
|
sql.append(" and (c.device_sn like ? or c.sim_no like ?)");
|
|
|
sqlCount.append(" and (c.device_sn like '").append(sn).append("' or c.sim_no like '").append(sn).append("')");
|
|
|
args.add(sn);
|
|
|
args.add(sn);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(productId)){
|
|
|
if (StringUtils.isNotBlank(productId)) {
|
|
|
sql.append(" and c.product_id = ? ");
|
|
|
sqlCount.append(" and c.product_id = '").append(productId).append("'");
|
|
|
args.add(productId);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(name)){
|
|
|
name = "%"+name+"%";
|
|
|
if (StringUtils.isNotBlank(name)) {
|
|
|
name = "%" + name + "%";
|
|
|
sql.append(" and c.name like ?");
|
|
|
sqlCount.append(" and c.name like '").append(name).append("'");
|
|
|
args.add(name);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(categoryCode)){
|
|
|
if (StringUtils.isNotBlank(categoryCode)) {
|
|
|
sql.append(" and c.category_code = ? ");
|
|
|
sqlCount.append(" and c.category_code = '").append(categoryCode).append("'");
|
|
|
args.add(categoryCode);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(manufacturerId)){
|
|
|
if (StringUtils.isNotBlank(manufacturerId)) {
|
|
|
sql.append(" and c.manufacturer_id = ? ");
|
|
|
sqlCount.append(" and c.manufacturer_id = '").append(manufacturerId).append("'");
|
|
|
args.add(manufacturerId);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(hospitalName)){
|
|
|
hospitalName = "%"+hospitalName+"%";
|
|
|
if (StringUtils.isNotBlank(hospitalName)) {
|
|
|
hospitalName = "%" + hospitalName + "%";
|
|
|
sql.append(" and c.hospital_name like ?");
|
|
|
sqlCount.append(" and c.hospital_name like '").append(hospitalName).append("'");
|
|
|
args.add(hospitalName);
|
|
@ -276,25 +284,25 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
//数据权限过滤
|
|
|
List<String> orgList = orgUserService.getUserOrgById(userAgent.getUID());
|
|
|
if(!orgList.contains(userAgent.commonHospital)){
|
|
|
if (!orgList.contains(userAgent.commonHospital)) {
|
|
|
sql.append(" and c.hospital in (").append(orgUserService.getUserOrg(orgList)).append(")");
|
|
|
sqlCount.append(" and c.hospital in (").append(orgUserService.getUserOrg(orgList)).append(")");
|
|
|
}
|
|
|
|
|
|
sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
|
|
|
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());
|
|
|
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->{
|
|
|
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){
|
|
|
List<IotPatientDeviceDO> deviceDOList = iotPatientDeviceDao.findByDeviceSn(deviceSn);
|
|
|
if (deviceDOList != null && deviceDOList.size() > 0) {
|
|
|
one.setIsBinding(1);
|
|
|
}else {
|
|
|
} else {
|
|
|
one.setIsBinding(2);
|
|
|
}
|
|
|
one.setCreateUserName(AesEncryptUtils.decrypt(one.getCreateUserName()));
|
|
@ -302,11 +310,12 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
});
|
|
|
translateDictForList(iotDeviceVOList);
|
|
|
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,iotDeviceVOList, page, size,count);
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions, iotDeviceVOList, page, size, count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否绑定查询
|
|
|
*
|
|
|
* @param sn
|
|
|
* @param hospital
|
|
|
* @param orderId
|
|
@ -316,97 +325,97 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop<IotDeviceVO, IotDeviceVO> queryPage(String sn, String hospital, String orderId, String purcharseId, Integer isBinding, Integer page, Integer size){
|
|
|
public MixEnvelop<IotDeviceVO, 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 left join iot_patient_device t on t.del = 1 AND c.device_sn = t.device_sn WHERE c.del=1 ");
|
|
|
StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_device c left join iot_patient_device t on t.del = 1 AND c.device_sn = t.device_sn WHERE c.del=1 ");
|
|
|
List<Object> args = new ArrayList<>();
|
|
|
|
|
|
if(StringUtils.isNotBlank(orderId)){
|
|
|
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)){
|
|
|
if (StringUtils.isNotBlank(purcharseId)) {
|
|
|
sql.append(" and c.purchase_id = ? ");
|
|
|
sqlCount.append(" and c.purchase_id = '").append(purcharseId).append("'");
|
|
|
args.add(purcharseId);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(hospital)){
|
|
|
if (StringUtils.isNotBlank(hospital)) {
|
|
|
sql.append(" and c.hospital = ? ");
|
|
|
sqlCount.append(" and c.hospital = '").append(hospital).append("'");
|
|
|
args.add(hospital);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(sn)){
|
|
|
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);
|
|
|
}
|
|
|
if(isBinding==1){
|
|
|
if (isBinding == 1) {
|
|
|
sql.append(" and t.id is not null ");
|
|
|
sqlCount.append(" and t.id is not null ");
|
|
|
}else {
|
|
|
} else {
|
|
|
sql.append(" and t.id is null ");
|
|
|
sqlCount.append(" and t.id is null ");
|
|
|
}
|
|
|
|
|
|
//数据权限过滤
|
|
|
List<String> orgList = orgUserService.getUserOrgById(userAgent.getUID());
|
|
|
if(!orgList.contains(userAgent.commonHospital)){
|
|
|
if (!orgList.contains(userAgent.commonHospital)) {
|
|
|
sql.append(" and c.hospital in (?) ");
|
|
|
sqlCount.append(" and c.hospital in (").append(orgUserService.getUserOrg(orgList)).append(")");
|
|
|
args.add(orgUserService.getUserOrg(orgList));
|
|
|
}
|
|
|
|
|
|
sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
|
|
|
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());
|
|
|
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->{
|
|
|
List<IotDeviceVO> iotDeviceVOList = convertToModels(list, new ArrayList<>(list.size()), IotDeviceVO.class);
|
|
|
iotDeviceVOList.forEach(one -> {
|
|
|
one.setIsBinding(isBinding);
|
|
|
one.setCreateUserName(AesEncryptUtils.decrypt(one.getCreateUserName()));
|
|
|
one.setUpdateUserName(AesEncryptUtils.decrypt(one.getUpdateUserName()));
|
|
|
});
|
|
|
translateDictForList(iotDeviceVOList);
|
|
|
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,iotDeviceVOList, page, size,count);
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions, iotDeviceVOList, page, size, count);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop<IotDeviceVO, IotDeviceVO> findDevice(Integer page, Integer size) {
|
|
|
String sql ="SELECT DISTINCT c.* from iot_device c left join iot_patient_device t on t.del = 1 AND c.device_sn = t.device_sn WHERE c.del=1 ";
|
|
|
String sql = "SELECT DISTINCT c.* from iot_device c left join iot_patient_device t on t.del = 1 AND c.device_sn = t.device_sn WHERE c.del=1 ";
|
|
|
|
|
|
//数据权限过滤
|
|
|
List<String> orgList = orgUserService.getUserOrgById(userAgent.getUID());
|
|
|
if(!orgList.contains(userAgent.commonHospital)){
|
|
|
sql += " and c.hospital in ("+orgUserService.getUserOrg(orgList)+")";
|
|
|
if (!orgList.contains(userAgent.commonHospital)) {
|
|
|
sql += " and c.hospital in (" + orgUserService.getUserOrg(orgList) + ")";
|
|
|
}
|
|
|
|
|
|
sql += " GROUP BY c.`name`";
|
|
|
List<IotDeviceDO> list = jdbcTempalte.query(sql,new BeanPropertyRowMapper(IotDeviceDO.class));
|
|
|
for (int i=0;i<list.size();i++){
|
|
|
List<IotDeviceDO> list = jdbcTempalte.query(sql, new BeanPropertyRowMapper(IotDeviceDO.class));
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
list.get(i).setCreateUserName(AesEncryptUtils.decrypt(list.get(i).getCreateUserName()));
|
|
|
list.get(i).setUpdateUserName(AesEncryptUtils.decrypt(list.get(i).getUpdateUserName()));
|
|
|
}
|
|
|
//DO转VO
|
|
|
List<IotDeviceVO> iotDeviceVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceVO.class);
|
|
|
List<IotDeviceVO> iotDeviceVOList = convertToModels(list, new ArrayList<>(list.size()), IotDeviceVO.class);
|
|
|
|
|
|
translateDictForList(iotDeviceVOList);
|
|
|
|
|
|
long count = list.size();
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,iotDeviceVOList, page, size,count);
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions, iotDeviceVOList, page, size, count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据设备序列号判断设备是否存在
|
|
|
*
|
|
|
* @param deviceSn
|
|
|
* @return
|
|
|
*/
|
|
@ -416,6 +425,7 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 根据设备序列号查找设备
|
|
|
*
|
|
|
* @param deviceSn
|
|
|
* @return
|
|
|
*/
|
|
@ -423,26 +433,39 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
return iotDeviceDao.findByDeviceSn(deviceSn);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据设备唯一码查找设备
|
|
|
*
|
|
|
* @param deviceUniqueCode
|
|
|
* @return
|
|
|
*/
|
|
|
public IotDeviceDO findByDeviceUniqueCode(String deviceUniqueCode) {
|
|
|
return iotDeviceDao.findByDeviceUniqueCode(deviceUniqueCode);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据设备序列号查找设备
|
|
|
*
|
|
|
* @param deviceSn
|
|
|
* @param productId
|
|
|
* @param hospital
|
|
|
* @return
|
|
|
*/
|
|
|
public IotDeviceDO findDeviceBySn(String deviceSn,String productId,String hospital){
|
|
|
String sql ="SELECT c.* from iot_device c WHERE c.del=1 ";
|
|
|
if(StringUtils.isNotEmpty(deviceSn)){
|
|
|
sql += " and c.device_sn = '"+deviceSn+"'";
|
|
|
public IotDeviceDO findDeviceBySn(String deviceSn, String productId, String hospital) {
|
|
|
String sql = "SELECT c.* from iot_device c WHERE c.del=1 ";
|
|
|
if (StringUtils.isNotEmpty(deviceSn)) {
|
|
|
sql += " and c.device_sn = '" + deviceSn + "'";
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(productId)){
|
|
|
sql += " and c.product_id = '"+productId+"'";
|
|
|
if (StringUtils.isNotEmpty(productId)) {
|
|
|
sql += " and c.product_id = '" + productId + "'";
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(hospital)){
|
|
|
sql += " and c.hospital = '"+hospital+"'";
|
|
|
if (StringUtils.isNotEmpty(hospital)) {
|
|
|
sql += " and c.hospital = '" + hospital + "'";
|
|
|
}
|
|
|
List<IotDeviceDO> list = jdbcTempalte.query(sql,new BeanPropertyRowMapper(IotDeviceDO.class));
|
|
|
if(list.size()>0){
|
|
|
List<IotDeviceDO> list = jdbcTempalte.query(sql, new BeanPropertyRowMapper(IotDeviceDO.class));
|
|
|
if (list.size() > 0) {
|
|
|
list.get(0).setCreateUserName(AesEncryptUtils.decrypt(list.get(0).getCreateUserName()));
|
|
|
list.get(0).setUpdateUserName(AesEncryptUtils.decrypt(list.get(0).getUpdateUserName()));
|
|
|
return list.get(0);
|
|
@ -453,7 +476,7 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
/**
|
|
|
* 设备导入
|
|
|
*/
|
|
|
public IotDeviceImportRecordVO importDevice(String fileUrl, String fileName, String purcharseId, List<IotDeviceImportVO> importVOList){
|
|
|
public IotDeviceImportRecordVO importDevice(String fileUrl, String fileName, String purcharseId, List<IotDeviceImportVO> importVOList) {
|
|
|
IotDeviceImportRecordDO recordDO = new IotDeviceImportRecordDO();
|
|
|
IotOrderPurchaseDO purchaseDO = iotOrderPurchaseDao.findById(purcharseId);
|
|
|
recordDO.setDel(1);
|
|
@ -465,57 +488,61 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
recordDO.setStatus(IotDeviceImportRecordDO.DeviceImportRecordStatus.create.getValue());
|
|
|
|
|
|
iotDeviceImportRecordDao.save(recordDO);
|
|
|
IotDeviceImportRecordVO vo = convertToModel(recordDO,IotDeviceImportRecordVO.class);
|
|
|
IotDeviceImportRecordVO vo = convertToModel(recordDO, IotDeviceImportRecordVO.class);
|
|
|
|
|
|
//批量导入 异步操作
|
|
|
importRecordService.importDevice(purchaseDO,importVOList,recordDO);
|
|
|
importRecordService.importDevice(purchaseDO, importVOList, recordDO);
|
|
|
|
|
|
return vo;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
;
|
|
|
|
|
|
/**
|
|
|
* 分页查找导入记录
|
|
|
*
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @param purcharseId
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop<IotDeviceImportRecordVO, IotDeviceImportRecordVO> queryImportRecordPage(Integer page, Integer size, String purcharseId){
|
|
|
public MixEnvelop<IotDeviceImportRecordVO, IotDeviceImportRecordVO> queryImportRecordPage(Integer page, Integer size, String purcharseId) {
|
|
|
StringBuffer sql = new StringBuffer("SELECT c.* from iot_device_import_record c WHERE c.del=1 ");
|
|
|
StringBuffer sqlCount = new StringBuffer("SELECT COUNT(c.id) count from iot_device_import_record c WHERE c.del=1 ");
|
|
|
List<Object> args = new ArrayList<>();
|
|
|
|
|
|
if(StringUtils.isNotBlank(purcharseId)){
|
|
|
if (StringUtils.isNotBlank(purcharseId)) {
|
|
|
sql.append(" and c.purchase_id=? ");
|
|
|
sqlCount.append(" and c.purchase_id='").append(purcharseId).append("' ");
|
|
|
args.add(purcharseId);
|
|
|
}
|
|
|
sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
|
|
|
sql.append("order by c.update_time desc limit ").append((page - 1) * size).append(",").append(size);
|
|
|
|
|
|
List<IotDeviceImportRecordDO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotDeviceImportRecordDO.class));
|
|
|
List<Map<String,Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
|
|
|
List<IotDeviceImportRecordDO> list = jdbcTempalte.query(sql.toString(), args.toArray(), new BeanPropertyRowMapper(IotDeviceImportRecordDO.class));
|
|
|
List<Map<String, Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
|
|
|
long count = Long.valueOf(countList.get(0).get("count").toString());
|
|
|
|
|
|
//DO转VO
|
|
|
List<IotDeviceImportRecordVO> importRecordVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceImportRecordVO.class);
|
|
|
List<IotDeviceImportRecordVO> importRecordVOList = convertToModels(list, new ArrayList<>(list.size()), IotDeviceImportRecordVO.class);
|
|
|
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,importRecordVOList, page, size,count);
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions, importRecordVOList, page, size, count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 字典翻译
|
|
|
*
|
|
|
* @param iotDeviceVOList
|
|
|
*/
|
|
|
public void translateDictForList(List<IotDeviceVO> iotDeviceVOList){
|
|
|
if(iotDeviceVOList.size()>0){
|
|
|
public void translateDictForList(List<IotDeviceVO> iotDeviceVOList) {
|
|
|
if (iotDeviceVOList.size() > 0) {
|
|
|
//字典翻译
|
|
|
Map<String,String> deviceBindingMap = iotSystemDictService.findByDictName("DEVICE_BINDING");
|
|
|
Map<String,String> deviceSourceMap = iotSystemDictService.findByDictName("DEVICE_SOURCE");
|
|
|
iotDeviceVOList.forEach(infoVO->{
|
|
|
if(infoVO.getIsBinding()!=null){
|
|
|
Map<String, String> deviceBindingMap = iotSystemDictService.findByDictName("DEVICE_BINDING");
|
|
|
Map<String, String> deviceSourceMap = iotSystemDictService.findByDictName("DEVICE_SOURCE");
|
|
|
iotDeviceVOList.forEach(infoVO -> {
|
|
|
if (infoVO.getIsBinding() != null) {
|
|
|
infoVO.setIsBindingName(deviceBindingMap.get(infoVO.getIsBinding().toString()));
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(infoVO.getDeviceSource())){
|
|
|
if (StringUtils.isNotBlank(infoVO.getDeviceSource())) {
|
|
|
infoVO.setDeviceSourceName(deviceSourceMap.get(infoVO.getDeviceSource()));
|
|
|
}
|
|
|
});
|
|
@ -524,50 +551,51 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
|
|
|
/**
|
|
|
* 字典翻译
|
|
|
*
|
|
|
* @param iotDeviceVO
|
|
|
*/
|
|
|
public void translateDictForOne(IotDeviceVO iotDeviceVO){
|
|
|
if(iotDeviceVO!=null){
|
|
|
public void translateDictForOne(IotDeviceVO iotDeviceVO) {
|
|
|
if (iotDeviceVO != null) {
|
|
|
//字典翻译
|
|
|
Map<String,String> deviceBindingMap = iotSystemDictService.findByDictName("DEVICE_BINDING");
|
|
|
Map<String,String> deviceSourceMap = iotSystemDictService.findByDictName("DEVICE_SOURCE");
|
|
|
Map<String,String> qualityStatusMap = iotSystemDictService.findByDictName("QUALITY_STATUS");
|
|
|
Map<String, String> deviceBindingMap = iotSystemDictService.findByDictName("DEVICE_BINDING");
|
|
|
Map<String, String> deviceSourceMap = iotSystemDictService.findByDictName("DEVICE_SOURCE");
|
|
|
Map<String, String> qualityStatusMap = iotSystemDictService.findByDictName("QUALITY_STATUS");
|
|
|
|
|
|
List<IotPatientDeviceDO> deviceDOList = iotPatientDeviceDao.findByDeviceSn(iotDeviceVO.getDeviceSn());
|
|
|
if(deviceDOList!=null&&deviceDOList.size()>0){
|
|
|
List<IotPatientDeviceDO> deviceDOList = iotPatientDeviceDao.findByDeviceSn(iotDeviceVO.getDeviceSn());
|
|
|
if (deviceDOList != null && deviceDOList.size() > 0) {
|
|
|
iotDeviceVO.setIsBinding(1);
|
|
|
}else {
|
|
|
} else {
|
|
|
iotDeviceVO.setIsBinding(2);
|
|
|
}
|
|
|
iotDeviceVO.setIsBindingName(deviceBindingMap.get(iotDeviceVO.getIsBinding().toString()));
|
|
|
|
|
|
if(StringUtils.isNotBlank(iotDeviceVO.getDeviceSource())){
|
|
|
if (StringUtils.isNotBlank(iotDeviceVO.getDeviceSource())) {
|
|
|
iotDeviceVO.setDeviceSourceName(deviceSourceMap.get(iotDeviceVO.getDeviceSource()));
|
|
|
}
|
|
|
//获取质检信息
|
|
|
IotDeviceQualityInspectionPlanDO planDO = iotDeviceQualityInspectionPlanDao.findByDeviceId(iotDeviceVO.getId());
|
|
|
if(planDO!=null){
|
|
|
if (planDO != null) {
|
|
|
iotDeviceVO.setQualityStatus(qualityStatusMap.get(planDO.getStatus()));//质检状态
|
|
|
}else if(StringUtils.isNotBlank(iotDeviceVO.getPurchaseId())){
|
|
|
} else if (StringUtils.isNotBlank(iotDeviceVO.getPurchaseId())) {
|
|
|
IotOrderPurchaseDO purchaseDO = iotOrderPurchaseDao.findById(iotDeviceVO.getPurchaseId());
|
|
|
if(purchaseDO!=null&&StringUtils.isNotBlank(purchaseDO.getQualityStatus())){
|
|
|
if (purchaseDO != null && StringUtils.isNotBlank(purchaseDO.getQualityStatus())) {
|
|
|
iotDeviceVO.setQualityStatus(qualityStatusMap.get(purchaseDO.getQualityStatus()));//质检状态
|
|
|
}
|
|
|
}
|
|
|
//数据来源
|
|
|
if(StringUtils.isNotBlank(iotDeviceVO.getPurchaseId())){
|
|
|
if (StringUtils.isNotBlank(iotDeviceVO.getPurchaseId())) {
|
|
|
List<IotProductDataTransmissionDO> dataTransmissionDOList = iotProductDataTransmissionDao.findByProductId(iotDeviceVO.getProductId());
|
|
|
if(dataTransmissionDOList!=null){
|
|
|
if (dataTransmissionDOList != null) {
|
|
|
List<IotProductDataTransmissionVO> dataTransmissionVOList =
|
|
|
convertToModels(dataTransmissionDOList,new ArrayList<>(dataTransmissionDOList.size()),IotProductDataTransmissionVO.class);
|
|
|
convertToModels(dataTransmissionDOList, new ArrayList<>(dataTransmissionDOList.size()), IotProductDataTransmissionVO.class);
|
|
|
iotDeviceVO.setDataTransmissionVOList(dataTransmissionVOList);
|
|
|
}
|
|
|
}
|
|
|
//关联居民
|
|
|
List<IotPatientDeviceDO> patientDeviceDOList = iotPatientDeviceDao.findByDeviceSn(iotDeviceVO.getDeviceSn());
|
|
|
if(patientDeviceDOList!=null){
|
|
|
if (patientDeviceDOList != null) {
|
|
|
List<IotPatientDeviceVO> patientDeviceVOList =
|
|
|
convertToModels(patientDeviceDOList,new ArrayList<>(patientDeviceDOList.size()),IotPatientDeviceVO.class);
|
|
|
convertToModels(patientDeviceDOList, new ArrayList<>(patientDeviceDOList.size()), IotPatientDeviceVO.class);
|
|
|
iotDeviceVO.setPatientDeviceVOList(patientDeviceVOList);
|
|
|
}
|
|
|
}
|
|
@ -613,4 +641,28 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
|
|
|
inputStream.close();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取一个空闲设备
|
|
|
*
|
|
|
* @param productId
|
|
|
* @return
|
|
|
*/
|
|
|
public IotDeviceDO findFreeDevice(String productId,String deviceSn) {
|
|
|
String sql = "SELECT c.* from iot_device c WHERE c.del=1 ";
|
|
|
if (StringUtils.isNotEmpty(productId)) {
|
|
|
sql += " and c.product_id = '" + productId + "'";
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(deviceSn)) {
|
|
|
sql += " and c.device_sn = '" + deviceSn + "'";
|
|
|
}
|
|
|
sql += " AND c.is_grant='0' AND c.`status`='1' ";
|
|
|
List<IotDeviceDO> list = jdbcTempalte.query(sql, new BeanPropertyRowMapper(IotDeviceDO.class));
|
|
|
if (list.size() > 0) {
|
|
|
list.get(0).setCreateUserName(AesEncryptUtils.decrypt(list.get(0).getCreateUserName()));
|
|
|
list.get(0).setUpdateUserName(AesEncryptUtils.decrypt(list.get(0).getUpdateUserName()));
|
|
|
return list.get(0);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
}
|