Prechádzať zdrojové kódy

feature: 修改合同编号规则

liuyaqi 2 rokov pred
rodič
commit
5a3bd4e543

+ 12 - 3
opms_parent/app/service/base.go

@@ -2,15 +2,16 @@ package service
 
 import (
 	"context"
+	"fmt"
+	"log"
+	"reflect"
+
 	"dashoo.cn/opms_libary/myerrors"
 	"dashoo.cn/opms_libary/request"
-	"fmt"
 	"github.com/gogf/gf/container/gmap"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/util/gconv"
 	"github.com/smallnest/rpcx/share"
-	"log"
-	"reflect"
 
 	"dashoo.cn/common_definition/comm_def"
 	"dashoo.cn/opms_libary/micro_srv"
@@ -35,6 +36,14 @@ func Sequence(db gdb.DB, name string) (string, error) {
 	return v.String(), nil
 }
 
+func SequenceYearRest(db gdb.DB, name string) (int, error) {
+	v, err := db.GetValue("select `next_year_reset_val`( ? );", name)
+	if err != nil {
+		return 0, err
+	}
+	return v.Int(), nil
+}
+
 // SetCreatedInfo 插入数据库时设置创建信息
 func SetCreatedInfo(entry interface{}, id int, name string) {
 	v := reflect.ValueOf(entry)

+ 2 - 2
opms_parent/app/service/contract/ctr_contract.go

@@ -374,12 +374,12 @@ func (s CtrContractService) Add(ctx context.Context, req *model.CtrContractAddRe
 	// 	return 0, myerrors.TipsError("所选项目已添加合同")
 	// }
 
-	sequence, err := service.Sequence(s.Dao.DB, "contract_code")
+	sequence, err := service.SequenceYearRest(s.Dao.DB, "contract_code")
 	if err != nil {
 		return 0, err
 	}
 	if req.ContractCode == "" {
-		req.ContractCode = fmt.Sprintf("DS%s%s-%s", req.ContractType, time.Now().Format("0601"), sequence)
+		req.ContractCode = fmt.Sprintf("DH%s%s-%03d", req.ContractType, time.Now().Format("0601"), sequence)
 	}
 	c, err = s.Dao.Where("contract_code = ?", req.ContractCode).One()
 	if err != nil {

+ 1 - 1
opms_parent/app/service/proj/business.go

@@ -64,7 +64,7 @@ func (p *businessService) GetList(req *model.ProjBusinessSearchReq) (total int,
 		db = db.Where("proj."+p.Dao.C.NboSource, req.NboSource)
 	}
 	if req.DistributorName != "" {
-		db = db.Where("proj."+p.Dao.C.DistributorName, "%"+req.DistributorName+"%")
+		db = db.WhereLike("proj."+p.Dao.C.DistributorName, "%"+req.DistributorName+"%")
 	}
 	if req.BeginTime != "" {
 		db = db.WhereGTE("proj."+p.Dao.C.FilingTime, req.BeginTime)

+ 12 - 0
opms_parent/schema/function.sql

@@ -24,6 +24,18 @@ RETURN currval(seq_name);
 END $ 
 DELIMITER ;
 
+alter table plat_sequence add `year` int(11) DEFAULT NULL COMMENT '年份' after increment;
+update plat_sequence set year=2023,current_value=50  where name = 'contract_code'
+
+DROP FUNCTION IF EXISTS next_year_reset_val;
+DELIMITER $
+CREATE FUNCTION next_year_reset_val (seq_name VARCHAR(50)) RETURNS INTEGER LANGUAGE SQL DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER COMMENT '' BEGIN
+UPDATE plat_sequence SET current_value=0, `year`=year(now()) WHERE `year` = year(now())-1;
+UPDATE plat_sequence SET current_value=current_value+increment WHERE name = seq_name;
+RETURN currval(seq_name);
+END $
+DELIMITER ;
+
 -- INSERT INTO plat_sequence VALUES ('customer_code', 1000, 1, '', 1000, '系统管理员', '2023-02-09 10:27:42', null, null, null, null);
 -- INSERT INTO plat_sequence VALUES ('contract_code', 1000, 1, '', 1000, '系统管理员', '2023-02-09 10:27:42', null, null, null, null);
 -- select `nextval`('customer_code');