This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,4 @@
package process
type ProcessApi struct {
}

47
api/app/process/req.go Normal file
View File

@ -0,0 +1,47 @@
package process
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// 新增进度
type CreateProcessReq struct {
g.Meta `path:"/process/create" method:"post" tags:"APP(里程碑进度上报)" summary:"新增里程碑进度"`
Stage string `json:"stage" v:"required" dc:"上传阶段名称"`
ProjectId int64 `json:"projectId" v:"required#该用户暂未绑定项目" dc:"项目ID"`
Percentage int `json:"percentage" dc:"完成情况1已完成 0未完成"`
Notes string `json:"notes" dc:"备注"`
CompleteTime gtime.Time `json:"completeTime" dc:"完成时间"`
}
// 获取进度列表
type ProcessListReq struct {
g.Meta `path:"/process/list" method:"get" tags:"APP(里程碑进度上报)" summary:"获取里程碑进度列表"`
ProjectId int64 `json:"projectId" v:"required" dc:"项目ID"`
Page int `json:"page" v:"required" dc:"页码"`
PageSize int `json:"pageSize" v:"required" dc:"每页大小"`
}
// 更新进度信息
type UpdateProcessReq struct {
g.Meta `path:"/process/update" method:"put" tags:"APP(里程碑进度上报)" summary:"更新里程碑进度信息"`
ProcessID int64 `json:"processId" v:"required" dc:"进度ID"`
Stage string `json:"stage" v:"required" dc:"上传阶段名称"`
ProjectId int64 `json:"projectId" v:"required" dc:"项目ID"`
Percentage int `json:"percentage" dc:"完成情况1已完成 0未完成"`
Notes string `json:"notes" dc:"备注"`
CompleteTime gtime.Time `json:"completeTime" dc:"完成时间"`
}
// 删除进度
type DeleteProcessReq struct {
g.Meta `path:"/process/delete" method:"delete" tags:"APP(里程碑进度上报)" summary:"删除里程碑进度"`
ProcessID int64 `json:"processId" v:"required" dc:"进度ID"`
}
// 获取详情
type ProcessDetailReq struct {
g.Meta `path:"/process/detail" method:"delete" tags:"APP(里程碑进度上报)" summary:"获取里程碑进度详情"`
ProcessID int64 `json:"processId" v:"required" dc:"进度ID"`
}

56
api/app/process/res.go Normal file
View File

@ -0,0 +1,56 @@
package process
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"time"
)
// 新增进度
type CreateProcessRes struct {
}
// 获取列表
type ProcessListRes struct {
g.Meta `mime:"application/json"`
Processes []ProcessVo `json:"processes"`
}
// Process 表的结构体定义
type Process struct {
g.Meta `mime:"application/json"`
ProcessID int64 `json:"processId" dc:"主键ID"`
ProjectId int64 `json:"projectId" dc:"项目ID"`
Stage string `json:"stage" dc:"阶段"`
Percentage int `json:"percentage" dc:"进度"`
Notes string `json:"notes" dc:"备注"`
CreatedAt time.Time `json:"createdAt" dc:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" dc:"更新时间"`
CompleteTime gtime.Time `json:"completeTime" dc:"完成时间"`
CreatedBy int `json:"createdBy" dc:"录入人"`
}
// Process 表的结构体定义
type ProcessVo struct {
g.Meta `mime:"application/json"`
ProcessID int64 `json:"processId" dc:"主键ID"`
ProjectId int64 `json:"projectId" dc:"项目ID"`
Stage string `json:"stage" dc:"阶段"`
Percentage int `json:"percentage" dc:"进度"`
Notes string `json:"notes" dc:"备注"`
CreatedAt time.Time `json:"createdAt" dc:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" dc:"更新时间"`
CompleteTime gtime.Time `json:"completeTime" dc:"完成时间"`
CreatedBy int `json:"createdBy" dc:"录入人ID"`
CreatedByName string `json:"createdByName" dc:"录入人姓名"`
}
type UpdateProcessRes struct {
}
type DeleteProcessRes struct {
}
type ProcessDetailRes struct {
ProcessInfo ProcessVo `json:"processInfo"`
}

View File

