New file |
| | |
| | | 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; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | 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.*; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-01-24 19:01 |
| | | * @LastEditTime 2024-01-24 19:01 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "总账管理", description = "总账管理") |
| | | @RestController |
| | | @RequestMapping(path="general") |
| | | @RequiredArgsConstructor |
| | | public class GeneralCtrl { |
| | | private final GeneralSv generalSv; |
| | | |
| | | /** |
| | | * 根据指定条件获取总账记录 |
| | | * 查询前先生成未生成的总账记录 |
| | | * @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_generals") |
| | | @SsoAop() |
| | | public BaseResponse<QueryResultVo<List<VoGeneral>>> getOperates(QoGeneral vo){ |
| | | try { |
| | | add_general(); |
| | | QueryResultVo<List<VoGeneral>> res = generalSv.getGenerals(vo); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询交易记录异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导出总账记录 |
| | | * @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) { |
| | | for(int i = 0; i < list_operateDate.size(); i++) { |
| | | String operateDate = list_operateDate.get(i).get("operateDate").toString(); |
| | | // 根据交易日期获取总账记录列表(待生成的) |
| | | List<SeGeneral> list_general = Optional.ofNullable(generalSv.getGeneralByOperateDate(operateDate)).orElse(new ArrayList<>()); |
| | | if(list_general.size() > 0) { |
| | | for(int j = 0; j < list_general.size(); j++) { |
| | | SeGeneral general = list_general.get(j); |
| | | generalSv.addGeneral(general); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 审核总账 |
| | | * 1. 修改总账审核状态 |
| | | * 2. 添加总账审核记录 |
| | | * @param po |
| | | * @param bindingResult |
| | | * @return |
| | | */ |
| | | @Operation(summary = "审核总账", description = "审核总账") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "操作结果:true:成功,false:失败(BaseResponse.content)", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "audit", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> audit(@RequestBody @Valid DtoGeneral po, BindingResult bindingResult){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | Long generalId = po.getGeneralId(); |
| | | Byte auditStatus = po.getAuditStatus(); |
| | | String auditOpinion = po.getAuditOpinion(); |
| | | Long operator = po.getOperator(); |
| | | Date auditTime = new Date(); |
| | | |
| | | if(generalId == null) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.GENERAL_ID_CANNOT_BE_NULL.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * 判断总账是否存在 |
| | | */ |
| | | if(generalSv.getGeneralById(generalId) == null) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.GENERAL_NOT_EXIST.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * 修改总账审核状态 |
| | | */ |
| | | SeGeneral seGeneral = new SeGeneral(); |
| | | seGeneral.setId(generalId); |
| | | seGeneral.setAuditStatus(auditStatus); |
| | | Integer rec_updateGeneral = Optional.ofNullable(generalSv.updateGeneral(seGeneral)).orElse(0); |
| | | if(rec_updateGeneral == 0) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.GENERAL_AUDIT_FAIL.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * 添加总账审核记录 |
| | | */ |
| | | SeAudits seAudits = new SeAudits(); |
| | | seAudits.setGeneralId(generalId); |
| | | seAudits.setAuditStatus(auditStatus); |
| | | seAudits.setAuditOpinion(auditOpinion); |
| | | seAudits.setOperator(operator); |
| | | seAudits.setOperateDt(auditTime); |
| | | Integer rec_addAucits = Optional.ofNullable(generalSv.addAudits(seAudits)).orElse(0); |
| | | if(rec_addAucits == 0) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.AUDITS_ADD_FAIL.getMessage()); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } |