SimService.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package com.ruoyi.sim.service.impl;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Objects;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.common.utils.DateUtils;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.scheduling.annotation.Async;
  10. import org.springframework.stereotype.Service;
  11. import com.ruoyi.sim.mapper.SimMapper;
  12. import com.ruoyi.sim.domain.Sim;
  13. /**
  14. * 模拟器Service业务层处理
  15. *
  16. * @author tom
  17. * @date 2024-12-13
  18. */
  19. @Service
  20. public class SimService {
  21. @Autowired
  22. private SimMapper simMapper;
  23. /**
  24. * 查询模拟器
  25. *
  26. * @param simId 模拟器主键
  27. * @return 模拟器
  28. */
  29. public Sim selectSimBySimId(Long simId) {
  30. return simMapper.selectSimBySimId(simId);
  31. }
  32. /**
  33. * 查询模拟器列表
  34. *
  35. * @param sim 模拟器
  36. * @return 模拟器
  37. */
  38. public List<Sim> selectSimList(Sim sim) {
  39. return simMapper.selectSimList(sim);
  40. }
  41. /**
  42. * 新增模拟器
  43. *
  44. * @param sim 模拟器
  45. * @return 结果
  46. */
  47. public int insertSim(Sim sim) {
  48. sim.setCreateTime(DateUtils.getNowDate());
  49. return simMapper.insertSim(sim);
  50. }
  51. /**
  52. * 修改模拟器
  53. *
  54. * @param sim 模拟器
  55. * @return 结果
  56. */
  57. public int updateSim(Sim sim) {
  58. sim.setUpdateTime(DateUtils.getNowDate());
  59. return simMapper.updateSim(sim);
  60. }
  61. /**
  62. * 批量删除模拟器
  63. *
  64. * @param simIds 需要删除的模拟器主键
  65. * @return 结果
  66. */
  67. public int deleteSimBySimIds(Long[] simIds) {
  68. return simMapper.deleteSimBySimIds(simIds);
  69. }
  70. /**
  71. * 删除模拟器信息
  72. *
  73. * @param simId 模拟器主键
  74. * @return 结果
  75. */
  76. public int deleteSimBySimId(Long simId) {
  77. return simMapper.deleteSimBySimId(simId);
  78. }
  79. // -------------------------------- tom add --------------------------------
  80. public boolean existBySimId(final Long simId) {
  81. if (simId == null) {
  82. return false;
  83. }
  84. if (simId == 0) {
  85. return false;
  86. }
  87. Sim s = selectSimBySimId(simId);
  88. if (s == null) {
  89. return false;
  90. }
  91. return true;
  92. }
  93. public boolean existBySimNum(final String simNum) {
  94. if (StringUtils.isEmpty(simNum)) {
  95. return false;
  96. }
  97. Sim s = uniqueBySimNum(simNum);
  98. if (s == null) {
  99. return false;
  100. }
  101. return true;
  102. }
  103. public Sim uniqueBySimNum(final String simNum) {
  104. Sim q = new Sim();
  105. q.setSimNum(simNum);
  106. List<Sim> simList = simMapper.selectSimList(q);
  107. if (!simList.isEmpty()) {
  108. return simList.get(0);
  109. }
  110. return null;
  111. }
  112. public List<Sim> listAll() {
  113. return selectSimList(new Sim());
  114. }
  115. /**
  116. * 获取所有没有被禁用的模拟器列表
  117. *
  118. * @return
  119. */
  120. public AjaxResult listAllEnableAj() {
  121. return AjaxResult.success(listAllEnable());
  122. }
  123. public List<Sim> listAllEnable() {
  124. List<Sim> list = new ArrayList<>();
  125. listAll()
  126. .stream()
  127. .filter(Objects::nonNull)
  128. .filter(s -> !Sim.State.DISABLE.equals(s.getSimState()))
  129. .forEach(list::add);
  130. return list;
  131. }
  132. public List<Sim> listAllOnline() {
  133. List<Sim> list = new ArrayList<>();
  134. listAll()
  135. .stream()
  136. .filter(Objects::nonNull)
  137. .filter(s -> Sim.State.ONLINE.equals(s.getSimState()))
  138. .forEach(list::add);
  139. return list;
  140. }
  141. public List<Sim> listAllEnableBySimType(String simType) {
  142. List<Sim> list = new ArrayList<>();
  143. listAll()
  144. .stream()
  145. .filter(Objects::nonNull)
  146. .filter(s -> !Sim.State.DISABLE.equals(s.getSimState()))
  147. .filter(s -> s.getSimType().equals(simType))
  148. .forEach(list::add);
  149. return list;
  150. }
  151. public int updateAllEnableState(String simState) {
  152. List<Sim> list = listAllEnable();
  153. for (Sim sim : list) {
  154. sim.setSimState(simState);
  155. simMapper.updateSim(sim);
  156. }
  157. return list.size();
  158. }
  159. public List<String> listSimTypes() {
  160. return Sim.TYPE_SET.stream().toList();
  161. }
  162. public boolean checkSimTypeOk(String simType) {
  163. return Sim.TYPE_SET.contains(simType);
  164. }
  165. public boolean checkState(String simState) {
  166. return Sim.STATE_SET.contains(simState);
  167. }
  168. public int updateSimStateBySimId(Long simId, String simState) {
  169. // check
  170. if (checkState(simState)) {
  171. }
  172. //
  173. Sim q = selectSimBySimId(simId);
  174. if (Objects.isNull(q)) {
  175. return 0;
  176. }
  177. q.setSimState(simState);
  178. return updateSim(q);
  179. }
  180. public boolean isSimStateBySimId(Long simId, String simState) {
  181. // check
  182. if (checkState(simState)) {
  183. }
  184. Sim q = selectSimBySimId(simId);
  185. if (Objects.isNull(q)) {
  186. return false;
  187. }
  188. return (q.getSimState().equals(simState));
  189. }
  190. public boolean isSimDisable(Long simId) {
  191. return isSimStateBySimId(simId, Sim.State.DISABLE);
  192. }
  193. public int updateSimSnBySimId(Long simId, String simSn) {
  194. // check
  195. if (StringUtils.isEmpty(simSn)) {
  196. return 0;
  197. }
  198. //
  199. Sim q = selectSimBySimId(simId);
  200. if (Objects.isNull(q)) {
  201. return 0;
  202. }
  203. q.setSimSn(simSn);
  204. q.setUpdateTime(DateUtils.getNowDate());
  205. return updateSim(q);
  206. }
  207. public int updateAllEnableStateInit() {
  208. List<Sim> list = simMapper.selectSimList(new Sim());
  209. int count = 0;
  210. for (Sim o : list) {
  211. if (o == null) {
  212. continue;
  213. }
  214. if (!Objects.equals(o.getSimState(), Sim.State.DISABLE)) {
  215. o.setSimState(Sim.State.ENABLE_INIT);
  216. }
  217. updateSim(o);
  218. count = count + 1;
  219. }
  220. return count;
  221. }
  222. @Async("tp-log")
  223. public void updateLastSentTime(Sim s) {
  224. if (s == null) {
  225. return;
  226. }
  227. s.setLastSentTime(DateUtils.getNowDate());
  228. updateSim(s);
  229. }
  230. @Async("tp-log")
  231. public void updateLastReceivedTime(Sim s) {
  232. if (s == null) {
  233. return;
  234. }
  235. s.setLastReceivedTime(DateUtils.getNowDate());
  236. updateSim(s);
  237. }
  238. }