吉安感知网项目-后端
linwei
2026-01-26 94c833f5908453da5957809ec97873df930bcfa6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.sxkj.fw.record.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.sxkj.fw.record.entity.FwAlarmFavoriteEntity;
import org.sxkj.fw.record.excel.FwAlarmFavoriteExcel;
import org.sxkj.fw.record.mapper.FwAlarmFavoriteMapper;
import org.sxkj.fw.record.service.IFwAlarmFavoriteService;
import org.sxkj.fw.record.vo.FwAlarmFavoriteVO;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 告警记录关注表 服务实现类
 *
 * @author lw
 * @since 2026-01-23
 */
@Service
public class FwAlarmFavoriteServiceImpl extends BaseServiceImpl<FwAlarmFavoriteMapper, FwAlarmFavoriteEntity> implements IFwAlarmFavoriteService {
 
    @Override
    public IPage<FwAlarmFavoriteVO> selectFwAlarmFavoritePage(IPage<FwAlarmFavoriteVO> page, FwAlarmFavoriteVO fwAlarmFavorite) {
        return page.setRecords(baseMapper.selectFwAlarmFavoritePage(page, fwAlarmFavorite));
    }
 
 
    @Override
    public List<FwAlarmFavoriteExcel> exportFwAlarmFavorite(Wrapper<FwAlarmFavoriteEntity> queryWrapper) {
        List<FwAlarmFavoriteExcel> fwAlarmFavoriteList = baseMapper.exportFwAlarmFavorite(queryWrapper);
        // fwAlarmFavoriteList.forEach(fwAlarmFavorite -> {
        //    fwAlarmFavorite.setTypeName(DictCache.getValue(DictEnum.YES_NO, FwAlarmFavorite.getType()));
        //});
        return fwAlarmFavoriteList;
    }
 
    /**
     *
     * @param longList
     * @return
     */
    @Override
    public boolean cancelFavorite(List<Long> longList) {
        List<FwAlarmFavoriteEntity> list = list(Wrappers.<FwAlarmFavoriteEntity>lambdaQuery()
            .in(FwAlarmFavoriteEntity::getAlarmRecordId, longList)
            .eq(FwAlarmFavoriteEntity::getUserId, AuthUtil.getUserId()));
        List<Long> collect = list.stream().map(item -> item.getId()).collect(Collectors.toList());
        return deleteLogic(collect);
    }
 
    /**
     * 关注接口
     * @param fwAlarmFavoriteEntity 关注实体
     * @return boolean 是否操作成功
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveFwAlarmFavorite(FwAlarmFavoriteEntity fwAlarmFavoriteEntity) {
        // 查询是否存在记录(包括已删除)
        FwAlarmFavoriteEntity existingEntity = baseMapper.selectOne(Wrappers.<FwAlarmFavoriteEntity>lambdaQuery()
            .eq(FwAlarmFavoriteEntity::getAlarmRecordId, fwAlarmFavoriteEntity.getAlarmRecordId())
            .eq(FwAlarmFavoriteEntity::getUserId, fwAlarmFavoriteEntity.getUserId())
        );
 
        if (existingEntity != null) {
            // 已关注状态
            if (existingEntity.getIsDeleted() == 0) {
                return true;
            }
            // 恢复已删除记录
            existingEntity.setIsDeleted(0);
            existingEntity.setTitle(fwAlarmFavoriteEntity.getTitle());
            existingEntity.setRemark(fwAlarmFavoriteEntity.getRemark());
            existingEntity.setUpdateUser(AuthUtil.getUserId());
            return updateById(existingEntity);
        }
 
        // 新增记录
        fwAlarmFavoriteEntity.setIsDeleted(0);
        fwAlarmFavoriteEntity.setCreateUser(AuthUtil.getUserId());
        return save(fwAlarmFavoriteEntity);
    }
}