@ -0,0 +1,74 @@
package process
import (
"context"
"github.com/gogf/gf/v2/frame/g"
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
)
func (p ProcessApi) CreateProcess(ctx context.Context, req *CreateProcessReq) (res *CreateProcessRes, err error) {
res = new(CreateProcessRes)
// 获取当前登陆用户的ID
userID := ct.New().GetUserId(ctx)
param := g.Map{
"stage": req.Stage,
"project_id": req.ProjectId,
"percentage": req.Percentage,
"complete_time": req.CompleteTime,
"notes": req.Notes,
"created_by": userID,
}
// 插入数据
_, err = g.Model("process").Ctx(ctx).Insert(param)
if err != nil {
return nil, err
}
return res, nil
}
// 根据项目列表查询里程碑数据
func (p ProcessApi) GetProcessList(ctx context.Context, req *ProcessListReq) (res *ProcessListRes, err error) {
res = new(ProcessListRes)
err = g.Model("process").Ctx(ctx).Fields("process.*,sys_user.user_nickname AS createdByName").
LeftJoin("sys_user on sys_user.id = process.created_by").
Where("project_id = ?", req.ProjectId).Page(req.Page, req.PageSize).Scan(&res.Processes)
if err != nil {
return nil, err
}
return res, nil
}
func (p ProcessApi) UpdateProcess(ctx context.Context, req *UpdateProcessReq) (res *UpdateProcessRes, err error) {
res = new(UpdateProcessRes)
_, err = g.Model("process").Ctx(ctx).Data(g.Map{
"stage": req.Stage,
"project_id": req.ProjectId,
"percentage": req.Percentage,
"complete_time": req.CompleteTime,
"notes": req.Notes,
}).Where("process_id = ?", req.ProcessID).Update()
if err != nil {
return nil, err
}
return res, nil
}
func (p ProcessApi) DeleteProcess(ctx context.Context, req *DeleteProcessReq) (res *DeleteProcessRes, err error) {
res = new(DeleteProcessRes)
_, err = g.Model("process").Ctx(ctx).Where("process_id", req.ProcessID).Delete()
if err != nil {
return nil, err
}
return res, nil
}
func (p ProcessApi) ProcessDetail(ctx context.Context, req *ProcessDetailReq) (res *ProcessDetailRes, err error) {
res = new(ProcessDetailRes)
g.Model("process").Ctx(ctx).Fields("process.*,sys_user.user_nickname AS createdByName").
InnerJoin("sys_user on sys_user.id = process.created_by").
Scan(&res.ProcessInfo)
if err != nil {
return nil, err
}
return res, nil
}

View File

@ -0,0 +1,4 @@
package project
type Project struct {
}

44
api/app/project/req.go Normal file
View File

@ -0,0 +1,44 @@
package project
import "github.com/gogf/gf/v2/frame/g"
// 查询所有项目列表数据
type ProjectIndexModuleReq struct {
g.Meta `path:"index" method:"get" tags:"APP(项目相关)" summary:"项目列表数据【首页列表】"`
ProjectName string `json:"projectName" dc:"模糊搜索项目名"`
PageNum int `json:"pageNum" dc:"页码" v:"required"`
PageSize int `json:"pageSize" dc:"每页数量" v:"required"`
}
// 根据项目ID查询详情【基础数据】
type ProjectIndexModuleDetailReq struct {
g.Meta `path:"base" method:"get" tags:"APP(项目相关)" summary:"项目详情数据【基础数据】"`
ProjectId string `json:"projectId" v:"required" dc:"项目ID"`
}
// 根据项目ID查询详情【项目计划】
type ProjectPlanDetailReq struct {
g.Meta `path:"plan" method:"get" tags:"APP(项目相关)" summary:"项目详情数据【项目计划】"`
ProjectId string `json:"projectId" v:"required" dc:"项目ID"`
}
// 根据项目ID查询详情【视频监控】
type ProjectVideoDetailReq struct {
g.Meta `path:"video" method:"get" tags:"APP(项目相关)" summary:"项目详情数据【视频监控】"`
ProjectId string `json:"projectId" v:"required" dc:"项目ID"`
}
// 根据项目ID查询详情【施工日志】
type ProjectLogReq struct {
g.Meta `path:"log" method:"get" tags:"APP(项目相关)" summary:"项目详情数据【施工日志】"`
ProjectId int64 `json:"projectId" v:"required" dc:"项目ID"`
}
// 根据项目ID查询详情【计划详情】
type ProjectPlanDetailStatusReq struct {
g.Meta `path:"/planDetail" tags:"APP(项目相关)" method:"get" summary:"项目详情数据【计划详情】"`
ProjectID int `json:"projectId"`
Status int `json:"status" dc:"任务状态 0:待开始 1:进行中 2:已完成 3:滞后"`
PageNum int `json:"pageNum" dc:"页码" v:"required"`
PageSize int `json:"pageSize" dc:"每页数量" v:"required"`
}

126
api/app/project/res.go Normal file
View File

