animeic 2 yıl önce
ebeveyn
işleme
82c45f9aa5

+ 8 - 0
boxcost/api/bill-produce.go

@@ -155,6 +155,14 @@ func GetProduceBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		query["planId"], _ = primitive.ObjectIDFromHex(query["planId"].(string))
 	}
 
+	// 时间范围查询
+	// createTime 选中的当天时间
+	if ct, ok := query["createTime"]; ok {
+		startTime, endTime := getDayRange(ct.(time.Time))
+		delete(query, "createTime")
+		query["createTime"] = bson.M{"$gte": startTime, "$lte": endTime}
+	}
+
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillProduce,
 		Query:       query,

+ 8 - 0
boxcost/api/bill.go

@@ -163,6 +163,14 @@ func GetBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		query["planId"], _ = primitive.ObjectIDFromHex(query["planId"].(string))
 	}
 
+	// 时间范围查询
+	// createTime 选中的当天时间
+	if ct, ok := query["createTime"]; ok {
+		startTime, endTime := getDayRange(ct.(time.Time))
+		delete(query, "createTime")
+		query["createTime"] = bson.M{"$gte": startTime, "$lte": endTime}
+	}
+
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillPurchase,
 		Query:       query,

+ 0 - 117
boxcost/api/prcess.go

@@ -1,117 +0,0 @@
-package api
-
-import (
-	"box-cost/db/model"
-	"box-cost/db/repo"
-	"box-cost/log"
-	"errors"
-	"fmt"
-	"time"
-
-	"github.com/gin-gonic/gin"
-	"go.mongodb.org/mongo-driver/bson"
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-// 工序管理
-func Process(r *GinRouter) {
-
-	// 创建工序
-	r.POST("/process", CreateProcess)
-
-	// 获取工序详情
-	r.GET("/process/:id", GetProcess)
-
-	// 获取工序列表
-	r.GET("/process/list", GetProcesss)
-
-	// 更新工序
-	r.POST("/process/update", UpdateProcess)
-
-	// 删除工序
-	r.POST("/process/delete/:id", DelProcess)
-}
-
-// 创建工序
-func CreateProcess(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	var process model.Process
-
-	err := c.ShouldBindJSON(&process)
-	if err != nil {
-		fmt.Println(err)
-		return nil, errors.New("参数错误!")
-	}
-	ctx := apictx.CreateRepoCtx()
-
-	if process.Name == "" {
-		return nil, errors.New("工序名为空")
-	}
-
-	process.CreateTime = time.Now()
-	process.UpdateTime = time.Now()
-
-	result, err := repo.RepoAddDoc(ctx, repo.CollectionProcess, &process)
-	return result, err
-}
-
-// 获取工序详情
-func GetProcess(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	processId := c.Param("id")
-	id, err := primitive.ObjectIDFromHex(processId)
-	if err != nil {
-		return nil, errors.New("非法id")
-	}
-	var process model.Process
-	option := &repo.DocSearchOptions{
-		CollectName: repo.CollectionProcess,
-		Query:       repo.Map{"_id": id},
-	}
-
-	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), option, &process)
-	if !found || err != nil {
-		log.Info(err)
-		return nil, errors.New("数据未找到")
-	}
-
-	return process, nil
-}
-
-// 获取工序列表
-func GetProcesss(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	page, size, query := UtilQueryPageSize(c)
-
-	option := &repo.PageSearchOptions{
-		CollectName: repo.CollectionProcess,
-		Query:       query,
-		Page:        page,
-		Size:        size,
-		Sort:        bson.M{"createTime": -1},
-	}
-	return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
-}
-
-// 更新工序
-func UpdateProcess(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var process model.Process
-	err := c.ShouldBindJSON(&process)
-	if err != nil {
-		return nil, errors.New("参数错误")
-	}
-	if process.Id.Hex() == "" {
-		return nil, errors.New("id的为空")
-	}
-	process.UpdateTime = time.Now()
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionProcess, process.Id.Hex(), &process)
-}
-
-// 删除工序
-func DelProcess(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	processId := c.Param("id")
-	if processId == "" {
-		return nil, errors.New("id为空")
-	}
-
-	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionProcess, processId)
-}

