admin
2024-09-27 17caebabf7a6a529b7039c71e21e5a324e31ea20
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.*;
/**
@@ -60,6 +76,20 @@
        @Override
        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();
@@ -106,4 +136,136 @@
            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 day, HttpServletResponse response) throws IOException {
        ChannelAgentSettleRecordMapper.DaoQuery daoQuery=new ChannelAgentSettleRecordMapper.DaoQuery();
        daoQuery.settleDay = day;
        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("");
    }
}