Эх сурвалжийг харах

2024-01-18 优化单价,添加运输条码

zoie 1 жил өмнө
parent
commit
7182d76daa

+ 1 - 1
conf/app.conf

@@ -49,7 +49,7 @@ FilterNotEnterDeptURL = "/api/medicine-template/init"
 
 
 # 统一身份认证
 # 统一身份认证
 # OAuth_baseUrl = "http://192.168.11.77:8100"
 # OAuth_baseUrl = "http://192.168.11.77:8100"
-OAuth_baseUrl = "http://127.0.0.1:8001"
+OAuth_baseUrl = "http://127.0.0.1:8000"
 # 服务发现服务信息
 # 服务发现服务信息
 Service_number = "q9YeglML"
 Service_number = "q9YeglML"
 Service_authCode = "3EDJRaagFTVVo2Ilo80nHJfLVN1O1234"
 Service_authCode = "3EDJRaagFTVVo2Ilo80nHJfLVN1O1234"

+ 34 - 28
controllers/sales.go

@@ -92,19 +92,19 @@ func (c SalesController) SalesExcel() {
 	f.SetCellValue("Sheet1", "G2", "批号")
 	f.SetCellValue("Sheet1", "G2", "批号")
 	f.SetCellValue("Sheet1", "H2", "数量")
 	f.SetCellValue("Sheet1", "H2", "数量")
 	f.SetCellValue("Sheet1", "I2", "单位")
 	f.SetCellValue("Sheet1", "I2", "单位")
-	f.SetCellValue("Sheet1", "J2", "购进单价")
-	f.SetCellValue("Sheet1", "K2", "购进金额")
-	f.SetCellValue("Sheet1", "L2", "销售单价")
-	f.SetCellValue("Sheet1", "M2", "销售金额")
-	f.SetCellValue("Sheet1", "N2", "批准文号")
+	f.SetCellValue("Sheet1", "J2", "单价")
+	f.SetCellValue("Sheet1", "K2", "金额")
+	//f.SetCellValue("Sheet1", "L2", "销售单价")
+	//f.SetCellValue("Sheet1", "M2", "销售金额")
+	f.SetCellValue("Sheet1", "L2", "批准文号")
 	// 设置列宽
 	// 设置列宽
 	f.SetColWidth("Sheet1", "A", "A", 12)
 	f.SetColWidth("Sheet1", "A", "A", 12)
 	f.SetColWidth("Sheet1", "B", "C", 15)
 	f.SetColWidth("Sheet1", "B", "C", 15)
-	f.SetColWidth("Sheet1", "C", "E", 15)
+	f.SetColWidth("Sheet1", "C", "E", 23)
 	f.SetColWidth("Sheet1", "E", "F", 15)
 	f.SetColWidth("Sheet1", "E", "F", 15)
 	f.SetColWidth("Sheet1", "F", "G", 12)
 	f.SetColWidth("Sheet1", "F", "G", 12)
 	f.SetColWidth("Sheet1", "H", "I", 10)
 	f.SetColWidth("Sheet1", "H", "I", 10)
-	f.SetColWidth("Sheet1", "J", "N", 12)
+	f.SetColWidth("Sheet1", "J", "L", 12)
 
 
 	line := 2
 	line := 2
 
 
@@ -121,11 +121,9 @@ func (c SalesController) SalesExcel() {
 		f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v[models.FieldBatchNumber])
 		f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v[models.FieldBatchNumber])
 		f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v["quantity"])
 		f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v["quantity"])
 		f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v[models.FieldUnitName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v[models.FieldUnitName])
-		f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), utils.ToFloat64(v["purchase_unit_price"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), utils.ToFloat64(v["purchase_money"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), utils.ToFloat64(v["sales_unit_price"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), utils.ToFloat64(v["sales_money"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), v[models.FieldApprovalNumber])
+		f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), utils.ToFloat64(v["unit_price"]))
+		f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), utils.ToFloat64(v["money"]))
+		f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), v[models.FieldApprovalNumber])
 
 
 	}
 	}
 	Style1, _ := f.NewStyle(
 	Style1, _ := f.NewStyle(
@@ -211,15 +209,15 @@ func (c SalesController) SalesReportExcel() {
 	f.SetCellValue("Sheet1", "C2", "规格")
 	f.SetCellValue("Sheet1", "C2", "规格")
 	f.SetCellValue("Sheet1", "D2", "数量")
 	f.SetCellValue("Sheet1", "D2", "数量")
 	f.SetCellValue("Sheet1", "E2", "单位")
 	f.SetCellValue("Sheet1", "E2", "单位")
-	f.SetCellValue("Sheet1", "F2", "购进单价")
-	f.SetCellValue("Sheet1", "G2", "购进金额")
-	f.SetCellValue("Sheet1", "H2", "销售单价")
-	f.SetCellValue("Sheet1", "I2", "销售金额")
-	f.SetCellValue("Sheet1", "J2", "利润金额")
+	f.SetCellValue("Sheet1", "F2", "单价")
+	f.SetCellValue("Sheet1", "G2", "金额")
+	//f.SetCellValue("Sheet1", "H2", "销售单价")
+	//f.SetCellValue("Sheet1", "I2", "销售金额")
+	//f.SetCellValue("Sheet1", "J2", "利润金额")
 	// 设置列宽
 	// 设置列宽
-	f.SetColWidth("Sheet1", "A", "C", 15)
+	f.SetColWidth("Sheet1", "A", "C", 27)
 	f.SetColWidth("Sheet1", "D", "E", 10)
 	f.SetColWidth("Sheet1", "D", "E", 10)
-	f.SetColWidth("Sheet1", "F", "J", 12)
+	f.SetColWidth("Sheet1", "F", "G", 12)
 
 
 	line := 2
 	line := 2
 
 
@@ -231,19 +229,19 @@ func (c SalesController) SalesReportExcel() {
 		f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldSpecName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldSpecName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), utils.ToInt(v["total"]))
 		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), utils.ToInt(v["total"]))
 		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldUnitName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldUnitName])
