| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.Device; |
| | | import com.moral.api.entity.DeviceAdjustValue; |
| | | import com.moral.api.entity.Sensor; |
| | |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | return resultMap; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getDataByCondition(Map map) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | int current = Integer.parseInt(map.get("current").toString()); |
| | | int size = Integer.parseInt(map.get("size").toString()); |
| | | Page<DeviceAdjustValue> page = new Page<>(current,size); |
| | | QueryWrapper<DeviceAdjustValue> wrapper_Condition = new QueryWrapper<>(); |
| | | wrapper_Condition.eq("is_delete",Constants.NOT_DELETE); |
| | | if (!ObjectUtils.isEmpty(map.get("mac"))){ |
| | | wrapper_Condition.eq("mac",map.get("mac")); |
| | | } |
| | | if (!ObjectUtils.isEmpty(map.get("sensor_code"))){ |
| | | wrapper_Condition.eq("sensor_code",map.get("sensor_code")); |
| | | } |
| | | if (!ObjectUtils.isEmpty(map.get("orderType"))){ |
| | | String orderType = map.get("orderType").toString(); |
| | | if (orderType.equals(Constants.ORDER_ASC)){ |
| | | wrapper_Condition.orderByAsc("start_time"); |
| | | }else { |
| | | wrapper_Condition.orderByDesc("start_time"); |
| | | } |
| | | } |
| | | Page resultPage = deviceAdjustValueMapper.selectPage(page,wrapper_Condition); |
| | | List<DeviceAdjustValue> deviceAdjustValues = resultPage.getRecords(); |
| | | List<Map<String,Object>> deviceAdjustValueList = new ArrayList<>(); |
| | | for (DeviceAdjustValue deviceAdjustValue:deviceAdjustValues) { |
| | | Map deviceAdjustValueMap = JSON.parseObject(JSON.toJSONString(deviceAdjustValue),Map.class); |
| | | deviceAdjustValueList.add(deviceAdjustValueMap); |
| | | } |
| | | resultMap.put("deviceAdjustValues",deviceAdjustValueList); |
| | | int totalNumber = deviceAdjustValueMapper.selectCount(wrapper_Condition); |
| | | resultMap.put("totalNumber",totalNumber); |
| | | resultMap.put("current",current); |
| | | resultMap.put("size",size); |
| | | int totalPageNumber = totalNumber/size; |
| | | if(totalNumber%size != 0){ |
| | | totalPageNumber += 1; |
| | | } |
| | | resultMap.put("totalPageNumber",totalPageNumber); |
| | | return resultMap; |
| | | } |
| | | |
| | | } |