InvoiceCustInfoServiceImpl.java 9.74 KB
package com.zteits.pay.biz.invoice;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zteits.clouds.api.apibase.bean.BizResult;
import com.zteits.clouds.api.apibase.constants.AppErrorEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.AppException;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.pay.TdCCustInvoiceinfoDTO;
import com.zteits.clouds.api.dto.pay.TdCCustMailingAddressDTO;
import com.zteits.clouds.api.dto.pay.param.*;
import com.zteits.clouds.api.service.order.backorder.oper.BackParkOrderOperService;
import com.zteits.clouds.api.service.order.backorder.query.BackOrderQueryService;
import com.zteits.clouds.api.service.order.parkorder.oper.RNTParkOrderOperService;
import com.zteits.clouds.api.service.order.parkorder.query.PubParkOrderQueryService;
import com.zteits.clouds.api.service.order.payorder.query.PayOrderQueryService;
import com.zteits.clouds.api.service.order.rechargeorder.oper.RechargeOrderOperService;
import com.zteits.clouds.api.service.order.rechargeorder.query.RechargeOrderQueryService;
import com.zteits.clouds.api.service.order.vipcardorder.oper.VipCardOrderOperService;
import com.zteits.clouds.api.service.order.vipcardorder.query.VipCardOrderQueryService;
import com.zteits.clouds.api.service.pay.AppOrgService;
import com.zteits.clouds.api.service.pay.invoice.InvoiceCustInfoService;
import com.zteits.pay.configuration.mail.MailService;
import com.zteits.pay.dao.*;
import com.zteits.pay.domain.TdCCustInvoiceinfo;
import com.zteits.pay.domain.TdCCustInvoiceinfoExample;
import com.zteits.pay.domain.TdCCustMailingAddress;
import com.zteits.pay.domain.TdCCustMailingAddressExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Copyright: Copyright (c) 2019  ZTE-ITS
 *
 * @Description:
 * @ProjectName: zteits-clouds
 * @Package: com.zteits.pay.biz.invoice
 * @ClassName: InvoiceCustInfoServiceImpl
 * Modification History:
 * Date         Author          Version         Description
 * ---------------------------------------------------------*
 * 2022/7/11      wb        v1.0.0          创建
 */
@Component
public class InvoiceCustInfoServiceImpl implements InvoiceCustInfoService {

    private static final Logger logger = LoggerFactory.getLogger(InvoiceCustInfoServiceImpl.class);
    @Autowired
    private TdCCustInvoiceinfoDao custInvoiceinfoDao;

    @Autowired
    private TdCCustMailingAddressDao custMailingAddressDao;
    /**
     * 新增一条客户发票抬头信息
     */
    @Override
    public BizResult<Long> insertCustomerInvoiceInfo(TdCCustInvoiceinfoRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }
        /**检查当前用户绑定抬头是否超过五个*/
        Long count = custInvoiceinfoDao.checkBindInfoNum(requestObject);
        logger.info("checkBindInfoNum:当前用户已绑定了"+count+"个抬头信息。");
        if (count >=5 ) {
            throw new AppException(AppErrorEnum.APP_INFOOUTLIMIT_ERROR);
        }
        TdCCustInvoiceinfo record = new TdCCustInvoiceinfo();
        BeanUtils.copyProperties(requestObject, record);
        logger.info("insertCustomerInvoiceInfo TdCCustInvoiceinfo--->: {} ", JSONObject.toJSON(record));

