package com.yeshi.buwan.controller.api;
|
|
import com.google.common.base.Function;
|
import com.google.common.collect.Maps;
|
import com.google.gson.Gson;
|
import com.ks.goldcorn.exception.GoldAppException;
|
import com.ks.goldcorn.exception.GoldTradeException;
|
import com.ks.goldcorn.exception.GoldUserException;
|
import com.ks.goldcorn.pojo.DO.GoldCornGetSource;
|
import com.ks.goldcorn.pojo.DO.GoldCornRecord;
|
import com.ks.goldcorn.pojo.DO.GoldCornRecordCountMap;
|
import com.ks.goldcorn.pojo.Query.GoldCornRecordQuery;
|
import com.yeshi.buwan.domain.goldcorn.CodeCornGetSourceType;
|
import com.yeshi.buwan.domain.goldcorn.GoldCornTaskActionDetail;
|
import com.yeshi.buwan.domain.jump.JumpDetail;
|
import com.yeshi.buwan.domain.jump.JumpTypeEnum;
|
import com.yeshi.buwan.domain.system.DetailSystem;
|
import com.yeshi.buwan.domain.system.DetailSystemConfig;
|
import com.yeshi.buwan.dto.goldcorn.SignInGoldCornDateData;
|
import com.yeshi.buwan.exception.goldcorn.SignInException;
|
import com.yeshi.buwan.exception.user.LoginUserException;
|
import com.yeshi.buwan.service.imp.DetailSystemConfigService;
|
import com.yeshi.buwan.service.inter.goldcorn.GoldCornTaskActionDetailService;
|
import com.yeshi.buwan.service.inter.goldcorn.SignInService;
|
import com.yeshi.buwan.service.inter.system.SystemConfigService;
|
import com.yeshi.buwan.service.manager.GoldCornManager;
|
import com.yeshi.buwan.util.Constant;
|
import com.yeshi.buwan.util.JsonUtil;
|
import com.yeshi.buwan.util.JsonUtilV2;
|
import com.yeshi.buwan.util.TimeUtil;
|
import com.yeshi.buwan.vo.AcceptData;
|
import com.yeshi.buwan.vo.goldcorn.GoldCornCouponVideoVO;
|
import com.yeshi.buwan.vo.goldcorn.GoldCornRecordVO;
|
import com.yeshi.buwan.vo.goldcorn.GoldCornTaskVO;
|
import com.yeshi.buwan.vo.goldcorn.SignInInfoVO;
|
import net.sf.json.JSONObject;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
@Controller
|
@RequestMapping("api/v2/goldcorn")
|
public class GoldCornController {
|
|
Logger logger = LoggerFactory.getLogger(GoldCornController.class);
|
|
|
@Resource
|
private GoldCornManager goldCornManager;
|
|
@Resource
|
private SignInService signInService;
|
|
@Resource
|
private SystemConfigService systemConfigService;
|
|
@Resource
|
private GoldCornTaskActionDetailService goldCornTaskActionDetailService;
|
|
@Resource
|
private DetailSystemConfigService configService;
|
|
|
/**
|
* 挣金币
|
*
|
* @param acceptData
|
* @param code
|
* @param loginUid
|
* @param param1
|
* @param param2
|
* @return
|
*/
|
@RequestMapping("makeGoldCorn")
|
@ResponseBody
|
public String makeGoldCorn(AcceptData acceptData, String code, String loginUid, String param1, String param2) {
|
try {
|
GoldCornGetSource source = goldCornManager.getGoldCornGetSource(CodeCornGetSourceType.valueOf(code));
|
goldCornManager.addGoldCorn(loginUid, CodeCornGetSourceType.valueOf(code), null, source.getSourceName(), "");
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("goldCorn", source.getGoldCorn());
|
return JsonUtil.loadTrueJson(jsonObject.toString());
|
} catch (GoldUserException e) {
|
return JsonUtil.loadFalseJson(e.getMessage());
|
} catch (GoldAppException e) {
|
return JsonUtil.loadFalseJson(e.getMessage());
|
} catch (GoldTradeException e) {
|
return JsonUtil.loadFalseJson(e.getMessage());
|
} catch (Exception e) {
|
e.printStackTrace();
|
logger.error("添加影视豆出错", e);
|
return JsonUtil.loadFalseJson("影视豆添加失败");
|
}
|
|
}
|
|
|
@RequestMapping("canDoTask")
|
@ResponseBody
|
public String canDoTask(AcceptData acceptData, String loginUid, String code, String param2) {
|
|
long time = goldCornManager.getNextDoTaskTime(CodeCornGetSourceType.valueOf(code), loginUid);
|
if (time <= 0) {
|
return JsonUtil.loadTrueJson("");
|
} else {
|
long span = time - System.currentTimeMillis();
|
int ss = (int) (span / 1000);
|
int h = ss / 3600;
|
int m = ss % 3600 / 60;
|
int s = ss % 60;
|
String st = "";
|
if (h > 0) {
|
st += h + "小时";
|
}
|
if (m != 0 || h > 0)
|
st += m + "分钟";
|
if (s > 0 && st.length() == 0)
|
st += s + "秒";
|
return JsonUtil.loadFalseJson(String.format("请%s后再试", st));
|
}
|
|
}
|
|
|
@RequestMapping("signIn")
|
@ResponseBody
|
public String signIn(AcceptData acceptData, String loginUid) {
|
try {
|
int goldCorn = signInService.signIn(loginUid);
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("goldCorn", goldCorn);
|
return JsonUtil.loadTrueJson(jsonObject.toString());
|
} catch (LoginUserException e) {
|
return JsonUtil.loadFalseJson("签到出错,请稍后再试");
|
} catch (SignInException e) {
|
e.printStackTrace();
|
logger.error("签到出错:", e);
|
return JsonUtil.loadFalseJson(e.getMessage());
|
}
|
|
}
|
|
@RequestMapping("getSignInData")
|
@ResponseBody
|
public String getSignInData(AcceptData acceptData, String loginUid) {
|
try {
|
SignInInfoVO signInInfo = new SignInInfoVO();
|
List<SignInGoldCornDateData> recordList = signInService.getContinueSignInList(loginUid);
|
signInInfo.setDateList(recordList);
|
signInInfo.setSignDay(signInService.getContinueSignDayCount(loginUid));
|
signInInfo.setBalance((int) goldCornManager.getBalance(loginUid));
|
SignInInfoVO.SignInConfig config = new SignInInfoVO.SignInConfig();
|
config.setRecordUrl(systemConfigService.getConfigValueByKeyCache("goldCornRecordUrl"));
|
config.setRuleUrl(systemConfigService.getConfigValueByKeyCache("goldCornRuleUrl"));
|
|
String action = systemConfigService.getConfigValueByKeyCache("useGoldCornAction");
|
JSONObject actionJSON = JSONObject.fromObject(action);
|
Gson gson = new Gson();
|
config.setUserJump(gson.fromJson(actionJSON.optJSONObject("jumpDetail").toString(), JumpDetail.class));
|
config.setUserJumpParams(actionJSON.optString("params"));
|
|
signInInfo.setSignInConfig(config);
|
signInInfo.setCanSignIn(!signInService.isTodaySignIned(loginUid, new Date()));
|
return JsonUtil.loadTrueJson(new Gson().toJson(signInInfo));
|
} catch (Exception e) {
|
e.printStackTrace();
|
logger.error("获取签到信息异常:", e);
|
}
|
return JsonUtil.loadFalseJson("服务器内部错误");
|
}
|
|
|
/**
|
* 获取金币记录
|
*
|
* @param acceptData
|
* @param loginUid
|
* @param page
|
* @return
|
*/
|
@RequestMapping("getRecordList")
|
@ResponseBody
|
public String getRecordList(AcceptData acceptData, String loginUid, int page) {
|
GoldCornRecordQuery recordQuery = new GoldCornRecordQuery();
|
recordQuery.setPageSize(Constant.pageCount);
|
recordQuery.setPage(page);
|
try {
|
List<GoldCornRecord> list = goldCornManager.getRecordList(recordQuery, loginUid);
|
List<GoldCornRecordVO> voList = new ArrayList<>();
|
for (GoldCornRecord record : list) {
|
voList.add(new GoldCornRecordVO(record.getTitle(), record.getDesc(), TimeUtil.getGernalTime(record.getCreateTime().getTime(), "yyyy.MM.dd HH:mm"), record.getType() == GoldCornRecord.TYPE_CONSUME ? 0 - record.getGoldCorn() : record.getGoldCorn()));
|
}
|
long count = goldCornManager.getRecordCount(recordQuery, loginUid);
|
JSONObject data = new JSONObject();
|
data.put("list", new Gson().toJson(voList));
|
data.put("count", count);
|
return JsonUtilV2.loadTrueJson(data.toString());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return JsonUtil.loadFalseJson("服务器内部错误");
|
}
|
|
@RequestMapping("getCouponVideoList")
|
@ResponseBody
|
public String getCouponVideoList(AcceptData acceptData) {
|
List<GoldCornCouponVideoVO> voList = new ArrayList<>();
|
JumpDetail jumpDetail = new JumpDetail();
|
jumpDetail.setType(JumpTypeEnum.web);
|
|
JSONObject params = new JSONObject();
|
params.put("url", "https://www.baidu.com");
|
|
voList.add(new GoldCornCouponVideoVO("https://r1.ykimg.com/058400005FA60E6A14187C0791817503?x-oss-process=image/resize,w_290/interlace,1/quality,Q_80", jumpDetail, params.toString().replace("\"", "\\" + "\"")));
|
voList.add(new GoldCornCouponVideoVO("https://r1.ykimg.com/058400005F2BA59B6AEB660E907A2B99?x-oss-process=image/resize,w_290/interlace,1/quality,Q_80", jumpDetail, params.toString().replace("\"", "\\" + "\"")));
|
voList.add(new GoldCornCouponVideoVO("https://r1.ykimg.com/052700005DC9247B1B769182B50A8C21?x-oss-process=image/resize,w_290/interlace,1/quality,Q_80", jumpDetail, params.toString().replace("\"", "\\" + "\"")));
|
// if (voList.size() < 3)
|
voList.clear();
|
JSONObject data = new JSONObject();
|
data.put("list", new Gson().toJson(voList));
|
data.put("count", voList.size());
|
data.put("exchangeUrl", "http://www.baidu.com");
|
return JsonUtil.loadTrueJson(data.toString());
|
}
|
|
@RequestMapping("getTaskList")
|
@ResponseBody
|
public String getTaskList(AcceptData acceptData, String loginUid) {
|
List<GoldCornTaskVO> voList = new ArrayList<>();
|
try {
|
//登录
|
List<GoldCornGetSource> list1 = goldCornManager.listGetCornSource(1, 20);
|
|
List<GoldCornGetSource> list = new ArrayList<>();
|
list.addAll(list1);
|
|
//删除华为渠道的看激励视频任务
|
if (acceptData.getChannel().equalsIgnoreCase("huawei")) {
|
if (list != null && list.size() > 0)
|
for (int i = 0; i < list.size(); i++) {
|
if (list.get(i).getSourceCode().equalsIgnoreCase(CodeCornGetSourceType.watchRewardAd.name())) {
|
//华为是否正在上线
|
DetailSystemConfig onLiningVersionInfo = configService.getConfigByKey("ad_hw_online_version_info", new DetailSystem("44"), 1);
|
JSONObject onLiningVersionInfoJson = JSONObject.fromObject(onLiningVersionInfo.getValue());
|
int onLiningVersionCode = onLiningVersionInfoJson.optInt("versionCode");
|
if (acceptData.getVersion() >= onLiningVersionCode) {
|
list.remove(i);
|
break;
|
}
|
}
|
}
|
}
|
|
|
List<String> sourceCodes = new ArrayList<>();
|
for (GoldCornGetSource source : list) {
|
sourceCodes.add(source.getSourceCode());
|
}
|
|
List<GoldCornTaskActionDetail> details = goldCornTaskActionDetailService.list(sourceCodes);
|
Map<String, GoldCornTaskActionDetail> detailMap = Maps.uniqueIndex(details.iterator(), new Function<GoldCornTaskActionDetail, String>() {
|
@Override
|
public String apply(GoldCornTaskActionDetail detail) {
|
return detail.getSourceCode();
|
}
|
});
|
|
|
//加载已完成数据
|
|
Date maxCreateTime = new Date();
|
Date minCreateTime = new Date(TimeUtil.convertGernalTime(TimeUtil.getGernalTime(maxCreateTime.getTime(), "yyyyMMdd"), "yyyyMMdd"));
|
|
List<GoldCornRecordCountMap> mapList = goldCornManager.countRecordByGetSource(loginUid, sourceCodes, minCreateTime, maxCreateTime);
|
Map<String, GoldCornRecordCountMap> map = new HashMap<>();
|
if (mapList != null)
|
for (GoldCornRecordCountMap m : mapList) {
|
map.put(m.getSourceCode(), m);
|
}
|
String[] hiddens = new String[]{CodeCornGetSourceType.elme.name(), CodeCornGetSourceType.meituan.name()};
|
List<String> hiddenList = Arrays.asList(hiddens);
|
for (GoldCornGetSource source : list) {
|
|
GoldCornTaskVO vo = GoldCornTaskVO.create(source);
|
//详细的信息
|
GoldCornTaskActionDetail detail = detailMap.get(source.getSourceCode());
|
if (detail != null) {
|
vo.setJumpDetail(detail.getJumpDetail());
|
vo.setParams(detail.getParams());
|
vo.setActionName(detail.getActionName());
|
}
|
|
if (!hiddenList.contains(source.getSourceCode())) {
|
if (map.get(source.getSourceCode()) == null) {
|
vo.setDesc(source.getSourceDesc() + "," + String.format("今日已完成%s/%s", 0, source.getMaxDayCount()));
|
} else {
|
vo.setEnable(map.get(source.getSourceCode()).getCount() < source.getMaxDayCount());
|
vo.setDesc(source.getSourceDesc() + "," + String.format("今日已完成%s/%s", map.get(source.getSourceCode()).getCount(), source.getMaxDayCount()));
|
}
|
} else {
|
vo.setGoldCorn("实付款*" + source.getGoldCorn());
|
}
|
|
voList.add(vo);
|
}
|
|
|
} catch (Exception e) {
|
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("list", new Gson().toJson(voList));
|
data.put("count", voList.size());
|
return JsonUtil.loadTrueJson(data.toString());
|
}
|
|
|
}
|