|
@@ -3,9 +3,18 @@ package com.bz.smart_city.service.impl;
|
|
|
import com.bz.smart_city.commom.constant.MeterReadEnum;
|
|
|
import com.bz.smart_city.commom.exception.ServiceException;
|
|
|
import com.bz.smart_city.commom.util.*;
|
|
|
+import com.bz.smart_city.dao.*;
|
|
|
import com.bz.smart_city.dto.*;
|
|
|
|
|
|
+import com.bz.smart_city.entity.*;
|
|
|
+import com.bz.smart_city.rabbitmq.model.RabbitDeviceParamData;
|
|
|
+import com.bz.smart_city.rabbitmq.model.RabbitParamData;
|
|
|
+import com.bz.smart_city.rabbitmq.model.RabbitWaterConsumptionData;
|
|
|
+import com.bz.smart_city.service.MessageService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.amqp.rabbit.connection.SimpleResourceHolder;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.jdbc.datasource.DataSourceUtils;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -15,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
@@ -22,30 +32,12 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-import com.bz.smart_city.entity.ClearingRecord;
|
|
|
-import com.bz.smart_city.entity.Customer;
|
|
|
-import com.bz.smart_city.entity.Device;
|
|
|
-import com.bz.smart_city.entity.DeviceDataDim;
|
|
|
-import com.bz.smart_city.entity.JobCard;
|
|
|
-import com.bz.smart_city.entity.MeterReadRate;
|
|
|
-import com.bz.smart_city.entity.MeterReadRecord;
|
|
|
-import com.bz.smart_city.entity.MeterRecordStat;
|
|
|
-import com.bz.smart_city.entity.Site;
|
|
|
-import com.bz.smart_city.entity.WMeterType;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.bz.smart_city.commom.model.CommonQueryCondition;
|
|
|
import com.bz.smart_city.commom.model.ListObjectWrapper;
|
|
|
import com.bz.smart_city.commom.model.Pagination;
|
|
|
import com.bz.smart_city.commom.model.ResultStatus;
|
|
|
-import com.bz.smart_city.dao.BuildingMapper;
|
|
|
-import com.bz.smart_city.dao.DeviceDataDimMapper;
|
|
|
-import com.bz.smart_city.dao.DeviceMapper;
|
|
|
-import com.bz.smart_city.dao.MeterReadRateMapper;
|
|
|
-import com.bz.smart_city.dao.MeterReadRecordMapper;
|
|
|
-import com.bz.smart_city.dao.StatMeterReadRateByBuildingMapper;
|
|
|
-import com.bz.smart_city.dao.UserMapper;
|
|
|
-import com.bz.smart_city.dao.WMeterTypeMapper;
|
|
|
import com.bz.smart_city.service.CustomerService;
|
|
|
import com.bz.smart_city.service.MeterReadRecordService;
|
|
|
import com.bz.smart_city.service.UserService;
|
|
@@ -97,8 +89,22 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
@Resource
|
|
|
private StatMeterReadRateByBuildingMapper statMeterReadRateByBuildingMapper;
|
|
|
|
|
|
+ @Value("${service.domain}")
|
|
|
+ private String domain;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskMapper taskMapper;
|
|
|
+ @Autowired
|
|
|
+ private MessageService messageService;
|
|
|
+
|
|
|
@Resource
|
|
|
CustomerService customerService;
|
|
|
+ @Value("${spring.rabbitmq.exchange}")
|
|
|
+ private String exchange;
|
|
|
+ @Value("${spring.rabbitmq.general-task-queue}")
|
|
|
+ private String queue;
|
|
|
+ @Autowired
|
|
|
+ private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
@Override
|
|
|
public Pagination<MeterReadRecord> queryMeterReadRecord(MeterReadRecord param, int pageNum, int pageSize) {
|
|
@@ -696,8 +702,15 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
@Override
|
|
|
public Pagination<WaterConsumptionDto> getWaterConsumptionList(CommonQueryCondition condition, Integer pageNum, Integer pageSize) {
|
|
|
log.info("begin MeterReadRecordService getWaterConsumptionList, params = " + JSON.toJSONString(condition) + ", pageNum = " + pageNum + ", pageSize = " + pageSize);
|
|
|
- PageHelper.startPage(pageNum, pageSize);
|
|
|
- List<WaterConsumptionDto> result = meterReadRecordMapper.getList(condition);
|
|
|
+ List<WaterConsumptionDto> result = null;
|
|
|
+ if(condition.getEndDate()-condition.getStartDate() > 0){
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ result = meterReadRecordMapper.getList(condition);
|
|
|
+ }else {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ result = meterReadRecordMapper.getListDay(condition);
|
|
|
+ }
|
|
|
+
|
|
|
log.info("end MeterReadRecordService getWaterConsumptionList, result.size = "+result.size());
|
|
|
return new Pagination<>(result);
|
|
|
}
|
|
@@ -1079,4 +1092,160 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
}
|
|
|
return readRecord ;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getConsumptionExcel(CommonQueryCondition condition, HttpServletResponse httpServletResponse) {
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ String title = "用水量统计";
|
|
|
+
|
|
|
+ RabbitWaterConsumptionData data = new RabbitWaterConsumptionData();
|
|
|
+ data.setUserId(loginUser.getId());
|
|
|
+ data.setSiteId(loginUser.getSiteId());
|
|
|
+ data.setCustomerId(condition.getCustormerId());
|
|
|
+ data.setProvinces(condition.getProvinces());
|
|
|
+ data.setCities(condition.getCities());
|
|
|
+ data.setRegions(condition.getRegions());
|
|
|
+ data.setCommunities(condition.getCommunities());
|
|
|
+ data.setBuildingIds(condition.getBuildingIds());
|
|
|
+ data.setStartDate(condition.getStartDate());
|
|
|
+ data.setEndDate(condition.getEndDate());
|
|
|
+ data.setMinConsumption(condition.getBeginRate());
|
|
|
+ data.setMaxConsumption(condition.getEndRate());
|
|
|
+ data.setSortOrder(condition.getSortOrder());
|
|
|
+ data.setCustomerIds(condition.getCustomerIds());
|
|
|
+ data.setTitle(title);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
+ LocalDateTime date = LocalDateTime.now();
|
|
|
+ String fileName = title + "-" + date.format(f) + ".xls";
|
|
|
+
|
|
|
+ Task task = new Task();
|
|
|
+ task.setName(fileName);
|
|
|
+ task.setType(1);
|
|
|
+ task.setStatus(1);
|
|
|
+ task.setCreateDate(LocalDateTime.now());
|
|
|
+ task.setUpdateDate(LocalDateTime.now());
|
|
|
+ taskMapper.insertSelective(task);
|
|
|
+ data.setTaskId(task.getId());
|
|
|
+
|
|
|
+ RabbitParamData<RabbitWaterConsumptionData> rabbitParamData = new RabbitParamData<>();
|
|
|
+ rabbitParamData.setService("waterConsumptionExcel");
|
|
|
+ rabbitParamData.setData(data);
|
|
|
+
|
|
|
+
|
|
|
+ String message = JSON.toJSONString(rabbitParamData);
|
|
|
+
|
|
|
+ //设置当前线程lookupKey,内部由ThreadLocal实现
|
|
|
+ SimpleResourceHolder.bind(rabbitTemplate.getConnectionFactory(), "platform");
|
|
|
+ //业务操作会根据线程中的lookupKey从routeConnectionFactory的targetConnectionFactories中选择对应的connectionFactory
|
|
|
+ rabbitTemplate.convertAndSend(exchange,queue, message);
|
|
|
+ //操作完以后记得解绑。不影响线程的后序其他工厂操作
|
|
|
+ SimpleResourceHolder.unbind(rabbitTemplate.getConnectionFactory());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeWaterConsumptionExcel(RabbitWaterConsumptionData data) {
|
|
|
+
|
|
|
+ CommonQueryCondition condition = setConditionForQuery(data);
|
|
|
+ List<WaterConsumptionDto> list = null;
|
|
|
+ if(condition.getEndDate()-condition.getStartDate() > 0){
|
|
|
+ list = meterReadRecordMapper.getList(condition);
|
|
|
+ }else {
|
|
|
+ list = meterReadRecordMapper.getListDay(condition);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String title = "用水量统计";
|
|
|
+ String[] rowsName = new String[]{"序号", "水表电子号", "水表档案号", "设备型号", "客户", "小区", "建筑", "安装地址","用水量"};
|
|
|
+ List<Object[]> dataList = newArrayList();
|
|
|
+ Object[] objs = null;
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ WaterConsumptionDto dto = list.get(i);
|
|
|
+ objs = new Object[rowsName.length];
|
|
|
+ objs[0] = i;
|
|
|
+ objs[1] = dto.getMeterNo();
|
|
|
+ objs[2] = dto.getFileNo();
|
|
|
+ objs[3] = dto.getManufacturerName()+"/"+dto.getEquipmentType()+"/"+dto.getModel();
|
|
|
+ objs[4] = dto.getCustomer();
|
|
|
+ objs[5] = dto.getCommunity();
|
|
|
+ objs[6] = dto.getBuilding();
|
|
|
+ objs[7] = dto.getLocation();
|
|
|
+ objs[8] = dto.getWaterConsumption();
|
|
|
+ dataList.add(objs);
|
|
|
+ }
|
|
|
+ ExcelUtil excelUtil = new ExcelUtil(title, rowsName, dataList);
|
|
|
+ String filePath = getFilePath();
|
|
|
+ try {
|
|
|
+ excelUtil.download(filePath);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException(-900, "导出异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ Task taskTemp = taskMapper.findById(data.getTaskId());
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+ //生成下载文件
|
|
|
+ Task task = new Task();
|
|
|
+ task.setId(data.getTaskId());
|
|
|
+ task.setPath(filePath);
|
|
|
+ task.setUpdateDate(LocalDateTime.now());
|
|
|
+ taskMapper.updateByPrimaryKeySelective(task);
|
|
|
+
|
|
|
+ //生成消息
|
|
|
+ Message message = new Message();
|
|
|
+ message.setSiteId(data.getSiteId());
|
|
|
+ message.setUserId(data.getUserId());
|
|
|
+ message.setMessageType(2);
|
|
|
+ message.setMessageTitle(data.getTitle()+"-导出");
|
|
|
+ message.setMessageContent(taskTemp.getName()+"导出完成");
|
|
|
+ message.setMessageUrl(domain+"/api/file/task/download?objId="+data.getTaskId());
|
|
|
+ message.setObjId(data.getTaskId());
|
|
|
+ message.setRead(0);
|
|
|
+ messageService.insertSelective(message);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("Exception {},{}",e.getMessage(),e);
|
|
|
+ Message message = new Message();
|
|
|
+ message.setSiteId(data.getSiteId());
|
|
|
+ message.setUserId(data.getUserId());
|
|
|
+ message.setMessageType(2);
|
|
|
+ message.setMessageTitle(data.getTitle()+"-导出");
|
|
|
+ message.setMessageContent(taskTemp.getName()+"导出失败");
|
|
|
+ message.setObjId(data.getTaskId());
|
|
|
+ message.setRead(0);
|
|
|
+ messageService.insertSelective(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private CommonQueryCondition setConditionForQuery(RabbitWaterConsumptionData data) {
|
|
|
+ CommonQueryCondition condition = new CommonQueryCondition();
|
|
|
+ condition.setSiteId(data.getSiteId());
|
|
|
+ condition.setCustormerId(data.getCustomerId());
|
|
|
+ condition.setProvinces(data.getProvinces());
|
|
|
+ condition.setCities(data.getCities());
|
|
|
+ condition.setRegions(data.getRegions());
|
|
|
+ condition.setCommunities(data.getCommunities());
|
|
|
+ condition.setBuildingIds(data.getBuildingIds());
|
|
|
+ condition.setStartDate(data.getStartDate());
|
|
|
+ condition.setEndDate(data.getEndDate());
|
|
|
+ condition.setBeginRate(data.getMinConsumption());
|
|
|
+ condition.setEndRate(data.getMaxConsumption());
|
|
|
+ condition.setCustomerIds(data.getCustomerIds());
|
|
|
+ condition.setSortOrder(data.getSortOrder());
|
|
|
+ return condition;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Value("${files.path}")
|
|
|
+ private String filesPath;
|
|
|
+
|
|
|
+ protected String getFilePath() {
|
|
|
+ String name = Util.createUUIDId();
|
|
|
+ String fullPath = filesPath + "/file/" + name + ".xls";
|
|
|
+ return fullPath;
|
|
|
+ }
|
|
|
}
|