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){
        console.log(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")
        pobj.code = code;
        pobj.user_id = pobj.userid;
        pobj.user_name = pobj.username;
        let result = await this.create(pobj)
        return system.getResult(result);
    }
    /**
     *
     * @param pobj
     * @returns {Promise<void>}
     */
    async updateForm(pobj) {
        let upData = {
            name:pobj.name,
            form_describe: pobj.form_describe
        }
        let result = await this.updateByWhere(upData,{id:pobj.id})
        return system.getResult(result);
    }

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

module.exports = ForminfoService;