Bladeren bron

add:布点范围

zoie 3 maanden geleden
bovenliggende
commit
7de08e10b4

+ 2 - 1
conf/app_prod.conf

@@ -40,4 +40,5 @@ BoosUuid = "fa5be10f-5be1-42be-a8dc-8d142e006266"
 # 冷链验证 报告负责人
 VdelUuid = "1c13436c-4511-4030-8b26-baadad88445a"
 
-
+OpenApi_Key = "coldverify"
+OpenApi_Secret = "H3L9OPQR2VX8ZZYN7STKFG5JMWB1CV4D"

+ 2 - 1
conf/app_test.conf

@@ -85,5 +85,6 @@ BoosUuid = "fa5be10f-5be1-42be-a8dc-8d142e006266"
 # 冷链验证 报告负责人
 VdelUuid = "1c13436c-4511-4030-8b26-baadad88445a"
 
-
+OpenApi_Key = "coldverify"
+OpenApi_Secret = "H3L9OPQR2VX8ZZYN7STKFG5JMWB1CV4D"
 

+ 1 - 14
controllers/Account.go

@@ -74,7 +74,7 @@ func (c *AccountController) List() {
 		return
 	}
 
-	if User_r.T_power > 2 {
+	if len(User_r.T_Distributor_id) > 0 && User_r.T_power > 2 {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"}
 		c.ServeJSON()
 		return
@@ -389,16 +389,3 @@ func (c *AccountController) UpPassword() {
 	c.ServeJSON()
 	return
 }
-
-// 获取管理员 关联ERP
-func (c *AccountController) List_All_For_ERP() {
-
-	PowerList := Account.Read_Power_List_ALL_1()
-	PowerMap := Account.UserPowerListToPowerMap(PowerList)
-	T_name := c.GetString("T_name")
-	var r_jsons lib.R_JSONS
-	r_jsons.List = Account.Read_Admin_List_ALL_Power("", T_name, PowerMap)
-	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
-	c.ServeJSON()
-	return
-}

+ 55 - 0
controllers/ERP.go

@@ -0,0 +1,55 @@
+package controllers
+
+import (
+	"ColdVerify_server/lib"
+	"ColdVerify_server/models/Account"
+	"ColdVerify_server/models/Distributor"
+	"ColdVerify_server/models/Task"
+)
+
+// 获取管理员 关联ERP
+func (c *AccountController) Account_List_All_For_ERP() {
+
+	PowerList := Account.Read_Power_List_ALL_1()
+	PowerMap := Account.UserPowerListToPowerMap(PowerList)
+	T_name := c.GetString("T_name")
+	var r_jsons lib.R_JSONS
+	r_jsons.List = Account.Read_Admin_List_ALL_Power("", T_name, PowerMap)
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
+	c.ServeJSON()
+	return
+}
+
+// 获取公司列表
+func (c *UserController) User_List_All_For_ERP() {
+
+	T_name := c.GetString("T_name")
+	CreateDate := c.GetString("CreateDate")
+	if len(CreateDate) > 0 && !lib.IsDateStr(CreateDate) {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
+		c.ServeJSON()
+		return
+	}
+	distributorList := Distributor.Read_Distributor_List_ALL("")
+	distributorMap := Distributor.DistributorListToMap(distributorList)
+	List, _ := Account.List_All_For_ERP(T_name, CreateDate, distributorMap)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: List}
+	c.ServeJSON()
+	return
+}
+
+func (c *TaskController) Task_List_All_For_ERP() {
+
+	T_reporting_pass_time := c.GetString("T_reporting_pass_time")
+	if len(T_reporting_pass_time) > 0 && !lib.IsDateStr(T_reporting_pass_time) {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
+		c.ServeJSON()
+		return
+	}
+	List, _ := Task.Read_Task_List_For_ERP(T_reporting_pass_time)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: List}
+	c.ServeJSON()
+	return
+}

+ 17 - 2
controllers/Task.go

