package com.ag.log;

import com.ag.base.BaseService;
import com.ag.base.DefaultBussniessImpl;
import com.ag.entity.log.DefineLogConfig;
import com.ag.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by yangxh on 2022/5/25.
 */
@Service
public class DefineLogConfigService extends BaseService {

    @Autowired
    private DefaultBussniessImpl bizDao;

    @Transactional
    public void saveGrid(org.json.JSONObject param, HttpServletResponse response, HttpServletRequest request){
        List<DefineLogConfig> adds = CommonUtil.getBeanlist(param, null, "create", DefineLogConfig.class);
        List<DefineLogConfig> upds = CommonUtil.getBeanlist(param, null, "update", DefineLogConfig.class);
        List<DefineLogConfig> dels = CommonUtil.getBeanlist(param, null, "destroy", DefineLogConfig.class);
        String[] cols = CommonUtil.getNeedColsByJson(param, null);
        adds.forEach(x->super.setSaveUser(param, x));
        upds.forEach(x->super.setUpdateUser(param, x));
        bizDao.saveAll(adds);
        bizDao.updateAll(upds, cols, "ID");
        bizDao.deleteAll(dels, "ID");
    }
}