        Long resultId = custInvoiceinfoDao.insertCustomerInvoiceInfo(record);
        if(requestObject.getReturnId() !=null && requestObject.getReturnId()){
            resultId = record.getId();
        }
        return new BizResult <Long> (resultId);
    }

    /**
     * 新增一条客户邮寄地址信息
     */
    @Override
    public BizResult <Long> insertCustomerMailingAddressInfo(TdCCustMailingAddressRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }

        TdCCustMailingAddress record = new TdCCustMailingAddress();
        BeanUtils.copyProperties(requestObject, record);

        return new BizResult <Long> (custMailingAddressDao.insertCustomerMailingAddressInfo(record));
    }

    /**
     * 删除一条客户发票抬头信息
     */
    @Override
    public BizResult <Boolean> deleteCustomerInvoiceInfoByID(DeleteCustInvoiceinfoRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }
        logger.info("deleteCustomerInvoiceInfoByID->id={}", requestObject.getId().toString());
        return new BizResult <Boolean> (custInvoiceinfoDao.deleteCustomerInvoiceInfoByID(requestObject.getId()));
    }

    /**
     * 删除一条客户邮寄地址信息
     */
    @Override
    public BizResult <Boolean> deleteCustomerMailingAddressInfoByID(DeleteCustMailingAddressRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }

        return new BizResult<Boolean> (custMailingAddressDao.deleteCustomerMailingAddressByID(requestObject.getId()));
    }

    /**
     * 更新一条客户发票抬头信息
     */
    @Override
    public BizResult <Boolean> updateCustomerInvoiceInfo(TdCCustInvoiceinfoRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }

        TdCCustInvoiceinfo record = new TdCCustInvoiceinfo();
        BeanUtils.copyProperties(requestObject, record);

        return new BizResult <Boolean> (custInvoiceinfoDao.updateByPrimaryKeySelective(record));
    }

    /**
     * 更新一条客户邮寄地址信息
     */
    @Override
    public BizResult<Boolean> updateCustomerMailingAddressInfo(TdCCustMailingAddressRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }
        TdCCustMailingAddress record = new TdCCustMailingAddress();
        BeanUtils.copyProperties(requestObject, record);

        return new BizResult<Boolean> (custMailingAddressDao.updateByPrimaryKeySelective(record));
    }

    /**
     * 查询一条客户发票抬头信息
     */
    @Override
    public BizResult <TdCCustInvoiceinfoDTO> queryCustomerInvoiceInfoById(QueryCustInvoiceinfoRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }

        TdCCustInvoiceinfo tdCCustInvoiceinfo = custInvoiceinfoDao.queryCustomerInvoiceInfoById(requestObject.getId());
        TdCCustInvoiceinfoDTO tdCCustInvoiceinfoDTO = new TdCCustInvoiceinfoDTO();
        if (null != tdCCustInvoiceinfo) {
            BeanUtils.copyProperties(tdCCustInvoiceinfo, tdCCustInvoiceinfoDTO);
        }

        return new BizResult <TdCCustInvoiceinfoDTO> (tdCCustInvoiceinfoDTO);
    }

    /**
     * 查询客户所有发票抬头信息
     */
    @Override
    public BizResult<List<TdCCustInvoiceinfoDTO>> queryCustInvoiceInfoList(
            QueryCustInvoiceInfoListRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }

        TdCCustInvoiceinfoExample example = new TdCCustInvoiceinfoExample();
        example.createCriteria().andCustIdEqualTo(requestObject.getCustId());

        List <TdCCustInvoiceinfo> tdCCustInvoiceinfoList = custInvoiceinfoDao.queryCustInvoiceInfoList(example);
        List <TdCCustInvoiceinfoDTO> tdCCustInvoiceinfoDTOList = null;
        if (null != tdCCustInvoiceinfoList) {
            tdCCustInvoiceinfoDTOList = JSON.parseArray(JSON.toJSONString(tdCCustInvoiceinfoList, false), TdCCustInvoiceinfoDTO.class);
        }

        return new BizResult <List<TdCCustInvoiceinfoDTO>> (tdCCustInvoiceinfoDTOList);
    }

    /**
     * 查询一条客户邮寄地址信息
     */
    @Override
    public BizResult <TdCCustMailingAddressDTO> queryCustomerMailingAddressInfoById(
            QueryCustMailingAddressRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }

        TdCCustMailingAddressDTO tdCCustMailingAddressDTO = new TdCCustMailingAddressDTO();
        TdCCustMailingAddress tdCCustMailingAddress = custMailingAddressDao.queryCustomerMailingAddressById(requestObject.getId());
        if (null != tdCCustMailingAddress) {
            BeanUtils.copyProperties(tdCCustMailingAddress, tdCCustMailingAddressDTO);
        }

        return new BizResult <TdCCustMailingAddressDTO> (tdCCustMailingAddressDTO);
    }

    /**
     * 查询客户所有邮寄地址信息
     */
    @Override
    public BizResult<List<TdCCustMailingAddressDTO>> queryCustMailingAddressInfoList(
            QueryCustMailingAddressInfoListRequest requestObject) {
        if (null == requestObject) {
            throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
        }

        TdCCustMailingAddressExample example = new TdCCustMailingAddressExample();
        example.createCriteria().andCustIdEqualTo(requestObject.getCustId());

        List<TdCCustMailingAddress> tdCCustMailingAddressList = custMailingAddressDao.queryCustMailingAddressInfoList(example);
        List<TdCCustMailingAddressDTO> tdCCustMailingAddressDTOList = null;
        if (null != tdCCustMailingAddressList) {
            tdCCustMailingAddressDTOList = JSON.parseArray(JSON.toJSONString(tdCCustMailingAddressList, false), TdCCustMailingAddressDTO.class);
        }

        return new BizResult <List<TdCCustMailingAddressDTO>> (tdCCustMailingAddressDTOList);
    }
}