InnerAPIController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. package com.fdkankan.manage.controller.inner;
  2. import cn.hutool.extra.servlet.ServletUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.fdkankan.manage.common.CameraTypeEnum;
  6. import com.fdkankan.manage.common.PageInfo;
  7. import com.fdkankan.manage.common.ResultCode;
  8. import com.fdkankan.manage.common.ResultData;
  9. import com.fdkankan.manage.controller.BaseController;
  10. import com.fdkankan.manage.entity.*;
  11. import com.fdkankan.manage.exception.BusinessException;
  12. import com.fdkankan.manage.service.*;
  13. import com.fdkankan.manage.util.RsaUtils;
  14. import com.fdkankan.manage.vo.request.CameraInStoreParam;
  15. import com.fdkankan.manage.vo.request.SceneParam;
  16. import com.fdkankan.manage.vo.request.UserParam;
  17. import com.fdkankan.manage.vo.response.UserAuthSceneVo;
  18. import com.fdkankan.manage.vo.response.UserShareSceneVo;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.HashSet;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. @RestController
  28. @RequestMapping("/service/manage/inner")
  29. public class InnerAPIController extends BaseController {
  30. @Autowired
  31. IJyUserService jyUserService;
  32. @Autowired
  33. IUserService userService;
  34. @Autowired
  35. IJySceneUserAuthService jySceneUserAuthService;
  36. @Autowired
  37. IScenePlusService scenePlusService;
  38. @Autowired
  39. IJyUserShareService jyUserShareService;
  40. @Autowired
  41. IJySceneAuthService jySceneAuthService;
  42. @PostMapping("/getByRyId")
  43. public ResultData getByRyId(@RequestBody UserParam param){
  44. if(StringUtils.isBlank(param.getRyNo()) && StringUtils.isBlank(param.getRyId())){
  45. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  46. }
  47. JyUser jyuser = null;
  48. if(StringUtils.isNotBlank(param.getRyId())){
  49. jyuser = jyUserService.getByRyId(param.getRyId());
  50. if(jyuser == null){
  51. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  52. }
  53. }
  54. if(StringUtils.isNotBlank(param.getRyNo())){
  55. jyuser = jyUserService.getByRyNo(param.getRyNo());
  56. if(jyuser == null){
  57. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  58. }
  59. }
  60. return ResultData.ok(jyuser);
  61. }
  62. @PostMapping("/getByRyNo")
  63. public ResultData getByRyNo(@RequestBody UserParam param){
  64. return ResultData.ok(jyUserService.getByRyNo(param.getRyNo()));
  65. }
  66. @PostMapping("/updateStatus")
  67. public ResultData updateStatus(@RequestBody UserParam userParam){
  68. userService.updateStatus(userParam);
  69. return ResultData.ok();
  70. }
  71. @PostMapping("/addUcenterUser")
  72. public ResultData addUcenterUser(@RequestBody UserParam param){
  73. userService.addUcenterUser(param);
  74. return ResultData.ok();
  75. }
  76. @PostMapping("/delUcenterUser")
  77. public ResultData delUcenterUser(@RequestBody UserParam param){
  78. userService.delUcenterUser(param);
  79. return ResultData.ok();
  80. }
  81. @PostMapping("/addAuth")
  82. public ResultData addAuth(@RequestBody JySceneUserAuth param){
  83. param.setCanDel(1);
  84. jySceneUserAuthService.addAuth(param);
  85. return ResultData.ok();
  86. }
  87. @PostMapping("/setAuthType")
  88. public ResultData setAuthType(@RequestBody JySceneUserAuth param){
  89. jySceneUserAuthService.setAuthType(param);
  90. return ResultData.ok();
  91. }
  92. @PostMapping("/delAuth")
  93. public ResultData delAuth(@RequestBody JySceneUserAuth param){
  94. if(StringUtils.isBlank(param.getNum()) || param.getCaseId() == null || (StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo()))){
  95. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  96. }
  97. if(StringUtils.isNotBlank(param.getNum()) && param.getCaseId() != null){
  98. param.setCaseId(null);
  99. }
  100. JySceneUserAuth db = null;
  101. if(StringUtils.isNotBlank(param.getRyId()) && StringUtils.isNotBlank(param.getNum())){
  102. db = jySceneUserAuthService.getByNumAndRyId(param.getNum(),param.getRyId());
  103. }
  104. if(StringUtils.isNotBlank(param.getRyNo()) && StringUtils.isNotBlank(param.getNum())){
  105. db = jySceneUserAuthService.getByNumAndRyNo(param.getNum(),param.getRyNo());
  106. }
  107. if(StringUtils.isNotBlank(param.getRyId()) && param.getCaseId() != null){
  108. db = jySceneUserAuthService.getByCaseIdAndRyId(param.getCaseId(),param.getRyId());
  109. }
  110. if(StringUtils.isNotBlank(param.getRyNo()) && param.getCaseId() != null){
  111. db = jySceneUserAuthService.getByCaseIdAndRyNo(param.getCaseId(),param.getRyNo());
  112. }
  113. if(db == null){
  114. throw new BusinessException(ResultCode.DEL_AUTH_ERROR);
  115. }
  116. jySceneUserAuthService.delAuth(db);
  117. return ResultData.ok();
  118. }
  119. @PostMapping("/checkAuthOther")
  120. public ResultData checkAuthOther(@RequestBody JySceneUserAuth param){
  121. return ResultData.ok(jySceneUserAuthService.checkAuthOther(param));
  122. }
  123. @GetMapping("/checkNumAuth/{num}")
  124. public ResultData checkNumAuth(@PathVariable String num){
  125. String clientIP = ServletUtil.getClientIP(request);
  126. return ResultData.ok( jySceneUserAuthService.checkNumAuth(num,getToken(),clientIP,getUserName(),getPassword()));
  127. }
  128. @PostMapping("/checkNumAuth")
  129. public ResultData checkNumAuth(@RequestBody JSONObject object){
  130. String clientIP = ServletUtil.getClientIP(request);
  131. return ResultData.ok( jySceneUserAuthService.checkNumAuth(object.getString("num"),getToken(),clientIP,object.getString("userName"),object.getString("password")));
  132. }
  133. @PostMapping("/getAuthType")
  134. public ResultData getAuthType(@RequestBody SceneParam param){
  135. return ResultData.ok(jySceneUserAuthService.getAuthType(param));
  136. }
  137. @PostMapping("/getAuthList")
  138. public ResultData getAuthList(@RequestBody SceneParam param){
  139. if(StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo())){
  140. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  141. }
  142. if(StringUtils.isBlank(param.getNum()) || param.getCaseId() == null){
  143. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  144. }
  145. if(StringUtils.isNotBlank(param.getNum()) && param.getCaseId() != null){
  146. param.setCaseId(null);
  147. }
  148. JySceneAuth jySceneAuth = null;
  149. if(StringUtils.isNotBlank(param.getNum())){
  150. jySceneAuth = jySceneAuthService.getByNum(param.getNum());
  151. }
  152. if(param.getCaseId() != null){
  153. jySceneAuth = jySceneAuthService.getByCaseId(param.getCaseId());
  154. }
  155. if(jySceneAuth == null){
  156. return ResultData.ok(PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize()));
  157. }
  158. param.setAuthType(jySceneAuth.getAuthType());
  159. return ResultData.ok(jySceneUserAuthService.getAuthList(param));
  160. }
  161. @PostMapping("/getSceneList")
  162. public ResultData getSceneList(@RequestBody SceneParam param){
  163. if(StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo())){
  164. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  165. }
  166. JyUser jyUser = null;
  167. if(StringUtils.isNotBlank(param.getRyId()) ){
  168. jyUser = jyUserService.getByRyId(param.getRyId());
  169. if(jyUser == null){
  170. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  171. }
  172. }
  173. if(StringUtils.isNotBlank(param.getRyNo()) ){
  174. jyUser = jyUserService.getByRyNo(param.getRyNo());
  175. if(jyUser == null){
  176. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  177. }
  178. }
  179. if(jyUser == null){
  180. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  181. }
  182. UserShareParam shareParam = new UserShareParam();
  183. shareParam.setJyUserId(Math.toIntExact(jyUser.getUserId()));
  184. shareParam.setPageNum(param.getPageNum());
  185. shareParam.setPageSize(param.getPageSize());
  186. Page<UserShareSceneVo> page= jyUserShareService.sceneList(shareParam);
  187. List<String> numList = page.getRecords().stream().map(UserShareSceneVo::getNum).collect(Collectors.toList());
  188. HashMap<String, JySceneAuth> authMap = jySceneAuthService.getByNumList(numList);
  189. HashMap<String, List<JySceneUserAuth>> userSceneAuthMap = jySceneUserAuthService.getByNumList(numList);
  190. HashSet<Integer> userIds = new HashSet<>();
  191. for (String key : userSceneAuthMap.keySet()) {
  192. List<JySceneUserAuth> userAuths = userSceneAuthMap.get(key);
  193. for (JySceneUserAuth userAuth : userAuths) {
  194. userIds.add(userAuth.getJyUserId());
  195. }
  196. }
  197. HashMap<Integer, JyUser> userHashMap = jyUserService.getByIds(new ArrayList<>(userIds));
  198. for (UserShareSceneVo record : page.getRecords()) {
  199. JySceneAuth jySceneAuth = authMap.get(record.getNum());
  200. if(jySceneAuth != null){
  201. record.setAuthType(jySceneAuth.getAuthType());
  202. List<JySceneUserAuth> userAuths = userSceneAuthMap.get(record.getNum()+"_"+jySceneAuth.getAuthType());
  203. if(userAuths != null && !userAuths.isEmpty()){
  204. for (JySceneUserAuth userAuth : userAuths) {
  205. JyUser jyUser1 = userHashMap.get(userAuth.getJyUserId());
  206. if(jyUser1 != null){
  207. userAuth.setRyId(jyUser1.getRyId());
  208. userAuth.setRyNo(jyUser1.getRyNo());
  209. userAuth.setRyNickName(jyUser1.getRyNickName());
  210. }
  211. }
  212. record.setAuthList(userAuths);
  213. }
  214. }
  215. }
  216. return ResultData.ok(PageInfo.PageInfo(page));
  217. }
  218. @PostMapping("/getAuthSceneList")
  219. public ResultData getAuthSceneList(@RequestBody SceneParam param){
  220. if(StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo())){
  221. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  222. }
  223. JyUser jyUser = null;
  224. if(StringUtils.isNotBlank(param.getRyId()) ){
  225. jyUser = jyUserService.getByRyId(param.getRyId());
  226. if(jyUser == null){
  227. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  228. }
  229. }
  230. if(StringUtils.isNotBlank(param.getRyNo()) ){
  231. jyUser = jyUserService.getByRyNo(param.getRyNo());
  232. if(jyUser == null){
  233. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  234. }
  235. }
  236. if(jyUser == null){
  237. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  238. }
  239. UserShareParam shareParam = new UserShareParam();
  240. shareParam.setPageNum(param.getPageNum());
  241. shareParam.setPageSize(param.getPageSize());
  242. shareParam.setJyUserId(jyUser.getId());
  243. Page<UserAuthSceneVo> page= jyUserShareService.sceneAuthVoList(shareParam);
  244. List<String> numList = page.getRecords().stream().map(UserAuthSceneVo::getNum).collect(Collectors.toList());
  245. HashMap<String, List<JySceneUserAuth>> map = jySceneUserAuthService.getByNumList(numList,jyUser.getId());
  246. for (UserAuthSceneVo record : page.getRecords()) {
  247. List<JySceneUserAuth> userAuths = map.get(record.getNum()+"_"+record.getAuthType());
  248. if(userAuths != null && !userAuths.isEmpty()){
  249. for (JySceneUserAuth userAuth : userAuths) {
  250. JyUser jyUser1 = jyUserService.getById(userAuth.getJyUserId());
  251. if(jyUser1 != null){
  252. userAuth.setRyId(jyUser1.getRyId());
  253. userAuth.setRyNo(jyUser1.getRyNo());
  254. userAuth.setRyNickName(jyUser1.getRyNickName());
  255. }
  256. }
  257. record.setAuthList(userAuths);
  258. }
  259. }
  260. return ResultData.ok(PageInfo.PageInfo(page));
  261. }
  262. @Autowired
  263. IDownService downService;
  264. /**
  265. * 检查下载
  266. * num 场景码
  267. */
  268. @GetMapping("/checkDownLoad")
  269. public ResultData checkDownLoad(@RequestParam(required = false) String num,
  270. @RequestParam(required = false,defaultValue = "0") Integer isObj){
  271. return ResultData.ok(downService.checkDownLoad(num,isObj));
  272. }
  273. /**
  274. * 下载场景
  275. * num 场景码
  276. */
  277. @GetMapping("/downScene")
  278. public ResultData downScene(@RequestParam(required = false) String num,
  279. @RequestParam(required = false,defaultValue = "0") Integer isObj){
  280. return ResultData.ok(downService.down(num,isObj));
  281. }
  282. /**
  283. * 下载场景进度条
  284. * num 场景码
  285. */
  286. @GetMapping("/downloadProcess")
  287. public ResultData downloadProcess(@RequestParam(required = false) String num,
  288. @RequestParam(required = false,defaultValue = "0") Integer isObj){
  289. return ResultData.ok(downService.downloadProcess(num,isObj));
  290. }
  291. @Autowired
  292. ICameraService cameraService;
  293. @PostMapping(value = "/cameraInStore")
  294. public ResultData cameraInStore(@RequestBody CameraInStoreParam param){
  295. if(StringUtils.isBlank(param.getSnCode()) || param.getCameraType() == null){
  296. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  297. }
  298. Camera camera = cameraService.getBySnCode(param.getSnCode());
  299. if(camera !=null){
  300. return ResultData.ok(camera);
  301. }
  302. String wifiPre = CameraTypeEnum.getCameraPrefixByType(param.getCameraType());
  303. cameraService.in(wifiPre + param.getSnCode().toUpperCase());
  304. camera = cameraService.getBySnCode(param.getSnCode());
  305. return ResultData.ok(camera);
  306. }
  307. }