ChinaMobileRestApiController.java 33 KB
Newer Older
liqin's avatar
liqin committed
1 2 3 4
package cn.wisenergy.chnmuseum.party.web.controller;

import cn.wisenergy.chnmuseum.party.auth.SHA256PasswordEncryptionService;
import cn.wisenergy.chnmuseum.party.auth.util.JwtTokenUtil;
wzp's avatar
wzp committed
5
import cn.wisenergy.chnmuseum.party.common.enums.AuditOperationEnum;
liqin's avatar
liqin committed
6
import cn.wisenergy.chnmuseum.party.common.enums.FileCatEnum;
liqin's avatar
liqin committed
7
import cn.wisenergy.chnmuseum.party.common.enums.FileTypeEnum;
liqin's avatar
liqin committed
8
import cn.wisenergy.chnmuseum.party.common.enums.LanguageEnum;
liqin's avatar
liqin committed
9
import cn.wisenergy.chnmuseum.party.common.util.TimeUtils;
yangtianyou's avatar
yangtianyou committed
10
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
liqin's avatar
liqin committed
11
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
wzp's avatar
wzp committed
12
import cn.wisenergy.chnmuseum.party.model.*;
liqin's avatar
liqin committed
13
import cn.wisenergy.chnmuseum.party.service.*;
wzp's avatar
wzp committed
14
import cn.wisenergy.chnmuseum.party.service.impl.*;
liqin's avatar
liqin committed
15 16
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.alibaba.fastjson.JSONObject;
liqin's avatar
liqin committed
17
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
yangtianyou's avatar
yangtianyou committed
18
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
wzp's avatar
wzp committed
19
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
liqin's avatar
liqin committed
20
import com.baomidou.mybatisplus.core.metadata.IPage;
liqin's avatar
liqin committed
21
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
liqin's avatar
liqin committed
22
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
liqin's avatar
liqin committed
23
import io.swagger.annotations.Api;
liqin's avatar
liqin committed
24 25
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
liqin's avatar
liqin committed
26
import io.swagger.annotations.ApiOperation;
liqin's avatar
liqin committed
27
import lombok.extern.slf4j.Slf4j;
liqin's avatar
liqin committed
28
import org.apache.commons.lang3.StringUtils;
wzp's avatar
wzp committed
29
import org.apache.shiro.authc.DisabledAccountException;
liqin's avatar
liqin committed
30
import org.apache.shiro.authc.IncorrectCredentialsException;
wzp's avatar
wzp committed
31
import org.apache.shiro.authz.annotation.RequiresAuthentication;
liqin's avatar
liqin committed
32 33 34
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
wzp's avatar
wzp committed
35
import org.springframework.scheduling.annotation.Scheduled;
yangtianyou's avatar
yangtianyou committed
36
import org.springframework.validation.annotation.Validated;
liqin's avatar
liqin committed
37 38 39
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
wzp's avatar
wzp committed
40
import java.time.LocalDate;
liqin's avatar
liqin committed
41
import java.time.LocalDateTime;
liqin's avatar
liqin committed
42 43 44
import java.util.HashMap;
import java.util.List;
import java.util.Map;
liqin's avatar
liqin committed
45
import java.util.concurrent.TimeUnit;
liqin's avatar
liqin committed
46
import java.util.stream.Collectors;
liqin's avatar
liqin committed
47

liqin's avatar
liqin committed
48
@Slf4j
liqin's avatar
liqin committed
49 50
@RestController()
@RequestMapping("/cmRestApi")
liqin's avatar
liqin committed
51
@Api(tags = {"中国移动API"})
liqin's avatar
liqin committed
52 53 54 55 56 57 58
public class ChinaMobileRestApiController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ChinaMobileRestApiController.class);

    @Resource
    private StringRedisTemplate stringRedisTemplate;

wzp's avatar
wzp committed
59 60 61
    @Resource
    private TUserServiceImpl userService;

wzp's avatar
wzp committed
62 63 64
    @Resource
    private TOrganServiceImpl organService;

wzp's avatar
wzp committed
65 66 67
    @Resource
    private RunLogServiceImpl runLogService;

wzp's avatar
wzp committed
68 69 70
    @Resource
    private TAreaServiceImpl areaService;

wzp's avatar
wzp committed
71 72 73
    @Resource
    private AssetServiceImpl assetService;

liqin's avatar
liqin committed
74 75 76
    @Resource
    private VideoContentService videoContentService;

wzp's avatar
wzp committed
77 78 79
    @Resource
    private TBoxOperationServiceImpl boxOperationService;

liqin's avatar
liqin committed
80 81 82
    @Resource
    private ExhibitionBoardService exhibitionBoardService;

yangtianyou's avatar
yangtianyou committed
83 84 85
    @Resource
    private TBoardStatisticService tBoardStatisticService;

liqin's avatar
liqin committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    @Resource
    private LearningProjectService learningProjectService;

    @Resource
    private LearningContentService learningContentService;

    @Resource
    private ExhibitionBoardCatService exhibitionBoardCatService;

    @Resource
    private CopyrightOwnerService copyrightOwnerService;

    @Resource
    private LearningContentBoardService learningContentBoardService;