@ -0,0 +1,126 @@
package project
import (
"time"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/v1/common"
)
// 项目列表响应数据
type ProjectListRes struct {
ProjectTotal int `json:"projectTotal"` // 项目总数
BuildProject int `json:"buildProject"` // 在建项目数量
ProjectCapacity int `json:"projectCapacity"` // 项目容量
ProjectListModels []ProjectListModel `json:"projectListModels"` // 列表数据
}
type ProjectListModel struct {
ProjectID int `json:"projectId"` // 项目ID
ProjectName string `json:"projectName"` // 项目名称
ProductionDays int `json:"productionDays"` // 安全生产天数
Status string `json:"status"` // 项目状态
TotalQuantity int `json:"totalQuantity"` // 总数量
CompletedQuantity int `json:"completedQuantity"` // 已完成数量
ProjectLeader string `json:"projectLeader"` // 项目负责人
OnStreamTime string `json:"onStreamTime"` // 开工时间
}
// 项目详情响应数据【基础数据部分】
type ProjectDetailModelRes struct {
ProjectID int `json:"projectId"` // 项目ID
ProjectName string `json:"projectName"` // 项目名称
ProjectLeader string `json:"projectLeader"` // 项目负责人
OnStreamTime string `json:"onStreamTime"` // 开工时间(计划开工)
ProductionDays int `json:"productionDays"` // 安全生产天数
TotalQuantity int `json:"totalQuantity"` // 总数量
CompletedQuantity int `json:"completedQuantity"` // 已完成数量
}
// 项目详情响应数据【项目计划】
type ProjectPlanDetailRes struct {
ProjectPlan
}
type ProjectPlan struct {
PendingPlan int `json:"pendingTasks"` // 待开始计划
ProcessingPlan int `json:"processingTasks"` // 进行中计划
CompletedPlan int `json:"completedTasks"` // 已完成计划
DeferredPlan int `json:"deferredTasks"` // 滞后计划
}
type ProjectPlanDetailStatusRes struct {
g.Meta `mime:"application/json"`
common.ListRes
List []SchduleList `json:"list"`
}
// SchduleList 计划详情
type SchduleList struct {
// 工作名称
WorkName string `json:"work_name"`
// 计划数量
PlanNum int `json:"plan_num"`
// 实际完成数量
FinishedNum int `json:"finished_num"`
// 开始时间
StartTime string `json:"start_at"`
// 结束时间
EndTime string `json:"end_at"`
// 工日
WorkDay int `json:"work_day"`
// 工作量百分比
WorkPercent int `json:"work_percent"`
// 负责人
Leader string `json:"principal"`
}
// 项目详情响应数据【视频监控】
type ProjectVideoDetailRes struct {
YS7Devices []YS7Device
}
type YS7Device struct {
ID int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
DeviceSerial string `json:"deviceSerial"`
DeviceName string `json:"deviceName"`
DeviceType string `json:"deviceType"`
Status int `json:"status"`
Defence int `json:"defence"`
DeviceVersion string `json:"deviceVersion"`
ProjectID string `json:"projectId"`
Detail string `json:"detail"`
Position string `json:"position"`
Remark string `json:"remark"`
VideoEncrypted int `json:"videoEncrypted"`
}
// 项目详情响应数据【施工日志】
type ProjectLogRes struct {
Logs []ConstructionLog `json:"logs"`
}
type ConstructionLog struct {
ID int64 `json:"id"`
DateOfOccurrence string `json:"dateOfOccurrence"`
Condition string `json:"condition"`
TechnologyQuality string `json:"technologyQuality"`
Remark string `json:"remark"`
Path string `json:"path"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
}
type VisualProgress struct {
Id int64 `json:"id" dc:"主键"`
ProjectID int64 `json:"projectId" dc:"项目ID"`
ProjectName string `json:"projectName" dc:"项目名称"`
ReporterID int64 `json:"reporterId" dc:"上报人ID"`
ReporterName string `json:"reporterName" dc:"上报人名字"`
ReportTime time.Time `json:"reportTime" dc:"上报时间"`
Title string `json:"title" dc:"形象标题"`
ProgressDesc string `json:"progressDesc" dc:"进度描述"`
AttachmentURL string `json:"attachmentUrl" dc:"附件URL"`
}

279
api/app/project/service.go Normal file
View File

@ -0,0 +1,279 @@
package project
import (
"context"
"fmt"
"time"
"github.com/gogf/gf/v2/frame/g"
"github.com/jinzhu/copier"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
)
// 项目首页信息列表
func (p Project) ProjectIndex(ctx context.Context, req *ProjectIndexModuleReq) (res *ProjectListRes, err error) {
res = new(ProjectListRes)
// 查询所有项目总数
count, err := g.Model("sys_project").Ctx(ctx).Count()
if err != nil {
return nil, err
}
res.ProjectTotal = count
// 查询所有项目的总容量之和
var capacity struct{ ProjectCapacity int }
err = g.Model("sys_project").Fields("SUM(actual) AS ProjectCapacity").Ctx(ctx).Scan(&capacity)
if err != nil {
return nil, err
}
res.ProjectCapacity = capacity.ProjectCapacity
// 分页查询大项目基础信息,然后遍历信息去补全其他的数据
var projects []struct {
ProjectID int `json:"projectId"`
ProjectName string `json:"projectName"`
ProjectLeader string `json:"projectLeader"`
OnStreamTime string `json:"onStreamTime"`
}
// 构建查询模型
query := g.Model("sys_project").Ctx(ctx).
Fields("id AS ProjectID, project_name AS ProjectName, on_stream_time AS OnStreamTime, principal AS ProjectLeader")
if req.ProjectName != "" {
query = query.Where("project_name LIKE ?", "%"+req.ProjectName+"%")
}
err = query.Scan(&projects)
if err != nil {
return nil, err
}
buildProjectCount := 0 // 初始化在建项目数量计数器
for _, project := range projects {
// 初始化列表模型
projectModel := ProjectListModel{
ProjectID: project.ProjectID,
ProjectName: project.ProjectName,
ProjectLeader: project.ProjectLeader,
OnStreamTime: project.OnStreamTime,
}
// 首先将字符串转换为 JSON
onStreamTime, err := time.Parse("2006-01-02", project.OnStreamTime)
if err != nil {
return nil, err
}
// 检查该项目的所有子项目是否均有完成时间
subProjectCount, err := g.Model("sub_project").Ctx(ctx).Where("project_id = ? AND done_time IS NOT NULL", project.ProjectID).Count()
totalSubProjects, err := g.Model("sub_project").Ctx(ctx).Where("project_id = ?", project.ProjectID).Count()
if err != nil {
return nil, err
}
// 如果所有子项目的完成时间都不为空则设置为竣工
if subProjectCount == totalSubProjects && totalSubProjects != 0 {
var latestDoneTimeString string
// 查询子项目最后完成的任务的时间
err = g.Model("sub_project").Ctx(ctx).
Fields("MAX(done_time)").
Where("project_id = ?", project.ProjectID).
Scan(&latestDoneTimeString)
if err != nil {
return nil, err
}
latestDoneTime, err := time.Parse("2006-01-02", latestDoneTimeString)
if err != nil {
return nil, err
}
// 安全生产天数等于最后任务的完成时间减去项目的开始时间
projectModel.ProductionDays = int(latestDoneTime.Unix()-onStreamTime.Unix()) / 86400
projectModel.Status = "竣工"
} else {
// 安全生产天数等于当前的时间减去项目的开始时间
projectModel.ProductionDays = int(time.Now().Unix()-onStreamTime.Unix()) / 86400
projectModel.Status = "在建"
buildProjectCount++ // 累加在建项目数量
}
// 查询相关工作计划的总量与完成量
var work struct {
TotalQuantity int `json:"totalQuantity"`
CompletedQuantity int `json:"completedQuantity"`
}
err = g.Model("work_schedule").Ctx(ctx).
Fields("SUM(plan_num) AS totalQuantity, SUM(finished_num) AS completedQuantity").
Where("project_id = ?", project.ProjectID).
Scan(&work)
if err != nil {
return nil, err
}
projectModel.TotalQuantity = work.TotalQuantity
projectModel.CompletedQuantity = work.CompletedQuantity
// 添加到结果列表中
res.ProjectListModels = append(res.ProjectListModels, projectModel)
}
// 设置在建项目数量
res.BuildProject = buildProjectCount
return res, nil
}
// 根据项目ID查询详情【基础数据】
func (p Project) ProjectDetail(ctx context.Context, req *ProjectIndexModuleDetailReq) (res *ProjectDetailModelRes, err error) {
res = new(ProjectDetailModelRes)
// 初始化查询模型,用于获取项目的基础信息
var project struct {
ProjectID int `db:"ProjectID"`
ProjectName string `db:"ProjectName"`
ProjectLeader string `db:"ProjectLeader"`
OnStreamTime string `db:"OnStreamTime"`
}
err = g.Model("sys_project").Ctx(ctx).
Fields("id AS ProjectID, project_name AS ProjectName, principal AS ProjectLeader, on_stream_time AS OnStreamTime").
Where("id = ?", req.ProjectId).
Scan(&project)
if err != nil {
return nil, err
}
// 将基本信息设置到响应结构体中
res.ProjectID = project.ProjectID
res.ProjectName = project.ProjectName
res.ProjectLeader = project.ProjectLeader
res.OnStreamTime = project.OnStreamTime
// 计算安全生产天数
onStreamDate, err := time.Parse("2006-01-02", project.OnStreamTime)
if err != nil {
return nil, err
}
res.ProductionDays = int(time.Since(onStreamDate).Hours() / 24) // 将时间差转换为天数
// 获取总数量和已完成数量
var quantities struct {
TotalQuantity int `db:"TotalQuantity"`
CompletedQuantity int `db:"CompletedQuantity"`
}
err = g.Model("work_schedule").Ctx(ctx).
Fields("SUM(plan_num) AS TotalQuantity, SUM(finished_num) AS CompletedQuantity").
Where("project_id = ?", project.ProjectID).
Scan(&quantities)
if err != nil {
return nil, err
}
res.TotalQuantity = quantities.TotalQuantity
res.CompletedQuantity = quantities.CompletedQuantity
return res, nil
}
// 根据项目ID查询详情【项目计划】
func (p Project) ProjectPlanDetail(ctx context.Context, req *ProjectPlanDetailReq) (res *ProjectPlanDetailRes, err error) {
res = new(ProjectPlanDetailRes)
// 使用结构体来接收查询结果
var planCounts struct {
PendingPlan int `db:"PendingPlan"` // 待开始
ProcessingPlan int `db:"ProcessingPlan"` // 进行中
CompletedPlan int `db:"CompletedPlan"` // 已完成
DeferredPlan int `db:"DeferredPlan"` // 滞后
}
// 构建查询语句以聚合不同状态的计划数量
err = g.Model("work_schedule").Ctx(ctx).
Fields(
"SUM(case when status = 0 then 1 else 0 end) AS PendingPlan",
"SUM(case when status = 1 then 1 else 0 end) AS ProcessingPlan",
"SUM(case when status = 2 then 1 else 0 end) AS CompletedPlan",
"SUM(case when status = 3 then 1 else 0 end) AS DeferredPlan",
).
Where("project_id = ?", req.ProjectId).
Scan(&planCounts)
if err != nil {
return nil, err
}
// 将查询结果映射到响应结构体中
res.ProjectPlan = ProjectPlan{
PendingPlan: planCounts.PendingPlan,
ProcessingPlan: planCounts.ProcessingPlan,
CompletedPlan: planCounts.CompletedPlan,
DeferredPlan: planCounts.DeferredPlan,
}
return res, nil
}
// 根据项目ID查询详情【项目计划详情】
func (p Project) ProjectPlanDetailStatus(ctx context.Context, req *ProjectPlanDetailStatusReq) (res *ProjectPlanDetailStatusRes, err error) {
res = new(ProjectPlanDetailStatusRes)
list := []model.SchduleDetail{}
m := dao.WorkSchedule.Ctx(ctx).As("wc").
LeftJoin("work_status as ws", "wc.work_id = ws.work_id").
LeftJoin("sys_project as sp", "wc.project_id = sp.id").
Where("wc.status = ? AND wc.project_id = ?", req.Status, req.ProjectID)
res.Total, err = m.Count()
if err != nil {
return nil, fmt.Errorf("failed to count: %w", err)
}
res.CurrentPage = req.PageNum
// 查询工作计划详情
m = m.Fields("ws.work_name,wc.plan_num,wc.finished_num,wc.start_at,wc.end_at,sp.principal")
err = m.Page(req.PageNum, req.PageSize).Scan(&list)
if err != nil {
return nil, fmt.Errorf("failed to fetch page: %w", err)
}
res.List = make([]SchduleList, 0, len(list))
copier.Copy(&res.List, &list)
return res, nil
}
// 根据项目ID查询详情【视频监控】
func (p Project) ProjectVideoDetail(ctx context.Context, req *ProjectVideoDetailReq) (res *ProjectVideoDetailRes, err error) {
res = new(ProjectVideoDetailRes)
err = g.Model("ys7devices").Ctx(ctx).
Fields(
"id AS ID, created_at AS CreatedAt, DeviceSerial, DeviceName, DeviceType, Status, Defence, DeviceVersion, ProjectId, Detail, Position, Remark, VideoEncrypted").
Where("ProjectId = ?", req.ProjectId).
Order("CreatedAt DESC").
Scan(&res.YS7Devices)
if err != nil {
return nil, err
}
return res, nil
}
// 根据项目ID查询详情【施工日志】
func (p Project) GetConstructionLogs(ctx context.Context, req *ProjectLogReq) (res *ProjectLogRes, err error) {
res = new(ProjectLogRes)
err = g.Model("bus_construction_log").Ctx(ctx).
Fields(
"id, date_of_occurrence, condition, technology_quality, remark, path, created_by, updated_by, created_at, updated_at, deleted_at").
Where("project_id = ? AND deleted_at IS NULL", req.ProjectId).
Order("date_of_occurrence DESC").
Scan(&res.Logs)
if err != nil {
return nil, err
}
return res, nil
}

31
api/app/stage/req.go Normal file
View File

@ -0,0 +1,31 @@
package stage
import (
"github.com/gogf/gf/v2/frame/g"
)
// 新增阶段
type CreateStageReq struct {
g.Meta `path:"/stage/create" method:"post" tags:"APP(上报阶段)" summary:"创建新阶段"`
StageName string `json:"stageName" dc:"阶段名称"`
}
// 获取阶段列表
type StageListReq struct {
g.Meta `path:"/stage/list" method:"get" tags:"APP(上报阶段)" summary:"获取阶段列表"`
Page int `json:"page" dc:"页码"`
PageSize int `json:"pageSize" dc:"大小"`
}
// 更新阶段信息
type UpdateStageReq struct {
g.Meta `path:"/stage/update" method:"put" tags:"APP(上报阶段)" summary:"更新阶段信息"`
StageID int64 `json:"stageId" dc:"阶段ID"`
StageName string `json:"stageName" dc:"阶段名称"`
}
// 删除阶段
type DeleteStageReq struct {
g.Meta `path:"/stage/delete" method:"delete" tags:"APP(上报阶段)" summary:"删除阶段"`
StageID int64 `json:"stageId" dc:"阶段ID"`
}

24
api/app/stage/res.go Normal file
View File

@ -0,0 +1,24 @@
package stage
import "time"
type CreateStageRes struct {
}
type StageListRes struct {
Stages []Stage `json:"stages"`
}
// Stage 表的结构体定义
type Stage struct {
StageID int64 `json:"stageId" gorm:"primary_key"`
StageName string `json:"stageName" dc:"阶段名称"`
CreatedAt time.Time `json:"createdAt" dc:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" dc:"更新时间"`
}
type UpdateStageRes struct {
}
type DeleteStageRes struct {
}

