This commit is contained in:
weizhong committed 2025-10-10 17:05:57 +08:00
commit 4a6a6728e4
7 files changed
+304 -10

No files matched your search

@@ -10,6 +10,7 @@ import org.dromara.zsjy.domain.vo.InternshipInfoVO;
import org.dromara.zsjy.domain.bo.InternshipInfoQueryBO;
import org.dromara.zsjy.domain.bo.InternshipInfoAddBO;
import org.dromara.zsjy.domain.bo.InternshipInfoEditBO;
import org.dromara.zsjy.domain.bo.InternshipInfoChangeBO;
import org.dromara.zsjy.service.IInternshipInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -225,4 +226,29 @@ public class InternshipInfoController extends BaseController {
return R.fail("获取实习信息失败:" + e.getMessage());
}
}
/**
* 实习信息变更
*/
@Operation(summary = "实习信息变更", description = "变更学生实习信息,将原记录设置为失效,并新增一条新的实习记录")
@SaCheckPermission("zsjy:internship:change")
@PostMapping("/change")
public R<Void> changeInternship(@RequestBody @Validated InternshipInfoChangeBO changeBO) {
log.info("实习信息变更请求,参数:{}", changeBO);
try {
Boolean result = internshipInfoService.changeInternshipInfo(changeBO);
if (result) {
log.info("实习信息变更成功,原实习ID:{},学生ID:{}",
changeBO.getInternshipId(), changeBO.getStudentId());
return R.ok();
} else {
log.error("实习信息变更失败,原实习ID:{}", changeBO.getInternshipId());
return R.fail("实习信息变更失败");
}
} catch (Exception e) {
log.error("实习信息变更异常,原实习ID:{},错误信息:{}",
changeBO.getInternshipId(), e.getMessage(), e);
return R.fail("实习信息变更失败:" + e.getMessage());
}
}
}
@@ -31,6 +31,11 @@ public class ZsjyInternshipInfo extends BaseEntity {
@TableId(value = "internship_id")
private Long internshipId;
/**
* 前一条实习记录ID(用于变更记录关联)
*/
private Long previousInternshipId;
/**
* 学生ID
*/
@@ -166,5 +171,9 @@ public class ZsjyInternshipInfo extends BaseEntity {
*/
@TableLogic(value = "0", delval = "1")
private Long deleted;
/**
* 变更原因(用于记录实习信息变更的原因)
*/
private String changeReason;
}
@@ -6,6 +6,7 @@ import org.dromara.zsjy.domain.vo.InternshipInfoVO;
import org.dromara.zsjy.domain.bo.InternshipInfoQueryBO;
import org.dromara.zsjy.domain.bo.InternshipInfoAddBO;
import org.dromara.zsjy.domain.bo.InternshipInfoEditBO;
import org.dromara.zsjy.domain.bo.InternshipInfoChangeBO;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
@@ -105,4 +106,13 @@ public interface IInternshipInfoService {
* @return 当前学生的实习信息,如果没有则返回null
*/
InternshipInfoVO getCurrentStudentInternship();
/**
* 实习信息变更
* <p>将原实习记录设置为"已变更"状态,并新增一条新的实习记录</p>
*
* @param changeBO 变更参数
* @return 是否成功
*/
Boolean changeInternshipInfo(InternshipInfoChangeBO changeBO);
}
@@ -20,6 +20,7 @@ import org.dromara.common.core.exception.ServiceException;
import org.dromara.zsjy.domain.bo.InternshipInfoQueryBO;
import org.dromara.zsjy.domain.bo.InternshipInfoAddBO;
import org.dromara.zsjy.domain.bo.InternshipInfoEditBO;
import org.dromara.zsjy.domain.bo.InternshipInfoChangeBO;
import org.dromara.zsjy.domain.vo.InternshipInfoVO;
import org.dromara.zsjy.domain.ZsjyInternshipInfo;
import org.dromara.zsjy.mapper.InternshipInfoMapper;
@@ -468,34 +469,34 @@ public class InternshipInfoServiceImpl implements IInternshipInfoService {
@Override
public InternshipInfoVO getCurrentStudentInternship() {
log.info("开始获取当前学生的实习信息");
// 获取当前登录用户ID
Long currentUserId = LoginHelper.getUserId();
log.info("当前登录用户ID:{}", currentUserId);
if (currentUserId == null) {
log.error("当前用户未登录");
throw new ServiceException("用户未登录");
}
// 根据用户ID查询实习信息
LambdaQueryWrapper<ZsjyInternshipInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ZsjyInternshipInfo::getStudentId, currentUserId)
.eq(ZsjyInternshipInfo::getDeleted, 0)
.orderByDesc(ZsjyInternshipInfo::getCreateTime)
.last("LIMIT 1"); // 只取最新的一条记录
ZsjyInternshipInfo internshipInfo = zsjyInternshipInfoMapper.selectOne(wrapper);
log.info("查询到的实习信息:{}", internshipInfo != null ? internshipInfo.getInternshipId() : "无");
if (internshipInfo == null) {
log.info("当前学生没有实习信息");
return null;
}
// 转换为VO
InternshipInfoVO vo = BeanUtil.toBean(internshipInfo, InternshipInfoVO.class);
// 查询学生信息并设置到VO中
XgStudentMsgVo studentInfo = getStudentInfo(currentUserId);
vo.setStudentName(studentInfo.getName());
@@ -504,8 +505,117 @@ public class InternshipInfoServiceImpl implements IInternshipInfoService {
vo.setMajorName(studentInfo.getMajorName());
vo.setCollegeName(studentInfo.getCollegeName());
vo.setGrade(studentInfo.getGrade());
log.info("成功获取当前学生实习信息,实习ID:{}", vo.getInternshipId());
return vo;
}
/**
* 实习信息变更
* <p>业务逻辑:</p>
* <ol>
* <li>将原实习记录的状态设置为"4已变更",标记为失效</li>
* <li>新增一条实习记录,previous_internship_id指向原记录</li>
* <li>保存变更原因到新记录的change_reason字段</li>
* </ol>
*
* @param changeBO 变更参数
* @return 是否成功
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean changeInternshipInfo(InternshipInfoChangeBO changeBO) {
log.info("=== 实习信息变更开始 ===");
log.info("1. 接收到的变更参数:{}", changeBO);
// 1. 查询原实习记录
ZsjyInternshipInfo oldInternshipInfo = zsjyInternshipInfoMapper.selectById(changeBO.getInternshipId());
if (ObjectUtil.isNull(oldInternshipInfo)) {
log.error("原实习信息不存在,ID:{}", changeBO.getInternshipId());
throw new ServiceException("原实习信息不存在");
}
log.info("2. 查询到原实习记录:实习ID={}, 学生ID={}, 单位={}",
oldInternshipInfo.getInternshipId(), oldInternshipInfo.getStudentId(),
oldInternshipInfo.getCompanyName());
// 2. 验证学生ID是否匹配
if (!oldInternshipInfo.getStudentId().equals(changeBO.getStudentId())) {
log.error("学生ID不匹配,原记录学生ID:{},变更请求学生ID:{}",
oldInternshipInfo.getStudentId(), changeBO.getStudentId());
throw new ServiceException("学生ID不匹配,无法进行变更操作");
}
// 3. 检查原记录状态是否允许变更(只有"进行中"的实习可以变更)
if (!"1".equals(oldInternshipInfo.getInternshipStatus())) {
log.error("只有进行中的实习信息才能变更,当前状态:{}", oldInternshipInfo.getInternshipStatus());
throw new ServiceException("只有进行中的实习信息才能变更");
}
// 4. 将原实习记录设置为"已变更"状态
ZsjyInternshipInfo updateOldInfo = new ZsjyInternshipInfo();
updateOldInfo.setInternshipId(oldInternshipInfo.getInternshipId());
updateOldInfo.setInternshipStatus("4"); // 4=已变更
int updateResult = zsjyInternshipInfoMapper.updateById(updateOldInfo);
log.info("3. 更新原实习记录状态为'已变更',结果:{}", updateResult > 0 ? "成功" : "失败");
if (updateResult <= 0) {
log.error("更新原实习记录状态失败");
throw new ServiceException("更新原实习记录状态失败");
}
// 5. 创建新的实习记录
ZsjyInternshipInfo newInternshipInfo = new ZsjyInternshipInfo();
// 复制学生基础信息(从原记录)
newInternshipInfo.setStudentId(oldInternshipInfo.getStudentId());
newInternshipInfo.setStudentNo(oldInternshipInfo.getStudentNo());
newInternshipInfo.setStudentName(oldInternshipInfo.getStudentName());
newInternshipInfo.setGender(oldInternshipInfo.getGender());
newInternshipInfo.setCollegeId(oldInternshipInfo.getCollegeId());
newInternshipInfo.setMajorId(oldInternshipInfo.getMajorId());
newInternshipInfo.setClassId(oldInternshipInfo.getClassId());
newInternshipInfo.setPhone(oldInternshipInfo.getPhone());
// 设置变更关联信息
newInternshipInfo.setPreviousInternshipId(oldInternshipInfo.getInternshipId()); // 关联原记录
newInternshipInfo.setChangeReason(changeBO.getChangeReason()); // 变更原因
// 设置新的实习信息(来自changeBO)
newInternshipInfo.setInternshipStatus(changeBO.getInternshipStatus());
newInternshipInfo.setCompanyName(changeBO.getCompanyName());
newInternshipInfo.setCompanyAddress(changeBO.getCompanyAddress());
newInternshipInfo.setCompanyContact(changeBO.getCompanyContact());
newInternshipInfo.setCompanyPhone(changeBO.getCompanyPhone());
newInternshipInfo.setCompanyIndustry(changeBO.getCompanyIndustry());
newInternshipInfo.setCompanyScale(changeBO.getCompanyScale());
newInternshipInfo.setPositionName(changeBO.getPositionName());
newInternshipInfo.setPositionDuties(changeBO.getPositionDuties());
newInternshipInfo.setInternshipAllowance(changeBO.getInternshipAllowance());
newInternshipInfo.setWorkHours(changeBO.getWorkHours());
newInternshipInfo.setAccommodationAddress(changeBO.getAccommodationAddress());
newInternshipInfo.setAccommodationType(changeBO.getAccommodationType());
newInternshipInfo.setAccommodationCost(changeBO.getAccommodationCost());
newInternshipInfo.setStartDate(changeBO.getStartDate());
newInternshipInfo.setEndDate(changeBO.getEndDate());
newInternshipInfo.setStatus("0"); // 状态:0=正常
log.info("4. 准备插入新实习记录:学生ID={}, 新单位={}, 变更原因={}",
newInternshipInfo.getStudentId(), newInternshipInfo.getCompanyName(),
newInternshipInfo.getChangeReason());
// 6. 插入新记录
int insertResult = zsjyInternshipInfoMapper.insert(newInternshipInfo);
log.info("5. 插入新实习记录,结果:{}", insertResult > 0 ? "成功" : "失败");
log.info("6. 新实习记录ID:{}", newInternshipInfo.getInternshipId());
if (insertResult <= 0) {
log.error("插入新实习记录失败");
throw new ServiceException("插入新实习记录失败");
}
boolean success = insertResult > 0;
log.info("=== 实习信息变更结束,结果:{} ===", success ? "成功" : "失败");
return success;
}
}