yangtianyou's avatar
yangtianyou committed
101 102 103 104 105 106 107 108 109
    @Resource
    private TAppVersionService appVersionService;

    @Resource
    private TAppDirPicService appDirPicService;

    @Resource
    private TAppRunPicService appRunPicService;

wzp's avatar
wzp committed
110
    private static final String SHIRO_JWT_TOKEN = "shiro:jwt:token:";
liqin's avatar
liqin committed
111 112 113 114 115
    //用户登录次数计数  redisKey 前缀
    private static final String SHIRO_LOGIN_COUNT = "shiro_login_count_";
    //用户登录是否被锁定    一小时 redisKey 前缀
    private static final String SHIRO_IS_LOCK = "shiro_is_lock_";

liqin's avatar
liqin committed
116 117
    @ApiOperation(value = "获取机顶盒密钥", notes = "获取机顶盒密钥")
    @GetMapping("/equitment/key")
wzp's avatar
wzp committed
118
    @RequiresAuthentication  //@RequiresPermissions("equitment:key")
liqin's avatar
liqin committed
119 120 121 122 123 124
    public Map<String, Object> getBoxPrivateKey(@RequestParam(value = "mac") String mac) {
        try {
            final LambdaQueryWrapper<TBoxOperation> queryWrapper = Wrappers.<TBoxOperation>lambdaQuery().eq(TBoxOperation::getMac, mac.trim().toUpperCase());
            final TBoxOperation tBoxOperation = this.boxOperationService.getOne(queryWrapper);
            if (tBoxOperation != null) {
                final String organId = tBoxOperation.getOrganId();
liqin's avatar
liqin committed
125 126
                final TUser tUser = getcurUser();
                if (tUser != null && organId.equals(tUser.getOrgId())) {
liqin's avatar
liqin committed
127 128 129
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("key", tBoxOperation.getPrivateKey());
                    return getResult(jsonObject);
liqin's avatar
liqin committed
130
                } else {
wzp's avatar
wzp committed
131
                    return getFailResult("500", "您无权获取本单位机顶盒密钥");
liqin's avatar
liqin committed
132
                }
liqin's avatar
liqin committed
133
            }
wzp's avatar
wzp committed
134
            return getFailResult("500", "未查询到相关机顶盒信息");
liqin's avatar
liqin committed
135 136 137 138 139 140
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
    }

wzp's avatar
wzp committed
141 142
    @ApiOperation(value = "机顶盒激活状态查询", notes = "机顶盒激活状态查询")
    @GetMapping("/equitment/activity")
wzp's avatar
wzp committed
143
    //@RequiresAuthentication  //@RequiresPermissions("/equitment/activity/")
wzp's avatar
wzp committed
144 145 146 147
    public Map<String, Object> getActivity(@RequestParam(required = true) String mac) {
        try {
            UpdateWrapper<TBoxOperation> wrapper = new UpdateWrapper<>();
            wrapper.eq("mac", mac);
wzp's avatar
wzp committed
148
            TBoxOperation one = boxOperationService.getOne(wrapper);
wzp's avatar
wzp committed
149 150
            HashMap<Object, Object> map = new HashMap<>();
            map.put("activityStatus", false);
wzp's avatar
wzp committed
151
            if (one != null) {
wzp's avatar
wzp committed
152 153 154 155 156 157 158 159
                map.put("activityStatus", true);
            }
            return getResult(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
    }
wzp's avatar
wzp committed
160

liqin's avatar
liqin committed
161
    @RequestMapping(value = "/user/webLogin", method = RequestMethod.POST)
wzp's avatar
wzp committed
162
    public Map<String, Object> login(@RequestParam(value = "username") String username,
liqin's avatar
liqin committed
163
                                            @RequestParam(value = "password") String password,
wzp's avatar
wzp committed
164
                                            @RequestParam(value = "mac") String mac) {
liqin's avatar
liqin committed
165
        JSONObject resultMap = new JSONObject(true);
wzp's avatar
wzp committed
166
        TUser user;
liqin's avatar
liqin committed
167
        if (StringUtils.isNoneBlank(username)) {
wzp's avatar
wzp committed
168

liqin's avatar
liqin committed
169
            try {
wzp's avatar
wzp committed
170
                //访问一次,计数一次
wzp's avatar
wzp committed
171 172 173 174 175 176
//                ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
//                if ("LOCK".equals(opsForValue.get(SHIRO_IS_LOCK + username))) {
//                    resultMap.put("resultCode", "400");
//                    resultMap.put("message", "由于密码输入错误次数大于5次,12小时内帐号已禁止登录!请您联系相关管理人员,联系电话:13924551212,邮箱:325346534@zh.com。");
//                    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
//                }
wzp's avatar
wzp committed
177 178
                user = userService.selectByUsername(username);
                if (user == null) {
wzp's avatar
wzp committed
179
                    resultMap.put("resultCode", "400");
wzp's avatar
wzp committed
180
                    resultMap.put("message", "用户名或密码不正确!");
wzp's avatar
wzp committed
181
                    return resultMap;
wzp's avatar
wzp committed
182
                }
wzp's avatar
wzp committed
183
                TBoxOperation operation = boxOperationService.getOne(new UpdateWrapper<TBoxOperation>().eq("organ_id", user.getOrgId()));
liqin's avatar
liqin committed
184
                if (operation == null || "".equals(operation.getMac())) {
wzp's avatar
wzp committed
185
                    resultMap.put("resultCode", "500");
wzp's avatar
wzp committed
186
                    resultMap.put("message", "用户未激活!");
wzp's avatar
wzp committed
187
                    return resultMap;
wzp's avatar
wzp committed
188
                }
liqin's avatar
liqin committed
189
                if (!mac.equals(operation.getMac())) {
wzp's avatar
wzp committed
190
                    resultMap.put("resultCode", "400");
wzp's avatar
wzp committed
191
                    resultMap.put("message", "mac地址不正确!");
wzp's avatar
wzp committed
192
                    return resultMap;
wzp's avatar
wzp committed
193
                }
wzp's avatar
wzp committed
194
                if (AuditOperationEnum.DISABLE.name().equals(user.getStatus())) {
wzp's avatar
wzp committed
195 196 197 198 199 200 201 202 203 204 205
                    throw new DisabledAccountException("此帐号已禁用,请联系管理员!");
                }

                if (user.getPermanent() != null && !user.getPermanent()) {
                    if (user.getEffectiveDate().isAfter(LocalDate.now()) || user.getExiredDate().isBefore(LocalDate.now())) {
                        throw new DisabledAccountException("此帐号已失效,请联系管理员!");
                    }
                }

                byte[] salt = user.getPasswordSalt();
                if (!new String(SHA256PasswordEncryptionService.createPasswordHash(password, salt)).equals(new String(user.getPasswordHash()))) {
wzp's avatar
wzp committed
206 207 208 209 210 211 212 213 214
//                    opsForValue.increment(SHIRO_LOGIN_COUNT + username, 1);
//                    //计数大于5时,设置用户被锁定一小时
//                    String s = opsForValue.get(SHIRO_LOGIN_COUNT + username);
//                    if (StringUtils.isNotBlank(s)) {
//                        if (Integer.parseInt(s) >= 5) {
//                            opsForValue.set(SHIRO_IS_LOCK + username, "LOCK");
//                            stringRedisTemplate.expire(SHIRO_IS_LOCK + username, 12, TimeUnit.HOURS);
//                        }
//                    }
liqin's avatar
liqin committed
215 216
                    throw new IncorrectCredentialsException("用户名或密码不正确!");
                }
wzp's avatar
wzp committed
217
                String token = JwtTokenUtil.sign(username, user.getId());
liqin's avatar
liqin committed
218
                // 将token信息存入Redis
wzp's avatar
wzp committed
219
                stringRedisTemplate.opsForValue().set(SHIRO_JWT_TOKEN + token, user.getId(), 240, TimeUnit.MINUTES);
liqin's avatar
liqin committed
220 221 222

                JSONObject jsonObject = new JSONObject(true);
                jsonObject.put("token", token);
wzp's avatar
wzp committed
223 224
                jsonObject.put("userId", user.getId());
                jsonObject.put("userName", user.getUserName());
liqin's avatar
liqin committed
225
                jsonObject.put("expire", TimeUtils.format(LocalDateTime.now().plusMinutes(240), TimeUtils.FORMAT_ONE));
wzp's avatar
wzp committed
226 227
                jsonObject.put("orgCode", user.getOrgId());
                jsonObject.put("orgName", user.getOrgName());
liqin's avatar
liqin committed
228

wzp's avatar
wzp committed
229
                resultMap.put("resultCode", "200");
wzp's avatar
wzp committed
230
                resultMap.put("message", "登录成功");
liqin's avatar
liqin committed
231
                resultMap.put("data", jsonObject);
wzp's avatar
wzp committed
232
                return resultMap;
liqin's avatar
liqin committed
233
            } catch (Exception e) {
wzp's avatar
wzp committed
234
                resultMap.put("resultCode", "500");
liqin's avatar
liqin committed
235 236 237
                resultMap.put("message", e.getMessage());
            }
        }
wzp's avatar
wzp committed
238
        return getFailResult(resultMap.get("message"));
liqin's avatar
liqin committed
239 240 241 242
    }

    @ApiOperation(value = "获取单个成员信息")
    @GetMapping(value = "/user/getUserInfo")
wzp's avatar
wzp committed
243
    @RequiresAuthentication
wzp's avatar
wzp committed
244
    public Map<String, Object> getById(String userId) {
wzp's avatar
wzp committed
245
        JSONObject resultMap = new JSONObject(true);
liqin's avatar
liqin committed
246
        try {
wzp's avatar
wzp committed
247
            TUser user = userService.getById(userId);
wzp's avatar
wzp committed
248
            TOrgan organ = organService.getById(user.getOrgId());
liqin's avatar
liqin committed
249

wzp's avatar
wzp committed
250
            if (null == user) {
wzp's avatar
wzp committed
251
                resultMap.put("resultCode", "500");
wzp's avatar
wzp committed
252 253
                resultMap.put("message", "用户不存在");
                resultMap.put("data", "");
wzp's avatar
wzp committed
254
                return resultMap;
liqin's avatar
liqin committed
255 256 257
            }

            JSONObject jsonObject = new JSONObject(true);
wzp's avatar
wzp committed
258 259
            jsonObject.put("userId", user.getId());
            jsonObject.put("userName", user.getUserName());
wzp's avatar
wzp committed
260
//            long expire = stringRedisTemplate.getExpire(SHIRO_JWT_TOKEN + token) == null ? 0L : stringRedisTemplate.getExpire(SHIRO_JWT_TOKEN + token);
wzp's avatar
wzp committed
261 262 263 264
            //jsonObject.put("expire", TimeUtils.format(LocalDateTime.now().plusMinutes(expire), TimeUtils.FORMAT_ONE));
            jsonObject.put("effectiveDate", user.getEffectiveDate());
            jsonObject.put("expireDate", user.getExiredDate());
            jsonObject.put("orgCode", user.getOrgId());
liqin's avatar
liqin committed
265
            jsonObject.put("orgName", organ.getName());
wzp's avatar
wzp committed
266

wzp's avatar
wzp committed
267
            resultMap.put("resultCode", "200");
liqin's avatar
liqin committed
268 269
            resultMap.put("message", "成功");
            resultMap.put("data", jsonObject);
wzp's avatar
wzp committed
270
            return resultMap;
liqin's avatar
liqin committed
271
        } catch (Exception e) {
wzp's avatar
wzp committed
272
            resultMap.put("resultCode", "500");
wzp's avatar
wzp committed
273
            resultMap.put("message", "获取单个成员信息失败!");
liqin's avatar
liqin committed
274
        }
wzp's avatar
wzp committed
275
        return getFailResult();
liqin's avatar
liqin committed
276 277
    }

liqin's avatar
liqin committed
278
    @RequestMapping(value = "/user/logout", method = RequestMethod.GET)
wzp's avatar
wzp committed
279
    @RequiresAuthentication
wzp's avatar
wzp committed
280
    public Map<String, Object> logout() {
wzp's avatar
wzp committed
281
        String token = request.getHeader("Authorization");
wzp's avatar
wzp committed
282
        JSONObject resultMap = new JSONObject(true);
wzp's avatar
wzp committed
283 284 285
        if (token.startsWith("Bearer ")) {
            token = token.substring(7);
        }
liqin's avatar
liqin committed
286 287
        try {
            if (StringUtils.isNotBlank(token)) {
wzp's avatar
wzp committed
288
//                SecurityUtils.getSubject().logout();
wzp's avatar
wzp committed
289

liqin's avatar
liqin committed
290 291
                this.stringRedisTemplate.delete(SHIRO_JWT_TOKEN + token);
            }
wzp's avatar
wzp committed
292
            resultMap.put("resultCode", "200");
liqin's avatar
liqin committed
293 294
            resultMap.put("message", "成功");
            resultMap.put("data", "");
wzp's avatar
wzp committed
295
            return resultMap;
liqin's avatar
liqin committed
296
        } catch (Exception e) {
wzp's avatar
wzp committed
297
            resultMap.put("resultCode", "500");
wzp's avatar
wzp committed
298 299
            resultMap.put("message", "注销错误!");
        }
wzp's avatar
wzp committed
300
        return getFailResult("注销错误!");
wzp's avatar
wzp committed
301 302 303 304 305 306
    }

    /**
     * 插入机顶盒日志表
     */
    @ApiOperation(value = "插入机顶盒日志表", notes = "插入机顶盒日志表")
wzp's avatar
wzp committed
307
    @PostMapping(value = "/equitment/runLog")
wzp's avatar
wzp committed
308
    @RequiresAuthentication
wzp's avatar
wzp committed
309
    public Map<String, Object> insertRunLog(RunLog runLog) {
wzp's avatar
wzp committed
310 311 312 313
        JSONObject resultMap = new JSONObject();

        try {
            boolean b = runLogService.insertRunLog(runLog);
wzp's avatar
wzp committed
314
            resultMap.put("resultCode", "200");
wzp's avatar
wzp committed
315 316
            resultMap.put("message", "成功");
            resultMap.put("data", "");
wzp's avatar
wzp committed
317
            return resultMap;
wzp's avatar
wzp committed
318
        } catch (Exception e) {
wzp's avatar
wzp committed
319
            resultMap.put("resultCode", "500");
wzp's avatar
wzp committed
320 321
            resultMap.put("message", "失败");
            resultMap.put("data", "");
liqin's avatar
liqin committed
322
        }
wzp's avatar
wzp committed
323
        return getFailResult();
liqin's avatar
liqin committed
324 325
    }

wzp's avatar
wzp committed
326 327 328 329 330
    /**
     * 查询语言列表
     */
    @ApiOperation(value = "查询语言列表", notes = "查询语言列表")
    @PostMapping(value = "/language/info")
wzp's avatar
wzp committed
331
    @RequiresAuthentication
wzp's avatar
wzp committed
332
    public Map<String, Object> languageInfo() {
wzp's avatar
wzp committed
333 334 335 336
        JSONObject resultMap = new JSONObject();

        try {
            List<Map<String, String>> list = areaService.languageInfo();
wzp's avatar
wzp committed
337
            resultMap.put("resultCode", "200");
wzp's avatar
wzp committed
338 339
            resultMap.put("message", "成功");
            resultMap.put("data", list);
wzp's avatar
wzp committed
340
            return resultMap;
wzp's avatar
wzp committed
341
        } catch (Exception e) {
wzp's avatar
wzp committed
342
            resultMap.put("resultCode", "500");
wzp's avatar
wzp committed
343 344 345
            resultMap.put("message", "失败");
            resultMap.put("data", "");
        }
wzp's avatar
wzp committed
346
        return getFailResult();
wzp's avatar
wzp committed
347 348
    }

liqin's avatar
liqin committed
349 350 351
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
liqin's avatar
liqin committed
352
            @ApiImplicitParam(name = "learningContentId", value = "学习内容ID", paramType = "query", dataType = "String")
liqin's avatar
liqin committed
353
    })
liqin's avatar
liqin committed
354
    @PostMapping("/exhibitionBoard/getPage")
wzp's avatar
wzp committed
355
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:page")
liqin's avatar
liqin committed
356
    @ApiOperation(value = "展板列表查询", notes = "展板列表查询")
liqin's avatar
liqin committed
357
    public Map<String, Object> getExhibitionBoardPageList(@RequestParam(value = "learningContentId", required = false) String learningContentId) {
liqin's avatar
liqin committed
358
        final IPage<ExhibitionBoard> page = this.learningContentBoardService.getBoardPageByLearningContentId(getPage(), learningContentId, null);
liqin's avatar
liqin committed
359
        for (ExhibitionBoard exhibitionBoard : page.getRecords()) {
liqin's avatar
liqin committed
360 361 362
            exhibitionBoard.setLearningContentId(learningContentId);
            if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
                String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
liqin's avatar
liqin committed
363 364 365 366 367 368
                exhibitionBoard.setBoardCopyrightOwnerName(name);
            }
            if (exhibitionBoard.getExhibitionBoardCatId() != null) {
                String name = this.exhibitionBoardCatService.getById(exhibitionBoard.getExhibitionBoardCatId()).getName();
                exhibitionBoard.setExhibitionBoardCatName(name);
            }
liqin's avatar
liqin committed
369
            if (exhibitionBoard.getVideoContentId() != null) {
liqin's avatar
liqin committed
370
                final VideoContent videoContent = this.videoContentService.getById(exhibitionBoard.getVideoContentId());
liqin's avatar
liqin committed
371
                if (videoContent != null) {
liqin's avatar
liqin committed
372 373
                    exhibitionBoard.setBoardVideoContentThumbnail(videoContent.getThumbnail());
                }
liqin's avatar
liqin committed
374
            }
liqin's avatar
liqin committed
375
            LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getVideoContentId());
liqin's avatar
liqin committed
376
            assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.VIDEO_CONTENT);
