| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.github.pagehelper.PageHelper;
|
| | | import com.moral.common.exception.BusinessException;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | import com.moral.entity.Device;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.service.AccountService;
|
| | | import com.moral.service.DeviceService;
|
| | |
|
| | | import tk.mybatis.mapper.entity.Example;
|
| | |
|
| | | @Service
|
| | | public class DeviceServiceImpl implements DeviceService {
|
| | |
|
| | | @Autowired
|
| | | @Resource
|
| | | private DeviceMapper deviceMapper;
|
| | |
|
| | | @Autowired
|
| | | @Resource
|
| | | private AccountService accountService;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getDeviceStates(Map<String, Object> parameters) {
|
| | | public Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | List<Map<String, Object>> list = deviceMapper.getDeviceStates(parameters);
|
| | | List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(parameters);
|
| | | Long all = 0L, normal = 0L, abnormal = 0L, stop = 0L;
|
| | | for (Map<String, Object> map : list) {
|
| | | Long count = (Long) map.get("count");
|
| | | all += count;
|
| | | switch ((Integer) map.get("state")) {
|
| | | switch (Integer.valueOf((String) map.get("state"))) {
|
| | | case 0:
|
| | | normal = count;
|
| | | break;
|
| | |
| | | result.put("stop", stop);
|
| | | return result;
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<Map<String, Object>> getSensorsByDevice(String mac) {
|
| | | return deviceMapper.getSensorsByDevice(mac);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void saveOrUpdateDevice(Device device) {
|
| | | ValidateUtil.notNull(device, "参数不可为空");
|
| | | ValidateUtil.notEmpty(device.getMac(), "参数不可为空");
|
| | | Example example = new Example(Device.class);
|
| | | example.or().andEqualTo("mac",device.getMac());
|
| | | List<Device> devices = deviceMapper.selectByExample(example);
|
| | | Date operateDate = new Date();
|
| | | device.setInstallTime(operateDate);
|
| | | if (ObjectUtils.isEmpty(devices)) {
|
| | | device.setCreateTime(operateDate);
|
| | | device.setState("4");
|
| | | deviceMapper.insertSelective(device);
|
| | | }else if (devices.size() > 1) {
|
| | | throw new BusinessException("设备信息异常,联系管理员!");
|
| | | }else {
|
| | | device.setId(devices.get(0).getId());
|
| | | deviceMapper.updateByPrimaryKeySelective(device);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize) {
|
| | | Example example = new Example(Device.class);
|
| | | example.or().andEqualTo("operateUserId",uid);
|
| | | PageHelper.startPage(pageIndex, pageSize);
|
| | | List<Device> devices = deviceMapper.selectByExample(example);
|
| | | return devices;
|
| | | }
|
| | |
|
| | | }
|