| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | |
| | | import com.ruoyi.iot.service.IDeviceService; |
| | | import com.ruoyi.iot.service.IProductService; |
| | | import com.ruoyi.iot.service.IToolService; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.quartz.SchedulerException; |
| | | import org.slf4j.Logger; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | |
| | | @Autowired |
| | | @Lazy |
| | | private EmqxService emqxService; |
| | | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | /** |
| | | * 查询设备 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询总设备数(台) |
| | | * |
| | | * @param id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public AjaxResult selectDeviceCount(int id) throws Exception { |
| | | //根据用户登录的角色身份查询总设备数(台) |
| | | int count = deviceMapper.selectDeviceCount(id); |
| | | //根据登录用户的角色身份查询设备的使用人数 |
| | | int total = deviceMapper.selectUserDeviceByCount(id); |
| | | AjaxResult ajax = new AjaxResult(); |
| | | ajax.put("deviceCount", count); |
| | | ajax.put("userTotal", total); |
| | | return AjaxResult.success("查询成功", ajax); |
| | | } |
| | | |
| | | /** |
| | | * 根据登录用户的id查询设备的使用人数 |
| | | * |
| | | * @param id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | |
| | | @Override |
| | | public int selectUserDeviceByCount(int id) throws Exception { |
| | | return deviceMapper.selectUserDeviceByCount(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<Device> selectDeviceAll() throws Exception { |
| | | return deviceMapper.selectDeviceAll(); |
| | | } |
| | | |
| | | /** |
| | | * 根据设备编号查询简介设备 |
| | | * |
| | | * @param serialNumber 设备主键 |
| | |
| | | // 查询物模型 |
| | | String thingsModels = thingsModelService.getCacheThingsModelByProductId(input.getProductId()); |
| | | JSONObject thingsModelObject = JSONObject.parseObject(thingsModels); |
| | | //ThingsModelValueItemDto——物模型 |
| | | List<ThingsModelValueItemDto> valueList = null; |
| | | if (type == 1) { |
| | | JSONArray properties = thingsModelObject.getJSONArray("properties"); |
| | |
| | | |
| | | // 查询物模型值 |
| | | ThingsModelValuesOutput deviceThings = deviceMapper.selectDeviceThingsModelValueBySerialNumber(input.getDeviceNumber()); |
| | | //物模型值的项——ThingsModelValueItem |
| | | List<ThingsModelValueItem> thingsModelValues = JSONObject.parseArray(deviceThings.getThingsModelValue(), ThingsModelValueItem.class); |
| | | |
| | | for (int i = 0; i < input.getThingsModelValueRemarkItem().size(); i++) { |
| | |
| | | * @return 设备 |
| | | */ |
| | | @Override |
| | | public List<DeviceShortOutput> selectDeviceShortList(Device device) { |
| | | public List<DeviceShortOutput> selectDeviceShortList(Device device, boolean repairFlag) { |
| | | SysUser user = getLoginUser().getUser(); |
| | | List<SysRole> roles = user.getRoles(); |
| | | for (int i = 0; i < roles.size(); i++) { |
| | | if (roles.get(i).getRoleKey().equals("tenant")) { |
| | | // 租户查看产品下所有设备 |
| | | device.setTenantId(user.getUserId()); |
| | | if (repairFlag == true) { |
| | | device.setInstallFlag(1); |
| | | } |
| | | break; |
| | | } else if (roles.get(i).getRoleKey().equals("general")) { |
| | | // 用户查看自己设备 |
| | | device.setUserId(user.getUserId()); |
| | | if (repairFlag == true) { |
| | | device.setInstallFlag(1); |
| | | } |
| | | break; |
| | | } else if (roles.get(i).getRoleKey().equals("tenanthelper")) { |
| | | //联营商合伙人查看设备 |
| | | //联营商合伙人需要根据他自己的userid去查询他上级的用户信息,tenantid是租户id和他的一级联营商所拥有的设备 |
| | | //通过用户ID查询用户根据当前登录的联营商合伙人去查询他的上级部门id是几,再通过他的上级部门id去查询所对应的一级联营商和所对应的tenantid |
| | | SysUser sysUser = userService.selectUserById(user.getUserId());//拿到所在的部门id |
| | | SysDept sysDept = sysDeptMapper.selectDeptById(sysUser.getDeptId()); //根据部门id去查询信息得到父级的部门id |
| | | SysDept sysDeptParent = sysDeptMapper.selectDeptById(sysDept.getParentId()); //根据父级部门的id去查询信息 |
| | | SysUser sysUserDept = userService.selectUserByDeptId(sysDeptParent.getDeptId());//根据得到的父级的部门id去sys_user表里面查询他的用户信息 |
| | | device.setTenantId(sysUserDept.getUserId()); |
| | | if (repairFlag == true) { |
| | | device.setInstallFlag(1); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | |
| | | device.setUserId(device.getUserId()); |
| | | device.setUserName(sysUser.getUserName()); |
| | | } |
| | | }else{ |
| | | } else { |
| | | // 其他联网设备不更新用户信息 |
| | | device.setUserId(null); |
| | | } |
| | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public int updateDeviceBySN(List<String> snList, Long tenantId) { |
| | | List<Device> deviceList = snList.stream().map(s -> { |
| | | Device device = new Device(); |
| | | device.setTenantId(tenantId); |
| | | device.setSerialNumber(s.trim()); |
| | | device.setAssignTime(DateUtils.getNowDate()); |
| | | return device; |
| | | }).collect(Collectors.toList()); |
| | | int i = 0; |
| | | for (Device device : deviceList) { |
| | | deviceMapper.updateDeviceBySerialNumber(device); |
| | | i++; |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | @Override |
| | | public int updateDeviceUserBySN(List<String> snList, Long userId) { |
| | | LoginUser loginUser = getLoginUser(); |
| | | List<Device> deviceList = snList.stream().map(s -> { |
| | | Device device = new Device(); |
| | | device.setSerialNumber(s.trim()); |
| | | return device; |
| | | }).collect(Collectors.toList()); |
| | | int i = 0; |
| | | for (Device device : deviceList) { |
| | | //判断设备是否存在 |
| | | Device deviceTmp = deviceMapper.selectShortDeviceBySerialNumber(device.getSerialNumber()); |
| | | if (deviceTmp == null) return -1; |
| | | //判断设备是不是已经分享 |
| | | List<DeviceUser> deviceUserList = deviceUserMapper.selectDeviceUserByDeviceId(deviceTmp.getDeviceId()); |
| | | for (DeviceUser deviceUserTmp : deviceUserList) { |
| | | if (deviceUserTmp.getUserId() == userId && deviceUserTmp.getIsOwner() == 0) |
| | | return -2; |
| | | } |
| | | |
| | | //更新设备表 |
| | | device.setUserId(userId); |
| | | device.setUserName(loginUser.getUsername()); |
| | | deviceMapper.updateDeviceBySerialNumber(device); |
| | | //更新设备对应的主人表 |
| | | DeviceUser deviceUser = new DeviceUser(); |
| | | deviceUser.setUserId(userId); |
| | | deviceUser.setUserName(loginUser.getUsername()); |
| | | //deviceUser.setPhonenumber(loginUser.getp); |
| | | deviceUser.setUpdateTime(DateUtils.getNowDate()); |
| | | deviceUser.setDeviceId(deviceTmp.getDeviceId()); |
| | | deviceUserMapper.updateDeviceUserInit(deviceUser); |
| | | i++; |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | | * 删除设备 |
| | | * |