package com.dy.pipIrrSell.general;
|
|
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.pojoBa.BaClient;
|
import com.dy.pipIrrGlobal.pojoSe.SeAudits;
|
import com.dy.pipIrrGlobal.pojoSe.SeGeneral;
|
import com.dy.pipIrrGlobal.voSe.VoGeneral;
|
import com.dy.pipIrrSell.general.dto.DtoGeneral;
|
import com.dy.pipIrrSell.general.qo.QoGeneral;
|
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.validation.Valid;
|
import lombok.RequiredArgsConstructor;
|
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.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()) ;
|
}
|
}
|
|
/**
|
* 生成总账
|
* 获取未生成总账的交易日期列表(当天的交易记录不生成总账)
|
* 将指定日期的交易记录汇总到总账表
|
* @return
|
*/
|
public void add_general(){
|
// 获取未生成总账的交易日期列表(当天的交易记录不生成总账)
|
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() ;
|
}
|
|
@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 = "getToAudit")
|
@SsoAop()
|
public BaseResponse<Map> getToAudit(QoToAudit vo){
|
try {
|
Map res = generalSv.getToAudit(vo);
|
return BaseResponseUtils.buildSuccess(res);
|
} catch (Exception e) {
|
log.error("查询交易汇总记录异常", e);
|
return BaseResponseUtils.buildException(e.getMessage()) ;
|
}
|
}
|
}
|