{"id":5689,"date":"2024-09-05T16:01:01","date_gmt":"2024-09-05T08:01:01","guid":{"rendered":""},"modified":"2024-09-05T16:01:01","modified_gmt":"2024-09-05T08:01:01","slug":"\u63d2\u4ef6\u5f00\u53d1\u8f6f\u4ef6_JavaScript\u63d2\u4ef6\u4e0b\u8f7d","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5689.html","title":{"rendered":"\u63d2\u4ef6\u5f00\u53d1\u8f6f\u4ef6_JavaScript\u63d2\u4ef6\u4e0b\u8f7d"},"content":{"rendered":"
\u5bf9\u4e00\u4e2a\u6570\u636e\u5e93\u8868\u8fdb\u884c\u589e,\u5220,\u4fee\u6539,\u67e5\u8be2\u64cd\u4f5c\u662f\u5e38\u89c1\u7684\u7f16\u7a0b\u4efb\u52a1.
\n
\u7edf\u4e00\u548c\u7b80\u5316\u6b64\u7c7b\u5f00\u53d1\u4efb\u52a1,\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387,\u5305\u62ec\u5b9e\u73b0,\u8c03\u8bd5\u548c\u7ef4\u62a4. <\/p>\n
\u672c\u6587\u4ee5\u5e38\u8d2d\u5546\u54c1\u7684\u529f\u80fd\u4e3a\u4f8b\uff0c\u8bf4\u660e\u57fa\u4e8e\u9700\u6c42\u5b8c\u6574\u5b9e\u73b0\u7684\u8fc7\u7a0b.
\n <\/p>\n
\u63d0\u4f9b\u95e8\u5e97\u7ecf\u5e38\u91c7\u8d2d\u5546\u54c1\u4fe1\u606f\u7684\u7ba1\u7406,\u63d0\u4f9b\u5bf9\u5feb\u6377\u8ba2\u5355\u7684\u652f\u6301.<\/p>\n
\u4e00\u4e2a\u534f\u8bae\u7684\u529f\u80fd\u5355\u4e00\u5316\uff0c\u907f\u514d\u8ba9\u4e00\u4e2a\u534f\u8bae\u627f\u8f7d\u592a\u591a\u529f\u80fd\uff0c\u534f\u8bae\u4e0e\u7528\u4f8b\u4e00\u4e00\u5bf9\u5e94\u4f5c\u4e3a\u8bbe\u8ba1\u539f\u5219\u3002<\/span> \u5e38\u8d2d\u5546\u54c1\u6570\u636e\u7ef4\u62a4\u7684\u534f\u8bae\u90fd\u8bbe\u8ba1\u4e3a\u652f\u6301\u6279\u91cf\u64cd\u4f5c. \u4ee5\u4e0b\u5185\u5bb9\u5728\u8bbe\u8ba1\u9636\u6bb5\u89c4\u5b9a\uff1a<\/p>\n .\u76f8\u5173\u8868\u7ed3\u6784\uff1a\u672c\u4f8b\u6709t_Ven_PreferGoods *\u534f\u8bae\u8bbe\u8ba1\u65f6\u8981\u6c42\u534f\u8bae\u7684\u53c2\u6570\u548c\u884c\u96c6\u5217\u540d\u79f0\u4e0e\u6570\u636e\u5e93\u8868\u4e00\u81f4.<\/span> \u5e38\u8d2d\u5546\u54c1\u8868(t_Ven_PreferGoods)\u7ed3\u6784: CPreferGoods\u7c7b\u5b9a\u4e49:\u5728wiser_data.h <\/p>\n CPreferGoods\u4eceCORMBase\u6d3e\u751f. \u589e\u52a0CPreferGoods\u7ed1\u5b9a(wiser_data.cpp) \u672a\u5b9e\u73b0CPreferGoods::Query\u7684\u539f\u56e0\u662f,<\/span>\u534f\u8bae7296\u5904\u7406\u51fd\u6570\u5229\u7528\u4e86SQLBasedMsgProc\u76f4\u63a5\u4eceSQL\u67e5\u8be2\u8fd4\u56de\u6d88\u606f\u5305,\u4e0d\u9700\u8981\u751f\u6210\u5bf9\u8c61\u7684\u8fc7\u7a0b,\u66f4\u6709\u6548. \u5982\u679c\u67e5\u8be2\u540e\u8fd8\u9700\u8981\u540e\u7eed\u5904\u7406\uff0c\u5219\u91c7\u7528\u5bf9\u8c61\u5316\u65b9\u5f0f\u66f4\u5408\u9002.<\/p>\n \u5728\u63d2\u4ef6Initialize\u4e2d\u589e\u52a0\u521d\u59cb\u5316\u7ed1\u5b9a\uff08CPreferGoods::InitBinder\uff09<\/span><\/p>\n<\/p>\n <\/p>\n \u5728\u63d2\u4ef6\u7c7b\u4e2d(wiser.h\u6587\u4ef6\u4e2d)\u589e\u52a0\u534f\u8bae\u5904\u7406\u51fd\u6570\u5b9a\u4e49. <\/p>\n \u5728\u63d2\u4ef6\u7c7b\u5b9e\u73b0\u6587\u4ef6(wiser.cpp)\u4e2d\u589e\u52a0\u534f\u8bae\u5904\u7406\u51fd\u6570\u6620\u5c04,\u5b9e\u73b0\u5404\u4e2a\u534f\u8bae\u5904\u7406\u51fd\u6570. CORMBase\u7c7b:<\/p>\n \u5934\u6587\u4ef6\uff1aorm_base.h
\n
\u5e38\u8d2d\u5546\u54c1\u76844\u534f\u8bae\u5982\u4e0b:
\n
.\u65b0\u589e\u5e38\u8d2d\u5546\u54c1(7293)
\n
\u652f\u6301\u6279\u91cf\u65b0\u589e
\n
.\u4fee\u6539\u5e38\u8d2d\u5546\u54c1(7294)
\n
\u652f\u6301\u6279\u91cf\u4fee\u6539
\n
.\u5220\u9664\u5e38\u8d2d\u573a\u9891(7295)
\n
\u652f\u6301\u6279\u91cf\u5220\u9664
\n
.\u67e5\u8be2\u5e38\u8d2d\u5546\u54c1(7296) <\/p>\n
\n
\u5e76\u975e\u6240\u6709\u64cd\u4f5c\u90fd\u8981\u652f\u6301\u6279\u91cf\uff0c\u53d6\u51b3\u4e8e\u4ea4\u4e92\u64cd\u4f5c\u754c\u9762\u89c4\u5b9a\u7684\u65b9\u5f0f\uff0c\u6279\u91cf\u5904\u7406\u4e00\u822c\u5bf9\u5e94\u4e00\u4e2a\u5217\u8868\u754c\u9762\uff0c\u8bb0\u5f55\u884c\u6709\u4e00\u4e2a\u52fe\u9009\u6846\u3002
\n
\u5e38\u89c1\u7684\u6279\u91cf\u64cd\u4f5c\u6709\u5220\u9664\uff0c\u72b6\u6001\u6539\u53d8\u3002
\n
\u65b0\u589e\u548c\u4fee\u6539\u5e76\u4e0d\u603b\u662f\u8981\u6c42\u6279\u91cf\u64cd\u4f5c\u3002
\n <\/p>\n2.\u5b9e\u73b0<\/h2>\n
\n
.\u534f\u8bae\u5728\u54ea\u4e2a\u63d2\u4ef6\u4e2d\u5b9e\u73b0:\u672c\u4f8b\u4e3awiser\u63d2\u4ef6
\n
.\u65b0\u589e\u54ea\u4e9b\u7c7b,\u7c7b\u7684\u5934\u6587\u4ef6,\u5b9e\u73b0\u6587\u4ef6(cpp):\u5982\u679c\u53ef\u88ab\u5176\u5b83\u63d2\u4ef6\u8bbf\u95ee\u5219\u628a\u6587\u4ef6\u653e\u5230common\u76ee\u5f55\u4e0b. <\/p>\n
\n <\/p>\n2.1\u6839\u636e\u8868\u7ed3\u6784\u5b9a\u4e49\u7c7b.<\/h3>\n
\n <\/p>\nEId int not null comment '\u8d2d\u4e70\u8005\u4f01\u4e1aid', GoodsID int not null comment '\u5546\u54c1id', CoEId int not null comment '\u4f9b\u8d27\u5546\u4f01\u4e1aid', PackQty int not null comment '\u5e38\u8d2d\u4ef6\u6570'<\/code><\/pre>\n
#include \"slic_data_env.h\" #include \"orm_base.h\" \/\/ \/\/\/< \u5e38\u8d2d\u5546\u54c1 class CPreferGoods : public CORMBase { public: class CQueryCond { \/\/\/< \u5e38\u8d2d\u5546\u54c1\u67e5\u8be2\u6761\u4ef6 public: string key_value_; }; public: SLIC_EID eid_; \/\/\/< \u8d2d\u4e70\u8005\u4f01\u4e1aID SLIC_GOODS_ID goods_id_; \/\/\/< \u5546\u54c1ID SLIC_EID co_eid_; \/\/\/< \u4f9b\u8d27\u8005\u4f01\u4e1aID int pack_qty_; \/\/\/< \u5e38\u8d2d\u6570\u91cf(\u4ef6\u6570) public: CPreferGoods():eid_(0),goods_id_(0),co_eid_(0),pack_qty_(0) { } BIND_DEFINE(CPreferGoods); static int Query(CQueryCond &cond,vector<CPreferGoods*> &data); \/\/\/< \u67e5\u8be2\u5e38\u8d2d\u5546\u54c1 };<\/code><\/pre>\n
\n
\u63d2\u4ef6\u5de5\u7a0b\u4e2d\u52a0\u5165common\\orm_base.cpp. <\/p>\n
\n <\/p>\n\/ BIND_DECLARE_BEGIN(CPreferGoods,\"t_Ven_PreferGoods\") FIELD_BIND3(CPreferGoods,eid_,\"EId\",true), FIELD_BIND3(CPreferGoods,co_eid_,\"CoEId\",true), FIELD_BIND3(CPreferGoods,goods_id_,\"GoodsID\",true), FIELD_BIND1(CPreferGoods,pack_qty_,\"PackQty\"), BIND_DECLARE_END(CPreferGoods) \/ int CPreferGoods::Query(CQueryCond &cond,vector<CPreferGoods*> &data) { return CE_UNIMPLEMENT; \/\/\/< \u672a\u5b9e\u73b0 }<\/code><\/pre>\n
\n <\/p>\nint CWiser::Initialize() { parent::Initialize(); CDataEnv::Init(); INIT_DATAENV_OBJECT(CDataEnv::env_,this->local_dbc_); CPreferGoods::InitBinder(); }<\/code><\/pre>\n
2.2\u534f\u8bae\u5b9e\u73b0<\/h3>\n
class CWiser : public CBasePlugin { \/\/\/< \u67e5\u8be2\u5e38\u8d2d\u5546\u54c1\uff087293\uff09 int OnQueryPreferGoods(CWrappedMsg<> *in,vector<CWrappedMsg<>*> &out,DISPATCH_RESULT &or); \/\/\/< \u65b0\u589e\u64cd\u4f5c\u5e38\u8d2d\u5546\u54c1\uff087294\uff09 int OnAddPreferGoods(CWrappedMsg<> *in,vector<CWrappedMsg<>*> &out,DISPATCH_RESULT &or); \/\/\/< \u4fee\u6539\u5e38\u8d2d\u5546\u54c1\u4fe1\u606f\uff087295\uff09 int OnChangePreferGoods(CWrappedMsg<> *in,vector<CWrappedMsg<>*> &out,DISPATCH_RESULT &or); \/\/\/< \u5220\u9664\u5e38\u8d2d\u5546\u54c1\uff087296\uff09 int OnDeletePreferGoods(CWrappedMsg<> *in,vector<CWrappedMsg<>*> &out,DISPATCH_RESULT &or); };<\/code><\/pre>\n
\n
\u534f\u8bae\u5904\u7406\u51fd\u6570\u53ea\u5217\u4e3e\u4e867294\u548c7293\u7684\u5bf9\u5e94\u51fd\u6570.7295,7296\u7684\u5904\u7406\u4e0e7294\u7c7b\u4f3c,\u5dee\u522b\u662f\u8c03\u7528CPreferGoods\u7684Update,Delete\u65b9\u6cd5\u3002
\n <\/p>\nMSG_FUNC_MAP CWiser::func_[] = { {7293,MT_REQUEST,(MSGFUNC)&OnQueryPreferGoods,true,\"\u67e5\u8be2\u5e38\u8d2d\u5546\u54c1\",\"\"}, {7294,MT_REQUEST,(MSGFUNC)&OnAddPreferGoods,true,\"\u65b0\u589e\u5e38\u8d2d\u5546\u54c1\",\"\"}, {7295,MT_REQUEST,(MSGFUNC)&OnChangePreferGoods,true,\"\u4fee\u6539\u5e38\u8d2d\u5546\u54c1\u4fe1\u606f\",\"\"}, {7296,MT_REQUEST,(MSGFUNC)&OnDeletePreferGoods,true,\"\u5220\u9664\u5e38\u8d2d\u5546\u54c1\",\"\"}, }; \/\/\/< \u65b0\u589e\u64cd\u4f5c\u5e38\u8d2d\u5546\u54c1\uff087294\uff09 int CWiser::OnAddPreferGoods(CWrappedMsg<> *in,vector<CWrappedMsg<>*> &out,DISPATCH_RESULT &or) { CMsg *msg = in->msg; long lEId = 0, lUserID = 0; CHECK_MSG_PARAMETER2(msg,\"EId\",&lEId,-1); \/\/\/< \u68c0\u67e5\u5e76\u8bfb\u53d6\u6d88\u606f\u53c2\u6570,\u5176\u5b83\u7c7b\u4f3c\u5b8f\u89c1BasePlugin.h\u4e2d\u7684\u5b9a\u4e49 CHECK_MSG_PARAMETER2(msg,\"UserID\",&lUserID,-1); CRowset *rs = 0; CHECK_MSG_ROWSET(msg,0,rs,-1); \/\/\/< \u68c0\u67e5\u6d88\u606f\u4e2d\u7684\u884c\u96c6 int rec_num = rs->GetRSMeta(RST_ROW_CNT); GETDBC(pdbor,this->local_dbc_.c_str()); FAIL_RETURN(pdbor->BeginTrans(),,-1); for (int i=0;i<rec_num;i++) { CPreferGoods pg; pg.eid_ = lEId; if (pg.LoadFrom(rs,i)) \/\/\/< \u4ece\u6d88\u606f\u884c\u96c6\u8bb0\u5f55\u52a0\u8f7d\u5bf9\u8c61\u6210\u5458 return -1; if (-1==pg.Insert(1)) return -1; } FAIL_RETURN(pdbor->CommitTrans(),,-1); return 0; } \/\/\/< \u67e5\u8be2\u5e38\u8d2d\u5546\u54c1\uff087293\uff09 int CWiser::OnQueryPreferGoods(CWrappedMsg<> *in,vector<CWrappedMsg<>*> &out,DISPATCH_RESULT &or) { CMsg *msg = in->msg; long lEId = 0, lUserID = 0; CHECK_MSG_PARAMETER2(msg,\"EId\",&lEId,-1); CHECK_MSG_PARAMETER2(msg,\"UserID\",&lUserID,-1); long co_eid=0; msg->GetParam(\"CoEId\",co_eid); string key_value; msg->GetParam(\"KeyValue\",key_value); bool has_key_value = !key_value.empty(); string cond; \/\/\/< \u5904\u7406\u67e5\u8be2\u6761\u4ef6 if (has_key_value) { int key_value_prop = CheckStringProp(key_value); \/\/\/< \u68c0\u67e5\u5b57\u7b26\u4e32\u7279\u6027:\u5168\u6570\u5b57,\u542b\u6c49\u5b57 if (key_value_prop&0x01) { \/\/\/< \u5168\u6570\u5b57 cond = LogMsg(\" (b.barcode like '%%%s%%' or b.mygoodsid like '%%%s%%') \",key_value.c_str(),key_value.c_str()); } else if (key_value_prop&0x02) { \/\/\/< \u542b\u6c49\u5b57 cond = LogMsg(\"b.goodsname like '%%%s%%'\",key_value.c_str()); } else { cond = LogMsg(\" (b.helpcode like '%%%s%%' or b.mygoodsid like '%%%s%%')\",key_value.c_str(),key_value.c_str()); } cond += \" and \"; } if (co_eid) { cond += LogMsg(\"a.coeid=%lu\",co_eid); cond += \" and \"; } if (!cond.empty()) cond.erase(cond.length()-5,5); \/\/\/< \u751f\u6210\u67e5\u8be2SQL string sql = LogMsg(\"select a.CoEid as EId, a.GoodsID,DataVersion,PicVersion from t_ven_PreferGoods a,t_bas_mygoods b\" \" where a.eid=%lu and a.coeid=b.eid and a.goodsid=b.goodsid %s %s order by EId,GoodsID\",lEId,!cond.empty() ? \"and\":\"\",cond.c_str()); return SQLBasedMsgProc(sql,in,out,or); \/\/\/\u6267\u884cSQL\u628a\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef } <\/code><\/pre>\n
3.\u7279\u6b8a\u5904\u7406<\/h2>\n
\n<\/div>\n CPendingOrg po; CMsg *req = new CMsg; req->SetMsgType(MT_REQUEST); req->SetMsgID(1); req->AddParam(\"MyOrgID\",\"1\"); req->AddParam(\"OrgType\",2L); po.LoadFrom(req); \/\/\/< CreateTime,Reason\u5b57\u6bb5\u5bf9\u5e94\u7684\u5c5e\u6027\u672a\u5305\u542b\u5728req\u6d88\u606f\u53c2\u6570\u4e2d \/\/\/< \u4ec5\u8bbe\u7f6e\u6210\u5458\u5e76\u4e0d\u80fd\u8ba9\u5e95\u5c42\u77e5\u6653\u9700\u8981\u4fee\u6539\u5bf9\u5e94\u5b57\u6bb5,\u9700\u8981\u663e\u5f0f\u8bbe\u7f6e\u9700\u8981\u4fee\u6539\u7684\u5b57\u6bb5. CDateTime::GetDateTime(po.create_time_); po.reason_ = 11; po.AddFields(OFFSETOF(CPendingOrg,reason_),OFFSETOF(CPendingOrg,create_time_),-1); \/\/\/< \u6307\u5b9a\u9700\u8981\u66f4\u65b0\u7684\u6210\u5458\u53d8\u91cf,\u652f\u6301\u4e00\u6b21\u6307\u5b9a\u591a\u4e2a\u6210\u5458,\u4ee5-1\u4f5c\u4e3a\u7ed3\u675f\u6807\u5fd7 if (po.Update()) return -1;<\/code><\/pre>\n<\/div>\n
\n<\/div>\n4.\u76f8\u5173\u4ee3\u7801\u8bf4\u660e<\/h2>\n
\n
\u5b9e\u73b0\u6587\u4ef6\uff1aorm_base.cpp
\n <\/p>\n\/\/ class CORMBase { protected: int GenKeyCond(string &cond); \/\/\/< \u751f\u6210\u6761\u4ef6\u8868\u8fbe\u5f0f\u4e32 public: virtual string& GetTableName() = 0; virtual vector<CFieldBind*>& GetKeyFields() = 0; public: virtual CRecordsetBindObjectBase* GetBinder() { return 0; } virtual CRecordsetBindObjectBase* NewBinder(const char *fld,...) { return 0; } virtual CRecordsetBindObjectBase* NewBinder(const char *fld,va_list arg) { return 0; } \/\/\/< \u68c0\u67e5\u5bf9\u8c61\u6570\u636e\u662f\u5426\u6709\u6548 \/\/\/< @return -1:\u9519\u8bef 0:\u65e0\u6548 1:\u6709\u6548 virtual int Check() { return 1; } \/\/\/ @return 0-\u6210\u529f -1-\u5931\u8d25 1-\u5b58\u5728\u4e3b\u952e\u51b2\u7a81 virtual int Insert(short on_dup_error=2); \/\/\/< on_dup_error \u5ffd\u7565-1\uff0c\u6309\u9519\u8bef\u5904\u7406-2,\u66f4\u65b0-3 virtual int Update(); \/\/\/< \u4fee\u6539\u5bf9\u8c61 virtual int Update(const char *fld,...); \/\/\/< \u4fee\u6539\u6307\u5b9a\u7684\u5b57\u6bb5 virtual int Select(const char *fld,...); \/\/\/< \u67e5\u8be2\u6307\u5b9a\u7684\u5b57\u6bb5 virtual int Delete(); virtual int Load(); \/\/\/< \u4ece\u6570\u636e\u5e93\u52a0\u8f7d\u5bf9\u8c61 virtual int LoadFrom(CMsg *msg); \/\/\/< \u4ece\u6d88\u606f\u53c2\u6570\u52a0\u8f7d\u5bf9\u8c61\u6210\u5458 virtual int LoadFrom(CRowset *rs,unsigned long recno); \/\/\/< \u4ece\u6d88\u606f\u884c\u96c6\u8bb0\u5f55\u52a0\u8f7d\u5bf9\u8c61 virtual int SaveTo(CMsg *msg); \/\/\/< \u628a\u5bf9\u8c61\u6210\u5458\u8f93\u51fa\u5230\u6d88\u606f\u53c2\u6570 virtual int ToField(CRowset *rs); \/\/\/< \u628a\u5bf9\u8c61\u6210\u5458\u8f93\u51fa\u5230\u884c\u96c6\u5217\u4fe1\u606f virtual int SaveTo(CRowset *rs); \/\/\/< \u628a\u5bf9\u8c61\u6210\u5458\u8f93\u51fa\u5230\u884c\u96c6\u8bb0\u5f55(\u65b0\u589e\u8bb0\u5f55) virtual int LoadFrom(CRecordset *rs); \/\/\/< \u4ece\u67e5\u8be2\u8bb0\u5f55\u96c6\u52a0\u8f7d\u5bf9\u8c61\u6210\u5458 };<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u63d2\u4ef6\u5f00\u53d1\u8f6f\u4ef6_JavaScript\u63d2\u4ef6\u4e0b\u8f7d\u5bf9\u4e00\u4e2a\u6570\u636e\u5e93\u8868\u8fdb\u884c\u589e,\u5220,\u4fee\u6539,\u67e5\u8be2\u64cd\u4f5c\u662f\u5e38\u89c1\u7684\u7f16\u7a0b\u4efb\u52a1.\u7edf\u4e00\u548c\u7b80\u5316\u6b64\u7c7b\u5f00\u53d1\u4efb\u52a1,\u53ef\u4ee5\u63d0\u9ad8...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5689"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5689"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5689\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}