package com.boman.web.core.service.save;

import com.alibaba.fastjson.JSONObject;
import com.boman.domain.constant.FormDataConstant;
import com.boman.web.core.domain.RowResult;
import com.boman.web.core.domain.TableContext;
import com.boman.web.core.mapper.StandardlyMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author shiqian
 * @description
 * @date 2021年03月22日 11:25
 **/
@Component
public class BaseSaveServiceImpl implements IBaseSaveService {

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseSaveServiceImpl.class);

    @Autowired
    private StandardlyMapper mapper;
    /**
     * 功能描述: 保存一行
     *
     * @param tableName  tableName
     * @param commitData commitData
     * @return com.boman.system.common.RowResult
     */
    @Override
    public RowResult insertRow(String tableName, JSONObject commitData) {
        int ret = mapper.insert(tableName, commitData);
        if (ret > 0) {
            LOGGER.info("保存成功，保存的数据为：{}", commitData);
            commitData.put(FormDataConstant.SUCCESS_CNT, ret);
            return RowResult.ok("保存成功", commitData);
        }

        return RowResult.error("失败");
    }

}
