feat:完善项目
This commit is contained in:
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"ArmedPolice/app/controller/account"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/config"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -82,13 +83,11 @@ func (a *Account) Login(c *gin.Context) {
|
||||
* }
|
||||
*/
|
||||
func (a *Account) Logout(c *gin.Context) {
|
||||
handle := getSession()(c)
|
||||
// 因跳过中间键,故只能自己去获取token用户信息
|
||||
token := c.GetHeader(config.APIRequestToken)
|
||||
|
||||
session := new(service.Session)
|
||||
session, _ := service.NewAuthToken(token).Auth()
|
||||
|
||||
if handle != nil {
|
||||
session = handle.(*service.Session)
|
||||
}
|
||||
err := account.NewInstance()(session).Logout()
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
@ -89,13 +89,13 @@ func (*Config) Area(c *gin.Context) {
|
||||
* @apiParam {Number} current 当前页
|
||||
* @apiParam {Number} page_size 页展示数
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 数据信息
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.id ID
|
||||
* @apiSuccess (200) {String} data.title 标题名称
|
||||
* @apiSuccess (200) {String} data.remark 备注信息
|
||||
* @apiSuccess (200) {Time} data.created_at 创建时间
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
@ -125,6 +125,30 @@ func (*Config) Breakdown(c *gin.Context) {
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/config/breakdown/add 故障信息添加
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName ConfigBreakdownAdd
|
||||
* @apiGroup Config
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
* @apiHeader {string} Content-Type=application/json 传输方式
|
||||
*
|
||||
* @apiParam {String} title 名称
|
||||
* @apiParam {String} [remark="''"] 备注名称
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Config) BreakdownAdd(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
@ -138,6 +162,31 @@ func (*Config) BreakdownAdd(c *gin.Context) {
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/config/breakdown/edit 故障信息修改
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName ConfigBreakdownEdit
|
||||
* @apiGroup Config
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
* @apiHeader {string} Content-Type=application/json 传输方式
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
* @apiParam {String} title 名称
|
||||
* @apiParam {String} [remark="''"] 备注名称
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Config) BreakdownEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
@ -152,6 +201,29 @@ func (*Config) BreakdownEdit(c *gin.Context) {
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/config/breakdown/delete 故障信息删除
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName ConfigBreakdownDelete
|
||||
* @apiGroup Config
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
* @apiHeader {string} Content-Type=application/json 传输方式
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Config) BreakdownDelete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
|
110
app/api/dashboard.go
Normal file
110
app/api/dashboard.go
Normal file
@ -0,0 +1,110 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/controller/dashboard"
|
||||
"ArmedPolice/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
/**
|
||||
* @apiDefine Dashboard 仪表盘
|
||||
*/
|
||||
|
||||
type Dashboard struct{}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/dashboard 工作台
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName DashboardIndex
|
||||
* @apiGroup Dashboard
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Object} data.workbench 待办事项
|
||||
* @apiSuccess (200) {String} data.workbench.id ID
|
||||
* @apiSuccess (200) {String} data.workbench.equipment_code 设备标识
|
||||
* @apiSuccess (200) {String} data.workbench.equipment_title 设备名称
|
||||
* @apiSuccess (200) {String} data.workbench.breakdown_title 故障信息
|
||||
* @apiSuccess (200) {String} data.workbench.username 用户名
|
||||
* @apiSuccess (200) {Time} data.workbench.created_at 创建时间
|
||||
* @apiSuccess (200) {Object} data.notice 公告信息
|
||||
* @apiSuccess (200) {String} data.notice.id ID
|
||||
* @apiSuccess (200) {String} data.notice.title 公告标题
|
||||
* @apiSuccess (200) {Time} data.notice.created_at 公告创建时间
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* "workbench": [
|
||||
* "id": "",
|
||||
* "equipment_code": "",
|
||||
* "equipment_title": ""
|
||||
* "breakdown_title": ""
|
||||
* "username": ""
|
||||
* "created_at": ""
|
||||
* ]
|
||||
* "notice": [
|
||||
* "id": "",
|
||||
* "title": "",
|
||||
* "created_at": "2021-11-01"
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
func (*Dashboard) Index(c *gin.Context) {
|
||||
data, err := dashboard.NewInstance()(getSession()(c).(*service.Session)).Index()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/dashboard/repair 工单维修信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName DashboardRepair
|
||||
* @apiGroup Dashboard
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} date 具体月份 - 2021-10-01
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Number} data.count 数量
|
||||
* @apiSuccess (200) {Number} data.amount 金额
|
||||
* @apiSuccess (200) {String} data.date 时间
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* {
|
||||
* "count": 0,
|
||||
* "amount": 0,
|
||||
* "date": "2021-11-01"
|
||||
* }...
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (*Dashboard) Repair(c *gin.Context) {
|
||||
form := &struct {
|
||||
Date string `json:"date" form:"date" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := dashboard.NewRepair()(getSession()(c).(*service.Session)).Static(form.Date)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Dashboard) Score(c *gin.Context) {
|
||||
|
||||
}
|
@ -11,8 +11,9 @@ type Manage struct{}
|
||||
type (
|
||||
// manageEquipmentForm 装备参数信息
|
||||
manageEquipmentForm struct {
|
||||
Code string `json:"code" form:"code" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Code string `json:"code" form:"code" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
ImageForm
|
||||
Config string `json:"config" form:"config"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
@ -23,8 +24,12 @@ type (
|
||||
Code string `json:"code" form:"code" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
ImageForm
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
Unit int `json:"unit" form:"Unit" binding:"required"`
|
||||
Price float64 `json:"price" form:"price" binding:"required"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
Unit int `json:"unit" form:"unit" binding:"required"`
|
||||
MaterialID string `json:"material_id" form:"material_id"`
|
||||
SupplierID string `json:"supplier_id" form:"supplier_id"`
|
||||
Stock float64 `json:"stock" form:"stock"`
|
||||
}
|
||||
// manageNoticeForm 公告参数信息
|
||||
manageNoticeForm struct {
|
||||
@ -33,11 +38,26 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (this *manageEquipmentForm) ParentInfo() uint64 {
|
||||
obj := &IDStringForm{ID: this.ParentID}
|
||||
return obj.Convert()
|
||||
}
|
||||
|
||||
func (this *manageMaterialForm) ManufacturerInfo() uint64 {
|
||||
obj := &IDStringForm{ID: this.ManufacturerID}
|
||||
return obj.Convert()
|
||||
}
|
||||
|
||||
func (this *manageMaterialForm) MaterialInfo() uint64 {
|
||||
obj := &IDStringForm{ID: this.MaterialID}
|
||||
return obj.Convert()
|
||||
}
|
||||
|
||||
func (this *manageMaterialForm) SupplierInfo() uint64 {
|
||||
obj := &IDStringForm{ID: this.SupplierID}
|
||||
return obj.Convert()
|
||||
}
|
||||
|
||||
/**
|
||||
* @apiDefine Manage 数据管理
|
||||
*/
|
||||
@ -207,6 +227,7 @@ func (*Manage) EquipmentDetail(c *gin.Context) {
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} parent_id 装备父集ID
|
||||
* @apiParam {String} code 器材编码
|
||||
* @apiParam {String} title 器材名称
|
||||
* @apiParam {String} image 器材图片
|
||||
@ -232,8 +253,8 @@ func (*Manage) EquipmentAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
|
||||
Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
|
||||
Remark: form.Remark,
|
||||
ParentID: form.ParentInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
|
||||
Config: form.Config, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
@ -247,6 +268,7 @@ func (*Manage) EquipmentAdd(c *gin.Context) {
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
* @apiParam {String} parent_id 装备父集ID
|
||||
* @apiParam {String} code 器材编码
|
||||
* @apiParam {String} title 器材名称
|
||||
* @apiParam {String} image 器材图片
|
||||
@ -274,7 +296,7 @@ func (*Manage) EquipmentEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
|
||||
ID: form.Convert(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
|
||||
ID: form.Convert(), ParentID: form.ParentInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
|
||||
Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
@ -432,10 +454,14 @@ func (*Manage) MaterialSelect(c *gin.Context) {
|
||||
*
|
||||
* @apiParam {String} manufacturer_id 制造商ID
|
||||
* @apiParam {String} code 器材编码
|
||||
* @apiParam {float} price 价格
|
||||
* @apiParam {String} title 器材名称
|
||||
* @apiParam {String} image 器材图片
|
||||
* @apiParam {Number} unit 单位
|
||||
* @apiParam {String} remark 备注
|
||||
* @apiParam {String} material_id 器材ID
|
||||
* @apiParam {String} supplier_id 供应商ID
|
||||
* @apiParam {String} [stock=0] 库存
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
@ -458,7 +484,8 @@ func (*Manage) MaterialAdd(c *gin.Context) {
|
||||
}
|
||||
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||
ManufacturerID: form.ManufacturerInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
|
||||
Remark: form.Remark, Unit: form.Unit,
|
||||
Price: form.Price, Remark: form.Remark, Unit: form.Unit, MaterialID: form.MaterialInfo(),
|
||||
SupplierID: form.SupplierInfo(), Stock: form.Stock,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
@ -474,6 +501,7 @@ func (*Manage) MaterialAdd(c *gin.Context) {
|
||||
* @apiParam {String} id ID
|
||||
* @apiParam {String} manufacturer_id 制造商ID
|
||||
* @apiParam {String} code 器材编码
|
||||
* @apiParam {float} price 价格
|
||||
* @apiParam {String} title 器材名称
|
||||
* @apiParam {String} image 器材图片
|
||||
* @apiParam {Number} unit 单位
|
||||
@ -502,7 +530,7 @@ func (*Manage) MaterialEdit(c *gin.Context) {
|
||||
}
|
||||
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||
ID: form.Convert(), ManufacturerID: form.ManufacturerInfo(), Code: form.Code, Title: form.Title,
|
||||
Image: form.FilterImageURL(), Remark: form.Remark, Unit: form.Unit,
|
||||
Price: form.Price, Image: form.FilterImageURL(), Remark: form.Remark, Unit: form.Unit,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ func initModel() {
|
||||
// 日志管理
|
||||
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
||||
&synchronized{iModel: model.NewSysBreakdown()},
|
||||
// 公告管理
|
||||
&synchronized{iModel: model.NewManageNotice()},
|
||||
// 功能信息
|
||||
&synchronized{iModel: model.NewManageSupplier()},
|
||||
&synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()},
|
||||
@ -72,7 +74,7 @@ func initCacheMode() {
|
||||
}
|
||||
}
|
||||
function(
|
||||
&caches{iModel: model.NewSysTenant(), iValues: func() interface{} {
|
||||
&caches{iModel: model.NewSysConfig(), iValues: func() interface{} {
|
||||
out := make([]*model.SysConfig, 0)
|
||||
_ = model.Find(model.NewSysConfig(), &out)
|
||||
return out
|
||||
@ -86,6 +88,8 @@ func initCacheMode() {
|
||||
}
|
||||
|
||||
func Init() {
|
||||
initModel()
|
||||
if *config.Init {
|
||||
initModel()
|
||||
}
|
||||
initCacheMode()
|
||||
}
|
||||
|
@ -60,23 +60,22 @@ type Area struct {
|
||||
}
|
||||
|
||||
type AreaInfo struct {
|
||||
Province string `json:"province"`
|
||||
City string `json:"city"`
|
||||
District string `json:"district"`
|
||||
Address string `json:"address"`
|
||||
ProvinceName string `json:"province_name"`
|
||||
CityName string `json:"city_name"`
|
||||
DistrictName string `json:"district_name"`
|
||||
}
|
||||
|
||||
func (m *Area) Format() *AreaInfo {
|
||||
out := &AreaInfo{Address: m.Address}
|
||||
out := &AreaInfo{}
|
||||
|
||||
if m.Province != "" {
|
||||
out.Province = config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province]
|
||||
out.ProvinceName = config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province]
|
||||
}
|
||||
if m.City != "" {
|
||||
out.City = config.SettingAreaInfo[m.Province][m.City]
|
||||
out.CityName = config.SettingAreaInfo[m.Province][m.City]
|
||||
}
|
||||
if m.District != "" {
|
||||
out.District = config.SettingAreaInfo[m.City][m.District]
|
||||
out.DistrictName = config.SettingAreaInfo[m.City][m.District]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ package model
|
||||
type ManageMaterialSupplier struct {
|
||||
Model
|
||||
MaterialID uint64 `gorm:"column:material_id;type:int(11);default:0;comment:器材ID" json:"material_id"`
|
||||
SupplierID uint64 `gorm:"column:supplier_id;type:int;default:0;comment:供应商ID" json:"-"`
|
||||
SupplierID uint64 `gorm:"column:supplier_id;type:int(11);default:0;comment:供应商ID" json:"-"`
|
||||
Stock float64 `gorm:"column:stock;type:decimal(10,2);default:0;comment:库存数" json:"stock"`
|
||||
FrozenStock float64 `gorm:"column:frozen_stock;type:decimal(10,2);default:0;comment:冻结的库存数" json:"-"`
|
||||
ModelDeleted
|
||||
|
@ -70,6 +70,9 @@ func (m *Model) GetID() uint64 {
|
||||
}
|
||||
|
||||
func (m *Model) GetEncodeID() string {
|
||||
if m.ID <= 0 {
|
||||
return ""
|
||||
}
|
||||
return utils.HASHIDEncode(int(m.ID))
|
||||
}
|
||||
|
||||
@ -338,6 +341,25 @@ func Find(model IModel, out interface{}, where ...*ModelWhereOrder) error {
|
||||
return db.Find(out).Error
|
||||
}
|
||||
|
||||
func FindLimit(model IModel, out interface{}, limit int, where ...*ModelWhereOrder) error {
|
||||
db := orm.GetDB().Table(model.TableName())
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
if wo.Where != nil {
|
||||
db = db.Where(wo.Where.Condition, wo.Where.Value)
|
||||
}
|
||||
if wo.Order != nil {
|
||||
db = db.Order(fmt.Sprintf("%s %s", wo.Order.Field, wo.Order.Mode))
|
||||
}
|
||||
}
|
||||
}
|
||||
if db.Migrator().HasColumn(model, FieldsForDeleted) {
|
||||
db = db.Where(FieldsForDeleted, DeleteStatusForNot)
|
||||
}
|
||||
return db.Offset(0).Limit(limit).Find(out).Error
|
||||
}
|
||||
|
||||
func Scan(model IModel, out interface{}, where ...*ModelWhereOrder) error {
|
||||
db := orm.GetDB().Table(model.TableName())
|
||||
|
||||
@ -376,6 +398,25 @@ func ScanFields(model IModel, out interface{}, fields []string, where ...*ModelW
|
||||
return db.Scan(out).Error
|
||||
}
|
||||
|
||||
func ScanLimitFields(model IModel, out interface{}, fields []string, limit int, where ...*ModelWhereOrder) error {
|
||||
db := orm.GetDB().Table(model.TableName()).Select(fields)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
if wo.Where != nil {
|
||||
db = db.Where(wo.Where.Condition, wo.Where.Value)
|
||||
}
|
||||
if wo.Order != nil {
|
||||
db = db.Order(fmt.Sprintf("%s %s", wo.Order.Field, wo.Order.Mode))
|
||||
}
|
||||
}
|
||||
}
|
||||
if db.Migrator().HasColumn(model, FieldsForDeleted) {
|
||||
db = db.Where(FieldsForDeleted, DeleteStatusForNot)
|
||||
}
|
||||
return db.Offset(0).Limit(limit).Scan(out).Error
|
||||
}
|
||||
|
||||
func Pluck(model IModel, field string, out interface{}, where ...*ModelWhere) error {
|
||||
db := orm.GetDB().Table(model.TableName())
|
||||
|
||||
|
@ -10,6 +10,7 @@ type WorkInstance struct {
|
||||
Model
|
||||
ModelTenant
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:null;comment:工单单号" json:"order_no"`
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Kind WorkInstanceKind `gorm:"column:kind;type:tinyint(1);default:0;comment:工单类型" json:"kind"`
|
||||
Title string `gorm:"column:title;type:varchar(30);default:null;comment:工单标题" json:"title"`
|
||||
EquipmentID uint64 `gorm:"column:equipment_id;type:int(11);default:0;comment:装备ID" json:"equipment_id"`
|
||||
|
@ -73,7 +73,7 @@ func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string)
|
||||
|
||||
// Logout 退出请求
|
||||
func (c *Instance) Logout() error {
|
||||
if c.UID > 0 {
|
||||
if c.Session != nil && c.UID > 0 {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
service.HubMessage.UnregisterHandle(service.NewWebsocket(c.UIDToString(), nil))
|
||||
}
|
||||
|
118
app/controller/dashboard/instance.go
Normal file
118
app/controller/dashboard/instance.go
Normal file
@ -0,0 +1,118 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct{ *service.Session }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 列表信息
|
||||
InstanceInfo struct {
|
||||
Workbench []*instanceInfoForWorkbench `json:"workbench"`
|
||||
Notice []*instanceInfoForNotice `json:"notice"`
|
||||
}
|
||||
// instanceInfoForWorkbench 待办事项
|
||||
instanceInfoForWorkbench struct {
|
||||
basic.CommonIDString
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
Username string `json:"username"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
// instanceInfoForNotice 公告信息
|
||||
instanceInfoForNotice struct {
|
||||
basic.CommonIDString
|
||||
Title string `json:"title"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
)
|
||||
|
||||
var defaultDataLimit int = 10
|
||||
|
||||
// Workbench 待办信息
|
||||
func (c *Instance) Workbench(limit int) ([]*instanceInfoForWorkbench, error) {
|
||||
mSysUserRole := model.NewSysUserRole()
|
||||
roleIDs := make([]string, 0)
|
||||
|
||||
err := model2.Pluck(mSysUserRole.SysUserRole, "role_id", &roleIDs, model2.NewWhere("uid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
|
||||
out := make([]*model.WorkInstanceInfo, 0)
|
||||
|
||||
if out, err = mWorkInstance.Workbench(&model.WorkbenchCondition{
|
||||
UID: c.UIDToString(), RoleIDs: roleIDs,
|
||||
}, limit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*instanceInfoForWorkbench, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mWorkInstance.SetID(v.ID)
|
||||
|
||||
list = append(list, &instanceInfoForWorkbench{
|
||||
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()},
|
||||
EquipmentCode: v.EquipmentCode,
|
||||
EquipmentTitle: v.EquipmentTitle,
|
||||
BreakdownTitle: v.BreakdownTitle,
|
||||
Username: v.Username,
|
||||
CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// notice 通知信息
|
||||
func (c *Instance) notice(limit int) ([]*instanceInfoForNotice, error) {
|
||||
mManageNotice := model.NewManageNotice()
|
||||
|
||||
out := make([]*model2.ManageNotice, 0)
|
||||
|
||||
if err := model2.ScanLimitFields(mManageNotice.ManageNotice, &out, []string{"id", "title", "created_at"}, limit, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*instanceInfoForNotice, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &instanceInfoForNotice{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
Title: v.Title,
|
||||
CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Index 首页信息
|
||||
func (c *Instance) Index() (*InstanceInfo, error) {
|
||||
out := new(InstanceInfo)
|
||||
var err error
|
||||
|
||||
if out.Workbench, err = c.Workbench(defaultDataLimit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Notice, err = c.notice(defaultDataLimit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{session}
|
||||
}
|
||||
}
|
66
app/controller/dashboard/repair.go
Normal file
66
app/controller/dashboard/repair.go
Normal file
@ -0,0 +1,66 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Repair struct{ *service.Session }
|
||||
|
||||
type RepairHandle func(session *service.Session) *Repair
|
||||
|
||||
// Static 统计
|
||||
func (c *Repair) Static(date string) (interface{}, error) {
|
||||
currentAt := time.Now()
|
||||
|
||||
if date != "" {
|
||||
currentAt = utils.DataTimeForLayout(date, "2006-01")
|
||||
}
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
monthBegin := utils.MonthBeginAt(int(currentAt.Year()), int(currentAt.Month()))
|
||||
monthEnd := utils.MonthFinishAt(int(currentAt.Year()), int(currentAt.Month()))
|
||||
|
||||
where = append(where, model2.NewWhereSectionTime("w.created_at", []string{
|
||||
utils.FormatDate(monthBegin),
|
||||
utils.FormatDate(monthEnd)})...)
|
||||
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
|
||||
out, err := mWorkInstance.Static(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_map := make(map[string]*model.WorkInstanceStaticInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
_map[v.Date] = v
|
||||
}
|
||||
list := make([]*model.WorkInstanceStaticInfo, 0)
|
||||
|
||||
for i := 0; i < monthEnd.Day(); i++ {
|
||||
if i > 0 {
|
||||
monthBegin = monthBegin.AddDate(0, 0, 1)
|
||||
}
|
||||
_date := utils.FormatDate(monthBegin)
|
||||
|
||||
if data, has := _map[_date]; has {
|
||||
list = append(list, data)
|
||||
continue
|
||||
}
|
||||
list = append(list, &model.WorkInstanceStaticInfo{
|
||||
Date: _date,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func NewRepair() RepairHandle {
|
||||
return func(session *service.Session) *Repair {
|
||||
return &Repair{session}
|
||||
}
|
||||
}
|
20
app/controller/dashboard/supplier.go
Normal file
20
app/controller/dashboard/supplier.go
Normal file
@ -0,0 +1,20 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/service"
|
||||
)
|
||||
|
||||
type Supplier struct{ *service.Session }
|
||||
|
||||
type SupplierHandle func(session *service.Session) *Supplier
|
||||
|
||||
func (c *Supplier) StaticScore() (*basic.PageDataResponse, error) {
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
}
|
||||
|
||||
func NewSupplier() SupplierHandle {
|
||||
return func(session *service.Session) *Supplier {
|
||||
return &Supplier{session}
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@ type (
|
||||
}
|
||||
// EquipmentParams 装备参数信息
|
||||
EquipmentParams struct {
|
||||
ID uint64
|
||||
ID, ParentID uint64
|
||||
Code, Title, Image, Config, Remark string
|
||||
}
|
||||
)
|
||||
@ -186,6 +186,7 @@ func (c *Equipment) Form(params *EquipmentParams) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
mManageEquipment.ParentID = params.ParentID
|
||||
mManageEquipment.Code = params.Code
|
||||
mManageEquipment.Title = params.Title
|
||||
mManageEquipment.Image.Image = params.Image
|
||||
@ -210,11 +211,7 @@ func (c *Equipment) Form(params *EquipmentParams) error {
|
||||
func (c *Equipment) Delete(id uint64) error {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
mManageEquipment.ID = id
|
||||
|
||||
if err := model2.Delete(mManageEquipment.ManageEquipment); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return model2.Delete(mManageEquipment.ManageEquipment)
|
||||
}
|
||||
|
||||
func NewEquipment() EquipmentHandle {
|
||||
|
@ -6,7 +6,9 @@ import (
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/config"
|
||||
"ArmedPolice/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -23,13 +25,17 @@ type (
|
||||
// MaterialInfo 基本信息
|
||||
MaterialInfo struct {
|
||||
basic.CommonIDString
|
||||
ManufacturerID string `json:"manufacturer_id"`
|
||||
*model.ManageMaterialInfo
|
||||
}
|
||||
// MaterialParams 基本参数
|
||||
MaterialParams struct {
|
||||
ID, ManufacturerID uint64
|
||||
Code, Title, Image, Remark string
|
||||
Unit int
|
||||
ID, ManufacturerID, MaterialID uint64
|
||||
Code, Title, Image, Remark string
|
||||
Unit int
|
||||
Price float64
|
||||
SupplierID uint64
|
||||
Stock float64
|
||||
}
|
||||
)
|
||||
|
||||
@ -62,7 +68,7 @@ func (c *Material) List(manufacturerID, supplierID uint64, code, title string, p
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mManageMaterial.Materials(page, pageSize, &count)
|
||||
out, err := mManageMaterial.Materials(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -70,9 +76,14 @@ func (c *Material) List(manufacturerID, supplierID uint64, code, title string, p
|
||||
list := make([]*MaterialInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mManageMaterial.SetID(v.ManageMaterial.ManufacturerID)
|
||||
|
||||
v.Stock -= v.FrozenStock
|
||||
v.Image.Image = v.Analysis(config.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &MaterialInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
ManufacturerID: mManageMaterial.GetEncodeID(),
|
||||
ManageMaterialInfo: v,
|
||||
})
|
||||
}
|
||||
@ -122,9 +133,13 @@ func (c *Material) Form(params *MaterialParams) error {
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
}
|
||||
if mManageMaterial.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
}
|
||||
mManageMaterial.ManufacturerID = params.ManufacturerID
|
||||
mManageMaterial.Code = params.Code
|
||||
mManageMaterial.Price = params.Price
|
||||
mManageMaterial.Title = params.Title
|
||||
mManageMaterial.Unit = model2.ManageMaterialUnit(params.Unit)
|
||||
mManageMaterial.Remark = params.Remark
|
||||
@ -133,15 +148,44 @@ func (c *Material) Form(params *MaterialParams) error {
|
||||
mManageMaterial.UpdatedAt = time.Now()
|
||||
return model2.Updates(mManageMaterial.ManageMaterial, mManageMaterial.ManageMaterial)
|
||||
}
|
||||
isExist, err := params.isExistForCode(mManageMaterial, c.TenantID)
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if params.MaterialID <= 0 {
|
||||
isExist, err := params.isExistForCode(mManageMaterial, c.TenantID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
mManageMaterial.TenantID = c.TenantID
|
||||
|
||||
if err = model2.Create(mManageMaterial.ManageMaterial, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
params.MaterialID = mManageMaterial.ID
|
||||
} else {
|
||||
if params.SupplierID <= 0 {
|
||||
return errors.New("操作错误,未知的供应商信息")
|
||||
}
|
||||
}
|
||||
mManageMaterialSupplier := model.NewManageMaterialSupplier()
|
||||
|
||||
var count int64
|
||||
|
||||
err := model2.Count(mManageMaterialSupplier.ManageMaterialSupplier, &count, model2.NewWhere("material_id", params.MaterialID),
|
||||
model2.NewWhere("supplier_id", params.SupplierID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,该器材已含有供应商信息")
|
||||
}
|
||||
mManageMaterialSupplier.MaterialID = params.MaterialID
|
||||
mManageMaterialSupplier.SupplierID = params.SupplierID
|
||||
mManageMaterialSupplier.Stock = params.Stock
|
||||
return model2.Create(mManageMaterialSupplier.ManageMaterialSupplier, tx)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
mManageMaterial.TenantID = c.TenantID
|
||||
return model2.Create(mManageMaterial.ManageMaterial)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
|
@ -15,8 +15,10 @@ type InstanceHandle func(session *service.Session) *Instance
|
||||
type (
|
||||
// InstanceInfo 租户信息
|
||||
InstanceInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
*model2.Area
|
||||
*model2.AreaInfo
|
||||
Remark string `json:"remark"`
|
||||
Children []*InstanceInfo `json:"children"`
|
||||
@ -29,17 +31,20 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Instance) tree(src []*model2.SysTenant, parentID uint64) []*InstanceInfo {
|
||||
func (c *Instance) tree(iModel model2.IModel, src []*model2.SysTenant, parentID uint64) []*InstanceInfo {
|
||||
out := make([]*InstanceInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
iModel.SetID(v.ParentID)
|
||||
out = append(out, &InstanceInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ParentID: iModel.GetEncodeID(),
|
||||
Name: v.Name,
|
||||
Area: &v.Area,
|
||||
AreaInfo: v.Area.Format(),
|
||||
Remark: v.Remark,
|
||||
Children: c.tree(src, v.ID),
|
||||
Children: c.tree(iModel, src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -55,7 +60,7 @@ func (c *Instance) List() ([]*InstanceInfo, error) {
|
||||
if err := model2.Find(mSysTenant.SysTenant, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
return c.tree(mSysTenant.SysTenant, out, 0), nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
|
@ -113,7 +113,7 @@ func (c *Instance) Person(materialID uint64, kind, page, pageSize int) (*basic.P
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mWorkInstance.Persons(c.UID, model2.WorkScheduleKindForRepair, page, pageSize, &count, where...)
|
||||
out, err := mWorkInstance.Persons(c.UID, page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -155,7 +155,7 @@ func (c *Instance) Workbench(materialID uint64, kind, page, pageSize int) (*basi
|
||||
|
||||
out := make([]*model.WorkInstanceInfo, 0)
|
||||
|
||||
if out, err = mWorkInstance.Workbench(&model.WorkbenchCondition{
|
||||
if out, err = mWorkInstance.Workbenchs(&model.WorkbenchCondition{
|
||||
UID: c.UIDToString(), RoleIDs: roleIDs,
|
||||
}, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
@ -202,6 +202,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
}
|
||||
// 工单信息
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
mWorkInstance.UID = c.UID
|
||||
mWorkInstance.Kind = model2.WorkInstanceKind(params.Kind)
|
||||
mWorkInstance.Title = params.Title
|
||||
mWorkInstance.EquipmentID = params.EquipmentID
|
||||
|
@ -21,8 +21,10 @@ type (
|
||||
}
|
||||
ManageMaterialInfo struct {
|
||||
*model.ManageMaterial
|
||||
ManufacturerName string `json:"manufacturer_name"` // 制造商
|
||||
SupplierName string `json:"supplier_name"` // 合作商
|
||||
Stock float64 `json:"stock"`
|
||||
FrozenStock float64 `json:"frozen_stock"`
|
||||
ManufacturerName string `json:"manufacturer_name"` // 制造商
|
||||
SupplierName string `json:"supplier_name"` // 合作商
|
||||
}
|
||||
)
|
||||
|
||||
@ -53,11 +55,12 @@ func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*m
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||
Select("m.*", "manufacturer.name AS manufacturer_name", "s.name AS supplier_name").
|
||||
Select("m.*", "manufacturer.name AS manufacturer_name", "s.name AS supplier_name", "m_s.stock", "m_s.frozen_stock").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS manufacturer ON m.manufacturer_id = manufacturer.id", mManageSupplier.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m_s ON m.id = m_s.material_id AND m_s.is_deleted = %d",
|
||||
model.NewManageMaterialSupplier().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m_s.supplier_id = s.id", mManageSupplier.TableName()))
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m_s.supplier_id = s.id", mManageSupplier.TableName())).
|
||||
Where("m.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
@ -69,7 +72,7 @@ func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*m
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
if err := db.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
|
@ -36,5 +36,5 @@ func (m *ManageMaterialSupplier) Basic(where ...*model.ModelWhere) ([]*ManageMat
|
||||
}
|
||||
|
||||
func NewManageMaterialSupplier() *ManageMaterialSupplier {
|
||||
return &ManageMaterialSupplier{}
|
||||
return &ManageMaterialSupplier{model.NewManageMaterialSupplier()}
|
||||
}
|
||||
|
@ -12,20 +12,29 @@ type WorkInstance struct {
|
||||
*model.WorkInstance
|
||||
}
|
||||
|
||||
// WorkInstanceInfo 基本信息
|
||||
type WorkInstanceInfo struct {
|
||||
ID uint64 `json:"-"`
|
||||
Title string `json:"title"`
|
||||
Kind model.WorkInstanceKind `json:"kind"`
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
ScheduleTitle string `json:"schedule_title"`
|
||||
Priority int `json:"priority"`
|
||||
Distribution string `json:"distribution"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
type (
|
||||
// WorkInstanceInfo 基本信息
|
||||
WorkInstanceInfo struct {
|
||||
ID uint64 `json:"-"`
|
||||
Title string `json:"title"`
|
||||
Kind model.WorkInstanceKind `json:"kind"`
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
ScheduleTitle string `json:"schedule_title"`
|
||||
Priority int `json:"priority"`
|
||||
Distribution string `json:"distribution"`
|
||||
Status int `json:"status"`
|
||||
Username string `json:"username"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
// WorkInstanceStaticInfo 基本统计信息
|
||||
WorkInstanceStaticInfo struct {
|
||||
Count int64 `json:"count"`
|
||||
Amount float64 `json:"amount"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
)
|
||||
|
||||
// WorkbenchCondition 工作台条件
|
||||
type WorkbenchCondition struct {
|
||||
@ -33,6 +42,13 @@ type WorkbenchCondition struct {
|
||||
RoleIDs []string
|
||||
}
|
||||
|
||||
func (m *WorkbenchCondition) roleInfo() string {
|
||||
if len(m.RoleIDs) <= 0 {
|
||||
return "''"
|
||||
}
|
||||
return strings.Join(m.RoleIDs, ",")
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (m *WorkInstance) Detail(id uint64) (*WorkInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
@ -56,9 +72,10 @@ func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*mod
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.title", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
"(SELECT GROUP_CONCAT(s_b.title) FROM ( SELECT id, title FROM sys_breakdown) AS s_b WHERE FIND_IN_SET( s_b.id, w.breakdown )) AS breakdown_title",
|
||||
"s.title AS schedule_title", "w.status", "w.created_at").
|
||||
"s.title AS schedule_title", "w.status", "u.name AS username", "w.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.schedule = s.id", model.NewWorkSchedule().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON w.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
@ -79,20 +96,15 @@ func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*mod
|
||||
}
|
||||
|
||||
// Persons 个人信息
|
||||
func (m *WorkInstance) Persons(uid uint64, kind model.WorkScheduleKind, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
mWorkSchedule := model.NewWorkSchedule()
|
||||
func (m *WorkInstance) Persons(uid uint64, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
|
||||
db := orm.GetDB().Table(model.NewWorkProgress().TableName()+" AS p").
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.title", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
"(SELECT GROUP_CONCAT(s_b.title) FROM ( SELECT id, title FROM sys_breakdown) AS s_b WHERE FIND_IN_SET( s_b.id, w.breakdown )) AS breakdown_title",
|
||||
"s.title AS schedule_title", "w.status", "w.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS w ON p.work_id = w.id", m.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT id, title FROM %s WHERE kind = %d ORDER BY stage ASC, step ASC limit 1) AS s ON p.schedule_id = s.id",
|
||||
mWorkSchedule.TableName(), kind)).
|
||||
Where("p.is_deleted = ? AND w.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot).
|
||||
Where("p.uid = ?", uid).
|
||||
Where("s.id > ?", 0)
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.schedule = s.id", model.NewWorkSchedule().TableName())).
|
||||
Where("w.uid = ? AND w.is_deleted = ?", uid, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
@ -111,7 +123,7 @@ func (m *WorkInstance) Persons(uid uint64, kind model.WorkScheduleKind, page, pa
|
||||
}
|
||||
|
||||
// Workbench 个人信息
|
||||
func (m *WorkInstance) Workbench(condition *WorkbenchCondition, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
func (m *WorkInstance) Workbench(condition *WorkbenchCondition, limit int, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
mWorkSchedule := model.NewWorkSchedule()
|
||||
|
||||
_condition := fmt.Sprintf(`CASE %s
|
||||
@ -123,7 +135,44 @@ ELSE "" END`, "s.target",
|
||||
model.WorkScheduleTargetForPerson,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForPerson, condition.UID,
|
||||
model.WorkScheduleTargetForRole,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForRole, strings.Join(condition.RoleIDs, ","))
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForRole, condition.roleInfo())
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.title", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
"(SELECT GROUP_CONCAT(s_b.title) FROM (SELECT id, title FROM sys_breakdown) AS s_b WHERE FIND_IN_SET( s_b.id, w.breakdown )) AS breakdown_title",
|
||||
"s.title AS schedule_title", "w.status", "u.name AS username", "w.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.schedule = s.id", mWorkSchedule.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON w.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Where(fmt.Sprintf("FIND_IN_SET(w.schedule, %s)", _condition))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*WorkInstanceInfo, 0)
|
||||
|
||||
if err := db.Order("w.id " + model.OrderModeToDesc).Limit(limit).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *WorkInstance) Workbenchs(condition *WorkbenchCondition, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
mWorkSchedule := model.NewWorkSchedule()
|
||||
|
||||
_condition := fmt.Sprintf(`CASE %s
|
||||
WHEN %d THEN
|
||||
(SELECT GROUP_CONCAT(a.id) FROM (SELECT id FROM %s WHERE target = %d AND target_value IN (%s)) AS a)
|
||||
WHEN %d THEN
|
||||
(SELECT GROUP_CONCAT(a.id) FROM (SELECT id FROM %s WHERE target = %d AND target_value IN (%s)) AS a)
|
||||
ELSE "" END`, "s.target",
|
||||
model.WorkScheduleTargetForPerson,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForPerson, condition.UID,
|
||||
model.WorkScheduleTargetForRole,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForRole, condition.roleInfo())
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.title", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
@ -150,6 +199,27 @@ ELSE "" END`, "s.target",
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *WorkInstance) Static(where ...*model.ModelWhere) ([]*WorkInstanceStaticInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("COUNT(w.id) AS count", "SUM(m.price * w_m.material_number) AS amount",
|
||||
"SUBSTRING(w.created_at, 1, 10) AS date").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS w_m ON w.id = w_m.work_id", model.NewWorkMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON w_m.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*WorkInstanceStaticInfo, 0)
|
||||
|
||||
if err := db.Group("SUBSTRING(w.created_at, 1, 10)").Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewWorkInstance() *WorkInstance {
|
||||
return &WorkInstance{model.NewWorkInstance()}
|
||||
}
|
||||
|
Reference in New Issue
Block a user