package com.ld.igds.phone.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.common.CoreDeviceService;
|
import com.ld.igds.common.dto.DepotSerData;
|
import com.ld.igds.constant.RespCodeEnum;
|
import com.ld.igds.models.Depot;
|
import com.ld.igds.models.Device;
|
import com.ld.igds.phone.constant.PhoneConstant;
|
import com.ld.igds.phone.dto.*;
|
import com.ld.igds.phone.param.ParamDevice;
|
import com.ld.igds.phone.param.PhoneRequest;
|
import com.ld.igds.phone.service.PhoneService;
|
import com.ld.igds.phone.util.PhoneRespUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* 设备控制-设备列表接口实现
|
*
|
* @author chen
|
*/
|
@Service
|
public class ServiceImpl5402 implements PhoneService {
|
|
@Autowired
|
private CoreCommonService coreCommonService;
|
@Autowired
|
private CoreDeviceService coreDeviceService;
|
|
@Override
|
public String getInterfaceId() {
|
return PhoneConstant.API_PHONE_5402;
|
}
|
|
@SuppressWarnings("unchecked")
|
@Override
|
public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser)
|
throws Exception {
|
|
//转化对象
|
ParamDevice paramDevice = JSONObject.parseObject(req.getData().toString(), ParamDevice.class);
|
|
//查看用户所属部门是否存在
|
String deptId = authUser.getDeptId();
|
if (StringUtils.isEmpty(deptId)) {
|
return PhoneRespUtil.error(RespCodeEnum.CODE_1111, "您的账号尚未分配部门/分库,无法查看!");
|
}
|
|
//判断登录用户部门是否是顶级部门,是的话默认分配到分库一
|
if (deptId.equals(authUser.getCompanyId())) {
|
deptId = authUser.getCompanyId() + "_001";
|
}
|
|
//创建响应的设备列表信息
|
List<DtoDevice> listDevice = new ArrayList<>();
|
DtoDevice dtoDevice;
|
// 根据仓库缓存获取相同建筑物下的仓库集合
|
List<Depot> list = coreCommonService.getCacheCommonBuildingDepot(
|
authUser.getCompanyId(), paramDevice.getDepotId());
|
// 获取ID信息
|
List<String> depotIds = list.stream().map(Depot::getId)
|
.collect(Collectors.toList());
|
|
// 根据仓库多个ID获取仓库与分机的关系数据
|
List<DepotSerData> depotSerDataList = coreCommonService
|
.getCacheDepotSerByDepots(authUser.getCompanyId(), depotIds);
|
|
List<Device> listAll = new ArrayList<Device>();
|
List<Device> tempList;
|
for (DepotSerData depotSerData : depotSerDataList) {
|
tempList = coreDeviceService.getCacheDeviceBySerId(
|
authUser.getCompanyId(), depotSerData.getSerId());
|
listAll.addAll(tempList);
|
}
|
|
if (listAll.size() > 0) {
|
// 循环遍历多个仓的
|
List<Device> listResult = listAll
|
.stream()
|
.filter(item -> item.getDepotId().equals(paramDevice.getDepotId())
|
&& (item.getType().equals(paramDevice.getType())
|
|| item.getType().equals(paramDevice.getType1())
|
|| item.getType().equals(paramDevice.getType2())
|
|| item.getType().equals(paramDevice.getType3())
|
)
|
)
|
.collect(Collectors.toList());
|
if (listResult.size() > 0) {
|
for (Device device : listResult) {
|
dtoDevice = new DtoDevice();
|
dtoDevice.setCompanyId(device.getCompanyId());
|
dtoDevice.setId(device.getId());
|
dtoDevice.setDepotId(device.getDepotId());
|
dtoDevice.setName(device.getName());
|
dtoDevice.setStatus(device.getStatus());
|
dtoDevice.setPassCode(device.getPassCode());
|
dtoDevice.setSerId(device.getSerId());
|
dtoDevice.setType(device.getType());
|
dtoDevice.setLocation(device.getLocation());
|
dtoDevice.setLink(device.getLink());
|
listDevice.add(dtoDevice);
|
}
|
}
|
}
|
|
if(listDevice.isEmpty()){
|
return PhoneRespUtil.error(RespCodeEnum.CODE_2000, "该仓库暂无设备信息,请联系管理员!");
|
}
|
|
return PhoneRespUtil.success(listDevice, req);
|
}
|
|
}
|