初始
This commit is contained in:
411
internal/app/system/logic/busQuality/bus_quality.go
Normal file
411
internal/app/system/logic/busQuality/bus_quality.go
Normal file
@ -0,0 +1,411 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-08-02 17:11:39
|
||||
// 生成路径: internal/app/system/logic/bus_quality.go
|
||||
// 生成人:gfast
|
||||
// desc:质量文档管理
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
comModel "github.com/tiger1103/gfast/v3/internal/app/common/model"
|
||||
commonEntity "github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
"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/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
wxDao "github.com/tiger1103/gfast/v3/internal/app/wxApplet/dao"
|
||||
wxModel "github.com/tiger1103/gfast/v3/internal/app/wxApplet/model"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusQuality(New())
|
||||
}
|
||||
|
||||
func New() *sBusQuality {
|
||||
return &sBusQuality{}
|
||||
}
|
||||
|
||||
type sBusQuality struct{}
|
||||
|
||||
func (s *sBusQuality) WxAddFunc(ctx context.Context, req *system.WxBusQualityAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
req.QualityDocument[0].Url = strings.ReplaceAll(req.QualityDocument[0].Url, "/file", "/wxfile") + ","
|
||||
_, err = dao.BusQuality.Ctx(ctx).Insert(do.BusQuality{
|
||||
QualityName: req.QualityName,
|
||||
QualityExplain: req.QualityExplain,
|
||||
QualityDocument: req.QualityDocument[0].Url,
|
||||
QualityType: req.QualityType,
|
||||
ProjectId: req.ProjectId,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) QualityDataListFunc(ctx context.Context, req *system.QualityDataListReq) (listRes *system.QualityDataListRes, err error) {
|
||||
var ufList []*comModel.UpFile
|
||||
listRes = new(system.QualityDataListRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
sql := dao.BusQuality.Ctx(ctx).Where("quality_type", req.QualityType).Where("project_id", req.ProjectId)
|
||||
|
||||
if req.IsPaging == "YES" || req.IsPaging == "yes" {
|
||||
listRes.Total, err = sql.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
sql = sql.Page(req.PageNum, req.PageSize).Order(order)
|
||||
}
|
||||
|
||||
var res []*model.BusQualityListRes
|
||||
err = sql.Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusQualityListRes, len(res))
|
||||
for k, v := range res {
|
||||
if err == nil {
|
||||
split := strings.Split(v.QualityDocument, ";")
|
||||
for _, data := range split {
|
||||
var uf *comModel.UpFile
|
||||
err := json.Unmarshal([]byte(data), &uf)
|
||||
if err != nil {
|
||||
uf = new(comModel.UpFile)
|
||||
uf.Name = v.QualityName
|
||||
uf.Url = v.QualityDocument
|
||||
}
|
||||
ufList = append(ufList, uf)
|
||||
}
|
||||
}
|
||||
listRes.List[k] = &model.BusQualityListRes{
|
||||
Id: v.Id,
|
||||
QualityName: v.QualityName,
|
||||
QualityExplain: v.QualityExplain,
|
||||
QualityDocumentObj: ufList,
|
||||
QualityType: v.QualityType,
|
||||
ProjectId: v.ProjectId,
|
||||
Status: v.Status,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) QualityFunc(ctx context.Context, req *system.QualityReq) (res *system.QualityRes, err error) {
|
||||
res = new(system.QualityRes)
|
||||
var dictList []*commonEntity.SysDictData
|
||||
g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "quality_type").Scan(&dictList)
|
||||
if len(dictList) > 0 {
|
||||
//1、计算得到数量
|
||||
var oneList []*system.QualityListRes
|
||||
for _, data := range dictList {
|
||||
sql := dao.BusQuality.Ctx(ctx).Where("project_id", req.ProjectId).Where("quality_type", data.DictValue)
|
||||
//2、获取数量
|
||||
count, _ := sql.Count()
|
||||
var twoList = new(system.QualityListRes)
|
||||
twoList.QualityType = data.DictValue
|
||||
twoList.QualityName = data.DictLabel
|
||||
twoList.QualityNumber = count
|
||||
oneList = append(oneList, twoList)
|
||||
}
|
||||
//总数累加
|
||||
num := 0.00
|
||||
for _, dada := range oneList {
|
||||
num = num + float64(dada.QualityNumber)
|
||||
dada.Proportion = "0"
|
||||
}
|
||||
//计算百分比
|
||||
if num != 0 {
|
||||
for _, dada := range oneList {
|
||||
bai := 100.00 / float64(num) * float64(dada.QualityNumber)
|
||||
dada.Proportion = strconv.FormatFloat(bai, 'f', 2, 64)
|
||||
}
|
||||
}
|
||||
res.List = oneList
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) GraphDataListFunc(ctx context.Context, req *system.GraphDataListReq) (listRes *system.GraphDataListRes, err error) {
|
||||
listRes = new(system.GraphDataListRes)
|
||||
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
|
||||
var graphDataList []*system.GraphDataListTwoRes
|
||||
if req.GraphStatus != "0" { //1、GraphStatus非0查询
|
||||
var DataList []*model.BusSafetyListRes
|
||||
g1 := dao.BusSafety.Ctx(ctx).Where("safety_type", req.GraphStatus).Where("project_id", req.ProjectId).OrderDesc("created_at")
|
||||
count, err := g1.Count()
|
||||
listRes.Total = count
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
err = g1.Page(req.PageNum, req.PageSize).Order(order).Scan(&DataList)
|
||||
for _, data := range DataList {
|
||||
var graphDataOne = new(system.GraphDataListTwoRes)
|
||||
graphDataOne.Id = data.Id
|
||||
graphDataOne.Name = data.SafetyName
|
||||
graphDataOne.DateTime = data.CreatedAt
|
||||
graphDataOne.Type = "1"
|
||||
graphDataList = append(graphDataList, graphDataOne)
|
||||
}
|
||||
} else { //2、GraphStatus 0查询 站班会
|
||||
var DataList []*wxModel.SysProjectTeamSquadListRes
|
||||
g1 := wxDao.SysProjectTeamSquad.Ctx(ctx).Where("project_id", req.ProjectId).OrderDesc("created_at")
|
||||
count, _ := g1.Count()
|
||||
listRes.Total = count
|
||||
err = g1.Page(req.PageNum, req.PageSize).Order(order).Scan(&DataList)
|
||||
for _, data := range DataList {
|
||||
var graphDataOne = new(system.GraphDataListTwoRes)
|
||||
graphDataOne.Id = data.Id
|
||||
graphDataOne.Name = "站班会"
|
||||
graphDataOne.DateTime = data.CreatedAt
|
||||
graphDataOne.Type = "0"
|
||||
graphDataList = append(graphDataList, graphDataOne)
|
||||
}
|
||||
}
|
||||
listRes.GraphDataList = graphDataList
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) GraphFunc(ctx context.Context, req *system.GraphReq) (listRes *system.GraphRes, err error) {
|
||||
listRes = new(system.GraphRes)
|
||||
var graphList []*system.GraphListRes
|
||||
|
||||
//1、统计站班会
|
||||
count, err := wxDao.SysProjectTeamSquad.Ctx(ctx).Where("project_id", req.ProjectId).Count()
|
||||
var graphData = new(system.GraphListRes)
|
||||
graphData.GraphStatus = "0"
|
||||
graphData.GraphName = "站班会"
|
||||
graphData.GraphNumber = count
|
||||
graphList = append(graphList, graphData)
|
||||
//2、统计例会表bus_safety
|
||||
var dictList []*commonEntity.SysDictData
|
||||
g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "safety_type").Scan(&dictList)
|
||||
if len(dictList) > 0 {
|
||||
for _, dataList := range dictList {
|
||||
var graphData = new(system.GraphListRes)
|
||||
count, err2 := dao.BusSafety.Ctx(ctx).Where("safety_type", dataList.DictValue).Where("project_id", req.ProjectId).Count()
|
||||
if err2 != nil {
|
||||
return
|
||||
}
|
||||
graphData.GraphStatus = dataList.DictValue
|
||||
graphData.GraphName = dataList.DictLabel
|
||||
graphData.GraphNumber = count
|
||||
graphList = append(graphList, graphData)
|
||||
}
|
||||
}
|
||||
//3、返回数据
|
||||
listRes.GraphList = graphList
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) List(ctx context.Context, req *system.BusQualitySearchReq) (listRes *system.BusQualitySearchRes, err error) {
|
||||
listRes = new(system.BusQualitySearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusQuality.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.BusQuality.Columns().ProjectId, req.ProjectId)
|
||||
}
|
||||
if req.QualityName != "" {
|
||||
m = m.Where(dao.BusQuality.Columns().QualityName+" like ?", "%"+req.QualityName+"%")
|
||||
}
|
||||
if req.QualityType != "" {
|
||||
m = m.Where(dao.BusQuality.Columns().QualityType+" = ?", req.QualityType)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.BusQuality.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusQuality.Columns().CreatedAt+" >=? AND "+dao.BusQuality.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusQualityInfoRes
|
||||
err = m.Fields(system.BusQualitySearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusQualityListRes, len(res))
|
||||
for k, v := range res {
|
||||
//qualityDocument := ([]*comModel.UpFile)(nil)
|
||||
//err = gjson.DecodeTo(v.QualityDocument, &qualityDocument)
|
||||
//liberr.ErrIsNil(ctx, err)
|
||||
listRes.List[k] = &model.BusQualityListRes{
|
||||
Id: v.Id,
|
||||
QualityName: v.QualityName,
|
||||
QualityExplain: v.QualityExplain,
|
||||
QualityDocument: v.QualityDocument,
|
||||
QualityType: v.QualityType,
|
||||
ProjectId: v.ProjectId,
|
||||
Status: v.Status,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) GetById(ctx context.Context, id uint64) (res *model.BusQualityInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
var ufList []*comModel.UpFile
|
||||
err = dao.BusQuality.Ctx(ctx).WithAll().Where(dao.BusQuality.Columns().Id, id).Scan(&res)
|
||||
if err == nil {
|
||||
split := strings.Split(res.QualityDocument, ";")
|
||||
for _, data := range split {
|
||||
var uf *comModel.UpFile
|
||||
err := json.Unmarshal([]byte(data), &uf)
|
||||
if err != nil {
|
||||
uf = new(comModel.UpFile)
|
||||
uf.Name = res.QualityName
|
||||
uf.Url = res.QualityDocument
|
||||
}
|
||||
ufList = append(ufList, uf)
|
||||
}
|
||||
}
|
||||
res.QualityDocumentObj = ufList
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusQualityInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) Add(ctx context.Context, req *system.BusQualityAddReq) (err error) {
|
||||
if len(req.QualityDocument) > 2 {
|
||||
err = errors.New("最多仅支持2个文件!")
|
||||
return err
|
||||
}
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//for _, obj := range req.QualityDocument {
|
||||
// obj.Url, err = libUtils.GetFilesPath(ctx, obj.Url)
|
||||
// liberr.ErrIsNil(ctx, err)
|
||||
//}
|
||||
|
||||
quality := do.BusQuality{
|
||||
QualityName: req.QualityName,
|
||||
QualityExplain: req.QualityExplain,
|
||||
QualityType: req.QualityType,
|
||||
ProjectId: req.ProjectId,
|
||||
}
|
||||
|
||||
if req.WxOrPc != "1" {
|
||||
req.WxOrPc = "2"
|
||||
quality.CreateBy = req.Openid
|
||||
if len(req.QualityDocument) > 0 {
|
||||
for i := range req.QualityDocument {
|
||||
req.QualityDocument[i].Url = strings.Replace(req.QualityDocument[0].Url, "file", "wxfile", 1)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quality.CreateBy = ct.New().GetLoginUser(ctx).Id
|
||||
}
|
||||
quality.UserType = req.WxOrPc
|
||||
if len(req.QualityDocument) > 0 {
|
||||
var str = ""
|
||||
for _, data := range req.QualityDocument {
|
||||
marshal, _ := json.Marshal(data)
|
||||
str = str + string(marshal) + ";"
|
||||
}
|
||||
if len(str) > 0 {
|
||||
quality.QualityDocument = str[:len(str)-1]
|
||||
}
|
||||
}
|
||||
|
||||
_, err = dao.BusQuality.Ctx(ctx).Insert(quality)
|
||||
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) Edit(ctx context.Context, req *system.BusQualityEditReq) (err error) {
|
||||
if len(req.QualityDocument) > 2 {
|
||||
err = errors.New("最多仅支持2个文件!")
|
||||
return err
|
||||
}
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
quality := do.BusQuality{
|
||||
QualityName: req.QualityName,
|
||||
QualityExplain: req.QualityExplain,
|
||||
QualityType: req.QualityType,
|
||||
ProjectId: req.ProjectId,
|
||||
Status: req.Status,
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
}
|
||||
|
||||
if req.WxOrPc != "1" {
|
||||
req.WxOrPc = "2"
|
||||
quality.CreateBy = req.Openid
|
||||
if len(req.QualityDocument) > 0 {
|
||||
for i := range req.QualityDocument {
|
||||
req.QualityDocument[i].Url = strings.Replace(req.QualityDocument[0].Url, "file", "wxfile", 1)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quality.UserType = ct.New().GetLoginUser(ctx).Id
|
||||
}
|
||||
quality.UserType = req.WxOrPc
|
||||
if len(req.QualityDocument) > 0 {
|
||||
var str = ""
|
||||
for _, data := range req.QualityDocument {
|
||||
marshal, _ := json.Marshal(data)
|
||||
str = str + string(marshal) + ";"
|
||||
}
|
||||
if len(str) > 0 {
|
||||
quality.QualityDocument = str[:len(str)-1]
|
||||
}
|
||||
}
|
||||
_, err = dao.BusQuality.Ctx(ctx).WherePri(req.Id).Update(quality)
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusQuality) Delete(ctx context.Context, ids []uint64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusQuality.Ctx(ctx).Delete(dao.BusQuality.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user