2021与蓝度共同重构项目,服务端
liuhaonan
2022-02-25 aeec50b8f8ac920884bb2f466cca27e8ee8bc089
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
package com.sandu.ximon.admin.controller;
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageHelper;
import com.sandu.common.domain.ResponseVO;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.util.ResponseUtil;
import com.sandu.ximon.admin.entity.ProgramPro;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.service.ClientService;
import com.sandu.ximon.admin.service.PoleLightemitService;
import com.sandu.ximon.admin.service.XiXunPlayerService;
import com.sandu.ximon.admin.utils.LightemitUtils;
import com.sandu.ximon.dao.domain.LedPlayerEntity;
import com.sandu.ximon.dao.domain.PlayPlanNv;
import com.sandu.ximon.dao.domain.PoleLightemitEntity;
import com.sandu.ximon.dao.domain.PoleXixunPlayerEntity;
import com.sandu.ximon.dao.enums.AdministratorEnums;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import java.util.Date;
import java.util.List;
 
/**
 * @Author liuhaonan
 * @Date 2022/2/22 13:55
 * @Version 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/xixun")
public class XiXunController {
 
    private final XiXunPlayerService xiXunPlayerService;
    private final ClientService clientService;
    private final PoleLightemitService poleLightemitService;
    private final LightemitUtils lightemitUtils;
 
    @PostMapping("/addProgram")
    public ResponseVO<Object> addProgram(@RequestBody ProgramPro programPro){
       return ResponseUtil.success(xiXunPlayerService.insert(programPro));
    }
 
    @PostMapping("/deleteProgram/{pid}")
    public ResponseVO<Object> deleteProgram(@PathVariable Long pid){
        return ResponseUtil.success(xiXunPlayerService.deleteProgram(pid));
    }
 
    @GetMapping("/getByPid/{pid}")
    public ResponseVO<Object> getByPid(@PathVariable Long pid){
        return ResponseUtil.success(xiXunPlayerService.getByPid(pid));
    }
    @GetMapping("/list")
    public ResponseVO<Object> list(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
 
        LambdaQueryWrapper<PoleXixunPlayerEntity> wrapper = Wrappers.lambdaQuery(PoleXixunPlayerEntity.class).like(PoleXixunPlayerEntity::getProgramName, keyword);
//        if(AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())){
//            boolean clientId = clientService.findClientId();
//            if(clientId){
//                wrapper= wrapper.eq(PoleXixunPlayerEntity::getUserId,SecurityUtils.getUserId());
//            }
//            wrapper= wrapper.eq(PoleXixunPlayerEntity::getClientId,clientService.getClientId());
//        }
//        wrapper=Wrappers.lambdaQuery(PoleXixunPlayerEntity.class);
//        if(StrUtil.isNotBlank(keyword)){
//            wrapper.like(PoleXixunPlayerEntity::getLightemitName,keyword).or(
//                    lambdaQueryWrapper -> {
//                        lambdaQueryWrapper.like(PoleXixunPlayerEntity::getLightemitControlCode, keyword);
//                    }
//            );
//        }
//        return ResponseUtil.success(poleLightemitService.list(wrapper));
        if(AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())) {
 
            return ResponseUtil.success(xiXunPlayerService.list(wrapper)); //  todo
        }else {
            return ResponseUtil.success(xiXunPlayerService.list(wrapper));
        }
    }
 
 
    @GetMapping("/pushToXixun/{pid}")
    public ResponseVO<Object> getByPid(@PathVariable Long pid, @RequestBody List<Long> lightemitIds ){
        xiXunPlayerService.videoXixunPlayer(pid,lightemitIds);
        return ResponseUtil.success("推送成功");
    }
 
    @PostMapping("/saveLed")
    public ResponseVO<Object> save(@RequestBody PoleLightemitEntity poleLightemit){
        int count = poleLightemitService.count(new QueryWrapper<PoleLightemitEntity>().eq("lightemit_control_code", poleLightemit.getLightemitControlCode()));
        if(count != 0){
          throw  new BusinessException("LED控制卡编号不能重复");
        }
 
        poleLightemit.setCreateUserId(SecurityUtils.getClientId());
 
        poleLightemitService.savePoleLightemit(poleLightemit);
 
 
        return ResponseUtil.success("新增成功");
    }
 
    @PostMapping("/updateLed/{ledId}")
    public ResponseVO<Object> updatePoleLightemit(@PathVariable Long ledId,@RequestBody PoleLightemitEntity poleLightemit){
        poleLightemitService.updatePoleLightemit(ledId,poleLightemit);
        return ResponseUtil.success("修改成功");
    }
 
    @PostMapping("/deleteLed")
    public ResponseVO<Object> deleteLed(@RequestBody List<Long> ledIds){
        boolean b = poleLightemitService.deletePoleLightemit(ledIds);
        if(b){
            return ResponseUtil.success("删除成功");
        }else {
            return ResponseUtil.success("删除失败");
        }
    }
 
 
    @GetMapping("/listLed")
    public ResponseVO<Object> listLed(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        LambdaQueryWrapper<PoleLightemitEntity> wrapper = Wrappers.lambdaQuery(PoleLightemitEntity.class);
        if(AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())){
            boolean clientId = clientService.findClientId();
            if(clientId){
                wrapper= wrapper.eq(PoleLightemitEntity::getUserId,SecurityUtils.getUserId());
            }
            wrapper= wrapper.eq(PoleLightemitEntity::getClientId,clientService.getClientId());
        }
        wrapper=Wrappers.lambdaQuery(PoleLightemitEntity.class);
        if(StrUtil.isNotBlank(keyword)){
            wrapper.like(PoleLightemitEntity::getLightemitName,keyword).or(
                    lambdaQueryWrapper -> {
                        lambdaQueryWrapper.like(PoleLightemitEntity::getLightemitControlCode, keyword);
                    }
            );
        }
        return ResponseUtil.success(poleLightemitService.list(wrapper));
    }
 
    /*
  获取led实时画面
   */
    @GetMapping("/getPicture/{id}")
    public ResponseVO<Object> getPicture(@PathVariable Long id){
        if(id == null){
           throw new BusinessException("未选择LED屏");
        }
        PoleLightemitEntity poleLightemitEntity = poleLightemitService.getById(id);
        if(poleLightemitEntity != null){
            String result = lightemitUtils.getPicture(poleLightemitEntity.getLightemitControlCode());
            return ResponseUtil.success(result);
        }else {
            throw new BusinessException("未选择LED屏");
        }
    }
}