ChinaMobileRestApiController.java 29.2 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;
liqin's avatar
liqin committed
5
import cn.wisenergy.chnmuseum.party.common.enums.LanguageEnum;
liqin's avatar
liqin committed
6
import cn.wisenergy.chnmuseum.party.common.util.TimeUtils;
yangtianyou's avatar
yangtianyou committed
7
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
liqin's avatar
liqin committed
8
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
liqin's avatar
liqin committed
9
import cn.wisenergy.chnmuseum.party.common.vo.VideoVo;
wzp's avatar
wzp committed
10
import cn.wisenergy.chnmuseum.party.model.*;
liqin's avatar
liqin committed
11
import cn.wisenergy.chnmuseum.party.service.*;
wzp's avatar
wzp committed
12
import cn.wisenergy.chnmuseum.party.service.impl.*;
liqin's avatar
liqin committed
13 14
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.alibaba.fastjson.JSONObject;
liqin's avatar
liqin committed
15 16
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
liqin's avatar
liqin committed
17
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
wzp's avatar
wzp committed
18
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
liqin's avatar
liqin committed
19
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
liqin's avatar
liqin committed
20
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
liqin's avatar
liqin committed
21
import io.swagger.annotations.Api;
liqin's avatar
liqin committed
22 23
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
liqin's avatar
liqin committed
24
import io.swagger.annotations.ApiOperation;
liqin's avatar
liqin committed
25
import lombok.extern.slf4j.Slf4j;
liqin's avatar
liqin committed
26
import org.apache.commons.lang3.StringUtils;
wzp's avatar
wzp committed
27
import org.apache.shiro.authc.DisabledAccountException;
liqin's avatar
liqin committed
28
import org.apache.shiro.authc.IncorrectCredentialsException;
yangtianyou's avatar
yangtianyou committed
29
import org.apache.shiro.authz.annotation.RequiresPermissions;
liqin's avatar
liqin committed
30 31 32 33 34 35
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;
wzp's avatar
wzp committed
42 43
import java.util.List;
import java.util.Map;
liqin's avatar
liqin committed
44
import java.util.concurrent.TimeUnit;
liqin's avatar
liqin committed
45
import java.util.stream.Collectors;
liqin's avatar
liqin committed
46

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

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

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private EmployeeServiceImpl employeeService;

wzp's avatar
wzp committed
61 62 63 64 65 66
    @Resource
    private TUserServiceImpl userService;

    @Resource
    private RunLogServiceImpl runLogService;

liqin's avatar
liqin committed
67 68 69
    @Resource
    private SysLogController sysLogController;

wzp's avatar
wzp committed
70 71 72
    @Resource
    private TAreaServiceImpl areaService;

wzp's avatar
wzp committed
73 74 75
    @Resource
    private TBoxOperationServiceImpl boxOperationService;

liqin's avatar
liqin committed
76 77 78
    @Resource
    private ExhibitionBoardService exhibitionBoardService;

yangtianyou's avatar
yangtianyou committed
79 80 81
    @Resource
    private TBoardStatisticService tBoardStatisticService;

liqin's avatar
liqin committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    @Resource
    private LearningProjectService learningProjectService;

    @Resource
    private LearningContentService learningContentService;

    @Resource
    private ExhibitionBoardCatService exhibitionBoardCatService;

    @Resource
    private CopyrightOwnerService copyrightOwnerService;

    @Resource
    private LearningContentBoardService learningContentBoardService;

liqin's avatar
liqin committed
97 98 99
    @Resource
    private AssetService assetService;

liqin's avatar
liqin committed
100 101 102 103 104 105
    private static final String SHIRO_JWT_TOKEN = "shiro:jwt:token:";
    //用户登录次数计数  redisKey 前缀
    private static final String SHIRO_LOGIN_COUNT = "shiro_login_count_";
    //用户登录是否被锁定    一小时 redisKey 前缀
    private static final String SHIRO_IS_LOCK = "shiro_is_lock_";