liqin's avatar
liqin committed
377 378
            List<Asset> videoList = this.assetService.list(assetQueryWrapper);
            exhibitionBoard.setVideoList(videoList);
liqin's avatar
liqin committed
379
        }
liqin's avatar
liqin committed
380
        return getResult(page);
liqin's avatar
liqin committed
381 382
    }

liqin's avatar
liqin committed
383
    @ApiOperation(value = "展板详情查询", notes = "展板详情查询")
liqin's avatar
liqin committed
384
    @ApiImplicitParams({
liqin's avatar
liqin committed
385
            @ApiImplicitParam(name = "boardId", value = "展板ID", dataType = "String", paramType = "query"),
liqin's avatar
liqin committed
386
            @ApiImplicitParam(name = "language", value = "语言", dataType = "String", paramType = "query")
liqin's avatar
liqin committed
387
    })
liqin's avatar
liqin committed
388
    @GetMapping("/exhibitionBoard/getBoardInfo")
wzp's avatar
wzp committed
389
    @RequiresAuthentication
liqin's avatar
liqin committed
390
    public Map<String, Object> getById(@RequestParam(value = "boardId") String id, @RequestParam(value = "language", required = false) LanguageEnum language) {
liqin's avatar
liqin committed
391
        ExhibitionBoard exhibitionBoard = exhibitionBoardService.getById(id);
liqin's avatar
liqin committed
392 393 394 395 396 397 398 399
        String exhibitionBoardCatId = exhibitionBoard.getExhibitionBoardCatId();
        if (exhibitionBoardCatId != null) {
            exhibitionBoard.setExhibitionBoardCatName(this.exhibitionBoardCatService.getById(exhibitionBoardCatId).getName());
        }
        String boardCopyrightOwnerId = exhibitionBoard.getBoardCopyrightOwnerId();
        if (boardCopyrightOwnerId != null) {
            exhibitionBoard.setBoardCopyrightOwnerName(this.copyrightOwnerService.getById(boardCopyrightOwnerId).getName());
        }
liqin's avatar
liqin committed
400 401 402 403
        if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
            String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
            exhibitionBoard.setVideoContentCopyrightOwnerName(name);
        }
