|
|
@@ -1,9 +1,9 @@
|
|
|
package instrument
|
|
|
|
|
|
import (
|
|
|
+ "dashoo.cn/micro_libary/response"
|
|
|
"dashoo.cn/modi_webapi/app/service/instrument"
|
|
|
"dashoo.cn/modi_webapi/library/request"
|
|
|
- "dashoo.cn/modi_webapi/library/response"
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/net/ghttp"
|
|
|
"github.com/gogf/gf/os/gtime"
|
|
|
@@ -13,34 +13,34 @@ import (
|
|
|
type Controller struct {
|
|
|
}
|
|
|
|
|
|
-func (c *Controller) GetAllInstrument(r *ghttp.Request){
|
|
|
+func (c *Controller) GetAllInstrument(r *ghttp.Request) {
|
|
|
page := request.GetPageInfo(r)
|
|
|
where := ""
|
|
|
|
|
|
- if productway := r.GetString("ProductWay"); productway != ""{
|
|
|
- if where == ""{
|
|
|
+ if productway := r.GetString("ProductWay"); productway != "" {
|
|
|
+ if where == "" {
|
|
|
where = fmt.Sprintf(" ProductWay = %v", productway)
|
|
|
} else {
|
|
|
where += fmt.Sprintf(" AND ProductWay = %v", productway)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if name := r.GetString("ProductName"); name != ""{
|
|
|
- if where == ""{
|
|
|
- where = fmt.Sprintf(" ProductName LIKE '%%%v%%'", name)
|
|
|
+ if name := r.GetString("Name"); name != "" {
|
|
|
+ if where == "" {
|
|
|
+ where = fmt.Sprintf(" Name LIKE '%%%v%%'", name)
|
|
|
} else {
|
|
|
- where += fmt.Sprintf(" AND ProductName LIKE '%%%v%%'", name)
|
|
|
+ where += fmt.Sprintf(" AND Name LIKE '%%%v%%'", name)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var result []instrument.Entity
|
|
|
- if err := instrument.GetAllInstrument(page, where, &result); err != nil{
|
|
|
- if err.Error() == "sql: no rows in result set"{
|
|
|
+ if err := instrument.GetAllInstrument(page, where, &result); err != nil {
|
|
|
+ if err.Error() == "sql: no rows in result set" {
|
|
|
response.Json(r, 0, "")
|
|
|
return
|
|
|
}
|
|
|
response.Json(r, -1, err.Error())
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
count, err1 := instrument.FindInstrumentCount(where)
|
|
|
if err1 != nil {
|
|
|
response.Json(r, -1, err1.Error())
|
|
|
@@ -50,18 +50,17 @@ func (c *Controller) GetAllInstrument(r *ghttp.Request){
|
|
|
records.Current = page.Current
|
|
|
records.Total = count
|
|
|
records.Records = result
|
|
|
- response.Json(r, 0, "", records)
|
|
|
+ response.Json(r, 0, "ok", records)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func (c *Controller) GetOneInstrument(r *ghttp.Request){
|
|
|
+func (c *Controller) GetOneInstrument(r *ghttp.Request) {
|
|
|
id := r.GetInt("id")
|
|
|
if result, err := instrument.FindOne(id); err != nil {
|
|
|
response.Json(r, 1, err.Error())
|
|
|
r.ExitAll()
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
var records response.PagedRecords
|
|
|
records.Records = result
|
|
|
response.Json(r, 0, "", records)
|
|
|
@@ -69,9 +68,9 @@ func (c *Controller) GetOneInstrument(r *ghttp.Request){
|
|
|
|
|
|
}
|
|
|
|
|
|
-func (c *Controller) AddInstrument(r *ghttp.Request){
|
|
|
+func (c *Controller) AddInstrument(r *ghttp.Request) {
|
|
|
Instrument := new(instrument.Entity)
|
|
|
- fmt.Println("---Instrument---",Instrument)
|
|
|
+ fmt.Println("---Instrument---", Instrument)
|
|
|
if err := r.Parse(Instrument); err != nil {
|
|
|
// 数据验证错误
|
|
|
if v, ok := err.(*gvalid.Error); ok {
|
|
|
@@ -95,7 +94,7 @@ func (c *Controller) AddInstrument(r *ghttp.Request){
|
|
|
Instrument.ModifiedBy = realName
|
|
|
Instrument.ModifiedUserId = userId
|
|
|
|
|
|
- if result,err := instrument.Insert(Instrument); err != nil {
|
|
|
+ if result, err := instrument.Insert(Instrument); err != nil {
|
|
|
response.Json(r, 1, err.Error())
|
|
|
} else {
|
|
|
var records response.PagedRecords
|
|
|
@@ -106,7 +105,7 @@ func (c *Controller) AddInstrument(r *ghttp.Request){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (c *Controller) UpdateInstrument(r *ghttp.Request){
|
|
|
+func (c *Controller) UpdateInstrument(r *ghttp.Request) {
|
|
|
Instrument := new(instrument.Entity)
|
|
|
if err := r.Parse(Instrument); err != nil {
|
|
|
// 数据验证错误
|
|
|
@@ -127,7 +126,7 @@ func (c *Controller) UpdateInstrument(r *ghttp.Request){
|
|
|
Instrument.ModifiedBy = realName
|
|
|
Instrument.ModifiedUserId = userId
|
|
|
|
|
|
- if _,err := instrument.Replace(Instrument); err != nil {
|
|
|
+ if _, err := instrument.Replace(Instrument); err != nil {
|
|
|
response.Json(r, 1, err.Error())
|
|
|
} else {
|
|
|
var records response.PagedRecords
|
|
|
@@ -138,9 +137,9 @@ func (c *Controller) UpdateInstrument(r *ghttp.Request){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (c *Controller) DeleteInstrument(r *ghttp.Request){
|
|
|
+func (c *Controller) DeleteInstrument(r *ghttp.Request) {
|
|
|
id := r.GetInt("id")
|
|
|
- if _,err := instrument.Delete(fmt.Sprintf("Id=%v", id)); err != nil{
|
|
|
+ if _, err := instrument.Delete(fmt.Sprintf("Id=%v", id)); err != nil {
|
|
|
response.Json(r, 1, err.Error())
|
|
|
r.ExitAll()
|
|
|
} else {
|