const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");

class ForminfoService extends ServiceBase {
    constructor() {
        super("configmag", ServiceBase.getDaoName(ForminfoService));
    }

    /**
     * 根据company_id 查询
     * @param pobj
     * @returns {Promise<void>}
     */
    async findByCompanyId(pobj) {
        if (pobj.company_id) {
            pobj.search.company_id = pobj.company_id;
        }
        let result = await this.findAndCountAll(pobj);
        return system.getResult(result);
    }

    /**
     * 创建表单
     * @param pobj
     * @returns {Promise<void>}
     */
    async createForm(pobj){
        if(!pobj.name){
            return system.getResult(null,'name can not be empty');
        }
        if(!pobj.form_describe){
            return system.getResult(null,'form_describe can not be empty');
        }
        let code = await this.getBusUid("fm")
        let formData = {
            name:pobj.name,
            code:code,
            form_describe:pobj.form_describe,
            form_item:formItem.data,
            user_id:pobj.user_id,
            user_name:pobj.username
        }
        let result = await this.create(formData);
        return system.getResult(result);
    }
    /**
     *
     * @param pobj
     * @returns {Promise<void>}
     */
    async updateForm(pobj) {
        return null;
    }

    async getFormList (pobj) {
        let res = await this.dao.findAndCountAll(pobj);
        return system.getResult(res);
    }
}

module.exports = ForminfoService;