Files
2025-07-07 20:11:59 +08:00

924 lines
42 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strconv"
"github.com/samber/lo"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/library/liberr"
"github.com/gogf/gf/v2/database/gdb"
"github.com/jinzhu/copier"
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
"github.com/tiger1103/gfast/v3/api/wxApplet/wxApplet"
wxSystem "github.com/tiger1103/gfast/v3/api/wxApplet/wxApplet"
systemController "github.com/tiger1103/gfast/v3/internal/app/system/controller"
controllerDao "github.com/tiger1103/gfast/v3/internal/app/system/dao"
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
serviceController "github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/dao"
wxAppletModel "github.com/tiger1103/gfast/v3/internal/app/wxApplet/model"
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/service"
"golang.org/x/net/context"
)
type appPortController struct {
systemController.BaseController
}
var AppPortController = new(appPortController)
// ===========================================APP首页===========================================
// ===========================================APP首页===========================================
// ===========================================APP首页===========================================
// GetsTheAttendanceOfASpecifiedShiftGroupFunc 班组长人员打卡统计
func (c *appPortController) GetsTheAttendanceOfASpecifiedShiftGroupFunc(ctx context.Context, req *wxApplet.GetsTheAttendanceOfASpecifiedShiftGroupReq) (res *wxApplet.GetsTheAttendanceOfASpecifiedShiftGroupRes, err error) {
res, err = service.SysProjectTeam().GetsTheAttendanceOfASpecifiedShiftGroupFunc(ctx, req)
return
}
// ListOfAttendancePersonnelFunc 获取用户对应出勤状态的人员列表
func (c *appPortController) ListOfAttendancePersonnelFunc(ctx context.Context, req *wxApplet.ListOfAttendancePersonnelReq) (res *wxApplet.ListOfAttendancePersonnelRes, err error) {
res, err = service.SysProjectTeam().ListOfAttendancePersonnelFunc(ctx, req)
return
}
// AppUserMenuFunc 获取用户菜单
func (c *appPortController) AppUserMenuFunc(ctx context.Context, req *wxApplet.AppUserMenusReq) (*wxApplet.AppUserMenusRes, error) {
// 获取用户信息
userInfo := ct.New().GetLoginUser(ctx)
// 获取用户角色
roleIds, err := getUserRoles(ctx, userInfo, req.UserType)
if err != nil {
return nil, err
}
var userMenuList []wxApplet.AppUserMenu
// 获取用户菜单
if err := controllerDao.AppMenus.Ctx(ctx).As("menu").
InnerJoin("app_role_menus roleMenu", "menu.menu_id = roleMenu.menu_id").
Where("roleMenu.role_id IN (?)", roleIds).
Fields("menu.menu_id, menu.menu_name").Scan(&userMenuList); err != nil {
return nil, fmt.Errorf("获取用户菜单失败:%w", err)
}
userMenuList = lo.UniqBy(userMenuList, func(item wxApplet.AppUserMenu) uint {
return item.MenuID
})
return &wxApplet.AppUserMenusRes{MenuList: userMenuList}, nil
}
// getUserRoles 获取用户角色
func getUserRoles(ctx context.Context, user *model.ContextUser, role int) ([]int, error) {
rules := []model.Ruler{}
query := controllerDao.AppUserRoles.Ctx(ctx).As("aur").
InnerJoin("app_roles ar", "aur.role_id = ar.role_id").
Fields("ar.role_id,ar.role_name,aur.user_id").
Where("aur.user_id", user.Id).
Where("aur.major_role", role)
if err := query.Scan(&rules); err != nil {
return nil, fmt.Errorf("获取用户角色失败:%w", err)
}
roleID := lo.FilterMap(rules, func(item model.Ruler, _ int) (int, bool) {
return item.RoleId, true
})
return roleID, nil
}
// AppMyAttendanceFunc 我的考勤
func (c *appPortController) AppMyAttendanceFunc(ctx context.Context, req *wxApplet.AppMyAttendanceReq) (res *wxApplet.AppMyAttendanceRes, err error) {
res = new(wxApplet.AppMyAttendanceRes)
res, err = service.BusAttendance().AppMyAttendanceFunc(ctx, req)
return
}
// AppMyAttendanceDetailsFunc 我的考勤详情数据
func (c *appPortController) AppMyAttendanceDetailsFunc(ctx context.Context, req *wxApplet.AppMyAttendanceDetailsReq) (res *wxApplet.AppMyAttendanceDetailsRes, err error) {
res = new(wxApplet.AppMyAttendanceDetailsRes)
res, err = service.BusAttendance().AppMyAttendanceDetailsFunc(ctx, req)
return
}
// AppProjectOverviewFunc 项目概况
func (c *appPortController) AppProjectOverviewFunc(ctx context.Context, req *wxApplet.AppProjectOverviewReq) (res *wxApplet.AppProjectOverviewRes, err error) {
res = new(wxApplet.AppProjectOverviewRes)
res, err = service.BusAttendance().AppProjectOverviewFunc(ctx, req)
return
}
// AppSafetyHazardTodayFunc 项目概况>今日AI安全隐患
func (c *appPortController) AppSafetyHazardTodayFunc(ctx context.Context, req *wxApplet.AppSafetyHazardTodayReq) (res *wxApplet.AppSafetyHazardTodayRes, err error) {
res, err = serviceController.BusViolationRecord().AppSafetyHazardTodayFunc(ctx, req)
return
}
// AppWeatherFunc 【小程序】获取施工人员天气
func (c *appPortController) AppWeatherFunc(ctx context.Context, req *wxApplet.AppWeatherReq) (res *wxApplet.AppWeatherRes, err error) {
res = new(wxApplet.AppWeatherRes)
we := coryCommon.Weather(req.Location)
bodyData := []byte(we)
err = json.Unmarshal(bodyData, &res)
if err != nil {
fmt.Println("Failed to parse JSON data:", err)
return
}
return
}
// AppProjectNoticeListFunc 首页获取滚动的项目公告列表
func (c *appPortController) AppProjectNoticeListFunc(ctx context.Context, req *wxApplet.AppProjectNoticeReq) (*wxApplet.AppProjectNoticeRes, error) {
userId := ct.New().GetLoginUser(ctx).Id
noticeList := []*wxApplet.ProjectNoticeList{}
if err := controllerDao.Notifications.Ctx(ctx).
Fields(controllerDao.Notifications.Columns().Title).
LeftJoin("notification_recipients nf", "notifications.id = nf.notification_id").
Where(controllerDao.Notifications.Columns().ProjectId, req.ProjectId).
Where(controllerDao.Notifications.Columns().IsApp, 1).
Where("nf.recipient_id", userId).
Limit(20).OrderDesc("notifications.id").Scan(&noticeList); err != nil {
return nil, fmt.Errorf("获取项目公告失败:%w", err)
}
return &wxApplet.AppProjectNoticeRes{
List: noticeList,
}, nil
}
// AppRegisteredButNotVerifiedWithRealName 获取所有已注册未实名的用户
func (c *appPortController) AppRegisteredButNotVerifiedWithRealName(ctx context.Context, req *wxApplet.AppRegisteredButNotVerifiedWithRealNameReq) (res *wxApplet.AppRegisteredButNotVerifiedWithRealNameRes, err error) {
res, err = serviceController.BusConstructionUser().AppRegisteredButNotVerifiedWithRealNameFunc(ctx, req)
return
}
// ===========================================定位考勤===========================================
// ===========================================定位考勤===========================================
// ===========================================定位考勤===========================================
// AppCodedBackwardsByLatitudeAndLongitudeFunc 根据经度纬度逆编码为省市区信息
func (c *appPortController) AppCodedBackwardsByLatitudeAndLongitudeFunc(ctx context.Context, req *wxApplet.AppCodedBackwardsByLatitudeAndLongitudeReq) (res *wxApplet.AppCodedBackwardsByLatitudeAndLongitudeRes, err error) {
res = new(wxApplet.AppCodedBackwardsByLatitudeAndLongitudeRes)
we := coryCommon.InverseGeocoding(req.Location)
bodyData := []byte(we)
err = json.Unmarshal(bodyData, &res)
if err != nil {
return
}
return
}
// AppOpenidByFounderFunc 返回当前用户所在项目的打卡范围
func (c *appPortController) AppOpenidByFounderFunc(ctx context.Context, req *wxApplet.AppOpenidByFounderReq) (res *wxApplet.AppOpenidByFounderRes, err error) {
res = new(wxApplet.AppOpenidByFounderRes)
founderFunc, err := OpenidByFounderFunc(ctx, req.Openid)
err = copier.Copy(&res, founderFunc)
return
}
// AppWhetherToEnterTheClockRangeFunc 判断当前用户是否进入打卡范围
func (c *appPortController) AppWhetherToEnterTheClockRangeFunc(ctx context.Context, req *wxApplet.AppWhetherToEnterTheClockRangeReq) (res *wxApplet.AppWhetherToEnterTheClockRangeRes, err error) {
res = new(wxApplet.AppWhetherToEnterTheClockRangeRes)
res, err = service.BusAttendance().AppWhetherToEnterTheClockRangeFunc(ctx, req)
return
}
// AppClockingStatusOfTheDayFunc 判断当前用户当天的打卡状态1未打卡、2已打上班卡、3已打下班卡
func (c *appPortController) AppClockingStatusOfTheDayFunc(ctx context.Context, req *wxApplet.AppClockingStatusOfTheDayReq) (res *wxApplet.AppClockingStatusOfTheDayRes, err error) {
res = new(wxApplet.AppClockingStatusOfTheDayRes)
res, err = service.BusAttendance().AppClockingStatusOfTheDayFunc(ctx, req)
return
}
// AppFaceDetectionFunc 人脸检测
func (c *appPortController) AppFaceDetectionFunc(ctx context.Context, req *wxApplet.AppFaceDetectionReq) (res *wxApplet.AppFaceDetectionRes, err error) {
res = new(wxApplet.AppFaceDetectionRes)
res.Path, err = FaceDetectionFunc(ctx, req.File)
return
}
// AppAttendanceCardFunc 考勤打卡
func (c *appPortController) AppAttendanceCardFunc(ctx context.Context, req *wxApplet.AppAttendanceCardReq) (res *wxApplet.AppAttendanceCardRes, err error) {
res = new(wxApplet.AppAttendanceCardRes)
addReq := wxApplet.BusAttendanceAddReq{}
copier.Copy(&addReq, &req)
err = service.BusAttendance().Add(ctx, &addReq)
return
}
// AppAllMembersOfTheCurrentGroupFunc 获取当前组的所有成员(除自己)
func (c *appPortController) AppAllMembersOfTheCurrentGroupFunc(ctx context.Context, req *wxApplet.AppAllMembersOfTheCurrentGroupReq) (res *wxApplet.AppAllMembersOfTheCurrentGroupRes, err error) {
res, err = service.BusConstructionUser().AppAllMembersOfTheCurrentGroupFunc(ctx, req)
return
}
// AppSelectThisUserByCardRecordFunc 为指定用户查询打卡记录
func (c *appPortController) AppSelectThisUserByCardRecordFunc(ctx context.Context, req *wxApplet.AppSelectThisUserByCardRecordReq) (res *wxApplet.AppSelectThisUserByCardRecordRes, err error) {
res, err = service.BusAttendance().AppSelectThisUserByCardRecordFunc(ctx, req)
return
}
// AppLocationAttendanceStatisticsFunc 定位考勤统计
func (c *appPortController) AppLocationAttendanceStatisticsFunc(ctx context.Context, req *wxApplet.AppLocationAttendanceStatisticsReq) (res *wxApplet.AppLocationAttendanceStatisticsRes, err error) {
res, err = service.BusAttendance().AppLocationAttendanceStatisticsFunc(ctx, req)
return
}
// AppSelectBySiteDateAndTimeFunc 根据openid获取到项目的逆编码地址及项目的上下班打卡时间
func (c *appPortController) AppSelectBySiteDateAndTimeFunc(ctx context.Context, req *wxApplet.AppSelectBySiteDateAndTimeReq) (res *wxApplet.AppSelectBySiteDateAndTimeRes, err error) {
res = new(wxApplet.AppSelectBySiteDateAndTimeRes)
data, err := serviceController.SysProject().GetById(ctx, req.ProjectId)
res.PunchRange = data.PunchRange
res.Lng = data.Lng
res.Lat = data.Lat
// 逆编码
var entity *coryCommon.InverseGeocodingRep
we := coryCommon.InverseGeocoding(data.Lng + "," + data.Lat)
bodyData := []byte(we)
err = json.Unmarshal(bodyData, &entity)
if err != nil {
return
}
res.Site = entity.Regeocode.FormattedAddress
return
}
// AppMyProjectListFunc 获取项目列表
func (c *appPortController) AppMyProjectListFunc(ctx context.Context, req *wxApplet.AppMyProjectListReq) (*wxApplet.SysUserProjectRelevancySearchRes, error) {
// 获取当前登录用户ID
userInfo := ct.New().GetLoginUser(ctx)
// 当前登录用户ID
userID := userInfo.Id
// 用户手机号
phone := userInfo.Mobile
var query *gdb.Model
fields := `a.*,
CASE WHEN (b.short_name IS NULL OR b.project_name = '') THEN b.project_name ELSE b.short_name END AS project_name,
b.lng, b.lat, b.type, b.project_site`
if req.ProjectType == 0 {
// 管理员获取项目时,将获取后台所拥有的项目
query = dao.SysUserProjectRelevancy.Ctx(ctx).As("a").
InnerJoin("sys_project as b on a.project_id = b.id").
Fields(fields).Where("a.user_id", userID)
} else {
// 当请求者为施工人员时,从 bus_construction_user 表中获取其绑定的项目信息
query = dao.BusConstructionUser.Ctx(ctx).As("a").
InnerJoin("sys_project as b on a.project_id = b.id").
Fields(fields).Where("a.phone", phone)
}
var projectList []*wxAppletModel.SysUserProjectRelevancyListRes
if err := query.Scan(&projectList); err != nil {
return nil, fmt.Errorf("获取项目列表失败:%w", err)
}
return &wxApplet.SysUserProjectRelevancySearchRes{
List: projectList,
}, nil
}
// AppReissueACardListFunc 补卡申请列表(目前只会展示缺卡的数据)
func (c *appPortController) AppReissueACardListFunc(ctx context.Context, req *wxApplet.AppReissueACardListReq) (res *wxApplet.AppReissueACardListRes, err error) {
res, err = service.BusAttendance().AppReissueACardListFunc(ctx, req)
return
}
// AppReissueACardIdFunc 补卡申请ID查询
func (c *appPortController) AppReissueACardIdFunc(ctx context.Context, req *wxApplet.AppReissueACardIdReq) (res *wxApplet.AppReissueACardIdRes, err error) {
res, err = service.BusAttendance().AppReissueACardIdFunc(ctx, req)
return
}
// AppCardReplacementApplicationAddFunc 新增补卡申请
func (c *appPortController) AppCardReplacementApplicationAddFunc(ctx context.Context, req *wxApplet.AppCardReplacementApplicationAddReq) (res *wxApplet.AppCardReplacementApplicationAddRes, err error) {
r := wxApplet.ReissueACardWxAddReq{}
copier.Copy(&r, &req)
err = serviceController.BusReissueACard().ReissueACardWxAdd(ctx, &r)
return
}
// AppReplacementCardApplicationRecordFunc 申请人补卡记录(分页)
func (c *appPortController) AppReplacementCardApplicationRecordFunc(ctx context.Context, req *wxApplet.AppReplacementCardApplicationRecordReq) (res *wxApplet.AppReplacementCardApplicationRecordRes, err error) {
res = new(wxApplet.AppReplacementCardApplicationRecordRes)
// 请求
r := wxApplet.ReissueACardWxGetByIdReq{}
copier.Copy(&r, &req)
// 返回
idFunc, err := serviceController.BusReissueACard().ReissueACardWxGetByIdFunc(ctx, &r)
copier.Copy(&res, &idFunc)
return
}
// AppTheTeamLeaderSupplementCardApprovalListFun 班组长补卡审批列表(分页)
func (c *appPortController) AppTheTeamLeaderSupplementCardApprovalListFun(ctx context.Context, req *wxApplet.AppTheTeamLeaderSupplementCardApprovalListReq) (res *wxApplet.AppTheTeamLeaderSupplementCardApprovalListRes, err error) {
entity := model.AppTheTeamLeaderSupplementCardApprovalRes{}
copier.Copy(&entity, &req)
entity.Type = "1"
res, err = serviceController.BusReissueACard().AppTheTeamLeaderSupplementCardApprovalListFun(ctx, &entity)
return
}
// AppTheTeamLeaderSupplementCardApprovalRecordListFunc 班组长补卡审批记录列表(分页)
func (c *appPortController) AppTheTeamLeaderSupplementCardApprovalRecordListFunc(ctx context.Context, req *wxApplet.AppTheTeamLeaderSupplementCardApprovalRecordListReq) (res *wxApplet.AppTheTeamLeaderSupplementCardApprovalListRes, err error) {
entity := model.AppTheTeamLeaderSupplementCardApprovalRes{}
copier.Copy(&entity, &req)
entity.Type = "2"
res, err = serviceController.BusReissueACard().AppTheTeamLeaderSupplementCardApprovalListFun(ctx, &entity)
return
}
// AppApprovalRecordDetailsFunc 审批记录详情
func (c *appPortController) AppApprovalRecordDetailsFunc(ctx context.Context, req *wxApplet.AppApprovalRecordDetailsReq) (res *wxApplet.AppApprovalRecordDetailsRes, err error) {
res, err = serviceController.BusReissueACard().AppApprovalRecordDetailsFunc(ctx, req)
return
}
// AppForemanApprovalFunc 班组长审批
func (c *appPortController) AppForemanApprovalFunc(ctx context.Context, req *wxApplet.AppForemanApprovalReq) (res *wxApplet.AppForemanApprovalRes, err error) {
entity := wxApplet.ReissueACardWxEditTeamReq{}
copier.Copy(&entity, &req)
err = serviceController.BusReissueACard().ReissueACardWxEditTeam(ctx, &entity)
return
}
// @Title AdministratorApprovalFunc 2024/7/26 15:20:00
// @Description 管理员审批(仅限于管理员操作)
// @Auth Cory
func (c *appPortController) AdministratorApprovalFunc(ctx context.Context, req *wxApplet.AdministratorApprovalReq) (res *wxApplet.AdministratorApprovalRes, err error) {
editReq := system.BusReissueACardEditReq{}
copier.Copy(&editReq, &req)
err = serviceController.BusReissueACard().Edit(ctx, &editReq)
return
}
// ===========================================安全HSE巡检工单===========================================
// ===========================================安全HSE巡检工单===========================================
// ===========================================安全HSE巡检工单===========================================
// AppManagementAppletListInformFunc 安全巡检工单列表-全部(分页)
func (c *appPortController) AppManagementAppletListInformFunc(ctx context.Context, req *wxApplet.AppManagementAppletListInformReq) (res *wxApplet.AppManagementAppletListRes, err error) {
res = new(wxApplet.AppManagementAppletListRes)
entity := wxApplet.HseManagementAppletListReq{}
copier.Copy(&entity, &req)
entity.Status = "0"
listFunc, err := serviceController.BusHseManagement().HseManagementAppletListFunc(ctx, &entity)
copier.Copy(&res, listFunc)
return
}
// AppManagementAppletListAbarbeitungFunc 安全巡检工单列表-整改(分页)
func (c *appPortController) AppManagementAppletListAbarbeitungFunc(ctx context.Context, req *wxApplet.AppManagementAppletListAbarbeitungReq) (res *wxApplet.AppManagementAppletListRes, err error) {
res = new(wxApplet.AppManagementAppletListRes)
entity := wxApplet.HseManagementAppletListReq{}
copier.Copy(&entity, &req)
entity.Status = "1"
listFunc, err := serviceController.BusHseManagement().HseManagementAppletListFunc(ctx, &entity)
copier.Copy(&res, listFunc)
return
}
// AppManagementAppletListReviewFunc 安全巡检工单列表-复查(分页)
func (c *appPortController) AppManagementAppletListReviewFunc(ctx context.Context, req *wxApplet.AppManagementAppletListReviewReq) (res *wxApplet.AppManagementAppletListRes, err error) {
res = new(wxApplet.AppManagementAppletListRes)
entity := wxApplet.HseManagementAppletListReq{}
copier.Copy(&entity, &req)
entity.Status = "2"
listFunc, err := serviceController.BusHseManagement().HseManagementAppletListFunc(ctx, &entity)
copier.Copy(&res, listFunc)
return
}
// APPAddedDataSecurityForBackgroundUsersFunc APP的后台用户新增安全数据
func (c *appPortController) APPAddedDataSecurityForBackgroundUsersFunc(ctx context.Context, req *wxApplet.APPAddedDataSecurityForBackgroundUsersReq) (res *wxApplet.APPAddedDataSecurityForBackgroundUsersRes, err error) {
entity := system.BusHseManagementAddReq{}
copier.Copy(&entity, &req)
entity.HseManagementAdd = 1
entity.FileTwo = req.File
err = serviceController.BusHseManagement().Add(ctx, &entity)
return
}
// APPReviewDataSecurityForBackgroundUsersFunc APP的后台用户复查安全数据
func (c *appPortController) APPReviewDataSecurityForBackgroundUsersFunc(ctx context.Context, req *wxApplet.APPReviewDataSecurityForBackgroundUsersReq) (res *wxApplet.APPReviewDataSecurityForBackgroundUsersRes, err error) {
entity := system.EditReviewReq{}
copier.Copy(&entity, &req)
err = serviceController.BusHseManagement().EditReview(ctx, &entity)
return
}
// ===========================================质量管理===========================================
// ===========================================质量管理===========================================
// ===========================================质量管理===========================================
// AppInspectionTicketAppletListInformFunc 质量管理列表-全部(分页)
func (c *appPortController) AppInspectionTicketAppletListInformFunc(ctx context.Context, req *wxApplet.AppInspectionTicketAppletListInformReq) (res *wxApplet.AppInspectionTicketAppletListRes, err error) {
res = new(wxApplet.AppInspectionTicketAppletListRes)
entity := wxApplet.InspectionTicketAppletListReq{}
copier.Copy(&entity, &req)
entity.Status = "0"
listFunc, err := serviceController.BusInspectionTicket().InspectionTicketAppletListFunc(ctx, &entity)
copier.Copy(&res, listFunc)
return
}
// AppInspectionTicketAppletListAbarbeitungFunc 质量管理列表-整改(分页)
func (c *appPortController) AppInspectionTicketAppletListAbarbeitungFunc(ctx context.Context, req *wxApplet.AppInspectionTicketAppletListAbarbeitungReq) (res *wxApplet.AppInspectionTicketAppletListRes, err error) {
res = new(wxApplet.AppInspectionTicketAppletListRes)
entity := wxApplet.InspectionTicketAppletListReq{}
copier.Copy(&entity, &req)
entity.Status = "1"
listFunc, err := serviceController.BusInspectionTicket().InspectionTicketAppletListFunc(ctx, &entity)
copier.Copy(&res, listFunc)
return
}
// AppInspectionTicketAppletListReviewFunc 质量管理列表-复查(分页)
func (c *appPortController) AppInspectionTicketAppletListReviewFunc(ctx context.Context, req *wxApplet.AppInspectionTicketAppletListReviewReq) (res *wxApplet.AppInspectionTicketAppletListRes, err error) {
res = new(wxApplet.AppInspectionTicketAppletListRes)
entity := wxApplet.InspectionTicketAppletListReq{}
copier.Copy(&entity, &req)
entity.Status = "2"
listFunc, err := serviceController.BusInspectionTicket().InspectionTicketAppletListFunc(ctx, &entity)
copier.Copy(&res, listFunc)
return
}
// AppQualityDataIsAddedForBackgroundUsersFunc APP的后台用户新增质量数据
func (c *appPortController) AppQualityDataIsAddedForBackgroundUsersFunc(ctx context.Context, req *wxApplet.AppQualityDataIsAddedForBackgroundUsersReq) (res *wxApplet.AppQualityDataIsAddedForBackgroundUsersRes, err error) {
entity := system.BusInspectionTicketAddReq{}
copier.Copy(&entity, &req)
entity.HseManagementAdd = 1
entity.FileTwo = req.File
err = serviceController.BusInspectionTicket().Add(ctx, &entity)
return
}
// AppBackgroundUsersReviewQualityDataFunc APP的后台用户复查质量数据
func (c *appPortController) AppBackgroundUsersReviewQualityDataFunc(ctx context.Context, req *wxApplet.AppBackgroundUsersReviewQualityDataReq) (res *wxApplet.AppBackgroundUsersReviewQualityDataRes, err error) {
entity := system.BusInspectionTicketVerificationReq{}
copier.Copy(&entity, &req)
err = serviceController.BusInspectionTicket().EditVerification(ctx, &entity)
return
}
// ===========================================AI===========================================
// ===========================================AI===========================================
// ===========================================AI===========================================
// AppAiInformFunc 选择处理人
func (c *appPortController) AppAiInformFunc(ctx context.Context, req *wxApplet.AppAiInformReq) (res *wxApplet.AppAiInformRes, err error) {
err = serviceController.BusViolationRecord().AppAiInformFunc(ctx, req)
return
}
// AppGetsAllThePeopleUnderTheCurrentPersonsProjectFunc 取当前人所在项目下的所有人
func (c *appPortController) AppGetsAllThePeopleUnderTheCurrentPersonsProjectFunc(ctx context.Context, req *wxApplet.AppGetsAllThePeopleUnderTheCurrentPersonsProjectReq) (res *wxApplet.AppGetsAllThePeopleUnderTheCurrentPersonsProjectRes, err error) {
res = new(wxApplet.AppGetsAllThePeopleUnderTheCurrentPersonsProjectRes)
projectFunc, err := serviceController.BusViolationRecord().AppGetsAllThePeopleUnderTheCurrentPersonsProjectFunc(ctx, req)
res = projectFunc
return
}
// AppWorkOrderPcListFunc AI工单列表根据pc用户主键ID进行分页获取
func (c *appPortController) AppWorkOrderPcListFunc(ctx context.Context, req *wxApplet.AppWorkOrderPcListReq) (res *wxApplet.AppWorkOrderPcListRes, err error) {
res = new(wxApplet.AppWorkOrderPcListRes)
projectFunc, err := serviceController.BusViolationRecord().AppWorkOrderPcListFunc(ctx, req)
res = projectFunc
return
}
// AppWorkOrderAppListFunc AI工单列表根据App用户主键ID进行分页获取
func (c *appPortController) AppWorkOrderAppListFunc(ctx context.Context, req *wxApplet.AppWorkOrderAppListReq) (res *wxApplet.AppWorkOrderPcListRes, err error) {
res = new(wxApplet.AppWorkOrderPcListRes)
projectFunc, err := serviceController.BusViolationRecord().AppWorkOrderAppListFunc(ctx, req)
res = projectFunc
return
}
// AppRectificationReplyFunc AI整改回复
func (c *appPortController) AppRectificationReplyFunc(ctx context.Context, req *wxApplet.AppRectificationReplyReq) (res *wxApplet.AppRectificationReplyRes, err error) {
res = new(wxApplet.AppRectificationReplyRes)
err = serviceController.BusViolationRecord().AppRectificationReplyFunc(ctx, req)
return
}
// AppReviewFuncFunc AI复查
func (c *appPortController) AppReviewFuncFunc(ctx context.Context, req *wxApplet.AppReviewReq) (res *wxApplet.AppReviewRes, err error) {
res = new(wxApplet.AppReviewRes)
req.Operator = ct.New().GetLoginUser(ctx).OpenId
err = serviceController.BusViolationRecord().AppReviewFuncFunc(ctx, req)
return
}
// AppWorkOrderParticularsFunc AI工单详情
func (c *appPortController) AppWorkOrderParticularsFunc(ctx context.Context, req *wxApplet.AppWorkOrderParticularsReq) (res *wxApplet.AppWorkOrderParticularsRes, err error) {
res = new(wxApplet.AppWorkOrderParticularsRes)
particularsFunc, err := serviceController.BusViolationRecord().AppWorkOrderParticularsFunc(ctx, req)
res = particularsFunc
return
}
// =========================================== 消息 ===========================================
// =========================================== 消息 ===========================================
// =========================================== 消息 ===========================================
// AppMessageListFunc 消息列表
func (c *appPortController) AppMessageListFunc(ctx context.Context, req *wxApplet.AppMessageListReq) (res *wxApplet.AppMessageListRes, err error) {
// 获取用户信息
user := ct.New().GetLoginUser(ctx)
res = new(wxApplet.AppMessageListRes)
fields := "title,created_at, (SELECT COUNT(*) FROM reminders WHERE is_read = 0 and user_id = '%s' and project_id = %s) AS unread_count"
userID := lo.If(req.OpenID != "", user.OpenId).Else(strconv.Itoa(int(user.Id)))
// 查询提醒
controllerDao.Reminders.Ctx(ctx).Fields(fmt.Sprintf(fields, userID, req.ProjectId)).
Where("is_read", 0).
Where("project_id", req.ProjectId).
OrderDesc("id").
Where("user_id", userID).
Limit(1).Scan(&res.Remind)
fields = "content as title,created_at, (SELECT COUNT(*) FROM comment_list WHERE is_read = 0 and receiver = %d and project_id = %s) AS unread_count"
controllerDao.CommentList.Ctx(ctx).Fields(fmt.Sprintf(fields, user.Id, req.ProjectId)).
Where("is_read", 0).
Where("receiver", user.Id).
Where("project_id", req.ProjectId).
OrderDesc("id").
Limit(1).Scan(&res.Comment)
return
}
// ===========================================人员管理===========================================
// ===========================================人员管理===========================================
// ===========================================人员管理===========================================
// AppChangeThePunchStatusForTheSpecifiedPersonFunc 给指定人更改打卡状态
func (c *appPortController) AppChangeThePunchStatusForTheSpecifiedPersonFunc(ctx context.Context, req *wxApplet.AppChangeThePunchStatusForTheSpecifiedPersonReq) (res *wxApplet.AppChangeThePunchStatusForTheSpecifiedPersonRes, err error) {
entity := system.ClockingConditionReq{}
copier.Copy(&entity, &req)
err = serviceController.BusConstructionUser().ClockingConditionFunc(ctx, &entity)
return
}
// AppSelectAppointProjectAllTeamFunc 获取指定项目所有班组
func (c *appPortController) AppSelectAppointProjectAllTeamFunc(ctx context.Context, req *wxApplet.AppSelectAppointProjectAllTeamReq) (res *wxApplet.AppSelectAppointProjectAllTeamRes, err error) {
res = new(wxApplet.AppSelectAppointProjectAllTeamRes)
var entity []*wxAppletModel.SysProjectTeamListRes
err = dao.SysProjectTeam.Ctx(ctx).Where(dao.SysProjectTeam.Columns().ProjectId, req.ProjectId).Scan(&entity)
res.List = entity
return
}
// AppListOfParticipatingUnitsFunc 参建单位列表
func (c *appPortController) AppListOfParticipatingUnitsFunc(ctx context.Context, req *wxApplet.AppListOfParticipatingUnitsReq) (res *wxApplet.AppListOfParticipatingUnitsRes, err error) {
res, err = service.BusLabourservice().AppListOfParticipatingUnitsFunc(ctx, req)
return
}
// AppListOfConstructionPersonnelFunc 施工人员列表(分页)
func (c *appPortController) AppListOfConstructionPersonnelFunc(ctx context.Context, req *wxApplet.AppListOfConstructionPersonnelReq) (res *wxApplet.AppListOfConstructionPersonnelRes, err error) {
res, err = service.BusConstructionUser().AppListOfConstructionPersonnelFunc(ctx, req)
return
}
// AppExitFunc 退场
func (c *appPortController) AppExitFunc(ctx context.Context, req *wxApplet.AppExitReq) (res *wxApplet.AppExitRes, err error) {
res = new(wxApplet.AppExitRes)
err = serviceController.BusConstructionUser().AppExitFunc(ctx, req)
return
}
// AppResubmitTheExitAttachmentFunc 补交退场附件
func (c *appPortController) AppResubmitTheExitAttachmentFunc(ctx context.Context, req *wxApplet.AppResubmitTheExitAttachmentReq) (res *wxApplet.AppResubmitTheExitAttachmentRes, err error) {
res = new(wxApplet.AppResubmitTheExitAttachmentRes)
err = serviceController.BusConstructionUser().AppResubmitTheExitAttachmentFunc(ctx, req)
return
}
// AppTeamAttendanceFunc 团队出勤
func (c *appPortController) AppTeamAttendanceFunc(ctx context.Context, req *wxApplet.AppTeamAttendanceReq) (res *wxApplet.AppTeamAttendanceRes, err error) {
res, err = service.BusAttendance().AppTeamAttendanceFunc(ctx, req)
return
}
// AppGetsThePeopleUnderTheSpecifiedProjectFunc 获取指定项目下已实名认证或已退出班组的人
func (c *appPortController) AppGetsThePeopleUnderTheSpecifiedProjectFunc(ctx context.Context, req *wxApplet.AppGetsThePeopleUnderTheSpecifiedProjectReq) (res *wxApplet.AppGetsThePeopleUnderTheSpecifiedProjectRes, err error) {
res, err = service.BusConstructionUser().AppGetsThePeopleUnderTheSpecifiedProjectFunc(ctx, req)
return
}
// AppJoinATeamFunc 加入指定项目下的指定班组
func (c *appPortController) AppJoinATeamFunc(ctx context.Context, req *wxApplet.AppJoinATeamReq) (res *wxApplet.AppJoinATeamRes, err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
for _, openid := range req.Openids {
r := new(wxSystem.SysProjectTeamMemberAddReq)
r.Openid = openid
r.PostId = 4
copier.Copy(r, req)
err = service.SysProjectTeamMember().Add(ctx, r)
liberr.ErrIsNil(ctx, err)
}
})
return err
})
return
}
// AppGetPersonnelDetailsFunc 获取人员详情
func (c *appPortController) AppGetPersonnelDetailsFunc(ctx context.Context, req *wxApplet.AppGetPersonnelDetailsReq) (res *wxApplet.AppGetPersonnelDetailsRes, err error) {
res, err = service.BusConstructionUser().AppGetPersonnelDetailsFunc(ctx, req)
return
}
// ===========================================提醒===========================================
// ===========================================提醒===========================================
// ===========================================提醒===========================================
// AIWorkOrderDetailsFunc AI工单详情
func (c *appPortController) AIWorkOrderDetailsFunc(ctx context.Context, req *wxApplet.AIWorkOrderDetailsReq) (res *wxApplet.AIWorkOrderDetailsRes, err error) {
res = new(wxApplet.AIWorkOrderDetailsRes)
err = g.Try(ctx, func(ctx context.Context) {
// 1、获取主体信息
err = g.DB().Model("reminders").As("e").
LeftJoin("bus_violation_record", "a", "a.id = e.order_id").
LeftJoin("sys_dict_data", "b", "b.dict_type = 'tour_type' and b.dict_value = a.tour_type").
LeftJoin("sys_dict_data", "c", "c.dict_type = 'violation_record_data_source' and c.dict_value = a.data_source").
LeftJoin("sys_project", "d", "d.id = a.project_id").
Fields("a.*,b.dict_label as tt,c.dict_label as ds,d.project_name as projectName,e.status").
Where("e.id", req.Id).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取当前AI数据失败")
if res.Openid != "" { // 获取处理人名称
value, _ := dao.BusConstructionUser.Ctx(ctx).Where("openid", res.Openid).Fields("user_name").Value()
res.OpenidName = value.String()
}
if res.Status == "3" { // 复查人名称
value, _ := g.DB().Model("sys_user").Ctx(ctx).Where("id", res.SelectPeople).Fields("user_nickname").Value()
res.ReviewName = value.String()
}
i2, _ := g.DB().Model("bus_violation_record_correlation").Ctx(ctx).
Where("a.record_id", res.Id).As("a").
LeftJoin("sys_user", "b", "b.id = a.user_id").
Fields("b.user_nickname").Array()
for i3 := range i2 { // 哪些人可以复查(只需有一个复查就行了)
res.SuperintendName = append(res.SuperintendName, i2[i3].String())
}
// 2、获取附件
var pathEntity []*model.BusViolationRecordPathLogicRes
err = g.DB().Model("bus_violation_record_path").Ctx(ctx).Where("ticket_id", req.Id).Scan(&pathEntity)
liberr.ErrIsNil(ctx, err, "查询失败")
// 3、分类附件
var one []*model.BusViolationRecordPathLogicRes
var two []*model.BusViolationRecordPathLogicRes
for i := range pathEntity {
if pathEntity[i].Type == "1" {
one = append(one, pathEntity[i])
} else {
two = append(two, pathEntity[i])
}
}
res.CheckAttachment = one
res.AbarbeitungAttachment = two
})
return
}
// QualityControlDetailsFunc 质量管理详情
func (c *appPortController) QualityControlDetailsFunc(ctx context.Context, req *wxApplet.QualityControlDetailsReq) (res *wxApplet.QualityControlDetailsRes, err error) {
res = new(wxApplet.QualityControlDetailsRes)
err = g.Try(ctx, func(ctx context.Context) {
m := g.DB().Model("reminders").As("e").
LeftJoin("bus_inspection_ticket", "a", "a.id = e.order_id").
LeftJoin("sys_project", "b", "b.id = a.project_id").
LeftJoin("sys_dict_data", "c", "dict_type = 'inspection_type' and dict_value = a.Inspection_type").
LeftJoin(dao.BusConstructionUser.Table(), "d", "d.openid = a.corrector").
Fields(
"a.id,b.project_name as projectName," + // 主键ID、项目名称
"c.dict_label," + // 巡检类型
"a.inspection_headline," + // 巡检主题
"a.inspection_result," + // 巡检结果
"d.user_name as abarbeitung," + // 整改人
"a.is_reply,a.reply_date," + // 是否回复、回复时间
"a.created_by as fill,a.created_at," + // 填报人、填报时间
"a.feedback," + // 整改反馈
"a.verification_result," + // 验证结果
"e.status,a.verification_type," + // 工单状态、验证状态
"a.updated_at as updatedAt," + // 更新时间
"a.rectification_time as rectificationTime", // 整改时间
)
err = m.Where("e.id", req.Id).Scan(&res)
liberr.ErrIsNil(ctx, err, "查询失败")
// 2、获取附件
var pathEntity []*wxApplet.SecurityManagementDetailsPath
err = g.DB().Model("bus_inspection_ticket_path").Ctx(ctx).Where("ticket_id", res.Id).Scan(&pathEntity)
liberr.ErrIsNil(ctx, err, "查询失败")
// 3、分类附件
var one []*wxApplet.SecurityManagementDetailsPath
var two []*wxApplet.SecurityManagementDetailsPath
for i := range pathEntity {
if pathEntity[i].Type == "1" {
one = append(one, pathEntity[i])
} else {
two = append(two, pathEntity[i])
}
}
res.Inspectionccessories = one
res.CorrectiveAttachment = two
// 3、获取
res.Fill = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res.Fill), res.Fill)
})
return
}
// SecurityManagementDetailsFunc 安全管理详情
func (c *appPortController) SecurityManagementDetailsFunc(ctx context.Context, req *wxApplet.SecurityManagementDetailsReq) (res *wxApplet.SecurityManagementDetailsRes, err error) {
res = new(wxApplet.SecurityManagementDetailsRes)
err = g.Try(ctx, func(ctx context.Context) {
m := g.DB().Model("reminders").As("f").
LeftJoin("bus_hse_management", "a", "a.id = f.order_id").
LeftJoin("sys_project", "b", "b.id = a.project_id").
LeftJoin("sys_dict_data", "c", "c.dict_type = 'study_type' and c.dict_value = a.study_type").
LeftJoin("sys_dict_data", "e", "e.dict_type = 'tour_type' and e.dict_value = a.tour_type").
LeftJoin(dao.BusConstructionUser.Table(), "d", "d.openid = a.corrector").
Fields(
"a.id,b.project_name as projectName," + // 主键ID、项目名称
"c.dict_label as studyTypeName," + // 检查类型
"e.dict_label as tourTypeName," + // 违章类型
"a.inspection_result," + // 巡检结果
"a.check_time," + // 检查时间
"a.reply_date," + // 要求整改期限
"a.team_name as teamName," + // 班组
"d.user_name as abarbeitung," + // 整改人
"a.rectification_time," + // 整改时间
"a.hidden_danger," + // 问题隐患
"a.measure," + // 整改措施
"a.review_time," + // 复查时间
"a.review," + // 复查情况
"f.status," + // 工单状态
"a.review_type," + // 复查状态
"a.created_by as fill," + // 复查状态
"a.created_at") // 创建人(检查、复查)
err = m.Where("f.id", req.Id).Scan(&res)
liberr.ErrIsNil(ctx, err, "查询失败")
// 2、获取附件
var pathEntity []*wxApplet.SecurityManagementDetailsPath
err = g.DB().Model("bus_hse_management_path").Ctx(ctx).Where("ticket_id", req.Id).Scan(&pathEntity)
liberr.ErrIsNil(ctx, err, "查询失败")
// 3、分类附件
var one []*wxApplet.SecurityManagementDetailsPath
var two []*wxApplet.SecurityManagementDetailsPath
for i := range pathEntity {
if pathEntity[i].Type == "1" {
one = append(one, pathEntity[i])
} else {
two = append(two, pathEntity[i])
}
}
res.CheckAttachment = one
res.AbarbeitungAttachment = two
// 3、获取
res.Fill = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res.Fill), res.Fill)
})
return
}
// ===========================================请假===========================================
// ===========================================请假===========================================
// ===========================================请假===========================================
// AppAskForLeaveAdd 务工者-请假新增
func (c *appPortController) AppAskForLeaveAdd(ctx context.Context, req *wxApplet.AppAskForLeaveAddReq) (res *wxApplet.AppBusAskforleaveAddRes, err error) {
err = service.BusAskforleave().AppAskForLeaveAdd(ctx, req)
return
}
// AppAskForLeaveListPage 务工者-请假记录列表-分页
func (c *appPortController) AppAskForLeaveListPage(ctx context.Context, req *wxApplet.AppAskForLeaveListPageReq) (res *wxApplet.AppAskForLeaveListPageRes, err error) {
return service.BusAskforleave().AppAskForLeaveListPage(ctx, req)
}
// AppAskForLeaveInfo 务工者-请假详情
func (c *appPortController) AppAskForLeaveInfo(ctx context.Context, req *wxApplet.AppAskForLeaveInfoReq) (res *wxApplet.AppAskForLeaveInfoRes, err error) {
return service.BusAskforleave().AppAskForLeaveInfo(ctx, req)
}
// AppBzzAskForLeaveListPage 班组长-审批
func (c *appPortController) AppBzzAskForLeaveUpdate(ctx context.Context, req *wxApplet.AppBzzAskForLeaveUpdateReq) (res *wxApplet.AppBzzAskForLeaveUpdateRes, err error) {
err = service.BusAskforleave().AppBzzAskForLeaveUpdate(ctx, req)
return
}
// ===========================================其它===========================================
// ===========================================其它===========================================
// ===========================================其它===========================================
// AppBase64ToImgFuncFunc 将图片的base64转成png存储到本地返回相对路径
func (c *appPortController) AppBase64ToImgFuncFunc(ctx context.Context, req *wxApplet.AppBase64ToImgFuncReq) (res *wxApplet.AppBase64ToImgFuncRes, err error) {
res = new(wxApplet.AppBase64ToImgFuncRes)
path, err := coryCommon.Base64ToImgFunc(req.Base64Str, "1", coryCommon.Helmet)
res.Path = "/" + path
return
}
// AppGetLatestAppVersionFunc 获取最新的App版本号
func (c *appPortController) AppGetLatestAppVersionFunc(ctx context.Context, req *wxApplet.GetLatestAppVersionReq) (*wxApplet.GetLatestAppVersionRes, error) {
var AppVersionInfo entity.AppVersions
err := controllerDao.AppVersions.Ctx(ctx).Fields(entity.AppVersions{}).
Where(controllerDao.AppVersions.Columns().Platform, req.Platform).
OrderDesc(controllerDao.AppVersions.Columns().Id).Limit(1).Scan(&AppVersionInfo)
if err != nil {
return nil, err
}
return &wxApplet.GetLatestAppVersionRes{
Info: AppVersionInfo,
}, nil
}
// AppReleaseAppVersionFunc 发布一个新的版本
func (c *appPortController) AppReleaseAppVersionFunc(ctx context.Context, req *wxApplet.ReleaseAppVersionReq) (*wxApplet.ReleaseAppVersionRes, error) {
var (
path, _ = os.Getwd()
Version = req.Version
plantType = req.Platform
)
// 根据平台类型拼接版本号
var devicePlatform string
switch plantType {
case 0:
devicePlatform = "Android"
case 1:
devicePlatform = "IOS"
}
// 拼接文件保存路径: 当前路径 + resource + public + version + 版本号 + 平台类型
filePath := filepath.Join(path, "resource", "public", "version", Version, devicePlatform)
// 保存到数据库的静态文件托管路径: file + version + 版本号 + 平台类型 + 文件名
savePath := filepath.Join("file", "version", Version, devicePlatform, req.File.Filename)
// 检查版本号是否已存在,如果存在则用新版本替换旧版本
var appVersion entity.AppVersions
if err := controllerDao.AppVersions.Ctx(ctx).Where(controllerDao.AppVersions.Columns().Version, Version).Where(controllerDao.AppVersions.Columns().Platform, plantType).Scan(&appVersion); err == nil {
// 删除旧版本文件
if err := os.RemoveAll(filepath.Join(filePath, filepath.Base(appVersion.FilePath))); err != nil {
return nil, fmt.Errorf("删除以往的版本文件失败:%w", err)
}
// 保存新版本文件
if _, err := req.File.Save(filePath); err != nil {
return nil, err
}
// 更新数据库中的文件路径
if _, err := controllerDao.AppVersions.Ctx(ctx).Data(gdb.Map{controllerDao.AppVersions.Columns().FilePath: savePath}).Where(controllerDao.AppVersions.Columns().Id, appVersion.Id).Update(); err != nil {
return nil, err
}
return &wxApplet.ReleaseAppVersionRes{}, nil
}
if _, err := req.File.Save(filePath); err != nil {
return nil, err
}
// 构造数据库记录
appVersionInfo := entity.AppVersions{
Version: Version, // 版本号
FilePath: savePath, // 文件路径
Platform: plantType, // 平台类型
}
// 保存到数据库
_, err := controllerDao.AppVersions.Ctx(ctx).Data(appVersionInfo).Insert()
if err != nil {
return nil, err
}
return &wxApplet.ReleaseAppVersionRes{}, nil
}