-		f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), utils.ToFloat64(v["purchase_unit_price"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), utils.ToFloat64(v["purchase_money"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToFloat64(v["sales_unit_price"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), utils.ToFloat64(v["sales_money"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), utils.ToFloat64(v["profit_money"]))
+		f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), utils.ToFloat64(v["unit_price"]))
+		f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), utils.ToFloat64(v["money"]))
+		//f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToFloat64(v["sales_unit_price"]))
+		//f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), utils.ToFloat64(v["sales_money"]))
+		//f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), utils.ToFloat64(v["profit_money"]))
 
 
 	}
 	}
 	line += 1
 	line += 1
 	f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "合计")
 	f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "合计")
 	f.SetCellFormula("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("SUM(D3:D%d)", line-1))
 	f.SetCellFormula("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("SUM(D3:D%d)", line-1))
 	f.SetCellFormula("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("SUM(G3:G%d)", line-1))
 	f.SetCellFormula("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("SUM(G3:G%d)", line-1))
-	f.SetCellFormula("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("SUM(I3:I%d)", line-1))
-	f.SetCellFormula("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("SUM(J3:J%d)", line-1))
+	//f.SetCellFormula("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("SUM(I3:I%d)", line-1))
+	//f.SetCellFormula("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("SUM(J3:J%d)", line-1))
 	Style1, _ := f.NewStyle(
 	Style1, _ := f.NewStyle(
 		&excelize.Style{
 		&excelize.Style{
 			Font:      &excelize.Font{Size: 14, Family: "宋体", Bold: true},
 			Font:      &excelize.Font{Size: 14, Family: "宋体", Bold: true},
@@ -464,7 +462,11 @@ func (c SalesController) SalesStockOutPdf1(reqData dto.SalesStockOutExcelReq) {
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
 		temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
 		temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
-		temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		if row[models.FieldApprovalNumber] == nil {
+			temp = append(temp, "")
+		} else {
+			temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		}
 		temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
 		temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldUnitName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldUnitName]))
 		temp = append(temp, fmt.Sprintf("%.2f", utils.ToFloat64(row["sales_unit_price"])))
 		temp = append(temp, fmt.Sprintf("%.2f", utils.ToFloat64(row["sales_unit_price"])))
@@ -595,7 +597,11 @@ func (c SalesController) SalesStockOutPdf(reqData dto.SalesStockOutExcelReq) {
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
 		temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
 		temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
-		temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		if row[models.FieldApprovalNumber] == nil {
+			temp = append(temp, "")
+		} else {
+			temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		}
 		temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
 		temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldUnitName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldUnitName]))
 		temp = append(temp, fmt.Sprintf("%.2f", utils.ToFloat64(row["sales_unit_price"])))
 		temp = append(temp, fmt.Sprintf("%.2f", utils.ToFloat64(row["sales_unit_price"])))

+ 144 - 30
controllers/stock_template.go

@@ -11,11 +11,16 @@ import (
 	"baliance.com/gooxml/document"
 	"baliance.com/gooxml/document"
 	"baliance.com/gooxml/measurement"
 	"baliance.com/gooxml/measurement"
 	"baliance.com/gooxml/schema/soo/wml"
 	"baliance.com/gooxml/schema/soo/wml"
+	"errors"
 	"fmt"
 	"fmt"
+	"github.com/boombuler/barcode"
+	"github.com/boombuler/barcode/code128"
 	"github.com/jung-kurt/gofpdf"
 	"github.com/jung-kurt/gofpdf"
+	"github.com/ser163/png2j"
 	"github.com/signintech/gopdf"
 	"github.com/signintech/gopdf"
 	"github.com/xuri/excelize/v2"
 	"github.com/xuri/excelize/v2"
 	"gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
 	"gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
+	"image/png"
 	"os"
 	"os"
 	"time"
 	"time"
 )
 )
@@ -369,11 +374,6 @@ func (c StockTemplateController) StockTemplateInventoryList() {
 // @Security Bearer
 // @Security Bearer
 func (c StockTemplateController) StockTemplateInventoryExcel(reqData dto.StockTemplateInventoryExcelReq) {
 func (c StockTemplateController) StockTemplateInventoryExcel(reqData dto.StockTemplateInventoryExcelReq) {
 	s := services.StockTemplate{}
 	s := services.StockTemplate{}
-	//reqData := dto.StockTemplateInventoryExcelReq{}
-	//if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
-	//	c.Error(global.ParseFormErr, err, err.Error())
-	//	return
-	//}
 	deptId := beegouser.GetDeptId(c.Ctx)
 	deptId := beegouser.GetDeptId(c.Ctx)
 	models.InitBasicData(deptId)
 	models.InitBasicData(deptId)
 	medicineInfo, err := s.GetMedicineInfo(deptId, map[string]interface{}{
 	medicineInfo, err := s.GetMedicineInfo(deptId, map[string]interface{}{
@@ -469,7 +469,8 @@ func (c StockTemplateController) StockTemplateInventoryExcel(reqData dto.StockTe
 
 
 	// 设置列宽
 	// 设置列宽
 	f.SetColWidth("Sheet1", "A", "B", 10)
 	f.SetColWidth("Sheet1", "A", "B", 10)
-	f.SetColWidth("Sheet1", "B", "F", 12)
+	f.SetColWidth("Sheet1", "B", "C", 14)
+	f.SetColWidth("Sheet1", "C", "F", 12)
 	f.SetColWidth("Sheet1", "F", "G", 8)
 	f.SetColWidth("Sheet1", "F", "G", 8)
 	f.SetColWidth("Sheet1", "G", "I", 12)
 	f.SetColWidth("Sheet1", "G", "I", 12)
 	f.SetColWidth("Sheet1", "I", "J", 8)
 	f.SetColWidth("Sheet1", "I", "J", 8)
@@ -593,8 +594,16 @@ func (c StockTemplateController) StockTemplateInventoryPdf1(reqData dto.StockTem
 			temp = append(temp, fmt.Sprintf("%s", row["receiving_unit"]))
 			temp = append(temp, fmt.Sprintf("%s", row["receiving_unit"]))
 		}
 		}
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
-		temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
-		temp = append(temp, fmt.Sprintf("%s", row[models.FieldQualificationNumber]))
+		if row[models.FieldApprovalNumber] == nil {
+			temp = append(temp, "")
+		} else {
+			temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		}
+		if row[models.FieldQualificationNumber] == nil {
+			temp = append(temp, "")
+		} else {
+			temp = append(temp, fmt.Sprintf("%s", row[models.FieldQualificationNumber]))
+		}
 
 
 		if utils.ToInt(row["stock_in_id"]) > 0 {
 		if utils.ToInt(row["stock_in_id"]) > 0 {
 			temp = append(temp, fmt.Sprintf("%d", row["total_in"]))
 			temp = append(temp, fmt.Sprintf("%d", row["total_in"]))
@@ -813,7 +822,11 @@ func (c StockTemplateController) StockTemplateInventoryPdf(reqData dto.StockTemp
 			temp = append(temp, fmt.Sprintf("%s", row["receiving_unit"]))
 			temp = append(temp, fmt.Sprintf("%s", row["receiving_unit"]))
 		}
 		}
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
-		temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		if row[models.FieldApprovalNumber] != nil {
+			temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		} else {
+			temp = append(temp, "")
+		}
 		if row[models.FieldQualificationNumber] != nil {
 		if row[models.FieldQualificationNumber] != nil {
 			temp = append(temp, fmt.Sprintf("%s", row[models.FieldQualificationNumber]))
 			temp = append(temp, fmt.Sprintf("%s", row[models.FieldQualificationNumber]))
 		} else {
 		} else {
@@ -948,7 +961,7 @@ func (c StockTemplateController) StockTemplateInventoryExport() {
 	}
 	}
 }
 }
 
 
-func (c StockTemplateController) TransportRecordWord(reqData dto.TransportRecordWordReq) {
+func (c StockTemplateController) TransportRecordWord(reqData models.TransportRecord) {
 	s := services.StockTemplate{}
 	s := services.StockTemplate{}
 	deptId := beegouser.GetDeptId(c.Ctx)
 	deptId := beegouser.GetDeptId(c.Ctx)
 
 
@@ -1901,7 +1914,7 @@ func (c StockTemplateController) TransportRecordWord(reqData dto.TransportRecord
 	c.Ctx.Output.Download("ofile/" + filename)
 	c.Ctx.Output.Download("ofile/" + filename)
 }
 }
 
 
-func (c StockTemplateController) TransportRecordPdf1(reqData dto.TransportRecordWordReq) {
+func (c StockTemplateController) TransportRecordPdf1(reqData models.TransportRecord) {
 	s := services.StockTemplate{}
 	s := services.StockTemplate{}
 	deptId := beegouser.GetDeptId(c.Ctx)
 	deptId := beegouser.GetDeptId(c.Ctx)
 
 
@@ -2170,14 +2183,24 @@ func (c StockTemplateController) TransportRecordPdf1(reqData dto.TransportRecord
 	}
 	}
 	defer func() {
 	defer func() {
 		os.Remove("ofile/" + filename)
 		os.Remove("ofile/" + filename)
+		//os.Remove(imgPath)
 	}()
 	}()
 
 
 	// 返回生成的 Excel 文件
 	// 返回生成的 Excel 文件
 	c.Ctx.Output.Download("ofile/" + filename)
 	c.Ctx.Output.Download("ofile/" + filename)
 
 
 }
 }
-func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordWordReq) {
+
+func getImageBytes(filePath string) []byte {
+	b, err := os.ReadFile(filePath)
+	if err != nil {
+		panic(err)
+	}
+	return b
+}
+func (c StockTemplateController) TransportRecordPdf(reqData models.TransportRecord) {
 	s := services.StockTemplate{}
 	s := services.StockTemplate{}
+	barcodeServ := services.Barcode{}
 	deptId := beegouser.GetDeptId(c.Ctx)
 	deptId := beegouser.GetDeptId(c.Ctx)
 
 
 	list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
 	list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
@@ -2185,6 +2208,26 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 		c.Error(500, err, err.Error())
 		c.Error(500, err, err.Error())
 		return
 		return
 	}
 	}
+	reqData.DeptID = deptId
+	reqData.DeptName = beegouser.GetDeptName(c.Ctx)
+	reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
+	reqData.SetDeptId(deptId)
+	code, err := barcodeServ.Insert(reqData)
+	if err != nil {
+		err = errors.New("生成条码失败")
+		c.Error(500, err, err.Error())
+		return
+	}
+	cs, _ := code128.Encode(code)
+	// 创建一个要输出数据的文件
+	imgPath := "ofile/img/" + code + ".png"
+	file, _ := os.Create(imgPath)
+	//defer file.Close()
+
+	// 设置图片像素大小
+	qrCode, _ := barcode.Scale(cs, 205, 50)
+	// 将code128的条形码编码为png图片
+	png.Encode(file, qrCode)
 
 
 	cols := []float64{83, 50, 55, 72, 72, 50, 66, 50, 27, 30}
 	cols := []float64{83, 50, 55, 72, 72, 50, 66, 50, 27, 30}
 
 
@@ -2194,7 +2237,11 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 		temp := []string{}
 		temp := []string{}
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldProductName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldProductName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
 		temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
-		temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		if row[models.FieldApprovalNumber] == nil {
+			temp = append(temp, "")
+		} else {
+			temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
+		}
 		if row[models.FieldQualificationNumber] == nil {
 		if row[models.FieldQualificationNumber] == nil {
 			temp = append(temp, "")
 			temp = append(temp, "")
 		} else {
 		} else {
@@ -2215,7 +2262,6 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 		}
 		}
 	}
 	}
 
 
-
 	pdf := &gopdf.GoPdf{}
 	pdf := &gopdf.GoPdf{}
 	pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
 	pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
 	pdf.SetMarginTop(40)
 	pdf.SetMarginTop(40)
@@ -2223,11 +2269,22 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 
 
 	pdf.AddPage()
 	pdf.AddPage()
 	pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
 	pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
-	pdf.SetFont("simsun", "", 22)
 
 
 	pdf.SetMargins(2, 5, 5, 5)
 	pdf.SetMargins(2, 5, 5, 5)
+	pdf.SetFont("simsun", "", 10)
+	pdf.SetX(20)
+	pdf.SetY(20)
+	pdf.Text("[扫码入库]")
+	pdf.SetX(20)
+	pdf.SetY(32)
+	pdf.Text("NO:" + code)
+
+	imgPath2 := "ofile/img/" + code + ".jpg"
+	png2j.Con2jpg(imgPath, imgPath2)
+	pdf.Image(imgPath2, 20, 35, nil)
 
 
 	titleStr := "表3-4 运输记录表"
 	titleStr := "表3-4 运输记录表"
+	pdf.SetFont("simsun", "", 22)
 	textw, _ := pdf.MeasureTextWidth(titleStr)
 	textw, _ := pdf.MeasureTextWidth(titleStr)
 	pdf.SetX((595 / 2) - (textw / 2))
 	pdf.SetX((595 / 2) - (textw / 2))
 	pdf.SetY(40)
 	pdf.SetY(40)
@@ -2242,7 +2299,7 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 
 
 	pdf.SetFont("simsun", "", 10)
 	pdf.SetFont("simsun", "", 10)
 	curx, y := 20., pdf.GetY()
 	curx, y := 20., pdf.GetY()
-	y += 25
+	y += 35
 	pdf.SetXY(curx, y)
 	pdf.SetXY(curx, y)
 	pdf.Text("运输工具: □冷藏车  □运输车  □普通车辆  □无  □其他")
 	pdf.Text("运输工具: □冷藏车  □运输车  □普通车辆  □无  □其他")
 	y += 16
 	y += 16
@@ -2261,7 +2318,7 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 	x := curx
 	x := curx
 	pdf.SetFont("simsun", "", 9)
 	pdf.SetFont("simsun", "", 9)
 	for i := 0; i < len(header); i++ {
 	for i := 0; i < len(header); i++ {
-		utils.RectFillColor(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
+		utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
 		x += cols[i]
 		x += cols[i]
 	}
 	}
 	y += h
 	y += h
@@ -2315,7 +2372,7 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 	pdf.SetX(curx)
 	pdf.SetX(curx)
 	x = curx
 	x = curx
 	for i := 0; i < len(header2); i++ {
 	for i := 0; i < len(header2); i++ {
-		utils.RectFillColor(pdf, header2[i], 9, x, y, cols2[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
+		utils.RectFillColorMultiCell(pdf, header2[i], 9, x, y, cols2[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
 		x += cols2[i]
 		x += cols2[i]
 	}
 	}
 	y = pdf.GetY()
 	y = pdf.GetY()
@@ -2373,8 +2430,7 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 			x += width
 			x += width
 		}
 		}
 
 
-
-		pdf.SetNewY(y+height,height)
+		pdf.SetNewY(y+height, height)
 
 
 		if pdf.GetY() < 30 || pdf.GetY() > 810 {
 		if pdf.GetY() < 30 || pdf.GetY() > 810 {
 			pdf.SetY(30)
 			pdf.SetY(30)
@@ -2452,6 +2508,8 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 	}
 	}
 	defer func() {
 	defer func() {
 		os.Remove("ofile/" + filename)
 		os.Remove("ofile/" + filename)
+		os.Remove(imgPath)
+		os.Remove(imgPath2)
 	}()
 	}()
 
 
 	// 返回生成的 Excel 文件
 	// 返回生成的 Excel 文件
@@ -2468,7 +2526,7 @@ func (c StockTemplateController) TransportRecordPdf(reqData dto.TransportRecordW
 // @Router /stock-template/inventory/list [post]
 // @Router /stock-template/inventory/list [post]
 // @Security Bearer
 // @Security Bearer
 func (c StockTemplateController) TransportRecordExport() {
 func (c StockTemplateController) TransportRecordExport() {
-	reqData := dto.TransportRecordWordReq{}
+	reqData := models.TransportRecord{}
 	if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
 	if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
 		c.Error(global.ParseFormErr, err, err.Error())
 		c.Error(global.ParseFormErr, err, err.Error())
 		return
 		return
@@ -2601,18 +2659,18 @@ func (c StockTemplateController) StockInquiryExcel() {
 	f.SetCellValue("Sheet1", "D2", "剂型")
 	f.SetCellValue("Sheet1", "D2", "剂型")
 	f.SetCellValue("Sheet1", "E2", "单位")
 	f.SetCellValue("Sheet1", "E2", "单位")
 	f.SetCellValue("Sheet1", "F2", "数量")
 	f.SetCellValue("Sheet1", "F2", "数量")
-	f.SetCellValue("Sheet1", "G2", "购进单价")
-	f.SetCellValue("Sheet1", "H2", "销售单价")
-	f.SetCellValue("Sheet1", "I2", "批号")
-	f.SetCellValue("Sheet1", "J2", "失效日期")
-	f.SetCellValue("Sheet1", "K2", "批准文号")
-	f.SetCellValue("Sheet1", "L2", "批签发编号")
+	f.SetCellValue("Sheet1", "G2", "单价")
+	//f.SetCellValue("Sheet1", "H2", "销售单价")
+	f.SetCellValue("Sheet1", "H2", "批号")
+	f.SetCellValue("Sheet1", "I2", "失效日期")
+	f.SetCellValue("Sheet1", "J2", "批准文号")
+	f.SetCellValue("Sheet1", "K2", "批签发编号")
 	// 设置列宽
 	// 设置列宽
 	f.SetColWidth("Sheet1", "A", "A", 20)
 	f.SetColWidth("Sheet1", "A", "A", 20)
 	f.SetColWidth("Sheet1", "B", "C", 15)
 	f.SetColWidth("Sheet1", "B", "C", 15)
 	f.SetColWidth("Sheet1", "D", "F", 12)
 	f.SetColWidth("Sheet1", "D", "F", 12)
 	f.SetColWidth("Sheet1", "F", "G", 10)
 	f.SetColWidth("Sheet1", "F", "G", 10)
-	f.SetColWidth("Sheet1", "G", "I", 10)
+	f.SetColWidth("Sheet1", "G", "I", 15)
 	f.SetColWidth("Sheet1", "I", "J", 12)
 	f.SetColWidth("Sheet1", "I", "J", 12)
 	f.SetColWidth("Sheet1", "J", "L", 15)
 	f.SetColWidth("Sheet1", "J", "L", 15)
 
 
@@ -2628,8 +2686,8 @@ func (c StockTemplateController) StockInquiryExcel() {
 		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldDosageFormName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldDosageFormName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldUnitName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldUnitName])
 		f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v["balance"])
 		f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v["balance"])
-		f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), utils.ToFloat64(v["purchase_unit_price"]))
-		f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToFloat64(v["sales_unit_price"]))
+		f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), utils.ToFloat64(v["unit_price"]))
+		//f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToFloat64(v["sales_unit_price"]))
 		f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v["batch_number"])
 		f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v["batch_number"])
 		f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v[models.FieldExpiryDate])
 		f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v[models.FieldExpiryDate])
 		f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v["approval_number"])
 		f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v["approval_number"])
@@ -2917,3 +2975,59 @@ func (c *StockTemplateController) InventoryPdf() {
 	//return
 	//return
 
 
 }
 }
+
+// StockTemplateInScanBarCode 扫条码入库
+// @Summary 扫条码入库
+// @Description 扫条码入库
+// @Tags 库存
+// @Param body body dto.StockTemplateOutInsertReq true "body"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /stock-template/out [post]
+// @Security Bearer
+func (c StockTemplateController) StockTemplateInScanBarCode() {
+	s := services.StockTemplate{}
+	reqData := dto.BatchStockTemplateOutInsertReq{}
+	if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
+		c.Error(global.ParseFormErr, err, err.Error())
+		return
+	}
+
+	reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
+	reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
+	err := s.StockTemplateOutScanCode(&reqData)
+	if err != nil {
+		c.Error(500, err, err.Error())
+		return
+	}
+	c.OK(nil, "扫码出库成功")
+}
+
+func (c StockTemplateController) GetBarCodeInfo() {
+	barcodeSvc := services.Barcode{}
+	s := services.StockTemplate{}
+	//if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
+	//	c.Error(global.ParseFormErr, err, err.Error())
+	//	return
+	//}
+	codeStr := c.GetString("code")
+	reqData := dto.GetBarCodeInfoReq{Code: codeStr}
+
+	var code models.Barcode
+	//数据权限检查
+	err := barcodeSvc.Get(&reqData, &code)
+	if err != nil {
+		c.Error(500, err, err.Error())
+		return
+	}
+
+	list, err := s.StockTemplateTransportRecordWord(&code.Data, code.Data.DeptID)
+	if err != nil {
+		c.Error(500, err, err.Error())
+		return
+	}
+	for _, v := range list {
+		v["forwardingUnit"] = code.Data.DeptName
+	}
+
+	c.OK(list, "查询成功")
+}

