|
@@ -0,0 +1,128 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.ElectricityMeterDTO;
|
|
|
+import com.welampiot.dto.ElectricityMeterLogDTO;
|
|
|
+import com.welampiot.service.ElectricityMeterLogService;
|
|
|
+import com.welampiot.service.ElectricityMeterService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.BaseVO;
|
|
|
+import com.welampiot.vo.ElectricityMeterLogVO;
|
|
|
+import com.welampiot.vo.ElectricityMeterVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/electricityMeter")
|
|
|
+public class ElectricityMeterController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ElectricityMeterService electricityMeterService;
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+ @Autowired
|
|
|
+ private ElectricityMeterLogService electricityMeterLogService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备列表
|
|
|
+ */
|
|
|
+ @RequestMapping("/getList")
|
|
|
+ private BaseResult<?> getList(BaseVO baseVO) {
|
|
|
+ Integer version = baseVO.getVersion();
|
|
|
+ baseVO.setPageAndCount(baseVO.getPage(), baseVO.getCount());
|
|
|
+ List<Integer> sectionList = getSectionList(baseVO.getUsername());
|
|
|
+ baseVO.setSectionList(sectionList);
|
|
|
+ List<ElectricityMeterDTO> list = electricityMeterService.getElectricityMeterListByBaseVO(baseVO);
|
|
|
+ Integer total = electricityMeterService.getEleMeterTotalByBaseVO(baseVO);
|
|
|
+ ElectricityMeterVO electricityMeterVO = new ElectricityMeterVO();
|
|
|
+ electricityMeterVO.setTotal(total);
|
|
|
+ electricityMeterVO.setList(list);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, electricityMeterVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除设备
|
|
|
+ */
|
|
|
+ @RequestMapping("/del")
|
|
|
+ private BaseResult<?> del(BaseVO baseVO) {
|
|
|
+ Integer version = baseVO.getVersion();
|
|
|
+ if (baseVO.getId() == null || baseVO.getId() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ electricityMeterService.delEleMeterDataById(baseVO.getId());
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日志列表
|
|
|
+ */
|
|
|
+ @RequestMapping("/logList")
|
|
|
+ private BaseResult<?> logList(BaseVO baseVO) {
|
|
|
+ Integer version = baseVO.getVersion();
|
|
|
+ if (baseVO.getId() == null || baseVO.getId() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ baseVO.setPageAndCount(baseVO.getPage(), baseVO.getCount());
|
|
|
+
|
|
|
+ if (baseVO.getDownload() != null && baseVO.getDownload() == 1) {
|
|
|
+ baseVO.setPage(null);
|
|
|
+ baseVO.setCount(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ElectricityMeterLogDTO> logList = electricityMeterLogService.getEleMeterLogByBaseVO(baseVO);
|
|
|
+ ElectricityMeterLogVO electricityMeterLogVO = new ElectricityMeterLogVO();
|
|
|
+ if (baseVO.getDownload() != null && baseVO.getDownload() == 1) {
|
|
|
+ String path = ElectricityMeterLogDTO.outEleMeterLog(logList, version);
|
|
|
+ electricityMeterLogVO.setPath(path);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,electricityMeterLogVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer total = electricityMeterLogService.getEleMeterLogTotalById(baseVO.getId());
|
|
|
+ electricityMeterLogVO.setTotal(total);
|
|
|
+ electricityMeterLogVO.setList(logList);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, electricityMeterLogVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑设备
|
|
|
+ */
|
|
|
+ @RequestMapping("/save")
|
|
|
+ private BaseResult<?> save(ElectricityMeterVO electricityMeterVO) {
|
|
|
+ Integer version = electricityMeterVO.getVersion();
|
|
|
+
|
|
|
+ if (electricityMeterVO.getName() == null || electricityMeterVO.getName().isEmpty())
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_DEV_NAME_ERROR, version);
|
|
|
+ if (electricityMeterVO.getAddress() == null || electricityMeterVO.getAddress().isEmpty())
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_ADDRESS_ERROR, version);
|
|
|
+ if (electricityMeterVO.getAreaId() == null || electricityMeterVO.getAreaId() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR, version);
|
|
|
+ if (electricityMeterVO.getSectionId() == null || electricityMeterVO.getSectionId() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR, version);
|
|
|
+ if (electricityMeterVO.getType() == null)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_DEV_TYPE_ERROR, version);
|
|
|
+
|
|
|
+ ElectricityMeterDTO meterDTO = new ElectricityMeterDTO();
|
|
|
+ meterDTO.setAddress(electricityMeterVO.getAddress());
|
|
|
+ if (electricityMeterVO.getId() == null || electricityMeterVO.getId() == 0) {
|
|
|
+ if (electricityMeterService.checkEleMeterData(meterDTO) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_ADDRESS_UNIQUE_ERROR, version);
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(electricityMeterVO, meterDTO);
|
|
|
+ electricityMeterService.addEleMeterData(meterDTO);
|
|
|
+ } else {
|
|
|
+ meterDTO.setId(electricityMeterVO.getId());
|
|
|
+ if (electricityMeterService.checkEleMeterData(meterDTO) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_ADDRESS_UNIQUE_ERROR, version);
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(electricityMeterVO, meterDTO);
|
|
|
+ electricityMeterService.updateEleMeterData(meterDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
|
|
|
+ }
|
|
|
+}
|