+ 10 - 91
boxcost/api/print.go

@@ -2,102 +2,21 @@ package api
 
 import (
 	"fmt"
-	"os"
-	"os/exec"
-	"path"
-	"runtime"
-	"strings"
-	"testing"
+	"time"
 
 	"github.com/gin-gonic/gin"
 )
 
 func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	loc, _ := time.LoadLocation("Local")
+	date := time.Now().Format("2006-01-02")
+	startDate := date + " 00:00:00"
+	startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", startDate, loc)
+	endDate := date + " 23:59:59"
+	endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", endDate, loc)
+	fmt.Println(startTime.Unix())
+	fmt.Println(endTime.Unix())
 
-	return nil, nil
+	return "success", nil
 
 }
-
-func TestToPdf(t *testing.T) {
-
-	fileSrcPath := "/Users/xing/Desktop/123/test2.docx" //自己机器上的文件地址
-	outPath := "/Users/xing/Desktop/123/pdf"            //转出文件的路径
-	fileType := "pdf"
-
-	osName := runtime.GOOS //获取系统类型
-	switch osName {
-	case "darwin": //mac系统
-		command := "/Applications/LibreOffice.app/Contents/MacOS/soffice"
-		pdfFile, err := FuncDocs2Pdf(command, fileSrcPath, outPath, fileType)
-		if err != nil {
-			println("转化异常:", err.Error())
-		}
-		fmt.Println("转化后的文件:", pdfFile)
-	case "linux":
-		command := "libreoffice7.3"
-		pdfFile, err := FuncDocs2Pdf(command, fileSrcPath, outPath, fileType)
-		if err != nil {
-			println("转化异常:", err.Error())
-		}
-		fmt.Println("转化后的文件:", pdfFile)
-	case "windows":
-		command := "soffice libreoffice" // 因为没有windows机器需要自己测试下这个命令行
-		pdfFile, err := FuncDocs2Pdf(command, fileSrcPath, outPath, fileType)
-		if err != nil {
-			println("转化异常:", err.Error())
-		}
-		fmt.Println("转化后的文件:", pdfFile)
-	default:
-		fmt.Println("暂时不支持的系统转化:" + runtime.GOOS)
-	}
-}
-
-/**
-*@tips libreoffice 转换指令:
-* libreoffice6.2 invisible --convert-to pdf csDoc.doc --outdir /home/[转出目录]
-*
-* @function 实现文档类型转换为pdf或html
-* @param command:libreofficed的命令(具体以版本为准);win:soffice; linux:libreoffice6.2
-*     fileSrcPath:转换文件的路径
-*     fileOutDir:转换后文件存储目录
-*     converterType:转换的类型pdf/html
-* @return fileOutPath 转换成功生成的文件的路径 error 转换错误
- */
-func FuncDocs2Pdf(command string, fileSrcPath string, fileOutDir string, converterType string) (fileOutPath string, error error) {
-	//校验fileSrcPath
-	srcFile, erByOpenSrcFile := os.Open(fileSrcPath)
-	if erByOpenSrcFile != nil && os.IsNotExist(erByOpenSrcFile) {
-		return "", erByOpenSrcFile
-	}
-	//如文件输出目录fileOutDir不存在则自动创建
-	outFileDir, erByOpenFileOutDir := os.Open(fileOutDir)
-	if erByOpenFileOutDir != nil && os.IsNotExist(erByOpenFileOutDir) {
-		erByCreateFileOutDir := os.MkdirAll(fileOutDir, os.ModePerm)
-		if erByCreateFileOutDir != nil {
-			fmt.Println("File ouput dir create error.....", erByCreateFileOutDir.Error())
-			return "", erByCreateFileOutDir
-		}
-	}
-	//关闭流
-	defer func() {
-		_ = srcFile.Close()
-		_ = outFileDir.Close()
-	}()
-	//convert
-	cmd := exec.Command(command, "--invisible", "--language=zh-CN", "--convert-to", converterType,
-		fileSrcPath, "--outdir", fileOutDir)
-	byteByStat, errByCmdStart := cmd.Output()
-	//命令调用转换失败
-	if errByCmdStart != nil {
-		return "", errByCmdStart
-	}
-	//success
-	fileOutPath = fileOutDir + "/" + strings.Split(path.Base(fileSrcPath), ".")[0]
-	if converterType == "html" {
-		fileOutPath += ".html"
-	} else {
-		fileOutPath += ".pdf"
-	}
-	fmt.Println("文件转换成功...", string(byteByStat))
-	return fileOutPath, nil
-}

