package com.taoke.autopay.controller.admin;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.TypeAdapter;
|
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonWriter;
|
import com.taoke.autopay.dao.agent.ChannelAgentMapper;
|
import com.taoke.autopay.dao.agent.ChannelAgentSettleRecordMapper;
|
import com.taoke.autopay.entity.OrderChannelEnum;
|
import com.taoke.autopay.entity.SystemConfigKeyEnum;
|
import com.taoke.autopay.entity.agent.ChannelAgent;
|
import com.taoke.autopay.entity.agent.ChannelAgentSettings;
|
import com.taoke.autopay.entity.agent.ChannelAgentSettleRecord;
|
import com.taoke.autopay.entity.agent.ChannelAgentSharingRatio;
|
import com.taoke.autopay.exception.ChannelAgentException;
|
import com.taoke.autopay.exception.ChannelAgentSettleException;
|
import com.taoke.autopay.factory.AgentFactory;
|
import com.taoke.autopay.service.SystemConfigService;
|
import com.taoke.autopay.service.agent.ChannelAgentService;
|
import com.taoke.autopay.service.agent.ChannelAgentSettingService;
|
import com.taoke.autopay.service.agent.ChannelAgentSettleService;
|
import com.taoke.autopay.service.agent.ChannelAgentSharingRatioService;
|
import com.taoke.autopay.utils.TimeUtil;
|
import com.taoke.autopay.vo.admin.AdminChannelAgentVO;
|
import com.taoke.autopay.vo.admin.AgentSearchVO;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
/**
|
* 渠道结算
|
*/
|
@Controller
|
@RequestMapping("/admin/api/agentsettle")
|
public class AdminAgentSettleController {
|
|
private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new TypeAdapter<Date>() {
|
@Override
|
public void write(JsonWriter out, Date value) throws IOException {
|
String desc = "";
|
if (value != null) {
|
// 判断是否是同一天
|
desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss");
|
out.value(desc);
|
} else {
|
out.value("");
|
}
|
}
|
|
@Override
|
public Date read(JsonReader in) throws IOException {
|
return new Date();
|
}
|
}).create();
|
|
@Resource
|
private ChannelAgentService channelAgentService;
|
|
@Resource
|
private ChannelAgentSettleService channelAgentSettleService;
|
|
|
@ResponseBody
|
@RequestMapping("list")
|
public String listAgent(String key, String day, int page, int limit) {
|
//先查询所有的数据
|
ChannelAgentSettleRecordMapper.DaoQuery query = new ChannelAgentSettleRecordMapper.DaoQuery();
|
query.settleDay = com.taoke.autopay.utils.StringUtil.isNullOrEmpty(day)?null:day;
|
query.sortList = Arrays.asList(new String[]{"_create_time desc"});
|
query.start = (long) (page - 1) * limit;
|
query.count = limit;
|
List<ChannelAgentSettleRecord> recordList = channelAgentSettleService.list(query);
|
long count = channelAgentSettleService.count(query);
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("list", gson.toJson(recordList));
|
return JsonUtil.loadTrueResult(data);
|
}
|
|
|
@ResponseBody
|
@RequestMapping("delete")
|
public String delete(Long id){
|
// 删除agent
|
channelAgentSettleService.delete(id);
|
return JsonUtil.loadTrueResult("");
|
}
|
|
@ResponseBody
|
@RequestMapping("startSettle")
|
public String startSettle(String day) {
|
try {
|
channelAgentSettleService.startSettle(day);
|
return JsonUtil.loadTrueResult("");
|
} catch (ChannelAgentSettleException e) {
|
return JsonUtil.loadFalseResult(e.getMessage());
|
}
|
}
|
}
|