liqin's avatar
liqin committed
404 405 406 407
        if (exhibitionBoard.getVideoContentId() != null) {
            String thumbnail = this.videoContentService.getById(exhibitionBoard.getVideoContentId()).getThumbnail();
            exhibitionBoard.setBoardVideoContentThumbnail(thumbnail);
        }
liqin's avatar
liqin committed
408

liqin's avatar
liqin committed
409 410
        LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
        assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
liqin's avatar
liqin committed
411 412 413
        if (language != null) {
            assetQueryWrapper.eq(Asset::getLanguage, language.name());
        }
liqin's avatar
liqin committed
414 415 416 417 418 419 420
        final List<Asset> audioList = this.assetService.list(assetQueryWrapper);
        exhibitionBoard.setAudioList(audioList);

        assetQueryWrapper.clear();
        assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
        assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_DATUM.name());
        final List<Asset> datumList = this.assetService.list(assetQueryWrapper);
liqin's avatar
liqin committed
421 422 423
        if (language != null) {
            datumList.removeIf(x -> FileTypeEnum.VIDEO.name().equals(x.getFileType()) && !language.name().equals(x.getLanguage()));
        }
liqin's avatar
liqin committed
424 425 426 427 428 429 430 431 432 433
        exhibitionBoard.setDatumList(datumList);

        final String videoContentId = exhibitionBoard.getVideoContentId();
        if (videoContentId != null) {
            final VideoContent videoContent = this.videoContentService.getById(videoContentId);
            exhibitionBoard.setVideoContentName(videoContent.getName());

            assetQueryWrapper.clear();
            assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, videoContentId);
            assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.VIDEO_CONTENT.name());
