Merge branch 'feature/multi_tenancy' into develop
diff --git a/build.gradle b/build.gradle
index 761f8b5..e2b539f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -56,10 +56,12 @@
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.10.1'
compile group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.10.1'
compile group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.10.1'
- compile 'com.supwisdom:payapi-sdk:1.0.9-1-gb3cd8c8'
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.3.4.RELEASE'
+ implementation 'com.supwisdom:payapi-sdk:1.0.11'
+ implementation 'com.supwisdom:multi-tenant-core:1.1.4'
+ implementation 'com.supwisdom:multi-tenant-datasource:1.1.4'
implementation 'com.github.penggle:kaptcha:2.3.2'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
diff --git a/config/application-devel-pg-xkx.properties b/config/application-devel-pg-xkx.properties
index 09f071c..0e5c007 100644
--- a/config/application-devel-pg-xkx.properties
+++ b/config/application-devel-pg-xkx.properties
@@ -1,6 +1,6 @@
spring.main.banner-mode=off
# create and drop tables and sequences, loads import.sql
-spring.jpa.hibernate.ddl-auto=update
+spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
#spring.datasource.continue-on-error=true
@@ -27,11 +27,22 @@
spring.jackson.serialization.fail-on-empty-beans=false
# task setting
-cron.offlinedtl=0/30 * * * * ?
-payapi.logintime=0 0/20 * * * ?
-#restaurant.chkdtltask.cron=0 0/3 * * * ?
+# 对账任务
restaurant.chkdtltask.cron=-
+# 统计任务
restaurant.statement.cron=-
+# 客户信息校对任务
+restaurant.customercheck.cron=-
+# 流水入账任务
+restaurant.submitofflinedtl.cron=-
+# 查询流水状态任务
+restaurant.querydtlresult.cron=-
# payapi setting
-payapi.url=http://localhost:8080/payapi
+payapi.url=http://172.28.201.70:10010/payapi
+payapi.appid=300091
+payapi.appkey=1ec857ac2c7749a4af092cd422e57861
+
+# multi-tenant setting
+multi-tenant.head.key=X-TENANT-ID
+
diff --git a/sql/public_SQL.sql b/sql/public_SQL.sql
new file mode 100644
index 0000000..57af746
--- /dev/null
+++ b/sql/public_SQL.sql
@@ -0,0 +1,12 @@
+create table "public"."tb_tenantconfig"(
+"cfgid" varchar(32) not null,
+"tenant_id" varchar(60) not null,
+"tenant_name" varchar(200),
+"tenant_schema" varchar(30) not null
+);
+alter table "public"."tb_tenantconfig" add constraint "uk_tenantconfig_tenantid" unique ("tenant_id");
+alter table "public"."tb_tenantconfig" add constraint "pk_tenantconfig_cfgid" primary key ("cfgid");
+
+-- INSERT INTO "tb_tenantconfig"("cfgid", "tenant_id", "tenant_name", "tenant_schema") VALUES ('1', 'dlszf.cn', '大理市政府机关食堂', 'dlszfst');
+-- INSERT INTO "tb_tenantconfig"("cfgid", "tenant_id", "tenant_name", "tenant_schema") VALUES ('2', 'ynrcc.cn', '大理农商行食堂', 'dlynrcc');
+-- commit;
\ No newline at end of file
diff --git a/sql/restarant_create_table.sql b/sql/restarant_create_table.sql
new file mode 100644
index 0000000..266e161
--- /dev/null
+++ b/sql/restarant_create_table.sql
@@ -0,0 +1,1334 @@
+-- ----------------------------
+-- Table structure for tb_account
+-- ----------------------------
+CREATE TABLE tb_account (
+ accno varchar(32) NOT NULL,
+ accname varchar(100),
+ availbal numeric(15, 2) NOT NULL,
+ balance numeric(15, 2) NOT NULL,
+ closedate varchar(8),
+ day_limit numeric(15, 2),
+ frozebal numeric(15, 2) NOT NULL,
+ lastday_dpsamt numeric(15, 2),
+ lastday_transamt numeric(15, 2),
+ last_transdate varchar(8),
+ lowfree_flag bool NOT NULL,
+ lowfree_limit numeric(15, 2),
+ max_bal numeric(15, 2),
+ opendate varchar(8) NOT NULL,
+ status varchar(20) NOT NULL,
+ subjno varchar(10),
+ tac varchar(32),
+ userid varchar(32) NOT NULL
+);
+ALTER TABLE tb_account ADD CONSTRAINT tb_account_pkey PRIMARY KEY (accno);
+ALTER TABLE tb_account ADD CONSTRAINT acc_subjno_uk UNIQUE (subjno, userid);
+CREATE INDEX acc_status_idx ON tb_account(status);
+CREATE INDEX acc_userid_idx ON tb_account(userid);
+
+-- ----------------------------
+-- Table structure for tb_apiclient
+-- ----------------------------
+CREATE TABLE tb_apiclient (
+ appid varchar(20) NOT NULL,
+ bcrypt_secret varchar(64) NOT NULL,
+ roles varchar(300),
+ secret varchar(64) NOT NULL,
+ status varchar(10) NOT NULL,
+ thirdurl varchar(200)
+);
+ALTER TABLE tb_apiclient ADD CONSTRAINT tb_apiclient_pkey PRIMARY KEY (appid);
+
+
+-- ----------------------------
+-- Table structure for tb_area
+-- ----------------------------
+CREATE TABLE tb_area (
+ id int4 NOT NULL,
+ addr varchar(240),
+ arealevel int4,
+ areaname varchar(60),
+ fid int4,
+ remark varchar(240)
+);
+ALTER TABLE tb_area ADD CONSTRAINT tb_area_pkey PRIMARY KEY (id);
+
+
+-- ----------------------------
+-- Table structure for tb_businesspara
+-- ----------------------------
+CREATE TABLE tb_businesspara (
+ parakey varchar(60) NOT NULL,
+ paraval varchar(1000)
+);
+ALTER TABLE tb_businesspara ADD CONSTRAINT tb_businesspara_pkey PRIMARY KEY (parakey);
+
+
+-- ----------------------------
+-- Table structure for tb_card
+-- ----------------------------
+CREATE TABLE tb_card (
+ cardno varchar(32) NOT NULL,
+ bankcardno varchar(20),
+ cardphyid varchar(8),
+ cardverno varchar(20),
+ closedate varchar(8),
+ custid varchar(32),
+ expiredate varchar(8),
+ opendate varchar(8),
+ status varchar(10),
+ transstatus varchar(32)
+);
+ALTER TABLE tb_card ADD CONSTRAINT tb_card_pkey PRIMARY KEY (cardno);
+
+
+-- ----------------------------
+-- Table structure for tb_cardver
+-- ----------------------------
+CREATE TABLE tb_cardver (
+ cardverno varchar(20) NOT NULL,
+ accdate varchar(8),
+ adderflag int4,
+ cardno varchar(32),
+ cardphyid varchar(8),
+ createtime varchar(14),
+ custid varchar(32),
+ optype varchar(10),
+ status varchar(10)
+);
+ALTER TABLE tb_cardver ADD CONSTRAINT tb_cardver_pkey PRIMARY KEY (cardverno);
+
+
+-- ----------------------------
+-- Table structure for tb_check_ctl
+-- ----------------------------
+CREATE TABLE tb_check_ctl (
+ id varchar(32) NOT NULL,
+ check_ok bool NOT NULL,
+ checkdate varchar(8) NOT NULL,
+ download_ok bool NOT NULL,
+ lastsaved timestamp(6),
+ remark varchar(1000),
+ startdate varchar(8),
+ statdate varchar(8) NOT NULL
+);
+ALTER TABLE tb_check_ctl ADD CONSTRAINT tb_check_ctl_pkey PRIMARY KEY (id);
+
+
+-- ----------------------------
+-- Table structure for tb_check_detail
+-- ----------------------------
+CREATE TABLE tb_check_detail (
+ id varchar(32) NOT NULL,
+ accdate varchar(8) NOT NULL,
+ amount numeric(15,2) NOT NULL,
+ chkresult varchar(20),
+ lastsaved timestamp(6),
+ local_refno varchar(32) NOT NULL,
+ other_refno varchar(32) NOT NULL,
+ other_sourcetype varchar(32) NOT NULL,
+ remark varchar(200),
+ resolved varchar(20),
+ shopaccno varchar(32) NOT NULL,
+ paytime varchar(32)
+);
+ALTER TABLE tb_check_detail ADD CONSTRAINT tb_check_detail_pkey PRIMARY KEY (id);
+ALTER TABLE tb_check_detail ADD CONSTRAINT uk_check_detail UNIQUE (accdate, shopaccno, local_refno);
+CREATE INDEX idx_check_detail_accdate ON tb_check_detail(accdate);
+
+
+-- ----------------------------
+-- Table structure for tb_check_file
+-- ----------------------------
+CREATE TABLE tb_check_file (
+ accdate varchar(8) NOT NULL,
+ chkresult varchar(20) NOT NULL,
+ lastsaved timestamp(6),
+ localamt numeric(15,2) NOT NULL,
+ localcnt int4 NOT NULL,
+ otheramt numeric(15,2) NOT NULL,
+ othercnt int4 NOT NULL,
+ remark varchar(1000),
+ status varchar(20) NOT NULL
+);
+ALTER TABLE tb_check_file ADD CONSTRAINT tb_check_file_pkey PRIMARY KEY (accdate);
+
+
+-- ----------------------------
+-- Table structure for tb_customer
+-- ----------------------------
+CREATE TABLE tb_customer (
+ custid varchar(32) NOT NULL,
+ batchno varchar(14),
+ checkstatus varchar(10),
+ custname varchar(30),
+ custtype int4,
+ idno varchar(20),
+ idtype varchar(10),
+ lastsaved varchar(14),
+ operid varchar(100),
+ phone varchar(11),
+ status varchar(10),
+ deptcode varchar(32)
+);
+ALTER TABLE tb_customer ADD CONSTRAINT tb_customer_pkey PRIMARY KEY (custid);
+CREATE INDEX customer_custid_idx ON tb_customer(custid);
+CREATE INDEX customer_name_idx ON tb_customer(custname);
+
+
+-- ----------------------------
+-- Table structure for tb_customerlist
+-- ----------------------------
+CREATE TABLE tb_customerlist (
+ cardno varchar(255) NOT NULL,
+ listid varchar(255) NOT NULL,
+ custname varchar(100),
+ lastsaved varchar(14),
+ listname varchar(50)
+);
+ALTER TABLE tb_customerlist ADD CONSTRAINT tb_customerlist_pkey PRIMARY KEY (cardno, listid);
+
+
+-- ----------------------------
+-- Table structure for tb_custtype
+-- ----------------------------
+CREATE TABLE tb_custtype (
+ custtypeid int4 NOT NULL,
+ custtypename varchar(20),
+ feetype int4
+);
+ALTER TABLE tb_custtype ADD CONSTRAINT tb_custtype_pkey PRIMARY KEY (custtypeid);
+
+
+-- ----------------------------
+-- Table structure for tb_dept
+-- ----------------------------
+CREATE TABLE tb_dept (
+ deptcode varchar(32) NOT NULL,
+ deptname varchar(255),
+ deptno varchar(20) NOT NULL,
+ ename varchar(255),
+ fdeptcode varchar(32) NOT NULL,
+ lastsaved varchar(20),
+ status varchar(255) NOT NULL
+);
+ALTER TABLE tb_dept ADD CONSTRAINT tb_dept_pkey PRIMARY KEY (deptcode);
+ALTER TABLE tb_dept ADD CONSTRAINT uk_dept_deptno UNIQUE (deptno);
+
+
+-- ----------------------------
+-- Table structure for tb_device
+-- ----------------------------
+CREATE TABLE tb_device (
+ id int4 NOT NULL,
+ beatstatus int4,
+ cardverno varchar(20),
+ checkername varchar(20),
+ checkstatus varchar(14),
+ devgroupid int4,
+ devicename varchar(60),
+ devphyid varchar(20),
+ factoryid varchar(10),
+ lastbeattime varchar(14),
+ lastlogintime varchar(14),
+ lastsaved varchar(14),
+ operid varchar(100),
+ runstatus int4,
+ shopid varchar(15),
+ state int4
+);
+ALTER TABLE tb_device ADD CONSTRAINT tb_device_pkey PRIMARY KEY (id);
+ALTER TABLE tb_device ADD CONSTRAINT uk_device_devphyid UNIQUE (devphyid);
+
+
+-- ----------------------------
+-- Table structure for tb_devicegroup
+-- ----------------------------
+CREATE TABLE tb_devicegroup (
+ devgroupid int4 NOT NULL,
+ groupname varchar(60),
+ operid varchar(100),
+ pid int4,
+ grouptype varchar(10)
+);
+ALTER TABLE tb_devicegroup ADD CONSTRAINT tb_devicegroup_pkey PRIMARY KEY (devgroupid);
+
+
+-- ----------------------------
+-- Table structure for tb_devpara
+-- ----------------------------
+CREATE TABLE tb_devpara (
+ paraname varchar(60) NOT NULL,
+ groupid int4 NOT NULL,
+ maxval varchar(10),
+ minval varchar(10),
+ paradesc varchar(600),
+ paraval varchar(90),
+ valtype varchar(10)
+);
+ALTER TABLE tb_devpara ADD CONSTRAINT tb_devpara_pkey PRIMARY KEY (paraname, groupid);
+
+
+-- ----------------------------
+-- Table structure for tb_devpara_bind
+-- ----------------------------
+CREATE TABLE tb_devpara_bind (
+ deviceid int4 NOT NULL,
+ groupid int4 NOT NULL,
+ lastsaved varchar(14)
+);
+ALTER TABLE tb_devpara_bind ADD CONSTRAINT tb_devpara_bind_pkey PRIMARY KEY (deviceid);
+
+
+-- ----------------------------
+-- Table structure for tb_devpara_group
+-- ----------------------------
+CREATE TABLE tb_devpara_group (
+ groupid int4 NOT NULL,
+ globalflag bool NOT NULL,
+ groupname varchar(200),
+ lastsaved varchar(14),
+ verno int8 NOT NULL
+);
+ALTER TABLE tb_devpara_group ADD CONSTRAINT tb_devpara_group_pkey PRIMARY KEY (groupid);
+
+
+
+-- ----------------------------
+-- Table structure for tb_dictionary
+-- ----------------------------
+CREATE TABLE tb_dictionary (
+ dictval varchar(30) NOT NULL,
+ dicttype varchar(255) NOT NULL,
+ dictcaption varchar(60),
+ dicttypename varchar(60)
+);
+ALTER TABLE tb_dictionary ADD CONSTRAINT tb_dictionary_pkey PRIMARY KEY (dictval, dicttype);
+
+
+
+-- ----------------------------
+-- Table structure for tb_discount_detail
+-- ----------------------------
+CREATE TABLE tb_discount_detail (
+ id varchar(32) NOT NULL,
+ cardno varchar(20),
+ lastsaved varchar(14),
+ ruleid int4,
+ status varchar(10) NOT NULL,
+ userid varchar(32),
+ username varchar(60)
+);
+ALTER TABLE tb_discount_detail ADD CONSTRAINT tb_discount_detail_pkey PRIMARY KEY (id);
+CREATE INDEX discountdetail_ruleid_idx ON tb_discount_detail(ruleid);
+
+
+-- ----------------------------
+-- Table structure for tb_discount_devbind
+-- ----------------------------
+CREATE TABLE tb_discount_devbind (
+ id varchar(32) NOT NULL,
+ create_operid varchar(32),
+ createtime varchar(14),
+ deviceid int4 NOT NULL,
+ ruleid int4 NOT NULL
+);
+ALTER TABLE tb_discount_devbind ADD CONSTRAINT tb_discount_devbind_pkey PRIMARY KEY (id);
+ALTER TABLE tb_discount_devbind ADD CONSTRAINT discount_devbind_uk UNIQUE (deviceid, ruleid);
+
+
+-- ----------------------------
+-- Table structure for tb_discount_rule
+-- ----------------------------
+CREATE TABLE tb_discount_rule (
+ ruleid int4 NOT NULL,
+ amount numeric(9,2) NOT NULL,
+ check_operid varchar(32),
+ create_operid varchar(32),
+ createtime varchar(14),
+ detail_status int4 NOT NULL,
+ endtime varchar(4) NOT NULL,
+ lastsaved varchar(14),
+ limitcnt int4 NOT NULL,
+ remark varchar(600),
+ rulename varchar(200) NOT NULL,
+ ruletype varchar(10) NOT NULL,
+ starttime varchar(4) NOT NULL,
+ status varchar(10) NOT NULL,
+ verno int4 NOT NULL
+);
+ALTER TABLE tb_discount_rule ADD CONSTRAINT tb_discount_rule_pkey PRIMARY KEY (ruleid);
+
+
+-- ----------------------------
+-- Table structure for tb_feetype_config
+-- ----------------------------
+CREATE TABLE tb_feetype_config (
+ paytype varchar(20) NOT NULL,
+ feetype varchar(20) NOT NULL,
+ crsubjno varchar(10),
+ drsubjno varchar(10),
+ summary varchar(200)
+);
+ALTER TABLE tb_feetype_config ADD CONSTRAINT tb_feetype_config_pkey PRIMARY KEY (paytype, feetype);
+
+
+-- ----------------------------
+-- Table structure for tb_function
+-- ----------------------------
+CREATE TABLE tb_function (
+ id int4 NOT NULL,
+ createtime varchar(14),
+ isleaf int4 NOT NULL,
+ lastsaved varchar(14),
+ menuicon varchar(255),
+ menuurl varchar(60) NOT NULL,
+ name varchar(32),
+ ordernum int4,
+ parentid int4
+);
+ALTER TABLE tb_function ADD CONSTRAINT tb_function_pkey PRIMARY KEY (id);
+
+
+-- ----------------------------
+-- Table structure for tb_mealsdtl
+-- ----------------------------
+CREATE TABLE tb_mealsdtl (
+ id varchar(15) NOT NULL,
+ amount numeric(9,2),
+ checkdate varchar(8) NOT NULL,
+ count int4,
+ deptcode varchar(9) NOT NULL,
+ devgroupid int4 NOT NULL,
+ deviceid varchar(9),
+ feeamount numeric(9,2),
+ feecount int4,
+ mealtype varchar(10) NOT NULL
+);
+ALTER TABLE tb_mealsdtl ADD CONSTRAINT tb_mealsdtl_pkey PRIMARY KEY (id);
+CREATE INDEX mealsdtl_idx ON tb_mealsdtl(checkdate,mealtype,deptcode,devgroupid,deviceid);
+
+
+-- ----------------------------
+-- Table structure for tb_mealtype
+-- ----------------------------
+CREATE TABLE tb_mealtype (
+ mealtype varchar(255) NOT NULL,
+ endtime varchar(255) NOT NULL,
+ lastsaved varchar(255) NOT NULL,
+ mealname varchar(255) NOT NULL
+);
+ALTER TABLE tb_mealtype ADD CONSTRAINT tb_mealtype_pkey PRIMARY KEY (mealtype);
+
+
+-- ----------------------------
+-- Table structure for tb_offlinetransdtl
+CREATE TABLE tb_offlinetransdtl (
+ billno varchar(20) NOT NULL,
+ accdate varchar(8),
+ acctime varchar(6),
+ amount numeric(9,2),
+ attr1 varchar(1000),
+ cardno varchar(9),
+ custid varchar(32),
+ custname varchar(30),
+ custtype int4,
+ managefee numeric(9,2),
+ mealtype varchar(10),
+ revbillno varchar(20),
+ revflag int4,
+ ruleid int4,
+ shopid varchar(15),
+ status varchar(10),
+ termid int4,
+ termsqlno int4,
+ transdate varchar(8),
+ transmode varchar(255),
+ transtime varchar(6),
+ transtype varchar(10)
+);
+ALTER TABLE tb_offlinetransdtl ADD CONSTRAINT tb_offlinetransdtl_pkey PRIMARY KEY (billno);
+
+
+-- ----------------------------
+-- Table structure for tb_oper_log
+-- ----------------------------
+CREATE TABLE tb_oper_log (
+ id varchar(32) NOT NULL,
+ functionid int4,
+ functionname varchar(255),
+ logdate varchar(255),
+ operid varchar(32) NOT NULL,
+ opername varchar(255),
+ resname varchar(255),
+ respath varchar(255)
+);
+ALTER TABLE tb_oper_log ADD CONSTRAINT tb_oper_log_pkey PRIMARY KEY (id);
+
+
+-- ----------------------------
+-- Table structure for tb_oper_role
+-- ----------------------------
+CREATE TABLE tb_oper_role (
+ id varchar(32) NOT NULL,
+ operid varchar(32) NOT NULL,
+ roleid varchar(32) NOT NULL
+);
+ALTER TABLE tb_oper_role ADD CONSTRAINT tb_oper_role_pkey PRIMARY KEY (id);
+CREATE INDEX operrole_operid_idx ON tb_oper_role(operid);
+
+
+-- ----------------------------
+-- Table structure for tb_operator
+-- ----------------------------
+CREATE TABLE tb_operator (
+ operid varchar(32) NOT NULL,
+ closedate varchar(8),
+ email varchar(60),
+ mobile varchar(20),
+ opendate varchar(8),
+ opercode varchar(20) NOT NULL,
+ opername varchar(100) NOT NULL,
+ operpwd varchar(80) NOT NULL,
+ opertype varchar(20) NOT NULL,
+ sex varchar(10),
+ status varchar(32) NOT NULL
+);
+ALTER TABLE tb_operator ADD CONSTRAINT tb_operator_pkey PRIMARY KEY (operid);
+ALTER TABLE tb_operator ADD CONSTRAINT opercode_idx UNIQUE (opercode);
+
+
+-- ----------------------------
+-- Table structure for tb_paytype
+-- ----------------------------
+CREATE TABLE tb_paytype (
+ paytype varchar(20) NOT NULL,
+ anonymous_enable varchar(10) NOT NULL,
+ charge_enable varchar(10) NOT NULL,
+ consume_enable varchar(10) NOT NULL,
+ enable varchar(20) NOT NULL,
+ paydesc varchar(200)
+);
+ALTER TABLE tb_paytype ADD CONSTRAINT tb_paytype_pkey PRIMARY KEY (paytype);
+
+
+-- ----------------------------
+-- Table structure for tb_paytype_config
+-- ----------------------------
+CREATE TABLE tb_paytype_config (
+ paytype varchar(20) NOT NULL,
+ configid varchar(40) NOT NULL,
+ config_name varchar(200),
+ config_value varchar(2000)
+);
+ALTER TABLE tb_paytype_config ADD CONSTRAINT tb_paytype_config_pkey PRIMARY KEY (paytype, configid);
+
+
+-- ----------------------------
+-- Table structure for tb_period
+-- ----------------------------
+CREATE TABLE tb_period (
+ period_year int4 NOT NULL,
+ period_month int4 NOT NULL,
+ enddate varchar(8) NOT NULL,
+ settleflag int4 NOT NULL,
+ startdate varchar(8) NOT NULL
+);
+ALTER TABLE tb_period ADD CONSTRAINT tb_period_pkey PRIMARY KEY (period_year, period_month);
+
+
+-- ----------------------------
+-- Table structure for tb_permission
+-- ----------------------------
+CREATE TABLE tb_permission (
+ id varchar(32) NOT NULL,
+ resid int4,
+ role_func_id varchar(32),
+ roleid varchar(32)
+);
+ALTER TABLE tb_permission ADD CONSTRAINT tb_permission_pkey PRIMARY KEY (id);
+
+
+-- ----------------------------
+-- Table structure for tb_person
+-- ----------------------------
+CREATE TABLE tb_person (
+ userid varchar(32) NOT NULL,
+ addr varchar(240),
+ country varchar(3),
+ email varchar(60),
+ idno varchar(30),
+ idtype varchar(20),
+ lastsaved varchar(14),
+ mobile varchar(30),
+ name varchar(200),
+ nation varchar(3),
+ sex varchar(10),
+ status varchar(10) NOT NULL,
+ tel varchar(20),
+ zipcode varchar(10)
+);
+ALTER TABLE tb_person ADD CONSTRAINT tb_person_pkey PRIMARY KEY (userid);
+ALTER TABLE tb_person ADD CONSTRAINT person_idno_uk UNIQUE (idtype, idno);
+CREATE INDEX person_name_idx ON tb_person(name);
+
+-- ----------------------------
+-- Table structure for tb_person_identity
+-- ----------------------------
+CREATE TABLE tb_person_identity (
+ third_uid varchar(60) NOT NULL,
+ createtime varchar(14),
+ lockflag int4 NOT NULL,
+ lossflag int4 NOT NULL,
+ status varchar(20) NOT NULL,
+ userid varchar(32)
+);
+ALTER TABLE tb_person_identity ADD CONSTRAINT tb_person_identity_pkey PRIMARY KEY (third_uid);
+ALTER TABLE tb_person_identity ADD CONSTRAINT fke0ix8ckx4xadoo6yrx0dkmrc0 FOREIGN KEY (userid) REFERENCES tb_person (userid) ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+
+-- ----------------------------
+-- Table structure for tb_points_account
+-- ----------------------------
+CREATE TABLE tb_points_account (
+ userid varchar(32) NOT NULL,
+ accumpoints int8,
+ lastsaved varchar(255),
+ points int8 NOT NULL,
+ sumpaypoints int8,
+ tac varchar(255)
+);
+ALTER TABLE tb_points_account ADD CONSTRAINT tb_points_account_pkey PRIMARY KEY (userid);
+
+
+-- ----------------------------
+-- Table structure for tb_points_transdtl
+-- ----------------------------
+CREATE TABLE tb_points_transdtl (
+ refno varchar(32) NOT NULL,
+ accdate varchar(8),
+ aftpoints int8,
+ befpoints int8,
+ billno varchar(32),
+ points int8 NOT NULL,
+ status varchar(15),
+ transdate varchar(8),
+ transtime varchar(9),
+ userid varchar(32) NOT NULL
+);
+ALTER TABLE tb_points_transdtl ADD CONSTRAINT tb_points_transdtl_pkey PRIMARY KEY (refno);
+CREATE INDEX points_transdtl_idx ON tb_points_transdtl (billno);
+
+
+-- ----------------------------
+-- Table structure for tb_resource
+-- ----------------------------
+CREATE TABLE tb_resource (
+ id int4 NOT NULL,
+ code varchar(32) NOT NULL,
+ function_id int4 NOT NULL,
+ name varchar(32),
+ uri varchar(32)
+);
+ALTER TABLE tb_resource ADD CONSTRAINT tb_resource_pkey PRIMARY KEY (id);
+
+
+
+-- ----------------------------
+-- Table structure for tb_role
+-- ----------------------------
+CREATE TABLE tb_role (
+ roleid varchar(32) NOT NULL,
+ createtime varchar(14),
+ editflag int4,
+ lastsaved varchar(14),
+ rolecode varchar(20) NOT NULL,
+ roledesc varchar(60),
+ rolename varchar(60) NOT NULL
+);
+ALTER TABLE tb_role ADD CONSTRAINT tb_role_pkey PRIMARY KEY (roleid);
+
+
+
+-- ----------------------------
+-- Table structure for tb_role_function
+-- ----------------------------
+CREATE TABLE tb_role_function (
+ id varchar(32) NOT NULL,
+ functionid int4 NOT NULL,
+ permissions varchar(200),
+ roleid varchar(32) NOT NULL
+);
+ALTER TABLE tb_role_function ADD CONSTRAINT tb_role_function_pkey PRIMARY KEY (id);
+
+
+-- ----------------------------
+-- Table structure for tb_rpt_mealsdtl
+-- ----------------------------
+CREATE TABLE tb_rpt_mealsdtl (
+ id varchar(32) NOT NULL,
+ checkdate varchar(8) NOT NULL,
+ custtype int4 NOT NULL,
+ deptcode varchar(32) NOT NULL,
+ devgroupid int4 NOT NULL,
+ deviceid int4 NOT NULL,
+ feeamt numeric(15,2),
+ feecnt int4,
+ mealtype varchar(20) NOT NULL,
+ paytype varchar(32) NOT NULL,
+ totalamt numeric(15,2),
+ totalcnt int4
+);
+ALTER TABLE tb_rpt_mealsdtl ADD CONSTRAINT tb_rpt_mealsdtl_pkey PRIMARY KEY (id);
+ALTER TABLE tb_rpt_mealsdtl ADD CONSTRAINT uk_rpt_mealsdtl UNIQUE (checkdate, deptcode, custtype, devgroupid, deviceid, mealtype, paytype);
+
+-- ----------------------------
+-- Table structure for tb_settle_log
+-- ----------------------------
+CREATE TABLE tb_settle_log (
+ id varchar(32) NOT NULL,
+ endtime varchar(14),
+ errcode varchar(10),
+ errmsg varchar(600),
+ starttime varchar(14)
+);
+ALTER TABLE tb_settle_log ADD CONSTRAINT tb_settle_log_pkey PRIMARY KEY (id);
+
+
+
+-- ----------------------------
+-- Table structure for tb_settlectl
+-- ----------------------------
+CREATE TABLE tb_settlectl (
+ booksetno int4 NOT NULL,
+ periodmonth int4 NOT NULL,
+ periodyear int4 NOT NULL,
+ settledate int4 NOT NULL,
+ statdate int4,
+ status int4 NOT NULL,
+ updtime varchar(14)
+);
+ALTER TABLE tb_settlectl ADD CONSTRAINT tb_settlectl_pkey PRIMARY KEY (booksetno);
+
+
+-- ----------------------------
+-- Table structure for tb_shop
+-- ----------------------------
+CREATE TABLE tb_shop (
+ shopid int4 NOT NULL,
+ addr varchar(240),
+ closedate varchar(8),
+ contactman varchar(60),
+ email varchar(60),
+ fshopid int4,
+ idno varchar(60),
+ idtype varchar(1),
+ mobile varchar(30),
+ opendate varchar(8),
+ shopaccno varchar(20),
+ shopname varchar(200),
+ shoptype int4,
+ status varchar(20),
+ tel varchar(20),
+ third_unique_identy varchar(200),
+ zipcode varchar(10)
+);
+ALTER TABLE tb_shop ADD CONSTRAINT tb_shop_pkey PRIMARY KEY (shopid);
+CREATE INDEX shop_shopaccno_idx ON tb_shop(shopaccno);
+
+
+-- ----------------------------
+-- Table structure for tb_shop_paytype
+-- ----------------------------
+CREATE TABLE tb_shop_paytype (
+ shopaccno varchar(10) NOT NULL,
+ paytype varchar(20) NOT NULL,
+ anonymous_enable varchar(10) NOT NULL,
+ consume_enable varchar(10) NOT NULL,
+ createtime varchar(14),
+ reverse_enable varchar(10) NOT NULL
+);
+ALTER TABLE tb_shop_paytype ADD CONSTRAINT tb_shop_paytype_pkey PRIMARY KEY (shopaccno, paytype);
+
+
+-- ----------------------------
+-- Table structure for tb_shop_paytype_config
+-- ----------------------------
+CREATE TABLE tb_shop_paytype_config (
+ cfgid int4 NOT NULL,
+ config_name varchar(200),
+ config_value varchar(2000),
+ configid varchar(40) NOT NULL,
+ paytype varchar(20) NOT NULL,
+ shopaccno varchar(10) NOT NULL
+);
+ALTER TABLE tb_shop_paytype_config ADD CONSTRAINT tb_shop_paytype_config_pkey PRIMARY KEY (cfgid);
+ALTER TABLE tb_shop_paytype_config ADD CONSTRAINT shop_paytype_config_uk UNIQUE (shopaccno, paytype, configid);
+
+
+-- ----------------------------
+-- Table structure for tb_shopacc
+-- ----------------------------
+CREATE TABLE tb_shopacc (
+ shopaccno varchar(10) NOT NULL,
+ closedate varchar(8),
+ opendate varchar(8),
+ shopid int4,
+ shopname varchar(200),
+ status varchar(20),
+ subjno varchar(10)
+);
+ALTER TABLE tb_shopacc ADD CONSTRAINT tb_shopacc_pkey PRIMARY KEY (shopaccno);
+
+
+-- ----------------------------
+-- Table structure for tb_shopaccbal
+-- ----------------------------
+CREATE TABLE tb_shopaccbal (
+ shopaccno varchar(10) NOT NULL,
+ accumcramt numeric(15,2),
+ accumdramt numeric(15,2),
+ balance numeric(15,2),
+ beginbal numeric(15,2),
+ cramt numeric(15,2),
+ dramt numeric(15,2),
+ lastsettleday varchar(8),
+ settletotalamt numeric(15,2),
+ updtime varchar(255)
+);
+ALTER TABLE tb_shopaccbal ADD CONSTRAINT tb_shopaccbal_pkey PRIMARY KEY (shopaccno);
+
+
+-- ----------------------------
+-- Table structure for tb_shopaccday
+-- ----------------------------
+CREATE TABLE tb_shopaccday (
+ shopaccno varchar(10) NOT NULL,
+ accdate varchar(8) NOT NULL,
+ balance numeric(15,2),
+ beginbal numeric(15,2),
+ cramt numeric(15,2),
+ dramt numeric(15,2),
+ period_month int4,
+ period_year int4,
+ updtime varchar(255)
+);
+ALTER TABLE tb_shopaccday ADD CONSTRAINT tb_shopaccday_pkey PRIMARY KEY (shopaccno, accdate);
+
+
+-- ----------------------------
+-- Table structure for tb_shopdevice
+-- ----------------------------
+CREATE TABLE tb_shopdevice (
+ deviceid int4 NOT NULL,
+ operid varchar(32) NOT NULL,
+ shopid varchar(15) NOT NULL
+);
+ALTER TABLE tb_shopdevice ADD CONSTRAINT tb_shopdevice_pkey PRIMARY KEY (deviceid);
+
+
+-- ----------------------------
+-- Table structure for tb_shopsettlement
+-- ----------------------------
+CREATE TABLE tb_shopsettlement (
+ shopsettlementno int4 NOT NULL,
+ operno varchar(40),
+ shopid varchar(255),
+ shopname varchar(200)
+);
+ALTER TABLE tb_shopsettlement ADD CONSTRAINT tb_shopsettlement_pkey PRIMARY KEY (shopsettlementno);
+ALTER TABLE tb_shopsettlement ADD CONSTRAINT uk_shopsettlement_shopid UNIQUE (shopid);
+
+
+-- ----------------------------
+-- Table structure for tb_sourcetype
+-- ----------------------------
+CREATE TABLE tb_sourcetype (
+ sourcetype varchar(20) NOT NULL,
+ anonymous_enable bool NOT NULL,
+ charge_enable bool NOT NULL,
+ checkable bool NOT NULL,
+ consume_enable bool NOT NULL,
+ enable bool NOT NULL,
+ paydesc varchar(200),
+ reversable bool NOT NULL
+);
+ALTER TABLE tb_sourcetype ADD CONSTRAINT tb_sourcetype_pkey PRIMARY KEY (sourcetype);
+
+
+-- ----------------------------
+-- Table structure for tb_subject
+-- ----------------------------
+CREATE TABLE tb_subject (
+ subjno varchar(10) NOT NULL,
+ balflag int4,
+ displayflag varchar(1),
+ endflag int4,
+ fsubjno varchar(10),
+ opendate int4,
+ subjlevel int4,
+ subjname varchar(60) NOT NULL,
+ subjtype int4
+);
+ALTER TABLE tb_subject ADD CONSTRAINT tb_subject_pkey PRIMARY KEY (subjno);
+
+
+-- ----------------------------
+-- Table structure for tb_subjectbal
+-- ----------------------------
+CREATE TABLE tb_subjectbal (
+ subjno varchar(10) NOT NULL,
+ accumcramt numeric(15,2),
+ accumdramt numeric(15,2),
+ accumsettleamt numeric(15,2),
+ begincrbal numeric(15,2),
+ begindrbal numeric(15,2),
+ cramt numeric(15,2),
+ crbal numeric(15,2),
+ dramt numeric(15,2),
+ drbal numeric(15,2),
+ lastsettleday int4,
+ updtime varchar(14)
+);
+ALTER TABLE tb_subjectbal ADD CONSTRAINT tb_subjectbal_pkey PRIMARY KEY (subjno);
+
+
+-- ----------------------------
+-- Table structure for tb_subjectday
+-- ----------------------------
+CREATE TABLE tb_subjectday (
+ subjno varchar(10) NOT NULL,
+ accdate varchar(8) NOT NULL,
+ begincrbal numeric(15,2),
+ begindrbal numeric(15,2),
+ cramt numeric(15,2),
+ crbal numeric(15,2),
+ dramt numeric(15,2),
+ drbal numeric(15,2),
+ period_month int4,
+ period_year int4,
+ updtime varchar(255)
+);
+ALTER TABLE tb_subjectday ADD CONSTRAINT tb_subjectday_pkey PRIMARY KEY (subjno, accdate);
+
+
+-- ----------------------------
+-- Table structure for tb_syspara
+-- ----------------------------
+CREATE TABLE tb_syspara (
+ paraid int4 NOT NULL,
+ displayflag varchar(10),
+ editflag int4 NOT NULL,
+ lastsaved varchar(14),
+ paraname varchar(90),
+ paraunit varchar(20),
+ paraval varchar(100),
+ remark varchar(240),
+ valuetype varchar(10)
+);
+ALTER TABLE tb_syspara ADD CONSTRAINT tb_syspara_pkey PRIMARY KEY (paraid);
+
+
+-- ----------------------------
+-- Table structure for tb_task_lock
+-- ----------------------------
+CREATE TABLE tb_task_lock (
+ taskcode varchar(30) NOT NULL,
+ remark varchar(600),
+ taskstatus int4 NOT NULL,
+ tasktime varchar(20)
+);
+ALTER TABLE tb_task_lock ADD CONSTRAINT tb_task_lock_pkey PRIMARY KEY (taskcode);
+
+-- ----------------------------
+-- Table structure for tb_tenant_jwtconfig
+-- ----------------------------
+CREATE TABLE tb_tenant_jwtconfig (
+ id varchar(20) NOT NULL,
+ jwt_secret varchar(200) NOT NULL
+);
+ALTER TABLE tb_tenant_jwtconfig ADD CONSTRAINT tb_tenant_jwtconfig_pkey PRIMARY KEY (id);
+
+
+-- ----------------------------
+-- Table structure for tb_transcode
+-- ----------------------------
+CREATE TABLE tb_transcode (
+ transcode int4 NOT NULL,
+ transname varchar(100) NOT NULL
+);
+ALTER TABLE tb_transcode ADD CONSTRAINT tb_transcode_pkey PRIMARY KEY (transcode);
+
+
+-- ----------------------------
+-- Table structure for tb_transdtl
+-- ----------------------------
+CREATE TABLE tb_transdtl (
+ billno varchar(20) NOT NULL,
+ accdate varchar(8),
+ acctime varchar(6),
+ amount numeric(9,2) NOT NULL,
+ attr1 varchar(1000),
+ cardno varchar(9),
+ core_accdate varchar(8),
+ core_status varchar(20),
+ custid varchar(32),
+ custname varchar(30),
+ custtype int4,
+ managefee numeric(9,2),
+ managefeetype varchar(15),
+ mealtype varchar(10),
+ refno varchar(32),
+ revbillno varchar(20),
+ revflag int4,
+ ruleid int4,
+ shopid varchar(15),
+ status varchar(10),
+ termid int4,
+ termsqlno int4,
+ transdate varchar(8) NOT NULL,
+ transmode varchar(10),
+ transtime varchar(6) NOT NULL,
+ transtype varchar(10),
+ core_sourcetype varchar(32)
+);
+ALTER TABLE tb_transdtl ADD CONSTRAINT tb_transdtl_pkey PRIMARY KEY (billno);
+CREATE INDEX transdtl_accdate_idx ON tb_transdtl(accdate);
+CREATE INDEX transdtl_coreaccdate_idx ON tb_transdtl(core_accdate,status);
+CREATE INDEX transdtl_status_idx ON tb_transdtl(status);
+CREATE INDEX transdtl_transdate_idx ON tb_transdtl (transdate);
+
+
+-- ----------------------------
+-- Table structure for tb_transtype
+-- ----------------------------
+CREATE TABLE tb_transtype (
+ transtype int4 NOT NULL,
+ crsubjno varchar(10),
+ drsubjno varchar(10),
+ summary varchar(200)
+);
+ALTER TABLE tb_transtype ADD CONSTRAINT tb_transtype_pkey PRIMARY KEY (transtype);
+
+
+
+-- ----------------------------
+-- Table structure for tb_userdtl
+-- ----------------------------
+CREATE TABLE tb_userdtl (
+ refno varchar(32) NOT NULL,
+ accdate varchar(8),
+ aftbal numeric(9,2),
+ amount numeric(9,2),
+ befbal numeric(9,2),
+ createtime varchar(14),
+ endtime varchar(14),
+ operid int4,
+ outtradeno varchar(60),
+ payinfo varchar(200),
+ paytype varchar(20),
+ remark varchar(240),
+ reverse_amount numeric(9,2),
+ reverse_flag varchar(255) NOT NULL,
+ shopaccno varchar(20),
+ status varchar(20),
+ tradeflag int4 NOT NULL,
+ transcode int4,
+ transdate varchar(8),
+ transdesc varchar(240),
+ transtime varchar(6),
+ userid varchar(32)
+);
+ALTER TABLE tb_userdtl ADD CONSTRAINT tb_userdtl_pkey PRIMARY KEY (refno);
+ALTER TABLE tb_userdtl ADD CONSTRAINT userdtl_outtradeno_uk UNIQUE (outtradeno, shopaccno);
+CREATE INDEX userdtl_accdate_idx ON tb_userdtl(accdate);
+CREATE INDEX userdtl_reverse_idx ON tb_userdtl(reverse_flag);
+CREATE INDEX userdtl_status_idx ON tb_userdtl(status);
+CREATE INDEX userdtl_transdate_idx ON tb_userdtl(transdate);
+
+
+-- ----------------------------
+-- Table structure for tb_userdtl_business
+-- ----------------------------
+CREATE TABLE tb_userdtl_business (
+ refno varchar(32) NOT NULL,
+ json_content varchar(1000)
+);
+ALTER TABLE tb_userdtl_business ADD CONSTRAINT tb_userdtl_business_pkey PRIMARY KEY (refno);
+
+
+-- ----------------------------
+-- Table structure for tb_userdtl_debitcredit
+-- ----------------------------
+CREATE TABLE tb_userdtl_debitcredit (
+ seqno int4 NOT NULL,
+ refno varchar(32) NOT NULL,
+ amount numeric(9,2),
+ craccno varchar(32),
+ crsubjno varchar(10),
+ draccno varchar(32),
+ drsubjno varchar(10),
+ summary varchar(240)
+);
+ALTER TABLE tb_userdtl_debitcredit ADD CONSTRAINT tb_userdtl_debitcredit_pkey PRIMARY KEY (seqno, refno);
+
+
+-- ----------------------------
+-- Table structure for tb_voucher
+-- ----------------------------
+CREATE TABLE tb_voucher (
+ voucherid varchar(32) NOT NULL,
+ amount numeric(9,2),
+ attachments int4,
+ cashier varchar(32),
+ checker varchar(32),
+ checkflag int4,
+ createdate int4,
+ editflag int4,
+ entrycnt int4,
+ invalidflag int4,
+ periodmonth int4,
+ periodyear int4,
+ poster varchar(32),
+ postflag int4,
+ preparer varchar(32),
+ signflag int4,
+ sourcetype varchar(20),
+ summary varchar(200),
+ transcnt int4,
+ transdate int4,
+ voucherdate int4,
+ voucherno int4
+);
+ALTER TABLE tb_voucher ADD CONSTRAINT tb_voucher_pkey PRIMARY KEY (voucherid);
+
+
+-- ----------------------------
+-- Table structure for tb_voucherentry
+-- ----------------------------
+CREATE TABLE tb_voucherentry (
+ voucherid varchar(32) NOT NULL,
+ entryid int4 NOT NULL,
+ accno varchar(32),
+ balance numeric(15,2),
+ balflag int4,
+ cramt numeric(15,2),
+ dramt numeric(15,2),
+ oppaccno varchar(32),
+ oppname varchar(240),
+ oppsubjno varchar(10),
+ subjno varchar(10),
+ summary varchar(240)
+);
+ALTER TABLE tb_voucherentry ADD CONSTRAINT tb_voucherentry_pkey PRIMARY KEY (voucherid, entryid);
+
+
+-- ----------------------------
+-- Table structure for tb_vouchernoctl
+-- ----------------------------
+CREATE TABLE tb_vouchernoctl (
+ vouchertype int4 NOT NULL,
+ periodmonth int4 NOT NULL,
+ voucherno int4 NOT NULL
+);
+ALTER TABLE tb_vouchernoctl ADD CONSTRAINT tb_vouchernoctl_pkey PRIMARY KEY (vouchertype);
+
+
+-- ----------------------------
+-- Table structure for tb_whitelist
+-- ----------------------------
+CREATE TABLE tb_whitelist (
+ whitelistid int4 NOT NULL,
+ check_operid varchar(32),
+ create_operid varchar(32),
+ createtime varchar(14),
+ lastsaved varchar(14),
+ listname varchar(200) NOT NULL,
+ remark varchar(600),
+ status varchar(10) NOT NULL
+);
+ALTER TABLE tb_whitelist ADD CONSTRAINT tb_whitelist_pkey PRIMARY KEY (whitelistid);
+
+
+-- ----------------------------
+-- Table structure for tb_whitelist_detail
+-- ----------------------------
+CREATE TABLE tb_whitelist_detail (
+ id varchar(32) NOT NULL,
+ cardno varchar(20),
+ cardphyid varchar(20),
+ lastsaved varchar(14),
+ status varchar(32),
+ userid varchar(32),
+ username varchar(60),
+ whitelistid int4 NOT NULL
+);
+ALTER TABLE tb_whitelist_detail ADD CONSTRAINT tb_whitelist_detail_pkey PRIMARY KEY (id);
+CREATE INDEX whitelistdetail_whitelistid_idx ON tb_whitelist_detail(whitelistid);
+
+
+-- ----------------------------
+-- Table structure for tb_whitelist_devbind
+-- ----------------------------
+CREATE TABLE tb_whitelist_devbind (
+ id varchar(32) NOT NULL,
+ create_operid varchar(32),
+ createtime varchar(14),
+ deviceid int4 NOT NULL,
+ whitelistid int4 NOT NULL
+);
+ALTER TABLE tb_whitelist_devbind ADD CONSTRAINT tb_whitelist_devbind_pkey PRIMARY KEY (id);
+ALTER TABLE tb_whitelist_devbind ADD CONSTRAINT whitelistid_devbind_uk UNIQUE (deviceid, whitelistid);
+
+
+-- ----------------------------
+-- Sequence structure for seq_area
+-- ----------------------------
+CREATE SEQUENCE "seq_area"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_cardverno
+-- ----------------------------
+CREATE SEQUENCE "seq_cardverno"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 99999999
+START 1
+CACHE 1
+CYCLE ;
+
+-- ----------------------------
+-- Sequence structure for seq_custtype
+-- ----------------------------
+CREATE SEQUENCE "seq_custtype"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_deptcode
+-- ----------------------------
+CREATE SEQUENCE "seq_deptcode"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 10
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_devgroup
+-- ----------------------------
+CREATE SEQUENCE "seq_devgroup"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_device
+-- ----------------------------
+CREATE SEQUENCE "seq_device"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 99999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_devparagroupid
+-- ----------------------------
+CREATE SEQUENCE "seq_devparagroupid"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 2
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_discountruleid
+-- ----------------------------
+CREATE SEQUENCE "seq_discountruleid"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_func
+-- ----------------------------
+CREATE SEQUENCE "seq_func"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1000
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_mealsdtl
+-- ----------------------------
+CREATE SEQUENCE "seq_mealsdtl"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_refno
+-- ----------------------------
+CREATE SEQUENCE "seq_refno"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 99999999
+START 1
+CACHE 1
+CYCLE ;
+
+-- ----------------------------
+-- Sequence structure for seq_res
+-- ----------------------------
+CREATE SEQUENCE "seq_res"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1000
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_settlement
+-- ----------------------------
+CREATE SEQUENCE "seq_settlement"
+INCREMENT 50
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_shop
+-- ----------------------------
+CREATE SEQUENCE "seq_shop"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
+
+-- ----------------------------
+-- Sequence structure for seq_whitelistid
+-- ----------------------------
+CREATE SEQUENCE "seq_whitelistid"
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 999999999
+START 1
+CACHE 1;
diff --git a/src/main/java/com/supwisdom/dlpay/AppLoginRunner.java b/src/main/java/com/supwisdom/dlpay/AppLoginRunner.java
index a9eaa0a..6016549 100644
--- a/src/main/java/com/supwisdom/dlpay/AppLoginRunner.java
+++ b/src/main/java/com/supwisdom/dlpay/AppLoginRunner.java
@@ -1,13 +1,12 @@
package com.supwisdom.dlpay;
-import com.supwisdom.dlpay.framework.dao.BusinessparaDao;
-import com.supwisdom.dlpay.framework.domain.TBusinesspara;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.paysdk.ApiLoginHelper;
import com.supwisdom.dlpay.paysdk.proxy.ApiLoginProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.cloud.openfeign.EnableFeignClients;
@@ -27,8 +26,12 @@
@Autowired
private ApiLoginProxy apiLoginProxy;
- @Autowired
- private BusinessparaDao businessparaDao;
+
+ @Value("${payapi.appid}")
+ private String appId;
+
+ @Value("${payapi.appkey}")
+ private String appKey;
@Override
public void run(ApplicationArguments args) throws Exception {
@@ -36,15 +39,13 @@
doLogin();
}
private void doLogin() {
- TBusinesspara appid=businessparaDao.findByParakey("payapi.appid");
- TBusinesspara secret=businessparaDao.findByParakey("payapi.secret");
- if(null==(appid)||null==(secret)){
+ if(StringUtil.isEmpty(appId) || StringUtil.isEmpty(appKey)){
logger.info("业务参数appid或secret未配置");
return;
}
try{
ApiLoginHelper helper = new ApiLoginHelper(apiLoginProxy);
- helper.login(appid.getParaval(), secret.getParaval());
+ helper.login(appId, appKey);
logger.info("登录成功");
}catch (Exception e){
logger.error("登录失败");
diff --git a/src/main/java/com/supwisdom/dlpay/AppPreparedEvent.java b/src/main/java/com/supwisdom/dlpay/AppPreparedEvent.java
index 304379c..f4b8085 100644
--- a/src/main/java/com/supwisdom/dlpay/AppPreparedEvent.java
+++ b/src/main/java/com/supwisdom/dlpay/AppPreparedEvent.java
@@ -16,6 +16,6 @@
@EventListener(ApplicationReadyEvent.class)
public void setupDictPool() {
- dictPool.init(); //初始化字典
+// dictPool.init(); //初始化字典 TODO:多租户不合适
}
}
diff --git a/src/main/java/com/supwisdom/dlpay/api/task/PosPayTask.java b/src/main/java/com/supwisdom/dlpay/api/task/PosPayTask.java
index 62c301f..e9fbb3b 100644
--- a/src/main/java/com/supwisdom/dlpay/api/task/PosPayTask.java
+++ b/src/main/java/com/supwisdom/dlpay/api/task/PosPayTask.java
@@ -11,6 +11,10 @@
import com.supwisdom.dlpay.restaurant.service.OfflineTransDtlService;
import com.supwisdom.dlpay.restaurant.service.TransDtlService;
import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
+import com.supwisdom.dlpay.tenant.service.MultiTenantService;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantDetails;
+import net.javacrumbs.shedlock.core.SchedulerLock;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,150 +31,183 @@
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
public class PosPayTask {
- private static final Logger logger = LoggerFactory.getLogger(PosPayTask.class);
+ private static final Logger logger = LoggerFactory.getLogger(PosPayTask.class);
- @Autowired
- private TransDtlService transDtlService;
- @Autowired
- private OfflineTransDtlService offlineTransDtlService;
- @Autowired
- private CitizenCardPayProxy citizenCardPayProxy;
- @Autowired
- private SystemUtilService systemUtilService;
- @Autowired
- private TransactionProxy transactionProxy;
+ @Autowired
+ private TransDtlService transDtlService;
+ @Autowired
+ private OfflineTransDtlService offlineTransDtlService;
+ @Autowired
+ private CitizenCardPayProxy citizenCardPayProxy;
+ @Autowired
+ private SystemUtilService systemUtilService;
+ @Autowired
+ private TransactionProxy transactionProxy;
+ @Autowired
+ private MultiTenantService multiTenantService;
- @Scheduled(cron = "0 0/1 * * * ?")
- private void submitOfflineDtlTask() {
- String date = DateUtil.getNow("yyyyMMdd");
- List<TOfflineTransDtl> dtls = offlineTransDtlService.getUncheckOfflineTransdtl(date, RestaurantConstant.TRANSTYPE_TRANSDTL_OFFLINE);
- logger.info("正在上传" + dtls.size() + "笔流水");
- if (dtls.size() > 0) {
- for (TOfflineTransDtl dtl : dtls) {
+ @Scheduled(cron = "${restaurant.submitofflinedtl.cron}")
+ @SchedulerLock(name = "RestaurantSubmitOfflinedtlTask", lockAtMostForString = "PT10M")
+ public void doSubmitOfflineDtlTask() {
+ long t1 = System.currentTimeMillis();
+ logger.debug("=================== 【脱机流水入账任务】开始: ===================");
- TTransDtl tTransDtl = gettTransDtl(dtl);
-
- CitizenCardPayinitParam param = new CitizenCardPayinitParam();
- param.setBillno(dtl.getBillno());
- param.setShopaccno(dtl.getShopid());
- param.setTransdate(dtl.getTransdate());
- param.setTranstime(dtl.getTranstime());
- param.setCardNo(dtl.getCardno());
- param.setDtltype("canteen");
- Double amt = dtl.getAmount() * 100;
- param.setAmount(amt.intValue());
- logger.info(dtl.getBillno() + "开始消费逻辑");
-
- CitizenPayResponse response = citizenCardPayProxy.citizencardPayinit(param);
- if (response.getRetcode() != 0) {
- saveFailTransdtls(dtl, tTransDtl, response);
- logger.info(dtl.getBillno() + "初始化失败," + response.getRetcode() + "," + response.getRetmsg() + "," + response.getException());
- continue;
- }
- CitizenCardPayfinishParam finishparam = new CitizenCardPayfinishParam();
- finishparam.setRefno(response.getRefno());
- CitizenPayResponse finishresp = citizenCardPayProxy.citizencardPayFinish(finishparam);
- if (finishresp.getRetcode() != 0) {
- saveFailTransdtls(dtl, tTransDtl, finishresp);
- logger.info(dtl.getBillno() + "消费确认失败," + finishresp.getRetcode() + "," + finishresp.getRetmsg() + "," + finishresp.getException());
- continue;
- }
- tTransDtl.setAccdate(date);
- tTransDtl.setAcctime(systemUtilService.getSysdatetime().getHosttime());
- tTransDtl.setCoreStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
- tTransDtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
- tTransDtl.setRefno(response.getRefno());
- dtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
- offlineTransDtlService.saveOfflineTransdtl(dtl);
- transDtlService.saveTransdtl(tTransDtl);
- }
-
- }
-
- List<TOfflineTransDtl> revdtls = offlineTransDtlService.getUncheckOfflineTransdtl(date, RestaurantConstant.TRANSTYPE_TRANSDTL_REVERT);
- if (revdtls.size() > 0) {
- for (TOfflineTransDtl revdtl : revdtls) {
- TTransDtl tTransDtl = gettTransDtl(revdtl);
- tTransDtl.setTranstype(RestaurantConstant.TRANSTYPE_TRANSDTL_REVERT);
- transDtlService.doRevertTransdtl(tTransDtl);
- }
- }
-
+ List<TenantDetails> multiTenantSchemas = multiTenantService.getSystemAllTenantDetails();
+ for (TenantDetails schema : multiTenantSchemas) {
+ TenantContextHolder.getContext().setTenant(schema); //切换schema
+ logger.debug("开始执行schema=[" + schema.getDbSchema() + "]的脱机流水入账任务:");
+ submitOfflineDtlTask(); //TODO:执行task
}
- private TTransDtl gettTransDtl(TOfflineTransDtl dtl) {
- TTransDtl tTransDtl = new TTransDtl();
- tTransDtl.setManagefee(dtl.getManagefee());
- tTransDtl.setAmount(dtl.getAmount());
- tTransDtl.setCardno(dtl.getCardno());
- tTransDtl.setStatus(dtl.getStatus());
- tTransDtl.setCustid(dtl.getCustid());
- tTransDtl.setBillno(dtl.getBillno());
- tTransDtl.setTermsqlno(dtl.getTermsqlno());
- tTransDtl.setMealtype(dtl.getMealtype());
- tTransDtl.setCusttype(dtl.getCusttype());
- tTransDtl.setShopid(dtl.getShopid());
- tTransDtl.setTransdate(dtl.getTransdate());
- tTransDtl.setTranstime(dtl.getTranstime());
- tTransDtl.setTranstype(RestaurantConstant.TRANSTYPE_TRANSDTL_OFFLINE);
+ long t2 = System.currentTimeMillis();
+ logger.debug("=================== 【脱机流水入账任务】结束,耗时 " + (t2 - t1) + " ms ===================");
+ }
- tTransDtl.setCustname(dtl.getCustname());
- tTransDtl.setTermid(dtl.getTermid());
- tTransDtl.setRuleid(dtl.getRuleid());
- tTransDtl.setManagefee(dtl.getManagefee());
- return tTransDtl;
- }
+ private void submitOfflineDtlTask() {
+ String date = DateUtil.getNow("yyyyMMdd");
+ List<TOfflineTransDtl> dtls = offlineTransDtlService.getUncheckOfflineTransdtl(date, RestaurantConstant.TRANSTYPE_TRANSDTL_OFFLINE);
+ logger.debug("正在上传" + dtls.size() + "笔流水");
+ if (dtls.size() > 0) {
+ for (TOfflineTransDtl dtl : dtls) {
- private void saveFailTransdtls(TOfflineTransDtl dtl, TTransDtl tTransDtl, CitizenPayResponse finishresp) {
- String status;
- String attr;
- if(RestaurantConstant.TRANSDTL_STATUS_WIT==finishresp.getRetcode()){
- status=RestaurantConstant.STATUS_TRANSDTL_WAIT;
- attr="";
- tTransDtl.setRefno(finishresp.getRefno());
- }else{
- status=RestaurantConstant.STATUS_TRANSDTL_FAIL;
- attr=finishresp.getRetmsg() + "," + finishresp.getException()+","+finishresp.getRetcode();
+ TTransDtl tTransDtl = gettTransDtl(dtl);
+
+ CitizenCardPayinitParam param = new CitizenCardPayinitParam();
+ param.setBillno(dtl.getBillno());
+ param.setShopaccno(dtl.getShopid());
+ param.setTransdate(dtl.getTransdate());
+ param.setTranstime(dtl.getTranstime());
+ param.setCardNo(dtl.getCardno());
+ param.setDtltype("canteen");
+ Double amt = dtl.getAmount() * 100;
+ param.setAmount(amt.intValue());
+ logger.info(dtl.getBillno() + "开始消费逻辑");
+
+ CitizenPayResponse response = citizenCardPayProxy.citizencardPayinit(param);
+ if (response.getRetcode() != 0) {
+ saveFailTransdtls(dtl, tTransDtl, response);
+ logger.error(dtl.getBillno() + "初始化失败," + response.getRetcode() + "," + response.getRetmsg() + "," + response.getException());
+ continue;
}
- dtl.setStatus(status);
- dtl.setAttr1(attr);
- tTransDtl.setStatus(status);
- tTransDtl.setAttr1(attr);
+ CitizenCardPayfinishParam finishparam = new CitizenCardPayfinishParam();
+ finishparam.setRefno(response.getRefno());
+ CitizenPayResponse finishresp = citizenCardPayProxy.citizencardPayFinish(finishparam);
+ if (finishresp.getRetcode() != 0) {
+ saveFailTransdtls(dtl, tTransDtl, finishresp);
+ logger.error(dtl.getBillno() + "消费确认失败," + finishresp.getRetcode() + "," + finishresp.getRetmsg() + "," + finishresp.getException());
+ continue;
+ }
+ tTransDtl.setAccdate(date);
+ tTransDtl.setAcctime(systemUtilService.getSysdatetime().getHosttime());
+ tTransDtl.setCoreStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
+ tTransDtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
+ tTransDtl.setRefno(response.getRefno());
+ dtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
offlineTransDtlService.saveOfflineTransdtl(dtl);
transDtlService.saveTransdtl(tTransDtl);
+ }
+
}
+ List<TOfflineTransDtl> revdtls = offlineTransDtlService.getUncheckOfflineTransdtl(date, RestaurantConstant.TRANSTYPE_TRANSDTL_REVERT);
+ if (revdtls.size() > 0) {
+ for (TOfflineTransDtl revdtl : revdtls) {
+ TTransDtl tTransDtl = gettTransDtl(revdtl);
+ tTransDtl.setTranstype(RestaurantConstant.TRANSTYPE_TRANSDTL_REVERT);
+ transDtlService.doRevertTransdtl(tTransDtl);
+ }
+ }
- @Scheduled(cron = "0 0/10 * * * ?")
- private void checkWipDtls() {
- String date = DateUtil.getNow("yyyyMMdd");
- List<TTransDtl> dtls = transDtlService.getSubmittingTransdtl(date);
- logger.info("正在核对" + dtls.size() + "笔未上传流水");
- if (dtls.size() > 0) {
- for (TTransDtl dtl : dtls) {
- QueryDtlResultParam param = new QueryDtlResultParam();
- param.setShopaccno(dtl.getShopid());
- param.setBillno(dtl.getBillno());
- param.setRefno(dtl.getRefno());
- QueryTransDtlResponse resp = transactionProxy.queryDtlResult(param);
- logger.info(dtl.getBillno()+":status==="+resp.getStatus());
+ }
- if(RestaurantConstant.STATUS_TRANSDTL_WAIT.equals(resp.getStatus())){
- logger.info(dtl.getBillno()+":"+resp.getRetcode()+":"+resp.getRetmsg());
- }else if (RestaurantConstant.STATUS_TRANSDTL_SUCCESS.equals(resp.getStatus())){
- dtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
- transDtlService.saveTransdtl(dtl);
- }else{
- dtl.setAttr1(resp.getRetmsg());
- dtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_FAIL);
- transDtlService.saveTransdtl(dtl);
+ private TTransDtl gettTransDtl(TOfflineTransDtl dtl) {
+ TTransDtl tTransDtl = new TTransDtl();
+ tTransDtl.setManagefee(dtl.getManagefee());
+ tTransDtl.setAmount(dtl.getAmount());
+ tTransDtl.setCardno(dtl.getCardno());
+ tTransDtl.setStatus(dtl.getStatus());
+ tTransDtl.setCustid(dtl.getCustid());
+ tTransDtl.setBillno(dtl.getBillno());
+ tTransDtl.setTermsqlno(dtl.getTermsqlno());
+ tTransDtl.setMealtype(dtl.getMealtype());
+ tTransDtl.setCusttype(dtl.getCusttype());
+ tTransDtl.setShopid(dtl.getShopid());
+ tTransDtl.setTransdate(dtl.getTransdate());
+ tTransDtl.setTranstime(dtl.getTranstime());
+ tTransDtl.setTranstype(RestaurantConstant.TRANSTYPE_TRANSDTL_OFFLINE);
- }
+ tTransDtl.setCustname(dtl.getCustname());
+ tTransDtl.setTermid(dtl.getTermid());
+ tTransDtl.setRuleid(dtl.getRuleid());
+ tTransDtl.setManagefee(dtl.getManagefee());
+ return tTransDtl;
+ }
- }
+ private void saveFailTransdtls(TOfflineTransDtl dtl, TTransDtl tTransDtl, CitizenPayResponse finishresp) {
+ String status;
+ String attr;
+ if (RestaurantConstant.TRANSDTL_STATUS_WIT == finishresp.getRetcode()) {
+ status = RestaurantConstant.STATUS_TRANSDTL_WAIT;
+ attr = "";
+ tTransDtl.setRefno(finishresp.getRefno());
+ } else {
+ status = RestaurantConstant.STATUS_TRANSDTL_FAIL;
+ attr = finishresp.getRetmsg() + "," + finishresp.getException() + "," + finishresp.getRetcode();
+ }
+ dtl.setStatus(status);
+ dtl.setAttr1(attr);
+ tTransDtl.setStatus(status);
+ tTransDtl.setAttr1(attr);
+ offlineTransDtlService.saveOfflineTransdtl(dtl);
+ transDtlService.saveTransdtl(tTransDtl);
+ }
+
+
+ @Scheduled(cron = "${restaurant.querydtlresult.cron}")
+ @SchedulerLock(name = "RestaurantQueryDtlResultTask", lockAtMostForString = "PT10M")
+ public void doQueryTask(){
+ long t1 = System.currentTimeMillis();
+ logger.debug("=================== 【查询流水状态任务】开始: ===================");
+
+ List<TenantDetails> multiTenantSchemas = multiTenantService.getSystemAllTenantDetails();
+ for (TenantDetails schema : multiTenantSchemas) {
+ TenantContextHolder.getContext().setTenant(schema); //切换schema
+ logger.debug("开始执行schema=[" + schema.getDbSchema() + "]的查询待支付流水支付状态任务:");
+ checkWipDtls(); //TODO:执行task
+ }
+
+ long t2 = System.currentTimeMillis();
+ logger.debug("=================== 【查询流水状态任务】结束,耗时 " + (t2 - t1) + " ms ===================");
+ }
+
+ private void checkWipDtls() {
+ String date = DateUtil.getNow("yyyyMMdd");
+ List<TTransDtl> dtls = transDtlService.getSubmittingTransdtl(date);
+ logger.debug("正在核对" + dtls.size() + "笔未上传流水");
+ if (dtls.size() > 0) {
+ for (TTransDtl dtl : dtls) {
+ QueryDtlResultParam param = new QueryDtlResultParam();
+ param.setShopaccno(dtl.getShopid());
+ param.setBillno(dtl.getBillno());
+ param.setRefno(dtl.getRefno());
+ QueryTransDtlResponse resp = transactionProxy.queryDtlResult(param);
+ logger.info(dtl.getBillno() + ":status===" + resp.getStatus());
+
+ if (RestaurantConstant.STATUS_TRANSDTL_WAIT.equals(resp.getStatus())) {
+ logger.debug(dtl.getBillno() + ":" + resp.getRetcode() + ":" + resp.getRetmsg());
+ } else if (RestaurantConstant.STATUS_TRANSDTL_SUCCESS.equals(resp.getStatus())) {
+ dtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_SUCCESS);
+ transDtlService.saveTransdtl(dtl);
+ } else {
+ dtl.setAttr1(resp.getRetmsg());
+ dtl.setStatus(RestaurantConstant.STATUS_TRANSDTL_FAIL);
+ transDtlService.saveTransdtl(dtl);
}
+ }
}
+ }
+
}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/core/JwtConfig.java b/src/main/java/com/supwisdom/dlpay/framework/core/JwtConfig.java
index c8992a8..c66b9fd 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/core/JwtConfig.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/core/JwtConfig.java
@@ -29,4 +29,8 @@
public String getTokenHeader() {
return tokenHeader;
}
+
+ public void setSecret(String secret) {
+ this.secret = secret;
+ }
}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/core/JwtTokenUtil.java b/src/main/java/com/supwisdom/dlpay/framework/core/JwtTokenUtil.java
index 481df61..55d04da 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/core/JwtTokenUtil.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/core/JwtTokenUtil.java
@@ -19,8 +19,11 @@
public class JwtTokenUtil {
private JwtConfig jwtConfig;
- public JwtTokenUtil(JwtConfig config) {
+ public JwtTokenUtil(JwtConfig config, String secret) {
this.jwtConfig = config;
+ if (null != secret && !"".equals(secret.trim())) {
+ this.jwtConfig.setSecret(secret); //TODO:替换秘钥
+ }
}
public String getHeader() {
diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/TenantConfigDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/TenantConfigDao.java
index b52710e..f016336 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/dao/TenantConfigDao.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/dao/TenantConfigDao.java
@@ -5,8 +5,12 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
+import java.util.List;
+
@Repository
public interface TenantConfigDao extends CrudRepository<TTenantConfig, String> {
- @Query("select t from TTenantConfig t where t.cfgid='main'")
- TTenantConfig getDefault();
+ TTenantConfig getByTenantId(String tenantid);
+
+ @Query("from TTenantConfig t order by t.tenantId ")
+ List<TTenantConfig> findAllTenants();
}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/TenantJwtconfigDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/TenantJwtconfigDao.java
new file mode 100644
index 0000000..cee36de
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/dao/TenantJwtconfigDao.java
@@ -0,0 +1,12 @@
+package com.supwisdom.dlpay.framework.dao;
+
+import com.supwisdom.dlpay.framework.domain.TTenantJwtconfig;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface TenantJwtconfigDao extends JpaRepository<TTenantJwtconfig, String> {
+ @Query("select t from TTenantJwtconfig t where t.id='main'")
+ TTenantJwtconfig getDefault();
+}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantConfig.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantConfig.java
index 3499322..1ed3ace 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantConfig.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantConfig.java
@@ -1,21 +1,24 @@
package com.supwisdom.dlpay.framework.domain;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
import javax.validation.constraints.NotNull;
@Entity
-@Table(name = "tb_tenantconfig")
+@Table(name = "TB_TENANTCONFIG", indexes = {@Index(name = "UK_TENANTCONFIG_TENANTID", unique = true, columnList = "TENANT_ID")})
public class TTenantConfig {
@Id
- @Column(name = "cfgid", length = 20)
+ @Column(name = "CFGID", nullable = false, length = 20)
private String cfgid;
+ @Column(name = "TENANT_ID", nullable = false, length = 60)
+ private String tenantId;
- @Column(name = "datacenter_id", length = 40)
- private String dataCenterId;
+ @Column(name = "TENANT_NAME", length = 200)
+ private String tenantName;
+
+ @Column(name = "TENANT_SCHEMA", nullable = false, length = 60)
+ private String tenantSchema;
+
public String getCfgid() {
return cfgid;
@@ -25,12 +28,27 @@
this.cfgid = cfgid;
}
- public String getDataCenterId() {
- return dataCenterId;
+ public String getTenantId() {
+ return tenantId;
}
- public void setDataCenterId(String dataCenterId) {
- this.dataCenterId = dataCenterId;
+ public void setTenantId(String tenantId) {
+ this.tenantId = tenantId;
}
+ public String getTenantName() {
+ return tenantName;
+ }
+
+ public void setTenantName(String tenantName) {
+ this.tenantName = tenantName;
+ }
+
+ public String getTenantSchema() {
+ return tenantSchema;
+ }
+
+ public void setTenantSchema(String tenantSchema) {
+ this.tenantSchema = tenantSchema;
+ }
}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantJwtconfig.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantJwtconfig.java
new file mode 100644
index 0000000..b93a1e9
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantJwtconfig.java
@@ -0,0 +1,33 @@
+package com.supwisdom.dlpay.framework.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "TB_TENANT_JWTCONFIG")
+public class TTenantJwtconfig {
+ @Id
+ @Column(name = "id", nullable = false, length = 20)
+ private String id;
+
+ @Column(name = "jwt_secret", nullable = false, length = 200)
+ private String jwtSecret;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getJwtSecret() {
+ return jwtSecret;
+ }
+
+ public void setJwtSecret(String jwtSecret) {
+ this.jwtSecret = jwtSecret;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiClientRepository.java b/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiClientRepository.java
index 1d48dd1..04043fe 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiClientRepository.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiClientRepository.java
@@ -1,6 +1,6 @@
package com.supwisdom.dlpay.framework.redisrepo;
-import com.supwisdom.dlpay.framework.domain.ApiClientRedis;
+import com.supwisdom.dlpay.framework.redistable.ApiClientRedis;
import org.springframework.data.repository.CrudRepository;
public interface ApiClientRepository extends CrudRepository<ApiClientRedis, String> {
diff --git a/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiJwtRepository.java b/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiJwtRepository.java
index 38a3fbe..57e0a85 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiJwtRepository.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/redisrepo/ApiJwtRepository.java
@@ -1,6 +1,6 @@
package com.supwisdom.dlpay.framework.redisrepo;
-import com.supwisdom.dlpay.framework.domain.JwtRedis;
+import com.supwisdom.dlpay.framework.redistable.JwtRedis;
import org.springframework.data.repository.CrudRepository;
public interface ApiJwtRepository extends CrudRepository<JwtRedis, String> {
diff --git a/src/main/java/com/supwisdom/dlpay/framework/redisrepo/PersonRepository.java b/src/main/java/com/supwisdom/dlpay/framework/redisrepo/PersonRepository.java
index a4925cd..5e627f1 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/redisrepo/PersonRepository.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/redisrepo/PersonRepository.java
@@ -1,6 +1,6 @@
package com.supwisdom.dlpay.framework.redisrepo;
-import com.supwisdom.dlpay.framework.domain.PersonRedis;
+import com.supwisdom.dlpay.framework.redistable.PersonRedis;
import org.springframework.data.repository.CrudRepository;
public interface PersonRepository extends CrudRepository<PersonRedis, String> {
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/ApiClientRedis.java b/src/main/java/com/supwisdom/dlpay/framework/redistable/ApiClientRedis.java
similarity index 94%
rename from src/main/java/com/supwisdom/dlpay/framework/domain/ApiClientRedis.java
rename to src/main/java/com/supwisdom/dlpay/framework/redistable/ApiClientRedis.java
index 2904156..3605ffa 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/domain/ApiClientRedis.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/redistable/ApiClientRedis.java
@@ -1,9 +1,8 @@
-package com.supwisdom.dlpay.framework.domain;
+package com.supwisdom.dlpay.framework.redistable;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
-
@RedisHash("app_client")
public class ApiClientRedis {
private @Id
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/JwtRedis.java b/src/main/java/com/supwisdom/dlpay/framework/redistable/JwtRedis.java
similarity index 93%
rename from src/main/java/com/supwisdom/dlpay/framework/domain/JwtRedis.java
rename to src/main/java/com/supwisdom/dlpay/framework/redistable/JwtRedis.java
index 47ece23..b3f5752 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/domain/JwtRedis.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/redistable/JwtRedis.java
@@ -1,4 +1,4 @@
-package com.supwisdom.dlpay.framework.domain;
+package com.supwisdom.dlpay.framework.redistable;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/PersonRedis.java b/src/main/java/com/supwisdom/dlpay/framework/redistable/PersonRedis.java
similarity index 94%
rename from src/main/java/com/supwisdom/dlpay/framework/domain/PersonRedis.java
rename to src/main/java/com/supwisdom/dlpay/framework/redistable/PersonRedis.java
index 623e55a..c1651ec 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/domain/PersonRedis.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/redistable/PersonRedis.java
@@ -1,4 +1,4 @@
-package com.supwisdom.dlpay.framework.domain;
+package com.supwisdom.dlpay.framework.redistable;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
diff --git a/src/main/java/com/supwisdom/dlpay/framework/security/MyAuthenticationSuccessHandler.java b/src/main/java/com/supwisdom/dlpay/framework/security/MyAuthenticationSuccessHandler.java
index 8708919..693a9cb 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/security/MyAuthenticationSuccessHandler.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/security/MyAuthenticationSuccessHandler.java
@@ -2,23 +2,25 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.supwisdom.dlpay.api.bean.JsonResult;
-import com.supwisdom.dlpay.framework.domain.TFunction;
import com.supwisdom.dlpay.framework.domain.TOperLog;
import com.supwisdom.dlpay.framework.domain.TOperator;
import com.supwisdom.dlpay.framework.util.DateUtil;
import com.supwisdom.dlpay.system.service.FunctionService;
import com.supwisdom.dlpay.system.service.OperatorService;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantSessionData;
+import com.supwisdom.multitenant.config.TenantSessionProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import java.io.IOException;
@Component("myAuthenctiationSuccessHandler")
@@ -28,7 +30,9 @@
@Autowired
private OperatorService operatorService;
@Autowired
- private FunctionService functionService;
+ private TenantSessionProperties tenantSessionProperties;
+
+
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
@@ -47,6 +51,10 @@
log.setFunctionname("登录成功");
operatorService.saveOperLog(log);
}
+
+ HttpSession session = request.getSession();
+ session.setAttribute(tenantSessionProperties.getName(),TenantContextHolder.getContext().getTenant());
+
response.setStatus(HttpStatus.OK.value());
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(objectMapper.writeValueAsString(JsonResult.ok("登录成功")));
diff --git a/src/main/java/com/supwisdom/dlpay/framework/service/impl/OperatorDetailServiceImpl.java b/src/main/java/com/supwisdom/dlpay/framework/service/impl/OperatorDetailServiceImpl.java
index 755828d..3619998 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/service/impl/OperatorDetailServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/service/impl/OperatorDetailServiceImpl.java
@@ -5,6 +5,11 @@
import com.supwisdom.dlpay.framework.domain.TOperator;
import com.supwisdom.dlpay.framework.service.OperatorDetailService;
import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.dlpay.tenant.TenantConstant;
+import com.supwisdom.dlpay.tenant.service.MultiTenantService;
+import com.supwisdom.multitenant.TenantContext;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
@@ -22,10 +27,30 @@
private OperatorDao operatorDao;
@Autowired
private OperRoleDao operRoleDao;
+ @Autowired
+ private MultiTenantService multiTenantService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
- TOperator oper = operatorDao.findByOpercode(username);
+ if (StringUtil.isEmpty(username)) throw new UsernameNotFoundException("用户名不能为空");
+
+ String opercode = username;
+ int index = username.lastIndexOf("@");
+ if (index > 1) {
+ opercode = username.substring(0, index);
+ TenantDetails details = multiTenantService.getDefaultTenantDetailsByTenantid(username.substring(index + 1));
+ if (null != details) TenantContextHolder.getContext().setTenant(details); //TODO:设置schema
+ } else {
+ TenantContextHolder.getContext().setTenant(TenantConstant.defaultTenantDetails);
+ }
+
+ TOperator oper = null;
+ try {
+ oper = operatorDao.findByOpercode(opercode);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
if (null == oper) {
throw new UsernameNotFoundException("管理员不存在");
}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CustomerServiceImpl.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CustomerServiceImpl.java
index cd30368..25ff130 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CustomerServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CustomerServiceImpl.java
@@ -165,7 +165,7 @@
String cardverno = systemUtilService.getCardverno();
List<TCard> card = cardDao.findAllByCustid(custid);
for (TCard c : card) {
- cardDao.deleteById(c.getCardno());
+ cardDao.delete(c);
String date = DateUtil.getNow("yyyyMMdd");
saveCardver(cardverno, date, c, c.getStatus(), RestaurantConstant.STATUS_CARD_LOGOUT, 0);
}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/task/CheckTransdtlTask.java b/src/main/java/com/supwisdom/dlpay/restaurant/task/CheckTransdtlTask.java
index 0e37ba0..8efd88f 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/task/CheckTransdtlTask.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/task/CheckTransdtlTask.java
@@ -13,6 +13,10 @@
import com.supwisdom.dlpay.restaurant.domain.TCheckFile;
import com.supwisdom.dlpay.restaurant.service.CheckTransdtlService;
import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
+import com.supwisdom.dlpay.tenant.TenantConstant;
+import com.supwisdom.dlpay.tenant.service.MultiTenantService;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantDetails;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,6 +34,8 @@
private SystemUtilService systemUtilService;
@Autowired
private CheckTransdtlService checkTransdtlService;
+ @Autowired
+ private MultiTenantService multiTenantService;
@Autowired
private ShopProxy shopProxy;
@@ -41,9 +47,22 @@
@Scheduled(cron = "${restaurant.chkdtltask.cron}")
@SchedulerLock(name = "RestaurantCheckTransdtlTask", lockAtMostForString = "PT20M")
public void doCheckTransdtlTask(){
- try{
- long t1 = System.currentTimeMillis();
- logger.info("=================== 对账任务开始: ===================");
+ long t1 = System.currentTimeMillis();
+ logger.info("=================== 对账任务开始: ===================");
+
+ List<TenantDetails> multiTenantSchemas = multiTenantService.getSystemAllTenantDetails();
+ for (TenantDetails schema : multiTenantSchemas) {
+ TenantContextHolder.getContext().setTenant(schema); //切换schema
+ logger.info("开始执行schema=[" + schema.getDbSchema() + "]的对账任务:");
+ doDealCheckTask(); //TODO:执行task
+ }
+
+ long t2 = System.currentTimeMillis();
+ logger.info("=================== 对账任务结束,耗时 " + (t2 - t1) + " ms ===================");
+ }
+
+ private void doDealCheckTask() {
+ try {
//step1: 获取上次对账到哪一天
TCheckCtl chkCtl = checkTransdtlService.doGetCheckTransdtlCtl();
if (null == chkCtl) {
@@ -64,11 +83,7 @@
chkCtl = downloadBillData(chkCtl);
if (chkCtl.getDownloadOk()) doCheckProcess(chkCtl);
}
-
- long t2 = System.currentTimeMillis();
- logger.info("=================== 对账任务结束,耗时 " + (t2 - t1) + " ms ===================");
-
- }catch (Exception e){
+ } catch (Exception e) {
logger.error("跟核心平台对账报错:" + e.getMessage());
e.printStackTrace();
}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/task/RestaurantTask.java b/src/main/java/com/supwisdom/dlpay/restaurant/task/RestaurantTask.java
index dd82f82..0208f54 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/task/RestaurantTask.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/task/RestaurantTask.java
@@ -15,6 +15,10 @@
import com.supwisdom.dlpay.restaurant.service.OfflineTransDtlService;
import com.supwisdom.dlpay.restaurant.service.TransDtlService;
import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
+import com.supwisdom.dlpay.tenant.service.MultiTenantService;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantDetails;
+import net.javacrumbs.shedlock.core.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,57 +33,75 @@
@Configuration
@EnableScheduling
public class RestaurantTask {
- private static final Logger logger = LoggerFactory.getLogger(RestaurantTask.class);
+ private static final Logger logger = LoggerFactory.getLogger(RestaurantTask.class);
- @Autowired
- private CardService cardService;
- @Autowired
- private CustomerService customerService;
- @Autowired
- private CustomerDao customerDao;
- @Autowired
- private UserProxy userProxy;
+ @Autowired
+ private MultiTenantService multiTenantService;
+ @Autowired
+ private CardService cardService;
+ @Autowired
+ private CustomerService customerService;
+ @Autowired
+ private CustomerDao customerDao;
+ @Autowired
+ private UserProxy userProxy;
- @Scheduled(cron = "0 0/1 * * * ? ")
- private void CustomerCheckTask(){
- CustomerSearchBean searchBean=new CustomerSearchBean();
- searchBean.setCheckstatus(RestaurantConstant.STATUS_CHECKSTATUS_UNCHECK);
+ @Scheduled(cron = "${restaurant.customercheck.cron}")
+ @SchedulerLock(name = "RestaurantCheckCustomerTask", lockAtMostForString = "PT20M")
+ public void doCustomerCheckTask() {
+ long t1 = System.currentTimeMillis();
+ logger.debug("=================== 客户信息校验任务开始: ===================");
- List<CustomerShowBean> dtls=customerService.getCustomerPage(searchBean).getData();
- logger.info("正同步"+dtls.size()+"名人员");
- if(dtls.size()>0){
- for(CustomerShowBean dtl:dtls){
- QueryUserParam param=new QueryUserParam();
- param.setCitizencardno(dtl.getCardno());
- UserInforResponse resp=userProxy.querybycardno(param);
- TCustomer customer=customerService.getCustomerByCustid(dtl.getCustid());
-
- if(resp.getRetcode()==0){
- TCard card=cardService.getCardByCardno(dtl.getCardno());
- if(null!=card){
- card.setCardphyid(resp.getCardphyid());
- card.setExpiredate(resp.getExpiredate());
- card.setBankcardno(resp.getBankcardno());
- card.setStatus(resp.getCardstatus());
- card.setTransstatus(resp.getTransstatus());
- cardService.saveCard(card);
- }
- customer.setPhone(resp.getPhone());
- customer.setCheckstatus(RestaurantConstant.STATUS_CHECKSTATUS_NORMAL);
- customer.setStatus(RestaurantConstant.STATUS_CARD_NORMAL);
- }else{
- customer.setCheckstatus(RestaurantConstant.STATUS_CHECKSTATUS_FAIL);
- customer.setStatus(RestaurantConstant.STATUS_CHECKSTATUS_FAIL);
- }
- customerDao.save(customer);
-
-
- }
-
- }
-
+ List<TenantDetails> multiTenantSchemas = multiTenantService.getSystemAllTenantDetails();
+ for (TenantDetails schema : multiTenantSchemas) {
+ TenantContextHolder.getContext().setTenant(schema); //切换schema
+ logger.debug("开始执行schema=[" + schema.getDbSchema() + "]的客户信息校验任务:");
+ dealCustomerCheckTask(); //TODO:执行task
}
+ long t2 = System.currentTimeMillis();
+ logger.debug("=================== 客户信息校验任务结束,耗时 " + (t2 - t1) + " ms ===================");
+ }
+
+ private void dealCustomerCheckTask() {
+ try {
+ CustomerSearchBean searchBean = new CustomerSearchBean();
+ searchBean.setCheckstatus(RestaurantConstant.STATUS_CHECKSTATUS_UNCHECK);
+
+ List<CustomerShowBean> dtls = customerService.getCustomerPage(searchBean).getData();
+ logger.debug("正同步" + dtls.size() + "名人员");
+ if (dtls.size() > 0) {
+ for (CustomerShowBean dtl : dtls) {
+ QueryUserParam param = new QueryUserParam();
+ param.setCitizencardno(dtl.getCardno());
+ UserInforResponse resp = userProxy.querybycardno(param);
+ TCustomer customer = customerService.getCustomerByCustid(dtl.getCustid());
+
+ if (resp.getRetcode() == 0) {
+ TCard card = cardService.getCardByCardno(dtl.getCardno());
+ if (null != card) {
+ card.setCardphyid(resp.getCardphyid());
+ card.setExpiredate(resp.getExpiredate());
+ card.setBankcardno(resp.getBankcardno());
+ card.setStatus(resp.getCardstatus());
+ card.setTransstatus(resp.getTransstatus());
+ cardService.saveCard(card);
+ }
+ customer.setPhone(resp.getPhone());
+ customer.setCheckstatus(RestaurantConstant.STATUS_CHECKSTATUS_NORMAL);
+ customer.setStatus(RestaurantConstant.STATUS_CARD_NORMAL);
+ } else {
+ customer.setCheckstatus(RestaurantConstant.STATUS_CHECKSTATUS_FAIL);
+ customer.setStatus(RestaurantConstant.STATUS_CHECKSTATUS_FAIL);
+ }
+ customerDao.save(customer);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
//TODO
@Scheduled(cron = "0 0/1 * * * ? ")
private void deleteExpiredWhitelist(){
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/task/TransdtlStatementTask.java b/src/main/java/com/supwisdom/dlpay/restaurant/task/TransdtlStatementTask.java
index cb256eb..7354852 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/task/TransdtlStatementTask.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/task/TransdtlStatementTask.java
@@ -4,6 +4,9 @@
import com.supwisdom.dlpay.framework.util.DateUtil;
import com.supwisdom.dlpay.restaurant.domain.TCheckCtl;
import com.supwisdom.dlpay.restaurant.service.CheckTransdtlService;
+import com.supwisdom.dlpay.tenant.service.MultiTenantService;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantDetails;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -12,6 +15,8 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import java.util.List;
+
/**
* 流水统计任务
*/
@@ -22,6 +27,8 @@
private SystemUtilService systemUtilService;
@Autowired
private CheckTransdtlService checkTransdtlService;
+ @Autowired
+ private MultiTenantService multiTenantService;
private static final Logger logger = LoggerFactory.getLogger(TransdtlStatementTask.class);
@@ -29,10 +36,22 @@
@Scheduled(cron = "${restaurant.statement.cron}")
@SchedulerLock(name = "RestaurantStatementTask", lockAtMostForString = "PT10M")
public void doStatementTask() {
- try {
- long t1 = System.currentTimeMillis();
- logger.info("=================== 【流水统计任务】开始: ===================");
+ long t1 = System.currentTimeMillis();
+ logger.info("=================== 【流水统计任务】开始: ===================");
+ List<TenantDetails> multiTenantSchemas = multiTenantService.getSystemAllTenantDetails();
+ for (TenantDetails schema : multiTenantSchemas) {
+ TenantContextHolder.getContext().setTenant(schema); //切换schema
+ logger.info("开始执行schema=[" + schema.getDbSchema() + "]的流水统计任务:");
+ doDealStatementTask(); //TODO:执行task
+ }
+
+ long t2 = System.currentTimeMillis();
+ logger.info("=================== 【流水统计任务】结束,耗时 " + (t2 - t1) + " ms ===================");
+ }
+
+ private void doDealStatementTask(){
+ try {
TCheckCtl checkCtl = checkTransdtlService.getSystemCheckCtl();
if (null == checkCtl) {
logger.error("还未与核心平台对账!");
@@ -56,9 +75,6 @@
break;
}
}
-
- long t2 = System.currentTimeMillis();
- logger.info("=================== 【流水统计任务】结束,耗时 " + (t2 - t1) + " ms ===================");
} catch (Exception e) {
logger.error("【流水统计任务】报错:" + e.getMessage());
e.printStackTrace();
diff --git a/src/main/java/com/supwisdom/dlpay/tenant/MyTenantDetailsProvider.java b/src/main/java/com/supwisdom/dlpay/tenant/MyTenantDetailsProvider.java
new file mode 100644
index 0000000..0f70178
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/tenant/MyTenantDetailsProvider.java
@@ -0,0 +1,42 @@
+package com.supwisdom.dlpay.tenant;
+
+import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.dlpay.tenant.service.MultiTenantService;
+import com.supwisdom.multitenant.TenantDetails;
+import com.supwisdom.multitenant.TenantDetailsProvider;
+import com.supwisdom.multitenant.TenantSessionData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+@Component
+public class MyTenantDetailsProvider implements TenantDetailsProvider {
+ private static final Map<String, TenantDetails> tenantDetailsMap = new Hashtable<>();
+
+ @Autowired
+ private MultiTenantService multiTenantService;
+
+ static {
+ tenantDetailsMap.put(TenantConstant.DEFAULT_TENANTID, TenantConstant.defaultTenantDetails);
+ }
+
+ @Override
+ public TenantDetails createDetailsById(String id) {
+ if (StringUtil.isEmpty(id)) return TenantConstant.defaultTenantDetails;
+
+ TenantDetails tenantDetails = tenantDetailsMap.get(id);
+ if (null == tenantDetails) {
+ tenantDetails = multiTenantService.getDefaultTenantDetailsByTenantid(id);
+ tenantDetailsMap.put(tenantDetails.getId(), tenantDetails);
+ }
+ return tenantDetails;
+ }
+
+ @Override
+ public TenantDetails defaultTenant() {
+ return TenantConstant.defaultTenantDetails;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/tenant/TenantConstant.java b/src/main/java/com/supwisdom/dlpay/tenant/TenantConstant.java
new file mode 100644
index 0000000..41a9276
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/tenant/TenantConstant.java
@@ -0,0 +1,12 @@
+package com.supwisdom.dlpay.tenant;
+
+import com.supwisdom.multitenant.TenantDetails;
+
+public class TenantConstant {
+ public static final String HEADER_TETANTID = "X-TENANT-ID";
+ public static final String DEFAULT_TENANTID = "default";
+ public static final String DEFAULT_DATACENTER = "default";
+
+ //默认的TenantDetails
+ public static final TenantDetails defaultTenantDetails = new TenantDetails(DEFAULT_TENANTID, "public", true, DEFAULT_DATACENTER);
+}
diff --git a/src/main/java/com/supwisdom/dlpay/tenant/service/MultiTenantService.java b/src/main/java/com/supwisdom/dlpay/tenant/service/MultiTenantService.java
new file mode 100644
index 0000000..1b464ad
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/tenant/service/MultiTenantService.java
@@ -0,0 +1,11 @@
+package com.supwisdom.dlpay.tenant.service;
+
+import com.supwisdom.multitenant.TenantDetails;
+
+import java.util.List;
+
+public interface MultiTenantService {
+ TenantDetails getDefaultTenantDetailsByTenantid(String tenantid);
+
+ List<TenantDetails> getSystemAllTenantDetails();
+}
diff --git a/src/main/java/com/supwisdom/dlpay/tenant/service/impl/MultiTenantServiceImpl.java b/src/main/java/com/supwisdom/dlpay/tenant/service/impl/MultiTenantServiceImpl.java
new file mode 100644
index 0000000..140a24a
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/tenant/service/impl/MultiTenantServiceImpl.java
@@ -0,0 +1,55 @@
+package com.supwisdom.dlpay.tenant.service.impl;
+
+import com.supwisdom.dlpay.framework.dao.TenantConfigDao;
+import com.supwisdom.dlpay.framework.domain.TTenantConfig;
+import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.dlpay.tenant.TenantConstant;
+import com.supwisdom.dlpay.tenant.service.MultiTenantService;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantDetails;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class MultiTenantServiceImpl implements MultiTenantService {
+ @Autowired
+ private TenantConfigDao tenantConfigDao;
+
+ @Override
+ public TenantDetails getDefaultTenantDetailsByTenantid(String tenantid) {
+ if(!StringUtil.isEmpty(tenantid)){
+ TenantContextHolder.getContext().setTenant(TenantConstant.defaultTenantDetails); //public下
+ TTenantConfig config = tenantConfigDao.getByTenantId(tenantid.trim());
+ if(null == config) throw new RuntimeException("tenantId=[" + tenantid + "] is error!!!");
+
+ TenantDetails tenantDetails = new TenantDetails();
+ tenantDetails.setId(tenantid.trim());
+ tenantDetails.setDbSchema(config.getTenantSchema());
+ tenantDetails.setDataCenter(TenantConstant.DEFAULT_DATACENTER);
+ tenantDetails.setEnabled(true);
+ return tenantDetails;
+ }
+ return TenantConstant.defaultTenantDetails;
+ }
+
+ @Override
+ public List<TenantDetails> getSystemAllTenantDetails() {
+ List<TenantDetails> result = new ArrayList<>(0);
+ TenantContextHolder.getContext().setTenant(TenantConstant.defaultTenantDetails); //public下
+ List<TTenantConfig> configList = tenantConfigDao.findAllTenants();
+ if (!StringUtil.isEmpty(configList)) {
+ for (TTenantConfig conf : configList) {
+ TenantDetails tenantDetails = new TenantDetails();
+ tenantDetails.setId(conf.getTenantId());
+ tenantDetails.setDbSchema(conf.getTenantSchema());
+ tenantDetails.setDataCenter(TenantConstant.DEFAULT_DATACENTER);
+ tenantDetails.setEnabled(true);
+ result.add(tenantDetails);
+ }
+ }
+ return result;
+ }
+}
diff --git a/src/main/kotlin/com/supwisdom/dlpay/RestaurantApplication.kt b/src/main/kotlin/com/supwisdom/dlpay/RestaurantApplication.kt
index eb901a8..654ab4b 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/RestaurantApplication.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/RestaurantApplication.kt
@@ -1,8 +1,11 @@
package com.supwisdom.dlpay
+import com.supwisdom.multitenant.annotations.EnableHttpHeaderTenantInterceptor
+import com.supwisdom.multitenant.annotations.EnableSessionTenantInterceptor
import io.lettuce.core.ReadFrom
import net.javacrumbs.shedlock.core.LockProvider
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider
+import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
@@ -67,7 +70,10 @@
}
}
+@EnableSchedulerLock(defaultLockAtMostFor = "PT20M")
@EnableDiscoveryClient
+@EnableSessionTenantInterceptor
+@EnableHttpHeaderTenantInterceptor
@ServletComponentScan
@SpringBootApplication
class RestaurantApplication
diff --git a/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt b/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt
index 4eb8794..d73b384 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt
@@ -1,14 +1,13 @@
package com.supwisdom.dlpay.framework.controller
import com.google.code.kaptcha.Producer
-import com.supwisdom.dlpay.exception.TransactionCheckException
import com.supwisdom.dlpay.framework.ResponseBodyBuilder
import com.supwisdom.dlpay.framework.core.JwtConfig
import com.supwisdom.dlpay.framework.core.JwtTokenUtil
import com.supwisdom.dlpay.framework.dao.ApiClientDao
-import com.supwisdom.dlpay.framework.dao.TenantConfigDao
-import com.supwisdom.dlpay.framework.domain.ApiClientRedis
-import com.supwisdom.dlpay.framework.domain.JwtRedis
+import com.supwisdom.dlpay.framework.dao.TenantJwtconfigDao
+import com.supwisdom.dlpay.framework.redistable.ApiClientRedis
+import com.supwisdom.dlpay.framework.redistable.JwtRedis
import com.supwisdom.dlpay.framework.domain.TOperator
import com.supwisdom.dlpay.framework.redisrepo.ApiClientRepository
import com.supwisdom.dlpay.framework.redisrepo.ApiJwtRepository
@@ -18,23 +17,21 @@
import com.supwisdom.dlpay.framework.service.SystemUtilService
import com.supwisdom.dlpay.framework.util.*
import com.supwisdom.dlpay.system.service.FunctionService
+import com.supwisdom.dlpay.tenant.TenantConstant
+import com.supwisdom.multitenant.TenantContextHolder
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
-import org.springframework.security.core.Authentication
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.core.userdetails.UserDetails
-import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer
-import org.springframework.security.oauth2.provider.OAuth2Authentication
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler
import org.springframework.social.connect.web.HttpSessionSessionStrategy
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.*
import org.springframework.web.context.request.ServletWebRequest
-import java.awt.image.BufferedImage
import java.io.IOException
import java.lang.Exception
import java.security.Principal
@@ -62,20 +59,14 @@
@Autowired
lateinit var jwtConfig: JwtConfig
+ @Autowired
+ lateinit var tenantJwtconfigDao: TenantJwtconfigDao
+
@GetMapping(value = ["/gettoken", "/gettoken/{clientid}"])
@ResponseBody
- fun loginInit(appid: String, @PathVariable clientid: String?,
- @RequestHeader(Constants.HEADER_TETANTID) tetantId: String?): ResponseEntity<Any> {
-
- /* tetantConfigDao.default?.also {
- if (it.tenantId != tetantId) {
- throw TransactionCheckException(TradeErrorCode.INPUT_DATA_ERROR,
- "租户ID错误")
- }
- } ?: throw TransactionCheckException(TradeErrorCode.BUSINESS_DEAL_ERROR,
- "系统未配置租户信息")*/
-
+ fun loginInit(appid: String, @PathVariable clientid: String?): ResponseEntity<Any> {
+ val tenantId = TenantContextHolder.getContext().tenant?.id ?: TenantConstant.DEFAULT_TENANTID
apiClientDao.findById(appid).run {
if (!isPresent) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build()
@@ -89,11 +80,11 @@
val token = generateRandomToken()
val now = systemUtil.sysdatetime.hostdatetime
ApiClientRedis().also {
- it.id = if (clientid == null) appid else "$appid-$clientid"
+ it.id = if (clientid == null) "$appid@$tenantId" else "$appid-$clientid@$tenantId"
it.loginTimestamp = now
it.roles = api.roles
- it.tenantId = tetantId
- it.token = HmacUtil.HMACSHA256( token,api.secret)
+ it.tenantId = tenantId
+ it.token = HmacUtil.HMACSHA256(token, api.secret)
}.also {
apiClientRepository.save(it)
}
@@ -116,11 +107,14 @@
@GetMapping(value = ["/authentication", "/authentication/{clientid}"])
fun login(appid: String, secret: String, @PathVariable clientid: String?): ResponseEntity<Any> {
- val requestId = if (clientid == null) appid else "$appid-$clientid"
+ val tenantId = TenantContextHolder.getContext().tenant?.id ?: TenantConstant.DEFAULT_TENANTID
+ val requestId = if (clientid == null) "$appid@$tenantId" else "$appid-$clientid@$tenantId"
+ val jwtSecret = tenantJwtconfigDao.default?.jwtSecret ?: "" //TODO: jwt秘钥从数据库取
+
return apiClientRepository.findById(requestId).let {
if (it.isPresent && checkSecretToken(it.get(), secret)) {
apiClientRepository.deleteById(requestId)
- val token = JwtTokenUtil(jwtConfig).generateToken(
+ val token = JwtTokenUtil(jwtConfig, jwtSecret).generateToken(
mapOf(Constants.JWT_CLAIM_UID to appid,
"issuer" to "payapi",
"audience" to (clientid ?: appid),
@@ -152,12 +146,14 @@
if (!auth.startsWith(jwtConfig.tokenHeader)) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build()
}
- val jwt = JwtTokenUtil(jwtConfig).verifyToken(auth.substring(jwtConfig.tokenHeader.length))
+ val jwtSecret = tenantJwtconfigDao.default?.jwtSecret ?: "" //TODO: jwt秘钥从数据库取
+
+ val jwt = JwtTokenUtil(jwtConfig, jwtSecret).verifyToken(auth.substring(jwtConfig.tokenHeader.length))
val appid = jwt["uid"] as String
return apiClientDao.findById(appid).let {
if (it.isPresent && it.get().status == TradeDict.STATUS_NORMAL) {
// 新证书
- val token = JwtTokenUtil(jwtConfig).generateToken(
+ val token = JwtTokenUtil(jwtConfig, jwtSecret).generateToken(
mapOf(Constants.JWT_CLAIM_UID to appid,
"issuer" to "payapi",
"audience" to jwt["audience"],
diff --git a/src/main/kotlin/com/supwisdom/dlpay/framework/service/impl/framework_service_impl.kt b/src/main/kotlin/com/supwisdom/dlpay/framework/service/impl/framework_service_impl.kt
index 8fc1a55..e504f96 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/framework/service/impl/framework_service_impl.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/framework/service/impl/framework_service_impl.kt
@@ -5,6 +5,7 @@
import com.supwisdom.dlpay.framework.core.JwtConfig
import com.supwisdom.dlpay.framework.core.JwtTokenUtil
import com.supwisdom.dlpay.framework.dao.ApiClientDao
+import com.supwisdom.dlpay.framework.dao.TenantJwtconfigDao
import com.supwisdom.dlpay.framework.service.CommonService
import com.supwisdom.dlpay.framework.util.StringUtil
import com.supwisdom.dlpay.framework.util.TradeErrorCode
@@ -18,21 +19,14 @@
lateinit var jwtConfig: JwtConfig
@Autowired
lateinit var apiClientDao: ApiClientDao
-
- private var jwtUtil: JwtTokenUtil? = null
-
- private fun getUtil(): JwtTokenUtil {
- if (jwtUtil == null) {
- jwtUtil = JwtTokenUtil((jwtConfig))
- }
- return jwtUtil as JwtTokenUtil
- }
+ @Autowired
+ lateinit var tenantJwtconfigDao: TenantJwtconfigDao
override fun getSystemVersion(): String {
try {
return Manifests.read("Restaurant-Version") ?: "version 1.0"
} catch (ex: Exception) {
- ex.printStackTrace()
+// ex.printStackTrace()
return "unknown"
}
}
@@ -40,7 +34,8 @@
override fun getRequestAppid(request: HttpServletRequest): String {
request.getHeader(jwtConfig.header).let {
if (null != it && it.startsWith(jwtConfig.tokenHeader)) {
- val claims = getUtil().verifyToken(it.substring(jwtConfig.tokenHeader.length))
+ val jwtSecret = tenantJwtconfigDao.default?.jwtSecret ?: "" //TODO: jwt秘钥从数据库取
+ val claims = JwtTokenUtil(jwtConfig, jwtSecret).verifyToken(it.substring(jwtConfig.tokenHeader.length))
val uid = claims["uid"]?.toString()
if (!StringUtil.isEmpty(uid)) {
return uid as String
diff --git a/src/main/kotlin/com/supwisdom/dlpay/security.kt b/src/main/kotlin/com/supwisdom/dlpay/security.kt
index 8e9ffce..3c52376 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/security.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/security.kt
@@ -3,8 +3,8 @@
import com.supwisdom.dlpay.framework.core.JwtConfig
import com.supwisdom.dlpay.framework.core.JwtTokenUtil
import com.supwisdom.dlpay.framework.core.PasswordBCryptConfig
+import com.supwisdom.dlpay.framework.dao.TenantJwtconfigDao
import com.supwisdom.dlpay.framework.redisrepo.ApiJwtRepository
-import com.supwisdom.dlpay.framework.security.MyPermissionEvaluator
import com.supwisdom.dlpay.framework.security.ValidateCodeSecurityConfig
import com.supwisdom.dlpay.framework.service.OperatorDetailService
import com.supwisdom.dlpay.framework.util.TradeDict
@@ -26,7 +26,6 @@
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
-import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler
import org.springframework.security.web.authentication.AuthenticationFailureHandler
import org.springframework.security.web.authentication.AuthenticationSuccessHandler
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
@@ -49,15 +48,8 @@
@Autowired
lateinit var apiJwtRepository: ApiJwtRepository
- private var jwtUtil: JwtTokenUtil? = null
-
-
- private fun getUtil(): JwtTokenUtil {
- if (jwtUtil == null) {
- jwtUtil = JwtTokenUtil((jwtConfig))
- }
- return jwtUtil as JwtTokenUtil
- }
+ @Autowired
+ lateinit var tenantJwtconfigDao: TenantJwtconfigDao
override fun doFilterInternal(request: HttpServletRequest, response: HttpServletResponse, filterChain: FilterChain) {
request.getHeader(jwtConfig.header)?.let { authHeader ->
@@ -67,7 +59,8 @@
} else {
throw JoseException("JWT Header error")
}
- val claims = getUtil().verifyToken(jwt)
+ val jwtSecret = tenantJwtconfigDao.default?.jwtSecret ?: "" //TODO: jwt秘钥从数据库取
+ val claims = JwtTokenUtil(jwtConfig, jwtSecret).verifyToken(jwt)
apiJwtRepository.findById(claims["jti"].toString()).let {
if (!it.isPresent) {
throw JoseException("JWT has not been register")
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index a606a3a..90e2544 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -35,4 +35,10 @@
restaurant.chkdtltask.cron=27 3/10 * * * ?
# 统计任务
restaurant.statement.cron=0 7/10 * * * ?
+# 客户信息校对任务
+restaurant.customercheck.cron=0 0/1 * * * ?
+# 流水入账任务
+restaurant.submitofflinedtl.cron=0 0/1 * * * ?
+# 查询流水状态任务
+restaurant.querydtlresult.cron=0 0/2 * * * ?
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index aafc754..da059e5 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -513,6 +513,11 @@
INSERT INTO "tb_businesspara" (parakey,paraval) VALUES ('customer.ignore', 'false');
INSERT INTO "tb_businesspara" (parakey,paraval) VALUES ('discounttime.month', '0');
+-- 多租户jwt秘钥配置,不同的租户secret最好配置不同
+INSERT INTO "tb_tenant_jwtconfig"("id", "jwt_secret") VALUES ('main', 'DLLSHLomEbrM0lk+NMQZbHfSxaDU1wekjT+kiC3YzDw=');
+--INSERT INTO "tb_tenant_jwtconfig"("id", "jwt_secret") VALUES ('main', 'DLSZFLomEbrM0lk+NMQZbHfSxaDU1wekjT+kiC3YzDw=');
+commit;
+
CREATE SEQUENCE SEQ_REFNO
INCREMENT BY 1