# CbCaseApproveController.java

    package cloud.wconnect.finance.controller.chargeback;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ForbiddenException;
    import cloud.wconnect.finance.entity.chargeback.CbCase;
    import cloud.wconnect.finance.pojo.dto.chargeback.ApproveCaseDTO;
    import cloud.wconnect.finance.pojo.dto.chargeback.SubmissionDTO;
    import cloud.wconnect.finance.service.chargeback.ICbCaseApproveService;
    import cloud.wconnect.finance.service.chargeback.ICbCaseService;
    import jakarta.validation.Valid;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Lazy;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.Map;

    /**
     * 控制层: Cb Case Approve
     *
     * @author yyt
     * 2023/8/31
     */
    @RestController
    @RequestMapping("/charge-back")
    public class CbCaseApproveController {

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private ICbCaseService cbCaseService;
        @Lazy
        @Autowired
        private ICbCaseApproveService cbCaseApproveService;

        /**
         * 财务送审
         *
         * @param id            case id
         * @param operationType 1：initial 阶段操作 publish，2：overdue 阶段操作 publish，3：portal 操作 publish，4：final 阶段操作 publish
         * @param property      资产标识
         * @param submissionDTO 邮件追加内容
         * @return {}
         * @author yyt
         * @date 2023/8/31
         */
        @ApiId(568)
        @PostMapping("/{id:\\d+}/finance/submission/{operationType:\\d+}")
        public Map financeSubmission(@PathVariable long id, @PathVariable int operationType, String property,
                                     @RequestBody SubmissionDTO submissionDTO) {
            CbCase cs = cbCaseService.checkExist(id);
            checkBelong(cs, sessionContext.getPropertyId(property));
            cbCaseApproveService.financeSubmission(cs, operationType, submissionDTO);

            return Collections.emptyMap();
        }

        /**
         * 撤销审批
         *
         * @param id       case id
         * @param property 资产标识
         * @return {}
         * @author yyt
         * @date 2023/8/31
         */
        @ApiId(569)
        @PutMapping("/{id:\\d+}/revoke-approval")
        public Map revokeApproval(@PathVariable long id, String property) {
            CbCase cs = cbCaseService.checkExist(id);
            checkBelong(cs, sessionContext.getPropertyId(property));

            cbCaseApproveService.revokeApproval(cs, sessionContext.getLoginUserId());

            return Collections.emptyMap();
        }

        /**
         * 审批
         *
         * @param id             case id
         * @param property       资产标识
         * @param approveCaseDTO 审批信息
         * @return {}
         * @author yyt
         * @date 2023/8/31
         */
        @ApiId(570)
        @PostMapping("/{id:\\d+}/approval")
        public Map approve(@PathVariable long id, String property, @Valid @RequestBody ApproveCaseDTO approveCaseDTO) {
            CbCase cs = cbCaseService.checkExist(id);
            checkBelong(cs, sessionContext.getPropertyId(property));

            cbCaseApproveService.approve(cs, approveCaseDTO);

            return Collections.emptyMap();
        }

        /**
         * 酒店送审
         *
         * @param id            case id
         * @param operationType 1：Hotel Operation 阶段操作 publish，2：patch 阶段操作 publish
         * @param property      资产标识
         * @param submissionDTO 邮件追加内容
         * @return {}
         * @author yyt
         * @date 2023/9/6
         */
        @ApiId(575)
        @PostMapping("/{id:\\d+}/hotel/submission/{operationType:\\d+}")
        public Map hotelSubmission(@PathVariable long id, @PathVariable int operationType, String property,
                                    @RequestBody SubmissionDTO submissionDTO) {
            CbCase cs = cbCaseService.checkExist(id);
            checkBelong(cs, sessionContext.getPropertyId(property));
            cbCaseApproveService.hotelSubmission(cs, operationType, submissionDTO);

            return Collections.emptyMap();
        }

        /**
         * 校验数据归属
         *
         * @param cs         case
         * @param propertyId 资产 id
         * @author yyt
         * @date 2023/8/26
         */
        private void checkBelong(CbCase cs, Integer propertyId) {
            if (!cs.getPropertyId().equals(propertyId)) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(), "the property id parameter is different from " +
                        "the property id of the cbCase;propertyId:" + propertyId + ",cbCasePropertyId:" + cs.getPropertyId() +
                        ",cbCaseId:" + cs.getId());
            }
        }

    }