+ 0 - 63
boxcost/api/print_test.go

@@ -1,63 +0,0 @@
-package api
-
-import (
-	"testing"
-)
-
-func TestFib(t *testing.T) {
-	var (
-		in       = 7
-		expected = 13
-	)
-	actual := Fib(in)
-	if actual != expected {
-		t.Errorf("-----")
-	}
-	t.Logf("%s", "sucess")
-}
-
-func Fib(n int) int {
-	if n < 2 {
-		return n
-	}
-	return Fib(n-1) + Fib(n-2)
-}
-
-// func BenchmarkHello(b *testing.B) {
-// 	for i := 0; 1 < b.N; i++ {
-// 		fmt.Sprintf("hello")
-// 	}
-// }
-
-// func BenchmarkFib10(b *testing.B) {
-
-//		for n := 0; n < b.N; n++ {
-//			Fib(10)
-//		}
-//	}
-func BenchmarkFib1(b *testing.B) {
-	benchmarkFib(1, b)
-}
-func BenchmarkFib2(b *testing.B) {
-	benchmarkFib(2, b)
-}
-func BenchmarkFib3(b *testing.B) {
-
-	benchmarkFib(3, b)
-}
-func BenchmarkFib10(b *testing.B) {
-	benchmarkFib(10, b)
-}
-func BenchmarkFib20(b *testing.B) {
-	benchmarkFib(20, b)
-}
-func BenchmarkFib40(b *testing.B) {
-	benchmarkFib(40, b)
-}
-
-func benchmarkFib(i int, b *testing.B) {
-	b.ReportAllocs()
-	for n := 0; n < b.N; n++ {
-		Fib(i)
-	}
-}

+ 0 - 3
boxcost/api/router.go

@@ -22,9 +22,6 @@ func RegRouters(svc *Service) {
 	// 工艺管理
 	Craft(boxcost)
 
-	// 工序管理
-	Process(boxcost)
-
 	// 供应商管理
 	Supplier(boxcost)
 

+ 11 - 0
boxcost/api/utils.go

@@ -104,3 +104,14 @@ func getUserById(apictx *ApiSession, id primitive.ObjectID) (*model.UserSmaple,
 	}, user)
 	return user, err
 }
+
+// 获取一天的起始终止时间
+func getDayRange(t time.Time) (start, end time.Time) {
+	loc, _ := time.LoadLocation("Local")
+	date := t.Format("2006-01-02")
+	startDate := date + " 00:00:00"
+	startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", startDate, loc)
+	endDate := date + " 23:59:59"
+	endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", endDate, loc)
+	return startTime, endTime
+}

+ 2 - 2
boxcost/app.yaml

@@ -29,7 +29,7 @@ debug:
   UserRole: string
 
 nats:
-  url: nats://124.71.139.24:14300
-  # url: nats://127.0.0.1:14300
+  # url: nats://124.71.139.24:14300
+  url: nats://127.0.0.1:14300
   maxReconnect: 1000
   reconnDelaySecond: 5

+ 1 - 1
boxcost/db/db.go

@@ -35,7 +35,7 @@ func (db *MongoDB) GetOrCreateDatabase(name string) *mongo.Database {
 }
 
 func NewMongoDB(bus *comm.NatsBus) *MongoDB {
-	inst, err := bus.NewMongoDBFromConfigDev("box-mongo")
+	inst, err := bus.NewMongoDBFromConfig("box-mongo")
 	if err != nil {
 		panic(err)
 	}

+ 0 - 1
boxcost/db/repo/repo.go

@@ -20,7 +20,6 @@ type RepoSession struct {
 const (
 	CollectionMaterial      = "material"
 	CollectionCraft         = "craft"
-	CollectionProcess       = "process"
 	CollectionSupplier      = "supplier"
 	CollectionSupplierPrice = "supplier-price"
 	CollectionPack          = "pack"