zhubaomin
2024-11-27 4fe39e9df868a8fdd40549f169adbea2e8bd622a
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralCtrl.java
@@ -1,16 +1,22 @@
package com.dy.pipIrrSell.general;
import com.alibaba.excel.EasyExcel;
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.excel.CellWriteHandler;
import com.dy.pipIrrGlobal.excel.ExcelUtil;
import com.dy.pipIrrGlobal.pojoBa.BaClient;
import com.dy.pipIrrGlobal.pojoSe.SeAudits;
import com.dy.pipIrrGlobal.pojoSe.SeGeneral;
import com.dy.pipIrrGlobal.voSe.VoGeneral;
import com.dy.pipIrrGlobal.voSe.VoTradeDetails;
import com.dy.pipIrrSell.general.dto.DtoGeneral;
import com.dy.pipIrrSell.general.qo.QoGeneral;
import com.dy.pipIrrSell.general.qo.QoSummary;
import com.dy.pipIrrSell.general.qo.QoToAudit;
import com.dy.pipIrrSell.result.SellResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
@@ -18,14 +24,18 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
/**
@@ -72,12 +82,32 @@
    }
    /**
     * 导出总账记录
     * @param response
     * @param vo
     */
    @SneakyThrows(IOException.class)
    @RequestMapping(value = "/export_general", method = RequestMethod.GET)
    @SsoAop()
    public void exportGeneral(HttpServletResponse response, QoGeneral vo) {
        ExcelUtil.setExcelRespProp(response, "总账" + LocalDate.now());
        List<VoGeneral> generalList = generalSv.exportGenerals(vo).getObj();
        EasyExcel.write(response.getOutputStream(), VoGeneral.class)
                .registerWriteHandler(new CellWriteHandler("财务对账-总账"))
                .sheet("总账")
                .doWrite(generalList);
    }
    /**
     * 生成总账
     *      获取未生成总账的交易日期列表(当天的交易记录不生成总账)
     *      将指定日期的交易记录汇总到总账表
     * @return
     */
    public void add_general(){
        //删除今天的总账
        generalSv.deleteTodayGeneral();
        // 获取未生成总账的交易日期列表(当天的交易记录不生成总账)
        List<Map<String, Object>> list_operateDate = Optional.ofNullable(generalSv.getDatesOfNotInGenerals()).orElse(new ArrayList<>());
        if(list_operateDate.size() > 0) {
@@ -164,4 +194,87 @@
        return BaseResponseUtils.buildSuccess() ;
    }
    /**
     * 开卡系统交易汇总查询与对账系统交易汇总查询共用接口
     * 开卡系统参数:收银员ID、查询起止日期
     * 对账系统参数:收银员ID、交易日期
     * @param vo
     * @return
     */
    @Operation(summary = "获得开卡系统交易统计记录", description = "返回开卡系统交易统计记录")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = BaClient.class))}
            )
    })
    @GetMapping(path = "getSummaries")
    @SsoAop()
    public BaseResponse<Map> getSummaries( @Valid QoSummary vo, BindingResult bindingResult){
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        try {
            Map res = generalSv.getSummaries(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询交易汇总记录异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
    /**
     * 获取财务对账_交易明细
     * @param vo
     * @return
     */
    @Operation(summary = "获取财务对账_交易明细", description = "获取财务对账_交易明细")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = BaClient.class))}
            )
    })
    @GetMapping(path = "get_trade_details")
    @SsoAop()
    public BaseResponse<Map> getTradeDetails(QoToAudit vo){
        try {
            return BaseResponseUtils.buildSuccess(generalSv.getTradeDetails(vo));
        } catch (Exception e) {
            log.error("查询交易记录异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
    /**
     * 导出财务对账_交易明细
     * @param response
     * @param vo
     */
    @SneakyThrows(IOException.class)
    @RequestMapping(value = "/export_trade_details", method = RequestMethod.GET)
    @SsoAop()
    public void exportTradeDetails(HttpServletResponse response, QoToAudit vo) {
        ExcelUtil.setExcelRespProp(response, "交易明细" + LocalDate.now());
        Map map_result = generalSv.exportTradeDetails(vo);
        Map map_record = (Map) map_result.get("records");
        List<VoTradeDetails> list = (List<VoTradeDetails>) map_record.get("list");
        Double totalTradeAmount = Double.parseDouble(map_result.get("totalTradeAmount").toString());
        VoTradeDetails po = new VoTradeDetails();
        po.setTradeAmount(totalTradeAmount);
        list.add(po);
        EasyExcel.write(response.getOutputStream(), VoTradeDetails.class)
                .registerWriteHandler(new CellWriteHandler("财务对账-交易明细"))
                .sheet("交易明细")
                .doWrite(list);
    }
}