+ 26 - 21
dto/stock_template.go

@@ -72,13 +72,13 @@ type BatchStockTemplateInInsertReq struct {
 // BatchStockTemplateOutInsertReq 增使用的结构体
 // BatchStockTemplateOutInsertReq 增使用的结构体
 type BatchStockTemplateOutInsertReq struct {
 type BatchStockTemplateOutInsertReq struct {
 	StockOutList []struct {
 	StockOutList []struct {
-		Id            int                    `json:"id" comment:"id" swaggerignore:"true"`
-		MedicineInfo  map[string]interface{} `json:"medicineInfo"`            // 药品信息
-		Quantity      int                    `json:"quantity"`                // 数量
-		UnitPrice     float32                `json:"unitPrice"`               // 购入单价
-		Operator      string                 `json:"operator"`                // 经办人
-		ReceivingUnit string                 `json:"receivingUnit"`           // 收货单位
-		Date          string                 `json:"date" valid:"MinSize(1)"` // 出库日期
+		Id           int                    `json:"id" comment:"id" swaggerignore:"true"`
+		MedicineInfo map[string]interface{} `json:"medicineInfo"` // 药品信息
+		Quantity     int                    `json:"quantity"`     // 数量
+		//UnitPrice     float32                `json:"unitPrice"`               // 销售单价
+		Operator      string `json:"operator"`                // 经办人
+		ReceivingUnit string `json:"receivingUnit"`           // 收货单位
+		Date          string `json:"date" valid:"MinSize(1)"` // 出库日期
 	} `json:"stockOutList"`
 	} `json:"stockOutList"`
 	common.ControlBy `swaggerignore:"true"`
 	common.ControlBy `swaggerignore:"true"`
 }
 }
@@ -89,11 +89,11 @@ type StockTemplateOutInsertReq struct {
 
 
 	MedicineInfo map[string]interface{} `json:"medicineInfo"` // 药品信息
 	MedicineInfo map[string]interface{} `json:"medicineInfo"` // 药品信息
 
 
-	Quantity      int     `json:"quantity" alias:"数量" valid:"Required;Min(1)"` // 数量
-	UnitPrice     float32 `json:"unitPrice"`                                   // 购入单价
-	Operator      string  `json:"operator"`                                    // 经办人
-	ReceivingUnit string  `json:"receivingUnit"`                               // 收货单位
-	Date          string  `json:"date"`                                        // 出库日期
+	Quantity int `json:"quantity" alias:"数量" valid:"Required;Min(1)"` // 数量
+	//UnitPrice     float32 `json:"unitPrice"`                                   // 购入单价
+	Operator      string `json:"operator"`      // 经办人
+	ReceivingUnit string `json:"receivingUnit"` // 收货单位
+	Date          string `json:"date"`          // 出库日期
 
 
 	common.ControlBy `swaggerignore:"true"`
 	common.ControlBy `swaggerignore:"true"`
 }
 }
@@ -109,11 +109,11 @@ type StockTemplateOutEditReq struct {
 
 
 	MedicineInfo map[string]interface{} `json:"medicineInfo"` // 药品信息
 	MedicineInfo map[string]interface{} `json:"medicineInfo"` // 药品信息
 
 
-	Quantity      int     `json:"quantity" alias:"数量" valid:"Required;Min(1)"` // 数量
-	UnitPrice     float32 `json:"unit_price"`                                  // 购入单价
-	Operator      string  `json:"operator"`                                    // 经办人
-	ReceivingUnit string  `json:"receiving_unit"`                              // 收货单位
-	Date          string  `json:"date"`                                        // 出库日期
+	Quantity int `json:"quantity" alias:"数量" valid:"Required;Min(1)"` // 数量
+	//UnitPrice     float32 `json:"unit_price"`                                  // 购入单价
+	Operator      string `json:"operator"`       // 经办人
+	ReceivingUnit string `json:"receiving_unit"` // 收货单位
+	Date          string `json:"date"`           // 出库日期
 
 
 	common.ControlBy `swaggerignore:"true"`
 	common.ControlBy `swaggerignore:"true"`
 }
 }