liqin's avatar
liqin committed
434 435 436
            if (language != null) {
                assetQueryWrapper.eq(Asset::getLanguage, language.name());
            }
liqin's avatar
liqin committed
437 438
            final List<Asset> videoList = this.assetService.list(assetQueryWrapper);
            exhibitionBoard.setVideoList(videoList);
liqin's avatar
liqin committed
439
        }
liqin's avatar
liqin committed
440
        return getResult(exhibitionBoard);
liqin's avatar
liqin committed
441 442
    }

yangtianyou's avatar
yangtianyou committed
443
    @PostMapping("/equitment/playLog")
wzp's avatar
wzp committed
444
    @RequiresAuthentication  //@RequiresPermissions("t:board:statistic:statisticBoardInfo")
yangtianyou's avatar
yangtianyou committed
445 446 447
    @ApiOperation(value = "播放记录信息反馈", notes = "播放记录信息反馈")
    public Map<String, Object> boardStatisticInfo(@Validated(value = {Add.class}) TBoardStatistic tBoardStatistic) {
        // 展板信息统计
liqin's avatar
liqin committed
448 449
        try {
            Object result = tBoardStatisticService.boardStatisticInfo(tBoardStatistic, false);
yangtianyou's avatar
yangtianyou committed
450
            // 返回操作结果
liqin's avatar
liqin committed
451
            if (result != null && (boolean) result) {
yangtianyou's avatar
yangtianyou committed
452 453
                return getSuccessResult();
            }
liqin's avatar
liqin committed
454
        } catch (Exception e) {
yangtianyou's avatar
yangtianyou committed
455 456 457 458 459 460
            e.printStackTrace();
        }
        // 保存失败
        return getFailResult();
    }

