feat:完善项目
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@
|
|||||||
.idea/
|
.idea/
|
||||||
doc/
|
doc/
|
||||||
log/
|
log/
|
||||||
|
dist/
|
||||||
cmd/ctl/main
|
cmd/ctl/main
|
||||||
cmd/ctl/ctl
|
cmd/ctl/ctl
|
||||||
main
|
main
|
||||||
|
@ -3,6 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"ArmedPolice/app/controller/account"
|
"ArmedPolice/app/controller/account"
|
||||||
"ArmedPolice/app/service"
|
"ArmedPolice/app/service"
|
||||||
|
"ArmedPolice/config"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,13 +83,11 @@ func (a *Account) Login(c *gin.Context) {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
func (a *Account) Logout(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()
|
err := account.NewInstance()(session).Logout()
|
||||||
APIResponse(err)(c)
|
APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
@ -89,13 +89,13 @@ func (*Config) Area(c *gin.Context) {
|
|||||||
* @apiParam {Number} current 当前页
|
* @apiParam {Number} current 当前页
|
||||||
* @apiParam {Number} page_size 页展示数
|
* @apiParam {Number} page_size 页展示数
|
||||||
*
|
*
|
||||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
* @apiSuccess (200) {Object} data 数据信息
|
||||||
* @apiSuccess (200) {String} msg 成功提示
|
|
||||||
* @apiSuccess (200) {Array} data 数据信息
|
|
||||||
* @apiSuccess (200) {String} data.id ID
|
* @apiSuccess (200) {String} data.id ID
|
||||||
* @apiSuccess (200) {String} data.title 标题名称
|
* @apiSuccess (200) {String} data.title 标题名称
|
||||||
* @apiSuccess (200) {String} data.remark 备注信息
|
* @apiSuccess (200) {String} data.remark 备注信息
|
||||||
* @apiSuccess (200) {Time} data.created_at 创建时间
|
* @apiSuccess (200) {Time} data.created_at 创建时间
|
||||||
|
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||||
|
* @apiSuccess (200) {String} msg 成功提示
|
||||||
*
|
*
|
||||||
* @apiSuccessExample {json} Success response:
|
* @apiSuccessExample {json} Success response:
|
||||||
* HTTPS 200 OK
|
* HTTPS 200 OK
|
||||||
@ -125,6 +125,30 @@ func (*Config) Breakdown(c *gin.Context) {
|
|||||||
APIResponse(err, data)(c)
|
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) {
|
func (*Config) BreakdownAdd(c *gin.Context) {
|
||||||
form := &struct {
|
form := &struct {
|
||||||
Title string `json:"title" form:"title" binding:"required"`
|
Title string `json:"title" form:"title" binding:"required"`
|
||||||
@ -138,6 +162,31 @@ func (*Config) BreakdownAdd(c *gin.Context) {
|
|||||||
APIResponse(err)(c)
|
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) {
|
func (*Config) BreakdownEdit(c *gin.Context) {
|
||||||
form := &struct {
|
form := &struct {
|
||||||
IDStringForm
|
IDStringForm
|
||||||
@ -152,6 +201,29 @@ func (*Config) BreakdownEdit(c *gin.Context) {
|
|||||||
APIResponse(err)(c)
|
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) {
|
func (*Config) BreakdownDelete(c *gin.Context) {
|
||||||
form := new(IDStringForm)
|
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 (
|
type (
|
||||||
// manageEquipmentForm 装备参数信息
|
// manageEquipmentForm 装备参数信息
|
||||||
manageEquipmentForm struct {
|
manageEquipmentForm struct {
|
||||||
Code string `json:"code" form:"code" binding:"required"`
|
ParentID string `json:"parent_id" form:"parent_id"`
|
||||||
Title string `json:"title" form:"title" binding:"required"`
|
Code string `json:"code" form:"code" binding:"required"`
|
||||||
|
Title string `json:"title" form:"title" binding:"required"`
|
||||||
ImageForm
|
ImageForm
|
||||||
Config string `json:"config" form:"config"`
|
Config string `json:"config" form:"config"`
|
||||||
Remark string `json:"remark" form:"remark"`
|
Remark string `json:"remark" form:"remark"`
|
||||||
@ -23,8 +24,12 @@ type (
|
|||||||
Code string `json:"code" form:"code" binding:"required"`
|
Code string `json:"code" form:"code" binding:"required"`
|
||||||
Title string `json:"title" form:"title" binding:"required"`
|
Title string `json:"title" form:"title" binding:"required"`
|
||||||
ImageForm
|
ImageForm
|
||||||
Remark string `json:"remark" form:"remark"`
|
Price float64 `json:"price" form:"price" binding:"required"`
|
||||||
Unit int `json:"unit" form:"Unit" 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 公告参数信息
|
||||||
manageNoticeForm struct {
|
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 {
|
func (this *manageMaterialForm) ManufacturerInfo() uint64 {
|
||||||
obj := &IDStringForm{ID: this.ManufacturerID}
|
obj := &IDStringForm{ID: this.ManufacturerID}
|
||||||
return obj.Convert()
|
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 数据管理
|
* @apiDefine Manage 数据管理
|
||||||
*/
|
*/
|
||||||
@ -207,6 +227,7 @@ func (*Manage) EquipmentDetail(c *gin.Context) {
|
|||||||
*
|
*
|
||||||
* @apiHeader {string} x-token token
|
* @apiHeader {string} x-token token
|
||||||
*
|
*
|
||||||
|
* @apiParam {String} parent_id 装备父集ID
|
||||||
* @apiParam {String} code 器材编码
|
* @apiParam {String} code 器材编码
|
||||||
* @apiParam {String} title 器材名称
|
* @apiParam {String} title 器材名称
|
||||||
* @apiParam {String} image 器材图片
|
* @apiParam {String} image 器材图片
|
||||||
@ -232,8 +253,8 @@ func (*Manage) EquipmentAdd(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
|
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
|
||||||
Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
|
ParentID: form.ParentInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
|
||||||
Remark: form.Remark,
|
Config: form.Config, Remark: form.Remark,
|
||||||
})
|
})
|
||||||
APIResponse(err)(c)
|
APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
@ -247,6 +268,7 @@ func (*Manage) EquipmentAdd(c *gin.Context) {
|
|||||||
* @apiHeader {string} x-token token
|
* @apiHeader {string} x-token token
|
||||||
*
|
*
|
||||||
* @apiParam {String} id ID
|
* @apiParam {String} id ID
|
||||||
|
* @apiParam {String} parent_id 装备父集ID
|
||||||
* @apiParam {String} code 器材编码
|
* @apiParam {String} code 器材编码
|
||||||
* @apiParam {String} title 器材名称
|
* @apiParam {String} title 器材名称
|
||||||
* @apiParam {String} image 器材图片
|
* @apiParam {String} image 器材图片
|
||||||
@ -274,7 +296,7 @@ func (*Manage) EquipmentEdit(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
|
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,
|
Remark: form.Remark,
|
||||||
})
|
})
|
||||||
APIResponse(err)(c)
|
APIResponse(err)(c)
|
||||||
@ -432,10 +454,14 @@ func (*Manage) MaterialSelect(c *gin.Context) {
|
|||||||
*
|
*
|
||||||
* @apiParam {String} manufacturer_id 制造商ID
|
* @apiParam {String} manufacturer_id 制造商ID
|
||||||
* @apiParam {String} code 器材编码
|
* @apiParam {String} code 器材编码
|
||||||
|
* @apiParam {float} price 价格
|
||||||
* @apiParam {String} title 器材名称
|
* @apiParam {String} title 器材名称
|
||||||
* @apiParam {String} image 器材图片
|
* @apiParam {String} image 器材图片
|
||||||
* @apiParam {Number} unit 单位
|
* @apiParam {Number} unit 单位
|
||||||
* @apiParam {String} remark 备注
|
* @apiParam {String} remark 备注
|
||||||
|
* @apiParam {String} material_id 器材ID
|
||||||
|
* @apiParam {String} supplier_id 供应商ID
|
||||||
|
* @apiParam {String} [stock=0] 库存
|
||||||
*
|
*
|
||||||
* @apiSuccess (200) {Object} data 数据信息
|
* @apiSuccess (200) {Object} data 数据信息
|
||||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||||
@ -458,7 +484,8 @@ func (*Manage) MaterialAdd(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||||
ManufacturerID: form.ManufacturerInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
|
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)
|
APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
@ -474,6 +501,7 @@ func (*Manage) MaterialAdd(c *gin.Context) {
|
|||||||
* @apiParam {String} id ID
|
* @apiParam {String} id ID
|
||||||
* @apiParam {String} manufacturer_id 制造商ID
|
* @apiParam {String} manufacturer_id 制造商ID
|
||||||
* @apiParam {String} code 器材编码
|
* @apiParam {String} code 器材编码
|
||||||
|
* @apiParam {float} price 价格
|
||||||
* @apiParam {String} title 器材名称
|
* @apiParam {String} title 器材名称
|
||||||
* @apiParam {String} image 器材图片
|
* @apiParam {String} image 器材图片
|
||||||
* @apiParam {Number} unit 单位
|
* @apiParam {Number} unit 单位
|
||||||
@ -502,7 +530,7 @@ func (*Manage) MaterialEdit(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||||
ID: form.Convert(), ManufacturerID: form.ManufacturerInfo(), Code: form.Code, Title: form.Title,
|
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)
|
APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@ func initModel() {
|
|||||||
// 日志管理
|
// 日志管理
|
||||||
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
||||||
&synchronized{iModel: model.NewSysBreakdown()},
|
&synchronized{iModel: model.NewSysBreakdown()},
|
||||||
|
// 公告管理
|
||||||
|
&synchronized{iModel: model.NewManageNotice()},
|
||||||
// 功能信息
|
// 功能信息
|
||||||
&synchronized{iModel: model.NewManageSupplier()},
|
&synchronized{iModel: model.NewManageSupplier()},
|
||||||
&synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()},
|
&synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()},
|
||||||
@ -72,7 +74,7 @@ func initCacheMode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function(
|
function(
|
||||||
&caches{iModel: model.NewSysTenant(), iValues: func() interface{} {
|
&caches{iModel: model.NewSysConfig(), iValues: func() interface{} {
|
||||||
out := make([]*model.SysConfig, 0)
|
out := make([]*model.SysConfig, 0)
|
||||||
_ = model.Find(model.NewSysConfig(), &out)
|
_ = model.Find(model.NewSysConfig(), &out)
|
||||||
return out
|
return out
|
||||||
@ -86,6 +88,8 @@ func initCacheMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
initModel()
|
if *config.Init {
|
||||||
|
initModel()
|
||||||
|
}
|
||||||
initCacheMode()
|
initCacheMode()
|
||||||
}
|
}
|
||||||
|
@ -60,23 +60,22 @@ type Area struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AreaInfo struct {
|
type AreaInfo struct {
|
||||||
Province string `json:"province"`
|
ProvinceName string `json:"province_name"`
|
||||||
City string `json:"city"`
|
CityName string `json:"city_name"`
|
||||||
District string `json:"district"`
|
DistrictName string `json:"district_name"`
|
||||||
Address string `json:"address"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Area) Format() *AreaInfo {
|
func (m *Area) Format() *AreaInfo {
|
||||||
out := &AreaInfo{Address: m.Address}
|
out := &AreaInfo{}
|
||||||
|
|
||||||
if m.Province != "" {
|
if m.Province != "" {
|
||||||
out.Province = config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province]
|
out.ProvinceName = config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province]
|
||||||
}
|
}
|
||||||
if m.City != "" {
|
if m.City != "" {
|
||||||
out.City = config.SettingAreaInfo[m.Province][m.City]
|
out.CityName = config.SettingAreaInfo[m.Province][m.City]
|
||||||
}
|
}
|
||||||
if m.District != "" {
|
if m.District != "" {
|
||||||
out.District = config.SettingAreaInfo[m.City][m.District]
|
out.DistrictName = config.SettingAreaInfo[m.City][m.District]
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ package model
|
|||||||
type ManageMaterialSupplier struct {
|
type ManageMaterialSupplier struct {
|
||||||
Model
|
Model
|
||||||
MaterialID uint64 `gorm:"column:material_id;type:int(11);default:0;comment:器材ID" json:"material_id"`
|
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"`
|
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:"-"`
|
FrozenStock float64 `gorm:"column:frozen_stock;type:decimal(10,2);default:0;comment:冻结的库存数" json:"-"`
|
||||||
ModelDeleted
|
ModelDeleted
|
||||||
|
@ -70,6 +70,9 @@ func (m *Model) GetID() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) GetEncodeID() string {
|
func (m *Model) GetEncodeID() string {
|
||||||
|
if m.ID <= 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return utils.HASHIDEncode(int(m.ID))
|
return utils.HASHIDEncode(int(m.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,6 +341,25 @@ func Find(model IModel, out interface{}, where ...*ModelWhereOrder) error {
|
|||||||
return db.Find(out).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 {
|
func Scan(model IModel, out interface{}, where ...*ModelWhereOrder) error {
|
||||||
db := orm.GetDB().Table(model.TableName())
|
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
|
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 {
|
func Pluck(model IModel, field string, out interface{}, where ...*ModelWhere) error {
|
||||||
db := orm.GetDB().Table(model.TableName())
|
db := orm.GetDB().Table(model.TableName())
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ type WorkInstance struct {
|
|||||||
Model
|
Model
|
||||||
ModelTenant
|
ModelTenant
|
||||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:null;comment:工单单号" json:"order_no"`
|
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"`
|
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"`
|
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"`
|
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 退出请求
|
// Logout 退出请求
|
||||||
func (c *Instance) Logout() error {
|
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.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||||
service.HubMessage.UnregisterHandle(service.NewWebsocket(c.UIDToString(), nil))
|
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 装备参数信息
|
||||||
EquipmentParams struct {
|
EquipmentParams struct {
|
||||||
ID uint64
|
ID, ParentID uint64
|
||||||
Code, Title, Image, Config, Remark string
|
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.Code = params.Code
|
||||||
mManageEquipment.Title = params.Title
|
mManageEquipment.Title = params.Title
|
||||||
mManageEquipment.Image.Image = params.Image
|
mManageEquipment.Image.Image = params.Image
|
||||||
@ -210,11 +211,7 @@ func (c *Equipment) Form(params *EquipmentParams) error {
|
|||||||
func (c *Equipment) Delete(id uint64) error {
|
func (c *Equipment) Delete(id uint64) error {
|
||||||
mManageEquipment := model.NewManageEquipment()
|
mManageEquipment := model.NewManageEquipment()
|
||||||
mManageEquipment.ID = id
|
mManageEquipment.ID = id
|
||||||
|
return model2.Delete(mManageEquipment.ManageEquipment)
|
||||||
if err := model2.Delete(mManageEquipment.ManageEquipment); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEquipment() EquipmentHandle {
|
func NewEquipment() EquipmentHandle {
|
||||||
|
@ -6,7 +6,9 @@ import (
|
|||||||
"ArmedPolice/app/model"
|
"ArmedPolice/app/model"
|
||||||
"ArmedPolice/app/service"
|
"ArmedPolice/app/service"
|
||||||
"ArmedPolice/config"
|
"ArmedPolice/config"
|
||||||
|
"ArmedPolice/serve/orm"
|
||||||
"errors"
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,13 +25,17 @@ type (
|
|||||||
// MaterialInfo 基本信息
|
// MaterialInfo 基本信息
|
||||||
MaterialInfo struct {
|
MaterialInfo struct {
|
||||||
basic.CommonIDString
|
basic.CommonIDString
|
||||||
|
ManufacturerID string `json:"manufacturer_id"`
|
||||||
*model.ManageMaterialInfo
|
*model.ManageMaterialInfo
|
||||||
}
|
}
|
||||||
// MaterialParams 基本参数
|
// MaterialParams 基本参数
|
||||||
MaterialParams struct {
|
MaterialParams struct {
|
||||||
ID, ManufacturerID uint64
|
ID, ManufacturerID, MaterialID uint64
|
||||||
Code, Title, Image, Remark string
|
Code, Title, Image, Remark string
|
||||||
Unit int
|
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
|
var count int64
|
||||||
|
|
||||||
out, err := mManageMaterial.Materials(page, pageSize, &count)
|
out, err := mManageMaterial.Materials(page, pageSize, &count, where...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -70,9 +76,14 @@ func (c *Material) List(manufacturerID, supplierID uint64, code, title string, p
|
|||||||
list := make([]*MaterialInfo, 0)
|
list := make([]*MaterialInfo, 0)
|
||||||
|
|
||||||
for _, v := range out {
|
for _, v := range out {
|
||||||
|
mManageMaterial.SetID(v.ManageMaterial.ManufacturerID)
|
||||||
|
|
||||||
|
v.Stock -= v.FrozenStock
|
||||||
v.Image.Image = v.Analysis(config.SettingInfo.Domain)
|
v.Image.Image = v.Analysis(config.SettingInfo.Domain)
|
||||||
|
|
||||||
list = append(list, &MaterialInfo{
|
list = append(list, &MaterialInfo{
|
||||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||||
|
ManufacturerID: mManageMaterial.GetEncodeID(),
|
||||||
ManageMaterialInfo: v,
|
ManageMaterialInfo: v,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -122,9 +133,13 @@ func (c *Material) Form(params *MaterialParams) error {
|
|||||||
return errors.New("操作错误,已存在此对应的器材编码")
|
return errors.New("操作错误,已存在此对应的器材编码")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if mManageMaterial.TenantID != c.TenantID {
|
||||||
|
return errors.New("操作错误,无权限操作")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mManageMaterial.ManufacturerID = params.ManufacturerID
|
mManageMaterial.ManufacturerID = params.ManufacturerID
|
||||||
mManageMaterial.Code = params.Code
|
mManageMaterial.Code = params.Code
|
||||||
|
mManageMaterial.Price = params.Price
|
||||||
mManageMaterial.Title = params.Title
|
mManageMaterial.Title = params.Title
|
||||||
mManageMaterial.Unit = model2.ManageMaterialUnit(params.Unit)
|
mManageMaterial.Unit = model2.ManageMaterialUnit(params.Unit)
|
||||||
mManageMaterial.Remark = params.Remark
|
mManageMaterial.Remark = params.Remark
|
||||||
@ -133,15 +148,44 @@ func (c *Material) Form(params *MaterialParams) error {
|
|||||||
mManageMaterial.UpdatedAt = time.Now()
|
mManageMaterial.UpdatedAt = time.Now()
|
||||||
return model2.Updates(mManageMaterial.ManageMaterial, mManageMaterial.ManageMaterial)
|
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 删除操作
|
// Delete 删除操作
|
||||||
|
@ -15,8 +15,10 @@ type InstanceHandle func(session *service.Session) *Instance
|
|||||||
type (
|
type (
|
||||||
// InstanceInfo 租户信息
|
// InstanceInfo 租户信息
|
||||||
InstanceInfo struct {
|
InstanceInfo struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
ParentID string `json:"parent_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
*model2.Area
|
||||||
*model2.AreaInfo
|
*model2.AreaInfo
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
Children []*InstanceInfo `json:"children"`
|
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)
|
out := make([]*InstanceInfo, 0)
|
||||||
|
|
||||||
for _, v := range src {
|
for _, v := range src {
|
||||||
if v.ParentID == parentID {
|
if v.ParentID == parentID {
|
||||||
|
iModel.SetID(v.ParentID)
|
||||||
out = append(out, &InstanceInfo{
|
out = append(out, &InstanceInfo{
|
||||||
ID: v.GetEncodeID(),
|
ID: v.GetEncodeID(),
|
||||||
|
ParentID: iModel.GetEncodeID(),
|
||||||
Name: v.Name,
|
Name: v.Name,
|
||||||
|
Area: &v.Area,
|
||||||
AreaInfo: v.Area.Format(),
|
AreaInfo: v.Area.Format(),
|
||||||
Remark: v.Remark,
|
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 {
|
if err := model2.Find(mSysTenant.SysTenant, &out); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return c.tree(out, 0), nil
|
return c.tree(mSysTenant.SysTenant, out, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Form 数据操作
|
// Form 数据操作
|
||||||
|
@ -113,7 +113,7 @@ func (c *Instance) Person(materialID uint64, kind, page, pageSize int) (*basic.P
|
|||||||
}
|
}
|
||||||
var count int64
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -155,7 +155,7 @@ func (c *Instance) Workbench(materialID uint64, kind, page, pageSize int) (*basi
|
|||||||
|
|
||||||
out := make([]*model.WorkInstanceInfo, 0)
|
out := make([]*model.WorkInstanceInfo, 0)
|
||||||
|
|
||||||
if out, err = mWorkInstance.Workbench(&model.WorkbenchCondition{
|
if out, err = mWorkInstance.Workbenchs(&model.WorkbenchCondition{
|
||||||
UID: c.UIDToString(), RoleIDs: roleIDs,
|
UID: c.UIDToString(), RoleIDs: roleIDs,
|
||||||
}, page, pageSize, &count, where...); err != nil {
|
}, page, pageSize, &count, where...); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -202,6 +202,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
|||||||
}
|
}
|
||||||
// 工单信息
|
// 工单信息
|
||||||
mWorkInstance := model.NewWorkInstance()
|
mWorkInstance := model.NewWorkInstance()
|
||||||
|
mWorkInstance.UID = c.UID
|
||||||
mWorkInstance.Kind = model2.WorkInstanceKind(params.Kind)
|
mWorkInstance.Kind = model2.WorkInstanceKind(params.Kind)
|
||||||
mWorkInstance.Title = params.Title
|
mWorkInstance.Title = params.Title
|
||||||
mWorkInstance.EquipmentID = params.EquipmentID
|
mWorkInstance.EquipmentID = params.EquipmentID
|
||||||
|
@ -21,8 +21,10 @@ type (
|
|||||||
}
|
}
|
||||||
ManageMaterialInfo struct {
|
ManageMaterialInfo struct {
|
||||||
*model.ManageMaterial
|
*model.ManageMaterial
|
||||||
ManufacturerName string `json:"manufacturer_name"` // 制造商
|
Stock float64 `json:"stock"`
|
||||||
SupplierName string `json:"supplier_name"` // 合作商
|
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()
|
mManageSupplier := model.NewManageSupplier()
|
||||||
|
|
||||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
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 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",
|
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)).
|
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 {
|
if len(where) > 0 {
|
||||||
for _, wo := range where {
|
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 {
|
if err := db.Count(count).Error; err != nil {
|
||||||
return nil, err
|
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 nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
|
@ -36,5 +36,5 @@ func (m *ManageMaterialSupplier) Basic(where ...*model.ModelWhere) ([]*ManageMat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewManageMaterialSupplier() *ManageMaterialSupplier {
|
func NewManageMaterialSupplier() *ManageMaterialSupplier {
|
||||||
return &ManageMaterialSupplier{}
|
return &ManageMaterialSupplier{model.NewManageMaterialSupplier()}
|
||||||
}
|
}
|
||||||
|
@ -12,20 +12,29 @@ type WorkInstance struct {
|
|||||||
*model.WorkInstance
|
*model.WorkInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkInstanceInfo 基本信息
|
type (
|
||||||
type WorkInstanceInfo struct {
|
// WorkInstanceInfo 基本信息
|
||||||
ID uint64 `json:"-"`
|
WorkInstanceInfo struct {
|
||||||
Title string `json:"title"`
|
ID uint64 `json:"-"`
|
||||||
Kind model.WorkInstanceKind `json:"kind"`
|
Title string `json:"title"`
|
||||||
EquipmentCode string `json:"equipment_code"`
|
Kind model.WorkInstanceKind `json:"kind"`
|
||||||
EquipmentTitle string `json:"equipment_title"`
|
EquipmentCode string `json:"equipment_code"`
|
||||||
BreakdownTitle string `json:"breakdown_title"`
|
EquipmentTitle string `json:"equipment_title"`
|
||||||
ScheduleTitle string `json:"schedule_title"`
|
BreakdownTitle string `json:"breakdown_title"`
|
||||||
Priority int `json:"priority"`
|
ScheduleTitle string `json:"schedule_title"`
|
||||||
Distribution string `json:"distribution"`
|
Priority int `json:"priority"`
|
||||||
Status int `json:"status"`
|
Distribution string `json:"distribution"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
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 工作台条件
|
// WorkbenchCondition 工作台条件
|
||||||
type WorkbenchCondition struct {
|
type WorkbenchCondition struct {
|
||||||
@ -33,6 +42,13 @@ type WorkbenchCondition struct {
|
|||||||
RoleIDs []string
|
RoleIDs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *WorkbenchCondition) roleInfo() string {
|
||||||
|
if len(m.RoleIDs) <= 0 {
|
||||||
|
return "''"
|
||||||
|
}
|
||||||
|
return strings.Join(m.RoleIDs, ",")
|
||||||
|
}
|
||||||
|
|
||||||
// Detail 详细信息
|
// Detail 详细信息
|
||||||
func (m *WorkInstance) Detail(id uint64) (*WorkInstanceInfo, error) {
|
func (m *WorkInstance) Detail(id uint64) (*WorkInstanceInfo, error) {
|
||||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
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").
|
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("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",
|
"(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 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 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)
|
Where("w.is_deleted = ?", model.DeleteStatusForNot)
|
||||||
|
|
||||||
if len(where) > 0 {
|
if len(where) > 0 {
|
||||||
@ -79,20 +96,15 @@ func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Persons 个人信息
|
// Persons 个人信息
|
||||||
func (m *WorkInstance) Persons(uid uint64, kind model.WorkScheduleKind, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
func (m *WorkInstance) Persons(uid uint64, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||||
mWorkSchedule := model.NewWorkSchedule()
|
|
||||||
|
|
||||||
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("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",
|
"(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", "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 %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",
|
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.schedule = s.id", model.NewWorkSchedule().TableName())).
|
||||||
mWorkSchedule.TableName(), kind)).
|
Where("w.uid = ? AND w.is_deleted = ?", uid, model.DeleteStatusForNot)
|
||||||
Where("p.is_deleted = ? AND w.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot).
|
|
||||||
Where("p.uid = ?", uid).
|
|
||||||
Where("s.id > ?", 0)
|
|
||||||
|
|
||||||
if len(where) > 0 {
|
if len(where) > 0 {
|
||||||
for _, wo := range where {
|
for _, wo := range where {
|
||||||
@ -111,7 +123,7 @@ func (m *WorkInstance) Persons(uid uint64, kind model.WorkScheduleKind, page, pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Workbench 个人信息
|
// 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()
|
mWorkSchedule := model.NewWorkSchedule()
|
||||||
|
|
||||||
_condition := fmt.Sprintf(`CASE %s
|
_condition := fmt.Sprintf(`CASE %s
|
||||||
@ -123,7 +135,44 @@ ELSE "" END`, "s.target",
|
|||||||
model.WorkScheduleTargetForPerson,
|
model.WorkScheduleTargetForPerson,
|
||||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForPerson, condition.UID,
|
mWorkSchedule.TableName(), model.WorkScheduleTargetForPerson, condition.UID,
|
||||||
model.WorkScheduleTargetForRole,
|
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").
|
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("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
|
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 {
|
func NewWorkInstance() *WorkInstance {
|
||||||
return &WorkInstance{model.NewWorkInstance()}
|
return &WorkInstance{model.NewWorkInstance()}
|
||||||
}
|
}
|
||||||
|
4
build_window.sh
Executable file
4
build_window.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
|
@ -11,9 +11,8 @@ import (
|
|||||||
"ArmedPolice/serve/orm"
|
"ArmedPolice/serve/orm"
|
||||||
"ArmedPolice/serve/web"
|
"ArmedPolice/serve/web"
|
||||||
"ArmedPolice/task"
|
"ArmedPolice/task"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Serve struct {
|
type Serve struct {
|
||||||
@ -32,10 +31,7 @@ func (this *Serve) Run() {
|
|||||||
logger.NewLogger().Init(&logger.Option{File: obj.Log.File, LeastDay: obj.Log.LeastDay, Level: obj.Log.Level, IsStdout: false}).Load()
|
logger.NewLogger().Init(&logger.Option{File: obj.Log.File, LeastDay: obj.Log.LeastDay, Level: obj.Log.Level, IsStdout: false}).Load()
|
||||||
})
|
})
|
||||||
orm.Init()
|
orm.Init()
|
||||||
|
common.Init()
|
||||||
if *config.Init {
|
|
||||||
common.Init()
|
|
||||||
}
|
|
||||||
cache.Init()
|
cache.Init()
|
||||||
task.Init()
|
task.Init()
|
||||||
app.Init()
|
app.Init()
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ArmedPoliceServer-Window",
|
"name": "ArmedPoliceServer-Window",
|
||||||
"format": "zip",
|
"format": "zip",
|
||||||
"pattern": "{Serve.exe,config.yaml,keys/*,file/*,start.sh,stop.sh}",
|
"pattern": "{ArmedPolice.exe,config.yaml,keys/*,json/*,server.sh}",
|
||||||
"options": {
|
"options": {
|
||||||
"dot": true,
|
"dot": true,
|
||||||
"ignore": [
|
"ignore": [
|
||||||
@ -47,7 +47,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ArmedPoliceServer-Linux",
|
"name": "ArmedPoliceServer-Linux",
|
||||||
"format": "tar",
|
"format": "tar",
|
||||||
"pattern": "{SciencesServer,config.yaml,keys/*,file/*,start.sh,stop.sh}",
|
"pattern": "{ArmedPolice,config.yaml,keys/*,json/*,server.sh}",
|
||||||
"options": {
|
"options": {
|
||||||
"dot": true,
|
"dot": true,
|
||||||
"ignore": [
|
"ignore": [
|
||||||
|
@ -31,6 +31,15 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (this *Router) registerWeb() {
|
||||||
|
this.handler.LoadHTMLGlob("dist/*.html") // 添加入口index.html
|
||||||
|
this.handler.LoadHTMLFiles("dist/*") // 添加资源路径
|
||||||
|
this.handler.Static("/js", "dist/js")
|
||||||
|
this.handler.Static("/css", "dist/css")
|
||||||
|
this.handler.Static("/assets", "dist/assets")
|
||||||
|
this.handler.StaticFile("/", "dist/index.html") //前端接口
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Router) registerAPI() {
|
func (this *Router) registerAPI() {
|
||||||
apiPrefix := "/api"
|
apiPrefix := "/api"
|
||||||
g := this.handler.Group(apiPrefix)
|
g := this.handler.Group(apiPrefix)
|
||||||
@ -54,6 +63,14 @@ func (this *Router) registerAPI() {
|
|||||||
v1.GET("/captcha", new(api.Captcha).Captcha)
|
v1.GET("/captcha", new(api.Captcha).Captcha)
|
||||||
// Upload 上传接口管理
|
// Upload 上传接口管理
|
||||||
v1.POST("/upload", new(api.Upload).Upload)
|
v1.POST("/upload", new(api.Upload).Upload)
|
||||||
|
// Dashboard 验证码接口管理
|
||||||
|
dashboardV1 := v1.Group("/dashboard")
|
||||||
|
{
|
||||||
|
_api := new(api.Dashboard)
|
||||||
|
dashboardV1.GET("/", _api.Index)
|
||||||
|
dashboardV1.POST("/repair", _api.Repair)
|
||||||
|
dashboardV1.GET("/score", _api.Score)
|
||||||
|
}
|
||||||
// Account 接口管理
|
// Account 接口管理
|
||||||
accountV1 := v1.Group("/account")
|
accountV1 := v1.Group("/account")
|
||||||
{
|
{
|
||||||
@ -197,22 +214,24 @@ func (this *Router) Init() *gin.Engine {
|
|||||||
app.NoMethod(NoMethodHandler())
|
app.NoMethod(NoMethodHandler())
|
||||||
app.Use(LoggerHandle("log/gin.log", 3))
|
app.Use(LoggerHandle("log/gin.log", 3))
|
||||||
app.Use(TimeoutHandle(time.Second * 30))
|
app.Use(TimeoutHandle(time.Second * 30))
|
||||||
app.Use(RecoveryHandler())
|
|
||||||
|
|
||||||
|
if config.IsDebug() {
|
||||||
|
gin.DefaultWriter = io.MultiWriter(os.Stdout)
|
||||||
|
app.StaticFS("/api-docs", http.Dir("./doc"))
|
||||||
|
} else {
|
||||||
|
app.Use(RecoveryHandler())
|
||||||
|
}
|
||||||
if this.RateLimitConfig != nil {
|
if this.RateLimitConfig != nil {
|
||||||
if this.RateLimitConfig.IsRate {
|
if this.RateLimitConfig.IsRate {
|
||||||
rate.NewIPRateLimiter()(this.RateLimitConfig.Limit, this.RateLimitConfig.Capacity)
|
rate.NewIPRateLimiter()(this.RateLimitConfig.Limit, this.RateLimitConfig.Capacity)
|
||||||
app.Use(rate.RequestIPRateLimiter()(this.RateLimitConfig.Limit, this.RateLimitConfig.Capacity))
|
app.Use(rate.RequestIPRateLimiter()(this.RateLimitConfig.Limit, this.RateLimitConfig.Capacity))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.IsDebug() {
|
|
||||||
gin.DefaultWriter = io.MultiWriter(os.Stdout)
|
|
||||||
app.StaticFS("/api-docs", http.Dir("./doc"))
|
|
||||||
}
|
|
||||||
app.StaticFS("/upload", http.Dir("./upload"))
|
app.StaticFS("/upload", http.Dir("./upload"))
|
||||||
app.MaxMultipartMemory = 4 << 20
|
app.MaxMultipartMemory = 4 << 20
|
||||||
this.handler = app
|
this.handler = app
|
||||||
// 注册路由
|
// 注册路由
|
||||||
|
this.registerWeb()
|
||||||
this.registerAPI()
|
this.registerAPI()
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -12,13 +14,20 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestArrayFlip(t *testing.T) {
|
func TestArrayFlip(t *testing.T) {
|
||||||
//flip := []uint64{1, 2, 3, 4}
|
////flip := []uint64{1, 2, 3, 4}
|
||||||
//out := ArrayFlip(flip)
|
////out := ArrayFlip(flip)
|
||||||
//t.Logf("out:%v\n", out)
|
////t.Logf("out:%v\n", out)
|
||||||
|
//
|
||||||
d := a & b & c
|
//d := a & b & c
|
||||||
t.Log(d)
|
//t.Log(d)
|
||||||
|
|
||||||
|
list := []int{1, 2, 3}
|
||||||
|
for _, v := range list {
|
||||||
|
go func() {
|
||||||
|
fmt.Printf("%d\n", v)
|
||||||
|
}()
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArrayStrings(t *testing.T) {
|
func TestArrayStrings(t *testing.T) {
|
||||||
|
@ -43,6 +43,11 @@ func DataTimeToDate(t string) time.Time {
|
|||||||
return _time
|
return _time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DataTimeForLayout(t string, layout string) time.Time {
|
||||||
|
_time, _ := time.ParseInLocation(layout, t, time.Local)
|
||||||
|
return _time
|
||||||
|
}
|
||||||
|
|
||||||
func GetMondayTime(t time.Time) time.Time {
|
func GetMondayTime(t time.Time) time.Time {
|
||||||
offset := int(time.Monday - t.Weekday())
|
offset := int(time.Monday - t.Weekday())
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user