52
api/app/stage/service.go Normal file
View File

@ -0,0 +1,52 @@
package stage
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"time"
)
// 创建阶段
func (s StageApi) CreateStage(ctx context.Context, req *CreateStageReq) (res *CreateStageRes, err error) {
res = new(CreateStageRes)
stage := Stage{
StageName: req.StageName,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
_, err = g.Model("stage").Ctx(ctx).Insert(&stage)
if err != nil {
return nil, err
}
return res, nil
}
func (s StageApi) GetStageList(ctx context.Context, req *StageListReq) (res *StageListRes, err error) {
res = new(StageListRes)
err = g.Model("stage").Ctx(ctx).Page(req.Page, req.PageSize).Scan(&res.Stages)
if err != nil {
return nil, err
}
return res, nil
}
func (s StageApi) UpdateStage(ctx context.Context, req *UpdateStageReq) (res *UpdateStageRes, err error) {
res = new(UpdateStageRes)
_, err = g.Model("stage").Ctx(ctx).Data(g.Map{
"stage_name": req.StageName,
"updated_at": time.Now(),
}).Where("stage_id", req.StageID).Update()
if err != nil {
return nil, err
}
return res, nil
}
func (s StageApi) DeleteStage(ctx context.Context, req *DeleteStageReq) (res *DeleteStageRes, err error) {
res = new(DeleteStageRes)
_, err = g.Model("stage").Ctx(ctx).Where("stage_id", req.StageID).Delete()
if err != nil {
return nil, err
}
return res, nil
}

4
api/app/stage/stage.go Normal file
View File

@ -0,0 +1,4 @@
package stage
type StageApi struct {
}

48
api/app/visual/req.go Normal file
View File

@ -0,0 +1,48 @@
package visual
import (
"github.com/gogf/gf/v2/frame/g"
)
// 新增形象进度
type CreateVisualProgressReq struct {
g.Meta `path:"/visual/create" method:"post" tags:"APP(形象进度相关)" summary:"新增形象进度"`
ProjectID int64 `json:"projectId" v:"required" dc:"项目ID"`
ReporterID int64 `json:"reporterId" v:"required" dc:"上报人ID"`
ReportTime string `json:"reportTime" v:"required" dc:"上报时间"`
Title string `json:"title" v:"required" dc:"形象标题"`
ProgressDesc string `json:"progressDesc" v:"required" dc:"进度描述"`
AttachmentURL string `json:"attachmentUrl" dc:"附件URL"`
}
// 根据项目ID查询形象进度列表
type ReadVisualProgressReq struct {
g.Meta `path:"/visual/list" method:"get" tags:"APP(形象进度相关)" summary:"查询指定项目的形象进度列表"`
ProjectID int64 `json:"projectId" v:"required" dc:"项目ID"`
Page int64 `json:"page" dc:"请求的页码" v:"required"`
PageSize int64 `json:"pageSize" dc:"每页显示的条目数" v:"required"`
Title string `json:"title" dc:"模糊搜索字段"`
}
// 更新形象进度
type UpdateVisualProgressReq struct {
g.Meta `path:"/visual/update" method:"post" tags:"APP(形象进度相关)" summary:"更新项目进度"`
ID int64 `json:"id" v:"required" dc:"记录ID"`
ProjectID int64 `json:"projectId" dc:"项目ID"`
ReporterID int64 `json:"reporterId" dc:"上报人ID"`
Title string `json:"title" dc:"形象标题"`
ProgressDesc string `json:"progressDesc" dc:"进度描述"`
AttachmentURL string `json:"attachmentUrl" dc:"附件URL"`
}
// 删除形象进度
type DeleteVisualProgressReq struct {
g.Meta `path:"/visual/delete" method:"delete" tags:"APP(形象进度相关)" summary:"删除项目进度"`
ID int64 `json:"id" v:"required" dc:"形象进度ID"`
}
// 根据ID查询形象进度详情
type GetVisualProgressDetailReq struct {
g.Meta `path:"/visual/detail" method:"get" tags:"APP(形象进度相关)" summary:"根据形象进度ID查询详情"`
ID int64 `json:"id" v:"required" dc:"形象进度ID"`
}

36
api/app/visual/res.go Normal file
View File

@ -0,0 +1,36 @@
package visual
// 新增形象进度
type CreateVisualProgressRes struct{}
// 形象进度列表
type ReadVisualProgressRes struct {
ProgressList []VisualProgress `json:"progressList"`
Total int64 `json:"total"`
}
type VisualProgress struct {
Id int64 `json:"id" dc:"主键"`
ProjectID int64 `json:"projectId" dc:"项目ID"`
ProjectName string `json:"projectName" dc:"项目名称"`
ReporterID int64 `json:"reporterId" dc:"上报人ID"`
ReporterName string `json:"reporterName" dc:"上报人名字"`
ReportTime string `json:"reportTime" dc:"上报时间"`
Title string `json:"title" dc:"形象标题"`
ProgressDesc string `json:"progressDesc" dc:"进度描述"`
AttachmentURL string `json:"attachmentUrl" dc:"附件URL"`
}
// 更新形象进度
type UpdateVisualProgressRes struct{}
// 删除形象进度
type DeleteVisualProgressRes struct{}
// 根据ID查询形象进度详情
type GetVisualProgressDetailRes struct {
Detail VisualProgressDetail `json:"visualProgressDetail"`
}
type VisualProgressDetail struct {
VisualProgress
}

13
api/app/visual/router.go Normal file
View File

@ -0,0 +1,13 @@
package visual
import "github.com/gogf/gf/v2/net/ghttp"
// 形象进度API
func InitAppProjectAPI(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareCORS)
group.Group("/visual", func(group *ghttp.RouterGroup) {
group.Group("/api/v1", func(group *ghttp.RouterGroup) {
group.Bind(new(Visual))
})
})
}

