| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.TSysEducationalInfo; |
| | | import com.ruoyi.system.query.TSysEducationalInfoQuery; |
| | | import com.ruoyi.system.service.TSysEducationalInfoService; |
| | | import com.ruoyi.system.vo.TSysEducationalInfoVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | private final TSysEducationalInfoService sysEducationalInfoService; |
| | | private final TokenService tokenService; |
| | | private final RedisCache redisCache; |
| | | @Autowired |
| | | public TSysEducationalInfoController(TSysEducationalInfoService sysEducationalInfoService, TokenService tokenService) { |
| | | public TSysEducationalInfoController(TSysEducationalInfoService sysEducationalInfoService, TokenService tokenService, RedisCache redisCache) { |
| | | this.sysEducationalInfoService = sysEducationalInfoService; |
| | | this.tokenService = tokenService; |
| | | this.redisCache = redisCache; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiOperation(value = "获取教育资讯分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<PageInfo<TSysEducationalInfo>> pageList(@RequestBody TSysEducationalInfoQuery query) { |
| | | public R<PageInfo<TSysEducationalInfoVO>> pageList(@RequestBody TSysEducationalInfoQuery query) { |
| | | Integer roleType = tokenService.getLoginUser().getUser().getRoleType(); |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | if(roleType == 5){ |
| | | query.setRoleType(roleType); |
| | | query.setUserId(userId); |
| | | } |
| | | return R.ok(sysEducationalInfoService.pageList(query)); |
| | | } |
| | |
| | | @ApiOperation(value = "查看教育资讯详情") |
| | | @GetMapping(value = "/getDetailById") |
| | | public R<TSysEducationalInfo> getDetailById(@RequestParam String id) { |
| | | return R.ok(sysEducationalInfoService.getById(id)); |
| | | TSysEducationalInfo sysEducationalInfo = sysEducationalInfoService.getById(id); |
| | | // 查询次数自增 使用数据库原子更新操作 |
| | | sysEducationalInfoService.update( |
| | | Wrappers.<TSysEducationalInfo>lambdaUpdate() |
| | | .setSql("click_count = click_count + 1") |
| | | .eq(TSysEducationalInfo::getId, id) |
| | | ); |
| | | // 如果是诊所 |
| | | Integer roleType = tokenService.getLoginUser().getUser().getRoleType(); |
| | | if(roleType == 5){ |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | Set<Long> clickCount = new HashSet<>(); |
| | | clickCount.add(userId); |
| | | redisCache.setCacheSet(Constants.SYS_EDUCATION_CLICK_COUNT+id,clickCount); |
| | | } |
| | | return R.ok(sysEducationalInfo); |
| | | } |
| | | |
| | | /** |