wzp's avatar
wzp committed
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
//    /**
//     * 管理员ajax登录请求 后端用户登录
//     *
//     * @param username
//     * @param password
//     * @return
//     */
//    @RequestMapping(value = "/user/webLogin", method = RequestMethod.POST)
//    public ResponseEntity<JSONObject> login(@RequestParam(value = "username") String username,
//                                            @RequestParam(value = "password") String password,
//                                            @RequestParam(value = "boxNo") String boxNo) {
//        JSONObject resultMap = new JSONObject(true);
//        Employee employee;
//        if (StringUtils.isNoneBlank(username)) {
//            //访问一次,计数一次
//            ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
//            if ("LOCK".equals(opsForValue.get(SHIRO_IS_LOCK + username))) {
//                resultMap.put("status", 400);
//                resultMap.put("message", "由于密码输入错误次数大于5次,12小时内帐号已禁止登录!请您联系相关管理人员,联系电话:13924551212,邮箱:325346534@zh.com。");
//                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
//            }
//            employee = employeeService.selectByUsername(username);
//            if (employee == null) {
//                resultMap.put("status", 500);
//                resultMap.put("message", "用户名或密码不正确!");
//                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
//            }
//            try {
//                byte[] salt = employee.getPasswordSalt();
//                if (!new String(SHA256PasswordEncryptionService.createPasswordHash(password, salt)).equals(new String(employee.getPasswordHash()))) {
//                    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);
//                        }
//                    }
//                    throw new IncorrectCredentialsException("用户名或密码不正确!");
//                }
//                String token = JwtTokenUtil.sign(username, employee.getId());
//                // 将token信息存入Redis
//                stringRedisTemplate.opsForValue().set(SHIRO_JWT_TOKEN + token, employee.getId(), 240, TimeUnit.MINUTES);
//
//                JSONObject jsonObject = new JSONObject(true);
//                jsonObject.put("token", token);
//                jsonObject.put("userId", employee.getId());
//                jsonObject.put("userName", employee.getUsername());
//                jsonObject.put("expire", TimeUtils.format(LocalDateTime.now().plusMinutes(240), TimeUtils.FORMAT_ONE));
//                jsonObject.put("orgCode", "");
//                jsonObject.put("orgName", "");
//
//                resultMap.put("resultCode", 200);
//                resultMap.put("message", "成功");
//                resultMap.put("data", jsonObject);
//                return ResponseEntity.status(HttpStatus.OK).body(resultMap);
//            } catch (Exception e) {
//                resultMap.put("status", 500);
//                resultMap.put("message", e.getMessage());
//            }
//        }
//        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
//    }
//
//    @ApiOperation(value = "获取单个成员信息")
//    @GetMapping(value = "/user/getUserInfo")
//    public ResponseEntity<JSONObject> getById(String userId, @RequestHeader("token") String token) {
//        try {
//            Employee employee = employeeService.selectByEmpId(userId);
//
//            if (null == employee) {
//                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
//            }
//
//            JSONObject jsonObject = new JSONObject(true);
//            jsonObject.put("token", token);
//            jsonObject.put("userId", employee.getId());
//            jsonObject.put("userName", employee.getUsername());
//            long expire = stringRedisTemplate.getExpire(SHIRO_JWT_TOKEN + token) == null ? 0L : stringRedisTemplate.getExpire(SHIRO_JWT_TOKEN + token);
//            jsonObject.put("expire", TimeUtils.format(LocalDateTime.now().plusMinutes(expire), TimeUtils.FORMAT_ONE));
////          BankBranchInfo bankBranch = this.employeeService.getById(Id);
////          if (bankBranch != null) {
////               employee.setBankBranchName(bankBranch.getName());
////          }
//            jsonObject.put("orgCode", "");
//            jsonObject.put("orgName", "");
//
//            JSONObject resultMap = new JSONObject(true);
//            resultMap.put("resultCode", 200);
//            resultMap.put("message", "成功");
//            resultMap.put("data", jsonObject);
//            return ResponseEntity.ok(resultMap);
//        } catch (Exception e) {
//            logger.error("查询成员信息错误!", e);
//        }
//        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
//    }


liqin's avatar
liqin committed
206 207 208 209 210 211 212 213 214 215
    /**
     * 管理员ajax登录请求 后端用户登录
     *
     * @param username
     * @param password
     * @return
     */
    @RequestMapping(value = "/user/webLogin", method = RequestMethod.POST)
    public ResponseEntity<JSONObject> login(@RequestParam(value = "username") String username,
                                            @RequestParam(value = "password") String password,
wzp's avatar
wzp committed
216
                                            @RequestParam(value = "mac") String mac) {
liqin's avatar
liqin committed
217
        JSONObject resultMap = new JSONObject(true);
wzp's avatar
wzp committed
218
        TUser user;
liqin's avatar
liqin committed
219
        if (StringUtils.isNoneBlank(username)) {
wzp's avatar
wzp committed
220

liqin's avatar
liqin committed
221
            try {
wzp's avatar
wzp committed
222 223 224 225 226 227 228 229 230 231 232 233 234
                //访问一次,计数一次
                ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
                if ("LOCK".equals(opsForValue.get(SHIRO_IS_LOCK + username))) {
                    resultMap.put("status", 400);
                    resultMap.put("message", "由于密码输入错误次数大于5次,12小时内帐号已禁止登录!请您联系相关管理人员,联系电话:13924551212,邮箱:325346534@zh.com。");
                    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
                }
                user = userService.selectByUsername(username);
                if (user == null) {
                    resultMap.put("status", 500);
                    resultMap.put("message", "用户名或密码不正确!");
                    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
                }
wzp's avatar
wzp committed
235
                TBoxOperation operation = boxOperationService.getOne(new UpdateWrapper<TBoxOperation>().eq("organ_id", user.getOrgId()));
liqin's avatar
liqin committed
236
                if (operation == null || "".equals(operation.getMac())) {
wzp's avatar
wzp committed
237 238 239 240
                    resultMap.put("status", 500);
                    resultMap.put("message", "用户未激活!");
                    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
                }
liqin's avatar
liqin committed
241
                if (!mac.equals(operation.getMac())) {
wzp's avatar
wzp committed
242 243 244 245
                    resultMap.put("status", 500);
                    resultMap.put("message", "mac地址不正确!");
                    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
                }
wzp's avatar
wzp committed
246 247 248 249 250 251 252 253 254 255 256 257
                if ("2".equals(user.getStatus())) {
                    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()))) {
liqin's avatar
liqin committed
258 259 260 261 262 263 264 265 266 267 268
                    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);
                        }
                    }
                    throw new IncorrectCredentialsException("用户名或密码不正确!");
                }
wzp's avatar
wzp committed
269
                String token = JwtTokenUtil.sign(username, user.getId());
liqin's avatar
liqin committed
270
                // 将token信息存入Redis
wzp's avatar
wzp committed
271
                stringRedisTemplate.opsForValue().set(SHIRO_JWT_TOKEN + token, user.getId(), 240, TimeUnit.MINUTES);
liqin's avatar
liqin committed
272 273 274

                JSONObject jsonObject = new JSONObject(true);
                jsonObject.put("token", token);
wzp's avatar
wzp committed
275 276
                jsonObject.put("userId", user.getId());
                jsonObject.put("userName", user.getUserName());
liqin's avatar
liqin committed
277
                jsonObject.put("expire", TimeUtils.format(LocalDateTime.now().plusMinutes(240), TimeUtils.FORMAT_ONE));
wzp's avatar
wzp committed
278 279
                jsonObject.put("orgCode", user.getOrgId());
                jsonObject.put("orgName", user.getOrgName());
liqin's avatar
liqin committed
280 281

                resultMap.put("resultCode", 200);
wzp's avatar
wzp committed
282
                resultMap.put("message", "登录成功");
liqin's avatar
liqin committed
283 284 285
                resultMap.put("data", jsonObject);
                return ResponseEntity.status(HttpStatus.OK).body(resultMap);
            } catch (Exception e) {
wzp's avatar
wzp committed
286
                resultMap.put("resultCode", 500);
liqin's avatar
liqin committed
287 288 289 290 291 292 293 294
                resultMap.put("message", e.getMessage());
            }
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
    }

    @ApiOperation(value = "获取单个成员信息")
    @GetMapping(value = "/user/getUserInfo")
wzp's avatar
wzp committed
295
    public ResponseEntity<JSONObject> getById(String userId) {
wzp's avatar
wzp committed
296
        JSONObject resultMap = new JSONObject(true);
liqin's avatar
liqin committed
297
        try {
wzp's avatar
wzp committed
298
            TUser user = userService.getById(userId);
liqin's avatar
liqin committed
299

wzp's avatar
wzp committed
300 301 302 303
            if (null == user) {
                resultMap.put("resultCode", 500);
                resultMap.put("message", "用户不存在");
                resultMap.put("data", "");
liqin's avatar
liqin committed
304 305 306 307
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }

            JSONObject jsonObject = new JSONObject(true);
wzp's avatar
wzp committed
308 309
            jsonObject.put("userId", user.getId());
            jsonObject.put("userName", user.getUserName());
wzp's avatar
wzp committed
310
//            long expire = stringRedisTemplate.getExpire(SHIRO_JWT_TOKEN + token) == null ? 0L : stringRedisTemplate.getExpire(SHIRO_JWT_TOKEN + token);
wzp's avatar
wzp committed
311 312 313 314 315 316
            //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());
            jsonObject.put("orgName", user.getOrgName());

liqin's avatar
liqin committed
317 318 319 320 321
            resultMap.put("resultCode", 200);
            resultMap.put("message", "成功");
            resultMap.put("data", jsonObject);
            return ResponseEntity.ok(resultMap);
        } catch (Exception e) {
wzp's avatar
wzp committed
322 323
            resultMap.put("resultCode", 500);
            resultMap.put("message", "获取单个成员信息失败!");
liqin's avatar
liqin committed
324
        }
wzp's avatar
wzp committed
325
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
liqin's avatar
liqin committed
326 327
    }

liqin's avatar
liqin committed
328
    @RequestMapping(value = "/user/logout", method = RequestMethod.GET)
wzp's avatar
wzp committed
329 330
    public ResponseEntity<JSONObject> logout() {
        String token = request.getHeader("Authorization");
wzp's avatar
wzp committed
331
        JSONObject resultMap = new JSONObject(true);
liqin's avatar
liqin committed
332 333
        try {
            if (StringUtils.isNotBlank(token)) {
wzp's avatar
wzp committed
334
//                SecurityUtils.getSubject().logout();
liqin's avatar
liqin committed
335 336 337 338 339 340 341
                this.stringRedisTemplate.delete(SHIRO_JWT_TOKEN + token);
            }
            resultMap.put("resultCode", 200);
            resultMap.put("message", "成功");
            resultMap.put("data", "");
            return ResponseEntity.status(HttpStatus.OK).body(resultMap);
        } catch (Exception e) {
wzp's avatar
wzp committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
            resultMap.put("resultCode", 500);
            resultMap.put("message", "注销错误!");
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
    }

    /**
     * 插入机顶盒日志表
     */
    @ApiOperation(value = "插入机顶盒日志表", notes = "插入机顶盒日志表")
    @PostMapping(value = "/insertRunLog")
    public ResponseEntity<JSONObject> insertRunLog(RunLog runLog) {
        JSONObject resultMap = new JSONObject();

        try {
            boolean b = runLogService.insertRunLog(runLog);
            resultMap.put("resultCode", 200);
            resultMap.put("message", "成功");
            resultMap.put("data", "");
            return ResponseEntity.status(HttpStatus.OK).body(resultMap);
        } catch (Exception e) {
            resultMap.put("resultCode", 500);
            resultMap.put("message", "失败");
            resultMap.put("data", "");
liqin's avatar
liqin committed
366
        }
wzp's avatar
wzp committed
367
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
liqin's avatar
liqin committed
368 369
    }

wzp's avatar
wzp committed
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
    /**
     * 查询语言列表
     */
    @ApiOperation(value = "查询语言列表", notes = "查询语言列表")
    @PostMapping(value = "/language/info")
    public ResponseEntity<JSONObject> languageInfo() {
        JSONObject resultMap = new JSONObject();

        try {
            List<Map<String, String>> list = areaService.languageInfo();
            resultMap.put("resultCode", 200);
            resultMap.put("message", "成功");
            resultMap.put("data", list);
            return ResponseEntity.status(HttpStatus.OK).body(resultMap);
        } catch (Exception e) {
            resultMap.put("resultCode", 500);
            resultMap.put("message", "失败");
            resultMap.put("data", "");
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
    }

liqin's avatar
liqin committed
392 393 394 395
    @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"),
liqin's avatar
liqin committed
396
            @ApiImplicitParam(name = "copyrightOwner", value = "版权方", paramType = "query", dataType = "String"),
liqin's avatar
liqin committed
397 398 399
            @ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
    })
liqin's avatar
liqin committed
400
    @PostMapping("/exhibitionBoard/getPage")
liqin's avatar
liqin committed
401
    @RequiresPermissions("exhibition:board:page")
liqin's avatar
liqin committed
402
    @ApiOperation(value = "获取展板分页列表", notes = "获取展板分页列表")
liqin's avatar
liqin committed
403
    public Map<String, Object> getExhibitionBoardPageList(GenericPageParam genericPageParam) {
liqin's avatar
liqin committed
404 405 406 407 408 409
        LambdaQueryWrapper<ExhibitionBoard> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
        if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
            queryWrapper.like(ExhibitionBoard::getName, genericPageParam.getNameOrCode());
        }
        // 对版权方模糊查询
liqin's avatar
liqin committed
410
        if (StringUtils.isNotBlank(genericPageParam.getBoardCopyrightOwnerId())) {
liqin's avatar
liqin committed
411
            queryWrapper.like(ExhibitionBoard::getAssetCopyrightOwnerId, genericPageParam.getBoardCopyrightOwnerId());
liqin's avatar
liqin committed
412 413 414 415 416 417 418 419 420 421 422 423
        }
        // 根据创建时间区间检索
        if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
            queryWrapper.ge(ExhibitionBoard::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                    .le(ExhibitionBoard::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
        }
        // 设置排序规则
        queryWrapper.orderByDesc(ExhibitionBoard::getCreateTime);
        // 设置查询内容
        queryWrapper.select(
                ExhibitionBoard::getId,
                ExhibitionBoard::getName,
liqin's avatar
liqin committed
424 425 426 427
                ExhibitionBoard::getAuditStatus,
                ExhibitionBoard::getPublished,
                ExhibitionBoard::getAssetCopyrightOwnerId,
                ExhibitionBoard::getExhibitionBoardCatId,
liqin's avatar
liqin committed
428 429 430 431
                ExhibitionBoard::getCreateTime,
                ExhibitionBoard::getUpdateTime);
        Page<ExhibitionBoard> page = this.exhibitionBoardService.page(getPage(), queryWrapper);
        for (ExhibitionBoard exhibitionBoard : page.getRecords()) {
liqin's avatar
liqin committed
432 433 434 435 436 437 438 439
            if (exhibitionBoard.getAssetCopyrightOwnerId() != null) {
                String name = this.copyrightOwnerService.getById(exhibitionBoard.getAssetCopyrightOwnerId()).getName();
                exhibitionBoard.setBoardCopyrightOwnerName(name);
            }
            if (exhibitionBoard.getExhibitionBoardCatId() != null) {
                String name = this.exhibitionBoardCatService.getById(exhibitionBoard.getExhibitionBoardCatId()).getName();
                exhibitionBoard.setExhibitionBoardCatName(name);
            }
liqin's avatar
liqin committed
440 441 442 443 444
            final String assetId = exhibitionBoard.getAssetId();
            final Asset asset = this.assetService.getById(assetId);
            final String videoUrl = asset.getVideoUrl();
            final List<VideoVo> videoVoList = JSONObject.parseObject(videoUrl, new TypeReference<List<VideoVo>>() {}, Feature.OrderedField);
            exhibitionBoard.setVideoUrlList(videoVoList.stream().map(VideoVo::getFileUrl).collect(Collectors.toList()));
liqin's avatar
liqin committed
445
        }
liqin's avatar
liqin committed
446
        return getResult(page);
liqin's avatar
liqin committed
447 448 449 450
    }

    @ApiOperation(value = "获取展板详情", notes = "获取展板详情")
    @ApiImplicitParams({
liqin's avatar
liqin committed
451 452
            @ApiImplicitParam(name = "boardId", value = "展板ID", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", dataType = "String", paramType = "query"),
liqin's avatar
liqin committed
453
    })
liqin's avatar
liqin committed
454
    @GetMapping("/exhibitionBoard/getBoardInfo")
liqin's avatar
liqin committed
455
    public Map<String, Object> getById(@RequestParam(value = "boardId") String id, @RequestParam("language") LanguageEnum language) {
liqin's avatar
liqin committed
456
        ExhibitionBoard exhibitionBoard = exhibitionBoardService.getById(id);
liqin's avatar
liqin committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
        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());
        }

        final String assetId = exhibitionBoard.getAssetId();
        final Asset asset = this.assetService.getById(assetId);
        final String videoUrl = asset.getVideoUrl();
        final List<VideoVo> videoVoList = JSONObject.parseObject(videoUrl, new TypeReference<List<VideoVo>>() {}, Feature.OrderedField);
        exhibitionBoard.setVideoUrlList(videoVoList.stream().map(VideoVo::getFileUrl).collect(Collectors.toList()));
        return getResult(exhibitionBoard);