wzp's avatar
wzp committed
461 462 463 464 465 466 467 468 469 470 471
    @Scheduled(cron = "0 0/5 * * * *")
    public void boardStatistic(){
        try {
            System.out.println("定时汇总播放记录开始...");
            tBoardStatisticService.boardStatisticInfo(null, true);
            System.out.println("定时汇总播放记录成功...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

liqin's avatar
liqin committed
472 473 474
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
liqin's avatar
liqin committed
475 476
            @ApiImplicitParam(name = "learningProjectId", value = "学习项目ID", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String")
liqin's avatar
liqin committed
477 478
    })
    @PostMapping("/learningContent/getPage")
wzp's avatar
wzp committed
479
    @RequiresAuthentication  //@RequiresPermissions("learning:content:page")
liqin's avatar
liqin committed
480
    @ApiOperation(value = "查询学习内容", notes = "查询学习内容")
liqin's avatar
liqin committed
481 482
    public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam,
                                                          @RequestParam(value = "learningProjectId", required = false) String learningProjectId) {
liqin's avatar
liqin committed
483 484
        LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
485 486 487 488
        if (StringUtils.isNotBlank(learningProjectId)) {
            queryWrapper.eq(LearningContent::getLearningProjectId, learningProjectId);
        }
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502
        if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
            queryWrapper.like(LearningContent::getName, genericPageParam.getNameOrCode());
        }
        // 根据创建时间区间检索
        if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
            queryWrapper.ge(LearningContent::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                    .le(LearningContent::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
        }
        // 设置排序规则
        queryWrapper.orderByDesc(LearningContent::getCreateTime);
        // 设置查询内容
        queryWrapper.select(
                LearningContent::getId,
                LearningContent::getName,
liqin's avatar
liqin committed
503 504 505 506 507
                LearningContent::getCover,
                LearningContent::getApplicableScope,
                LearningContent::getSortorder,
                LearningContent::getPublished,
                LearningContent::getDeleted,
liqin's avatar
liqin committed
508 509 510 511 512 513 514 515 516 517 518 519
                LearningContent::getAuditStatus,
                LearningContent::getCreateTime,
                LearningContent::getUpdateTime);
        Page<LearningContent> page = this.learningContentService.page(getPage(), queryWrapper);
        for (LearningContent learningContent : page.getRecords()) {
            LambdaQueryWrapper<LearningContentBoard> lambdaQueryWrapper = Wrappers.<LearningContentBoard>lambdaQuery().eq(LearningContentBoard::getLearningContentId, learningContent.getId());
            int exhibitionBoardCount = this.learningContentBoardService.count(lambdaQueryWrapper);
            learningContent.setExhibitionBoardCount(exhibitionBoardCount);
        }
        return getResult(page);
    }

liqin's avatar
liqin committed
520 521 522 523 524 525 526
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
    })
