初始化分组、分配教室
This commit is contained in:
parent
4985133ea4
commit
944f0e54d6
|
@ -43,6 +43,16 @@ public class CetGroupController extends JeecgController<CetGroup, ICetGroupServi
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICetInvigilateDataService cetInvigilateDataService;
|
private ICetInvigilateDataService cetInvigilateDataService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param webData
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation(value="分配教室", notes="分配教室")
|
||||||
|
@PostMapping(value = "/batchHandleClassRoom")
|
||||||
|
public Result<?> batchHandleClassRooms(@RequestBody Map<String, Object> webData) {
|
||||||
|
return cetGroupService.batchHandleClassRooms(webData);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
*
|
*
|
||||||
|
@ -177,7 +187,6 @@ public class CetGroupController extends JeecgController<CetGroup, ICetGroupServi
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//@AutoLog(value = "分组数据表-通过id查询")
|
|
||||||
@ApiOperation(value="分组数据表-通过id查询", notes="分组数据表-通过id查询")
|
@ApiOperation(value="分组数据表-通过id查询", notes="分组数据表-通过id查询")
|
||||||
@GetMapping(value = "/queryById")
|
@GetMapping(value = "/queryById")
|
||||||
public Result<CetGroup> queryById(@RequestParam(name="id",required=true) String id) {
|
public Result<CetGroup> queryById(@RequestParam(name="id",required=true) String id) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.jeecg.modules.controller;
|
package org.jeecg.modules.controller;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
@ -36,6 +37,10 @@ public class ClassRoomController extends JeecgController<ClassRoom, IClassRoomSe
|
||||||
@Autowired
|
@Autowired
|
||||||
private IClassRoomService classRoomService;
|
private IClassRoomService classRoomService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
*
|
*
|
||||||
|
|
|
@ -32,6 +32,9 @@ public class ClassRoom implements Serializable {
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
@ApiModelProperty(value = "主键")
|
@ApiModelProperty(value = "主键")
|
||||||
private String id;
|
private String id;
|
||||||
|
// @Excel(name = "教学楼名", width = 15)
|
||||||
|
@ApiModelProperty(value = "分组ID")
|
||||||
|
private String groupId;
|
||||||
/**教学楼名,如“理工一”、“崇师楼”*/
|
/**教学楼名,如“理工一”、“崇师楼”*/
|
||||||
@Excel(name = "教学楼名", width = 15)
|
@Excel(name = "教学楼名", width = 15)
|
||||||
@ApiModelProperty(value = "教学楼名,如“理工一”、“崇师楼”")
|
@ApiModelProperty(value = "教学楼名,如“理工一”、“崇师楼”")
|
||||||
|
@ -79,4 +82,7 @@ public class ClassRoom implements Serializable {
|
||||||
/**所属部门*/
|
/**所属部门*/
|
||||||
@ApiModelProperty(value = "所属部门")
|
@ApiModelProperty(value = "所属部门")
|
||||||
private String sysOrgCode;
|
private String sysOrgCode;
|
||||||
|
/**状态*/
|
||||||
|
@ApiModelProperty(value = "状态")
|
||||||
|
private String status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,11 @@ package org.jeecg.modules.service;
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.modules.entity.CetGroup;
|
import org.jeecg.modules.entity.CetGroup;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 分组数据表
|
* @Description: 分组数据表
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
|
@ -12,4 +15,5 @@ import org.jeecg.modules.entity.CetGroup;
|
||||||
*/
|
*/
|
||||||
public interface ICetGroupService extends IService<CetGroup> {
|
public interface ICetGroupService extends IService<CetGroup> {
|
||||||
|
|
||||||
|
Result<?> batchHandleClassRooms(Map<String, Object> webData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.modules.entity.ClassRoom;
|
import org.jeecg.modules.entity.ClassRoom;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 教室表
|
* @Description: 教室表
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
|
@ -14,4 +16,5 @@ import org.jeecg.modules.entity.ClassRoom;
|
||||||
public interface IClassRoomService extends IService<ClassRoom> {
|
public interface IClassRoomService extends IService<ClassRoom> {
|
||||||
|
|
||||||
Result<String> add(ClassRoom classRoom);
|
Result<String> add(ClassRoom classRoom);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
package org.jeecg.modules.service.impl;
|
package org.jeecg.modules.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.modules.entity.CetGroup;
|
import org.jeecg.modules.entity.CetGroup;
|
||||||
|
import org.jeecg.modules.entity.ClassRoom;
|
||||||
import org.jeecg.modules.mapper.CetGroupMapper;
|
import org.jeecg.modules.mapper.CetGroupMapper;
|
||||||
|
import org.jeecg.modules.mapper.ClassRoomMapper;
|
||||||
import org.jeecg.modules.service.ICetGroupService;
|
import org.jeecg.modules.service.ICetGroupService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 分组数据表
|
* @Description: 分组数据表
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
|
@ -16,5 +27,62 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CetGroupServiceImpl extends ServiceImpl<CetGroupMapper, CetGroup> implements ICetGroupService {
|
public class CetGroupServiceImpl extends ServiceImpl<CetGroupMapper, CetGroup> implements ICetGroupService {
|
||||||
|
@Autowired
|
||||||
|
private CetGroupMapper cetGroupMapper;
|
||||||
|
@Autowired
|
||||||
|
private ClassRoomMapper classRoomMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Result<?> batchHandleClassRooms(Map<String, Object> webData) {
|
||||||
|
Object idsObj = webData.get("ids");
|
||||||
|
if (!(idsObj instanceof List)) {
|
||||||
|
return Result.error("参数错误:未找到班级 ID 列表");
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> groupIds = (List<String>) idsObj;
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(groupIds)) {
|
||||||
|
return Result.error("请选择需要分配教室的班级");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询空闲教室(status = 0)
|
||||||
|
List<ClassRoom> freeRooms = classRoomMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<ClassRoom>().eq(ClassRoom::getStatus, 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (freeRooms.size() < groupIds.size()) {
|
||||||
|
return Result.error("空闲教室数量不足,请减少分配数量或释放教室");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < groupIds.size(); i++) {
|
||||||
|
String groupId = groupIds.get(i);
|
||||||
|
ClassRoom room = freeRooms.get(i);
|
||||||
|
|
||||||
|
// 使用 LambdaUpdateWrapper 更新教室状态和绑定班级
|
||||||
|
boolean updated = classRoomMapper.update(
|
||||||
|
null,
|
||||||
|
new LambdaUpdateWrapper<ClassRoom>()
|
||||||
|
.eq(ClassRoom::getId, room.getId())
|
||||||
|
.eq(ClassRoom::getStatus, 0) // 乐观锁保证未被其他线程占用
|
||||||
|
.set(ClassRoom::getGroupId, groupId)
|
||||||
|
.set(ClassRoom::getStatus, 1)
|
||||||
|
) > 0;
|
||||||
|
|
||||||
|
if (!updated) {
|
||||||
|
throw new RuntimeException("教室 " + room.getFullName() + " 被占用,请稍后重试");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新班级的教室字段(假设 classMapper 是使用 MyBatis Plus 的)
|
||||||
|
cetGroupMapper.update(
|
||||||
|
null,
|
||||||
|
new LambdaUpdateWrapper<CetGroup>()
|
||||||
|
.eq(CetGroup::getId, groupId)
|
||||||
|
.set(CetGroup::getRoomId, room.getId())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.ok("成功为 " + groupIds.size() + " 个班级分配教室");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,28 @@
|
||||||
package org.jeecg.modules.service.impl;
|
package org.jeecg.modules.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.checkerframework.checker.units.qual.A;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.common.system.vo.LoginUser;
|
||||||
|
import org.jeecg.modules.entity.CetGroup;
|
||||||
import org.jeecg.modules.entity.ClassRoom;
|
import org.jeecg.modules.entity.ClassRoom;
|
||||||
|
import org.jeecg.modules.mapper.CetGroupMapper;
|
||||||
import org.jeecg.modules.mapper.ClassRoomMapper;
|
import org.jeecg.modules.mapper.ClassRoomMapper;
|
||||||
import org.jeecg.modules.service.IClassRoomService;
|
import org.jeecg.modules.service.IClassRoomService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 教室表
|
* @Description: 教室表
|
||||||
|
@ -21,15 +32,42 @@ import java.util.Date;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ClassRoomServiceImpl extends ServiceImpl<ClassRoomMapper, ClassRoom> implements IClassRoomService {
|
public class ClassRoomServiceImpl extends ServiceImpl<ClassRoomMapper, ClassRoom> implements IClassRoomService {
|
||||||
|
@Autowired
|
||||||
|
private ClassRoomMapper classRoomMapper;
|
||||||
|
@Autowired
|
||||||
|
private CetGroupMapper cetGroupMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<String> add(ClassRoom classRoom) {
|
public Result<String> add(ClassRoom classRoom) {
|
||||||
|
if (classRoom == null) {
|
||||||
|
return Result.error("参数不能为空");
|
||||||
|
}
|
||||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
//完善
|
String username = sysUser.getUsername();
|
||||||
classRoom.setCreateTime(new Date());
|
Date now = new Date();
|
||||||
classRoom.setUpdateTime(new Date());
|
|
||||||
classRoom.setUpdateBy(sysUser.getUsername());
|
classRoom.setCreateTime(now);
|
||||||
classRoom.setCreateBy(sysUser.getUsername());
|
classRoom.setUpdateTime(now);
|
||||||
return null;
|
classRoom.setCreateBy(username);
|
||||||
|
classRoom.setUpdateBy(username);
|
||||||
|
classRoom.setStatus("0");
|
||||||
|
String building = Optional.ofNullable(classRoom.getBuilding()).orElse("");
|
||||||
|
String area = Optional.ofNullable(classRoom.getArea()).orElse("");
|
||||||
|
String roomNumber = Optional.ofNullable(classRoom.getRoomNumber()).orElse("");
|
||||||
|
// 拼接逻辑:有 area 的话加上 area.toUpperCase() + "区"
|
||||||
|
String areaPart = area.isEmpty() ? "" : area.toUpperCase() + "区";
|
||||||
|
// 最终 fullName
|
||||||
|
String fullName = building + areaPart + roomNumber;
|
||||||
|
classRoom.setArea(areaPart);
|
||||||
|
classRoom.setFullName(fullName);
|
||||||
|
|
||||||
|
int rows = classRoomMapper.insert(classRoom);
|
||||||
|
if (rows > 0) {
|
||||||
|
return Result.ok("添加成功");
|
||||||
|
} else {
|
||||||
|
return Result.error("添加失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue