作者 yangfu

refactor:

1.车间更新修改
2.增加打卡统计
... ... @@ -113,4 +113,8 @@ spec:
- name: SMS_SERVE_HOST
value: "https://sms.fjmaimaimai.com:9897"
- name: SUPLUS_SALE_APP
value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com"
\ No newline at end of file
value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com"
- name: MANUFACTURE_DEFAULT_COMPANYID
value: "23"
- name: MANUFACTURE_DEFAULT_ORGID
value: "487"
\ No newline at end of file
... ...
... ... @@ -30,7 +30,7 @@ func (attendanceService *AttendanceService) WorkerAttendanceReport(cmd *command.
// return nil, err
//}
attendanceReportService, _ := domainService.NewPGWorkerAttendanceReportService(transactionContext.(*pgTransaction.TransactionContext))
if _, err := attendanceReportService.Report(constant.MANUFACTURE_WEIGH_DEFAULT_COMPANYID, constant.MANUFACTURE_WEIGH_DEFAULT_COMPANYID, cmd.DeviceZkTeco); err != nil {
if _, err := attendanceReportService.Report(constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_COMPANYID, cmd.DeviceZkTeco); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -37,7 +37,7 @@ func (crontabService *CrontabService) initTask() {
})
task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud)
autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */1 * * * *", AutoApproveProductAttendanceRecord)
autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */2 * * * *", AutoApproveProductAttendanceRecord)
task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord)
autoApproveRecord := task.NewTask("autoApproveRecord", "0 */2 * * * *", AutoApproveProductRecord)
... ...
... ... @@ -335,9 +335,11 @@ func (productJobService *ProductJobService) SearchProductJob(operateInfo *domain
var result = make([]*dto.ProductJobDto, 0)
for i := range productJobs {
item := productJobs[i]
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(item, operateInfo.OrgId)
newJobDto.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newJobDto.WorkStation.Principal = item.WorkStation.Principal
result = append(result, newJobDto)
}
return count, result, nil
... ...
... ... @@ -17,7 +17,7 @@ type CreateProductPlanCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
BatchNumber string `cname:"批号" json:"batchNumber"`
// 生产日期
ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
... ...
... ... @@ -19,7 +19,7 @@ type UpdateProductPlanCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
BatchNumber string `cname:"批号" json:"batchNumber"`
// 生产日期
ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
... ... @@ -30,6 +30,8 @@ type UpdateProductPlanCommand struct {
PlanProductName string `cname:"计划的产品名称" json:"planProductName"`
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
// 投入量规格 默认份
DevotedUnit string `cname:"投入量规格" json:"devotedUnit" `
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
... ... @@ -39,7 +41,7 @@ type UpdateProductPlanCommand struct {
// 重量
Weight float64 `cname:"重量" json:"weight"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
Remark string `cname:"备注" json:"remark"`
// 生产日期
ProductDateTime time.Time `cname:"生产日期" json:"productDateTime" `
}
... ...
... ... @@ -24,6 +24,8 @@ type ProductPlanDto struct {
WorkOnDescription string `json:"workOnDescription"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `json:"machine"`
// 产品ID
ProductId int `json:"productId,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 投入量规格 默认份
... ... @@ -51,12 +53,14 @@ func (d *ProductPlanDto) LoadDto(m *domain.ProductPlan, orgId int) *ProductPlanD
d.WorkshopId = m.Workshop.WorkshopId
d.WorkshopName = m.Workshop.WorkshopName
d.WorkOn = m.WorkOn
d.Machine = m.Machine
d.PlanProductName = m.PlanProductName
d.UnitQuantity = m.PlanDevoted
d.DevotedUnit = "份"
if m.Ext.ProductPlanExt != nil {
d.DevotedUnit = m.Ext.ProductPlanExt.DevotedUnit
d.ProductId = m.Ext.ProductPlanExt.ProductId
}
d.PlanStatus = m.PlanStatus
d.TotalProduct = 0
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
... ... @@ -61,6 +62,16 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(cmd.BatchNumber) == 0 {
generator := redis.NewPlanBatchCodeCache(cmd.CompanyId)
code, err := redis.GenCode(generator)
if err != nil {
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常")
}
cmd.BatchNumber = code
}
newProductPlan := &domain.ProductPlan{
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
... ... @@ -89,6 +100,7 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre
DevotedUnit: cmd.DevotedUnit,
}),
}
if cmd.Weight > 0 {
newProductPlan.PlanDevoted.Weight = cmd.Weight
}
... ... @@ -262,7 +274,7 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd
ProductId: product.ProductId,
ProductCode: product.ProductCode,
ProductName: product.ProductName,
//ProductSpec: product.ProductSpec,
DevotedUnit: cmd.DevotedUnit,
})
productPlan.PlanDevoted.UnitWeight = product.ProductSpec.UnitWeight
cmd.PlanProductName = product.ProductName
... ...
package syncdata
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"strconv"
"strings"
"time"
... ... @@ -181,8 +183,15 @@ func (srv *PullDataK3CloudService) PullMaterial(timeFilter time.Time) error {
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var userService = domainService.NewUserService()
org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//MaterialK3cloud表数据到Proudct表
err = materialDao.SyncDataProudct(nowTime.Unix())
err = materialDao.SyncDataProudct(nowTime.Unix(), org.OrgName)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -175,7 +175,7 @@ func (workshopService *WorkshopService) RemoveWorkshop(removeWorkshopCommand *co
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeWorkshopCommand.WorkshopId)))
}
if !workshop.CanRemove() {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当车间下存在线别")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前车间下存在线别,不可删除")
}
if workshop, err := workshopRepository.Remove(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -7,16 +7,16 @@ import (
var (
// 生产制造 - 称重系统 - 默认公司
MANUFACTURE_WEIGH_DEFAULT_COMPANYID = 1
MANUFACTURE_DEFAULT_COMPANYID = 1
// 生产制造 - 称重系统 - 默认组织
MANUFACTURE_WEIGH_DEFAULT_ORGID = 1
MANUFACTURE_DEFAULT_ORGID = 1
)
func init() {
if os.Getenv("MANUFACTURE_WEIGH_DEFAULT_COMPANY_ID") != "" {
MANUFACTURE_WEIGH_DEFAULT_COMPANYID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_WEIGH_DEFAULT_COMPANYID"))
if os.Getenv("MANUFACTURE_DEFAULT_COMPANYID") != "" {
MANUFACTURE_DEFAULT_COMPANYID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_COMPANYID"))
}
if os.Getenv("MANUFACTURE_WEIGH_DEFAULT_ORGID") != "" {
MANUFACTURE_WEIGH_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_WEIGH_DEFAULT_ORGID"))
if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" {
MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID"))
}
}
... ...
... ... @@ -104,6 +104,14 @@ func (workshop *Workshop) UpdateLine(lineId int, lineName string) error {
if line.Removed == Deleted {
return fmt.Errorf("生产线:%v已删除", line.LineName)
}
for _, v := range workshop.ProductLines {
if v.Removed == Deleted {
continue
}
if v.LineName == lineName && v.LineId != lineId {
return fmt.Errorf("生产线:%v已存在", lineName)
}
}
line.LineName = lineName
return nil
}
... ... @@ -174,6 +182,21 @@ func (workshop *Workshop) UpdateSection(lineId, sectionId int, sectionName strin
if section.Removed == Deleted {
return fmt.Errorf("工段:%v已删除", section.SectionName)
}
// 当前线下面工段不能重复
line, err := workshop.FindLine(lineId)
if err != nil {
return err
}
for _, v := range line.ProductSections {
if v.Removed == Deleted {
continue
}
if v.SectionName == sectionName && v.SectionId != sectionId {
return fmt.Errorf("工段:%v已存在", sectionName)
}
}
section.SectionName = sectionName
return nil
}
... ...
... ... @@ -2,6 +2,7 @@ package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"strconv"
"strings"
... ... @@ -106,15 +107,15 @@ func (d *MaterialK3cloudDao) SyncDataMaterialK3cloud(data []models.MaterialK3clo
}
//SyncDataProudct 同步MaterialK3cloud表数据到Proudct表
func (d *MaterialK3cloudDao) SyncDataProudct(version int64) error {
func (d *MaterialK3cloudDao) SyncDataProudct(version int64, orgName string) error {
// -- 插入或者更新
sql := `INSERT INTO "manufacture"."product"(
sql := fmt.Sprintf(`INSERT INTO "manufacture"."product"(
"company_id", "org_id", "product_id", "product_code", "product_name",
"product_category", "product_spec", "created_at", "updated_at"
"product_category", "product_spec", "created_at", "updated_at","ext"
)
SELECT 0,use_org_id,"join_product_id","number","name","material_group_name",
json_build_object('unit',specification),now(),now()
FROM "manufacture"."material_k3cloud" WHERE "data_version"=? AND "material_group_number" LIKE '05%'
SELECT %v,%v,"join_product_id","number","name","material_group_name",
json_build_object('unit',specification),now(),now(),json_build_object('orgName','%v')
FROM "manufacture"."material_k3cloud" WHERE "data_version"=? AND "material_group_number" LIKE '05%%'
ON conflict ( product_id ) DO
UPDATE
SET (
... ... @@ -122,7 +123,7 @@ func (d *MaterialK3cloudDao) SyncDataProudct(version int64) error {
"product_category", "product_spec", "updated_at")=(
EXCLUDED."company_id", EXCLUDED."org_id",EXCLUDED."product_id",
EXCLUDED."product_code",EXCLUDED."product_name",EXCLUDED."product_category",
EXCLUDED."product_spec", EXCLUDED."updated_at") `
EXCLUDED."product_spec", EXCLUDED."updated_at") `, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, orgName)
_, err := d.transactionContext.PgTx.Exec(sql, version)
return err
}
... ...
... ... @@ -61,3 +61,28 @@ func NewProductCodeCache(id int) ProductCodeCache {
Time: time.Now(),
}
}
type PlanBatchCodeCache struct {
CompanyId int
Time time.Time
}
func (ca PlanBatchCodeCache) CacheKey() string {
str := fmt.Sprintf("%v:plan-batch-code:%v:%v", constant.CACHE_PREFIX, ca.CompanyId, ca.Time.Format("20060102"))
return str
}
func (ca PlanBatchCodeCache) Format(index int) string {
if index <= 999 {
return fmt.Sprintf("%v%03d", ca.Time.Format("20060102"), index)
}
return fmt.Sprintf("%v%d", ca.Time.Format("20060102"), index)
}
func (ca PlanBatchCodeCache) Expire() time.Duration {
return time.Hour * 24
}
func NewPlanBatchCodeCache(id int) PlanBatchCodeCache {
return PlanBatchCodeCache{
CompanyId: id,
Time: time.Now(),
}
}
... ...
... ... @@ -174,7 +174,6 @@ func (repository *ProductPlanRepository) Find(queryOptions map[string]interface{
query := sqlbuilder.BuildQuery(tx.Model(&productPlanModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("batch_number=?", "batchNumber")
if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`batch_number like '%%%v%%'`, v))
... ...
... ... @@ -14,7 +14,7 @@ import (
func WorkshopWorkTimeRecordStatics(c context.Context, t *asynq.Task) error {
svr := service.NewAttendanceService(nil)
cmd := &command.WorkshopWorkTimeRecordStaticsCommand{}
if err := json.Unmarshal(t.Payload(), cmd); err != nil {
if err := json.Unmarshal(t.Payload(), cmd); err != nil || cmd == nil {
return err
}
log.Logger.Debug(fmt.Sprintf("【考勤记录统计】 消费 记录ID:%v 时间:%v", cmd.ProductAttendanceId, cmd.WorkTimeBefore))
... ...