package cn.iocoder.yudao.module.crm.api.crmcustomer;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.crmcustomer.vo.CrmCustomerSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.crmcustomer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.crmcustomer.CrmCustomerService;
import cn.iocoder.yudao.module.hrm.api.crmcustomer.CrmCustomerApi;
import cn.iocoder.yudao.module.hrm.api.crmcustomer.dto.CrmCustomerDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * Flowable CRM Api 实现类
 */
@RestController
@Validated
public class CrmCustomerApiImpl implements CrmCustomerApi {

    @Resource
    private CrmCustomerService customerService;

    @Override
    public CommonResult<Boolean> updateCustomerPurchaseTotal(CrmCustomerDTO updateReqVO) {
        customerService.updateCustomerPurchaseTotal(BeanUtils.toBean(updateReqVO, CrmCustomerSaveReqVO.class));
        return success(true);
    }

    @Override
    public CommonResult<CrmCustomerDTO> getCustomer(Long id) {
        CrmCustomerDO customerDO = customerService.getCustomer(id);
        return success(BeanUtils.toBean(customerDO, CrmCustomerDTO.class));
    }
}
