public class ContractServiceImpl implements ContractService {

    @Override
    public void cancelContract(ContractDto dto) {
        if(dto==null){
            throw new BusinessException(BusinessException.CONTRACT_CANCEL_PARAM_NULL);
        }
        if(dto.getContractId()==null){
            throw new BusinessException(BusinessException.CONTRACT_ID_NULL);
        }
        //校验合同撤销方式
        if(StringUtils.isBlank(dto.getRecompenseMethod())){
            throw new BusinessException(BusinessException.COMPENSATE_METHOD_NULL);
        }
        //校验合同撤销金额
        if(dto.getRecompenseAmount()==null){
            throw new BusinessException(BusinessException.COMPENSATE_AMOUNT_NULL);
        }
        //校验合同撤销原因
        if(StringUtils.isBlank(dto.getCancelReason())){
            throw new BusinessException(BusinessException.COMPENSATE_REASON_NULL);
        }
        
        //撤销前查询合同及状态
        Contract contract = contractService.get(dto.getContractId());
        if(contract==null){
            throw new BusinessException(BusinessException.CONTRACT_NOT_EXIST);
        }
        if(ContractStateEnum.CANCEL.getValue().equals(contract.getState())){
            throw new BusinessException(BusinessException.CONTRACT_CANCELED);
        }
        if(!ContractStateEnum.EFFECT.getValue().equals(contract.getState())){
            throw new BusinessException(BusinessException.CONTRACT_NOT_EFFECT);
        }
        
        //撤销
        contract.setState(ContractStateEnum.CANCEL.getValue());
        contract.setCancelReason(dto.getCancelReason());
        contract.setCancelAmount(dto.getRecompenseAmount());
        contract.setCancelMethod(dto.getRecompenseMethod());
        contract.setCancelTime(new Date());
        //记录撤销操作
        contractService.cancel(contract,dto.getCancelReason());
        
        //合同撤销成功
        contract.setState(ContractStateEnum.CANCEL.getValue());
        //更新合同
        contractService.update(contract);
        
        //调用合同取消接口
        contractService.cancelContract(contract);
    }

    @Override
    public void modifyContract(ContractDto dto) {
        if(dto==null){
            throw new BusinessException(BusinessException.CONTRACT_MODIFY_PARAM_NULL);
        }
        if(dto.getContractId()==null){
            throw new BusinessException(BusinessException.CONTRACT_ID_NULL);
        }
        //校验合同修改金额
        if(dto.getRecompenseAmount()==null){
            throw new BusinessException(BusinessException.COMPENSATE_AMOUNT_NULL);
        }
        //校验合同修改原因
        if(StringUtils.isBlank(dto.getCancelReason())){
            throw new BusinessException(BusinessException.COMPENSATE_REASON_NULL);
        }
        
        //查询合同及状态
        Contract contract = contractService.get(dto.getContractId());
        if(contract==null){
            throw new BusinessException(BusinessException.CONTRACT_NOT_EXIST);
        }
        if(ContractStateEnum.CANCEL.getValue().equals(contract.getState())){
            throw new BusinessException(BusinessException.CONTRACT_CANCELED);
        }
        if(!ContractStateEnum.EFFECT.getValue().equals(contract.getState())){
            throw new BusinessException(BusinessException.CONTRACT_NOT_EFFECT);
        }
        
        //修改合同
        contract.setModifyAmount(dto.getRecompenseAmount());
        contract.setModifyReason(dto.getCancelReason());
        contract.setModifyTime(new Date());
        //记录修改操作
        contractService.modify(contract,dto.getCancelReason());
        
        //调用合同更新接口
        contractService.modifyContract(contract);
    }
    
    @Override
    public void deleteContract(ContractDto dto) {
        if(dto==null){
            throw new BusinessException(BusinessException.CONTRACT_DELETE_PARAM_NULL);
        }
        if(dto.getContractId()==null){
            throw new BusinessException(BusinessException.CONTRACT_ID_NULL);
        }
        //校验合同删除原因
        if(StringUtils.isBlank(dto.getCancelReason())){
            throw new BusinessException(BusinessException.COMPENSATE_REASON_NULL);
        }
        
        //查询合同及状态
        Contract contract = contractService.get(dto.getContractId());
        if(contract==null){
            throw new BusinessException(BusinessException.CONTRACT_NOT_EXIST);
        }
        if(ContractStateEnum.CANCEL.getValue().equals(contract.getState())){
            throw new BusinessException(BusinessException.CONTRACT_CANCELED);
        }
        if(!ContractStateEnum.EFFECT.getValue().equals(contract.getState())){
            throw new BusinessException(BusinessException.CONTRACT_NOT_EFFECT);
        }
        
        //撤销
        contract.setState(ContractStateEnum.CANCEL.getValue());
        contract.setCancelReason(dto.getCancelReason());
        contract.setCancelTime(new Date());
        //记录撤销操作
        contractService.delete(contract,dto.getCancelReason());
        
        //合同撤销成功
        contract.setState(ContractStateEnum.CANCEL.getValue());
        //更新合同
        contractService.update(contract);
        
        //调用合同取消接口
        contractService.cancelContract(contract);
    }

    @Override
    public List<ContractLogDto> queryLogByContractId(Long contractId) {
        if(contractId==null){
            throw new BusinessException(BusinessException.CONTRACT_ID_NULL);
        }
        return BeanCopyUtil.mapList(contractLogService.queryLogByContractId(contractId), ContractLogDto.class);
    }

}
合同撤销、修改和删除操作实现代码示例

原文地址: https://www.cveoy.top/t/topic/lk2E 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录