Browse Source

代jiawei提交

master
巴林闲侠 2 years ago
parent
commit
4c54c7ed51
  1. 3
      gowork/src/main/conf.ini
  2. 22
      gowork/src/main/project/API.go
  3. 129
      gowork/src/main/project/DbServe.go
  4. 3
      gowork/src/main/project/conf.ini

3
gowork/src/main/conf.ini

@ -0,0 +1,3 @@
[Server]
type = postgres
url = postgres://FashionAdmin:123456@10.8.30.36:5432/test

22
gowork/src/main/project/API.go

@ -77,18 +77,9 @@ func readPeople(c *gin.Context) {
} else {
defer rows.Close()
for rows.Next() {
var WorkUint8 []uint8
if err = rows.Scan(&project.Name_people, &project.Post_people, &WorkUint8); err != nil {
if err = rows.Scan(&project.Name_people, &project.Post_people, &project.MD, &project.TD, &project.WD, &project.THD, &project.FD, &project.SD, &project.SSD); err != nil {
fmt.Printf("%s", err)
} else {
workStr := string(WorkUint8)
var work []Work
err = json.Unmarshal([]byte(workStr), &work)
if err != nil {
fmt.Printf("%s", err)
return
}
project.Work = work
projects = append(projects, project)
}
}
@ -124,6 +115,9 @@ func writeProject(c *gin.Context) {
body, _ := ioutil.ReadAll(c.Request.Body)
if err := ProjectInDB(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": "data err",
})
} else {
c.JSON(http.StatusOK, gin.H{
@ -135,7 +129,9 @@ func writeProject(c *gin.Context) {
func writePeople(c *gin.Context) {
body, _ := ioutil.ReadAll(c.Request.Body)
if err := PeopleInDB(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": "data err",
})
} else {
c.JSON(http.StatusOK, gin.H{
"result": "ok",
@ -147,7 +143,9 @@ func writePeople(c *gin.Context) {
func writeWait(c *gin.Context) {
body, _ := ioutil.ReadAll(c.Request.Body)
if err := WaitInDB(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": "data err",
})
} else {
c.JSON(http.StatusOK, gin.H{
"result": "ok",

129
gowork/src/main/project/DbServe.go

@ -15,20 +15,9 @@ var wg sync.WaitGroup
var mt sync.Mutex
func OpenDB() {
//conf, err := ini.Load("conf.ini")
//if err != nil {
// fmt.Printf("%s", err)
//}
//
//for _, v := range conf.Sections() {
// fmt.Println(v.KeyStrings())
//}
utils.IniInit()
url := utils.GIniParser.GetString("Server", "url")
dbType := utils.GIniParser.GetString("Server", "type")
//dbType := "postgres"
//dbType := "postgres://postgres:postgres@10.8.30.156:5432/Anxinyun0808?sslmode=disable"
//url := "postgres://FashionAdmin:123456@10.8.30.36:5432/test"
if db, err = sql.Open(dbType, url); err != nil {
fmt.Printf("%s", err)
return
@ -54,9 +43,9 @@ func deleteDb(str []byte) error {
case "test_people":
k1 = "name_people"
k2 = "post_people"
case "test_prpject":
case "test_project":
k1 = "name_project"
k2 = "post_progress"
k2 = "progress"
case "test_waiting":
k1 = "name_project"
k2 = "progress"
@ -92,14 +81,21 @@ func ProjectInDB(str []byte) error {
if err != nil {
fmt.Printf("%s", err)
}
peopleSQL := fmt.Sprintf(
"DO $$ BEGIN\n"+
"IF NOT EXISTS ( SELECT * FROM test_project WHERE name_project = '%v' ) THEN\n"+
"INSERT INTO test_project (name_project, build_time, publish_time, part_people, progress )VALUES( '%v', '%v', '%v', '%v', '%v' );\n"+
"ELSE\n"+
"UPDATE test_project SET build_time = '%v',publish_time = '%v',part_people = '%v',progress = '%v' WHERE name_project = '%v';\n"+
"END IF;\nEND $$",
body.Name_project, body.Name_project, body.Build_time, body.Publish_time, string(bytePeople), body.Progress, body.Build_time, body.Publish_time, string(bytePeople), body.Progress, body.Name_project)
var peopleSQL string
if body.OName_project != "" {
peopleSQL = fmt.Sprintf("UPDATE test_project SET name_project ='%v' ,build_time = '%v',publish_time = '%v',part_people = '%v',progress = '%v' WHERE name_project = '%v';",
body.Name_project, body.Build_time, body.Publish_time, string(bytePeople), body.Progress, body.OName_project)
} else {
peopleSQL = fmt.Sprintf(
"DO $$ BEGIN\n"+
"IF NOT EXISTS ( SELECT * FROM test_project WHERE name_project = '%v' ) THEN\n"+
"INSERT INTO test_project (name_project, build_time, publish_time, part_people, progress )VALUES( '%v', '%v', '%v', '%v', '%v' );\n"+
"ELSE\n"+
"UPDATE test_project SET build_time = '%v',publish_time = '%v',part_people = '%v',progress = '%v' WHERE name_project = '%v';\n"+
"END IF;\nEND $$",
body.Name_project, body.Name_project, body.Build_time, body.Publish_time, string(bytePeople), body.Progress, body.Build_time, body.Publish_time, string(bytePeople), body.Progress, body.Name_project)
}
//var result sql.Result
_, err = db.Exec(peopleSQL)
if err != nil {
@ -130,19 +126,24 @@ func PeopleInDB(str []byte) error {
mt.Lock()
defer mt.Unlock()
defer wg.Done()
var byteWork []byte
byteWork, err = json.Marshal(body.Work)
if err != nil {
fmt.Printf("%s", err)
}
peopleSQL := fmt.Sprintf(
"DO\n$$\nBEGIN \n"+
"IF NOT EXISTS (select * FROM test_people WHERE name_people = '%v')\nTHEN\n"+
"INSERT INTO test_people (name_people,post_people,work)VALUES('%v','%v','%v');\n"+
"ELSE\n"+
"UPDATE test_people SET post_people ='%v' ,work= '%v' WHERE name_people = '%v';\n"+
"end if;\nEND\n$$",
body.Name_people, body.Name_people, body.Post_people, string(byteWork), body.Post_people, string(byteWork), body.Name_people)
var peopleSQL string
if body.OName_people != "" {
peopleSQL = fmt.Sprintf("UPDATE test_people SET name_people ='%v', post_people ='%v' ,md='%v',td='%v',wd='%v',thd='%v',fd='%v', sd='%v',ssd='%v'WHERE name_people = '%v';",
body.Name_people, body.Post_people, body.MD, body.TD, body.WD, body.THD, body.FD, body.SD, body.SSD, body.OName_people)
} else {
peopleSQL = fmt.Sprintf(
"DO\n$$\nBEGIN \n"+
"IF NOT EXISTS (select * FROM test_people WHERE name_people = '%v')\nTHEN\n"+
"INSERT INTO test_people (name_people,post_people,md,td,wd,thd,fd,sd,ssd)VALUES('%v','%v','%v','%v','%v','%v','%v','%v','%v');\n"+
"ELSE\n"+
"UPDATE test_people SET post_people ='%v' ,md='%v',td='%v',wd='%v',thd='%v',fd='%v',sd='%v',ssd='%v' WHERE name_people = '%v';\n"+
"end if;\nEND\n$$",
body.Name_people, body.Name_people, body.Post_people, body.MD, body.TD, body.WD, body.THD, body.FD, body.SD, body.SSD, body.Post_people, body.MD, body.TD, body.WD, body.THD, body.FD, body.SD, body.SSD, body.Name_people)
}
//var result sql.Result
_, err = db.Exec(peopleSQL)
if err != nil {
@ -173,14 +174,21 @@ func WaitInDB(str []byte) error {
mt.Lock()
defer mt.Unlock()
defer wg.Done()
peopleSQL := fmt.Sprintf(""+
"DO $$ BEGIN\n"+
"IF NOT EXISTS ( SELECT * FROM test_waiting WHERE name_project = '%v' ) THEN\n"+
"INSERT INTO test_waiting (name_project, from_project, contacts, progress)VALUES( '%v', '%v', '%v', '%v' );\n"+
"ELSE\n"+
"UPDATE test_waiting SET from_project = '%v',contacts = '%v',progress = '%v' WHERE name_project = '%v';\n"+
"END IF;\nEND $$",
body.Name_project, body.Name_project, body.From_project, body.Contacts, body.Progress, body.From_project, body.Contacts, body.Progress, body.Name_project)
var peopleSQL string
if body.OName_project != "" {
peopleSQL = fmt.Sprintf("UPDATE test_waiting SET name_project = '%v', from_project = '%v',contacts = '%v',progress = '%v' WHERE name_project = '%v';",
body.Name_project, body.From_project, body.Contacts, body.Progress, body.OName_project)
} else {
peopleSQL = fmt.Sprintf(""+
"DO $$ BEGIN\n"+
"IF NOT EXISTS ( SELECT * FROM test_waiting WHERE name_project = '%v' ) THEN\n"+
"INSERT INTO test_waiting (name_project, from_project, contacts, progress)VALUES( '%v', '%v', '%v', '%v' );\n"+
"ELSE\n"+
"UPDATE test_waiting SET from_project = '%v',contacts = '%v',progress = '%v' WHERE name_project = '%v';\n"+
"END IF;\nEND $$",
body.Name_project, body.Name_project, body.From_project, body.Contacts, body.Progress, body.From_project, body.Contacts, body.Progress, body.Name_project)
}
//var result sql.Result
_, err = db.Exec(peopleSQL)
if err != nil {
@ -206,11 +214,12 @@ type delete struct {
}
type Project struct {
Name_project string `json:"name_project"`
Build_time string `json:"build_time"`
Publish_time string `json:"publish_time"`
Part_people []pPeople `json:"part_people"`
Progress string `json:"progress"`
OName_project string `json:"o_name_project"`
Name_project string `json:"name_project"`
Build_time string `json:"build_time"`
Publish_time string `json:"publish_time"`
Part_people []pPeople `json:"part_people"`
Progress string `json:"progress"`
}
type pPeople struct {
@ -218,20 +227,30 @@ type pPeople struct {
}
type People struct {
Name_people string `json:"name_people"`
Post_people string `json:"post_people"`
Work []Work `json:"work"`
}
type Work struct {
Time string `json:"time"`
Project string `json:"project"`
OName_people string `json:"o_name_people"`
Name_people string `json:"name_people"`
Post_people string `json:"post_people"`
//Work []Work `json:"work"`
MD string `json:"md"`
TD string `json:"td"`
WD string `json:"wd"`
THD string `json:"thd"`
FD string `json:"fd"`
SD string `json:"sd"`
SSD string `json:"ssd"`
}
//type Work struct {
// Time string `json:"time"`
// Project string `json:"project"`
//}
type Wait struct {
Name_project string `json:"name_project"`
From_project string `json:"from_project"`
Contacts string `json:"contacts"`
Progress string `json:"progress"`
OName_project string `json:"o_name_project"`
Name_project string `json:"name_project"`
From_project string `json:"from_project"`
Contacts string `json:"contacts"`
Progress string `json:"progress"`
}
const SearchProject = `SELECT * FROM "test_project"`

3
gowork/src/main/project/conf.ini

@ -0,0 +1,3 @@
[Server]
type = postgres
url = postgres://FashionAdmin:123456@10.8.30.36:5432
Loading…
Cancel
Save