| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
| | | 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 {
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | | }
|