|
@@ -1,6 +1,7 @@
|
|
|
package controller
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"lims-extend/common"
|
|
|
"lims-extend/model"
|
|
@@ -40,3 +41,69 @@ func TakeTask(c *gin.Context) {
|
|
|
response.Success(c, gin.H{"task": task}, "任务领取成功")
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+func ShowTasks(c *gin.Context) {
|
|
|
+ softwareId := c.Query("software_id")
|
|
|
+ executorId := c.Query("worker_id")
|
|
|
+ isJoined := c.Query("is_joined")
|
|
|
+
|
|
|
+ db := common.GetDB()
|
|
|
+ type result struct {
|
|
|
+ ID string `json:"id"`
|
|
|
+ CreatTime model.Time `json:"create_time" gorm:"column:create_time"`
|
|
|
+ Creator string `json:"creator"`
|
|
|
+ CreatorId string `json:"creator_id" gorm:"column:creator_id"`
|
|
|
+ WorkerId string `json:"executor_id" gorm:"column:executor_id"`
|
|
|
+ Worker string `json:"worker"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ SoftwareName string `json:"software_name"`
|
|
|
+ SoftwareId string `json:"software_id" gorm:"column:software_id"`
|
|
|
+ State int `json:"state"`
|
|
|
+ Title string `json:"title"`
|
|
|
+ UpdateTime model.Time `json:"update_time" gorm:"column:update_time"`
|
|
|
+ Version string `json:"version"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ IsJoined bool `json:"is_joined"`
|
|
|
+ }
|
|
|
+ var res []result
|
|
|
+
|
|
|
+ sql := "SELECT task.id, task.create_time,plan.creator_id,task.executor_id," +
|
|
|
+ "plan.description,software_id,task.state,plan.title,task.update_time," +
|
|
|
+ "plan.version,plan.type from task,plan WHERE task.plan_id = plan.id and" +
|
|
|
+ " executor_id = ? %s %s"
|
|
|
+ if isJoined == "true" {
|
|
|
+ sql = fmt.Sprintf(sql, "and task.state <> 3", "%s")
|
|
|
+ } else if isJoined == "false" {
|
|
|
+ sql = fmt.Sprintf(sql, "and task.state = 3", "%s")
|
|
|
+ } else if isJoined == "" {
|
|
|
+ sql = fmt.Sprintf(sql, "%s", "")
|
|
|
+ }
|
|
|
+
|
|
|
+ if softwareId != "" {
|
|
|
+ sql = fmt.Sprintf(sql, "and software_id = ?")
|
|
|
+ db.Raw(sql, executorId, softwareId).Find(&res)
|
|
|
+ } else {
|
|
|
+ sql = fmt.Sprintf(sql, "")
|
|
|
+ db.Raw(sql, executorId).Find(&res)
|
|
|
+ }
|
|
|
+
|
|
|
+ type UserResult struct {
|
|
|
+ UserName string `gorm:"column:username"`
|
|
|
+ }
|
|
|
+ for i, v := range res {
|
|
|
+ var creator UserResult
|
|
|
+ var worker UserResult
|
|
|
+ db.Model(&model.User{}).Where("id = ?", v.CreatorId).First(&creator)
|
|
|
+ res[i].Creator = creator.UserName
|
|
|
+ db.Model(&model.User{}).Where("id = ?", v.WorkerId).First(&worker)
|
|
|
+ res[i].Worker = worker.UserName
|
|
|
+ if v.State != 3 {
|
|
|
+ res[i].IsJoined = true
|
|
|
+ }
|
|
|
+ var software model.Software
|
|
|
+ db.Model(&model.Software{}).Where("id = ?", v.SoftwareId).First(&software)
|
|
|
+ res[i].SoftwareName = software.Name
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{"taskList": res}, "success")
|
|
|
+}
|