123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- package com.fdkankan.manage.controller.inner;
- import cn.hutool.extra.servlet.ServletUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.manage.common.CameraTypeEnum;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.common.ResultData;
- import com.fdkankan.manage.controller.BaseController;
- import com.fdkankan.manage.entity.*;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.service.*;
- import com.fdkankan.manage.util.RsaUtils;
- import com.fdkankan.manage.vo.request.CameraInStoreParam;
- import com.fdkankan.manage.vo.request.SceneParam;
- import com.fdkankan.manage.vo.request.UserParam;
- import com.fdkankan.manage.vo.response.UserAuthSceneVo;
- import com.fdkankan.manage.vo.response.UserShareSceneVo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.stream.Collectors;
- @RestController
- @RequestMapping("/service/manage/inner")
- public class InnerAPIController extends BaseController {
- @Autowired
- IJyUserService jyUserService;
- @Autowired
- IUserService userService;
- @Autowired
- IJySceneUserAuthService jySceneUserAuthService;
- @Autowired
- IScenePlusService scenePlusService;
- @Autowired
- IJyUserShareService jyUserShareService;
- @Autowired
- IJySceneAuthService jySceneAuthService;
- @PostMapping("/getByRyId")
- public ResultData getByRyId(@RequestBody UserParam param){
- if(StringUtils.isBlank(param.getRyNo()) && StringUtils.isBlank(param.getRyId())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- JyUser jyuser = null;
- if(StringUtils.isNotBlank(param.getRyId())){
- jyuser = jyUserService.getByRyId(param.getRyId());
- if(jyuser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- }
- if(StringUtils.isNotBlank(param.getRyNo())){
- jyuser = jyUserService.getByRyNo(param.getRyNo());
- if(jyuser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- }
- return ResultData.ok(jyuser);
- }
- @PostMapping("/getByRyNo")
- public ResultData getByRyNo(@RequestBody UserParam param){
- return ResultData.ok(jyUserService.getByRyNo(param.getRyNo()));
- }
- @PostMapping("/updateStatus")
- public ResultData updateStatus(@RequestBody UserParam userParam){
- userService.updateStatus(userParam);
- return ResultData.ok();
- }
- @PostMapping("/addUcenterUser")
- public ResultData addUcenterUser(@RequestBody UserParam param){
- userService.addUcenterUser(param);
- return ResultData.ok();
- }
- @PostMapping("/delUcenterUser")
- public ResultData delUcenterUser(@RequestBody UserParam param){
- userService.delUcenterUser(param);
- return ResultData.ok();
- }
- @PostMapping("/addAuth")
- public ResultData addAuth(@RequestBody JySceneUserAuth param){
- param.setCanDel(1);
- jySceneUserAuthService.addAuth(param);
- return ResultData.ok();
- }
- @PostMapping("/setAuthType")
- public ResultData setAuthType(@RequestBody JySceneUserAuth param){
- jySceneUserAuthService.setAuthType(param);
- return ResultData.ok();
- }
- @PostMapping("/delAuth")
- public ResultData delAuth(@RequestBody JySceneUserAuth param){
- if(StringUtils.isBlank(param.getNum()) || param.getCaseId() == null || (StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo()))){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(StringUtils.isNotBlank(param.getNum()) && param.getCaseId() != null){
- param.setCaseId(null);
- }
- JySceneUserAuth db = null;
- if(StringUtils.isNotBlank(param.getRyId()) && StringUtils.isNotBlank(param.getNum())){
- db = jySceneUserAuthService.getByNumAndRyId(param.getNum(),param.getRyId());
- }
- if(StringUtils.isNotBlank(param.getRyNo()) && StringUtils.isNotBlank(param.getNum())){
- db = jySceneUserAuthService.getByNumAndRyNo(param.getNum(),param.getRyNo());
- }
- if(StringUtils.isNotBlank(param.getRyId()) && param.getCaseId() != null){
- db = jySceneUserAuthService.getByCaseIdAndRyId(param.getCaseId(),param.getRyId());
- }
- if(StringUtils.isNotBlank(param.getRyNo()) && param.getCaseId() != null){
- db = jySceneUserAuthService.getByCaseIdAndRyNo(param.getCaseId(),param.getRyNo());
- }
- if(db == null){
- throw new BusinessException(ResultCode.DEL_AUTH_ERROR);
- }
- jySceneUserAuthService.delAuth(db);
- return ResultData.ok();
- }
- @PostMapping("/checkAuthOther")
- public ResultData checkAuthOther(@RequestBody JySceneUserAuth param){
- return ResultData.ok(jySceneUserAuthService.checkAuthOther(param));
- }
- @GetMapping("/checkNumAuth/{num}")
- public ResultData checkNumAuth(@PathVariable String num){
- String clientIP = ServletUtil.getClientIP(request);
- return ResultData.ok( jySceneUserAuthService.checkNumAuth(num,getToken(),clientIP,getUserName(),getPassword()));
- }
- @PostMapping("/checkNumAuth")
- public ResultData checkNumAuth(@RequestBody JSONObject object){
- String clientIP = ServletUtil.getClientIP(request);
- return ResultData.ok( jySceneUserAuthService.checkNumAuth(object.getString("num"),getToken(),clientIP,object.getString("userName"),object.getString("password")));
- }
- @PostMapping("/getAuthType")
- public ResultData getAuthType(@RequestBody SceneParam param){
- return ResultData.ok(jySceneUserAuthService.getAuthType(param));
- }
- @PostMapping("/getAuthList")
- public ResultData getAuthList(@RequestBody SceneParam param){
- if(StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(StringUtils.isBlank(param.getNum()) || param.getCaseId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(StringUtils.isNotBlank(param.getNum()) && param.getCaseId() != null){
- param.setCaseId(null);
- }
- JySceneAuth jySceneAuth = null;
- if(StringUtils.isNotBlank(param.getNum())){
- jySceneAuth = jySceneAuthService.getByNum(param.getNum());
- }
- if(param.getCaseId() != null){
- jySceneAuth = jySceneAuthService.getByCaseId(param.getCaseId());
- }
- if(jySceneAuth == null){
- return ResultData.ok(PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize()));
- }
- param.setAuthType(jySceneAuth.getAuthType());
- return ResultData.ok(jySceneUserAuthService.getAuthList(param));
- }
- @PostMapping("/getSceneList")
- public ResultData getSceneList(@RequestBody SceneParam param){
- if(StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- JyUser jyUser = null;
- if(StringUtils.isNotBlank(param.getRyId()) ){
- jyUser = jyUserService.getByRyId(param.getRyId());
- if(jyUser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- }
- if(StringUtils.isNotBlank(param.getRyNo()) ){
- jyUser = jyUserService.getByRyNo(param.getRyNo());
- if(jyUser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- }
- if(jyUser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- UserShareParam shareParam = new UserShareParam();
- shareParam.setJyUserId(Math.toIntExact(jyUser.getUserId()));
- shareParam.setPageNum(param.getPageNum());
- shareParam.setPageSize(param.getPageSize());
- Page<UserShareSceneVo> page= jyUserShareService.sceneList(shareParam);
- List<String> numList = page.getRecords().stream().map(UserShareSceneVo::getNum).collect(Collectors.toList());
- HashMap<String, JySceneAuth> authMap = jySceneAuthService.getByNumList(numList);
- HashMap<String, List<JySceneUserAuth>> userSceneAuthMap = jySceneUserAuthService.getByNumList(numList);
- HashSet<Integer> userIds = new HashSet<>();
- for (String key : userSceneAuthMap.keySet()) {
- List<JySceneUserAuth> userAuths = userSceneAuthMap.get(key);
- for (JySceneUserAuth userAuth : userAuths) {
- userIds.add(userAuth.getJyUserId());
- }
- }
- HashMap<Integer, JyUser> userHashMap = jyUserService.getByIds(new ArrayList<>(userIds));
- for (UserShareSceneVo record : page.getRecords()) {
- JySceneAuth jySceneAuth = authMap.get(record.getNum());
- if(jySceneAuth != null){
- record.setAuthType(jySceneAuth.getAuthType());
- List<JySceneUserAuth> userAuths = userSceneAuthMap.get(record.getNum()+"_"+jySceneAuth.getAuthType());
- if(userAuths != null && !userAuths.isEmpty()){
- for (JySceneUserAuth userAuth : userAuths) {
- JyUser jyUser1 = userHashMap.get(userAuth.getJyUserId());
- if(jyUser1 != null){
- userAuth.setRyId(jyUser1.getRyId());
- userAuth.setRyNo(jyUser1.getRyNo());
- userAuth.setRyNickName(jyUser1.getRyNickName());
- }
- }
- record.setAuthList(userAuths);
- }
- }
- }
- return ResultData.ok(PageInfo.PageInfo(page));
- }
- @PostMapping("/getAuthSceneList")
- public ResultData getAuthSceneList(@RequestBody SceneParam param){
- if(StringUtils.isBlank(param.getRyId()) && StringUtils.isBlank(param.getRyNo())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- JyUser jyUser = null;
- if(StringUtils.isNotBlank(param.getRyId()) ){
- jyUser = jyUserService.getByRyId(param.getRyId());
- if(jyUser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- }
- if(StringUtils.isNotBlank(param.getRyNo()) ){
- jyUser = jyUserService.getByRyNo(param.getRyNo());
- if(jyUser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- }
- if(jyUser == null){
- throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
- }
- UserShareParam shareParam = new UserShareParam();
- shareParam.setPageNum(param.getPageNum());
- shareParam.setPageSize(param.getPageSize());
- shareParam.setJyUserId(jyUser.getId());
- Page<UserAuthSceneVo> page= jyUserShareService.sceneAuthVoList(shareParam);
- List<String> numList = page.getRecords().stream().map(UserAuthSceneVo::getNum).collect(Collectors.toList());
- HashMap<String, List<JySceneUserAuth>> map = jySceneUserAuthService.getByNumList(numList,jyUser.getId());
- for (UserAuthSceneVo record : page.getRecords()) {
- List<JySceneUserAuth> userAuths = map.get(record.getNum()+"_"+record.getAuthType());
- if(userAuths != null && !userAuths.isEmpty()){
- for (JySceneUserAuth userAuth : userAuths) {
- JyUser jyUser1 = jyUserService.getById(userAuth.getJyUserId());
- if(jyUser1 != null){
- userAuth.setRyId(jyUser1.getRyId());
- userAuth.setRyNo(jyUser1.getRyNo());
- userAuth.setRyNickName(jyUser1.getRyNickName());
- }
- }
- record.setAuthList(userAuths);
- }
- }
- return ResultData.ok(PageInfo.PageInfo(page));
- }
- @Autowired
- IDownService downService;
- /**
- * 检查下载
- * num 场景码
- */
- @GetMapping("/checkDownLoad")
- public ResultData checkDownLoad(@RequestParam(required = false) String num,
- @RequestParam(required = false,defaultValue = "0") Integer isObj){
- return ResultData.ok(downService.checkDownLoad(num,isObj));
- }
- /**
- * 下载场景
- * num 场景码
- */
- @GetMapping("/downScene")
- public ResultData downScene(@RequestParam(required = false) String num,
- @RequestParam(required = false,defaultValue = "0") Integer isObj){
- return ResultData.ok(downService.down(num,isObj));
- }
- /**
- * 下载场景进度条
- * num 场景码
- */
- @GetMapping("/downloadProcess")
- public ResultData downloadProcess(@RequestParam(required = false) String num,
- @RequestParam(required = false,defaultValue = "0") Integer isObj){
- return ResultData.ok(downService.downloadProcess(num,isObj));
- }
- @Autowired
- ICameraService cameraService;
- @PostMapping(value = "/cameraInStore")
- public ResultData cameraInStore(@RequestBody CameraInStoreParam param){
- if(StringUtils.isBlank(param.getSnCode()) || param.getCameraType() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Camera camera = cameraService.getBySnCode(param.getSnCode());
- if(camera !=null){
- return ResultData.ok(camera);
- }
- String wifiPre = CameraTypeEnum.getCameraPrefixByType(param.getCameraType());
- cameraService.in(wifiPre + param.getSnCode().toUpperCase());
- camera = cameraService.getBySnCode(param.getSnCode());
- return ResultData.ok(camera);
- }
- }
|