作者 yangfu

Merge remote-tracking branch 'origin/dev' into test

# Conflicts:
#	deploy/k8s/test/allied-creation-gateway.yaml
@@ -117,6 +117,8 @@ spec: @@ -117,6 +117,8 @@ spec:
117 value: "http://allied-creation-basic-dev.fjmaimaimai.com" 117 value: "http://allied-creation-basic-dev.fjmaimaimai.com"
118 - name: SMS_SERVE_HOST 118 - name: SMS_SERVE_HOST
119 value: "https://sms.fjmaimaimai.com:9897" 119 value: "https://sms.fjmaimaimai.com:9897"
  120 + - name: COST_STRUCTURED
  121 + value: "http://cost-structured-dev.fjmaimaimai.com"
120 - name: SUPLUS_SALE_APP 122 - name: SUPLUS_SALE_APP
121 value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com" 123 value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com"
122 # - name: REDIS_HOST 124 # - name: REDIS_HOST
@@ -12,7 +12,7 @@ spec: @@ -12,7 +12,7 @@ spec:
12 targetPort: 8082 12 targetPort: 8082
13 - name: "https" 13 - name: "https"
14 port: 443 14 port: 443
15 - targetPort: 443 15 + targetPort: 443
16 selector: 16 selector:
17 k8s-app: allied-creation-gateway 17 k8s-app: allied-creation-gateway
18 --- 18 ---
@@ -124,7 +124,7 @@ spec: @@ -124,7 +124,7 @@ spec:
124 - name: SMS_SERVE_HOST 124 - name: SMS_SERVE_HOST
125 value: "https://sms.fjmaimaimai.com:9897" 125 value: "https://sms.fjmaimaimai.com:9897"
126 - name: COST_STRUCTURED 126 - name: COST_STRUCTURED
127 - value: "http://cost-structured-test.fjmaimaimai.com" 127 + value: "https://cost-structured-test.fjmaimaimai.com"
128 - name: SUPLUS_SALE_APP 128 - name: SUPLUS_SALE_APP
129 value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com" 129 value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com"
130 - name: MANUFACTURE_WEIGH_DEFAULT_COMPANYID 130 - name: MANUFACTURE_WEIGH_DEFAULT_COMPANYID
@@ -4,6 +4,7 @@ go 1.16 @@ -4,6 +4,7 @@ go 1.16
4 4
5 require ( 5 require (
6 github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 6 github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
  7 + github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible // indirect
7 github.com/beego/beego/v2 v2.0.1 8 github.com/beego/beego/v2 v2.0.1
8 github.com/dgrijalva/jwt-go v3.2.0+incompatible 9 github.com/dgrijalva/jwt-go v3.2.0+incompatible
9 github.com/disintegration/imaging v1.6.2 10 github.com/disintegration/imaging v1.6.2
@@ -16,5 +17,6 @@ require ( @@ -16,5 +17,6 @@ require (
16 github.com/pdfcpu/pdfcpu v0.3.13 17 github.com/pdfcpu/pdfcpu v0.3.13
17 github.com/stretchr/testify v1.7.0 18 github.com/stretchr/testify v1.7.0
18 github.com/tal-tech/go-queue v1.0.5 19 github.com/tal-tech/go-queue v1.0.5
  20 + github.com/xuri/excelize/v2 v2.4.1 // indirect
19 golang.org/x/text v0.3.6 21 golang.org/x/text v0.3.6
20 ) 22 )
@@ -16,6 +16,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF @@ -16,6 +16,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
16 github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 16 github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
17 github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= 17 github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
18 github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk= 18 github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk=
  19 +github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible h1:uuJIwCFhbZy+zdvLy5zrcIToPEQP0s5CFOZ0Zj03O/w=
  20 +github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
19 github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= 21 github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
20 github.com/beanstalkd/go-beanstalk v0.1.0/go.mod h1:/G8YTyChOtpOArwLTQPY1CHB+i212+av35bkPXXj56Y= 22 github.com/beanstalkd/go-beanstalk v0.1.0/go.mod h1:/G8YTyChOtpOArwLTQPY1CHB+i212+av35bkPXXj56Y=
21 github.com/beego/beego/v2 v2.0.1 h1:07a7Z0Ok5vbqyqh+q53sDPl9LdhKh0ZDy3gbyGrhFnE= 23 github.com/beego/beego/v2 v2.0.1 h1:07a7Z0Ok5vbqyqh+q53sDPl9LdhKh0ZDy3gbyGrhFnE=
@@ -236,6 +238,7 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb @@ -236,6 +238,7 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
236 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= 238 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
237 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= 239 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
238 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 240 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
  241 +github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
239 github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= 242 github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
240 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= 243 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
241 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 244 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
@@ -483,6 +486,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -483,6 +486,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
483 golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= 486 golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
484 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 487 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
485 golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 488 golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
  489 +golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
486 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 490 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
487 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 491 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
488 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 492 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
  1 +package command
  2 +
  3 +type ImportCostDataCommand struct {
  4 + Types int `json:"types"`
  5 +}
@@ -14,6 +14,8 @@ type ImportDataCommand struct { @@ -14,6 +14,8 @@ type ImportDataCommand struct {
14 FileExt string `json:"-"` 14 FileExt string `json:"-"`
15 // 业务编码 15 // 业务编码
16 Code string `form:"code"` 16 Code string `form:"code"`
  17 + // 条件 - 成本结构会增加条件
  18 + Where string `form:"where"`
17 } 19 }
18 20
19 func (importDataCommand *ImportDataCommand) Valid(validation *validation.Validation) { 21 func (importDataCommand *ImportDataCommand) Valid(validation *validation.Validation) {
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "bytes"
  5 + "encoding/json"
4 "fmt" 6 "fmt"
5 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"  
6 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/converter"  
7 - "strings"  
8 -  
9 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
10 "github.com/linmadan/egglib-go/utils/excel" 8 "github.com/linmadan/egglib-go/utils/excel"
  9 + "github.com/xuri/excelize/v2"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService"
  14 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"
15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  16 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/cost_structured"
  17 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/converter"
  18 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/oss"
  19 + "io"
  20 + "strconv"
  21 + "strings"
16 ) 22 )
17 23
18 type ExcelDataService struct { 24 type ExcelDataService struct {
@@ -245,6 +251,118 @@ func (srv ExcelDataService) ImportDevice(importDataCommand *command.ImportDataCo @@ -245,6 +251,118 @@ func (srv ExcelDataService) ImportDevice(importDataCommand *command.ImportDataCo
245 return srv.importResultWithHeader(excelImport.DataFields, *result, len(items)), nil 251 return srv.importResultWithHeader(excelImport.DataFields, *result, len(items)), nil
246 } 252 }
247 253
  254 +// ImportCost 导入成本结构化
  255 +func (srv ExcelDataService) ImportCost(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  256 + excelImport := excel.NewExcelImport()
  257 + excelImport.RowBegin = 2 //第二行开始读取
  258 + excelImport.DataFields = []excel.DataField{
  259 + {EnName: "projectCode", CnName: "*项目编码"},
  260 + {EnName: "itemName", CnName: "*细项名称"},
  261 + {EnName: "choiceId", CnName: "*节点类型"},
  262 + {EnName: "text", CnName: "文本(数值)内容"},
  263 + {EnName: "image", CnName: "图片"},
  264 + {EnName: "formula", CnName: "计算公式"},
  265 + {EnName: "chargePersons", CnName: "*负责人"},
  266 + {EnName: "target", CnName: "目标值"},
  267 + {EnName: "targetPeriod", CnName: "目标值期限"},
  268 + {EnName: "present", CnName: "现状值"},
  269 + {EnName: "schedulePlanPercent", CnName: "进度计划比"},
  270 + {EnName: "benchmark", CnName: "标杆值"},
  271 + {EnName: "highest", CnName: "历史最高值"},
  272 + {EnName: "yesterdayActual", CnName: "昨日实际值"},
  273 + }
  274 + var buf bytes.Buffer
  275 + tee := io.TeeReader(importDataCommand.Reader, &buf)
  276 + excelData, err := converter.OpenImportFileFromIoReader(excelImport, tee, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  277 + if err != nil {
  278 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  279 + }
  280 + importCostCommand := &command.ImportCostDataCommand{}
  281 + err = json.Unmarshal([]byte(importDataCommand.Where), importCostCommand)
  282 + if err != nil {
  283 + return nil, application.ThrowError(application.ARG_ERROR, "风险类型不能为空")
  284 + }
  285 + if importCostCommand.Types <= 0 {
  286 + return nil, application.ThrowError(application.ARG_ERROR, "风险类型不能为空")
  287 + }
  288 + f, err := excelize.OpenReader(&buf)
  289 + if err != nil {
  290 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  291 + }
  292 + index := f.GetActiveSheetIndex()
  293 + //获取公司下所有用户
  294 + users, err := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator).UserSearch(allied_creation_user.ReqUserSearch{CompanyId: importDataCommand.Operator.CompanyId, Limit: 10000})
  295 + if err != nil {
  296 + return nil, application.ThrowError(application.ARG_ERROR, "获取用户数据失败")
  297 + }
  298 + userMap := make(map[string]allied_creation_user.UserDetail)
  299 + for _, item := range users.Users {
  300 + userMap[item.UserInfo.UserName] = item
  301 + }
  302 + createCostManagemant := cost_structured.BatchAddCostManagemantRequest{
  303 + BatchCreateCostManagemant: &domain.BatchCreateCostManagemant{
  304 + UserId: importDataCommand.Operator.UserId,
  305 + CompanyId: importDataCommand.Operator.CompanyId,
  306 + ProjectName: "",
  307 + Types: importCostCommand.Types,
  308 + CostManagemants: make([]*domain.CostManagemant, 0),
  309 + },
  310 + }
  311 + for key, v := range excelData {
  312 + if key == 0 {
  313 + createCostManagemant.ProjectName = strings.TrimSpace(v["itemName"])
  314 + }
  315 + _, mBytes, err := f.GetPicture(f.GetSheetName(index), "E"+fmt.Sprintf("%v", excelImport.RowBegin+key))
  316 + if err != nil {
  317 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "读取图片失败")
  318 + }
  319 + var ossFile string
  320 + if mBytes != nil {
  321 + ossFile, err = oss.UploadOss(mBytes)
  322 + if err != nil {
  323 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "上传图片失败")
  324 + }
  325 + }
  326 + //choiceId, err := strconv.Atoi(v["choiceId"])
  327 + choiceId := domain.NodeType{}.GetIdByName(strings.TrimSpace(v["choiceId"]))
  328 + // 负责人
  329 + chargePersons := make([]string, 0)
  330 + names := strings.Split(strings.TrimSpace(v["chargePersons"]), " ")
  331 + for _, userName := range names {
  332 + if userName == "" {
  333 + continue
  334 + }
  335 + if user, ok := userMap[userName]; ok {
  336 + chargePersons = append(chargePersons, fmt.Sprintf("%v", user.UserId))
  337 + }
  338 + }
  339 + //目标值期限
  340 + targetPeriod, _ := strconv.Atoi(strings.TrimSpace(v["targetPeriod"]))
  341 + item := &domain.CostManagemant{
  342 + ProjectCode: strings.TrimSpace(v["projectCode"]),
  343 + ItemName: strings.TrimSpace(v["itemName"]),
  344 + ChoiceId: choiceId,
  345 + Urls: []string{ossFile},
  346 + Formula: strings.TrimSpace(v["formula"]),
  347 + ChargePersons: chargePersons,
  348 + Target: strings.TrimSpace(v["target"]),
  349 + TargetPeriod: targetPeriod,
  350 + Present: strings.TrimSpace(v["present"]),
  351 + SchedulePlanPercent: strings.TrimSpace(v["schedulePlanPercent"]),
  352 + Benchmark: strings.TrimSpace(v["benchmark"]),
  353 + Highest: strings.TrimSpace(v["highest"]),
  354 + YesterdayActual: strings.TrimSpace(v["yesterdayActual"]),
  355 + Types: importCostCommand.Types,
  356 + }
  357 + createCostManagemant.CostManagemants = append(createCostManagemant.CostManagemants, item)
  358 + }
  359 + result, err := cost_structured.NewHttpLibCostStructured(importDataCommand.Operator).BatchCreateCostManagemant(createCostManagemant)
  360 + if err != nil {
  361 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  362 + }
  363 + return srv.importResultWithHeader(excelImport.DataFields, *result, len(createCostManagemant.CostManagemants)), nil
  364 +}
  365 +
248 // 导入结果 366 // 导入结果
249 func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, failRows []interface{}, totalRow int) interface{} { 367 func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, failRows []interface{}, totalRow int) interface{} {
250 var result = map[string]interface{}{ 368 var result = map[string]interface{}{
@@ -290,6 +408,7 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import @@ -290,6 +408,7 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import
290 domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx", 408 domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx",
291 domain.ImportProducts: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220120/object/1642670543_cbraNKjNPHcbN6RNBYQBrwhC7BXGbDWp.xlsx", 409 domain.ImportProducts: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220120/object/1642670543_cbraNKjNPHcbN6RNBYQBrwhC7BXGbDWp.xlsx",
292 domain.ImportDevices: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220126/object/1643184320_hT6sY5BKHmBa4TynfSGSCGyZ2KTTtzkj.xlsx", 410 domain.ImportDevices: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220126/object/1643184320_hT6sY5BKHmBa4TynfSGSCGyZ2KTTtzkj.xlsx",
  411 + domain.ImportCosts: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220311/object/1646977166_ATAD4tJbBDp4WhNFABatTZzkJDeZWB3K.xlsx",
293 } 412 }
294 var url string 413 var url string
295 var ok bool 414 var ok bool
@@ -44,6 +44,10 @@ var SMSCODE_ALL_POWER = "999512" @@ -44,6 +44,10 @@ var SMSCODE_ALL_POWER = "999512"
44 44
45 var EnableBlockChain = true 45 var EnableBlockChain = true
46 46
  47 +// 天联共创 成本结构化
  48 +var COST_STRUCTURED = "http://cost-structured-dev.fjmaimaimai.com"
  49 +//var COST_STRUCTURED = "http://localhost:8085"
  50 +
47 func init() { 51 func init() {
48 if os.Getenv("LOG_LEVEL") != "" { 52 if os.Getenv("LOG_LEVEL") != "" {
49 LOG_LEVEL = os.Getenv("LOG_LEVEL") 53 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -81,4 +85,7 @@ func init() { @@ -81,4 +85,7 @@ func init() {
81 if os.Getenv("SUPLUS_SALE_APP") != "" { 85 if os.Getenv("SUPLUS_SALE_APP") != "" {
82 SUPLUS_SALE_APP = os.Getenv("SUPLUS_SALE_APP") 86 SUPLUS_SALE_APP = os.Getenv("SUPLUS_SALE_APP")
83 } 87 }
  88 + if os.Getenv("COST_STRUCTURED") != "" {
  89 + COST_STRUCTURED = os.Getenv("COST_STRUCTURED")
  90 + }
84 } 91 }
  1 +package constant
  2 +
  3 +const OssAccessKey = "LTAI4Fz1LUBW2fXp6QWaJHRS"
  4 +
  5 +const OssSecret = "aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
  6 +
  7 +var OssBucket = "timeless-world"
  8 +
  9 +const OssDomain = "http://timeless-world.oss-cn-shenzhen.aliyuncs.com"
@@ -2,11 +2,18 @@ package constant @@ -2,11 +2,18 @@ package constant
2 2
3 import "os" 3 import "os"
4 4
5 -var POSTGRESQL_DB_NAME = "terms" 5 +//var POSTGRESQL_DB_NAME = "terms"
  6 +//var POSTGRESQL_USER = "postgres"
  7 +//var POSTGRESQL_PASSWORD = "123456"
  8 +//var POSTGRESQL_HOST = "127.0.0.1"
  9 +//var POSTGRESQL_PORT = "5432"
  10 +//var DISABLE_CREATE_TABLE = false
  11 +//var DISABLE_SQL_GENERATE_PRINT = false
  12 +var POSTGRESQL_DB_NAME = "allied_creation_dev"
6 var POSTGRESQL_USER = "postgres" 13 var POSTGRESQL_USER = "postgres"
7 var POSTGRESQL_PASSWORD = "123456" 14 var POSTGRESQL_PASSWORD = "123456"
8 -var POSTGRESQL_HOST = "127.0.0.1"  
9 -var POSTGRESQL_PORT = "5432" 15 +var POSTGRESQL_HOST = "114.55.200.59"
  16 +var POSTGRESQL_PORT = "31543"
10 var DISABLE_CREATE_TABLE = false 17 var DISABLE_CREATE_TABLE = false
11 var DISABLE_SQL_GENERATE_PRINT = false 18 var DISABLE_SQL_GENERATE_PRINT = false
12 19
  1 +package domain
  2 +
  3 +type BatchCreateCostManagemant struct {
  4 + UserId int64 `cname:"操作人id" json:"UserId" valid:"Required"`
  5 + // 公司id
  6 + CompanyId int64 `cname:"公司id" json:"companyId" valid:"Required"`
  7 + // 项目id
  8 + ProjectId int64 `cname:"项目id" json:"projectId,string"`
  9 + // 项目名称
  10 + ProjectName string `cname:"项目名称" json:"projectName" valid:"Required"`
  11 + // 项目分类: 1风险 2成本 3品质 4交期 5服务 6客户关系 7品牌
  12 + Types int `cname:"项目分类: 1风险 2成本 3品质 4交期 5服务 6客户关系 7品牌" json:"types" valid:"Required"`
  13 + //成本數組
  14 + CostManagemants []*CostManagemant `cname:"成本数组" json:"costManagemants" valid:"Required"`
  15 +}
  16 +
  17 +// 成本管理
  18 +type CostManagemant struct {
  19 + // 项目编码
  20 + ProjectCode string `json:"projectCode,string"`
  21 + // 成本管理Id
  22 + CostManagemantId int64 `json:"costManagemantId,string"`
  23 + // 公式id
  24 + CompanyId int64 `json:"companyId,string"`
  25 + // 标杆值,字符串,如果纯数字的时候参与计算
  26 + Benchmark string `json:"benchmark"`
  27 + // 负责人数组
  28 + ChargePersons []string `json:"chargePersons"`
  29 + // 历史最高值,字符串,如果纯数字的时候参与计算
  30 + Highest string `json:"highest"`
  31 + // 细项名称
  32 + ItemName string `json:"itemName"`
  33 + // 级别
  34 + Level int `json:"level"`
  35 + // 父id
  36 + ParentId int64 `json:"parentId,string"`
  37 + // 现状值,字符串,如果纯数字的时候参与计算
  38 + Present string `json:"present"`
  39 + // 当前选择的节点类型 1、combination 组合框 2、staff 员工选取 3、text 文本框 4、BOM BOM表
  40 + // 5、number数值框 6、calculate计算框
  41 + ChoiceId int `cname:"当前选择的节点类型 1、combination 组合框 2、staff 员工选取 3、text 文本框 4、BOM BOM表 5、number数值框 6、calculate计算框" json:"choiceId"`
  42 + // 图片
  43 + Urls []string `cname:"图片" json:"urls"`
  44 + // calculate 计算框:计算框公式
  45 + Formula string `cname:"calculate 计算框:计算框公式" json:"formula" `
  46 + // 项目id
  47 + ProjectId int64 `json:"projectId,string"`
  48 + // 项目名称
  49 + ProjectName string `json:"projectName"`
  50 + // 进度计划比,字符串,如果纯数字的时候参与计算
  51 + SchedulePlanPercent string `json:"schedulePlanPercent"`
  52 + // 结构类型
  53 + //StructureType int `json:"structureType"`
  54 + // 目标值 字符串 为数字时 参与计算
  55 + Target string `json:"target"`
  56 + // 目标值期限 1 第一季度 2第二季度 3第三季度 4第四季度 5 年度
  57 + TargetPeriod int `json:"targetPeriod"`
  58 + // 顶级成本管理id
  59 + TopCostManagemantId int64 `json:"topCostManagemantId,string"`
  60 + // 项目分类: 1风险 2成本 3品质 4交期 5服务 6客户关系 7品牌
  61 + Types int `json:"types"`
  62 + // 昨日实际值
  63 + YesterdayActual string `json:"yesterdayActual"`
  64 +}
  65 +
  66 +type NodeType struct {
  67 + TypeId int
  68 + TypeName string
  69 +}
  70 +
  71 +var NodeTypeGroup = []NodeType{
  72 + {TypeId: 1, TypeName: "组合框"},
  73 + {TypeId: 2, TypeName: "员工类型"},
  74 + {TypeId: 3, TypeName: "文本类型"},
  75 + {TypeId: 4, TypeName: "BOM表类型"},
  76 + {TypeId: 5, TypeName: "数值框"},
  77 + {TypeId: 6, TypeName: "计算框"},
  78 + {TypeId: 7, TypeName: "图片框"},
  79 +}
  80 +
  81 +func (NodeType) GetIdByName(name string) int {
  82 + group := NodeTypeGroup
  83 + for _, item := range group {
  84 + if item.TypeName == name {
  85 + return item.TypeId
  86 + }
  87 + }
  88 + return 0
  89 +}
@@ -68,6 +68,8 @@ const ( @@ -68,6 +68,8 @@ const (
68 ImportProducts = "BUSINESS_ALLIED-MANUFACTURING_BASIC_PRODUCT" 68 ImportProducts = "BUSINESS_ALLIED-MANUFACTURING_BASIC_PRODUCT"
69 // 导入设备 69 // 导入设备
70 ImportDevices = "BUSINESS_ALLIED-MANUFACTURING_BASIC_DEVICE" 70 ImportDevices = "BUSINESS_ALLIED-MANUFACTURING_BASIC_DEVICE"
  71 + //导入成本结构
  72 + ImportCosts = "BUSINESS_ALLIED-COST"
71 ) 73 )
72 74
73 const ( 75 const (
  1 +package cost_structured
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
  10 +)
  11 +
  12 +//HttpLibCostStructured 成本结构化
  13 +type HttpLibCostStructured struct {
  14 + service_gateway.BaseServiceGateway
  15 + baseUrL string
  16 +}
  17 +
  18 +func NewHttpLibCostStructured(operator domain.Operator) *HttpLibCostStructured {
  19 + return &HttpLibCostStructured{
  20 + BaseServiceGateway: service_gateway.BaseServiceGateway{
  21 + ConnectTimeout: 100 * time.Second,
  22 + ReadWriteTimeout: 100 * time.Second,
  23 + CompanyId: operator.CompanyId,
  24 + OrgId: operator.OrgId,
  25 + InOrgIds: operator.OrgIds,
  26 + UserId: operator.UserId,
  27 + UserBaseId: operator.UserBaseId,
  28 + },
  29 + baseUrL: constant.COST_STRUCTURED,
  30 + }
  31 +
  32 +}
  33 +
  34 +func (gateway HttpLibCostStructured) BaseUrl() string {
  35 + return gateway.baseUrL
  36 +}
  37 +
  38 +//批量添加成本管理
  39 +func (gateway HttpLibCostStructured) BatchCreateCostManagemant(param BatchAddCostManagemantRequest) (*BatchAddCostManagemantResponse, error) {
  40 + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/cost-managemants/batch-update-cost-managemants")
  41 + method := "post"
  42 + var data BatchAddCostManagemantResponse
  43 + err := gateway.FastDoRequest(url, method, param, &data)
  44 + return &data, err
  45 +}
  46 +type BatchAddCostManagemantRequest struct {
  47 + *domain.BatchCreateCostManagemant
  48 +}
  49 +type BatchAddCostManagemantResponse []interface{}
  50 +
  51 +func (gateway HttpLibCostStructured) ListCostManagemant(param ListCostManagemantRequest) (*ListCostManagemantResponse, error) {
  52 + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/cost-managemants/")
  53 + method := "post"
  54 + var data ListCostManagemantResponse
  55 + err := gateway.FastDoRequest(url, method, param, &data)
  56 + return &data, err
  57 +}
  58 +
  59 +
  60 +
  61 +
  62 +
  63 +
  64 +
  65 +type (
  66 + ListCostManagemantRequest struct {
  67 + // 页码
  68 + PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  69 + // 页数
  70 + PageSize int `cname:"页数" json:"pageSize,omitempty"`
  71 + // 查询项目(结构)类型
  72 + Types int `cname:"查询项目(结构)类型" json:"types" valid:"Required"`
  73 + // 查询项目id
  74 + ProjectId int64 `cname:"查询项目id" json:"projectId"`
  75 + }
  76 + ListCostManagemantResponse struct {
  77 + Grid struct {
  78 + List []SearchProductItem `json:"list"`
  79 + Total int `json:"total"`
  80 + } `json:"grid"`
  81 + }
  82 + SearchProductItem struct {
  83 + ProductID int `json:"productId"`
  84 + ProductCode string `json:"productCode"`
  85 + ProductName string `json:"productName"`
  86 + ProductCategory string `json:"productCategory"`
  87 + Unit string `json:"unit"`
  88 + UnitWeight float64 `json:"unitWeight"`
  89 + }
  90 +)
  91 +
  92 +
  93 +
  94 +
  95 +
  96 +
  97 +
  98 +/*设备*/
  99 +
  100 +
  101 +
  102 +type BatchAddDeviceRequest struct {
  103 + List []*domain.ImportDeviceItem `json:"list"`
  104 +}
  105 +type BatchAddDeviceResponse []interface{}
  106 +
  107 +/**生产记录**/
  108 +//SearchProduct 搜索员工产能统计
  109 +func (gateway HttpLibCostStructured) SearchEmployeeProductive(param SearchEmployeeProductiveRequest) (*SearchEmployeeProductiveResponse, error) {
  110 + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/product-records/employee-productive/search")
  111 + method := "post"
  112 + var data SearchEmployeeProductiveResponse
  113 + err := gateway.FastDoRequest(url, method, param, &data)
  114 + return &data, err
  115 +}
  116 +
  117 +type (
  118 + SearchEmployeeProductiveRequest struct {
  119 + // 页码
  120 + //PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  121 + // 页数
  122 + //PageSize int `cname:"页数" json:"pageSize,omitempty"`
  123 + // 车间名称
  124 + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
  125 + // 生产线名称
  126 + LineName string `cname:"生产线名称" json:"lineName,omitempty"`
  127 + // 工段名称
  128 + SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
  129 + // 姓名
  130 + UserName string `cname:"姓名" json:"userName"`
  131 + // 员工类型 1:固定 2:派遣 3.临时
  132 + EmployeeType string `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
  133 + // 开始时间
  134 + BeginTime string `cname:"开始时间" json:"beginTime"`
  135 + // 结束时间
  136 + EndTime string `cname:"结束时间" json:"endTime"`
  137 + }
  138 + SearchEmployeeProductiveResponse struct {
  139 + Grid struct {
  140 + List []EmployeeProductiveItem `json:"list"`
  141 + Total int `json:"total"`
  142 + } `json:"grid"`
  143 + }
  144 + EmployeeProductiveItem struct {
  145 + EmployeeProductRecordID int `json:"employeeProductRecordId"`
  146 + ProductWorker struct {
  147 + UserID int `json:"userId"`
  148 + UserName string `json:"userName"`
  149 + Avatar string `json:"avatar"`
  150 + Phone string `json:"phone"`
  151 + EmployeeType int `json:"employeeType"`
  152 + } `json:"productWorker"`
  153 + WorkStationID string `json:"workStationId"`
  154 + WorkshopID int `json:"workshopId"`
  155 + WorkshopName string `json:"workshopName"`
  156 + LineID int `json:"lineId"`
  157 + LineName string `json:"lineName"`
  158 + SectionID int `json:"sectionId"`
  159 + SectionName string `json:"sectionName"`
  160 + WorkOn string `json:"workOn"`
  161 + PlanProductName string `json:"planProductName"`
  162 + BatchNumber string `json:"batchNumber"`
  163 + ParticipateType int `json:"participateType"`
  164 + ProductWeigh float64 `json:"productWeigh"`
  165 + SecondLevelWeigh float64 `json:"secondLevelWeigh"`
  166 + CreatedAt string `json:"createdAt"`
  167 + OrgName string `json:"orgName"`
  168 + AuthFlag bool `json:"authFlag"`
  169 + QualificationRate int `json:"qualificationRate"`
  170 + }
  171 +)
  172 +
  173 +//SearchProduct 搜索员工产能统计
  174 +func (gateway HttpLibCostStructured) SearchWorkshopProductive(param SearchWorkshopProductiveRequest) (*SearchWorkshopProductiveResponse, error) {
  175 + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/product-records/workshop-productive/search")
  176 + method := "post"
  177 + var data SearchWorkshopProductiveResponse
  178 + err := gateway.FastDoRequest(url, method, param, &data)
  179 + return &data, err
  180 +}
  181 +
  182 +type (
  183 + SearchWorkshopProductiveRequest struct {
  184 + // 品名
  185 + PlanProductName string `cname:"品名" json:"planProductName,omitempty"`
  186 + // 工段名称
  187 + SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
  188 + // 开始时间
  189 + BeginTime string `cname:"开始时间" json:"beginTime"`
  190 + // 结束时间
  191 + EndTime string `cname:"结束时间" json:"endTime"`
  192 + }
  193 + SearchWorkshopProductiveResponse struct {
  194 + Grid struct {
  195 + List []WorkshopProductiveItem `json:"list"`
  196 + Total int `json:"total"`
  197 + } `json:"grid"`
  198 + }
  199 + WorkshopProductiveItem struct {
  200 + EmployeeProductRecordID int `json:"employeeProductRecordId"`
  201 + ProductWorker struct {
  202 + UserID int `json:"userId"`
  203 + UserName string `json:"userName"`
  204 + Avatar string `json:"avatar"`
  205 + Phone string `json:"phone"`
  206 + EmployeeType int `json:"employeeType"`
  207 + } `json:"productWorker"`
  208 + WorkStationID string `json:"workStationId"`
  209 + WorkshopID int `json:"workshopId"`
  210 + WorkshopName string `json:"workshopName"`
  211 + LineID int `json:"lineId"`
  212 + LineName string `json:"lineName"`
  213 + SectionID int `json:"sectionId"`
  214 + SectionName string `json:"sectionName"`
  215 + WorkOn string `json:"workOn"`
  216 + PlanProductName string `json:"planProductName"`
  217 + BatchNumber string `json:"batchNumber"`
  218 + //ParticipateType int `json:"participateType"`
  219 + // 投入量
  220 + DevotedProductWeigh float64 `json:"devotedProductWeigh"`
  221 + // 产能
  222 + ProductWeigh float64 `json:"productWeigh"`
  223 + // 二级品产能
  224 + SecondLevelWeigh float64 `json:"secondLevelWeigh"`
  225 + CreatedAt string `json:"createdAt"`
  226 + OrgName string `json:"orgName"`
  227 + AuthFlag bool `json:"authFlag"`
  228 + QualificationRate int `json:"qualificationRate"`
  229 + }
  230 +)
  231 +
  232 +/*** 考勤记录 ***/
  233 +//SearchEmployeeAttendanceStatics 搜索员工工时统计
  234 +func (gateway HttpLibCostStructured) SearchEmployeeAttendanceStatics(param SearchEmployeeAttendanceStaticsRequest) (*SearchEmployeeAttendanceStaticsResponse, error) {
  235 + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/attendances/employee-attendance-statics/search")
  236 + method := "post"
  237 + var data SearchEmployeeAttendanceStaticsResponse
  238 + err := gateway.FastDoRequest(url, method, param, &data)
  239 + return &data, err
  240 +}
  241 +
  242 +type (
  243 + SearchEmployeeAttendanceStaticsRequest struct {
  244 + // 车间名称
  245 + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
  246 + // 生产线名称
  247 + LineName string `cname:"生产线名称" json:"lineName,omitempty"`
  248 + // 工段名称
  249 + SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
  250 + // 姓名
  251 + UserName string `cname:"姓名" json:"userName,omitempty"`
  252 + // 考勤状态 1.未审核 2:已审核 4.自动审核
  253 + AttendanceStatus int `cname:"考勤状态 1.未审核 2:已审核 4.自动审核" json:"attendanceStatus,omitempty"`
  254 + // 开始时间
  255 + BeginTime string `cname:"开始时间" json:"beginTime"`
  256 + // 结束时间
  257 + EndTime string `cname:"结束时间" json:"endTime"`
  258 + }
  259 + SearchEmployeeAttendanceStaticsResponse struct {
  260 + Grid struct {
  261 + List []SearchEmployeeAttendanceStaticsItem `json:"list"`
  262 + Total int `json:"total"`
  263 + } `json:"grid"`
  264 + }
  265 + SearchEmployeeAttendanceStaticsItem struct {
  266 + ProductAttendanceID int `json:"productAttendanceId"`
  267 + SignDate string `json:"signDate"`
  268 + WorkStationID string `json:"workStationId"`
  269 + WorkshopID int `json:"workshopId"`
  270 + WorkshopName string `json:"workshopName"`
  271 + LineID int `json:"lineId"`
  272 + LineName string `json:"lineName"`
  273 + SectionID int `json:"sectionId"`
  274 + SectionName string `json:"sectionName"`
  275 + ProductWorker struct {
  276 + UserID int `json:"userId"`
  277 + UserName string `json:"userName"`
  278 + EmployeeType int `json:"employeeType"`
  279 + Avatar string `json:"avatar"`
  280 + Phone string `json:"phone"`
  281 + } `json:"productWorker"`
  282 + AttendanceType int `json:"attendanceType"`
  283 + AttendanceStatus int `json:"attendanceStatus"`
  284 + AttendanceTypeDescription string `json:"attendanceTypeDescription"`
  285 + EmployeeTypeDescription string `json:"employeeTypeDescription"`
  286 + AttendanceStatusDescription string `json:"attendanceStatusDescription"`
  287 + WorkTime float64 `json:"workTime"`
  288 + OrgName string `json:"orgName"`
  289 + AuthFlag bool `json:"authFlag"`
  290 + }
  291 +)
  292 +
  293 +//SearchEmployeeAttendanceStatics 搜索员工工时统计
  294 +func (gateway HttpLibCostStructured) SearchWorkshopWorkTimeStatics(param SearchWorkshopWorkTimeStaticsRequest) (*SearchWorkshopWorkTimeStaticsResponse, error) {
  295 + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/attendances/workshop-attendance-statics/search")
  296 + method := "post"
  297 + var data SearchWorkshopWorkTimeStaticsResponse
  298 + err := gateway.FastDoRequest(url, method, param, &data)
  299 + return &data, err
  300 +}
  301 +
  302 +type (
  303 + SearchWorkshopWorkTimeStaticsRequest struct {
  304 + // 车间名称
  305 + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
  306 + // 生产线名称
  307 + LineName string `cname:"生产线名称" json:"lineName,omitempty"`
  308 + // 开始时间
  309 + BeginTime string `cname:"开始时间" json:"beginTime"`
  310 + // 结束时间
  311 + EndTime string `cname:"结束时间" json:"endTime"`
  312 + }
  313 + SearchWorkshopWorkTimeStaticsResponse struct {
  314 + Grid struct {
  315 + List []SearchWorkshopWorkTimeStaticsItem `json:"list"`
  316 + Total int `json:"total"`
  317 + } `json:"grid"`
  318 + }
  319 + SearchWorkshopWorkTimeStaticsItem struct {
  320 + WorkshopWorkTimeRecordID int `json:"workshopWorkTimeRecordId"`
  321 + WorkStationID string `json:"workStationId"`
  322 + WorkshopID int `json:"workshopId"`
  323 + WorkshopName string `json:"workshopName"`
  324 + LineID int `json:"lineId"`
  325 + LineName string `json:"lineName"`
  326 + SectionID int `json:"sectionId"`
  327 + SectionName string `json:"sectionName"`
  328 + EftWorkTime float64 `json:"eftWorkTime"`
  329 + EdWorkTime int `json:"edWorkTime"`
  330 + EptWorkTime int `json:"eptWorkTime"`
  331 + RecordDate string `json:"recordDate"`
  332 + OrgName string `json:"orgName"`
  333 + AuthFlag bool `json:"authFlag"`
  334 + }
  335 +)
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/cost_structured"
7 "net/http" 8 "net/http"
8 "os" 9 "os"
9 "strconv" 10 "strconv"
@@ -67,6 +68,8 @@ func init() { @@ -67,6 +68,8 @@ func init() {
67 68
68 web.InsertFilter("/v1/manufacture/*", web.BeforeRouter, middleware.CheckAccessToken()) 69 web.InsertFilter("/v1/manufacture/*", web.BeforeRouter, middleware.CheckAccessToken())
69 web.InsertFilter("/v1/manufacture/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/manufacture", allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(domain.Operator{}))) 70 web.InsertFilter("/v1/manufacture/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/manufacture", allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(domain.Operator{})))
  71 + web.InsertFilter("/v1/cost/*", web.BeforeRouter, middleware.CheckAccessToken())
  72 + web.InsertFilter("/v1/cost/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/cost", cost_structured.NewHttpLibCostStructured(domain.Operator{})))
70 } 73 }
71 74
72 func AllowCors() func(ctx *context.Context) { 75 func AllowCors() func(ctx *context.Context) {
@@ -214,6 +214,8 @@ func defaultImport(controller *ExcelDataController) { @@ -214,6 +214,8 @@ func defaultImport(controller *ExcelDataController) {
214 data, err = excelService.ImportProduct(cmd) 214 data, err = excelService.ImportProduct(cmd)
215 case domain.ImportDevices: 215 case domain.ImportDevices:
216 data, err = excelService.ImportDevice(cmd) 216 data, err = excelService.ImportDevice(cmd)
  217 + case domain.ImportCosts:
  218 + data,err = excelService.ImportCost(cmd)
217 default: 219 default:
218 err = fmt.Errorf("导入不存在 Code:%v", cmd.Code) 220 err = fmt.Errorf("导入不存在 Code:%v", cmd.Code)
219 } 221 }
  1 +package oss
  2 +
  3 +import (
  4 + "bytes"
  5 + "fmt"
  6 + "github.com/aliyun/aliyun-oss-go-sdk/oss"
  7 + "github.com/linmadan/egglib-go/utils/snowflake"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
  9 +)
  10 +
  11 +var snow, _ = snowflake.NewIdWorker(1)
  12 +
  13 +func UploadOss(data []byte) (string, error) {
  14 + client, err := oss.New("oss-cn-shenzhen.aliyuncs.com", constant.OssAccessKey, constant.OssSecret)
  15 + if err != nil {
  16 + return "", err
  17 + }
  18 + bucket, err := client.Bucket(constant.OssBucket)
  19 + if err != nil {
  20 + return "", err
  21 + }
  22 + fileId, err := snow.NextId()
  23 + if err != nil {
  24 + return "", err
  25 + }
  26 + fileName := "costs/" + fmt.Sprintf("%v", fileId)
  27 + err = bucket.PutObject(fileName, bytes.NewBuffer(data))
  28 + return constant.OssDomain +"/"+ fileName, err
  29 +}
  1 +package oss
  2 +
  3 +import (
  4 + "fmt"
  5 + "io/ioutil"
  6 + "testing"
  7 +)
  8 +
  9 +func TestOss(t *testing.T){
  10 + mBytes,_:=ioutil.ReadFile("./test.png")
  11 + result,err := UploadOss(mBytes)
  12 + fmt.Println(result,err)
  13 +}