package com.ruoyi.service.impl; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.*; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.MapUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.domain.ArchiveRecords; import com.ruoyi.domain.Archiverecordstouser; import com.ruoyi.domain.vo.AnalysisResult; import com.ruoyi.domain.vo.ArchiveInfoVo; import com.ruoyi.mapper.ArchiveRecordsMapper; import com.ruoyi.mapper.ArchiverecordstouserMapper; import com.ruoyi.service.IArchiveRecordsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; /** * 档案记录Service业务层处理 * * @author ruoyi * @date 2025-07-12 */ @Service public class ArchiveRecordsServiceImpl extends ServiceImpl implements IArchiveRecordsService { // @Autowired // private ArchiveRecordsMapper archiveRecordsMapper; @Autowired private ArchiverecordstouserMapper archiverecordstouserMapper; private LambdaQueryWrapper buildCondition(ArchiveRecords archiveRecords, Long userId){ LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.like(!StringUtils.isEmpty(archiveRecords.getProjectName()), ArchiveRecords::getProjectName, archiveRecords.getProjectName()) .like(!StringUtils.isEmpty(archiveRecords.getFilingNumber()), ArchiveRecords::getFilingNumber, archiveRecords.getFilingNumber()) .like(!StringUtils.isEmpty(archiveRecords.getArchiveRoomNumber()), ArchiveRecords::getArchiveRoomNumber, archiveRecords.getArchiveRoomNumber()) .like(!StringUtils.isEmpty(archiveRecords.getRecordId()), ArchiveRecords::getRecordId, archiveRecords.getRecordId()); // .like(!StringUtils.isEmpty(zfProperty.getLocation()), ZfProperty::getLocation, zfProperty.getLocation()) // .like(!StringUtils.isEmpty(zfProperty.getHolder()), ZfProperty::getHolder, zfProperty.getHolder()) // .like(!StringUtils.isEmpty(zfProperty.getAddress()), ZfProperty::getAddress, zfProperty.getAddress()) // .like(!StringUtils.isEmpty(zfProperty.getRemark()), ZfProperty::getRemark, zfProperty.getRemark()) // .eq(zfProperty.getFamilyId()!=null,ZfProperty::getFamilyId,zfProperty.getFamilyId()) // .in(ZfProperty::getFamilyId,familyIdList) // .eq(zfProperty.getHappenTime()!=null,ZfProperty::getHappenTime,zfProperty.getHappenTime()) // .between(zfProperty.getHappenStartTime() != null && zfProperty.getHappenEndTime() != null, ZfProperty::getHappenTime, zfProperty.getHappenStartTime(), zfProperty.getHappenEndTime()); // lqw.orderByDesc(ZfProperty::getCreateTime); if(userId==1) lqw.orderByDesc(ArchiveRecords::getCreateTime); System.out.println("ssssssssssssddd0000000000000000"); return lqw; } @Override public Long getMaxId() { //return this. return baseMapper.findMaxId(); } @Override public AjaxResult selectDataList(ArchiveRecords archiveRecords, Integer pageNum, Integer pageSize) { //拿到当前用户的id // 获取当前用户ID Long userid = SecurityUtils.getUserId(); LambdaQueryWrapper lqw = buildCondition(archiveRecords, userid); System.out.println("-------------"); System.out.println(pageNum); Page page = new Page<>(pageNum, pageSize); // 使用自定义的分页查询方法,先连接再分页 Page pageResult = this.baseMapper.selectJoinUserPage(page, userid, lqw); //selectJoinUserPage(page, lqw); List beanRecords = pageResult.getRecords();//得到查询出来的数据 // List beanRecords = list(lqw); // log.info("从数据库中查到的为:{}", beanRecords); // return markOwnData(familyId, fatherFaId, motherFaId, beanRecords); beanRecords.forEach(record ->{ if(record.isArchiveRecordsId()!=null&&record.getUserId()==userid) { record.setOwnData(true); } else record.setOwnData(false); }); //不是管理员进行排序 // if(userid != 1) // Collections.sort(beanRecords, Comparator.comparing(ArchiveRecords::isOwnData)); HashMap data = MapUtils.getResult(pageResult, beanRecords); // System.out.println(data.get("data")); // System.out.println(data.get("pageNum")); // System.out.println(data.get("total")); return AjaxResult.success(data); } /** * 查询档案记录 * * @param id 档案记录主键 * @return 档案记录 */ @Override public ArchiveRecords selectArchiveRecordsById(Long id) { System.out.println(id); System.out.println("-------------ssssssssssssssssss"); LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(id!=null, ArchiveRecords::getId, id); List records = list(lqw); if(!records.isEmpty()) return records.get(0); else return null; } /** * 查询档案记录列表 * * @param archiveRecords 档案记录 * @return 档案记录 */ @Override public List selectArchiveRecordsList(ArchiveRecords archiveRecords) { //拿到当前用户的id // 获取当前用户ID Long userid = SecurityUtils.getUserId(); LambdaQueryWrapper lambdaQueryWrapper = buildCondition(archiveRecords,userid); List beanRecords = list(lambdaQueryWrapper); return beanRecords; } /** * 新增档案记录 * * @param archiveRecords 档案记录 * @return 结果 */ @Override public int insertArchiveRecords(ArchiveRecords archiveRecords) { LocalDateTime time = LocalDateTime.now(); Date date = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()); archiveRecords.setCreateTime(date); archiveRecords.setRecordStatus("未录入"); // archiveRecords boolean res = this.save(archiveRecords); if(res) return 1; else return 0; } /** * 修改档案记录 * * @param archiveRecords 档案记录 * @return 结果 */ @Override public int updateArchiveRecords(ArchiveRecords archiveRecords) { boolean result = updateById(archiveRecords); if(result) return 1; else return 0; } /** * 批量删除档案记录 * * @param ids 需要删除的档案记录主键 * @return 结果 */ @Override public int deleteArchiveRecordsByIds(Long[] ids) { Long res = 0L; for(Long id: ids) { this.baseMapper.updateAllInfoById(id); } return 1; } /** * 删除档案记录信息 * * @param id 档案记录主键 * @return 结果 */ @Override public int deleteArchiveRecordsById(Long id) { return 0; } @Override public ArchiveInfoVo selectByRecordId(Long id) { return this.baseMapper.findByRecordId(id); } @Override public AjaxResult importExcel(MultipartFile file) { ExcelUtil util = new ExcelUtil<>(ArchiveRecords.class); List dataList = null; try { dataList = util.importExcel(file.getInputStream()); } catch (Exception e) { throw new RuntimeException("没有按照规则导入数据"); } assert dataList != null; for (ArchiveRecords archiveRecords : dataList) { // physcialService.mySave(physcial); this.mySave(archiveRecords); } return AjaxResult.success(); } @Override public List statisticAya() { return this.baseMapper.statisticAyasis(); } public AjaxResult mySave(ArchiveRecords archiveRecords) { //检查是否有重复数据插入 LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(!StringUtils.isEmpty(archiveRecords.getRecordId()), ArchiveRecords::getRecordId,archiveRecords.getRecordId()); List list = list(lqw); if (list.size() > 0) { // throw new RuntimeException("请勿新增重复数据"); //如果有重复数据,则根据recordId进行数据修改 this.baseMapper.update(archiveRecords, lqw); return AjaxResult.success(); } else { if (save(archiveRecords)) { return AjaxResult.success(); } else { return AjaxResult.error(); } } } }