作者 tangxvhui

更新

... ... @@ -28,4 +28,5 @@ _testmain.go
swagger.json
swagger.yaml
*.log
lastupdate.tmp
\ No newline at end of file
lastupdate.tmp
allied-creation-manufacture
... ...
package dto
type RewardStandardList struct {
Id int `json:"id"` //奖惩标准id
WorkshopId int `json:"workshopId"` //车间id
WorkshopName string `json:"workshopName"` //车间名称
LineId int `json:"lineId"` //生产线ID
LineName string `json:"lineName"` //生产线名称
SectionId int `json:"sectionId"` //工段ID
SectionName string `json:"sectionName"` //工段名称
Remark string `json:"remark"` //备注
TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数
TargetTypeName string `json:"targetTypeName"` //指标类别
TargeReward string `json:"targeReward"` //描述功劳指标
TargeFault string `json:"targeVal2"` //描述过失指标
}
... ...
package query
type ListRewardStandard struct {
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber"`
// 页数
PageSize int `cname:"页数" json:"pageSize"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName"`
// 线别名称
LineName string `cname:"线别名称" json:"lineName"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName"`
}
... ...
... ... @@ -13,13 +13,13 @@ import (
type RewardStandardService struct{}
func NewProductService(options map[string]interface{}) *RewardStandardService {
func NewRewardStandardService(options map[string]interface{}) *RewardStandardService {
newService := &RewardStandardService{}
return newService
}
//SaveRewardStandard 保存奖惩标准数据
func (srv RewardStandardService) SaveRewardStandard(operateInfo domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) {
func (srv RewardStandardService) SaveRewardStandard(operateInfo *domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) {
if err := param.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -118,7 +118,7 @@ func (srv RewardStandardService) SaveRewardStandard(operateInfo domain.OperateIn
}
//GetRewardStandard 根据id获取奖惩标准数据
func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) {
func (srv RewardStandardService) GetRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -142,6 +142,9 @@ func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandar
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if operateInfo.CompanyId != rewardStandardData.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在")
}
result := dto.RewardStandardInfo{
Id: rewardStandardData.Id,
... ... @@ -162,7 +165,7 @@ func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandar
}
//DeleteRewardStandard 根据id删除奖惩标准
func (srv RewardStandardService) DeleteRewardStandard(param *query.GetRewardStandard) (*domain.RewardStandard, error) {
func (srv RewardStandardService) DeleteRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*domain.RewardStandard, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -181,10 +184,84 @@ func (srv RewardStandardService) DeleteRewardStandard(param *query.GetRewardStan
"id": param.Id,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在"+err.Error())
return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在:"+err.Error())
}
if operateInfo.CompanyId != rewardStandardData.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在")
}
_, err = rewardStandardRepo.Remove(rewardStandardData)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "操作指标数据失败"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return rewardStandardData, nil
}
func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStandard) (int64, []dto.RewardStandardList, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
condition := map[string]interface{}{
"limit": 20,
"offset": 0,
"companyId": param.CompanyId,
}
if param.PageSize > 0 {
condition["limit"] = param.PageSize
}
offset := param.PageSize * (param.PageSize - 1)
if offset > 0 {
condition["offset"] = offset
}
if len(param.WorkshopName) > 0 {
condition["workshopName"] = param.WorkshopName
}
if len(param.SectionName) > 0 {
condition["sectionName"] = param.SectionName
}
if len(param.LineName) > 0 {
condition["lineName"] = param.LineName
}
cnt, rewardStandardList, err := rewardStandardRepo.Find(condition)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var listResult []dto.RewardStandardList
var temp dto.RewardStandardList
for _, v := range rewardStandardList {
temp = dto.RewardStandardList{
Id: v.Id,
WorkshopId: v.Workshop.WorkshopId,
WorkshopName: v.Workshop.WorkshopName,
LineId: v.ProductLine.LineId,
LineName: v.ProductLine.LineName,
SectionId: v.ProductSection.SectionId,
SectionName: v.ProductSection.SectionName,
Remark: v.Remark,
TargetType: v.TargetType,
TargetTypeName: v.TargetTypeName(),
TargeReward: v.ShowTargeReward(),
TargeFault: v.ShowTargeFault(),
}
listResult = append(listResult, temp)
}
return cnt, listResult, nil
}
... ...
... ... @@ -28,7 +28,7 @@ var MQTT_HOST = "47.97.5.102"
var MQTT_PORT = "6000"
var MQTT_USER = "admin"
var MQTT_PASSWORD = "123456"
var MQTT_UP = true
var MQTT_UP = false
func init() {
MQTT_HOST = Configurator.DefaultString("MQTT_HOST", MQTT_HOST)
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"errors"
"fmt"
"strconv"
"time"
)
... ... @@ -104,6 +105,7 @@ func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2
return nil
}
//TargetTypeName
func (m *RewardStandard) TargetTypeName() string {
switch m.TargetType {
case TargetType1:
... ... @@ -119,3 +121,39 @@ func (m *RewardStandard) TargetTypeName() string {
}
return ""
}
//ShowTargeReward 功过指标描述,功劳
func (m *RewardStandard) ShowTargeReward() string {
show := ""
switch m.TargetType {
case TargetType1:
show = fmt.Sprintf(">=%skg/小时", m.TargeVal1)
case TargetType2:
show = fmt.Sprintf(">=%s%%", m.TargeVal1)
case TargetType3:
show = fmt.Sprintf("<=%s次或损失<=%s元", m.TargeVal1, m.TargeVal2)
case TargetType4:
show = fmt.Sprintf("<=%s次或损失<=%s元", m.TargeVal1, m.TargeVal2)
case TargetType5:
show = fmt.Sprintf("金属<=%s次或非金属<=%s", m.TargeVal1, m.TargeVal2)
}
return show
}
//ShowTargeFault 功过指标描述,过失
func (m *RewardStandard) ShowTargeFault() string {
show := ""
switch m.TargetType {
case TargetType1:
show = fmt.Sprintf("<%skg/小时", m.TargeVal1)
case TargetType2:
show = fmt.Sprintf("<%s%%", m.TargeVal1)
case TargetType3:
show = fmt.Sprintf(">%s次或损失>%s元", m.TargeVal1, m.TargeVal2)
case TargetType4:
show = fmt.Sprintf("<=%s次或损失>%s元", m.TargeVal1, m.TargeVal2)
case TargetType5:
show = fmt.Sprintf("金属>%s次或非金属>%s", m.TargeVal1, m.TargeVal2)
}
return show
}
... ...
... ... @@ -116,7 +116,6 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{})
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["workshopId"]; ok {
query.Where("work_shop->>'workshopId'='?'", v)
}
... ... @@ -131,6 +130,16 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{})
query.Where("target_type=?", v)
}
if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_shop->>'workshopName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["lineName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_line->>'lineName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["sectionName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_section->>'sectionName' like '%%%v%%'`, v))
}
cnt, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/service"
)
type RewardStandardController struct {
beego.BaseController
}
//创建奖惩标准
func (c RewardStandardController) CreatedRewardStandard() {
srv := service.NewRewardStandardService(nil)
createCommand := &command.SaveRewardStandardCommand{}
Must(c.Unmarshal(createCommand))
operater := ParseOperateInfo(c.BaseController)
data, err := srv.SaveRewardStandard(operater, createCommand)
c.Response(data, err)
}
//更新奖惩标准
func (c RewardStandardController) UpdateRewardStandard() {
srv := service.NewRewardStandardService(nil)
createCommand := &command.SaveRewardStandardCommand{}
Must(c.Unmarshal(createCommand))
operater := ParseOperateInfo(c.BaseController)
data, err := srv.SaveRewardStandard(operater, createCommand)
c.Response(data, err)
}
//获取奖惩标准
func (c RewardStandardController) GetRewardStandard() {
srv := service.NewRewardStandardService(nil)
id, _ := c.GetInt(":id")
getQuery := &query.GetRewardStandard{
Id: id,
}
operater := ParseOperateInfo(c.BaseController)
data, err := srv.GetRewardStandard(operater, getQuery)
c.Response(data, err)
}
//删除奖惩标准
func (c RewardStandardController) DeleteRewardStandard() {
srv := service.NewRewardStandardService(nil)
getQuery := &query.GetRewardStandard{}
Must(c.Unmarshal(getQuery))
operater := ParseOperateInfo(c.BaseController)
data, err := srv.DeleteRewardStandard(operater, getQuery)
c.Response(data, err)
}
//列表展示奖惩标准
func (c RewardStandardController) ListRewardStandard() {
srv := service.NewRewardStandardService(nil)
cmd := &query.ListRewardStandard{}
Must(c.Unmarshal(cmd))
operateInfo := ParseOperateInfo(c.BaseController)
cmd.CompanyId = operateInfo.CompanyId
total, data, err := srv.ListRewardStandard(cmd)
ResponseGrid(c.BaseController, total, data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
)
func init() {
web.Router("/reward-standard/", &controllers.RewardStandardController{}, "Post:CreatedRewardStandard")
web.Router("/reward-standard/:id", &controllers.RewardStandardController{}, "Put:UpdateRewardStandard")
web.Router("/reward-standard/:id", &controllers.RewardStandardController{}, "Get:GetRewardStandard")
web.Router("/reward-standard/remove", &controllers.RewardStandardController{}, "Post:DeleteRewardStandard")
web.Router("/reward-standard/search", &controllers.RewardStandardController{}, "Post:ListRewardStandard")
}
... ...