吉安感知网项目-后端
rain
2026-01-09 3ae46f2a59f9d4e751f78d8dc1a896ceba5ca495
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
106
107
108
109
110
111
112
113
114
115
116
/*
 *      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.area.service.impl;
 
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.sxkj.common.utils.HeaderUtils;
import org.sxkj.fw.area.entity.FwDefenseSceneEntity;
import org.sxkj.fw.area.vo.FwDefenseSceneVO;
import org.sxkj.fw.area.excel.FwDefenseSceneExcel;
import org.sxkj.fw.area.mapper.FwDefenseSceneMapper;
import org.sxkj.fw.area.service.IFwDefenseSceneService;
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.util.List;
import java.util.Date;
 
/**
 * 防控场景表 服务实现类
 *
 * @author lw
 * @since 2026-01-08
 */
@Service
public class FwDefenseSceneServiceImpl extends BaseServiceImpl<FwDefenseSceneMapper, FwDefenseSceneEntity> implements IFwDefenseSceneService {
 
    @Override
    public IPage<FwDefenseSceneVO> selectFwDefenseScenePage(IPage<FwDefenseSceneVO> page, FwDefenseSceneVO fwDefenseScene) {
        return page.setRecords(baseMapper.selectFwDefenseScenePage(page, fwDefenseScene));
    }
 
 
    @Override
    public List<FwDefenseSceneExcel> exportFwDefenseScene(Wrapper<FwDefenseSceneEntity> queryWrapper) {
        List<FwDefenseSceneExcel> fwDefenseSceneList = baseMapper.exportFwDefenseScene(queryWrapper);
        //fwDefenseSceneList.forEach(fwDefenseScene -> {
        //    fwDefenseScene.setTypeName(DictCache.getValue(DictEnum.YES_NO, FwDefenseScene.getType()));
        //});
        return fwDefenseSceneList;
    }
 
    @Override
    public boolean save(FwDefenseSceneEntity fwDefenseScene) {
        fillCreateFields(fwDefenseScene);
        return super.save(fwDefenseScene);
    }
 
    @Override
    public boolean updateById(FwDefenseSceneEntity fwDefenseScene) {
        fillUpdateFields(fwDefenseScene);
        return super.updateById(fwDefenseScene);
    }
 
    @Override
    public boolean saveOrUpdate(FwDefenseSceneEntity fwDefenseScene) {
        if (fwDefenseScene.getId() == null) {
            fillCreateFields(fwDefenseScene);
        } else {
            fillUpdateFields(fwDefenseScene);
        }
        return super.saveOrUpdate(fwDefenseScene);
    }
 
    private void fillCreateFields(FwDefenseSceneEntity fwDefenseScene) {
        Long userId = AuthUtil.getUserId();
        String deptIdStr = AuthUtil.getDeptId();
        Long deptId = null;
        if (StringUtil.isNotBlank(deptIdStr)) {
            try {
                deptId = Long.valueOf(deptIdStr);
            } catch (NumberFormatException ignored) {
                deptId = null;
            }
        }
        String areaCode = HeaderUtils.getAreaCode();
        if (StringUtil.isBlank(areaCode)) {
            areaCode = fwDefenseScene.getAreaCode();
        }
        Date now = new Date();
        fwDefenseScene.setCreateUser(userId);
        fwDefenseScene.setUpdateUser(userId);
        if (deptId != null) {
            fwDefenseScene.setCreateDept(deptId);
        }
        if (StringUtil.isNotBlank(areaCode)) {
            fwDefenseScene.setAreaCode(areaCode);
        }
        fwDefenseScene.setCreateTime(now);
        fwDefenseScene.setUpdateTime(now);
    }
 
    private void fillUpdateFields(FwDefenseSceneEntity fwDefenseScene) {
        Long userId = AuthUtil.getUserId();
        if (userId != null) {
            fwDefenseScene.setUpdateUser(userId);
        }
        fwDefenseScene.setUpdateTime(new Date());
    }
 
}