package com.hzs.system.sys.provider;

import cn.hutool.core.bean.BeanUtil;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.system.sys.SysBusinessLog;
import com.hzs.system.sys.IBusinessLogApi;
import com.hzs.system.sys.dto.BusinessLogDTO;
import com.hzs.system.sys.service.ISysBusinessLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 业务操作明细dubbo服务
 */
@Slf4j
@DubboService
public class BusinessLogServiceProvider implements IBusinessLogApi {

    @Autowired
    private ISysBusinessLogService iSysBusinessLogService;

    @Override
    public R<String> save(BusinessLogDTO dto) {
        try {
            SysBusinessLog sysBusinessLog = BeanUtil.copyProperties(dto, SysBusinessLog.class);
            iSysBusinessLogService.save(sysBusinessLog);
            return R.ok();
        } catch (Exception e) {
            log.error("保存操作明细异常", e);
            return R.fail("保存操作明细异常");
        }
    }

    @Override
    public R<String> saveBatch(List<BusinessLogDTO> dtoList) {
        try {
            List<SysBusinessLog> sysBusinessLogList = BeanUtil.copyToList(dtoList, SysBusinessLog.class);
            iSysBusinessLogService.saveBatch(sysBusinessLogList);
            return R.ok();
        } catch (Exception e) {
            log.error("批量保存操作明细异常", e);
            return R.fail("批量保存操作明细异常");
        }
    }

}
