| | |
| | | package com.moral.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.moral.common.bean.PageBean; |
| | | import com.moral.common.util.MyBatisBaseMapUtil; |
| | | import com.moral.common.util.RedisUtils; |
| | | import com.moral.entity.DeviceVersion; |
| | | import com.moral.entity.DeviceVersionSensor; |
| | | import com.moral.entity.Sensor; |
| | | import com.moral.mapper.DeviceVersionMapper; |
| | | import com.moral.mapper.DeviceVersionSensorMapper; |
| | | import com.moral.service.DeviceVersionService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import tk.mybatis.mapper.entity.Example; |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class DeviceVersionServiceImpl implements DeviceVersionService { |
| | |
| | | @Resource |
| | | private DeviceVersionSensorMapper deviceVersionSensorMapper; |
| | | private static Class ENTITY_CLASS = DeviceVersion.class; |
| | | @Override |
| | | public PageBean queryByPageBean(PageBean pageBean){ |
| | | return MyBatisBaseMapUtil.queryPage(deviceVersionMapper,pageBean,ENTITY_CLASS); |
| | | } |
| | | @Override |
| | | public void addOrModify(DeviceVersion deviceVersion){ |
| | | try{ |
| | | if(deviceVersion.getId()==null){ |
| | | deviceVersion.setUpdateTime(new Date()); |
| | | deviceVersionMapper.insertSelective(deviceVersion); |
| | | }else{ |
| | | deviceVersion.setUpdateTime(new Date()); |
| | | deviceVersionMapper.updateByPrimaryKeySelective(deviceVersion); |
| | | } |
| | | } |
| | |
| | | public void deleteByIds(Integer... ids) { |
| | | if(ids!=null&&ids.length>0){ |
| | | if(ids.length==1){ |
| | | deviceVersionMapper.deleteByPrimaryKey(ids[0]); |
| | | DeviceVersion deviceVersion = new DeviceVersion(); |
| | | deviceVersion.setId(ids[0]); |
| | | deviceVersion.setIsDelete(true); |
| | | deviceVersion.setUpdateTime(new Date()); |
| | | deviceVersionMapper.updateByPrimaryKeySelective(deviceVersion); |
| | | }else{ |
| | | DeviceVersion deviceVersion = new DeviceVersion(); |
| | | deviceVersion.setIsDelete(true); |
| | | deviceVersion.setUpdateTime(new Date()); |
| | | Example example = new Example(ENTITY_CLASS); |
| | | example.or().andIn("id", Arrays.asList(ids)); |
| | | deviceVersionMapper.deleteByExample(example); |
| | | deviceVersionMapper.updateByExampleSelective(deviceVersion,example); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | @Override |
| | | public void versionSensorConfig(Integer deviceVersionId, Integer[] sensorIds){ |
| | | Example example = new Example(DeviceVersionSensor.class); |
| | | example.or().andEqualTo("deviceVersionId",deviceVersionId); |
| | | deviceVersionSensorMapper.deleteByExample(example); |
| | | redisUtils.remove("deviceVersion_" + deviceVersionId); |
| | | if(sensorIds!=null && sensorIds.length >0){ |
| | | List<DeviceVersionSensor> deviceVersionSensorList = new ArrayList<DeviceVersionSensor>(); |
| | | for(int sensorId:sensorIds){ |
| | |
| | | public List<DeviceVersion> getVersionsByOrgId(int organizationId){ |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Integer queryMaxVersionNo() { |
| | | Example example = new Example(DeviceVersion.class); |
| | | example.orderBy("version").desc(); |
| | | List<DeviceVersion> deviceVersionList = deviceVersionMapper.selectByExample(example); |
| | | if(deviceVersionList.size()>0){ |
| | | return deviceVersionList.get(0).getVersion(); |
| | | } |
| | | return null; |
| | | } |
| | | @Override |
| | | public DeviceVersion queryByVersionNo(int versionNo) { |
| | | DeviceVersion query = new DeviceVersion(); |
| | | query.setVersion(versionNo); |
| | | return deviceVersionMapper.selectOne(query); |
| | | } |
| | | @Override |
| | | public List<Integer> getSensorIds(int deviceVersionId){ |
| | | DeviceVersionSensor deviceVersionSensor = new DeviceVersionSensor(); |