ElectricBoxServiceImpl.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package com.welampiot.service.impl;
  2. import com.welampiot.common.BaseResult;
  3. import com.welampiot.common.InterfaceResultEnum;
  4. import com.welampiot.dao.ElectricBoxDao;
  5. import com.welampiot.dto.ElectricBoxDTO;
  6. import com.welampiot.dto.ElectricModuleDTO;
  7. import com.welampiot.service.AirSwitchInfoService;
  8. import com.welampiot.service.ElectricBoxService;
  9. import com.welampiot.service.ElectricModuleService;
  10. import com.welampiot.utils.ToolUtils;
  11. import com.welampiot.vo.ElectricBoxReturnVO;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import java.text.ParseException;
  15. import java.text.SimpleDateFormat;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * ClassName: ElectricBoxServiceImpl
  22. * Package: com.welampiot.service.impl
  23. * Description:
  24. *
  25. * @Author: zhj_Start
  26. * @Create: 2023/3/25 - 14:46
  27. * @Version: v1.0
  28. */
  29. @Service
  30. public class ElectricBoxServiceImpl implements ElectricBoxService {
  31. @Autowired
  32. private ElectricBoxDao electricBoxDao;
  33. @Autowired
  34. protected ElectricModuleService electricModuleService;
  35. @Autowired
  36. private ToolUtils toolUtils;
  37. @Autowired
  38. private AirSwitchInfoService airSwitchInfoService;
  39. @Override
  40. public ElectricBoxReturnVO getElectricBoxListBySectionId(ElectricBoxDTO dto) {
  41. ElectricBoxReturnVO electricBoxReturnVO = new ElectricBoxReturnVO();
  42. electricBoxReturnVO.setTotal(electricBoxDao.getTotalByStatus(dto));
  43. electricBoxReturnVO.setDevTotal(electricBoxDao.getTotalByStatus(dto));
  44. electricBoxReturnVO.setOnlineTotal(electricBoxDao.getOnlineTotalByStatus(dto));
  45. electricBoxReturnVO.setOfflineTotal(electricBoxDao.getOfflineTotalByStatus(dto));
  46. List<ElectricBoxDTO> electricBoxList = electricBoxDao.getElectricBoxListBySectionId(dto);
  47. List<ElectricBoxDTO> electricBoxDTOS = new ArrayList<>();
  48. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  49. electricBoxList.forEach(electricBoxDTO ->{
  50. if (electricBoxDTO.getInstallDate() != null && !electricBoxDTO.getInstallDate().equals("")){
  51. try {
  52. electricBoxDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(electricBoxDTO.getInstallDate())));
  53. } catch (ParseException e) {
  54. throw new RuntimeException(e);
  55. }
  56. }else {
  57. electricBoxDTO.setInstallDate("");
  58. }
  59. if (electricBoxDTO.getExpirationDate() != null && !electricBoxDTO.getExpirationDate().equals("")){
  60. try {
  61. electricBoxDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(electricBoxDTO.getExpirationDate())));
  62. } catch (ParseException e) {
  63. throw new RuntimeException(e);
  64. }
  65. }else {
  66. electricBoxDTO.setExpirationDate("");
  67. }
  68. if (electricBoxDTO.getOnlineCount() != null && electricBoxDTO.getOnlineCount() > 0){
  69. electricBoxDTO.setOnline(1);
  70. }else {
  71. electricBoxDTO.setOnline(0);
  72. }
  73. List<ElectricModuleDTO> listByBoxId = electricModuleService.getListByBoxId(electricBoxDTO.getId());
  74. List<Map> maps = new ArrayList<>();
  75. for (ElectricModuleDTO e :listByBoxId) {
  76. Map<Object, Object> objectObjectMap = new HashMap<>();
  77. objectObjectMap.put("id",e.getId());
  78. objectObjectMap.put("boxId",e.getBoxId());
  79. objectObjectMap.put("address",e.getAddress());
  80. objectObjectMap.put("type",e.getType());
  81. maps.add(objectObjectMap);
  82. }
  83. electricBoxDTO.setModuleList(maps);
  84. if (electricBoxDTO.getDevType() == null) electricBoxDTO.setDevType(0);
  85. electricBoxDTOS.add(electricBoxDTO);
  86. });
  87. electricBoxReturnVO.setList(electricBoxDTOS);
  88. return electricBoxReturnVO;
  89. }
  90. @Override
  91. public Integer getTotalByStatus(ElectricBoxDTO dto) {
  92. return electricBoxDao.getTotalByStatus(dto);
  93. }
  94. @Override
  95. public Integer getOnlineTotalByStatus(ElectricBoxDTO dto) {
  96. return electricBoxDao.getOnlineTotalByStatus(dto);
  97. }
  98. @Override
  99. public Integer getOfflineTotalByStatus(ElectricBoxDTO dto) {
  100. return electricBoxDao.getOfflineTotalByStatus(dto);
  101. }
  102. @Override
  103. public BaseResult add(ElectricBoxDTO dto) {
  104. if (dto.getAreaId() == 0 || dto.getAreaId() == null) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,dto.getVersion());
  105. if (dto.getSectionId() == 0 || dto.getSectionId() == null) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,dto.getVersion());
  106. if (dto.getName() == null || dto.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_BOX_NAME_ERROR,dto.getVersion());
  107. ElectricBoxDTO electricBoxDTO = new ElectricBoxDTO();
  108. electricBoxDTO.setSectionId(dto.getSectionId());
  109. electricBoxDTO.setName(dto.getName());
  110. if (electricBoxDao.checkData(electricBoxDTO).intValue() > 0) return toolUtils.response(InterfaceResultEnum.ELECTRIC_BOX_NAME_UNIQUE_ERROR,dto.getVersion());
  111. if (dto.getModuleList() == null || dto.getModuleList().isEmpty()) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ERROR,dto.getVersion());
  112. electricBoxDao.add(dto);
  113. List<Map> moduleList = dto.getModuleList();
  114. for (Map map:moduleList) {
  115. ElectricModuleDTO electricModuleDTO = new ElectricModuleDTO();
  116. if (map.containsKey("id")) electricModuleDTO.setId(Integer.parseInt((String) map.get("id")));
  117. electricModuleDTO.setBoxId(dto.getId());
  118. if (map.containsKey("address") && map.get("address").toString().length() > 0) {
  119. electricModuleDTO.setAddress((String) map.get("address"));
  120. }else {
  121. return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ADDRESS_ERROR,dto.getVersion());
  122. }
  123. electricModuleDTO.setType(Integer.parseInt((String) map.get("type")));
  124. if (electricModuleDTO.getId() != null && electricModuleDTO.getId() > 0){
  125. electricModuleService.add(electricModuleDTO);
  126. }else {
  127. electricModuleService.update(electricModuleDTO);
  128. }
  129. }
  130. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion());
  131. }
  132. @Override
  133. public BaseResult update(ElectricBoxDTO dto) {
  134. if (dto.getAreaId() == 0 || dto.getAreaId() == null) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,dto.getVersion());
  135. if (dto.getSectionId() == 0 || dto.getSectionId() == null) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,dto.getVersion());
  136. if (dto.getName() == null || dto.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_BOX_NAME_ERROR,dto.getVersion());
  137. ElectricBoxDTO electricBoxDTO = new ElectricBoxDTO();
  138. electricBoxDTO.setSectionId(dto.getSectionId());
  139. electricBoxDTO.setName(dto.getName());
  140. electricBoxDTO.setId(dto.getId());
  141. if (electricBoxDao.checkData(electricBoxDTO).intValue() > 0) return toolUtils.response(InterfaceResultEnum.ELECTRIC_BOX_NAME_UNIQUE_ERROR,dto.getVersion());
  142. if (dto.getModuleList() == null || dto.getModuleList().isEmpty()) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ERROR,dto.getVersion());
  143. electricBoxDao.add(dto);
  144. List<Map> moduleList = dto.getModuleList();
  145. for (Map map:moduleList) {
  146. ElectricModuleDTO electricModuleDTO = new ElectricModuleDTO();
  147. if (map.containsKey("id")) electricModuleDTO.setId(Integer.parseInt((String) map.get("id")));
  148. electricModuleDTO.setBoxId(dto.getId());
  149. if (map.containsKey("address") && map.get("address").toString().length() > 0) {
  150. electricModuleDTO.setAddress((String) map.get("address"));
  151. }else {
  152. return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ADDRESS_ERROR,dto.getVersion());
  153. }
  154. electricModuleDTO.setType(Integer.parseInt((String) map.get("type")));
  155. if (electricModuleDTO.getId() != null && electricModuleDTO.getId() > 0){
  156. electricModuleService.add(electricModuleDTO);
  157. }else {
  158. electricModuleService.update(electricModuleDTO);
  159. }
  160. }
  161. electricBoxDao.update(dto);
  162. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion());
  163. }
  164. @Override
  165. public Integer checkData(ElectricBoxDTO dto) {
  166. return electricBoxDao.checkData(dto);
  167. }
  168. @Override
  169. public Integer delete(ElectricBoxDTO dto) {
  170. airSwitchInfoService.deleteByBoxId(dto.getId());
  171. electricModuleService.deleteByBoxId(dto.getId());
  172. return electricBoxDao.delete(dto);
  173. }
  174. @Override
  175. public ElectricBoxDTO getDetailsById(Integer id) {
  176. return electricBoxDao.getDetailsById(id);
  177. }
  178. @Override
  179. public void changeElectricBoxLocationById(ElectricBoxDTO dto) {
  180. electricBoxDao.changeElectricBoxLocationById(dto);
  181. }
  182. }