liqin's avatar
liqin committed
527
    @PostMapping("/learningProject/getPage")
wzp's avatar
wzp committed
528
    @RequiresAuthentication  //@RequiresPermissions("learning:project:page")
liqin's avatar
liqin committed
529
    @ApiOperation(value = "查询项目", notes = "查询项目")
liqin's avatar
liqin committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
    public Map<String, Object> getLearningProjectPageList(GenericPageParam genericPageParam) {
        LambdaQueryWrapper<LearningProject> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
        if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
            queryWrapper.like(LearningProject::getName, genericPageParam.getNameOrCode());
        }
        // 根据创建时间区间检索
        if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
            queryWrapper.ge(LearningProject::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                    .le(LearningProject::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
        }
        // 设置排序规则
        queryWrapper.orderByDesc(LearningProject::getCreateTime);
        // 设置查询内容
        queryWrapper.select(
                LearningProject::getId,
                LearningProject::getName,
                LearningProject::getRemarks,
                LearningProject::getCreateTime,
                LearningProject::getUpdateTime);
        Page<LearningProject> page = this.learningProjectService.page(getPage(), queryWrapper);
        for (LearningProject learningProject : page.getRecords()) {
            LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery()
                    .eq(LearningContent::getLearningProjectId, learningProject.getId())
liqin's avatar
liqin committed
554
                    .eq(LearningContent::getPublished, true);
liqin's avatar
liqin committed
555 556 557 558 559 560 561 562
            lambdaQueryWrapper.select(LearningContent::getName);
            List<LearningContent> learningContentList = this.learningContentService.list(lambdaQueryWrapper);
            String learningContentNames = learningContentList.stream().map(LearningContent::getName).collect(Collectors.joining("、"));
            learningProject.setLearningContentNames(learningContentNames);
        }
        return getResult(page);
    }

liqin's avatar
liqin committed
563
    @ApiImplicitParams(value = {
liqin's avatar
liqin committed
564 565
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
liqin's avatar
liqin committed
566
            @ApiImplicitParam(name = "boardId", value = "展板内容ID", paramType = "path", dataType = "String", required = true)
liqin's avatar
liqin committed
567
    })
liqin's avatar
liqin committed
568
    @GetMapping("/exhibitionBoard/getRefMaterial/{boardId}")
wzp's avatar
wzp committed
569
    @RequiresAuthentication  //@RequiresPermissions("learning:project:page")
liqin's avatar
liqin committed
570
    @ApiOperation(value = "展板参考资料分页查询", notes = "展板参考资料分页查询")
liqin's avatar
liqin committed
571
    public Map<String, Object> getBoardRefMaterial(@PathVariable(value = "boardId") String boardId) {
liqin's avatar
liqin committed
572
        final ExhibitionBoard exhibitionBoard = this.exhibitionBoardService.getById(boardId);
liqin's avatar
liqin committed
573 574
        final LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
        assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_DATUM.name());
liqin's avatar
liqin committed
575
        final Page<Asset> datumList = this.assetService.page(this.getPage(), assetQueryWrapper);
liqin's avatar
liqin committed
576
        return getResult(datumList);
liqin's avatar
liqin committed
577 578 579 580 581
    }

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
liqin's avatar
liqin committed
582
            @ApiImplicitParam(name = "learningContentId", value = "学习内容ID", paramType = "query", dataType = "String"),
liqin's avatar
liqin committed
583 584 585
            @ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String")
    })
    @PostMapping("/exhibitionBoard/search")
wzp's avatar
wzp committed
586
    @RequiresAuthentication  //@RequiresPermissions("learning:content:board:page")
liqin's avatar
liqin committed
587
    @ApiOperation(value = "模糊搜索查询", notes = "模糊搜索查询")
liqin's avatar
liqin committed
588 589
    public Map<String, Object> getLearningContentBoardPageList(GenericPageParam genericPageParam,
                                                               @RequestParam(value = "learningContentId", required = false) String learningContentId) {
liqin's avatar
liqin committed
590
        IPage<ExhibitionBoard> page = this.learningContentBoardService.getBoardPageByLearningContentId(getPage(), learningContentId, genericPageParam.getNameOrCode());
liqin's avatar
liqin committed
591 592 593
        return getResult(page);
    }

