MrShi
2026-01-13 3a154bdb0a5aaa2c0ac3eac95a6ba747068bd454
server/visits/dmvisit_admin/src/main/java/com/doumee/cloud/web/cabinet/CabinetController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,222 @@
package com.doumee.cloud.web.cabinet;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.doumee.api.BaseController;
import com.doumee.config.annotation.LoginNoRequired;
import com.doumee.core.annotation.trace.Trace;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.utils.Constants;
import com.doumee.dao.business.JkVersionMapper;
import com.doumee.dao.business.dto.*;
import com.doumee.dao.business.model.InterfaceLog;
import com.doumee.dao.business.model.JkCabinetGrid;
import com.doumee.dao.business.model.JkInterfaceLog;
import com.doumee.dao.business.model.JkVersion;
import com.doumee.dao.business.vo.AdminCabinetVO;
import com.doumee.dao.business.vo.CabinetDetailVO;
import com.doumee.dao.business.vo.CabinetFaceVO;
import com.doumee.dao.business.vo.CabinetInfoVO;
import com.doumee.dao.web.response.DriverHomeVO;
import com.doumee.service.business.*;
import com.doumee.service.business.third.model.ApiResponse;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Rk
 * @create 2025/10/15 9:10
 */
@Api(tags = "【钥匙柜】钥匙柜业务")
@Trace(exclude = true)
@RestController
@RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX+"/web/cabinet")
@Slf4j
public class CabinetController extends BaseController {
    @Autowired
    private JkCabinetService jkCabinetService;
    @Autowired
    private JkCabinetGridService jkCabinetGridService;
    @Autowired
    private JkInterfaceLogService interfaceLogService;
    @Autowired
    private JkIccardService jkIccardService;
    @Autowired
    private JkVersionService jkVersionService;
    @LoginNoRequired
    @ApiOperation("获取钥匙柜APK最新版本")
    @GetMapping("/getLastVersion")
    public ApiResponse<JkVersion> getLastVersion () {
        JkVersion jkVersion = jkVersionService.getLastVersion();
        this.saveInterfaceLog(null, JSONObject.toJSONString(jkVersion),"getLastVersion","获取钥匙柜APK最新版本");
        return ApiResponse.success(jkVersion);
    }
    @LoginNoRequired
    @ApiOperation("获取钥匙柜基本信息 - å¸æœº")
    @GetMapping("/getCabinetInfoForDriver")
    public ApiResponse<CabinetInfoVO> getCabinetInfoForDriver (@RequestParam String code) {
        CabinetInfoVO cabinetInfoVO = jkCabinetService.getCabinetInfoForDriver(code);
        this.saveInterfaceLog(Constants.strToJson("code",code), JSONObject.toJSONString(cabinetInfoVO),"getCabinetInfoForDriver","获取钥匙柜基本信息 - å¸æœº");
        return ApiResponse.success(cabinetInfoVO);
    }
    @LoginNoRequired
    @ApiOperation("更新钥匙柜在线状态")
    @GetMapping("/updateRunStatusById")
    public ApiResponse updateRunStatusById (@RequestParam Integer id) {
        jkCabinetService.updateRunStatusById(id);
        this.saveInterfaceLog(Constants.strToJson("id",id.toString()), null,"updateRunStatusById","更新钥匙柜在线状态");
        return ApiResponse.success("更新成功");
    }
    @ApiOperation("获取可管理的钥匙柜列表 - ç®¡ç†å‘˜")
    @GetMapping("/getAdminCabinetInfo")
    public ApiResponse<List<AdminCabinetVO>> getAdminCabinetInfo (@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        List<AdminCabinetVO> list = jkCabinetService.getAdminCabinetInfo(getLoginUser(token));
        this.saveInterfaceLog(null, JSONArray.toJSONString(list),"getAdminCabinetInfo","获取可管理的钥匙柜列表 - ç®¡ç†å‘˜");
        return ApiResponse.success(list);
    }
    @ApiOperation("获取钥匙柜详情 - ç®¡ç†å‘˜")
    @GetMapping("/getCabinetDetail")
    public ApiResponse<CabinetDetailVO> getCabinetDetail (@RequestParam Integer cabinetId, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        CabinetDetailVO cabinetDetailVO = jkCabinetService.getCabinetDetail(cabinetId,getLoginUser(token));
        this.saveInterfaceLog(Constants.strToJson("cabinetId",cabinetId.toString()), JSONObject.toJSONString(cabinetDetailVO),"getCabinetDetail","获取钥匙柜详情 - ç®¡ç†å‘˜");
        return ApiResponse.success(cabinetDetailVO);
    }
    @ApiOperation("标记柜格故障 - ç®¡ç†å‘˜")
    @PostMapping("/markFault")
    public ApiResponse markFault(@RequestBody OptGridDTO dto, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        dto.setLoginUserInfo(getLoginUser(token));
        jkCabinetGridService.markFault(dto);
        this.saveInterfaceLog(JSONObject.toJSONString(dto), null,"markFault","标记柜格故障 - ç®¡ç†å‘˜");
        return ApiResponse.success("操作成功");
    }
    @ApiOperation("标记柜格正常 - ç®¡ç†å‘˜")
    @PostMapping("/cancelFault")
    public ApiResponse cancelFault(@RequestBody OptGridDTO dto, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        dto.setLoginUserInfo(getLoginUser(token));
        jkCabinetGridService.cancelFault(dto);
        this.saveInterfaceLog(JSONObject.toJSONString(dto), null,"cancelFault","标记柜格正常 - ç®¡ç†å‘˜");
        return ApiResponse.success("操作成功");
    }
    @ApiOperation("标记维修保养 - ç®¡ç†å‘˜")
    @PostMapping("/markRepair")
    public ApiResponse markRepair(@RequestBody OptGridDTO dto, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        dto.setLoginUserInfo(getLoginUser(token));
        jkCabinetGridService.markRepair(dto);
        this.saveInterfaceLog(JSONObject.toJSONString(dto), null,"markRepair","标记维修保养 - ç®¡ç†å‘˜");
        return ApiResponse.success("操作成功");
    }
    @LoginNoRequired
    @ApiOperation("关闭柜门")
    @PostMapping("/closeGrid")
    public ApiResponse closeGrid(@RequestBody CloseGridDTO dto) {
        jkCabinetGridService.closeGrid(dto);
        this.saveInterfaceLog(JSONObject.toJSONString(dto), null,"closeGrid","关闭柜门");
        return ApiResponse.success("操作成功");
    }
    @ApiOperation("批量开门 - ç®¡ç†å‘˜")
    @PostMapping("/batchOpenGridAdmin")
    public ApiResponse batchOpenGridAdmin(@RequestBody OptGridDTO dto, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        dto.setLoginUserInfo(getLoginUser(token));
        jkCabinetGridService.batchOpenGridAdmin(dto);
        this.saveInterfaceLog(JSONObject.toJSONString(dto), null,"batchOpenGridAdmin","批量开门 - ç®¡ç†å‘˜");
        return ApiResponse.success("操作成功");
    }
    @LoginNoRequired
    @ApiOperation("获取钥匙柜人脸数据")
    @GetMapping("/getCabinetFaceVO")
    public ApiResponse<CabinetFaceVO> getCabinetFaceVO(@RequestParam String code) {
        CabinetFaceVO cabinetFaceVO = jkCabinetService.getCabinetFaceVO(code);
        this.saveInterfaceLog(Constants.strToJson("code",code), JSONObject.toJSONString(cabinetFaceVO),"getCabinetFaceVO","获取钥匙柜人脸数据");
        return ApiResponse.success(cabinetFaceVO);
    }
    @LoginNoRequired
    @ApiOperation("获取可操作柜格 - å¸æœº")
    @PostMapping("/getDriverGrid")
    public ApiResponse<List<JkCabinetGrid>> getDriverGrid(@RequestBody GetDriverGridDTO dto) {
        List<JkCabinetGrid> jkCabinetGridList = jkCabinetGridService.getDriverGrid(dto);
        this.saveInterfaceLog(JSONObject.toJSONString(dto), JSONObject.toJSONString(jkCabinetGridList),"getDriverGrid","获取可操作柜格 - å¸æœº");
        return ApiResponse.success(jkCabinetGridList);
    }
    @LoginNoRequired
    @ApiOperation("开启柜格 - å¸æœº")
    @PostMapping("/openGridDriver")
    public ApiResponse openGridDriver(@RequestBody OpenGridDriverDTO dto) {
        jkCabinetGridService.openGridDriver(dto);
        this.saveInterfaceLog(JSONObject.toJSONString(dto), null,"openGridDriver","开启柜格 - å¸æœº");
        return ApiResponse.success("操作成功");
    }
    @LoginNoRequired
    @ApiOperation("获取IC卡用户主键 - å¸æœº")
    @PostMapping("/getMemberIdByCode")
    public ApiResponse<Integer> getMemberIdByCode(@RequestBody QueryUserByCodeDTO dto) {
        this.saveInterfaceLog(JSONObject.toJSONString(dto), null,"getMemberIdByCode","获取IC卡用户主键 - å¸æœº");
        return ApiResponse.success(jkIccardService.getMemberIdByCode(dto));
    }
    private void saveInterfaceLog(String s, String result,String url,String name) {
        JkInterfaceLog hkMonitoryLogDO=new JkInterfaceLog();
        hkMonitoryLogDO.setType(0);
        hkMonitoryLogDO.setCreateDate(new Date());
        hkMonitoryLogDO.setIsdeleted(0);
        hkMonitoryLogDO.setRequest(s);
        hkMonitoryLogDO.setRepose(result);
        hkMonitoryLogDO.setName("【钥匙柜】"+name);
        hkMonitoryLogDO.setUrl(url);
        interfaceLogService.create(hkMonitoryLogDO);
    }
    @LoginNoRequired
    @ApiOperation("酒精检测告警")
    @PostMapping("/alcoholTestAlarm")
    public ApiResponse alcoholTestAlarm(@RequestBody AlcoholTestAlarmDTO dto) {
        jkCabinetGridService.alcoholTestAlarm(dto);
        return ApiResponse.success("操作成功");
    }
    @LoginNoRequired
    @ApiOperation("柜格开门超时未关闭告警")
    @PostMapping("/timeOutUnCloseAlarm")
    public ApiResponse timeOutUnCloseAlarm(@RequestBody TimeOutCloseGridDTO dto) {
        jkCabinetGridService.timeOutUnCloseAlarm(dto);
        return ApiResponse.success("操作成功");
    }
}