liqin's avatar
liqin committed
472 473
    }

yangtianyou's avatar
yangtianyou committed
474 475 476 477 478
    @PostMapping("/equitment/playLog")
    @RequiresPermissions("t:board:statistic:statisticBoardInfo")
    @ApiOperation(value = "播放记录信息反馈", notes = "播放记录信息反馈")
    public Map<String, Object> boardStatisticInfo(@Validated(value = {Add.class}) TBoardStatistic tBoardStatistic) {
        // 展板信息统计
liqin's avatar
liqin committed
479 480
        try {
            Object result = tBoardStatisticService.boardStatisticInfo(tBoardStatistic, false);
yangtianyou's avatar
yangtianyou committed
481
            // 返回操作结果
liqin's avatar
liqin committed
482
            if (result != null && (boolean) result) {
yangtianyou's avatar
yangtianyou committed
483 484
                return getSuccessResult();
            }
liqin's avatar
liqin committed
485
        } catch (Exception e) {
yangtianyou's avatar
yangtianyou committed
486 487 488 489 490 491
            e.printStackTrace();
        }
        // 保存失败
        return getFailResult();
    }

liqin's avatar
liqin committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
    @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")
    })
    @PostMapping("/learningContent/getPage")
    @RequiresPermissions("learning:content:page")
    @ApiOperation(value = "获取学习内容分页列表", notes = "获取学习内容分页列表")
    public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam) {
        LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
        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,
                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
531 532 533 534 535 536 537
    @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
538
    @PostMapping("/learningProject/getPage")
liqin's avatar
liqin committed
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
    @RequiresPermissions("learning:project:page")
    @ApiOperation(value = "获取学习项目分页列表", notes = "获取学习项目分页列表")
    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())
                    .eq(LearningContent::getIsPublished, true);
            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
574
}