
package com.jeelowcode.module.biz.service.impl;

import cn.hutool.json.JSONUtil;
import com.jeelowcode.core.framework.controller.BaseController;
import com.jeelowcode.core.framework.mapper.JeeLowCodeSqlMapper;
import com.jeelowcode.core.framework.service.IFormService;
import com.jeelowcode.core.framework.service.IFrameSqlService;
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
import com.jeelowcode.framework.plus.SqlHelper;
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoQueryWrapper;
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
import com.jeelowcode.framework.utils.model.ResultDataModel;
import com.jeelowcode.module.biz.service.IPlanIssusService;
import com.jeelowcode.module.biz.service.ITodoRequestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


/**
 * demo
 */
@Slf4j
@Service
public class TodoRequestServiceImpl extends BaseController implements ITodoRequestService {

    @Autowired
    private IFrameSqlService sqlService;

    @Autowired
    private IFormService dbFormService;

    @Override
    public boolean isExistTodoRequest(long billId, String todoType) {
        SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper();
        wrapper.setTableName("lc_todo_request_info");
        wrapper.setWhere(where->{
            where.eq("bill_id",billId);
            where.eq("bill_action",todoType);
            where.eq("is_success",1);
        });
        Map<String, Object> dataMap = sqlService.getDataOneByPlus(wrapper);
        return !dataMap.isEmpty();
    }

    @Override
    public void addTodoRequest(HashMap<String, Object> newRecord) {
        String tableName="lc_todo_request_info";
        Long formId = dbFormService.getDbFormIdByTableName(tableName);
        super.addJsonData(formId, JSONUtil.parseObj(newRecord));
    }
}
