|
|
|
@@ -1,12 +1,14 @@ |
|
|
|
package com.iformall.controller; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxQuestion; |
|
|
|
import com.iformall.domain.po.WxQuestionConfig; |
|
|
|
import com.iformall.domain.po.WxQuestionLog; |
|
|
|
import com.iformall.domain.vo.WxCouponChannelVo; |
|
|
|
import com.iformall.enums.EnumQuestionConfigStatus; |
|
|
|
import com.iformall.service.WxCUserBasicInfoService; |
|
|
|
import com.iformall.service.WxCUserTagsService; |
|
|
|
@@ -14,16 +16,22 @@ import com.iformall.service.WxQuestionService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import net.sf.saxon.trans.Err; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
import org.springframework.boot.configurationprocessor.json.JSONArray; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.ValueOperations; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Random; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@RequestMapping("/api/wxQuestion") |
|
|
|
@@ -40,9 +48,18 @@ public class WxQuestionController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private WxCUserBasicInfoService wxCUserBasicInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Qualifier("questionRedisTemplate") |
|
|
|
private RedisTemplate<String, List<WxQuestion>> questionRedisTemplate ; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Qualifier("questionConfigRedisTemplate") |
|
|
|
private RedisTemplate<String, List<WxQuestionConfig>> questionConfigRedisTemplate ; |
|
|
|
|
|
|
|
@ApiOperation("查寻问券") |
|
|
|
@GetMapping("getQuestion") |
|
|
|
public Result getQuestion(@RequestParam("couponType") String couponType) { |
|
|
|
List<WxQuestionConfig> listConfig = null ; |
|
|
|
WxQuestionConfig wxQuestionConfig = new WxQuestionConfig(); |
|
|
|
wxQuestionConfig.updateTenantInfo(getTenantInfo()); |
|
|
|
JSONArray ct = new JSONArray(); |
|
|
|
@@ -51,18 +68,39 @@ public class WxQuestionController extends BaseController { |
|
|
|
}catch (Exception e) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
// TODO 缓存优化 |
|
|
|
wxQuestionConfig.setCouponTypeList(ct.toString()); |
|
|
|
List<WxQuestionConfig> listConfig = wxQuestionService.findConfigList(wxQuestionConfig); |
|
|
|
|
|
|
|
ValueOperations<String, List<WxQuestionConfig>> operations = questionConfigRedisTemplate.opsForValue(); |
|
|
|
String keyConfig = StringUtils.join(getTenantInfo().getTenantId(),":","questionConfig",":","getQuestion",":",couponType); |
|
|
|
boolean hasKey1 = questionConfigRedisTemplate.hasKey(keyConfig+ couponType); |
|
|
|
if (hasKey1) { |
|
|
|
listConfig = operations.get(keyConfig+ couponType) ; |
|
|
|
} else { |
|
|
|
wxQuestionConfig.setCouponTypeList(ct.toString()); |
|
|
|
listConfig = wxQuestionService.findConfigList(wxQuestionConfig); |
|
|
|
if(!CollectionUtils.isEmpty(listConfig)) { |
|
|
|
operations.set(keyConfig+ couponType,listConfig,24, TimeUnit.HOURS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (listConfig.size() > 0) { |
|
|
|
wxQuestionConfig = listConfig.get(0); |
|
|
|
List<Long> questionIds = JSONObject.parseArray(wxQuestionConfig.getQuestionList(), Long.class); |
|
|
|
if (wxQuestionConfig.getStatus().equals(EnumQuestionConfigStatus.ON.getCode()) |
|
|
|
&& questionIds.size() > 0) { |
|
|
|
WxQuestion wxQuestion = new WxQuestion(); |
|
|
|
wxQuestion.updateTenantInfo(getTenantInfo()); |
|
|
|
wxQuestion.setIds(questionIds); |
|
|
|
List<WxQuestion> listQuestion = wxQuestionService.findList(wxQuestion); |
|
|
|
List<WxQuestion> listQuestion = null ; |
|
|
|
|
|
|
|
ValueOperations<String, List<WxQuestion>> questionOperations = questionRedisTemplate.opsForValue(); |
|
|
|
String key = StringUtils.join(getTenantInfo().getTenantId(),":","question",":","getQuestion",":",couponType); |
|
|
|
boolean hasKey2 = questionRedisTemplate.hasKey(key+ couponType); |
|
|
|
if (hasKey2) { |
|
|
|
listQuestion = questionOperations.get(key+ couponType) ; |
|
|
|
} else { |
|
|
|
WxQuestion wxQuestion = new WxQuestion(); |
|
|
|
wxQuestion.updateTenantInfo(getTenantInfo()); |
|
|
|
wxQuestion.setIds(questionIds); |
|
|
|
listQuestion = wxQuestionService.findList(wxQuestion); |
|
|
|
} |
|
|
|
|
|
|
|
if (listQuestion.size() > 0) { |
|
|
|
Iterator<WxQuestion> q = listQuestion.iterator(); |
|
|
|
WxQuestionLog wxQuestionLog = new WxQuestionLog(); |
|
|
|
|