doum
2026-05-26 f4d592f3626f94117d8a4eb22176a28290931980
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package com.doumee.service.business.impl;
 
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.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.Utils;
import com.doumee.dao.business.YwElectricalParamMapper;
import com.doumee.dao.business.model.YwElectricalParam;
import com.doumee.service.business.YwElectricalParamService;
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.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
@Service
public class YwElectricalParamServiceImpl implements YwElectricalParamService {
 
    @Autowired
    private YwElectricalParamMapper ywElectricalParamMapper;
 
    @Override
    public Integer create(YwElectricalParam row) {
        fillPrice(row);
        fillCreate(row);
        ywElectricalParamMapper.insert(row);
        return row.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        ywElectricalParamMapper.deleteById(id);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for (Integer id : ids) {
            deleteById(id);
        }
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        YwElectricalParam upd = new YwElectricalParam();
        upd.setId(id);
        upd.setIsdeleted(Constants.ONE);
        upd.setEdirot(user.getId());
        upd.setEditDate(new Date());
        ywElectricalParamMapper.updateById(upd);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for (Integer id : ids) {
            deleteById(id, user);
        }
    }
 
    @Override
    public void delete(YwElectricalParam ywElectricalParam) {
        UpdateWrapper<YwElectricalParam> deleteWrapper = new UpdateWrapper<>(ywElectricalParam);
        ywElectricalParamMapper.delete(deleteWrapper);
    }
 
    @Override
    public void updateById(YwElectricalParam row) {
        if (row == null || row.getId() == null) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        fillPrice(row);
        if (row.getLoginUserInfo() != null) {
            row.setEdirot(row.getLoginUserInfo().getId());
            row.setEditDate(new Date());
        }
        ywElectricalParamMapper.updateById(row);
    }
 
    @Override
    public void updateByIdInBatch(List<YwElectricalParam> rows) {
        if (CollectionUtils.isEmpty(rows)) {
            return;
        }
        for (YwElectricalParam row : rows) {
            updateById(row);
        }
    }
 
    @Override
    public YwElectricalParam findById(Integer id) {
        YwElectricalParam row = ywElectricalParamMapper.selectById(id);
        if (row == null || Objects.equals(row.getIsdeleted(), Constants.ONE)) {
            return null;
        }
        return row;
    }
 
    @Override
    public YwElectricalParam findOne(YwElectricalParam ywElectricalParam) {
        QueryWrapper<YwElectricalParam> wrapper = new QueryWrapper<>(ywElectricalParam).last("limit 1");
        return ywElectricalParamMapper.selectOne(wrapper);
    }
 
    @Override
    public List<YwElectricalParam> findList(YwElectricalParam ywElectricalParam) {
        QueryWrapper<YwElectricalParam> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(YwElectricalParam::getIsdeleted, Constants.ZERO);
        if (ywElectricalParam != null && ywElectricalParam.getStatus() != null) {
            wrapper.lambda().eq(YwElectricalParam::getStatus, ywElectricalParam.getStatus());
        }
        wrapper.lambda().orderByDesc(YwElectricalParam::getId);
        return ywElectricalParamMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<YwElectricalParam> findPage(PageWrap<YwElectricalParam> pageWrap) {
        IPage<YwElectricalParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwElectricalParam> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.eq(YwElectricalParam::getIsdeleted, Constants.ZERO);
        if (pageWrap.getModel() != null && StringUtils.isNotBlank(pageWrap.getModel().getNameKeyword())) {
            queryWrapper.like(YwElectricalParam::getName, pageWrap.getModel().getNameKeyword().trim());
        }
        queryWrapper.eq(pageWrap.getModel().getStatus() != null, YwElectricalParam::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.orderByDesc(YwElectricalParam::getId);
        IPage<YwElectricalParam> result = ywElectricalParamMapper.selectJoinPage(page, YwElectricalParam.class, queryWrapper);
        return PageData.from(result);
    }
 
    @Override
    public long count(YwElectricalParam ywElectricalParam) {
        QueryWrapper<YwElectricalParam> wrapper = new QueryWrapper<>(ywElectricalParam);
        return ywElectricalParamMapper.selectCount(wrapper);
    }
 
    private void fillPrice(YwElectricalParam row) {
        BigDecimal base = row.getBasePrice() != null ? row.getBasePrice() : BigDecimal.ZERO;
        BigDecimal extra = row.getExtraPrice() != null ? row.getExtraPrice() : BigDecimal.ZERO;
        row.setPrice(base.add(extra));
    }
 
    private void fillCreate(YwElectricalParam row) {
        Date now = new Date();
        row.setCreateDate(now);
        row.setEditDate(now);
        row.setIsdeleted(Constants.ZERO);
        if (row.getStatus() == null) {
            row.setStatus(Constants.ZERO);
        }
        if (row.getLoginUserInfo() != null) {
            row.setCreator(row.getLoginUserInfo().getId());
            row.setEdirot(row.getLoginUserInfo().getId());
        }
    }
}