admin
2025-02-09 39bd9f965dfb48925a66fcd80787144b7541b866
src/main/java/com/taoke/autopay/controller/admin/AdminAgentSettleController.java
@@ -1,12 +1,18 @@
package com.taoke.autopay.controller.admin;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
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.dto.admin.AgentSettleExcelDataDto;
import com.taoke.autopay.dto.admin.OrderExcelDataDto;
import com.taoke.autopay.entity.OrderChannelEnum;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.entity.agent.ChannelAgent;
@@ -21,20 +27,30 @@
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.Constant;
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.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.NumberUtil;
import org.yeshi.utils.StringUtil;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
/**
@@ -61,6 +77,20 @@
        public Date read(JsonReader in) throws IOException {
            return new Date();
        }
    }).registerTypeAdapter(BigDecimal.class, new TypeAdapter<BigDecimal>() {
        @Override
        public void write(JsonWriter out, BigDecimal value) throws IOException {
            if (value != null) {
                out.value(value.toString());
            } else {
                out.value("");
            }
        }
        @Override
        public BigDecimal read(JsonReader in) throws IOException {
            return new BigDecimal("0.00");
        }
    }).create();
    @Resource
@@ -72,10 +102,11 @@
    @ResponseBody
    @RequestMapping("list")
    public String listAgent(String key, String day, int page, int limit) {
    public String listAgent(String key, String startDay,String endDay, int page, int limit) {
        //先查询所有的数据
        ChannelAgentSettleRecordMapper.DaoQuery query = new ChannelAgentSettleRecordMapper.DaoQuery();
        query.settleDay = com.taoke.autopay.utils.StringUtil.isNullOrEmpty(day)?null:day;
        query.minSettleDay = com.taoke.autopay.utils.StringUtil.isNullOrEmpty(startDay)?null:startDay;
        query.maxSettleDay = com.taoke.autopay.utils.StringUtil.isNullOrEmpty(endDay)?null:endDay;
        query.sortList = Arrays.asList(new String[]{"_create_time desc"});
        query.start = (long) (page - 1) * limit;
        query.count = limit;
@@ -96,14 +127,175 @@
        return JsonUtil.loadTrueResult("");
    }
    /**
     * @author hxh
     * @description 开始结算
     * @date 0:28 2024/10/14
     * @param: startDay 开始日期
     * @param: endDay 结束日期
     * @return java.lang.String
     **/
    @ResponseBody
    @RequestMapping("startSettle")
    public String startSettle(String  day) {
    public String startSettle(String  startDay, String endDay) {
        if(StringUtil.isNullOrEmpty(startDay)||StringUtil.isNullOrEmpty(endDay)){
            return JsonUtil.loadFalseResult("结算日期输入不完整");
        }
        if(Integer.parseInt(startDay.replace("-",""))>Integer.parseInt(endDay.replace("-",""))){
            return JsonUtil.loadFalseResult("开始日期不能大于结束日期");
        }
        long startTimeStamp =  TimeUtil.convertToTimeTemp(startDay,"yyyy-MM-dd");
        long endTimeStamp =  TimeUtil.convertToTimeTemp(endDay,"yyyy-MM-dd");
        List<String> days=new ArrayList<>();
        for(int i=0;i<100;i++){
          if(endTimeStamp< startTimeStamp + i*24*60*60*1000L){
              break;
          }
          days.add(TimeUtil.getGernalTime(startTimeStamp + i*24*60*60*1000L,"yyyy-MM-dd"));
       }
        try {
           channelAgentSettleService.startSettle(day);
            for(String day:days) {
                channelAgentSettleService.startSettle(day);
            }
            return JsonUtil.loadTrueResult("");
        } catch (ChannelAgentSettleException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        }
    }
    /**
     * @author hxh
     * @description 提现列表
     * @date 13:14 2024/7/29
     * @param: key
     * @param: startTime
     * @param: endTime
     * @param: status
     * @param: page
     * @param: limit
     * @return java.lang.String
     **/
    @ResponseBody
    @RequestMapping("listWithdraw")
    public String listWithdraw(String key, String startTime,String endTime, String status, int page, int limit) {
        //先查询所有的数据
        ChannelAgentSettleRecordMapper.DaoQuery query = new ChannelAgentSettleRecordMapper.DaoQuery();
        query.agentId = !NumberUtil.isNumeric(key)?null:Long.parseLong(key);
        query.minWithDrawApplyTime = StringUtil.isNullOrEmpty(startTime)?null:new Date(TimeUtil.convertToTimeTemp(startTime,"yyyy-MM-dd HH:mm:ss"));
        query.maxWithDrawApplyTime = StringUtil.isNullOrEmpty(endTime)?null:new Date(TimeUtil.convertToTimeTemp(endTime,"yyyy-MM-dd HH:mm:ss"));
        if(status==null||Integer.parseInt(status)<0){
            query.statusList=Arrays.asList(new Integer[]{ ChannelAgentSettleRecord.STATUS_WITHDRAWING,ChannelAgentSettleRecord.STATUS_WITHDRAW_SUCCESS,ChannelAgentSettleRecord.STATUS_WITHDRAW_REJECTED});
        }else{
            query.status=Integer.parseInt(status);
        }
        query.sortList = Arrays.asList(new String[]{"_withdraw_apply_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);
    }
    /**
     * @author hxh
     * @description
     * @date 13:23 2024/7/29
     * @param: ids JSONARRAY
     * @return java.lang.String
     **/
    @ResponseBody
    @RequestMapping("pass")
    public String passWithdraw(String ids) {
       if(StringUtil.isNullOrEmpty(ids)){
           return JsonUtil.loadFalseResult("请上传ids");
       }
        Type type=new TypeToken<List<Long>>(){}.getType();
        try {
            channelAgentSettleService.processWithdraw(gson.fromJson(ids,type), true);
            return JsonUtil.loadTrueResult("");
        } catch (ChannelAgentSettleException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        }
    }
    @ResponseBody
    @RequestMapping("reject")
    public String rejectWithdraw(String ids) {
        if(StringUtil.isNullOrEmpty(ids)){
            return JsonUtil.loadFalseResult("请上传ids");
        }
        Type type=new TypeToken<List<Long>>(){}.getType();
        try {
            channelAgentSettleService.processWithdraw(gson.fromJson(ids,type), false);
            return JsonUtil.loadTrueResult("");
        } catch (ChannelAgentSettleException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        }
    }
    @RequestMapping("downloadSettleTable")
    public void downloadSettleTable(String startDay,String endDay, HttpServletResponse response) throws IOException {
        ChannelAgentSettleRecordMapper.DaoQuery daoQuery=new ChannelAgentSettleRecordMapper.DaoQuery();
        daoQuery.minSettleDay = com.taoke.autopay.utils.StringUtil.isNullOrEmpty(startDay)?null:startDay;
        daoQuery.maxSettleDay = com.taoke.autopay.utils.StringUtil.isNullOrEmpty(endDay)?null:endDay;
        daoQuery.count = 10000;
        daoQuery.status =  ChannelAgentSettleRecord.STATUS_NOT_SETTLE;
        List<ChannelAgentSettleRecord> list =   channelAgentSettleService.list(daoQuery);
        List<AgentSettleExcelDataDto> dataList=new ArrayList<>();
        for(ChannelAgentSettleRecord record:list){
            AgentSettleExcelDataDto dto=AgentSettleExcelDataDto.builder()
                    .id(record.getId())
                    .agentId(record.getAgentId())
                    .actualSettleMoney(record.getSettleMoney().toString())
                    .settleMoney(record.getSettleMoney().toString())
                    .day(record.getSettleDay())
                    .build();
            dataList.add(dto);
        }
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
        String fileName="settle_"+URLEncoder.encode(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyyMMdd_HHmmss"),"UTF-8");
        response.setHeader("Content-disposition","attachment;filename*=utf-8''"+fileName+".xlsx");
        EasyExcel.write(response.getOutputStream(),AgentSettleExcelDataDto.class).sheet("结算确认单").doWrite(dataList);
    }
    @ResponseBody
    @RequestMapping("uploadSettleExcel")
    public String uploadImg(@RequestParam("file") MultipartFile file, HttpSession session) throws IOException {
        InputStream inputStream = file.getInputStream();
        EasyExcel.read(inputStream, AgentSettleExcelDataDto.class, new ReadListener<AgentSettleExcelDataDto>() {
            @Override
            public void invoke(AgentSettleExcelDataDto o, AnalysisContext analysisContext) {
                System.out.println("读取到数据: " + o.getDay());
                try {
                    channelAgentSettleService.actualSettle(o.getId(),new BigDecimal(o.getActualSettleMoney()));
                } catch (ChannelAgentSettleException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
            }
        }).sheet().doRead();
        return JsonUtil.loadTrueResult("");
    }
}