liqin's avatar
liqin committed
594 595 596 597 598
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer")
    })
    @PostMapping("/asset/search")
wzp's avatar
wzp committed
599
    @RequiresAuthentication  //@RequiresPermissions("learning:content:board:page")
liqin's avatar
liqin committed
600 601 602
    @ApiOperation(value = "获取当前用户可查看的视频信息", notes = "获取当前用户可查看的视频信息")
    public Map<String, Object> getAssetPageByOrganId() {
        final TUser tUser = getcurUser();
liqin's avatar
liqin committed
603 604 605 606 607 608
        if (tUser != null && tUser.getOrgCode() != null) {
            final String orgCode = tUser.getOrgCode();
            IPage<Asset> page = this.learningContentBoardService.getAssetPageByOrganCode(getPage(), orgCode);
            return getResult(page);
        }
        return getFailResult("400", "用户未登录");
liqin's avatar
liqin committed
609 610
    }

yangtianyou's avatar
yangtianyou committed
611 612 613 614 615
    @ApiOperation(value = "app最新版本查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "versionNo", value = "app版本号", dataType = "String", paramType = "query")
    })
    @GetMapping(value = "/version/check")
wzp's avatar
wzp committed
616
    @RequiresAuthentication  //@RequiresPermissions("app:version:check")
liqin's avatar
liqin committed
617
    public Map<String, Object> versionCheck(String versionNo) {
yangtianyou's avatar
yangtianyou committed
618 619 620
        TAppVersion current = new TAppVersion();//当前版本
        // 查询最新版本号信息
        QueryWrapper<TAppVersion> qw = new QueryWrapper<>();
liqin's avatar
liqin committed
621
        qw.eq("is_current", 1);
yangtianyou's avatar
yangtianyou committed
622 623
        qw.select().orderByDesc("update_time");
        List<TAppVersion> currentList = appVersionService.list(qw);
liqin's avatar
liqin committed
624
        if (currentList == null || currentList.size() == 0) {
yangtianyou's avatar
yangtianyou committed
625
            return getFailResult("未设置当前版本信息");
liqin's avatar
liqin committed
626
        } else {
yangtianyou's avatar
yangtianyou committed
627 628 629
            current = currentList.get(0);
        }
        Map map = new HashMap();
wzp's avatar
wzp committed
630 631 632 633
        map.put("isLatest", versionNo.equals(current.getAppVersion()));
        map.put("versionNo", current.getAppVersion());
        map.put("versionUrl", current.getApkUrl());
        map.put("updateLog", current.getUpdateLog());
634
        map.put("updateTime", current.getUpdateTime());
yangtianyou's avatar
yangtianyou committed
635 636
        return getResult(map);
    }
liqin's avatar
liqin committed
637 638


yangtianyou's avatar
yangtianyou committed
639 640
    @ApiOperation(value = "app界面图片查询")
    @GetMapping(value = "/app/picSelect")
wzp's avatar
wzp committed
641
    //@RequiresAuthentication  //@RequiresPermissions("app:pic:select")
liqin's avatar
liqin committed
642
    public Map<String, Object> appPicSelect() {
yangtianyou's avatar
yangtianyou committed
643 644 645 646
        TAppDirPic currentDir = null;// 当前目录页面
        TAppRunPic currentRun = null;// 当前运行画面
        // 查询当前目录界面信息
        QueryWrapper<TAppDirPic> qw = new QueryWrapper<>();
liqin's avatar
liqin committed
647
        qw.eq("is_current", 1);
yangtianyou's avatar
yangtianyou committed
648 649
        qw.select().orderByDesc("create_time");
        List<TAppDirPic> currentDirList = appDirPicService.list(qw);
liqin's avatar
liqin committed
650
        if (currentDirList != null && currentDirList.size() > 0) {
yangtianyou's avatar
yangtianyou committed
651 652 653
            currentDir = currentDirList.get(0);
        }
        QueryWrapper<TAppRunPic> qw1 = new QueryWrapper<>();
liqin's avatar
liqin committed
654
        qw1.eq("is_current", 1);
yangtianyou's avatar
yangtianyou committed
655 656
        qw1.select().orderByDesc("create_time");
        List<TAppRunPic> currentRunList = appRunPicService.list(qw1);
liqin's avatar
liqin committed
657
        if (currentRunList != null && currentRunList.size() > 0) {
yangtianyou's avatar
yangtianyou committed
658 659
            currentRun = currentRunList.get(0);
        }
liqin's avatar
liqin committed
660

yangtianyou's avatar
yangtianyou committed
661
        Map map = new HashMap();
wzp's avatar
wzp committed
662 663
        map.put("dirImgUrl", currentDir != null ? currentDir.getAppDirPic() : "未设置目录图片");
        map.put("runImgUrl", currentRun != null ? currentRun.getAppRunPic() : "未设置运行图片");
yangtianyou's avatar
yangtianyou committed
664 665
        return getResult(map);
    }
liqin's avatar
liqin committed
666
}