DeviceServiceImpl.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package com.zoniot.ccrc.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.github.pagehelper.PageHelper;
  4. import com.zoniot.ccrc.commom.exception.ServiceException;
  5. import com.zoniot.ccrc.commom.model.DeviceData;
  6. import com.zoniot.ccrc.commom.model.Pagination;
  7. import com.zoniot.ccrc.commom.utils.ExcelUtil;
  8. import com.zoniot.ccrc.commom.utils.UserUtil;
  9. import com.zoniot.ccrc.dao.OrganizationMapper;
  10. import com.zoniot.ccrc.dto.BuildingSelectDto;
  11. import com.zoniot.ccrc.dto.BuildingSelectInfoDto;
  12. import com.zoniot.ccrc.dto.DeviceDto;
  13. import com.zoniot.ccrc.dto.LoginUser;
  14. import com.zoniot.ccrc.service.BuildingService;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import javax.annotation.Resource;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.text.SimpleDateFormat;
  21. import java.util.List;
  22. import com.zoniot.ccrc.entity.Device;
  23. import com.zoniot.ccrc.dao.DeviceMapper;
  24. import com.zoniot.ccrc.service.DeviceService;
  25. import static com.google.common.collect.Lists.newArrayList;
  26. @Slf4j
  27. @Service
  28. public class DeviceServiceImpl implements DeviceService{
  29. @Resource
  30. private DeviceMapper deviceMapper;
  31. @Autowired
  32. private BuildingService buildingService;
  33. @Resource
  34. private OrganizationMapper organizationMapper;
  35. @Override
  36. public int insertSelective(Device record) {
  37. return deviceMapper.insertSelective(record);
  38. }
  39. @Override
  40. public int updateByPrimaryKeySelective(Device record) {
  41. return deviceMapper.updateByPrimaryKeySelective(record);
  42. }
  43. @Override
  44. public int updateBatch(List<Device> list) {
  45. return deviceMapper.updateBatch(list);
  46. }
  47. @Override
  48. public int batchInsert(List<Device> list) {
  49. return deviceMapper.batchInsert(list);
  50. }
  51. @Override
  52. public Pagination<DeviceDto> pageList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, int pageNum, int pageSize) {
  53. LoginUser loginUser = UserUtil.getCurrentUser();
  54. Integer userId = null;
  55. List<Integer> communityIds = null;
  56. if (loginUser.getRoleType() !=null && loginUser.getRoleType() == 4) userId = loginUser.getId();
  57. if (orgId != null) communityIds = organizationMapper.findCommunityIds(orgId);
  58. PageHelper.startPage(pageNum,pageSize);
  59. List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),userId,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,communityIds,sortColumn,sortOrder);
  60. return new Pagination<>(list);
  61. }
  62. @Override
  63. public void getDeviceListExcel(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, HttpServletResponse httpServletResponse) {
  64. String title = "设备列表";
  65. LoginUser loginUser = UserUtil.getCurrentUser();
  66. Integer userId = null;
  67. List<Integer> communityIds = null;
  68. if (loginUser.getRoleType() !=null && loginUser.getRoleType() == 4) userId = loginUser.getId();
  69. if (orgId != null) communityIds = organizationMapper.findCommunityIds(orgId);
  70. List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),userId,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,communityIds,sortColumn,sortOrder);
  71. //水表档案号、水表电子号、设备状态、当前读数、机构、客户编号、客户名称、手机号、标签、建筑、安装地址、网格员
  72. SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  73. //DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  74. String[] rowsName = new String[]{"序号", "水表档案号", "水表电子号", "设备状态", "当前读数", "机构", "客户编号", "客户名称", "手机号", "标签","建筑","安装地址","网格员"};
  75. List<Object[]> dataList = newArrayList();
  76. Object[] objs = null;
  77. for (int i = 0; i < list.size(); i++) {
  78. DeviceDto data = list.get(i);
  79. objs = new Object[rowsName.length];
  80. objs[0] = i;
  81. objs[1] = data.getFileNo();
  82. objs[2] = data.getMeterNo();
  83. objs[3] = getDeviceStatusName(data.getDeviceStatus());
  84. objs[4] = data.getMeterReading();
  85. objs[5] = data.getOrgName();
  86. objs[6] = data.getCustomerNo();
  87. objs[7] = data.getCustomerName();
  88. objs[8] = data.getCustomerPhone();
  89. objs[9] = data.getLabel();
  90. objs[10] = data.getBuildingName();
  91. objs[11] = data.getLocDesc();
  92. objs[12] = data.getUsername();
  93. dataList.add(objs);
  94. }
  95. ExcelUtil excelUtil = new ExcelUtil(title, rowsName, dataList);
  96. try {
  97. excelUtil.export(httpServletResponse);
  98. } catch (Exception e) {
  99. throw new ServiceException(-900, "导出异常");
  100. }
  101. }
  102. private String getDeviceStatusName(Integer deviceStatus){
  103. //1:正常 2:故障 3:无 4: 预警 5:未启用
  104. if (deviceStatus == 1) return "正常";
  105. if (deviceStatus == 2) return "故障";
  106. if (deviceStatus == 4) return "预警";
  107. if (deviceStatus == 5) return "未启用";
  108. return "";
  109. }
  110. @Override
  111. public List<BuildingSelectDto> deviceAreaList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus) {
  112. LoginUser loginUser = UserUtil.getCurrentUser();
  113. Integer userId = null;
  114. List<Integer> communityIds = null;
  115. if (loginUser.getRoleType() !=null && loginUser.getRoleType() == 4) userId = loginUser.getId();
  116. if (orgId != null) communityIds = organizationMapper.findCommunityIds(orgId);
  117. List<BuildingSelectInfoDto> list = deviceMapper.deviceAreaList(loginUser.getSiteId(),userId,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,communityIds);
  118. return buildingService.areaList(list);
  119. }
  120. @Override
  121. public DeviceDto deviceDetailV2(Long deviceId) {
  122. return deviceMapper.findDeviceDetail(deviceId);
  123. }
  124. @Override
  125. public void syncDevice(DeviceData deviceData) {
  126. Integer siteId = organizationMapper.findSiteId(deviceData.getCustomerId());
  127. //Integer siteId = 1;
  128. Device device = new Device();
  129. device.setId(deviceData.getId());
  130. device.setDeviceNo(deviceData.getDeviceNo());
  131. device.setMeterNo(deviceData.getMeterNo());
  132. device.setFileNo(deviceData.getFileNo());
  133. device.setSealNo(deviceData.getSealNo());
  134. device.setSiteId(siteId);
  135. device.setSysId(deviceData.getSysId());
  136. device.setDeviceTypeId(deviceData.getDeviceTypeId());
  137. device.setManufacturerId(deviceData.getManufacturerId());
  138. device.setBuildingId(deviceData.getBuildingId());
  139. device.setCommunityId(deviceData.getCommunityId());
  140. device.setLocDesc(deviceData.getLocDesc());
  141. device.setMeterReading(deviceData.getMeterReading());
  142. device.setValveStatus(deviceData.getValveStatus());
  143. device.setDeviceStatus(deviceData.getDeviceStatus());
  144. device.setLastReceiveTime(deviceData.getLastReceiveTime());
  145. device.setStatus(deviceData.getStatus());
  146. device.setCreateBy("system");
  147. device.setDateCreate(deviceData.getDateCreate());
  148. device.setUpdateBy("system");
  149. device.setDateUpdate(deviceData.getDateUpdate());
  150. log.info("syncDevice device {}", JSON.toJSONString(device));
  151. deviceMapper.replaceSelective(device);
  152. }
  153. }