package com.unisinsight.project.controller; import cn.hutool.json.JSONUtil; import com.unisinsight.project.entity.req.DeviceReq; import com.unisinsight.project.entity.req.DeviceUserReq; import com.unisinsight.project.entity.req.LoginReq; import com.unisinsight.project.exception.BaseErrorCode; import com.unisinsight.project.exception.Result; import com.unisinsight.project.service.ClientService; import com.unisinsight.project.service.DeviceService; import com.unisinsight.project.service.DeviceUserMappingService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Objects; /** * @description: * @author: rdpnr_puzhi * @create: 2025/08/08 */ @Slf4j @RestController @RequestMapping("/api/nex/v1/client") @Api(tags = "客户端类") public class ClientController { @Resource private ClientService clientService; @Resource private DeviceUserMappingService deviceUserMappingService; @Resource private DeviceService deviceService; @ApiOperation(value = "用户认证") @PostMapping("/authentication") public Result authentication(@RequestBody LoginReq loginReq) { if (Objects.isNull(loginReq)) { return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR); } log.info("用户认证请求参数为:{}", JSONUtil.toJsonStr(loginReq)); DeviceReq deviceReq = new DeviceReq(); deviceReq.setDeviceId(loginReq.getDeviceId()); deviceReq.setDeviceName("默认终端"); deviceReq.setDeviceGroupId(3L); deviceReq.setDeviceGroupName("默认终端分组"); return deviceService.insert(deviceReq); } @ApiOperation(value = "用户登录") @PostMapping("/login") public Result loginUser(@RequestBody LoginReq loginReq) { if (Objects.isNull(loginReq)) { return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR); } log.info("用户登录请求参数为:{}", JSONUtil.toJsonStr(loginReq)); DeviceUserReq deviceUserReq = new DeviceUserReq(); deviceUserReq.setDeviceId(loginReq.getDeviceId()); deviceUserReq.setUserName(loginReq.getUsername()); deviceUserReq.setPassword(loginReq.getPassword()); //todo 后面再调 // Result result = deviceUserMappingService.loginUser(deviceUserReq); HashMap hashMap = new HashMap<>(); hashMap.put("token", "123456"); return Result.successResult(hashMap); } @ApiOperation(value = "获取镜像列表") @PostMapping("/getImageList") public Result getImageList(@RequestBody LoginReq loginReq) { if (Objects.isNull(loginReq)) { return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR); } log.info("获取镜像列表请求参数为:{}", JSONUtil.toJsonStr(loginReq)); // Result imageList = clientService.getImageList(loginReq.getDeviceId(), loginReq.getToken()); List> hashMaps = new ArrayList<>(); HashMap map = new HashMap<>(); map.put("name", "ubuntu-20.04.6-desktop-amd64.iso"); map.put("torrent", "https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-desktop-amd64.iso.torrent"); hashMaps.add(map); HashMap map1 = new HashMap<>(); map1.put("name", "uos_nbd_20250806.qcow2"); map1.put("torrent", "http://10.100.51.86:8114/api/vdi/file/down/win10_v2307_uefi_demo.vhdx.torrent"); hashMaps.add(map1); HashMap map2 = new HashMap<>(); map2.put("name", "win10_v2307_uefi_demo.vhdx"); map2.put("torrent", "http://10.100.51.86:8114/api/vdi/file/down/win10_v2307_uefi_demo.vhdx.torrent"); hashMaps.add(map2); HashMap hashMap = new HashMap<>(); hashMap.put("list", hashMaps); return Result.successResult(hashMap); } @ApiOperation(value = "版本更新") @PostMapping("/update") public Result getImageUpdate(@RequestBody LoginReq loginReq) { if (Objects.isNull(loginReq)) { return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR); } log.info("版本更新请求参数为:{}", JSONUtil.toJsonStr(loginReq)); HashMap hashMap = new HashMap<>(); hashMap.put("version", "1.0.0"); hashMap.put("url", "https://intent-bathhouse.name"); return Result.successResult(hashMap); } }