| @@ -1,7 +1,5 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| @@ -22,7 +20,7 @@ import java.util.List; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("wxQuestion") | @RequestMapping("wxQuestion") | ||||
| @Api(description="标签弹窗接口") | |||||
| @Api(description="问券调查") | |||||
| public class WxQuestionController extends BaseController { | public class WxQuestionController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @@ -0,0 +1,96 @@ | |||||
| package com.iformall.controller; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| 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.enums.EnumQuestionConfigStatus; | |||||
| import com.iformall.service.WxQuestionService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.boot.configurationprocessor.json.JSONArray; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.List; | |||||
| import java.util.Random; | |||||
| @RestController | |||||
| @RequestMapping("wxQuestion") | |||||
| @Api(description="问券调查") | |||||
| public class WxQuestionController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxQuestionService wxQuestionService; | |||||
| @ApiOperation("查寻问券") | |||||
| @GetMapping("getQuestion") | |||||
| public Result getQuestion(String couponType) { | |||||
| WxQuestionConfig wxQuestionConfig = new WxQuestionConfig(); | |||||
| wxQuestionConfig.setTenantId(getTenantId()); | |||||
| JSONArray ct = new JSONArray(); | |||||
| ct.put(Integer.valueOf(couponType)); | |||||
| wxQuestionConfig.setCouponTypeList(ct.toString()); | |||||
| List<WxQuestionConfig> listConfig = wxQuestionService.findConfigList(wxQuestionConfig); | |||||
| if (listConfig.size() > 0) { | |||||
| if (listConfig.get(0).getStatus().equals(EnumQuestionConfigStatus.ON.getCode())) { | |||||
| WxQuestion wxQuestion = new WxQuestion(); | |||||
| wxQuestion.setTenantId(getTenantId()); | |||||
| wxQuestion.setIds(JSONObject.parseArray(wxQuestionConfig.getQuestionList(), Long.class)); | |||||
| List<WxQuestion> listQuestion = wxQuestionService.findList(wxQuestion); | |||||
| if (listQuestion.size() > 0) { | |||||
| Iterator<WxQuestion> q = listQuestion.iterator(); | |||||
| WxQuestionLog wxQuestionLog = new WxQuestionLog(); | |||||
| while(q.hasNext()){ | |||||
| WxQuestion x = q.next(); | |||||
| wxQuestionLog.setQuestionId(x.getId()); | |||||
| wxQuestionLog.setUserId(getUserId()); | |||||
| wxQuestionLog.setTenantId(getTenantId()); | |||||
| if(wxQuestionService.findLogList(wxQuestionLog).size()>0){ | |||||
| q.remove(); | |||||
| } | |||||
| } | |||||
| if (listQuestion.size() > 0) | |||||
| return new ResultData(listQuestion.get(new Random().nextInt(listQuestion.size()))); | |||||
| } | |||||
| } | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("设置问券配置") | |||||
| @PostMapping("answerQuestion") | |||||
| public Result answerQuestion(@RequestBody WxQuestionLog wxQuestionLog) { | |||||
| if (wxQuestionLog == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| if (wxQuestionLog.getQuestionId() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| if (wxQuestionLog.getAnswer() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| String[] arys1 = wxQuestionLog.getAnswer().split(","); | |||||
| List<Long> as = new ArrayList<>(); | |||||
| for (int i = 0; i < arys1.length; i++) { | |||||
| as.add(Long.parseLong(arys1[i])); | |||||
| } | |||||
| wxQuestionLog.setAnswer(JSONObject.toJSONString(as)); | |||||
| wxQuestionLog.setUserId(getUserId()); | |||||
| wxQuestionService.saveOrUpdateLog(wxQuestionLog); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | |||||
| @@ -3,6 +3,7 @@ package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.domain.po.WxQuestion; | import com.iformall.domain.po.WxQuestion; | ||||
| import com.iformall.domain.po.WxQuestionConfig; | import com.iformall.domain.po.WxQuestionConfig; | ||||
| import com.iformall.domain.po.WxQuestionLog; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -46,5 +47,9 @@ public interface WxQuestionService { | |||||
| List<WxQuestionConfig> findConfigList(WxQuestionConfig wxQuestionConfig); | List<WxQuestionConfig> findConfigList(WxQuestionConfig wxQuestionConfig); | ||||
| List<WxQuestionLog> findLogList(WxQuestionLog wxQuestionLog); | |||||
| void saveOrUpdateConfig(WxQuestionConfig record); | void saveOrUpdateConfig(WxQuestionConfig record); | ||||
| void saveOrUpdateLog(WxQuestionLog record); | |||||
| } | } | ||||
| @@ -62,17 +62,10 @@ public class WxGameServiceImpl implements WxGameService { | |||||
| @Override | @Override | ||||
| public WxGame getOne(WxGame wxGame) { | public WxGame getOne(WxGame wxGame) { | ||||
| List<WxGame> list = wxGameMapper.findList(wxGame); | |||||
| WxGame record = null; | WxGame record = null; | ||||
| // get game's count | |||||
| int countOfGame = wxGameMapper.selectCount(wxGame); | |||||
| if (countOfGame == 1){ | |||||
| record = wxGameMapper.selectOne(wxGame); | |||||
| } else if (countOfGame > 1){ | |||||
| // random | |||||
| int pageNum = (int)(1+Math.random()*(countOfGame-1+1)); | |||||
| PageInfo<WxGame> gamePageInfo = | |||||
| PageHelper.startPage(pageNum, 1).doSelectPageInfo(() -> wxGameMapper.findList(wxGame)); | |||||
| record = gamePageInfo.getList().get(0); | |||||
| if (list.size() >0) { | |||||
| record = list.get(new Random().nextInt(list.size())); | |||||
| } | } | ||||
| if (record != null) { | if (record != null) { | ||||
| @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.po.WxQuestion; | import com.iformall.domain.po.WxQuestion; | ||||
| import com.iformall.domain.po.WxQuestionConfig; | import com.iformall.domain.po.WxQuestionConfig; | ||||
| import com.iformall.domain.po.WxQuestionLog; | |||||
| import com.iformall.mapper.WxQuestionConfigMapper; | import com.iformall.mapper.WxQuestionConfigMapper; | ||||
| import com.iformall.mapper.WxQuestionLogMapper; | import com.iformall.mapper.WxQuestionLogMapper; | ||||
| import com.iformall.mapper.WxQuestionMapper; | import com.iformall.mapper.WxQuestionMapper; | ||||
| @@ -14,6 +15,7 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| @Service | @Service | ||||
| @@ -66,15 +68,37 @@ public class WxQuestionServiceImpl implements WxQuestionService { | |||||
| return wxQuestionConfigMapper.findList(wxQuestionConfig); | return wxQuestionConfigMapper.findList(wxQuestionConfig); | ||||
| } | } | ||||
| @Override | |||||
| public List<WxQuestionLog> findLogList(WxQuestionLog wxQuestionLog) { | |||||
| return wxQuestionLogMapper.findList(wxQuestionLog); | |||||
| } | |||||
| @Override | @Override | ||||
| public void saveOrUpdateConfig(WxQuestionConfig record) { | public void saveOrUpdateConfig(WxQuestionConfig record) { | ||||
| if (record.getId() == null) { | if (record.getId() == null) { | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| record.setCreateTime(new Date()); | |||||
| record.setUpdateTime(new Date()); | |||||
| wxQuestionConfigMapper.insertSelective(record); | wxQuestionConfigMapper.insertSelective(record); | ||||
| } else { | } else { | ||||
| record.setUpdateTime(new Date()); | |||||
| wxQuestionConfigMapper.updateByPrimaryKeySelective(record); | wxQuestionConfigMapper.updateByPrimaryKeySelective(record); | ||||
| } | } | ||||
| } | } | ||||
| @Override | |||||
| public void saveOrUpdateLog(WxQuestionLog record) { | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| record.setCreateTime(new Date()); | |||||
| record.setUpdateTime(new Date()); | |||||
| wxQuestionLogMapper.insertSelective(record); | |||||
| } else { | |||||
| record.setUpdateTime(new Date()); | |||||
| wxQuestionLogMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -27,11 +27,11 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != questionList "> | <if test=" null != questionList "> | ||||
| and JSON_CONTAINS(`question_list`->'$',JSON_ARRAY(#{questionList})) | |||||
| and JSON_CONTAINS(question_list,#{questionList}) | |||||
| </if> | </if> | ||||
| <if test=" null != couponTypeList "> | <if test=" null != couponTypeList "> | ||||
| and JSON_CONTAINS(`coupon_type_list`->'$',JSON_ARRAY(#{couponTypeList})) | |||||
| and JSON_CONTAINS(coupon_type_list,#{couponTypeList}) | |||||
| </if> | </if> | ||||
| <if test=" null != createTime "> | <if test=" null != createTime "> | ||||
| @@ -38,7 +38,7 @@ | |||||
| and `tenant_id` = #{tenantId} | and `tenant_id` = #{tenantId} | ||||
| </if> | </if> | ||||
| <if test=" null != answerId "> | |||||
| <if test=" null != answer "> | |||||
| and `answer` = #{answer} | and `answer` = #{answer} | ||||
| </if> | </if> | ||||