/* uglified */
const utils=require("../../utils/functions"),_=require("../../utils/Underscore");exports.add=function(e,s){if(!(e.id&&e.businessId&&e.shopId&&e.config))throw new Error("参数不完整");nw.process.mainModule.exports.api.db.select("SELECT CONFIG FROM B_EQUIPMENT WHERE ID=?",[e.id],function(n){n.length>0&&nw.process.mainModule.exports.api.setting.update(e,e.id);let i=utils.getInsertSql("B_EQUIPMENT",e);nw.process.mainModule.exports.api.db.exec(i,function(n){n?_.isFunction(s)&&s({code:500,message:n}):(nw.process.mainModule.exports.sync.add("business.updateEquipment",{equipment:e.id,config:JSON.stringify(e.config)}),_.isFunction(s)&&s({code:200}))})})},exports.get=function(e,s){try{if(e=e||{},console.log("setting.get"),e.equipmentId=e.equipmentId||nw.process.mainModule.exports.vue.business.equipment.id,!e.equipmentId)throw new Error("参数不完整");nw.process.mainModule.exports.api.db.select("SELECT CONFIG FROM B_EQUIPMENT WHERE ID=?",[e.equipmentId],function(e){0===e.length?_.isFunction(s)&&s({code:500,message:"找不到此设备的设置"}):_.isFunction(s)&&s({code:200,data:JSON.parse(e[0].CONFIG),message:""})})}catch(e){console.error(e),_.isFunction(s)&&s({code:500,data:null,message:e.message})}},exports.update=function(e,s){if(!e)throw new Error("缺少参数");let n=nw.process.mainModule.exports.vue.business.equipment.id;console.log("setting.update"),delete e.dataVersion;let i=utils.getUpdateSql("B_EQUIPMENT",e,{id:n});nw.process.mainModule.exports.api.db.exec(i,function(n){if(n)_.isFunction(s)&&s({code:500,message:n});else if(nw.process.mainModule.exports.vue.business.base&&nw.process.mainModule.exports.vue.business.base.id){let n={id:nw.process.mainModule.exports.vue.business.equipment.id,businessId:nw.process.mainModule.exports.vue.business.equipment.businessId,shopId:nw.process.mainModule.exports.vue.business.equipment.shopId,code:nw.process.mainModule.exports.vue.business.equipment.code,feature:nw.process.mainModule.exports.vue.business.equipmentfeature,creatTime:nw.process.mainModule.exports.vue.business.equipment.creatTime,modifyTime:nw.process.mainModule.exports.vue.business.equipment.modifyTime,config:JSON.stringify(e.config),dataVersion:null,syncVersion:nw.process.mainModule.exports.vue.business.equipment.syncVersion};nw.process.mainModule.exports.sync.add("business.updateEquipment",n),_.isFunction(s)&&s({code:200,message:""})}})};