96
api/app/visual/service.go Normal file
View File

@ -0,0 +1,96 @@
package visual
import (
"context"
"github.com/gogf/gf/v2/frame/g"
)
// 新增形象进度
func (v Visual) CreateVisualProgress(ctx context.Context, req *CreateVisualProgressReq) (res *CreateVisualProgressRes, err error) {
res = &CreateVisualProgressRes{}
_, err = g.Model("visual_progress").Ctx(ctx).Data(g.Map{
"project_id": req.ProjectID,
"reporter_id": req.ReporterID,
"report_time": req.ReportTime,
"title": req.Title,
"progress_desc": req.ProgressDesc,
"attachment_url": req.AttachmentURL,
}).Insert()
if err != nil {
return nil, err
}
return res, nil
}
// 形象进度列表
func (v Visual) GetVisualProgress(ctx context.Context, req *ReadVisualProgressReq) (res *ReadVisualProgressRes, err error) {
res = &ReadVisualProgressRes{}
offset := (req.Page - 1) * req.PageSize
count, err := g.Model("visual_progress").Ctx(ctx).Count()
if err != nil {
return nil, err
}
err = g.Model("visual_progress").Ctx(ctx).
Fields("sys_project.id, sys_project.project_name, user.user_nickname AS reporterName, visual_progress.*").
// 连表查询项目ID、项目名称
LeftJoin("sys_project on visual_progress.project_id = sys_project.id").
LeftJoin("sys_user AS user on user.id = visual_progress.reporter_id").
Where("visual_progress.project_id = ?", req.ProjectID).
Where("visual_progress.title LIKE ?", "%"+req.Title+"%").
Offset(int(offset)).Limit(int(req.PageSize)).
Order("visual_progress.report_time DESC").
Scan(&res.ProgressList)
if err != nil {
return nil, err
}
res.Total = int64(count)
return res, nil
}
// 更新形象进度
func (v Visual) UpdateVisualProgress(ctx context.Context, req *UpdateVisualProgressReq) (res *UpdateVisualProgressRes, err error) {
res = &UpdateVisualProgressRes{}
_, err = g.Model("visual_progress").Ctx(ctx).Data(g.Map{
"project_id": req.ProjectID,
"reporter_id": req.ReporterID,
"title": req.Title,
"progress_desc": req.ProgressDesc,
"attachment_url": req.AttachmentURL,
}).Where("id", req.ID).Update()
if err != nil {
return nil, err
}
return res, nil
}
// 删除形象进度
func (v Visual) DeleteVisualProgress(ctx context.Context, req *DeleteVisualProgressReq) (res *DeleteVisualProgressRes, err error) {
res = &DeleteVisualProgressRes{}
// 删除之前调用一个方法获取当前登录用户的ID如果是自己才可以删除
_, err = g.Model("visual_progress").Ctx(ctx).Where("id", req.ID).Delete()
if err != nil {
return nil, err
}
return res, nil
}
// 根据ID查询形象进度详情
func (v Visual) GetVisualProgressDetail(ctx context.Context, req *GetVisualProgressDetailReq) (res *GetVisualProgressDetailRes, err error) {
res = &GetVisualProgressDetailRes{}
// 查询项目基本信息
err = g.Model("visual_progress").Ctx(ctx).
Fields("sys_project.id, sys_project.project_name, user.user_nickname AS reporterName, visual_progress.*").
// 连表查询项目ID、项目名称
InnerJoin("sys_project on visual_progress.project_id = sys_project.id").
// 连表查询上报人名字(暂未确定是哪张用户表,需要联查)
InnerJoin("sys_user AS user on user.id = visual_progress.reporter_id").
Where("visual_progress.id = ?", req.ID).
Scan(&res.Detail)
// 查询备注列表信息
if err != nil {
return nil, err
}
return res, nil
}

