Kaynağa Gözat

清理无用代码

sunmiao 4 yıl önce
ebeveyn
işleme
bfc44ac712

+ 33 - 34
smartdoorlock/src/dashoo.cn/smartdoorlock_api/app/api/remote_control/remote_control.go

@@ -15,6 +15,7 @@ import (
 	//"fmt"
 	"github.com/gogf/gf/net/ghttp"
 )
+
 // 角色API管理对象
 type Controller struct {
 }
@@ -39,10 +40,10 @@ func (c *Controller) RtuUdate(r *ghttp.Request) {
 	}
 	//取出设备编号
 	//code := strings.Split(TopicMessage.Topic, "/")
-	fmt.Println("----设备编号------",TopicMessage.Topic)
+	fmt.Println("----设备编号------", TopicMessage.Topic)
 	fmt.Println("----command------", command)
 
-	response.Json(r, 0,TopicMessage.Topic)
+	response.Json(r, 0, TopicMessage.Topic)
 }
 
 //RTU下发 CMD
@@ -51,40 +52,40 @@ func (c *Controller) RtuSeedCmd(r *ghttp.Request) {
 	command := r.GetString("instruction")
 	ygnick := r.GetString("ygnick")
 	ygopenid := r.GetString("ygopenid")
-	seriallist :=  r.GetString("seriallist")
-	if strings.Index(seriallist,TagCode) == -1 {
+	seriallist := r.GetString("seriallist")
+	if strings.Index(seriallist, TagCode) == -1 {
 		response.Json(r, 4, "用户无权限")
 	}
 	fmt.Println("---111-----")
 	//获取用户名及对应编码
 	var channelslist remote_control.Channels
-	if err := remote_control.GetChannelsname(TagCode,&channelslist); err != nil {
-		fmt.Println("----err---",err)
+	if err := remote_control.GetChannelsname(TagCode, &channelslist); err != nil {
+		fmt.Println("----err---", err)
 		response.Json(r, 3, "无此权限")
 	} else {
-	ccoed := "sg/cmd/" +channelslist.Serial
-	if ygopenid == "" {
-		response.Json(r, 2, "", "生成失败")
-		fmt.Println("---生成失败-----")
-	} else {
-		command = "SHELL:@" + command
-		fmt.Println("-Topic:-", ccoed, command)
-		var userlist remote_control.Base_user
-		if err := remote_control.GetBase_username(ygopenid, &userlist); err != nil {
-			response.Json(r, 1, "请重新登录")
-			fmt.Println("---请重新登录-----")
+		ccoed := "sg/cmd/" + channelslist.Serial
+		if ygopenid == "" {
+			response.Json(r, 2, "", "生成失败")
+			fmt.Println("---生成失败-----")
 		} else {
-			if err := remote_control.SaveTriggerHistory(userlist.DepartmentName,channelslist.Title,channelslist.Serial, command, ygnick, userlist.Realname, userlist.UserName, ygopenid,1); err != nil {
-				response.Json(r, 1, "", "保存历史失败")
-				fmt.Println("---保存历史失败-----")
+			command = "SHELL:@" + command
+			fmt.Println("-Topic:-", ccoed, command)
+			var userlist remote_control.Base_user
+			if err := remote_control.GetBase_username(ygopenid, &userlist); err != nil {
+				response.Json(r, 1, "请重新登录")
+				fmt.Println("---请重新登录-----")
 			} else {
-				//MQTT发送
-				remote_control.MqttSend(ccoed, command)
-				response.Json(r, 0, "", "")
+				if err := remote_control.SaveTriggerHistory(userlist.DepartmentName, channelslist.Title, channelslist.Serial, command, ygnick, userlist.Realname, userlist.UserName, ygopenid, 1); err != nil {
+					response.Json(r, 1, "", "保存历史失败")
+					fmt.Println("---保存历史失败-----")
+				} else {
+					//MQTT发送
+					remote_control.MqttSend(ccoed, command)
+					response.Json(r, 0, "", "")
+				}
 			}
 		}
 	}
-	}
 }
 
 //RTU下发 CMD
@@ -96,11 +97,11 @@ func (c *Controller) RtuButtonSeedCmd(r *ghttp.Request) {
 
 	//获取用户名及对应编码
 	var channelslist remote_control.Channels
-	if err := remote_control.GetChannelsnamebycode(Code,&channelslist); err != nil {
-		fmt.Println("----err---",err)
+	if err := remote_control.GetChannelsnamebycode(Code, &channelslist); err != nil {
+		fmt.Println("----err---", err)
 		response.Json(r, 3, "无此权限")
 	} else {
-		ccoed := "sg/cmd/" +channelslist.Serial
+		ccoed := "sg/cmd/" + channelslist.Serial
 		if ygopenid == "" {
 			response.Json(r, 2, "", "生成失败")
 			fmt.Println("---生成失败-----")
@@ -114,7 +115,7 @@ func (c *Controller) RtuButtonSeedCmd(r *ghttp.Request) {
 			} else {
 				//MQTT发送
 				remote_control.MqttSend(ccoed, command)
-				if err := remote_control.SaveTriggerHistory(userlist.DepartmentName,channelslist.Title,channelslist.Serial, command, ygnick, userlist.Realname, userlist.UserName, ygopenid,1); err != nil {
+				if err := remote_control.SaveTriggerHistory(userlist.DepartmentName, channelslist.Title, channelslist.Serial, command, ygnick, userlist.Realname, userlist.UserName, ygopenid, 1); err != nil {
 					response.Json(r, 1, "", "保存历史失败")
 					fmt.Println("---保存历史失败-----")
 				} else {
@@ -130,11 +131,11 @@ func (c *Controller) GetTriggerHistory(r *ghttp.Request) {
 	page := request.GetPageInfo(r)
 	code := r.GetString("code")
 	where := " 1 = 1 "
-	if code != ""{
+	if code != "" {
 		where = where + " and  ChannelCode = " + code
 	}
 	var list []remote_control.Record_History
-	if count,err := remote_control.GetTriggerHistory(page.Current, page.Size,&list,where); err != nil {
+	if count, err := remote_control.GetTriggerHistory(page.Current, page.Size, &list, where); err != nil {
 		response.Json(r, 1, err.Error())
 	} else {
 		var records response.PagedRecords
@@ -165,8 +166,8 @@ func (c *Controller) SetIdentifyCallBack(r *ghttp.Request) {
 		r.ExitAll()
 	}
 	r.Response.WriteJson(remote_control.Result{
-		Result: 1,
-		Success:  true,
+		Result:  1,
+		Success: true,
 	})
 	r.Exit()
 }
@@ -179,5 +180,3 @@ func (c *Controller) PersonCreate(r *ghttp.Request) {
 	// 照片下发
 	remote_control.FaceCreate("025")
 }
-
-

+ 0 - 259
smartdoorlock/src/dashoo.cn/smartdoorlock_api/app/service/neo/base_neo.go

@@ -1,259 +0,0 @@
-// ==========================================================================
-// This is auto-generated by gf cli tool. You may not really want to edit it.
-// ==========================================================================
-
-package neo
-
-import (
-	"database/sql"
-	"github.com/gogf/gf/database/gdb"
-	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/os/gtime"
-	"time"
-)
-
-// Entity is the golang structure for table neo_test.
-type BaseNeo struct {
-	Id          int    `orm:"id,primary"  json:"id"`          //
-	Cid         int    `orm:"cid"  json:"cid"`                //
-	Name        string `orm:"name"        json:"name"`        //
-	Description string `orm:"description" json:"description"` //
-	CreateTime  int    `orm:"create_time" json:"create_time"` //
-	CeshiDesc   int    `orm:"ceshi_desc" json:"ceshi_desc"`   //
-	CreateOn    string `orm:"create_on" json:"create_on"`     //
-}
-type BaseNeoClass struct {
-	BaseNeo
-	Stclass string `orm:"st_class" json:"st_class"` //
-}
-
-type BaseTable struct {
-	Id  int    `orm:"id,primary"  json:"id"`
-	K   string `orm:"k"  json:"k"`
-	K1  string `orm:"k1" json:"k1"`
-	K2  string `orm:"k2" json:"k2"`
-	K3  string `orm:"k3" json:"k3"`
-	K4  string `orm:"k4" json:"k4"`
-	K5  string `orm:"k5" json:"k5"`
-	K6  string `orm:"k6" json:"k6"`
-	K7  string `orm:"k7" json:"k7"`
-	K8  string `orm:"k8" json:"k8"`
-	K9  string `orm:"k9" json:"k9"`
-	K10 string `orm:"k10" json:"k10"`
-	K11 string `orm:"k11" json:"k11"`
-	K12 string `orm:"k12" json:"k12"`
-}
-
-type GeneBoardTable struct {
-	Id            int         `orm:"Id,primary"    json:"id"`              //
-	BoardNum      string      `orm:"BoardNum"      json:"board_num"`       // 板号
-	BoardDay      string      `orm:"BoardDay"      json:"board_day"`       // 年月日
-	LNum          int         `orm:"LNum"          json:"l_num"`           // 剩余孔
-	BoardTestType string      `orm:"BoardTestType" json:"board_test_type"` // 测序类型
-	CreateOn      *gtime.Time `orm:"CreateOn"      json:"create_on"`       //
-	IsNew         string      `orm:"IsNew"      json:"is_new"`             //
-}
-
-type GeneBoardTableInfo struct {
-	Id      int    `orm:"id,primary"  json:"id"`
-	K       string `orm:"k"  json:"k"`
-	K1      string `orm:"k1" json:"k1"`
-	K2      string `orm:"k2" json:"k2"`
-	K3      string `orm:"k3" json:"k3"`
-	K4      string `orm:"k4" json:"k4"`
-	K5      string `orm:"k5" json:"k5"`
-	K6      string `orm:"k6" json:"k6"`
-	K7      string `orm:"k7" json:"k7"`
-	K8      string `orm:"k8" json:"k8"`
-	K9      string `orm:"k9" json:"k9"`
-	K10     string `orm:"k10" json:"k10"`
-	K11     string `orm:"k11" json:"k11"`
-	K12     string `orm:"k12" json:"k12"`
-	BoardId int    `orm:"BoardId" json:"board_id"`
-}
-
-type Instrument struct {
-	Id                      int       `xorm:"not null pk autoincr INT(10)"`
-	Code                    string    `xorm:"VARCHAR(50)"`      //设备编码
-	Name                    string    `xorm:"VARCHAR(255)"`     //设备名称
-	SupplierId              int       `xorm:"INT(10)"`          //供应商Id
-	Supplier                string    `xorm:"VARCHAR(255)"`     //供应商
-	FactoryNum 				string    `xorm:"VARCHAR(255)"` 	//出厂编号
-	Model                   string    `xorm:"VARCHAR(255)"`     //型号
-	Brand                   string    `xorm:"VARCHAR(255)"`     //设备品牌
-	Classification          string    `xorm:"VARCHAR(255)"`     //设备大类
-	Location                string    `xorm:"VARCHAR(50)"`      //设备所在位置
-	Remarks                 string    `xorm:"VARCHAR(255)"`     //备注
-	State                   int       `xorm:"INT(10)"`          //设备状态 1正常 2异常
-	CalibrationTime         time.Time `xorm:"DATETIME"`         //校准时间
-	CalibrationDeadline     int       `xorm:"INT(10)"`          //校准使用期限
-	CalibrationDeadlineType int       `xorm:"INT(10)"`          //期限类型:1:天 2:周 3:月 4:年
-	MaintenCycle            int       `xorm:"INT(10)"`          //维护周期数
-	CycleType               int       `xorm:"INT(10)"`          //维护周期类型
-	FileUrl                 string    `xorm:"VARCHAR(50)"`      //操作规程文件路径
-	FileName                string    `xorm:"VARCHAR(50)"`      //操作规程文件名称
-	HeartbeatTime           time.Time `xorm:"DATETIME created"` //心跳时间 对应服务器时间
-	IsFixedPoint            int       `xorm:"INT(2)"`
-	CreateOn                time.Time `xorm:"DATETIME created"`
-	CreateUserId            int       `xorm:"INT(10)"`
-	CreateBy                string    `xorm:"VARCHAR(50)"`
-	ModifiedOn              time.Time `xorm:"DATETIME updated"`
-	ModifiedUserId          int       `xorm:"INT(10)"`
-	ModifiedBy              string    `xorm:"VARCHAR(50)"`
-	Remark                  string    `xorm:"VARCHAR(50)"`
-	TimeNotification        int       `xorm:"INT(10)"`
-	Sharable                int       `xorm:"TINYINT"`
-	Responsible             string    `xorm:"VARCHAR(50)"` //责任人
-	EndTime                 time.Time `xorm:"DATETIME"`    //截止日期
-	Purchasedate            time.Time `xorm:"DATETIME"`    //采购日期
-	MaintenTime             time.Time `xorm:"DATE"`        //维护日期
-	JoinPlan                bool      `xorm:"TINYINT"`     //是否参与点检计划
-}
-//入库表
-type Bank_Apply_Main struct {
-	Id             int       `xorm:"not null pk autoincr INT(10)"`
-	EntryNo        string    `xorm:"VARCHAR(50)"`
-	ApplyType      int       `xorm:"int(10)"`
-	ApplyStatus    int       `xorm:"int(10)"`
-	OperationBy    string    `xorm:"VARCHAR(50)"`
-	Section        string    `xorm:"VARCHAR(50)"`
-	EntryTime      time.Time `xorm:"DATETIME"`
-	ConUserId      int       `xorm:"int(10)"`
-	ConUserBy      string    `xorm:"VARCHAR(50)"`
-	ConTime        time.Time `xorm:"DATETIME"`
-	Remark         string    `xorm:"VARCHAR(255)"`
-	Exception 	   string	 `xorm:"VARCHAR(512)"`
-	AuditorRemark  string    `xorm:"VARCHAR(255)"`
-	CreateOn       time.Time `xorm:"DATETIME created"` //创建时间
-	CreateUserId   int       `xorm:"INT(10)"`
-	CreateBy       string    `xorm:"VARCHAR(50)"` //创建人
-	ModifiedOn     time.Time `xorm:"DATETIME updated"`
-	ModifiedUserId int       `xorm:"INT(10)"`
-	ModifiedBy     string    `xorm:"VARCHAR(50)"`
-	TaskStatus	   int		 `xorm:"INT(10)"`
-	Reason         int		 `xorm:"INT(10)"`
-	ApplyCount     string    `xorm:"VARCHAR(50)"`
-}
-//入库子表
-type Bank_Apply_Detail struct {
-	Id             int       `xorm:"not null pk autoincr INT(10)"`
-	ParentId       int       `xorm:"int(10)"` //父类id
-	BarCode        string    `xorm:"VARCHAR(50)"`
-	SampleCode     string    `xorm:"VARCHAR(50)"`
-	SampleType     int       `xorm:"INT(10)"`
-	SampleTypeName string    `xorm:"VARCHAR(50)"` //样本类型
-	InitCapacity   float32   `xorm:"FLOAT"`
-	Capacity       float32   `xorm:"FLOAT"`
-	TaskStatus	   int		 `xorm:"INT(4)"`
-	Unit           string    `xorm:"VARCHAR(50)"`
-	GroupID		   string    `xorm:"VARCHAR(50)"`
-	EquipmentId    int       `xorm:"INT(10)"`
-	ShelfId        int       `xorm:"INT(10)"`
-	BoxId          int       `xorm:"INT(10)"`
-	Position       string    `xorm:"VARCHAR(50)"` //位置 冻存盒的 X代表第几列 Y代表第几行  X;
-	PositionInfo      string    `xorm:"VARCHAR(100)"` //列表中显示的位置信息(容器+层+盒+position)
-	CHUserId       int       `xorm:"INT(10)"`
-	CHUserBy       string    `xorm:"VARCHAR(50)"`
-	CancelId       int       `xorm:"INT(10)"`
-	CancelBy       string    `xorm:"VARCHAR(50)"`
-	DetailStatus   int       `xorm:"int(10)"`
-	CreateOn       time.Time `xorm:"DATETIME created"` //创建时间
-	CreateUserId   int       `xorm:"INT(10)"`
-	CreateBy       string    `xorm:"VARCHAR(50)"` //创建人
-	ModifiedOn     time.Time `xorm:"DATETIME updated"`
-	ModifiedUserId int       `xorm:"INT(10)"`
-	ModifiedBy     string    `xorm:"VARCHAR(50)"`
-	RecoveryId     int       `xorm:INT(10)`
-	DetailId       int       `xorm:INT(10)`
-	IsLocked       int        `xorm:INT(10)`
-	Reason         int       `xorm:INT(10)`
-
-}
-//维修保养
-type InstrumenMaintainLog struct {
-	Id             int       `xorm:"not null pk autoincr INT(10)"`
-	InstrumenId    int       `xorm:"INT(10)"`      //设备id
-	InstrumenName  string    `xorm:"VARCHAR(50)"`  //设备名称
-	InstrumenCode  string    `xorm:"VARCHAR(50)"`  //设备编号
-	OperaRemark    string    `xorm:"VARCHAR(500)"` //操作说明
-	OperaTpye      string    `xorm:"VARCHAR(50)"`  //操作类型
-	TypeCode       int       `xorm:"INT(2)"`       //操作类型编号
-	OperaUser      string    `xorm:"VARCHAR(50)"`  //操作人
-	OperaOn        time.Time `xorm:"DATETIME"`     //操作日期
-	CreateOn       time.Time `xorm:"DATETIME created"`
-	CreateUserId   int       `xorm:"INT(10)"`
-	CreateBy       string    `xorm:"VARCHAR(50)"`
-	ModifiedOn     time.Time `xorm:"DATETIME updated"`
-	ModifiedUserId int       `xorm:"INT(10)"`
-	ModifiedBy     string    `xorm:"VARCHAR(50)"`
-}
-//曲线报表
-type AutoGenerated struct {
-	Results []Results `json:"results"`
-}
-type Series struct {
-	Name string `json:"name"`
-	Columns []string `json:"columns"`
-	Values []interface{} `json:"values"`
-}
-type Results struct {
-	Series []Series `json:"series"`
-}
-
-type GeneBoardTableEmpty struct {
-	Id  int    `orm:"id,primary"  json:"id"`
-	K   string `orm:"k"  json:"k"`
-	K1  string `orm:"k1" json:"k1"`
-	K2  string `orm:"k2" json:"k2"`
-	K3  string `orm:"k3" json:"k3"`
-	K4  string `orm:"k4" json:"k4"`
-	K5  string `orm:"k5" json:"k5"`
-	K6  string `orm:"k6" json:"k6"`
-	K7  string `orm:"k7" json:"k7"`
-	K8  string `orm:"k8" json:"k8"`
-	K9  string `orm:"k9" json:"k9"`
-	K10 string `orm:"k10" json:"k10"`
-	K11 string `orm:"k11" json:"k11"`
-	K12 string `orm:"k12" json:"k12"`
-}
-
-var (
-	TableBaseNeo = "neo_test"
-	ModelBaseNeo = g.DB("default").Table(TableBaseNeo).Safe()
-)
-
-var (
-	Tablebank_apply_detail = "bank_apply_detail"
-	Modelbank_apply = g.DB("default").Table(Tablebank_apply_detail).Safe()
-)
-
-// Inserts does "INSERT...INTO..." statement for inserting current object into table.
-func (r *BaseNeo) Insert() (result sql.Result, err error) {
-	return ModelBaseNeo.Data(r).Insert()
-}
-
-// Replace does "REPLACE...INTO..." statement for inserting current object into table.
-// If there's already another same record in the table (it checks using primary key or unique index),
-// it deletes it and insert this one.
-func (r *BaseNeo) Replace() (result sql.Result, err error) {
-	return ModelBaseNeo.Data(r).Replace()
-}
-
-// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
-// It updates the record if there's already another same record in the table
-// (it checks using primary key or unique index).
-func (r *BaseNeo) Save() (result sql.Result, err error) {
-	return ModelBaseNeo.Data(r).Save()
-}
-
-// Update does "UPDATE...WHERE..." statement for updating current object from table.
-// It updates the record if there's already another same record in the table
-// (it checks using primary key or unique index).
-func (r *BaseNeo) Update() (result sql.Result, err error) {
-	return ModelBaseNeo.Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
-}
-
-// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
-func (r *BaseNeo) Delete() (result sql.Result, err error) {
-	return ModelBaseNeo.Where(gdb.GetWhereConditionOfStruct(r)).Delete()
-}

+ 0 - 198
smartdoorlock/src/dashoo.cn/smartdoorlock_api/app/service/neo/neo.go

@@ -1,198 +0,0 @@
-package neo
-
-import (
-	"database/sql"
-	"encoding/json"
-	"fmt"
-	"github.com/gogf/gf/database/gdb"
-	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/os/gtime"
-	"io/ioutil"
-	"net/http"
-	"strconv"
-	"time"
-)
-
-var (
-	// 表对象
-	table = g.DB().Table("neo_test t").Safe()
-	//设备管理表
-	table2 = g.DB().Table("instrument").Safe()
-	//入库表
-	table3 = g.DB().Table("bank_apply_detail b").Safe()
-	//维修保养表
-	table4 = g.DB().Table("instrumenmaintainlog").Safe()
-
-	table5 = g.DB().Table("gene_board_table_info").Safe()
-
-	table6 = g.DB().Table("gene_board_table_empty").Safe()
-)
-
-func GetList(where, order string, curPage, pageSize int, listPtr *[]BaseNeoClass) (total int, err error) {
-	err = table.LeftJoin("neo_class c", "t.cid=c.id").Fields("t.*,c.st_class").Where(where).OrderBy(order).Limit((curPage-1)*pageSize, pageSize).Scan(listPtr)
-	if err != nil {
-		return 0, err
-	}
-	total, err = ModelBaseNeo.Where(where).Count()
-	if err != nil {
-		return 0, err
-	}
-	return total, nil
-}
-
-func UpdateNeo(id int, theNeo *BaseNeoClass) error {
-	record := gdb.Map{
-		"Name":        theNeo.Name,
-		"Description": theNeo.Description,
-		"ceshi_desc":  theNeo.CeshiDesc,
-		"cid":         theNeo.Stclass,
-	}
-	_, err := ModelBaseNeo.Data(record).Where("Id", id).Update()
-	return err
-}
-
-func SaveNeo(theNeo *BaseNeoClass) error {
-	record := gdb.Map{
-		"Name":        theNeo.Name,
-		"Description": theNeo.Description,
-		"ceshi_desc":  theNeo.CeshiDesc,
-		"create_on":   gtime.Now(),
-		"cid":         theNeo.Stclass,
-	}
-
-	_, err := table2.Data(record).Save()
-	return err
-}
-
-func GetStById(id int, listPtr *BaseNeoClass) (err error) {
-	err = table.LeftJoin("neo_class c", "t.cid=c.id").Fields("t.*,c.st_class").Where("t.id=?", id).Scan(listPtr)
-
-	if err != nil && err != sql.ErrNoRows {
-		return err
-	}
-	return nil
-}
-
-//获取单个设备
-func GetIntById(id int, listPtr *Instrument) (err error) {
-	err = table2.Where("Id =" + strconv.Itoa(id)).Scan(listPtr)
-	if err != nil {
-		return err
-	}
-	return nil
-}
-
-//获取入库单
-func GetSampleRKbyEquipmentId(id int, order string, curPage, pageSize int,listPtr *[]Bank_Apply_Main) (err error) {
-	err = table3.LeftJoin("bank_apply_main a", "a.Id = b.ParentId").Fields("a.*").Where("b.EquipmentId = ? and b.DetailStatus = 2", id).OrderBy(order).Limit((curPage-1)*pageSize, pageSize).Group("(a.EntryNo)").Scan(listPtr)
-	if err != nil {
-		return  err
-	}
-	return  nil
-}
-
-
-//获取维修保养
-func GetmaintainlogbyInstrumenId(id int, order string, curPage, pageSize int,listPtr *[]InstrumenMaintainLog) (err error) {
-	err = table4.Where("InstrumenId =" + strconv.Itoa(id)).OrderBy(order).Limit((curPage-1)*pageSize, pageSize).Scan(listPtr)
-	if err != nil {
-		return err
-	}
-	return nil
-}
-
-//获取设备管理曲线报表
-func GetbyCode(id string,listPtr *AutoGenerated) (err error) {
-	client := &http.Client{}
-	nowtm := time.Now().Unix()
-	beforetime := strconv.FormatInt(nowtm - 3*24*60*60,10)
-	nowtime := strconv.FormatInt(nowtm,10)
-	strUrl := "http://47.92.238.200:18010/v1/channels/c"+ id +"/datapoints?start="+ beforetime +"&end=" + nowtime
-
-	req, err := http.NewRequest("GET", strUrl,nil)
-	req.Header.Add("Content-Type", "application/json")
-	req.Header.Add("apikey", "301c6bbe78b07cfd07376794f64c6bf6")
-	resp, err := client.Do(req)
-
-	fmt.Println("resp= ", resp)
-	if resp != nil {
-		defer resp.Body.Close()
-	}
-	jsonBlob, _ := ioutil.ReadAll(resp.Body)
-	json.Unmarshal(jsonBlob, &listPtr)
-	if err != nil {
-		return err
-	}
-	return nil
-}
-
-func DeleteNeo(where string) error {
-	_, err := ModelBaseNeo.Delete(where)
-	return err
-}
-
-func GetTable(listPtr *[]BaseTable) (err error) {
-	err = table3.Scan(listPtr)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-//查询有没有符合条件的Table,有就返还数据,没有就新建60条数据
-func GetBoardTable(where, typeName, nowTime string, listPtr *[]GeneBoardTable) (total int, err error) {
-	total, err = table4.Where(where).Count()
-	if err != nil {
-		return 0, err
-	}
-	//如果库里没当天 当测序类型的数据,则新建60条数据
-	if total == 0 {
-		for i := 1; i <= 8; i++ {
-			record := gdb.Map{
-				"BoardNum":      nowTime + "-" + typeName + fmt.Sprintf("%02d", i),
-				"BoardDay":      nowTime,
-				"LNum":          96,
-				"BoardTestType": typeName,
-				"CreateOn":      gtime.Now(),
-				"IsNew":         "(新板)",
-			}
-			_, errs := table4.Data(record).Save()
-			if errs != nil {
-				return 0, errs
-			}
-		}
-	}
-	where += fmt.Sprintf(" and LNum> '%d'", 0)
-	err = table4.Where(where).Scan(listPtr)
-	if err != nil {
-		return 0, err
-	}
-	return total, nil
-
-}
-
-//根据板号获取板的孔号详情
-func GetTableInfo(where string, listPtr *[]GeneBoardTableInfo) (err error) {
-	total := 0
-	total, err = table5.Where(where).Count()
-	if err != nil {
-		return err
-	}
-	//如果没有查到数据则返回一个全新的孔板
-	if total == 0 {
-		err = table6.Scan(listPtr)
-		if err != nil {
-			return err
-		}
-	} else {
-		//如果有数据则返回板数据
-		err = table5.Where(where).Scan(listPtr)
-		if err != nil {
-			return err
-		}
-
-	}
-
-	return nil
-}

+ 0 - 16
smartdoorlock/src/dashoo.cn/smartdoorlock_api/config/config.toml

@@ -8,29 +8,13 @@
     server = "39.98.34.197"
     port = "12379"
 
-# token认证设置
-[gtoken]
-    # 缓存模式 1 gcache 2 gredis
-    cache-mode = 1
-    # 是否支持多端登录
-    multi-login = true
-    # 必须16,24或32个字母
-    encrypt-key = "jwtdashoo-191225"
-
 # 数据库连接
 [database]
     [[database.default]]
         Debug = true
         link = "mysql:mcs_user:X6T1pa5o1AgO@tcp(rm-8vbk16zx2rbfu6jt6uo.mysql.zhangbei.rds.aliyuncs.com)/mcs_db"
 #link = "mysql:mcs_user:X6T1pa5o1AgO@tcp(47.92.249.239:3306)/mcs_db"
-# Redis数据库配置
-[redis]
-    default = "127.0.0.1:16379,0,soccer"
-    cache   = "127.0.0.1:16379,1,soccer?idleTimeout=600"
 
-[micro_srv]
-    auth = "dashoo.labsop.srv.auth-prod-1.0"
-    admin = "dashoo.labsop.srv.admin-prod-1.0"
 
 [owner]
     name = "Tom Preston-Werner"

+ 3 - 7
smartdoorlock/src/dashoo.cn/smartdoorlock_api/go.mod

@@ -3,15 +3,11 @@ module dashoo.cn/smartdoorlock_api
 go 1.12
 
 require (
-	dashoo.cn/common_proto v0.0.0
 	dashoo.cn/micro_libary v0.0.0
-	github.com/BurntSushi/toml v0.3.1
 	github.com/eclipse/paho.mqtt.golang v1.2.0
-	github.com/gogf/gf v1.14.2
-	github.com/micro/go-micro/v2 v2.5.1-0.20200417165434-16db76bee2fb
-	golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect
+	github.com/gogf/gf v1.15.3
 )
 
-replace dashoo.cn/micro_libary => ../../../../micro_libary
+replace dashoo.cn/micro_libary => ../../../../../micro_libary
 
-replace dashoo.cn/common_proto => ../../../../micro_common_proto/src
+replace dashoo.cn/common_proto => ../../../../../micro_common_proto/src

+ 0 - 355
smartdoorlock/src/dashoo.cn/smartdoorlock_api/library/gtoken/gtoken.go

@@ -1,355 +0,0 @@
-package gtoken
-
-import (
-	"context"
-	"dashoo.cn/micro_libary/microsrv"
-	"fmt"
-	"strings"
-
-	auth "dashoo.cn/common_proto/auth"
-	"dashoo.cn/smartdoorlock_api/app/service/user"
-	"github.com/gogf/gf/encoding/gjson"
-	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/net/ghttp"
-	"github.com/gogf/gf/os/glog"
-	"github.com/gogf/gf/os/gtime"
-	"github.com/gogf/gf/util/gconv"
-)
-
-var authClient auth.AuthService
-
-func init() {
-	authSvrName, theClient := microsrv.GetMicroConfig("micro_srv.auth")
-	authClient = auth.NewAuthService(authSvrName, theClient)
-}
-
-// GfToken gtoken结构体
-type GfToken struct {
-	// 认证失败中文提示
-	AuthFailMsg string
-
-	// 登录路径
-	LoginPath string
-	// 登录验证方法 return userKey 用户标识 如果userKey为空,结束执行
-	LoginBeforeFunc func(r *ghttp.Request) (string, string, interface{})
-	// 登录返回方法
-	LoginAfterFunc func(r *ghttp.Request, respData Resp)
-	// 登出地址
-	LogoutPath string
-	// 登出验证方法 return true 继续执行,否则结束执行
-	LogoutBeforeFunc func(r *ghttp.Request) bool
-	// 登出返回方法
-	LogoutAfterFunc func(r *ghttp.Request, respData Resp)
-
-	// 拦截地址
-	AuthPaths g.SliceStr
-	// 认证验证方法 return true 继续执行,否则结束执行
-	AuthBeforeFunc func(r *ghttp.Request) bool
-	// 认证返回方法
-	AuthAfterFunc func(r *ghttp.Request, respData Resp)
-}
-
-// Init 初始化
-func (m *GfToken) Init() bool {
-	if m.AuthFailMsg == "" {
-		m.AuthFailMsg = "请求错误或登录超时"
-	}
-
-	if m.LoginAfterFunc == nil {
-		m.LoginAfterFunc = func(r *ghttp.Request, respData Resp) {
-			if !respData.Success() {
-				r.Response.WriteJson(respData)
-			} else {
-				json, err := gjson.DecodeToJson(respData.Data)
-				if err != nil {
-					r.Response.WriteJson(Unauthorized("sys fail", ""))
-					return
-				}
-				r.Response.WriteJson(Succ(json))
-			}
-		}
-	}
-
-	if m.LogoutBeforeFunc == nil {
-		m.LogoutBeforeFunc = func(r *ghttp.Request) bool {
-			return true
-		}
-	}
-
-	if m.LogoutAfterFunc == nil {
-		m.LogoutAfterFunc = func(r *ghttp.Request, respData Resp) {
-			if respData.Success() {
-				r.Response.WriteJson(Succ("Logout success"))
-			} else {
-				r.Response.WriteJson(respData)
-			}
-		}
-	}
-
-	if m.AuthBeforeFunc == nil {
-		m.AuthBeforeFunc = func(r *ghttp.Request) bool {
-			// 静态页面不拦截
-			if r.IsFileRequest() {
-				return false
-			}
-
-			return true
-		}
-	}
-	if m.AuthAfterFunc == nil {
-		m.AuthAfterFunc = func(r *ghttp.Request, respData Resp) {
-			if respData.Success() {
-				r.Middleware.Next()
-			} else {
-				var params map[string]interface{}
-				if r.Method == "GET" {
-					params = r.GetMap()
-				} else if r.Method == "POST" {
-					params = r.GetMap()
-				} else {
-					r.Response.Writeln("Request Method is ERROR! ")
-					return
-				}
-
-				no := gconv.String(gtime.TimestampMilli())
-
-				glog.Info(fmt.Sprintf("[AUTH_%s][url:%s][params:%s][data:%s]",
-					no, r.URL.Path, params, respData.Json()))
-				respData.Msg = m.AuthFailMsg
-				r.Response.WriteStatus(401)
-				r.Response.WriteJson(respData)
-				r.ExitAll()
-			}
-		}
-	}
-
-	return true
-}
-
-// Start 启动
-func (m *GfToken) Start() bool {
-	if !m.Init() {
-		return false
-	}
-	glog.Info("[GToken][params:" + m.String() + "]start... ")
-
-	s := g.Server()
-
-	// 认证拦截器
-	if m.AuthPaths == nil {
-		glog.Error("[GToken]HookPathList not set")
-		return false
-	}
-	for _, authPath := range m.AuthPaths {
-		if strings.HasSuffix(authPath, "/*") {
-			s.BindMiddleware(authPath, m.AuthMiddleware)
-		} else {
-			s.BindMiddleware(authPath+"/*", m.AuthMiddleware)
-		}
-	}
-
-	// 登录
-	if m.LoginPath == "" || m.LoginBeforeFunc == nil {
-		glog.Error("[GToken]LoginPath or LoginBeforeFunc not set")
-		return false
-	}
-	s.BindHandler(m.LoginPath, m.Login)
-
-	// 登出
-	if m.LogoutPath == "" {
-		glog.Error("[GToken]LogoutPath or LogoutFunc not set")
-		return false
-	}
-	s.BindHandler(m.LogoutPath, m.Logout)
-
-	return true
-}
-
-// Start 结束
-func (m *GfToken) Stop() bool {
-	glog.Info("[GToken]stop. ")
-	return true
-}
-
-//// GetTokenData 通过token获取对象
-//func (m *GfToken) GetTokenData(r *ghttp.Request) Resp {
-//	respData := m.getRequestToken(r)
-//	if respData.Success() {
-//		// 验证token
-//		respData = m.ValidToken(respData.DataString())
-//	}
-//
-//	return respData
-//}
-
-// 获取或建立Token
-func (m *GfToken) GetOrGenToken(tenant, userKey, uuid string, resp *Resp) error {
-	rsp, err := authClient.GetToken(context.TODO(), &auth.Request{
-		Tenant:  tenant,
-		UserKey: userKey,
-		Uuid:    uuid,
-		Data:    "",
-	})
-	if err != nil {
-		glog.Error(err)
-		return err
-	}
-
-	if err := gconv.Struct(rsp, resp); err != nil {
-		glog.Error(err)
-		return err
-	}
-	return nil
-}
-
-// 删除Token
-func (m *GfToken) RemoveToken(token string, resp *Resp) error {
-	rsp, err := authClient.RemoveToken(context.TODO(), &auth.ReqToken{
-		Token: token,
-	})
-	if err != nil {
-		return err
-	}
-	if err := gconv.Struct(rsp, resp); err != nil {
-		return err
-	}
-	return nil
-}
-
-// Login 登录
-func (m *GfToken) Login(r *ghttp.Request) {
-	//userKey, data := m.LoginBeforeFunc(r)
-	// todo 暂时不考虑data
-	userKey, uuid, _ := m.LoginBeforeFunc(r)
-	tenant := r.Header.Get("Tenant")
-	//tenant := g.Config().GetString("gtoken.tenant")
-	if userKey == "" {
-		glog.Error("[GToken]Login userKey is empty")
-		return
-	}
-	if tenant == "" {
-		glog.Error("[GToken]Login tenant is empty")
-		return
-	}
-	if uuid == "" {
-		glog.Error("[GToken]Login uuid is empty")
-		return
-	}
-	respToken := new(Resp)
-	err := m.GetOrGenToken(tenant, userKey, uuid, respToken)
-	if err != nil {
-		return
-	}
-
-	m.LoginAfterFunc(r, *respToken)
-}
-
-// Logout 登出
-func (m *GfToken) Logout(r *ghttp.Request) {
-	if m.LogoutBeforeFunc(r) {
-		// 获取请求token
-		respData := m.getRequestToken(r)
-		if respData.Success() {
-			// 删除token
-			respToken := new(Resp)
-			err := m.RemoveToken(respData.DataString(), respToken)
-			if err != nil {
-				glog.Error(err)
-				return
-			}
-		}
-
-		m.LogoutAfterFunc(r, respData)
-	}
-}
-
-// AuthMiddleware 认证拦截
-func (m *GfToken) AuthMiddleware(r *ghttp.Request) {
-	// 不需要认证,直接下一步
-	if !m.AuthBeforeFunc(r) {
-		r.Middleware.Next()
-		return
-	}
-
-	// 获取请求token
-	tokenResp := m.getRequestToken(r)
-	if tokenResp.Success() {
-		// 验证token
-		tokenResp = m.ValidToken(tokenResp.DataString())
-		// 查询user信息并放入r中
-		theuser := new(user.BaseUser)
-		username := ""
-		if j, err := gjson.DecodeToJson([]byte(tokenResp.DataString())); err != nil {
-			glog.Error(err)
-		} else {
-			j.SetViolenceCheck(true)
-			username = j.GetString("userKey")
-		}
-		user.GetUserByUserName(username, theuser)
-		r.SetParam("username", theuser.UserName)
-		r.SetParam("userid", theuser.Id)
-		r.SetParam("realname", theuser.Realname)
-	}
-	m.AuthAfterFunc(r, tokenResp)
-
-}
-
-// getRequestToken 返回请求Token
-func (m *GfToken) getRequestToken(r *ghttp.Request) Resp {
-	authHeader := r.Header.Get("Authorization")
-	if authHeader != "" {
-		parts := strings.SplitN(authHeader, " ", 2)
-		if !(len(parts) == 2 && parts[0] == "Bearer") {
-			glog.Warning("[GToken]authHeader:" + authHeader + " get token key fail")
-			return Unauthorized("get token key fail", "")
-		} else if parts[1] == "" {
-			glog.Warning("[GToken]authHeader:" + authHeader + " get token fail")
-			return Unauthorized("get token fail", "")
-		}
-
-		return Succ(parts[1])
-	}
-
-	authHeader = r.GetString("token")
-	if authHeader == "" {
-		return Unauthorized("query token fail", "")
-	}
-	return Succ(authHeader)
-}
-
-// validToken 验证Token
-func (m *GfToken) ValidToken(token string) Resp {
-	if token == "" {
-		return Unauthorized("valid token empty", "")
-	}
-
-	respToken := new(Resp)
-	rsp, err := authClient.ValidToken(context.TODO(), &auth.ReqToken{
-		Token: token,
-	})
-	if err != nil {
-		glog.Error(err)
-		return Unauthorized("auth service error", "")
-	}
-
-	if err := gconv.Struct(rsp, respToken); err != nil {
-		glog.Error(err)
-		return Unauthorized("auth service error", "")
-	}
-	return *respToken
-}
-
-// String token解密方法
-func (m *GfToken) String() string {
-	return gconv.String(g.Map{
-		// 缓存模式 1 gcache 2 gredis 默认1
-		//"CacheMode":      m.CacheMode,
-		//"CacheKey":       m.CacheKey,
-		//"Timeout":        m.Timeout,
-		//"TokenDelimiter": m.TokenDelimiter,
-		//"EncryptKey":     string(m.EncryptKey),
-		"LoginPath":  m.LoginPath,
-		"LogoutPath": m.LogoutPath,
-		"AuthPaths":  gconv.String(m.AuthPaths),
-	})
-}

+ 0 - 92
smartdoorlock/src/dashoo.cn/smartdoorlock_api/library/gtoken/gtoken_resp.go

@@ -1,92 +0,0 @@
-package gtoken
-
-import (
-	"encoding/json"
-	"github.com/gogf/gf/util/gconv"
-)
-
-const (
-	SUCCESS      = 0
-	FAIL         = -1
-	ERROR        = -99
-	UNAUTHORIZED = -401
-	//配置
-	TypeConfig = 1
-	//  字典
-	TypeDict = 2
-)
-
-type Resp struct {
-	Code int         `json:"code"`
-	Msg  string      `json:"msg"`
-	Data interface{} `json:"data"`
-}
-
-// 获取Data值转字符串
-func (resp Resp) Success() bool {
-	return resp.Code == SUCCESS
-}
-
-// 获取Data转字符串
-func (resp Resp) DataString() string {
-	return gconv.String(resp.Data)
-}
-
-// 获取Data转Int
-func (resp Resp) DataInt() int {
-	return gconv.Int(resp.Data)
-}
-
-// 获取Data值转字符串
-func (resp Resp) GetString(key string) string {
-	return gconv.String(resp.Get(key))
-}
-
-// 获取Data值转Int
-func (resp Resp) GetInt(key string) int {
-	return gconv.Int(resp.Get(key))
-}
-
-// 获取Data值
-func (resp Resp) Get(key string) interface{} {
-	m := gconv.Map(resp.Data)
-	if m == nil {
-		return ""
-	}
-	return m[key]
-}
-
-func (resp Resp) Json() string {
-	str, _ := json.Marshal(resp)
-	return string(str)
-}
-
-// 成功
-func Succ(data interface{}) Resp {
-	return Resp{SUCCESS, "success", data}
-}
-
-// 失败
-func Fail(msg string) Resp {
-	return Resp{FAIL, msg, ""}
-}
-
-// 失败设置Data
-func FailData(msg string, data interface{}) Resp {
-	return Resp{FAIL, msg, data}
-}
-
-// 错误
-func Error(msg string) Resp {
-	return Resp{ERROR, msg, ""}
-}
-
-// 错误设置Data
-func ErrorData(msg string, data interface{}) Resp {
-	return Resp{ERROR, msg, data}
-}
-
-// 认证失败
-func Unauthorized(msg string, data interface{}) Resp {
-	return Resp{UNAUTHORIZED, msg, data}
-}

+ 0 - 56
smartdoorlock/src/dashoo.cn/smartdoorlock_api/library/gtoken/gtoken_test.go

@@ -1,56 +0,0 @@
-package gtoken_test
-
-import (
-	"dashoo.cn/smartdoorlock_api/library/gtoken"
-	"github.com/gogf/gf/encoding/gjson"
-	"testing"
-)
-
-func TestEncryptDecryptToken(t *testing.T) {
-	t.Log("encrypt and decrypt token test ")
-	gfToken := gtoken.GfToken{}
-	gfToken.Init()
-
-	userKey := "123123"
-
-	respToken := new(gtoken.Resp)
-	err := gfToken.GetOrGenToken(userKey, respToken)
-	if err != nil {
-		t.Log(err)
-	}
-	t.Log(respToken)
-
-	j, err := gjson.DecodeToJson(respToken.Data)
-	if err != nil {
-		t.Error(err)
-	}
-
-	//token := respToken.GetString("token")
-	token := j.GetString("token")
-	t.Log(token)
-
-	//s, _:=gbase64.Decode([]byte(token))
-	//token = string(s)
-	//t.Log(token)
-	resp := gfToken.ValidToken(token)
-	t.Log(resp)
-
-	//token := gfToken.EncryptToken(userKey, "")
-	//if !token.Success() {
-	//	t.Error(token.Json())
-	//}
-	//t.Log(token.DataString())
-	//
-	//token2 := gfToken.DecryptToken(token.GetString("token"))
-	//if !token2.Success() {
-	//	t.Error(token2.Json())
-	//}
-	//t.Log(token2.DataString())
-	//if userKey != token2.GetString("userKey") {
-	//	t.Error("token decrypt userKey error")
-	//}
-	//if token.GetString("uuid") != token2.GetString("uuid") {
-	//	t.Error("token decrypt uuid error")
-	//}
-
-}

+ 1 - 38
smartdoorlock/src/dashoo.cn/smartdoorlock_api/router/router.go

@@ -6,51 +6,14 @@ import (
 	"github.com/gogf/gf/net/ghttp"
 )
 
-// 测试用
-type Task struct{}
-
-func (c *Task) Add(r *ghttp.Request) {
-	r.Response.Writeln("Add")
-}
-
-func (c *Task) Task(r *ghttp.Request) {
-	r.Response.Writeln("Task")
-}
-
 // 统一路由注册.
 func init() {
 	s := g.Server()
-	//s.BindHookHandler("/login", ghttp.HOOK_BEFORE_SERVE, CorsHookHandler)
-	//s.BindHookHandler("/logout", ghttp.HOOK_BEFORE_SERVE, CorsHookHandler)
 
-	//s.BindHandler("ALL:/login", auth.GfJWTMiddleware.LoginHandler)
 	s.Group("/api").Bind([]ghttp.GroupItem{
 		{"ALL", "*", CorsHookHandler, ghttp.HOOK_BEFORE_SERVE},
-		//{"MIDDLEWARE", "*", MiddlewareCORS},
-		//{"ALL", "/user", new(user.Controller)},
-		//{"ALL", "/role", new(role.Controller)},
-		//{"ALL", "/neo", new(neo.Controller)},
 		{"ALL", "/remote_control", new(remote_control.Controller)},
-		//{"ALL", "/task", new(Task)},
-		//{"ALL", "/permission", new(permission.Controller)},
-		//{"ALL", "/organize", new(organize.Controller)},
-		//{"ALL", "/menu", new(menu.Controller)},
 	})
-
-	//var u user.Controller
-
-	// 开启全局soken服务
-	//loginFunc := user.SiTest
-
-	//loginFunc := user.SignIn
-	//
-	//gfToken := &gtoken.GfToken{
-	//	LoginPath:       "/login",
-	//	LoginBeforeFunc: loginFunc,
-	//	LogoutPath:      "/logout",
-	//	AuthPaths:       g.SliceStr{"/api"},
-	//}
-	//gfToken.Start()
 }
 
 // 实现权限校验
@@ -65,7 +28,7 @@ func CorsHookHandler(r *ghttp.Request) {
 	//r.Response.CORSDefault()
 	var CORSOptions = ghttp.CORSOptions{
 		AllowOrigin:      "*",
-		AllowMethods:     ghttp.HTTP_METHODS,
+		AllowMethods:     "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE",
 		AllowCredentials: "true",
 		AllowHeaders:     "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With,Tenant",
 		MaxAge:           3628800,