|
@@ -0,0 +1,326 @@
|
|
|
|
|
+package com.fs.qw.controller;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.fs.common.annotation.Log;
|
|
|
|
|
+import com.fs.common.core.controller.BaseController;
|
|
|
|
|
+import com.fs.common.core.domain.AjaxResult;
|
|
|
|
|
+import com.fs.common.core.page.TableDataInfo;
|
|
|
|
|
+import com.fs.common.enums.BusinessType;
|
|
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
|
|
+import com.fs.common.utils.poi.ExcelUtil;
|
|
|
|
|
+import com.fs.qw.domain.IpadAllocationDetails;
|
|
|
|
|
+import com.fs.qw.domain.IpadAllocationRecords;
|
|
|
|
|
+import com.fs.qw.domain.QwIpadServer;
|
|
|
|
|
+import com.fs.qw.mapper.IpadAllocationRecordsMapper;
|
|
|
|
|
+import com.fs.qw.param.ServerParam;
|
|
|
|
|
+import com.fs.qw.service.IIpadAllocationRecordsService;
|
|
|
|
|
+import com.fs.qw.service.IQwIpadServerService;
|
|
|
|
|
+import com.fs.qw.utils.HMACAuth;
|
|
|
|
|
+import com.fs.qw.vo.IpadAllocationRecordsVO;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 分配记录Controller
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author fs
|
|
|
|
|
+ * @date 2025-11-20
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/qw/records")
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class IpadAllocationRecordsController extends BaseController {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIpadAllocationRecordsService ipadAllocationRecordsService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IQwIpadServerService serverService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IpadAllocationRecordsMapper ipadAllocationRecordsMapper;
|
|
|
|
|
+ @Value("${ipad.url}")
|
|
|
|
|
+ private String ipadServerUrl;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询分配记录列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('shop:records:list')")
|
|
|
|
|
+ @GetMapping("/list")
|
|
|
|
|
+ public TableDataInfo list(IpadAllocationRecords ipadAllocationRecords) {
|
|
|
|
|
+ startPage();
|
|
|
|
|
+ List<IpadAllocationRecords> list = ipadAllocationRecordsService.selectIpadAllocationRecordsList(ipadAllocationRecords);
|
|
|
|
|
+ return getDataTable(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导出分配记录列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('shop:records:export')")
|
|
|
|
|
+ @Log(title = "分配记录", businessType = BusinessType.EXPORT)
|
|
|
|
|
+ @GetMapping("/export")
|
|
|
|
|
+ public AjaxResult export(IpadAllocationRecords ipadAllocationRecords) {
|
|
|
|
|
+ List<IpadAllocationRecords> list = ipadAllocationRecordsService.selectIpadAllocationRecordsList(ipadAllocationRecords);
|
|
|
|
|
+ ExcelUtil<IpadAllocationRecords> util = new ExcelUtil<IpadAllocationRecords>(IpadAllocationRecords.class);
|
|
|
|
|
+ return util.exportExcel(list, "分配记录数据");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取分配记录详细信息
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('shop:records:query')")
|
|
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id) {
|
|
|
|
|
+ return AjaxResult.success(ipadAllocationRecordsService.selectIpadAllocationRecordsById(id));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增分配记录
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('shop:records:add')")
|
|
|
|
|
+ @Log(title = "分配记录", businessType = BusinessType.INSERT)
|
|
|
|
|
+ @PostMapping
|
|
|
|
|
+ public AjaxResult add(@RequestBody IpadAllocationRecords ipadAllocationRecords) {
|
|
|
|
|
+ return toAjax(ipadAllocationRecordsService.insertIpadAllocationRecords(ipadAllocationRecords));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改分配记录
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('shop:records:edit')")
|
|
|
|
|
+ @Log(title = "分配记录", businessType = BusinessType.UPDATE)
|
|
|
|
|
+ @PutMapping
|
|
|
|
|
+ public AjaxResult edit(@RequestBody IpadAllocationRecords ipadAllocationRecords) {
|
|
|
|
|
+ return toAjax(ipadAllocationRecordsService.updateIpadAllocationRecords(ipadAllocationRecords));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除分配记录
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('shop:records:remove')")
|
|
|
|
|
+ @Log(title = "分配记录", businessType = BusinessType.DELETE)
|
|
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
|
|
+ return toAjax(ipadAllocationRecordsService.deleteIpadAllocationRecordsByIds(ids));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //根据记录id查询他的服务器详情
|
|
|
|
|
+ @GetMapping("/server/{id}")
|
|
|
|
|
+ public AjaxResult getServerInfo(@PathVariable("id") Long id) {
|
|
|
|
|
+ IpadAllocationRecords ipadAllocationRecords = ipadAllocationRecordsService.selectIpadAllocationRecordsById(id);
|
|
|
|
|
+ if (ipadAllocationRecords == null) {
|
|
|
|
|
+ return AjaxResult.error("记录不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<IpadAllocationDetails> detailsList = JSON.parseArray(ipadAllocationRecords.getServerJson(), IpadAllocationDetails.class);
|
|
|
|
|
+ return AjaxResult.success(detailsList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${ipad.companyId:13}")
|
|
|
|
|
+ private Long companyId;
|
|
|
|
|
+ //发起申请ipad服务器
|
|
|
|
|
+ @GetMapping("/apply")
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public AjaxResult apply(Integer applyCount,String area) throws Exception {
|
|
|
|
|
+ //校验count是否为正整数
|
|
|
|
|
+ if (applyCount == null || applyCount <= 0) {
|
|
|
|
|
+ return AjaxResult.error("申请数量必须为正整数");
|
|
|
|
|
+ }
|
|
|
|
|
+ //校验area是否为空
|
|
|
|
|
+ if (area == null || area.isEmpty()) {
|
|
|
|
|
+ return AjaxResult.error("区域不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //插入数据库申请表
|
|
|
|
|
+ IpadAllocationRecords ipadAllocationRecords = new IpadAllocationRecords();
|
|
|
|
|
+ ipadAllocationRecords.setCompanyId(13L);
|
|
|
|
|
+ ipadAllocationRecords.setApplyQuantity(applyCount);
|
|
|
|
|
+ ipadAllocationRecords.setSubmitTime(LocalDateTime.now());
|
|
|
|
|
+ ipadAllocationRecords.setRegion(area);
|
|
|
|
|
+ ipadAllocationRecordsMapper.insert(ipadAllocationRecords);
|
|
|
|
|
+ //发起http请求
|
|
|
|
|
+ //调用ipad服务器申请接口
|
|
|
|
|
+ HashMap<Object, Object> param = new HashMap<>();
|
|
|
|
|
+ param.put("allocationId", ipadAllocationRecords.getId());//携带id过去,以后查询结果
|
|
|
|
|
+ param.put("companyId", companyId);//公司id自己去配置文件改自己公司的id去腕表找
|
|
|
|
|
+ param.put("region", area);//区域
|
|
|
|
|
+ param.put("applyQuantity", applyCount);
|
|
|
|
|
+ String paramJson = JSON.toJSONString(param);
|
|
|
|
|
+ HttpRequest post = HttpUtil.createPost(ipadServerUrl + "/ipad/records/addRecords");
|
|
|
|
|
+ log.info("发起请求,申请参数:{},url:{}", paramJson, ipadServerUrl + "/ipad/records/addRecords");
|
|
|
|
|
+ post.body(paramJson);
|
|
|
|
|
+ post.header("Authorization", HMACAuth.generateToken());
|
|
|
|
|
+ //发起请求
|
|
|
|
|
+ String result = post.execute().body();
|
|
|
|
|
+ log.info("发起ipad服务器申请,申请数量:{},申请id:{},申请结果:{}", applyCount, ipadAllocationRecords.getId(), result);
|
|
|
|
|
+ //code不为200,回滚数据库
|
|
|
|
|
+ AjaxResult response = JSON.parseObject(result, AjaxResult.class);
|
|
|
|
|
+ if (response == null || (Integer) response.get("code") != 200) {
|
|
|
|
|
+ ipadAllocationRecordsMapper.deleteById(ipadAllocationRecords.getId());
|
|
|
|
|
+ throw new Exception("申请失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ return AjaxResult.success("申请成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //批量更新分配记录状态
|
|
|
|
|
+ @PostMapping("/batchUpdate")
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public AjaxResult batchUpdate(@RequestBody Long[] ids) throws Exception {
|
|
|
|
|
+ //校验ids是否为空
|
|
|
|
|
+ if (ids == null || ids.length == 0) {
|
|
|
|
|
+ return AjaxResult.error("ids不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ //发起http请求
|
|
|
|
|
+ //调用ipad服务器更新接口
|
|
|
|
|
+ HashMap<Object, Object> param = new HashMap<>();
|
|
|
|
|
+ param.put("ids", ids);
|
|
|
|
|
+ String paramJson = JSON.toJSONString(param);
|
|
|
|
|
+ HttpRequest post = HttpUtil.createPost(ipadServerUrl + "/ipad/records/updateRecords");
|
|
|
|
|
+ post.body(paramJson);
|
|
|
|
|
+ post.header("Authorization", HMACAuth.generateToken());
|
|
|
|
|
+ //发起请求
|
|
|
|
|
+ String result = post.execute().body();
|
|
|
|
|
+
|
|
|
|
|
+ log.info("发起ipad服务器更新状态,更新数量:{},拉取结果:{}", ids.length, result);
|
|
|
|
|
+
|
|
|
|
|
+ //解析返回的JSON结果
|
|
|
|
|
+ AjaxResult response = JSON.parseObject(result, AjaxResult.class);
|
|
|
|
|
+
|
|
|
|
|
+ //首先判断code是否为200
|
|
|
|
|
+ if (response != null && (Integer) response.get("code") == 200) {
|
|
|
|
|
+ //获取data字段
|
|
|
|
|
+ Object data = response.get("data");
|
|
|
|
|
+
|
|
|
|
|
+ //将data转换为List<IpadAllocationRecordsVO>
|
|
|
|
|
+ List<IpadAllocationRecordsVO> recordsList = JSON.parseArray(JSON.toJSONString(data), IpadAllocationRecordsVO.class);
|
|
|
|
|
+
|
|
|
|
|
+ for (IpadAllocationRecordsVO vo : recordsList) {
|
|
|
|
|
+ IpadAllocationRecords ipadAllocationRecords = ipadAllocationRecordsMapper.selectById(vo.getId());
|
|
|
|
|
+ if (!ipadAllocationRecords.getAuditStatus().equals(0)) {
|
|
|
|
|
+ ipadAllocationRecords.setServerJson(JSON.toJSONString(vo.getDetailsList()));
|
|
|
|
|
+ ipadAllocationRecordsMapper.updateById(ipadAllocationRecords);
|
|
|
|
|
+ log.info("分配记录id:{},状态已更新,无需重复更新", vo.getId());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("更新分配记录,记录id:{},更新状态:{},分配数量:{},审核时间:{},拒绝原因:{},公司名称:{}",
|
|
|
|
|
+ vo.getId(), vo.getAuditStatus(), vo.getAllocatedQuantity(), vo.getReviewTime(), vo.getRejectionReason(), vo.getCompanyName());
|
|
|
|
|
+ if (ipadAllocationRecords != null) {
|
|
|
|
|
+ ipadAllocationRecords.setAuditStatus(vo.getAuditStatus());
|
|
|
|
|
+ ipadAllocationRecords.setUpdatedTime(LocalDateTime.now());
|
|
|
|
|
+ ipadAllocationRecords.setAllocatedQuantity(vo.getAllocatedQuantity());
|
|
|
|
|
+ ipadAllocationRecords.setReviewTime(vo.getReviewTime());
|
|
|
|
|
+ ipadAllocationRecords.setRejectionReason(vo.getRejectionReason());
|
|
|
|
|
+ ipadAllocationRecords.setCompanyName(vo.getCompanyName());
|
|
|
|
|
+ ipadAllocationRecords.setServerJson(JSON.toJSONString(vo.getDetailsList()));
|
|
|
|
|
+ ipadAllocationRecords.setRegion(vo.getRegion());
|
|
|
|
|
+ ipadAllocationRecordsMapper.updateById(ipadAllocationRecords);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<IpadAllocationDetails> detailsList = vo.getDetailsList();
|
|
|
|
|
+ for (IpadAllocationDetails details : detailsList) {
|
|
|
|
|
+ //去查询是否有相同端口和ip的服务器,有则去更新total_count和count都加上allocatedSeats,没有则添加一条服务器记录。
|
|
|
|
|
+ Integer allocatedSeats = details.getAllocatedSeats();
|
|
|
|
|
+ QwIpadServer server = serverService.selectIpAndPort(details.getIpAddress(), details.getPort());
|
|
|
|
|
+ if (server != null) {
|
|
|
|
|
+ server.setTotalCount(server.getTotalCount() + allocatedSeats);
|
|
|
|
|
+ server.setCount(server.getCount() + allocatedSeats);
|
|
|
|
|
+ server.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
+// server.setRecordId(details.getAllocationId());//后面的审核记录会覆盖之前的审核记录id,这里存的是最新的审核记录id
|
|
|
|
|
+ serverService.updateById(server);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //添加一条服务器记录
|
|
|
|
|
+ QwIpadServer newServer = new QwIpadServer();
|
|
|
|
|
+// newServer.setRecordId(details.getAllocationId());
|
|
|
|
|
+ newServer.setIp(details.getIpAddress());
|
|
|
|
|
+ newServer.setPort(String.valueOf(details.getPort()));
|
|
|
|
|
+ newServer.setTotalCount(Long.valueOf(allocatedSeats));
|
|
|
|
|
+ newServer.setCount(Long.valueOf(allocatedSeats));
|
|
|
|
|
+ newServer.setAddressId("520000000000");
|
|
|
|
|
+ newServer.setUrl(details.getAccessUrl());
|
|
|
|
|
+ newServer.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
+ serverService.getBaseMapper().insert(newServer);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //返回成功结果
|
|
|
|
|
+ return AjaxResult.success("更新成功", recordsList);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //返回错误结果
|
|
|
|
|
+ String errorMsg = response != null ? (String) response.get("msg") : "更新失败";
|
|
|
|
|
+ return AjaxResult.error(errorMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //释放已申请的ipad服务器
|
|
|
|
|
+ //释放哪条记录的那台服务器多少台
|
|
|
|
|
+ @PostMapping("/release")
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public AjaxResult release(@RequestBody ServerParam serverParam) throws Exception {
|
|
|
|
|
+ //校验参数是否为空
|
|
|
|
|
+ if (serverParam == null) {
|
|
|
|
|
+ return AjaxResult.error("serverParam不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QwIpadServer server = serverService.selectIpAndPort(serverParam.getIpAddress(), Long.valueOf(serverParam.getPort()));
|
|
|
|
|
+ if (server == null) {
|
|
|
|
|
+ log.info("服务器地址:{},端口:{},未查询到服务器记录,无法释放", serverParam.getIpAddress(), serverParam.getPort());
|
|
|
|
|
+ return AjaxResult.error("未查询到服务器记录,无法释放");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (serverParam.getReleaseCount() > server.getCount()) {
|
|
|
|
|
+ log.info("服务器id:{},释放数量:{},剩余数量:{},释放数量大于剩余数量,无法释放", server.getId(), serverParam.getReleaseCount(), server.getCount());
|
|
|
|
|
+ return AjaxResult.error("释放数量大于剩余数量,无法释放");
|
|
|
|
|
+ }
|
|
|
|
|
+ IpadAllocationRecords record = ipadAllocationRecordsMapper.selectById(serverParam.getRecordId());
|
|
|
|
|
+ if (record == null) {
|
|
|
|
|
+ log.info("服务器id:{},释放数量:{},申请记录为空,无法释放", server.getId(), serverParam.getReleaseCount());
|
|
|
|
|
+ return AjaxResult.error("申请记录为空,无法释放");
|
|
|
|
|
+ }
|
|
|
|
|
+ record.setAllocatedQuantity(record.getAllocatedQuantity() - serverParam.getReleaseCount());
|
|
|
|
|
+// record.setApplyQuantity(record.getApplyQuantity() - serverParam.getReleaseCount());
|
|
|
|
|
+
|
|
|
|
|
+ server.setCount(server.getCount() - serverParam.getReleaseCount());
|
|
|
|
|
+ server.setTotalCount(server.getTotalCount() - serverParam.getReleaseCount());
|
|
|
|
|
+ ipadAllocationRecordsMapper.updateById(record);
|
|
|
|
|
+ serverService.updateById(server);
|
|
|
|
|
+
|
|
|
|
|
+ ServerParam build = ServerParam.builder()
|
|
|
|
|
+ .ipadServerId(serverParam.getIpadServerId())
|
|
|
|
|
+ .recordId(serverParam.getRecordId())
|
|
|
|
|
+ .releaseCount(serverParam.getReleaseCount())
|
|
|
|
|
+ .ipAddress(serverParam.getIpAddress())
|
|
|
|
|
+ .port(serverParam.getPort())
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ //发起http请求
|
|
|
|
|
+ String body = JSON.toJSONString(build);
|
|
|
|
|
+
|
|
|
|
|
+ HttpRequest post = HttpUtil.createPost(ipadServerUrl + "/ipad/records/release");
|
|
|
|
|
+ post.body(body);
|
|
|
|
|
+ post.header("Authorization", HMACAuth.generateToken());
|
|
|
|
|
+ //发起请求
|
|
|
|
|
+ String result = post.execute().body();
|
|
|
|
|
+ log.info("发起ipad服务器释放状态,释放数量:{},拉取结果:{}", body, result);
|
|
|
|
|
+
|
|
|
|
|
+ //解析返回的JSON结果
|
|
|
|
|
+ AjaxResult response = JSON.parseObject(result, AjaxResult.class);
|
|
|
|
|
+
|
|
|
|
|
+ //首先判断code是否为200,不是回滚事务
|
|
|
|
|
+ if (!response.get("code").equals(200)) {
|
|
|
|
|
+ String errorMsg = response != null ? (String) response.get("msg") : "释放失败";
|
|
|
|
|
+ throw new Exception(errorMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ return AjaxResult.success("释放成功");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|