|
|
|
|
@ -1,16 +1,25 @@ |
|
|
|
|
|
|
|
|
|
package org.springblade.modules.workOrder.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.modules.workOrder.entity.InformationAttach; |
|
|
|
|
import org.springblade.modules.workOrder.vo.InformationAttachVO; |
|
|
|
|
import org.springblade.modules.workOrder.excel.InformationAttachExcel; |
|
|
|
|
import org.springblade.modules.workOrder.mapper.InformationAttachMapper; |
|
|
|
|
import org.springblade.modules.workOrder.service.IInformationAttachService; |
|
|
|
|
import org.springframework.dao.DataIntegrityViolationException; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
|
|
|
|
|
import java.rmi.ServerException; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 资料附件表 服务实现类 |
|
|
|
|
@ -18,6 +27,7 @@ import java.util.List; |
|
|
|
|
* @author BladeX |
|
|
|
|
* @since 2024-10-14 |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
|
public class InformationAttachServiceImpl extends BaseServiceImpl<InformationAttachMapper, InformationAttach> implements IInformationAttachService { |
|
|
|
|
|
|
|
|
|
@ -36,4 +46,75 @@ public class InformationAttachServiceImpl extends BaseServiceImpl<InformationAtt |
|
|
|
|
return informationAttachList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R add(List<InformationAttach> informationAttach) { |
|
|
|
|
if (CollectionUtils.isEmpty(informationAttach)) { |
|
|
|
|
log.error("信息附件对象为空"); |
|
|
|
|
return R.fail(400, "信息附件对象为空"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 创建查询条件,检查是否存在相同父ID和名称的附件
|
|
|
|
|
LambdaQueryWrapper<InformationAttach> wrapper = Wrappers.lambdaQuery(InformationAttach.class) |
|
|
|
|
.eq(InformationAttach::getParentId, informationAttach.get(0).getParentId()) |
|
|
|
|
.in(InformationAttach::getName, informationAttach.stream().map(InformationAttach::getName).collect(Collectors.toList())); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// 执行查询,获取符合条件的记录数
|
|
|
|
|
long count = this.count(wrapper); |
|
|
|
|
|
|
|
|
|
// 如果大于0,则说明已经存在
|
|
|
|
|
if (count > 0) { |
|
|
|
|
return R.fail(200, "文件名称重复!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 执行保存操作,并返回操作结果
|
|
|
|
|
boolean saveResult = this.saveBatch(informationAttach); |
|
|
|
|
log.info("保存信息附件结果: {}", saveResult); |
|
|
|
|
return R.status(saveResult); |
|
|
|
|
} catch (DataIntegrityViolationException e) { |
|
|
|
|
log.error("保存信息附件时发生数据完整性错误", e); |
|
|
|
|
return R.fail(500, "保存信息附件时发生数据完整性错误"); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("保存信息附件时发生错误", e); |
|
|
|
|
return R.fail(500, "保存信息附件时发生错误"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R edit(InformationAttach informationAttach) { |
|
|
|
|
try { |
|
|
|
|
// 输入验证
|
|
|
|
|
if (informationAttach == null || informationAttach.getId() == null || informationAttach.getParentId() == null || informationAttach.getName() == null) { |
|
|
|
|
return R.fail(400, "输入参数不合法"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 创建一个Lambda查询包装器,用于构建查询条件
|
|
|
|
|
LambdaQueryWrapper<InformationAttach> wrapper = Wrappers.lambdaQuery(InformationAttach.class) |
|
|
|
|
// 排除当前记录的ID
|
|
|
|
|
.ne(InformationAttach::getId, informationAttach.getId()) |
|
|
|
|
// 查询条件:父ID相等
|
|
|
|
|
.eq(InformationAttach::getParentId, informationAttach.getParentId()) |
|
|
|
|
// 查询条件:名称相等
|
|
|
|
|
.eq(InformationAttach::getName, informationAttach.getName()); |
|
|
|
|
|
|
|
|
|
// 使用上述条件查询记录数
|
|
|
|
|
long count = this.count(wrapper); |
|
|
|
|
// 如果大于0,则说明已经存在
|
|
|
|
|
if (count > 0) { |
|
|
|
|
// 返回失败响应,提示文件名称重复
|
|
|
|
|
return R.fail(200, "[" + informationAttach.getName() + "]该文件名称重复!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 更新数据库中的当前记录
|
|
|
|
|
return R.status(this.updateById(informationAttach)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
// 记录异常日志
|
|
|
|
|
log.error("编辑信息附件时发生异常", e); |
|
|
|
|
// 返回失败响应
|
|
|
|
|
return R.fail(500, "系统内部错误"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|