2021与蓝度共同重构项目,服务端
liuhaonan
2022-08-22 52a3bda95de2e73e5958644f57b2a3d32168a4a1
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
package com.sandu.ximon.admin.service;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.LEDProgramParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.LEDProgram;
import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.LEDProgramMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
@AllArgsConstructor
public class LEDProgramService extends BaseServiceImpl<LEDProgramMapper, LEDProgram> {
 
    private final ClientService clientService;
 
    public boolean addProgram(LEDProgramParam receiveParam) {
 
        LEDProgram led = new LEDProgram();
        led.setUserId(SecurityUtils.getUserId());
        led.setUserName(SecurityUtils.getUsername());
        if (clientService.findClientId()) {
            led.setClientId(clientService.getClientId());
        }
        led.setName(receiveParam.getName());
        led.setPreview(receiveParam.getPreviewUrl());
        led.setWidth(receiveParam.getWidth());
        led.setHeight(receiveParam.getHeight());
        if (receiveParam.getPages() == null) {
            throw new BusinessException("节目内容丢失");
        }
        led.setPages(JSON.toJSONString(receiveParam.getPages()));
        return save(led);
    }
 
 
    public boolean updateProgram(Long pid, LEDProgramParam receiveParam) {
 
        LEDProgram led = getById(pid);
        if (led == null) {
            throw new BusinessException("未找到该节目");
        }
 
        led.setName(receiveParam.getName());
        led.setPreview(receiveParam.getPreviewUrl());
        led.setWidth(receiveParam.getWidth());
        led.setHeight(receiveParam.getHeight());
        if (receiveParam.getPages() == null) {
            throw new BusinessException("节目内容丢失");
        }
        led.setPages(JSON.toJSONString(receiveParam.getPages()));
        return updateById(led);
    }
 
 
    public boolean deleteProgram(Long id) {
        LEDProgram byId = getById(id);
        if (byId == null) {
            throw new BusinessException("未找到该节目");
        }
 
        return removeById(id);
 
    }
 
    public LEDProgramParam getByPid(Long id) {
        LEDProgram byId = getById(id);
        if (byId == null) {
            throw new BusinessException("未找到该节目");
        }
        LEDProgramParam param = new LEDProgramParam();
        param.setId(byId.getId());
        param.setHeight(byId.getHeight());
        param.setWidth(byId.getWidth());
        param.setName(byId.getName());
        param.setPreviewUrl(byId.getPreview());
        param.setPages(JSON.parseObject(byId.getPages(), List.class));
        return param;
    }
 
    public List<LEDProgram> listProgram(BaseConditionVO baseConditionVO, Integer order, Integer seq, String keyword) {
        LambdaQueryWrapper<LEDProgram> wrapper = listPrograms();
 
        if (keyword != null && !keyword.isEmpty()) {
            wrapper.like(LEDProgram::getName, keyword);
        }
        //排序字段
        String orderByResult = "id";
        //正序、倒叙
        String orderBySeq = OrderByEnums.ASC.getCode();
        if (order != null) {
            switch (order) {
                case 1:
                    orderByResult = OrderByEnums.LED_N_PROGRAM_CREATE_TIME.getCode();
                    break;
                default:
            }
        }
        if (seq != null) {
            switch (seq) {
                case 1:
                    orderBySeq = OrderByEnums.ASC.getCode();
                    break;
                case 2:
                    orderBySeq = OrderByEnums.DESC.getCode();
                    break;
                default:
                    break;
            }
        }
        //排序方式
        String orderBy = orderByResult + " " + orderBySeq;
 
        if (baseConditionVO != null) {
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy);
        }
        return list(wrapper);
    }
 
    public List<LEDProgram> listProgramOnBinding(String keyword) {
        LambdaQueryWrapper<LEDProgram> wrapper = listPrograms();
 
        if (keyword != null && !keyword.isEmpty()) {
            wrapper.like(LEDProgram::getName, keyword);
        }
 
        return list(wrapper);
    }
 
 
    public LambdaQueryWrapper<LEDProgram> listPrograms() {
        if (SecurityUtils.getClientId() == null) {
            return Wrappers.lambdaQuery(LEDProgram.class);
        } else {
            return Wrappers.lambdaQuery(LEDProgram.class).eq(LEDProgram::getUserId, SecurityUtils.getUserId())
                    .or(w -> {
                        w.eq(LEDProgram::getClientId, SecurityUtils.getClientId());
                    });
        }
    }
}