4
api/app/visual/visual.go Normal file
View File

@ -0,0 +1,4 @@
package visual
type Visual struct {
}

View File

@ -0,0 +1,38 @@
package visual_remark
import "github.com/gogf/gf/v2/frame/g"
// 新增形象进度评论
type CreateRemarkReq struct {
g.Meta `path:"/remark/create" method:"post" tags:"APP(形象进度评论相关)" summary:"新增形象进度评论"`
VisualProgressID int `json:"visualProgressId" v:"required" dc:"形象进度ID"`
Comment string `json:"comment" v:"required" dc:"评论的内容"`
UserID int `json:"userId" v:"required" dc:"评论的用户ID"`
}
// 查看某个形象进度的评论列表
type ListRemarksReq struct {
g.Meta `path:"/remark/list" method:"get" tags:"APP(形象进度评论相关)" summary:"查看某个形象进度的评论列表"`
VisualID int64 `json:"visualID" v:"required" dc:"形象进度ID"`
}
// 获取形象进度评论详细信息
type GetRemarkDetailReq struct {
g.Meta `path:"/remark/detail" method:"get" tags:"APP(形象进度评论相关)" summary:"获取形象进度评论详细信息"`
ID int64 `json:"id" v:"required" dc:"备注ID"`
}
// 更新形象进度评论
type UpdateRemarkReq struct {
g.Meta `path:"/remark/update" method:"post" tags:"APP(形象进度评论相关)" summary:"更新形象进度评论"`
ID int `json:"id" v:"required" dc:"主键ID"`
VisualProgressID int `json:"visualProgressId" dc:"形象进度ID"`
Comment string `json:"comment" dc:"评论的内容"`
UserID int `json:"userId" dc:"评论的用户ID"`
}
// 删除形象进度评论
type DeleteRemarkReq struct {
g.Meta `path:"/remark/delete" method:"delete" tags:"APP(形象进度评论相关)" summary:"删除形象进度评论"`
ID int `json:"id" v:"required" dc:"主键ID"`
}