@@ -80,7 +80,7 @@ func (c *TaskController) List() {
 	}
 
 	var T_admin string
-	if User_r.T_power > 1 {
+	if User_r.T_power > 2 {
 		T_admin = User_r.T_uuid
 	}
 	// 经销商下管理员可查看自己经销商下所有的任务
@@ -1513,6 +1513,10 @@ func (c *TaskController) UpReportingState() {
 		r.T_reporting_state = T_reporting_state
 		clos = append(clos, "T_reporting_state")
 	}
+	if T_reporting_state == Task.TaskReportingStatePass {
+		r.T_reporting_pass_time = time.Now().Format("2006-01-02 15:04:05")
+		clos = append(clos, "T_reporting_pass_time")
+	}
 	if len(T_signature) > 0 {
 		r.T_reporting_signature = T_signature
 		clos = append(clos, "T_reporting_signature")
@@ -2544,6 +2548,17 @@ func (c *TaskController) Copy() {
 		c.ServeJSON()
 		return
 	}
+	dc := Device.DeviceClass{
+		T_uuid:  User_r.T_uuid,
+		T_State: 1,
+	}
+	T_class_id, is := Device.Add_DeviceClass(dc)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
+		c.ServeJSON()
+		return
+	}
+	System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
 	// 查询信息采集信息
 	infoCollection, is := InfoCollection.Read_InfoCollection(r.T_InfoCollection_id)
 	if !is {
@@ -2556,7 +2571,7 @@ func (c *TaskController) Copy() {
 		T_InfoCollection_id:    r.T_InfoCollection_id,
 		T_InfoTemplate_id:      infoCollection.T_InfoTemplate_id,
 		T_start_time:           infoCollection.T_start_time, // 项目开始时间使用信息采集开始时间
-		T_class:                r.T_class,
+		T_class:                int(T_class_id),
 		T_uuid:                 r.T_uuid,
 		T_name:                 T_name,
 		T_VerifyTemplate_class: r.T_VerifyTemplate_class,

+ 2 - 2
controllers/VerifyTemplate.go

@@ -182,8 +182,8 @@ func (c *VerifyTemplateController) Up() {
 
 		var deployList []VerifyTemplate.VerifyTemplateDeploy
 		// 将 布点1|布点2|布点3| 格式替换为 [{"T_name":"布点1","T_scope":"布点范围1"},{"T_name":"布点2","T_scope":"布点范围2"}]
-		if strings.Contains(strings.Trim(r.T_deploy, "|"), "|") {
-			deploys := strings.Split(r.T_deploy, "|")
+		if strings.Contains(T_deploy, "|") {
+			deploys := strings.Split(strings.Trim(T_deploy, "|"), "|")
 			for _, v := range deploys {
 				deployList = append(deployList, VerifyTemplate.VerifyTemplateDeploy{T_name: v})
 			}

+ 3 - 3
models/Account/Admin.go

@@ -109,7 +109,7 @@ func Read_Admin_List(T_Distributor_id string, T_name string, page int, page_z in
 		cond1 = cond1.And("T_Distributor_id", T_Distributor_id)
 	} else {
 		// 只查询内部管理员数据
-		cond1 = cond1.And("T_Distributor_id__isnull", true)
+		cond1 = cond1.AndCond(cond1.Or("T_Distributor_id__isnull", true).Or("T_Distributor_id", ""))
 	}
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
 	cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
@@ -181,13 +181,13 @@ func Read_Admin_List_ALL_1() (maps []Admin) {
 }
 
 // 获取全部列表
-func Read_Admin_List_ALL_Power(T_Distributor_id string, T_name string,PowerMaps map[int]string) (maps []AdminPower_R) {
+func Read_Admin_List_ALL_Power(T_Distributor_id string, T_name string, PowerMaps map[int]string) (maps []AdminPower_R) {
 
 	o := orm.NewOrm()
 	var r []Admin
 	qs := o.QueryTable(new(Admin))
 	if len(T_Distributor_id) == 0 {
-		qs = qs.Filter("T_Distributor_id__isnull", true)
+		qs = qs.Filter("T_Distributor_id", "")
 	} else {
 		qs = qs.Filter("T_Distributor_id", T_Distributor_id)
 	}

+ 30 - 0
models/Account/User.go

@@ -210,6 +210,36 @@ func Read_User_List(T_Distributor_id string, T_name string, page int, page_z int
 
 	return User_r, cnt
 }
+func List_All_For_ERP(T_name string, CreateTime string, distributorMap map[string]string) ([]User_R, int64) {
+	o := orm.NewOrm()
+
+	// 也可以直接使用 Model 结构体作为表名
+	var r []User
+	qs := o.QueryTable(new(User))
+
+	cond := orm.NewCondition()
+	cond1 := cond.And("T_State", 1)
+	if len(T_name) > 0 {
+		cond1 = cond1.And("T_name__icontains", T_name)
+	}
+	if len(CreateTime) > 0 {
+		start := CreateTime + " 00:00:00"
+		end := CreateTime + " 23:59:59"
+		log.Println("CreateTime_s:", start, end)
+		cond1 = cond1.And("CreateTime__gte", start).And("CreateTime__lte", end)
+	}
+
+	qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
+	cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
+
+	// 转换
+	var User_r []User_R
+	for _, v := range r {
+		User_r = append(User_r, UserToUser_R(v, distributorMap))
+	}
+
+	return User_r, cnt
+}
 
 // 获取全部列表
 func Read_User_List_ALL() (maps []User) {

+ 39 - 2
models/Task/Task.go

@@ -12,6 +12,7 @@ import (
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
+	"log"
 	"strings"
 	"time"
 )
@@ -224,12 +225,13 @@ type Task struct {
 
 	// 报告
 	T_reporting_start_time    string  `orm:"size(256);null"`  // 验证报告开始时间 接收信息采集表的时间
-	T_reporting_end_time      string  `orm:"size(256);null"`  // 验证报告结束时间 负责人审核通过最后一次上传时间
+	T_reporting_end_time      string  `orm:"size(256);null"`  // 验证报告结束时间 负责人审核通过最后一次上传时间
 	T_reporting_time_interval float64 `orm:"size(256);null"`  // 时间间隔 单位分钟
 	T_reporting_overtime      float64 `orm:"size(256);null"`  // 验证报告超时时间 单位分钟
 	T_reporting_signature     string  `orm:"type(text)"`      // 验证报告客户签字确认图片
 	T_reporting_return_times  int     `orm:"size(256);null"`  // 验证报告退回次数
 	T_reporting_audit_record  string  `orm:"type(text);null"` // 验证报告审核记录
+	T_reporting_pass_time     string  `orm:"size(256);null"`  // 验证报告负责人通过时间
 
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
@@ -292,6 +294,9 @@ type Task_ struct {
 	InfoCollection  InfoCollection.InfoCollection //信息采集
 	T_record        string                        //
 
+	T_device_type         string
+	T_verify_type         string
+	T_reporting_pass_time string
 }
 
 type Task_Stat struct {
@@ -480,6 +485,10 @@ func TaskToTask_(T Task, userMap, adminMap map[string]string) (T_ Task_) {
 	T_.T_CalibrationExpirationTime = T.T_CalibrationExpirationTime
 	T_.T_record = T.T_record
 
+	T_.T_device_type = T.T_device_type
+	T_.T_verify_type = T.T_verify_type
+	T_.T_reporting_pass_time = T.T_reporting_pass_time
+
 	return T_
 }
 func TaskToTask_Stat(T Task, userMap, adminMap map[string]string) (T_ Task_Stat) {
@@ -803,7 +812,6 @@ func Read_UserTask_List(T_uuid string, T_name string, userMap, adminMap map[stri
 		offset = int64((page - 1) * page_z)
 	}
 	cond := orm.NewCondition()
-	//cond1 := cond.And("T_name__icontains", T_name).And("T_State", 1)
 	cond1 := cond.And("T_name__icontains", T_name).And("T_Show", 1).And("T_State", 1)
 	if len(T_uuid) > 0 {
 		cond1 = cond1.And("T_uuid", T_uuid)
@@ -1107,3 +1115,32 @@ func Read_UserTask_StatisticalRanking(T_uuid, T_scheme string) []Task {
 
 	return r
 }
+
+// 获取任务列表
+func Read_Task_List_For_ERP(T_reporting_pass_time string) ([]Task_, int) {
+
+	o := orm.NewOrm()
+
+	qs := o.QueryTable(new(Task))
+	var r []Task
+
+	cond := orm.NewCondition()
+	cond1 := cond.And("T_State", 1).And("T_reporting_state", TaskReportingStatePass)
+	if len(T_reporting_pass_time) > 0 {
+		start := T_reporting_pass_time + " 00:00:00"
+		end := T_reporting_pass_time + " 23:59:59"
+		log.Println("CreateTime_s:", start, end)
+		cond1 = cond1.And("T_reporting_pass_time__gte", start).And("T_reporting_pass_time__lte", end)
+	}
+
+	qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
+	cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
+
+	// 转换
+	var TaskList []Task_
+	for _, v := range r {
+		TaskList = append(TaskList, TaskToTask_(v, map[string]string{}, map[string]string{}))
+	}
+
+	return TaskList, int(cnt)
+}

+ 11 - 8
models/VerifyTemplate/VerifyTemplate.go

@@ -43,12 +43,13 @@ type VerifyTemplate_R struct {
 	T_name              string `orm:"size(256);null"` // 标题
 	T_sort              int    `orm:"size(200);null"` // 分类
 
-	T_scheme    string                 // 方案模版
-	T_reporting string                 // 报告模版
-	T_inspect   string                 // 自检
-	T_marking   string                 // 标识模版
-	T_cover     string                 // 封面
-	T_deploy    []VerifyTemplateDeploy // 布点选项  格式 布点内容1|布点内容2|布点内容3
+	T_scheme      string                 // 方案模版
+	T_reporting   string                 // 报告模版
+	T_inspect     string                 // 自检
+	T_marking     string                 // 标识模版
+	T_cover       string                 // 封面
+	T_deploy      string                 // 布点选项  格式 布点内容1|布点内容2|布点内容3
+	T_deploy_list []VerifyTemplateDeploy // 布点选项  格式 布点内容1|布点内容2|布点内容3
 }
 
 func (t *VerifyTemplate) TableName() string {
@@ -85,9 +86,11 @@ func VerifyTemplateToVerifyTemplate_R(T VerifyTemplate) (T_r VerifyTemplate_R) {
 				logs.Error("布点 JSON 反序列化失败:", err)
 			}
 		}
-
 	}
-	T_r.T_deploy = deployList
+	for _, deploy := range deployList {
+		T_r.T_deploy += deploy.T_name + "|"
+	}
+	T_r.T_deploy_list = deployList
 
 	return T_r
 }

+ 3 - 1
routers/openapi.go

@@ -76,7 +76,9 @@ func init() {
 
 	ns := beego.NewNamespace("/openapi",
 		beego.NSBefore(ApiKeyAuthMiddleware),
-		beego.NSRouter("/user/list", &controllers.AccountController{}, "*:List_All_For_ERP"), // 管理员所有列表
+		beego.NSRouter("/admin/list", &controllers.AccountController{}, "*:Account_List_All_For_ERP"), // 管理员所有列表
+		beego.NSRouter("/company/list", &controllers.UserController{}, "*:User_List_All_For_ERP"),     // 公司所有列表
+		beego.NSRouter("/task/list", &controllers.TaskController{}, "*:Task_List_All_For_ERP"),        // 公司所有列表
 	)
 	beego.AddNamespace(ns)
 }