renkang
2026-04-03 9da725bbfc582042a5a448bff5a2eb990527fda2
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
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwElectricalLogMapper;
import com.doumee.dao.business.model.YwElectricalLog;
import com.doumee.service.business.YwElectricalLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 电器类操作日志Service实现
 * @author renkang
 * @date 2026/04/03
 */
@Service
public class YwElectricalLogServiceImpl implements YwElectricalLogService {
 
    @Autowired
    private YwElectricalLogMapper ywElectricalLogMapper;
 
    @Override
    public Integer create(YwElectricalLog ywElectricalLog) {
        if (Objects.isNull(ywElectricalLog)
                || StringUtils.isBlank(ywElectricalLog.getName())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo loginUserInfo = ywElectricalLog.getLoginUserInfo();
        ywElectricalLog.setCreateDate(new Date());
        ywElectricalLog.setCreator(loginUserInfo.getId());
        ywElectricalLog.setEditDate(new Date());
        ywElectricalLog.setEditor(loginUserInfo.getId());
        ywElectricalLog.setIsdeleted(Constants.ZERO);
        ywElectricalLogMapper.insert(ywElectricalLog);
        return ywElectricalLog.getId();
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        ywElectricalLogMapper.update(new UpdateWrapper<YwElectricalLog>()
                .lambda()
                .set(YwElectricalLog::getIsdeleted, Constants.ONE)
                .set(YwElectricalLog::getEditDate, DateUtil.getCurrDateTime())
                .set(YwElectricalLog::getEditor, user.getId())
                .eq(YwElectricalLog::getId, id)
        );
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for (Integer id : ids) {
            this.deleteById(id, user);
        }
    }
 
    @Override
    public void updateById(YwElectricalLog ywElectricalLog) {
        if (Objects.isNull(ywElectricalLog) || Objects.isNull(ywElectricalLog.getId())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo loginUserInfo = ywElectricalLog.getLoginUserInfo();
        ywElectricalLog.setEditDate(new Date());
        ywElectricalLog.setEditor(loginUserInfo.getId());
        ywElectricalLogMapper.updateById(ywElectricalLog);
    }
 
    @Override
    public YwElectricalLog findById(Integer id) {
        return ywElectricalLogMapper.selectOne(new QueryWrapper<YwElectricalLog>().lambda()
                .eq(YwElectricalLog::getId, id)
                .last(" limit 1 "));
    }
 
    @Override
    public PageData<YwElectricalLog> findPage(PageWrap<YwElectricalLog> pageWrap) {
        IPage<YwElectricalLog> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwElectricalLog> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        YwElectricalLog model = pageWrap.getModel();
        queryWrapper.selectAll(YwElectricalLog.class)
                .and(Objects.nonNull(model) && StringUtils.isNotBlank(model.getName()),
                        i -> i.like(YwElectricalLog::getName, model.getName()))
                .eq(Objects.nonNull(model) && Objects.nonNull(model.getDeviceType()), YwElectricalLog::getDeviceType, model.getDeviceType())
                .eq(Objects.nonNull(model) && Objects.nonNull(model.getType()), YwElectricalLog::getType, model.getType())
                .eq(Objects.nonNull(model) && Objects.nonNull(model.getSuccess()), YwElectricalLog::getSuccess, model.getSuccess())
                .eq(YwElectricalLog::getIsdeleted, Constants.ZERO)
                .orderByDesc(YwElectricalLog::getCreateDate);
        IPage<YwElectricalLog> iPage = ywElectricalLogMapper.selectJoinPage(page, YwElectricalLog.class, queryWrapper);
        return PageData.from(iPage);
    }
}