View File

@ -0,0 +1,31 @@
package visual_remark
// 查看某个形象进度的评论列表
type ListRemarksRes struct {
VisualProgressRemarks []VisualProgressRemark `json:"visualProgressRemarks"`
}
type VisualProgressRemark struct {
ID int `json:"id"`
Username string `json:"username"`
Avatar string `json:"avatar"`
VisualProgressID int `json:"visualProgressId"`
VisualProgressTitle string `json:"visualProgressTitle"`
Comment string `json:"comment"`
UserID int `json:"userId"`
CreatedAt string `json:"createdAt"`
}
// 查看形象进度评论详细信息
type GetRemarkDetailRes struct {
VisualProgressRemark
}
// 新增形象进度评论
type CreateRemarkRes struct{}
// 更新形象进度评论
type UpdateRemarkRes struct{}
// 删除形象进度评论
type DeleteRemarkRes struct{}

View File

@ -0,0 +1,115 @@
package visual_remark
import (
"context"
"errors"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/v1/system"
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
// 列表请求
func (v VisualRemark) ListRemarks(ctx context.Context, req *ListRemarksReq) (res *ListRemarksRes, err error) {
res = &ListRemarksRes{}
err = g.Model("visual_progress_remark AS remark").Ctx(ctx).
Fields("remark.*,visual.title AS visualProgressTitle, user.user_nickname AS Username, cuser.head_icon AS Avatar").
// 连表查询形象进度表得到形象进度标题
LeftJoin("visual_progress AS visual", "visual.id = remark.visual_progress_id").
// 连表查询评论人的名字(暂未确定是哪张用户表,需要联查)
LeftJoin("sys_user AS user on user.id = remark.user_id").
// 头像需要从另外一张表查询出来
LeftJoin("bus_construction_user AS cuser on cuser.phone = user.mobile").
Where("visual.id = ? AND cuser.deleted_at is null", req.VisualID).
Scan(&res.VisualProgressRemarks)
g.Dump(res.VisualProgressRemarks)
if err != nil {
return nil, err
}
return res, nil
}
// 获取详情
func (v VisualRemark) GetRemarkDetail(ctx context.Context, req *GetRemarkDetailReq) (res *GetRemarkDetailRes, err error) {
res = &GetRemarkDetailRes{}
err = g.Model("visual_progress_remark AS remark").Ctx(ctx).
Fields("remark.*,visual.title AS visualProgressTitle, user.user_nickname AS Username, user.avatar AS Avatar").
// 连表查询形象进度表得到形象进度标题
LeftJoin("visual_progress AS visual on visual.id = remark.visual_progress_id").
// 连表查询评论人的名字
LeftJoin("sys_user AS user on user.id = remark.user_id").
Where("remark.id = ? AND cuser.deleted_at is null", req.ID).
Scan(&res.VisualProgressRemark)
if err != nil {
return nil, err
}
return res, nil
}
// 新增形象进度
func (v VisualRemark) CreateRemark(ctx context.Context, req *CreateRemarkReq) (res *CreateRemarkRes, err error) {
res = &CreateRemarkRes{}
_, err = g.Model("visual_progress_remark").Ctx(ctx).Data(g.Map{
"visual_progress_id": req.VisualProgressID,
"comment": req.Comment,
"user_id": req.UserID,
}).Insert()
if err != nil {
return nil, err
}
var VisualProgressVo struct {
ProjectId int `json:"projectId"`
ReporterId int `json:"reporterId"`
}
// 根据形象进度ID查询项目ID、发布者ID
g.Model("visual_progress").Fields("project_id AS ProjectId", "reporter_id AS ReporterId").
Where("id", req.VisualProgressID).Scan(&VisualProgressVo)
// 新增之后通知对应的发起人
param := &system.CommentListAddReq{
ProjectId: VisualProgressVo.ProjectId,
Receiver: VisualProgressVo.ReporterId,
Content: req.Comment,
Sender: req.UserID,
}
service.CommentList().Add(ctx, param)
return res, nil
}
// 更新形象备注
func (v VisualRemark) UpdateRemark(ctx context.Context, req *UpdateRemarkReq) (res *UpdateRemarkRes, err error) {
res = &UpdateRemarkRes{}
_, err = g.Model("visual_progress_remark").Ctx(ctx).Data(g.Map{
"visual_progress_id": req.VisualProgressID,
"comment": req.Comment,
"user_id": req.UserID,
}).Where("id", req.ID).Update()
if err != nil {
return nil, err
}
return res, nil
}
// 删除形象备注
func (v VisualRemark) DeleteRemark(ctx context.Context, req *DeleteRemarkReq) (res *DeleteRemarkRes, err error) {
userID := ct.New().GetUserId(ctx)
var VisualProgressRemarkVo struct {
ID int `json:"id"`
UserID uint64 `json:"userId"`
}
g.Model("visual_progress_remark").Ctx(ctx).Where("id", req.ID).Scan(&VisualProgressRemarkVo)
// 当前用户等于评论的发起人才可以删除自己的评论
if userID == VisualProgressRemarkVo.UserID {
res = &DeleteRemarkRes{}
_, err = g.Model("visual_progress_remark").Ctx(ctx).Where("id", req.ID).Delete()
if err != nil {
return nil, err
}
} else {
return nil, errors.New("只能删除自己的评论信息")
}
return
}

View File

@ -0,0 +1,4 @@
package visual_remark
type VisualRemark struct {
}