@@ -185,10 +185,11 @@ type StockTemplateInventoryExcelReq struct {
 
 
 // TransportRecordWordReq 列表或者搜索使用结构体
 // TransportRecordWordReq 列表或者搜索使用结构体
 type TransportRecordWordReq struct {
 type TransportRecordWordReq struct {
-	Date          string `json:"date"`          // 出库时间
-	ReceivingUnit string `json:"receivingUnit"` // 收货单位
-	ProductID     int    `json:"productId"`     // 药品名称id
-	Type          string `json:"type"`          // 类型
+	Date          string `json:"date"`                         // 出库时间
+	ReceivingUnit string `json:"receivingUnit"`                // 收货单位
+	ProductID     int    `json:"productId"`                    // 药品名称id
+	Type          string `json:"type"`                         // 类型
+	DeptID        string `json:"deptId"  swaggerignore:"true"` // 部门id
 }
 }
 
 
 // StockStatListReq 列表或者搜索使用结构体
 // StockStatListReq 列表或者搜索使用结构体
@@ -214,3 +215,7 @@ type StockUnitListReq struct {
 type StockOperatorListReq struct {
 type StockOperatorListReq struct {
 	Name string
 	Name string
 }
 }
+
+type GetBarCodeInfoReq struct {
+	Code string `json:"code"`
+}

+ 3 - 0
go.mod

@@ -5,6 +5,7 @@ go 1.19
 require (
 require (
 	baliance.com/gooxml v1.0.1
 	baliance.com/gooxml v1.0.1
 	github.com/beego/beego/v2 v2.1.0
 	github.com/beego/beego/v2 v2.1.0
+	github.com/boombuler/barcode v1.0.0
 	github.com/bytedance/go-tagexpr/v2 v2.7.12
 	github.com/bytedance/go-tagexpr/v2 v2.7.12
 	github.com/gin-gonic/gin v1.8.1
 	github.com/gin-gonic/gin v1.8.1
 	github.com/go-basic/uuid v1.0.0
 	github.com/go-basic/uuid v1.0.0
@@ -14,6 +15,7 @@ require (
 	github.com/gobwas/glob v0.2.3
 	github.com/gobwas/glob v0.2.3
 	github.com/google/uuid v1.3.0
 	github.com/google/uuid v1.3.0
 	github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5
 	github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5
+	github.com/ser163/png2j v0.1.2-beta
 	github.com/signintech/gopdf v0.20.0
 	github.com/signintech/gopdf v0.20.0
 	github.com/smartystreets/goconvey v1.8.1
 	github.com/smartystreets/goconvey v1.8.1
 	github.com/swaggo/swag v1.16.2
 	github.com/swaggo/swag v1.16.2
@@ -74,6 +76,7 @@ require (
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
 	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
+	github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
 	github.com/nsqio/go-nsq v1.0.8 // indirect
 	github.com/nsqio/go-nsq v1.0.8 // indirect
 	github.com/nyaruka/phonenumbers v1.0.55 // indirect
 	github.com/nyaruka/phonenumbers v1.0.55 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.2 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.2 // indirect

+ 6 - 7
go.sum

@@ -85,6 +85,7 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
 github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
 github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
+github.com/boombuler/barcode v1.0.0 h1:s1TvRnXwL2xJRaccrdcBQMZxq6X7DvsMogtmJeHDdrc=
 github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
 github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
 github.com/bsm/redislock v0.5.0 h1:ODM11/cbuUXQqLgZWK6XQnufaTjsBE2UcwBc2EAFNDA=
 github.com/bsm/redislock v0.5.0 h1:ODM11/cbuUXQqLgZWK6XQnufaTjsBE2UcwBc2EAFNDA=
 github.com/bsm/redislock v0.5.0/go.mod h1:qagqKlV+xiLy26iV34Y3zRPxRcJjQYbV7pZfWFeSZ8M=
 github.com/bsm/redislock v0.5.0/go.mod h1:qagqKlV+xiLy26iV34Y3zRPxRcJjQYbV7pZfWFeSZ8M=
@@ -200,8 +201,6 @@ github.com/go-redis/redis/v7 v7.2.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRf
 github.com/go-redis/redis/v7 v7.3.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
 github.com/go-redis/redis/v7 v7.3.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
 github.com/go-redis/redis/v7 v7.4.0 h1:7obg6wUoj05T0EpY0o8B59S9w5yeMWql7sw2kwNW1x4=
 github.com/go-redis/redis/v7 v7.4.0 h1:7obg6wUoj05T0EpY0o8B59S9w5yeMWql7sw2kwNW1x4=
 github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
 github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
-github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
-github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
 github.com/go-resty/resty/v2 v2.11.0 h1:i7jMfNOJYMp69lq7qozJP+bjgzfAzeOhuGlyDrqxT/8=
 github.com/go-resty/resty/v2 v2.11.0 h1:i7jMfNOJYMp69lq7qozJP+bjgzfAzeOhuGlyDrqxT/8=
 github.com/go-resty/resty/v2 v2.11.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A=
 github.com/go-resty/resty/v2 v2.11.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A=
 github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
@@ -457,6 +456,8 @@ github.com/nats-io/nats.go v1.12.1/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/
 github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s=
 github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s=
 github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
 github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
 github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
 github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
+github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
+github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 github.com/nsqio/go-nsq v1.0.8 h1:3L2F8tNLlwXXlp2slDUrUWSBn2O3nMh8R1/KEDFTHPk=
 github.com/nsqio/go-nsq v1.0.8 h1:3L2F8tNLlwXXlp2slDUrUWSBn2O3nMh8R1/KEDFTHPk=
 github.com/nsqio/go-nsq v1.0.8/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
 github.com/nsqio/go-nsq v1.0.8/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
@@ -552,6 +553,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
 github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
 github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
+github.com/ser163/png2j v0.1.2-beta h1:ri7e+tGw/Y1TV18x8O4uONqaHjyTv/L2rnI3Ft5bMeA=
+github.com/ser163/png2j v0.1.2-beta/go.mod h1:QusatApB4GgVnjdAL45Erna5GxAaAd7KsPv3mrswtp8=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
 github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
 github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
@@ -666,7 +669,6 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
 golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
 golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
 golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
-golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
 golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
 golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
 golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
 golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
 golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
 golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
@@ -755,7 +757,6 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT
 golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
 golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
@@ -763,7 +764,6 @@ golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
 golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
 golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
 golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
 golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
-golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
 golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
 golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
 golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
 golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
 golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
 golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
@@ -856,7 +856,6 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
 golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
 golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
@@ -883,7 +882,6 @@ golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
-golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
 golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
@@ -893,6 +891,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
 golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

+ 44 - 0
models/barcode.go

@@ -0,0 +1,44 @@
+package models
+
+import (
+	model2 "Medical_ERP/common/model"
+	"database/sql/driver"
+	"encoding/json"
+)
+
+// 运输记录表
+type TransportRecord struct {
+	Date             string `json:"date"`                           // 出库时间
+	ReceivingUnit    string `json:"receivingUnit"`                  // 收货单位
+	ProductID        int    `json:"productId"`                      // 药品名称id
+	Type             string `json:"type"`                           // 类型
+	DeptID           int    `json:"deptId"  swaggerignore:"true"`   // 部门id
+	DeptName         string `json:"deptName"  swaggerignore:"true"` // 部门名称
+	model2.ControlBy `gorm:"-"`
+}
+
+type Barcode struct {
+	model2.Model
+	Code string          `gorm:"size:128;index" json:"code"`            //条码编号
+	Data TransportRecord `gorm:"type:json;comment:'条码信息'" json:"data" ` // 条码信息
+	model2.ControlBy
+	model2.ModelTime
+}
+
+// Value 存储数据的时候转换为字符串
+func (e TransportRecord) Value() (driver.Value, error) {
+	d, err := json.Marshal(e)
+	return string(d), err
+}
+
+func (e *TransportRecord) Scan(src interface{}) error {
+	return json.Unmarshal(src.([]byte), e)
+}
+
+func (e *Barcode) TableName() string {
+	return "barcode"
+}
+
+func (e *Barcode) GetId() interface{} {
+	return e.Id
+}

+ 3 - 3
models/dosage_form.go

@@ -6,9 +6,9 @@ import (
 
 
 type DosageForm struct {
 type DosageForm struct {
 	model2.Model
 	model2.Model
-	Name   string `orm:"size(128)" json:"name"`                   //剂型名称
-	Sort   int    `orm:"size(4)" json:"-" swaggerignore:"true"`   //剂型排序
-	Remark string `orm:"size(255)" json:"-" swaggerignore:"true"` //描述
+	Name   string `gorm:"size:128" json:"name"`                   //剂型名称
+	Sort   int    `gorm:"size:4" json:"-" swaggerignore:"true"`   //剂型排序
+	Remark string `gorm:"size:255" json:"-" swaggerignore:"true"` //描述
 	model2.ControlBy
 	model2.ControlBy
 	model2.ModelTime
 	model2.ModelTime
 }
 }

+ 3 - 3
models/enterprise.go

@@ -7,9 +7,9 @@ import (
 // 生产企业
 // 生产企业
 type Enterprise struct {
 type Enterprise struct {
 	model2.Model
 	model2.Model
-	Name   string `orm:"size(128)" json:"name"`                   //生产企业名称
-	Sort   int    `orm:"size(4)" json:"-" swaggerignore:"true"`   //生产企业排序
-	Remark string `orm:"size(255)" json:"-" swaggerignore:"true"` //描述
+	Name   string `gorm:"size:128" json:"name"`                   //生产企业名称
+	Sort   int    `gorm:"size:4" json:"-" swaggerignore:"true"`   //生产企业排序
+	Remark string `gorm:"size:255" json:"-" swaggerignore:"true"` //描述
 	model2.ControlBy
 	model2.ControlBy
 	model2.ModelTime
 	model2.ModelTime
 }
 }

+ 1 - 0
models/init.go

@@ -27,6 +27,7 @@ func AutoMigrateDB() {
 			&StockIn{},
 			&StockIn{},
 			&StockOut{},
 			&StockOut{},
 			&MedicineInventory{},
 			&MedicineInventory{},
+			&Barcode{},
 		)
 		)
 	if err != nil {
 	if err != nil {
 		log.Fatalf("migrate db fail: %v", err)
 		log.Fatalf("migrate db fail: %v", err)

+ 4 - 2
models/medicine_template.go

@@ -76,12 +76,14 @@ func GetInitMedicineTemplateSql(deptId int) string {
         produced_date DATE comment '生产日期',
         produced_date DATE comment '生产日期',
         approval_number VARCHAR(256) comment '批准文号',
         approval_number VARCHAR(256) comment '批准文号',
         qualification_number VARCHAR(256) comment '批签发编号',
         qualification_number VARCHAR(256) comment '批签发编号',
-        purchase_unit_price DECIMAL(10,2) comment '购进单价',
-        sales_unit_price DECIMAL(10,2) comment '销售单价'
+        unit_price DECIMAL(10,2) comment '单价'
     );`
     );`
 	return sqlStmt
 	return sqlStmt
 }
 }
 
 
+//purchase_unit_price DECIMAL(10,2) comment '购进单价',
+//sales_unit_price DECIMAL(10,2) comment '销售单价'
+
 // 获取插入数据sql
 // 获取插入数据sql
 func GetInsertMedicineTemplateSql(deptId, typeId int, columnName string) string {
 func GetInsertMedicineTemplateSql(deptId, typeId int, columnName string) string {
 	var typeStr string
 	var typeStr string

+ 3 - 3
models/product.go

@@ -6,9 +6,9 @@ import (
 
 
 type Product struct {
 type Product struct {
 	model2.Model
 	model2.Model
-	Name   string `orm:"size(128)" json:"name"`                   //产品名称
-	Sort   int    `orm:"size(4)" json:"-" swaggerignore:"true"`   //产品排序
-	Remark string `orm:"size(255)" json:"-" swaggerignore:"true"` //描述
+	Name   string `gorm:"size:128" json:"name"`                   //产品名称
+	Sort   int    `gorm:"size:4" json:"-" swaggerignore:"true"`   //产品排序
+	Remark string `gorm:"size:255" json:"-" swaggerignore:"true"` //描述
 	model2.ControlBy
 	model2.ControlBy
 	model2.ModelTime
 	model2.ModelTime
 }
 }

+ 3 - 3
models/spec.go

@@ -6,9 +6,9 @@ import (
 
 
 type Spec struct {
 type Spec struct {
 	model2.Model
 	model2.Model
-	Name   string `orm:"size(128)" json:"name"`                   //规格名称
-	Sort   int    `orm:"size(4)" json:"-" swaggerignore:"true"`   //规格排序
-	Remark string `orm:"size(255)" json:"-" swaggerignore:"true"` //描述
+	Name   string `gorm:"size:128" json:"name"`                   //规格名称
+	Sort   int    `gorm:"size:4" json:"-" swaggerignore:"true"`   //规格排序
+	Remark string `gorm:"size:255" json:"-" swaggerignore:"true"` //描述
 	model2.ControlBy
 	model2.ControlBy
 	model2.ModelTime
 	model2.ModelTime
 }
 }

+ 6 - 6
models/stock_out.go

@@ -4,12 +4,12 @@ import model2 "Medical_ERP/common/model"
 
 
 type StockOut struct {
 type StockOut struct {
 	model2.Model
 	model2.Model
-	MedicineID    int     `json:"medicineId" gorm:"size:4;not null;comment:药品信息ID"` // 药品信息ID
-	Quantity      int     `json:"quantity" gorm:"size:128;"`                        // 数量
-	UnitPrice     float32 `json:"unitPrice"`                                        // 购入单价
-	Operator      string  `json:"operator" gorm:"size:128;"`                        // 经办人
-	ReceivingUnit string  `json:"receivingUnit" gorm:"size:128;"`                   // 收货单位
-	Date          string  `json:"date" gorm:"size:128;"`                            // 入库日期
+	MedicineID int `json:"medicineId" gorm:"size:4;not null;comment:药品信息ID"` // 药品信息ID
+	Quantity   int `json:"quantity" gorm:"size:128;"`                        // 数量
+	//UnitPrice     float32 `json:"unitPrice"`                                        // 销售单价
+	Operator      string `json:"operator" gorm:"size:128;"`      // 经办人
+	ReceivingUnit string `json:"receivingUnit" gorm:"size:128;"` // 收货单位
+	Date          string `json:"date" gorm:"size:128;"`          // 入库日期
 	model2.ControlBy
 	model2.ControlBy
 	model2.ModelTime
 	model2.ModelTime
 }
 }

+ 3 - 3
models/unit.go

@@ -6,9 +6,9 @@ import (
 
 
 type Unit struct {
 type Unit struct {
 	model2.Model
 	model2.Model
-	Name   string `orm:"size(128)" json:"name"`                   //单位名称
-	Sort   int    `orm:"size(4)" json:"-" swaggerignore:"true"`   //单位排序
-	Remark string `orm:"size(255)" json:"-" swaggerignore:"true"` //描述
+	Name   string `gorm:"size:128" json:"name"`                   //单位名称
+	Sort   int    `gorm:"size:4" json:"-" swaggerignore:"true"`   //单位排序
+	Remark string `gorm:"size:255" json:"-" swaggerignore:"true"` //描述
 	model2.ControlBy
 	model2.ControlBy
 	model2.ModelTime
 	model2.ModelTime
 }
 }

+ 3 - 2
routers/stock.go

@@ -22,8 +22,9 @@ func init() {
 		beego.NSRouter("/inventory/export", &controllers.StockTemplateController{}, "*:StockTemplateInventoryExport"), // 库存 - excel
 		beego.NSRouter("/inventory/export", &controllers.StockTemplateController{}, "*:StockTemplateInventoryExport"), // 库存 - excel
 		beego.NSRouter("/inventory/pdf", &controllers.StockTemplateController{}, "*:InventoryPdf"),
 		beego.NSRouter("/inventory/pdf", &controllers.StockTemplateController{}, "*:InventoryPdf"),
 		beego.NSRouter("/transport-record/export", &controllers.StockTemplateController{}, "*:TransportRecordExport"),
 		beego.NSRouter("/transport-record/export", &controllers.StockTemplateController{}, "*:TransportRecordExport"),
-		beego.NSRouter("/scan-code-in", &controllers.StockTemplateController{}, "*:StockTemplateInScanCode"),   // 扫码入库
-		beego.NSRouter("/scan-code-out", &controllers.StockTemplateController{}, "*:StockTemplateOutScanCode"), // 扫码出库
+		beego.NSRouter("/transport-record/barcode-info", &controllers.StockTemplateController{}, "*:GetBarCodeInfo"), // 获取条码信息
+		beego.NSRouter("/scan-code-in", &controllers.StockTemplateController{}, "*:StockTemplateInScanCode"),         // 扫码入库
+		beego.NSRouter("/scan-code-out", &controllers.StockTemplateController{}, "*:StockTemplateOutScanCode"),       // 扫码出库
 	)
 	)
 	stock := beego.NewNamespace("/api/stock",
 	stock := beego.NewNamespace("/api/stock",
 		beego.NSRouter("/unit/list", &controllers.StockTemplateController{}, "*:StockUnitList"),         // 收/发货单位列表
 		beego.NSRouter("/unit/list", &controllers.StockTemplateController{}, "*:StockUnitList"),         // 收/发货单位列表

+ 61 - 0
services/barcode.go

@@ -0,0 +1,61 @@
+package services
+
+import (
+	"Medical_ERP/common/global"
+	db "Medical_ERP/common/initialize"
+	model2 "Medical_ERP/common/model"
+	"Medical_ERP/dto"
+	"Medical_ERP/models"
+	"errors"
+	"fmt"
+	"github.com/beego/beego/v2/core/logs"
+	"gorm.io/gorm"
+	"time"
+)
+
+type Barcode struct {
+}
+
+// getNextIncrementalCode 从数据库中获取下一个递增码
+func (e *Barcode) getNextIncrementalCode() (string, error) {
+	// 获取当前日期
+	var count int64
+	current := time.Now().Format("20060102")
+	err := db.DB.Model(&models.Barcode{}).Where("code LIKE ?", current+"%").Count(&count).Error
+	if err != nil {
+		logs.Error("db error: %s", err)
+		return "", err
+	}
+	return fmt.Sprintf("%s%04d", current, count+1), nil
+
+}
+
+// Insert 创建Spec对象
+func (e *Barcode) Insert(c models.TransportRecord) (code string, err error) {
+	incrementalCode, err := e.getNextIncrementalCode()
+	if err != nil {
+		logs.Error("生成条形码失败", err)
+		return code, global.CreateFailedErr
+	}
+	data := models.Barcode{Code: incrementalCode, Data: c, ControlBy: model2.ControlBy{CreateBy: c.CreateBy, DeptId: c.DeptId}}
+	err = db.DB.Create(&data).Error
+	if err != nil {
+		logs.Error("db error: %s", err)
+		return code, global.CreateFailedErr
+	}
+	return data.Code, nil
+}
+
+// Get 获取DosageForm对象
+func (e *Barcode) Get(d *dto.GetBarCodeInfoReq, barcodeModel *models.Barcode) error {
+	err := db.DB.Where("code = ?", d.Code).First(barcodeModel).Error
+
+	if err != nil {
+		logs.Error("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.GetNotFoundOrNoPermissionErr
+		}
+		return global.GetFailedErr
+	}
+	return nil
+}

+ 20 - 28
services/sales.go

@@ -18,7 +18,7 @@ type Sales struct {
 func (e *Sales) SalesList(c *dto.SalesPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 func (e *Sales) SalesList(c *dto.SalesPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 
 
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
-	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND unit_price > 0 AND stock_out.deleted_at is null"
+	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"
 	if c.ProductID > 0 {
 	if c.ProductID > 0 {
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 	}
 	}
@@ -38,7 +38,7 @@ func (e *Sales) SalesList(c *dto.SalesPageReq, deptId int) (list []map[string]in
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 	}
 	}
 	err = db.DB.Table("stock_out").
 	err = db.DB.Table("stock_out").
-		Select(mtable + ".*,stock_out.*,stock_out.unit_price as sales_unit_price").
+		//Select(mtable + ".*,stock_out.*,stock_out.unit_price as sales_unit_price").
 		Scopes(
 		Scopes(
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 		).
 		).
@@ -52,12 +52,9 @@ func (e *Sales) SalesList(c *dto.SalesPageReq, deptId int) (list []map[string]in
 	}
 	}
 	models.InitBasicData(deptId)
 	models.InitBasicData(deptId)
 	for i := 0; i < len(list); i++ {
 	for i := 0; i < len(list); i++ {
-		list[i]["purchase_unit_price"] = utils.ToFloat64(list[i]["purchase_unit_price"])
-		list[i]["sales_unit_price"] = utils.ToFloat64(list[i]["sales_unit_price"])
-		// 购进金额
-		list[i]["purchase_money"] = utils.ToFloat64(list[i]["purchase_unit_price"]) * utils.ToFloat64(list[i]["quantity"])
-		// 销售金额
-		list[i]["sales_money"] = utils.ToFloat64(list[i]["sales_unit_price"]) * utils.ToFloat64(list[i]["quantity"])
+		list[i]["unit_price"] = utils.ToFloat64(list[i]["unit_price"])
+		// 金额
+		list[i]["money"] = utils.ToFloat64(list[i]["unit_price"]) * utils.ToFloat64(list[i]["quantity"])
 		if id, ok := list[i][models.FieldProductID]; ok {
 		if id, ok := list[i][models.FieldProductID]; ok {
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 		}
 		}
@@ -79,7 +76,7 @@ func (e *Sales) SalesList(c *dto.SalesPageReq, deptId int) (list []map[string]in
 func (e *Sales) SalesListExcel(c *dto.SalesPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 func (e *Sales) SalesListExcel(c *dto.SalesPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 
 
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
-	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND unit_price > 0 AND stock_out.deleted_at is null"
+	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"
 	if c.ProductID > 0 {
 	if c.ProductID > 0 {
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 	}
 	}
@@ -99,7 +96,7 @@ func (e *Sales) SalesListExcel(c *dto.SalesPageReq, deptId int) (list []map[stri
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 	}
 	}
 	err = db.DB.Table("stock_out").
 	err = db.DB.Table("stock_out").
-		Select(mtable + ".*,stock_out.*,stock_out.unit_price as sales_unit_price").
+		//Select(mtable + ".*,stock_out.*," + mtable + ".unit_price as unit_price").
 		Joins("left join " + mtable + " on stock_out.medicine_id = " + mtable + ".id").
 		Joins("left join " + mtable + " on stock_out.medicine_id = " + mtable + ".id").
 		Where(whereSql).
 		Where(whereSql).
 		Scan(&list).Error
 		Scan(&list).Error
@@ -109,12 +106,9 @@ func (e *Sales) SalesListExcel(c *dto.SalesPageReq, deptId int) (list []map[stri
 	}
 	}
 	models.InitBasicData(deptId)
 	models.InitBasicData(deptId)
 	for i := 0; i < len(list); i++ {
 	for i := 0; i < len(list); i++ {
-		list[i]["purchase_unit_price"] = utils.ToFloat64(list[i]["purchase_unit_price"])
-		list[i]["sales_unit_price"] = utils.ToFloat64(list[i]["sales_unit_price"])
-		// 购进金额
-		list[i]["purchase_money"] = utils.ToFloat64(list[i]["purchase_unit_price"]) * utils.ToFloat64(list[i]["quantity"])
-		// 销售金额
-		list[i]["sales_money"] = utils.ToFloat64(list[i]["sales_unit_price"]) * utils.ToFloat64(list[i]["quantity"])
+		list[i]["unit_price"] = utils.ToFloat64(list[i]["unit_price"])
+		// 金额
+		list[i]["money"] = utils.ToFloat64(list[i]["unit_price"]) * utils.ToFloat64(list[i]["quantity"])
 		if id, ok := list[i][models.FieldProductID]; ok {
 		if id, ok := list[i][models.FieldProductID]; ok {
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 		}
 		}
@@ -138,7 +132,7 @@ func (e *Sales) SalesListExcel(c *dto.SalesPageReq, deptId int) (list []map[stri
 func (e *Sales) SalesReportList(c *dto.SalesPageReq, deptId int) (list []map[string]interface{}, err error) {
 func (e *Sales) SalesReportList(c *dto.SalesPageReq, deptId int) (list []map[string]interface{}, err error) {
 
 
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
-	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND unit_price > 0 AND stock_out.deleted_at is null"
+	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"
 	if c.ProductID > 0 {
 	if c.ProductID > 0 {
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 	}
 	}
@@ -166,13 +160,9 @@ func (e *Sales) SalesReportList(c *dto.SalesPageReq, deptId int) (list []map[str
 	}
 	}
 	models.InitBasicData(deptId)
 	models.InitBasicData(deptId)
 	for i := 0; i < len(list); i++ {
 	for i := 0; i < len(list); i++ {
-		list[i]["purchase_unit_price"] = utils.ToFloat64(list[i]["purchase_unit_price"])
-		list[i]["sales_unit_price"] = utils.ToFloat64(list[i]["sales_unit_price"])
-		// 购进金额
-		list[i]["purchase_money"] = utils.ToFloat64(list[i]["purchase_unit_price"]) * utils.ToFloat64(list[i]["total"])
-		// 销售金额
-		list[i]["sales_money"] = utils.ToFloat64(list[i]["sales_unit_price"]) * utils.ToFloat64(list[i]["total"])
-		list[i]["profit_money"] = utils.ToFloat64(list[i]["sales_money"]) - utils.ToFloat64(list[i]["purchase_money"])
+		list[i]["unit_price"] = utils.ToFloat64(list[i]["unit_price"])
+		// 金额
+		list[i]["money"] = utils.ToFloat64(list[i]["unit_price"]) * utils.ToFloat64(list[i]["total"])
 		if id, ok := list[i][models.FieldProductID]; ok {
 		if id, ok := list[i][models.FieldProductID]; ok {
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 		}
 		}
@@ -196,7 +186,7 @@ func (e *Sales) SalesReportList(c *dto.SalesPageReq, deptId int) (list []map[str
 func (e *Sales) SalesOrderList(c *dto.SalesOrderPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 func (e *Sales) SalesOrderList(c *dto.SalesOrderPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 
 
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
-	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND unit_price > 0 AND stock_out.deleted_at is null"
+	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"
 	if c.ProductID > 0 {
 	if c.ProductID > 0 {
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
 	}
 	}
@@ -213,7 +203,7 @@ func (e *Sales) SalesOrderList(c *dto.SalesOrderPageReq, deptId int) (list []map
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 	}
 	}
 	err = db.DB.Table("stock_out").
 	err = db.DB.Table("stock_out").
-		Select(mtable + ".*,stock_out.*,stock_out.unit_price as sales_unit_price").
+		//Select(mtable + ".*,stock_out.*,stock_out.unit_price as sales_unit_price").
 		Scopes(
 		Scopes(
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 		).
 		).
@@ -227,6 +217,7 @@ func (e *Sales) SalesOrderList(c *dto.SalesOrderPageReq, deptId int) (list []map
 	}
 	}
 	models.InitBasicData(deptId)
 	models.InitBasicData(deptId)
 	for i := 0; i < len(list); i++ {
 	for i := 0; i < len(list); i++ {
+		list[i]["sales_unit_price"] = utils.ToFloat64(list[i]["unit_price"])
 		list[i]["sales_money"] = utils.ToFloat64(list[i]["unit_price"]) * utils.ToFloat64(list[i]["quantity"])
 		list[i]["sales_money"] = utils.ToFloat64(list[i]["unit_price"]) * utils.ToFloat64(list[i]["quantity"])
 		if id, ok := list[i][models.FieldProductID]; ok {
 		if id, ok := list[i][models.FieldProductID]; ok {
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
@@ -253,7 +244,7 @@ func (e *Sales) SalesOrderList(c *dto.SalesOrderPageReq, deptId int) (list []map
 func (e *Sales) SalesStockOutExcel(c *dto.SalesStockOutExcelReq, deptId int) (list []map[string]interface{}, err error) {
 func (e *Sales) SalesStockOutExcel(c *dto.SalesStockOutExcelReq, deptId int) (list []map[string]interface{}, err error) {
 
 
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
-	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND unit_price > 0 AND stock_out.deleted_at is null"
+	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"
 	if len(c.Date) > 0 {
 	if len(c.Date) > 0 {
 		whereSql += " AND stock_out.date = '" + c.Date + "'"
 		whereSql += " AND stock_out.date = '" + c.Date + "'"
 	}
 	}
@@ -261,7 +252,7 @@ func (e *Sales) SalesStockOutExcel(c *dto.SalesStockOutExcelReq, deptId int) (li
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 	}
 	}
 	err = db.DB.Table("stock_out").
 	err = db.DB.Table("stock_out").
-		Select(mtable + ".*,stock_out.*,stock_out.unit_price as sales_unit_price").
+		//Select(mtable + ".*,stock_out.*,stock_out.unit_price as sales_unit_price").
 		Joins("left join " + mtable + " on stock_out.medicine_id = " + mtable + ".id").
 		Joins("left join " + mtable + " on stock_out.medicine_id = " + mtable + ".id").
 		Where(whereSql).
 		Where(whereSql).
 		Scan(&list).Error
 		Scan(&list).Error
@@ -271,6 +262,7 @@ func (e *Sales) SalesStockOutExcel(c *dto.SalesStockOutExcelReq, deptId int) (li
 	}
 	}
 	models.InitBasicData(deptId)
 	models.InitBasicData(deptId)
 	for i := 0; i < len(list); i++ {
 	for i := 0; i < len(list); i++ {
+		list[i]["sales_unit_price"] = utils.ToFloat64(list[i]["unit_price"])
 		list[i]["sales_money"] = utils.ToFloat64(list[i]["unit_price"]) * utils.ToFloat64(list[i]["quantity"])
 		list[i]["sales_money"] = utils.ToFloat64(list[i]["unit_price"]) * utils.ToFloat64(list[i]["quantity"])
 		if id, ok := list[i][models.FieldProductID]; ok {
 		if id, ok := list[i][models.FieldProductID]; ok {
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
 			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))

+ 3 - 3
services/stock.go

@@ -191,9 +191,9 @@ func (e *Stock) StockOut(c *dto.StockOutInsertReq) error {
 	tx := db.DB.Begin()
 	tx := db.DB.Begin()
 	// 进行入库操作
 	// 进行入库操作
 	stockOutRecord := models.StockOut{
 	stockOutRecord := models.StockOut{
-		MedicineID:    medicineInfo.Id,
-		Quantity:      c.Quantity,
-		UnitPrice:     c.UnitPrice,
+		MedicineID: medicineInfo.Id,
+		Quantity:   c.Quantity,
+		//UnitPrice:     c.UnitPrice,
 		Operator:      c.Operator,
 		Operator:      c.Operator,
 		ReceivingUnit: c.ReceivingUnit,
 		ReceivingUnit: c.ReceivingUnit,
 		Date:          c.Date,
 		Date:          c.Date,

+ 61 - 62
services/stock_template.go

@@ -247,7 +247,7 @@ func (e *StockTemplate) StockTemplateInScanCode(req *dto.BatchStockTemplateInIns
 			for k, v := range c.MedicineInfo {
 			for k, v := range c.MedicineInfo {
 				sql += fmt.Sprintf("`%s`='%v',", k, v)
 				sql += fmt.Sprintf("`%s`='%v',", k, v)
 			}
 			}
-			sql += fmt.Sprintf("`%s`='%v',", "purchase_unit_price", c.UnitPrice)
+			sql += fmt.Sprintf("`%s`='%v',", "unit_price", c.UnitPrice)
 
 
 			sql = sql[:len(sql)-1]
 			sql = sql[:len(sql)-1]
 			err = tx.Exec(sql).Error
 			err = tx.Exec(sql).Error
@@ -264,7 +264,7 @@ func (e *StockTemplate) StockTemplateInScanCode(req *dto.BatchStockTemplateInIns
 			}
 			}
 		} else {
 		} else {
 			medicineInfoId = utils.ToInt(medicineInfo["id"])
 			medicineInfoId = utils.ToInt(medicineInfo["id"])
-			err = tx.Table(models.GetMedicineInfoTableName(req.DeptId)).Where("id = ?", medicineInfoId).Update("purchase_unit_price", c.UnitPrice).Error
+			err = tx.Table(models.GetMedicineInfoTableName(req.DeptId)).Where("id = ?", medicineInfoId).Update("unit_price", c.UnitPrice).Error
 			if err != nil {
 			if err != nil {
 				tx.Rollback()
 				tx.Rollback()
 				logs.Error("db error: %s", err)
 				logs.Error("db error: %s", err)
@@ -347,7 +347,7 @@ func (e *StockTemplate) StockTemplateIn(c *dto.StockTemplateInInsertReq) error {
 		for k, v := range c.MedicineInfo {
 		for k, v := range c.MedicineInfo {
 			sql += fmt.Sprintf("`%s`='%v',", k, v)
 			sql += fmt.Sprintf("`%s`='%v',", k, v)
 		}
 		}
-		sql += fmt.Sprintf("`%s`='%v',", "purchase_unit_price", c.UnitPrice)
+		sql += fmt.Sprintf("`%s`='%v',", "unit_price", c.UnitPrice)
 
 
 		sql = sql[:len(sql)-1]
 		sql = sql[:len(sql)-1]
 		err = tx.Exec(sql).Error
 		err = tx.Exec(sql).Error
@@ -444,7 +444,7 @@ func (e *StockTemplate) StockTemplateInEdit(c *dto.StockTemplateInEditReq) error
 		for k, v := range c.MedicineInfo {
 		for k, v := range c.MedicineInfo {
 			sql += fmt.Sprintf("`%s`='%v',", k, v)
 			sql += fmt.Sprintf("`%s`='%v',", k, v)
 		}
 		}
-		sql += fmt.Sprintf("`%s`='%v',", "purchase_unit_price", c.UnitPrice)
+		sql += fmt.Sprintf("`%s`='%v',", "unit_price", c.UnitPrice)
 
 
 		sql = sql[:len(sql)-1]
 		sql = sql[:len(sql)-1]
 		err = tx.Exec(sql).Error
 		err = tx.Exec(sql).Error
@@ -696,17 +696,17 @@ func (e *StockTemplate) StockTemplateOut(c *dto.StockTemplateOutInsertReq) error
 	}
 	}
 
 
 	tx := db.DB.Begin()
 	tx := db.DB.Begin()
-	err = tx.Table(models.GetMedicineInfoTableName(c.DeptId)).Where("id = ?", medicineInfoId).Update("sales_unit_price", c.UnitPrice).Error
-	if err != nil {
-		tx.Rollback()
-		logs.Error("db error: %s", err)
-		return global.CreateFailedErr
-	}
+	//err = tx.Table(models.GetMedicineInfoTableName(c.DeptId)).Where("id = ?", medicineInfoId).Update("sales_unit_price", c.UnitPrice).Error
+	//if err != nil {
+	//	tx.Rollback()
+	//	logs.Error("db error: %s", err)
+	//	return global.CreateFailedErr
+	//}
 	// 进行出库操作
 	// 进行出库操作
 	stockOutRecord := models.StockOut{
 	stockOutRecord := models.StockOut{
-		MedicineID:    medicineInfoId,
-		Quantity:      c.Quantity,
-		UnitPrice:     c.UnitPrice,
+		MedicineID: medicineInfoId,
+		Quantity:   c.Quantity,
+		//UnitPrice:     c.UnitPrice,
 		Operator:      c.Operator,
 		Operator:      c.Operator,
 		ReceivingUnit: c.ReceivingUnit,
 		ReceivingUnit: c.ReceivingUnit,
 		Date:          c.Date,
 		Date:          c.Date,
@@ -776,7 +776,7 @@ func (e *StockTemplate) StockTemplateOutEdit(c *dto.StockTemplateOutEditReq) err
 	tx := db.DB.Begin()
 	tx := db.DB.Begin()
 
 
 	medicineInfoId = utils.ToInt(medicineInfo["id"])
 	medicineInfoId = utils.ToInt(medicineInfo["id"])
-	c.MedicineInfo["sales_unit_price"] = c.UnitPrice
+	//c.MedicineInfo["sales_unit_price"] = c.UnitPrice
 	err = tx.Table(models.GetMedicineInfoTableName(c.DeptId)).Where("id = ?", medicineInfoId).Updates(c.MedicineInfo).Error
 	err = tx.Table(models.GetMedicineInfoTableName(c.DeptId)).Where("id = ?", medicineInfoId).Updates(c.MedicineInfo).Error
 	if err != nil {
 	if err != nil {
 		tx.Rollback()
 		tx.Rollback()
@@ -793,24 +793,10 @@ func (e *StockTemplate) StockTemplateOutEdit(c *dto.StockTemplateOutEditReq) err
 		return global.UpdateFailedErr
 		return global.UpdateFailedErr
 	}
 	}
 
 
-	// 修改入库信息
-	//stockOutRecord := models.StockOut{
-	//	MedicineID:    medicineInfoId,
-	//	Quantity:      c.Quantity,
-	//	UnitPrice:     c.UnitPrice,
-	//	Operator:      c.Operator,
-	//	ReceivingUnit: c.ReceivingUnit,
-	//	Date:          c.Date,
-	//	ControlBy: model2.ControlBy{
-	//		UpdateBy: c.UpdateBy,
-	//	},
-	//}
-	//err = tx.Where("id = ?", c.Id).Updates(&stockOutRecord).Error
-
 	stockOutRecordMap := map[string]interface{}{
 	stockOutRecordMap := map[string]interface{}{
-		"medicine_id":    medicineInfoId,
-		"quantity":       c.Quantity,
-		"unit_price":     c.UnitPrice,
+		"medicine_id": medicineInfoId,
+		"quantity":    c.Quantity,
+		//"unit_price":     c.UnitPrice,
 		"operator":       c.Operator,
 		"operator":       c.Operator,
 		"receiving_unit": c.ReceivingUnit,
 		"receiving_unit": c.ReceivingUnit,
 		"date":           c.Date,
 		"date":           c.Date,
@@ -1036,17 +1022,17 @@ func (e *StockTemplate) BatchStockTemplateOut(req *dto.BatchStockTemplateOutInse
 			return errors.New(fmt.Sprintf("库存量【%d】小于出库库存量【%d】,出库失败", mi.Balance, c.Quantity))
 			return errors.New(fmt.Sprintf("库存量【%d】小于出库库存量【%d】,出库失败", mi.Balance, c.Quantity))
 		}
 		}
 
 
-		err = tx.Table(models.GetMedicineInfoTableName(req.DeptId)).Where("id = ?", medicineInfoId).Update("sales_unit_price", c.UnitPrice).Error
-		if err != nil {
-			tx.Rollback()
-			logs.Error("db error: %s", err)
-			return global.CreateFailedErr
-		}
+		//err = tx.Table(models.GetMedicineInfoTableName(req.DeptId)).Where("id = ?", medicineInfoId).Update("sales_unit_price", c.UnitPrice).Error
+		//if err != nil {
+		//	tx.Rollback()
+		//	logs.Error("db error: %s", err)
+		//	return global.CreateFailedErr
+		//}
 		// 进行出库操作
 		// 进行出库操作
 		stockOutRecord := models.StockOut{
 		stockOutRecord := models.StockOut{
-			MedicineID:    medicineInfoId,
-			Quantity:      c.Quantity,
-			UnitPrice:     c.UnitPrice,
+			MedicineID: medicineInfoId,
+			Quantity:   c.Quantity,
+			//UnitPrice:     c.UnitPrice,
 			Operator:      c.Operator,
 			Operator:      c.Operator,
 			ReceivingUnit: c.ReceivingUnit,
 			ReceivingUnit: c.ReceivingUnit,
 			Date:          c.Date,
 			Date:          c.Date,
@@ -1139,17 +1125,17 @@ func (e *StockTemplate) StockTemplateOutScanCode(req *dto.BatchStockTemplateOutI
 			return errors.New(fmt.Sprintf("【%s】库存量【%d】小于出库库存量【%d】,出库失败", medicineName, mi.Balance, c.Quantity))
 			return errors.New(fmt.Sprintf("【%s】库存量【%d】小于出库库存量【%d】,出库失败", medicineName, mi.Balance, c.Quantity))
 		}
 		}
 
 
-		err = tx.Table(models.GetMedicineInfoTableName(req.DeptId)).Where("id = ?", medicineInfoId).Update("sales_unit_price", c.UnitPrice).Error
-		if err != nil {
-			tx.Rollback()
-			logs.Error("db error: %s", err)
-			return global.CreateFailedErr
-		}
+		//err = tx.Table(models.GetMedicineInfoTableName(req.DeptId)).Where("id = ?", medicineInfoId).Update("sales_unit_price", c.UnitPrice).Error
+		//if err != nil {
+		//	tx.Rollback()
+		//	logs.Error("db error: %s", err)
+		//	return global.CreateFailedErr
+		//}
 		// 进行出库操作
 		// 进行出库操作
 		stockOutRecord := models.StockOut{
 		stockOutRecord := models.StockOut{
-			MedicineID:    medicineInfoId,
-			Quantity:      c.Quantity,
-			UnitPrice:     c.UnitPrice,
+			MedicineID: medicineInfoId,
+			Quantity:   c.Quantity,
+			//UnitPrice:     c.UnitPrice,
 			Operator:      c.Operator,
 			Operator:      c.Operator,
 			ReceivingUnit: c.ReceivingUnit,
 			ReceivingUnit: c.ReceivingUnit,
 			Date:          c.Date,
 			Date:          c.Date,
@@ -1202,7 +1188,7 @@ func (e *StockTemplate) StockTemplateOutScanCode(req *dto.BatchStockTemplateOutI
 	return nil
 	return nil
 }
 }
 
 
-// StockTemplateInList 库列表
+// StockTemplateInList 库列表
 func (e *StockTemplate) StockTemplateInList(c *dto.StockTemplateInPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 func (e *StockTemplate) StockTemplateInList(c *dto.StockTemplateInPageReq, deptId int) (list []map[string]interface{}, count int64, err error) {
 
 
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
@@ -1293,7 +1279,7 @@ func (e *StockTemplate) StockTemplateOutList(c *dto.StockTemplateOutPageReq, dep
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
 	}
 	}
 	err = db.DB.Table("stock_out").
 	err = db.DB.Table("stock_out").
-		Select(mtable + ".*,stock_out.*,stock_out.id AS id").
+		Select(mtable + ".*," + "stock_out.*,stock_out.id AS id," + mtable + ".unit_price as sales_unit_price").
 		Scopes(
 		Scopes(
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 		).
 		).
@@ -1728,7 +1714,7 @@ func (e *StockTemplate) StockHomeStat(deptId int) (list map[string]interface{},
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
 	whereSql := " WHERE mi.dept_id = " + strconv.Itoa(deptId) + " AND deleted_at is null"
 	whereSql := " WHERE mi.dept_id = " + strconv.Itoa(deptId) + " AND deleted_at is null"
 	var result []map[string]interface{}
 	var result []map[string]interface{}
-	sql := "SELECT mi.balance,m_info.purchase_unit_price FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory GROUP BY medicine_id) AS mi_latest " +
+	sql := "SELECT mi.balance,m_info.unit_price FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory GROUP BY medicine_id) AS mi_latest " +
 		"JOIN medicine_inventory AS mi ON mi.medicine_id=mi_latest.medicine_id AND mi.id=mi_latest.latest_id " +
 		"JOIN medicine_inventory AS mi ON mi.medicine_id=mi_latest.medicine_id AND mi.id=mi_latest.latest_id " +
 		"LEFT JOIN " + mtable + " AS m_info ON mi.medicine_id=m_info.id" + whereSql
 		"LEFT JOIN " + mtable + " AS m_info ON mi.medicine_id=m_info.id" + whereSql
 
 
@@ -1741,45 +1727,58 @@ func (e *StockTemplate) StockHomeStat(deptId int) (list map[string]interface{},
 	inventoryQuantity := 0
 	inventoryQuantity := 0
 	inventoryAmount := 0.0
 	inventoryAmount := 0.0
 	for i := 0; i < len(result); i++ {
 	for i := 0; i < len(result); i++ {
-		purchase_unit_price := utils.ToFloat64(result[i]["purchase_unit_price"])
+		unit_price := utils.ToFloat64(result[i]["unit_price"])
 		inventoryQuantity += utils.ToInt(result[i]["balance"])
 		inventoryQuantity += utils.ToInt(result[i]["balance"])
-		inventoryAmount += utils.ToFloat64(inventoryQuantity) * purchase_unit_price
+		inventoryAmount += utils.ToFloat64(inventoryQuantity) * unit_price
 
 
 	}
 	}
-	var totalOut, totalOutSale, totalIn, totalInPurchase int
+	var totalOut, totalIn int
+	var totalOutMoney, totalInMoney float64
 
 
-	err = db.DB.Model(models.StockIn{}).Select("COALESCE(SUM(quantity),0)").Where("dept_id = ? AND unit_price = 0", deptId).Scan(&totalIn).Error
+	err = db.DB.Model(models.StockIn{}).Select("COALESCE(SUM(quantity),0)").Where("dept_id = ?", deptId).Scan(&totalIn).Error
 	if err != nil {
 	if err != nil {
 		logs.Error("db error: %s ", err)
 		logs.Error("db error: %s ", err)
 		return list, count, err
 		return list, count, err
 	}
 	}
-	err = db.DB.Model(models.StockIn{}).Select("COALESCE(SUM(quantity),0)").Where("dept_id = ? AND unit_price > 0", deptId).Scan(&totalInPurchase).Error
+
+	err = db.DB.Table("stock_in").
+		Select("SUM(stock_in.quantity * "+mtable+".unit_price)").
+		Joins("join "+mtable+" on stock_in.medicine_id = "+mtable+".id").
+		Where("dept_id = ? ", deptId).
+		Scan(&totalInMoney).Error
 	if err != nil {
 	if err != nil {
 		logs.Error("db error: %s ", err)
 		logs.Error("db error: %s ", err)
 		return list, count, err
 		return list, count, err
 	}
 	}
-	err = db.DB.Model(models.StockOut{}).Select("COALESCE(SUM(quantity),0)").Where("dept_id = ? AND unit_price = 0", deptId).Scan(&totalOut).Error
+
+	err = db.DB.Model(models.StockOut{}).Select("COALESCE(SUM(quantity),0)").Where("dept_id = ?", deptId).Scan(&totalOut).Error
 	if err != nil {
 	if err != nil {
 		logs.Error("db error: %s ", err)
 		logs.Error("db error: %s ", err)
 		return list, count, err
 		return list, count, err
 	}
 	}
-	err = db.DB.Model(models.StockOut{}).Select("COALESCE(SUM(quantity),0)").Where("dept_id = ? AND unit_price > 0", deptId).Scan(&totalOutSale).Error
+
+	err = db.DB.Table("stock_out").
+		Select("SUM(stock_out.quantity * "+mtable+".unit_price)").
+		Joins("join "+mtable+" on stock_out.medicine_id = "+mtable+".id").
+		Where("dept_id = ? ", deptId).
+		Scan(&totalOutMoney).Error
 	if err != nil {
 	if err != nil {
 		logs.Error("db error: %s ", err)
 		logs.Error("db error: %s ", err)
 		return list, count, err
 		return list, count, err
 	}
 	}
+
 	list = make(map[string]interface{})
 	list = make(map[string]interface{})
 	list["inventoryQuantity"] = inventoryQuantity // 库存总量
 	list["inventoryQuantity"] = inventoryQuantity // 库存总量
 	list["inventoryAmount"] = inventoryAmount     // 库存总额(成本金额)
 	list["inventoryAmount"] = inventoryAmount     // 库存总额(成本金额)
 	list["totalOut"] = totalOut                   // 出库
 	list["totalOut"] = totalOut                   // 出库
-	list["totalOutSale"] = totalOutSale           // 销售出库
+	list["totalOutMoney"] = totalOutMoney         // 出库总金额
 	list["totalIn"] = totalIn                     // 入库
 	list["totalIn"] = totalIn                     // 入库
-	list["totalInPurchase"] = totalInPurchase     // 采购入库
+	list["totalInMoney"] = totalInMoney           // 入库总金额
 
 
 	return list, count, nil
 	return list, count, nil
 
 
 }
 }
-func (e *StockTemplate) StockTemplateTransportRecordWord(c *dto.TransportRecordWordReq, deptId int) (list []map[string]interface{}, err error) {
+func (e *StockTemplate) StockTemplateTransportRecordWord(c *models.TransportRecord, deptId int) (list []map[string]interface{}, err error) {
 
 
 	mtable := models.GetMedicineInfoTableName(deptId)
 	mtable := models.GetMedicineInfoTableName(deptId)
 	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"
 	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"

+ 18 - 0
utils/comm_test.go

@@ -3,6 +3,10 @@ package utils
 import (
 import (
 	"fmt"
 	"fmt"
 	"github.com/beego/beego/v2/core/logs"
 	"github.com/beego/beego/v2/core/logs"
+	"github.com/boombuler/barcode"
+	"github.com/boombuler/barcode/code128"
+	"image/png"
+	"os"
 	"testing"
 	"testing"
 )
 )
 
 
@@ -24,3 +28,17 @@ func TestAmountConvert(t *testing.T) {
 
 
 	fmt.Println(cols1)
 	fmt.Println(cols1)
 }
 }
+
+func TestGetQRCode(t *testing.T) {
+	// 创建一个code128编码的 BarcodeIntCS
+	cs, _ := code128.Encode("123456")
+	// 创建一个要输出数据的文件
+	file, _ := os.Create("qr3.png")
+	defer file.Close()
+
+	// 设置图片像素大小
+	qrCode, _ := barcode.Scale(cs, 350, 70)
+	// 将code128的条形码编码为png图片
+	png.Encode(file, qrCode)
+
+}