Browse Source

BigPartPurchase: 特殊申购自动流转采购单

Yi 1 year ago
parent
commit
3fb53c800d

+ 5 - 3
apiserver/model/bigpartpurchase.go

@@ -40,15 +40,17 @@ func (b *BigPartPurchase) TableName() string {
 	return "bigpartpurchase"
 }
 
+var Location, _ = time.LoadLocation("Asia/Shanghai")
+
 func NewBigPartPurchase(pastureId, departmentId, employeeId, providerId int64,
 	purchaseType modernPb.PurchaseType_Kind, orderNumber, createdTime, providerName string,
 ) *BigPartPurchase {
 	var statue int32 = 2
-	if purchaseType.Number() == 3 {
+	if purchaseType == modernPb.PurchaseType_Complimentary_Item {
 		statue = 7
 	}
-	local, _ := time.LoadLocation("Asia/Shanghai")
-	createTime, _ := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", createdTime), local)
+
+	createTime, _ := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", createdTime), Location)
 	return &BigPartPurchase{
 		PastureId:      pastureId,
 		OrderNumber:    orderNumber,

+ 97 - 45
apiserver/model/buydetail.go

@@ -1,70 +1,122 @@
 package model
 
 import (
+	modernPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/xdmy"
 	"time"
 )
 
 type BigBuyDetail struct {
 	// 采购订单
-	ID           int       `gorm:"column:id"`
-	DoneDate     time.Time `gorm:"column:DoneDate"`
-	ArrivalStatu int       `gorm:"column:arrivalStatu"`
-	BuyeCode     string    `gorm:"column:buyeCode"` //申购单号
-	BuyerDate    time.Time `gorm:"column:buyerDate"`
-	BuyerPerson  int       `gorm:"column:buyerPerson"`
-	Enable       int       `gorm:"column:enable"`    //是否删除
-	MatchCode    string    `gorm:"column:matchCode"` //配单
-	Note         string    `gorm:"column:note"`      //关闭原因
-	PastureID    int       `gorm:"column:pastureId"`
-	ProviderID   int       `gorm:"column:providerId"`
-	Statu        int       `gorm:"column:statu"`     // 到货状态
-	ZeroCou      int       `gorm:"column:zeroCou"`   //配单数量
-	SapNumber    string    `gorm:"column:sapNumber"` //sap采购单号
-	SapStatus    int       `gorm:"column:sapStatus"` // 同步状态
-	SapError     string    `gorm:"column:sapError"`  // sap接口错误信息
-	SrmStatus    int       `gorm:"column:srmStatus"`
-	SrmNumber    string    `gorm:"column:srmNumber"`
-	SrmError     string    `gorm:"column:srmError"`
+	ID           int                        `gorm:"column:id"`
+	DoneDate     time.Time                  `gorm:"column:DoneDate"`
+	ArrivalStatu int                        `gorm:"column:arrivalStatu"`
+	BuyeCode     string                     `gorm:"column:buyeCode"` //申购单号
+	BuyerDate    time.Time                  `gorm:"column:buyerDate"`
+	BuyerPerson  int                        `gorm:"column:buyerPerson"`
+	Enable       int                        `gorm:"column:enable"`    //是否删除
+	MatchCode    string                     `gorm:"column:matchCode"` //配单
+	Note         string                     `gorm:"column:note"`      //关闭原因
+	PastureID    int                        `gorm:"column:pastureId"`
+	ProviderID   int                        `gorm:"column:providerId"`
+	Statu        int                        `gorm:"column:statu"`     // 到货状态
+	ZeroCou      int                        `gorm:"column:zeroCou"`   //配单数量
+	SapNumber    string                     `gorm:"column:sapNumber"` //sap采购单号
+	SapStatus    int                        `gorm:"column:sapStatus"` // 同步状态
+	SapError     string                     `gorm:"column:sapError"`  // sap接口错误信息
+	SrmStatus    int                        `gorm:"column:srmStatus"`
+	SrmNumber    string                     `gorm:"column:srmNumber"`
+	SrmError     string                     `gorm:"column:srmError"`
+	PurchaseType modernPb.PurchaseType_Kind `gorm:"column:purchase_type"` // 申购类类型 0 正常 1 暂估 2 垫付 3 赠品';
+}
+
+func (BigBuyDetail) TableName() string {
+	return "bigbuydetail"
 }
+
+func NewBigBuyDetail(buyeCode, matchCode string, pastureId, providerId, buyerPerson int64, purchaseType modernPb.PurchaseType_Kind) *BigBuyDetail {
+	nowTime := time.Now()
+	todayZore := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
+	return &BigBuyDetail{
+		DoneDate:     todayZore,
+		ArrivalStatu: 0,
+		BuyeCode:     buyeCode,
+		BuyerDate:    todayZore,
+		BuyerPerson:  int(buyerPerson),
+		Enable:       0,
+		MatchCode:    matchCode,
+		Note:         "",
+		PastureID:    int(pastureId),
+		ProviderID:   int(providerId),
+		Statu:        0,
+		ZeroCou:      0,
+		SapNumber:    "",
+		SapStatus:    0,
+		SapError:     "",
+		SrmStatus:    0,
+		SrmNumber:    "",
+		SrmError:     "",
+		PurchaseType: purchaseType,
+	}
+}
+
+// BuyDetail 采购订单明细
 type BuyDetail struct {
-	// 采购订单明细
-	ID int `json:"id" gorm:"column:id"`
-	// Model
-	Amount         int       `json:"amount" gorm:"column:amount"` //采购数量
-	BigID          int       `json:"bigId" gorm:"column:bigId"`
-	BrandID        int       `json:"brandId" gorm:"column:brandId"`
-	ContractID     int       `json:"contractId" gorm:"column:contractId"`
+	ID             int       `json:"id" gorm:"column:id"`
 	PastureID      int       `json:"pastureId" gorm:"column:pastureId"`
 	ContractCode   string    `json:"contractCode" gorm:"column:contractCode"`
+	ContractID     int       `json:"contractId" gorm:"column:contractId"`
+	Statue         int       `json:"statue" gorm:"column:statue"` // '采购状态状态(0,未到货,1部分到货,3全部到货)',
+	Amount         int       `json:"amount" gorm:"column:amount"` //采购数量
+	StoredQuantity float64   `json:"storedQuantity" gorm:"column:storedQuantity"`
+	IsStorage      int       `json:"isStorage" gorm:"column:isStorage"` //'判断是否完全是否入库(0:否  1: 是)'
+	Note           string    `json:"note" gorm:"column:note"`
+	Enable         int       `json:"enable" gorm:"column:enable"`
+	BigID          int       `json:"bigId" gorm:"column:bigId"`
+	SumAmount      int       `json:"sumAmount" gorm:"column:sumAmount"`         //申购数量',
+	ReceiveAmount  float64   `json:"receiveAmount" gorm:"column:receiveAmount"` // '入库数量',
+	ReceiveDate    time.Time `json:"receiveDate" gorm:"column:receiveDate"`     // '入库时间',
 	DepartmentName string    `json:"departmentName" gorm:"column:departmentName"`
-	IsStorage      int       `json:"isStorage" gorm:"column:isStorage"`     //'判断是否完全是否入库(0:否  1: 是)'
-	ReceiveDate    time.Time `json:"receiveDate" gorm:"column:receiveDate"` // '入库时间',
 	PartCode       string    `json:"partCode" gorm:"column:partCode"`
+	BrandID        int       `json:"brandId" gorm:"column:brandId"`
 	Price          float64   `json:"price" gorm:"column:price"`
-	ReceiveAmount  string    `json:"receiveAmount" gorm:"column:receiveAmount"` // '入库数量',
-	Salesreturn    string    `json:"salesreturn" gorm:"column:salesreturn"`     //退货数量
-	Statue         int       `json:"statue" gorm:"column:statue"`               // '采购状态状态(0,未到货,1部分到货,3全部到货)',
 	Remark         string    `json:"remark" gorm:"column:remark"`
-	Note           string    `json:"note" gorm:"column:note"`
-	StoredQuantity string    `json:"storedQuantity" gorm:"column:storedQuantity"`
-	SumAmount      int       `json:"sumAmount" gorm:"column:sumAmount"` //申购数量',
-	Enable         int       `json:"enable" gorm:"column:enable"`
-	Dflag          int       `json:"dflag" gorm:"column:dflag"`
-	Unit           string
-	IsZeroStock    int
-	RowNumber      int `json:"rowNumber" gorm:"column:rowNumber"`
-}
-type BigBuyDetailReq struct {
-	Code string `json:"matchCode" gorm:"column:matchcode"` //配单号
-	ID   string `json:"id" gorm:"column:id"`               //申购单id
+	RowNumber      int       `json:"rowNumber" gorm:"column:rowNumber"`
+	// Salesreturn    string    `json:"salesreturn" gorm:"column:salesreturn"`     //退货数量
+	//Dflag          int    `json:"dflag" gorm:"column:dflag"`
+	//Unit        string
 }
 
 func (BuyDetail) TableName() string {
 	return "buydetail"
 }
 
-func (BigBuyDetail) TableName() string {
-	return "bigbuydetail"
+func NewBuyDetail(bigId, pastureId, amount, contractId, brandId int64, partCode, contractCode, remark, departmentName string, price float64) *BuyDetail {
+	return &BuyDetail{
+		Amount:         int(amount),
+		BigID:          int(bigId),
+		BrandID:        int(brandId),
+		ContractID:     int(contractId),
+		PastureID:      int(pastureId),
+		ContractCode:   contractCode,
+		DepartmentName: departmentName,
+		IsStorage:      0,
+		ReceiveDate:    time.Time{},
+		PartCode:       partCode,
+		Price:          price,
+		ReceiveAmount:  0,
+		Statue:         0,
+		Remark:         remark,
+		Note:           "",
+		StoredQuantity: 0,
+		SumAmount:      0,
+		Enable:         0,
+		RowNumber:      0,
+	}
+}
+
+type BigBuyDetailReq struct {
+	Code string `json:"matchCode" gorm:"column:matchcode"` //配单号
+	ID   string `json:"id" gorm:"column:id"`               //申购单id
 }
 
 type BigBuyDetailStr struct {

+ 22 - 18
apiserver/model/department.go

@@ -1,26 +1,30 @@
 package model
 
+// Department 组织机构
 type Department struct {
-	// 组织机构
-	KCcode         string `gorm:"column:KCcode"`
-	XRCode         string `gorm:"column:XRCode"`
-	Address        string `gorm:"column:address"`
-	DeptCode       string `gorm:"column:deptCode"`
-	Enable         int    `gorm:"column:enable"`
-	ID             int    `gorm:"column:id"`
-	IsDel          int    `gorm:"column:isDel"`
-	IsGroupco      int    `gorm:"column:isGroupco"`
-	IsPasture      int    `gorm:"column:isPasture"`
-	Iscal          int    `gorm:"column:iscal"`
-	Name           string `gorm:"column:name"`
-	Parentid       int    `gorm:"column:parentid"`
-	PastureID      int    `gorm:"column:pastureId"`
-	Remark         string `gorm:"column:remark"`
-	Sort           string `gorm:"column:sort"`
-	CostCenterCode string `gorm:"column:costCenter_code"`
-
+	ID                   int    `gorm:"column:id"`
+	Name                 string `gorm:"column:name"`
+	PastureID            int    `gorm:"column:pastureId"`
+	DeptCode             string `gorm:"column:deptCode"`
+	Address              string `gorm:"column:address"`
+	Parentid             int    `gorm:"column:parentid"`
+	IsGroupco            int    `gorm:"column:isGroupco"`
+	IsPasture            int    `gorm:"column:isPasture"`
+	Remark               string `gorm:"column:remark"`
+	Sort                 string `gorm:"column:sort"`
+	Enable               int    `gorm:"column:enable"`
+	IsDel                int    `gorm:"column:isDel"`
+	XRCode               string `gorm:"column:XRCode"`
+	Iscal                int    `gorm:"column:iscal"`
+	KCcode               string `gorm:"column:KCcode"`
+	PastureName          string `gorm:"column:pasturename"`
+	CostCenterCode       string `gorm:"column:costCenter_code"`
 	CompanyCode          string `gorm:"column:company_code"`     //公司代码
 	PurchasingGroup      string `gorm:"column:purchasing_group"` //采购组织
 	Factory              string `gorm:"column:factory"`          //工厂
 	ParchaseOrganization string `gorm:"column:parchase_organization"`
 }
+
+func (d *Department) TableName() string {
+	return "department"
+}

+ 46 - 0
apiserver/routers/api/db.go

@@ -2055,6 +2055,9 @@ func ExecDataByConfig(c *gin.Context) {
 			}
 		}(tx)
 		//}
+		defer func() {
+			partpurchaseCharge1(tempval_)
+		}()
 
 		if err == nil {
 			if tempv, exists := c.Get("jwt_username"); exists {
@@ -2149,6 +2152,49 @@ func BillType(tempval_ map[string]interface{}) {
 		}
 	}
 }
+
+// partpurchaseCharge1 特殊申购审核完成-》采购单管理
+func partpurchaseCharge1(tempval_ map[string]interface{}) {
+	fmt.Println("partpurchaseCharge1==>", tempval_["data"])
+	switch tempval_["data"].(type) {
+	case []interface{}:
+		if len(tempval_["data"].([]interface{})) > 0 {
+			name := tempval_["data"].([]interface{})[0].(map[string]interface{})["name"]
+			switch name {
+			case "partpurchaseCharge1": // 特殊申购审核完成-》采购单管理
+				dataList, ok := tempval_["data"].([]interface{})
+				if !ok {
+					return
+				}
+				if len(dataList) <= 0 {
+					return
+				}
+				dataListMap, ok := tempval_["data"].([]interface{})[0].(map[string]interface{})
+				if !ok {
+					return
+				}
+				paramsMap, ok := dataListMap["parammaps"].(map[string]interface{})
+				if !ok {
+					return
+				}
+				id, ok := paramsMap["id"].(float64)
+				if !ok {
+					return
+				}
+				state, ok := paramsMap["statue"].(float64)
+				if !ok {
+					return
+				}
+				if state != 7 {
+					return
+				}
+				err := service.SpecialtyToProcure(int64(id))
+				fmt.Println("partpurchaseCharge===>", err)
+			}
+		}
+	}
+}
+
 func interfacetostring(val interface{}) string {
 	switch val.(type) {
 	case string:

+ 96 - 0
apiserver/service/purchase.go

@@ -2,8 +2,10 @@ package service
 
 import (
 	"context"
+	"fmt"
 	modernPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/xdmy"
 	"gitee.com/xuyiping_admin/pkg/xerr"
+	"github.com/pkg/errors"
 	"gorm.io/gorm"
 	"kpt.xdmy/apiserver/model"
 	"strconv"
@@ -11,6 +13,16 @@ import (
 
 // CreateSpecialtyPurchase 创建特殊申购信息
 func CreateSpecialtyPurchase(ctx context.Context, req *modernPb.SparePartsRequisitionsRequest) error {
+	var bigPartPurchaseId int64 = 0
+	// 赠品
+	defer func() {
+		if req.PurchaseType == modernPb.PurchaseType_Complimentary_Item {
+			if err := SpecialtyToProcure(bigPartPurchaseId); err != nil {
+				fmt.Println("SpecialtyToProcure===>", bigPartPurchaseId)
+			}
+		}
+	}()
+
 	return s.d.DB.Transaction(func(tx *gorm.DB) error {
 		newBigPartPurchase := model.NewBigPartPurchase(
 			int64(req.PastureId), int64(req.DepartmentId), int64(req.EmployeId),
@@ -35,6 +47,90 @@ func CreateSpecialtyPurchase(ctx context.Context, req *modernPb.SparePartsRequis
 				return xerr.WithStack(err)
 			}
 		}
+		bigPartPurchaseId = newBigPartPurchase.Id
+		return nil
+	})
+}
+
+// SpecialtyToProcure 特殊申购-自动流转采购单
+func SpecialtyToProcure(id int64) error {
+	// 获取特殊申购单信息
+	newBigPartPurchase := &model.BigPartPurchase{Id: id}
+	if err := s.d.DB.Model(new(model.BigPartPurchase)).First(newBigPartPurchase).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+	// 过滤掉非特殊申购的数据
+	if newBigPartPurchase.PurchaseType <= 0 {
+		return nil
+	}
+
+	newPartPurchase := make([]*model.PartPurchase, 0)
+	if err := s.d.DB.Model(new(model.PartPurchase)).Where("bigId = ?", newBigPartPurchase.Id).Find(&newPartPurchase).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+
+	return s.d.DB.Transaction(func(tx *gorm.DB) error {
+		// 获取申购单号
+		var orderCode string
+		if err := tx.Raw(fmt.Sprintf("CALL createCodeN(%d,'%s')", newBigPartPurchase.PastureId, "CG")).Scan(&orderCode).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+
+		historyBigBuyDetail := &model.BigBuyDetail{}
+		if err := tx.Model(new(model.BigBuyDetail)).Where("buyeCode = ?", orderCode).First(historyBigBuyDetail).Error; err != nil {
+			if !errors.Is(err, gorm.ErrRecordNotFound) {
+				return xerr.WithStack(err)
+			}
+		}
+		// 避免重复提交
+		if historyBigBuyDetail.BuyeCode == orderCode {
+			return xerr.Customf("该申购单号已经存在:%s", orderCode)
+		}
+
+		newBigBuyDetail := model.NewBigBuyDetail(
+			orderCode, newBigPartPurchase.OrderNumber, newBigPartPurchase.PastureId,
+			newBigPartPurchase.ProviderId, newBigPartPurchase.EmployeId, newBigPartPurchase.PurchaseType)
+		if err := tx.Model(new(model.BigBuyDetail)).Create(newBigBuyDetail).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+
+		buyDetailList := make([]*model.BuyDetail, 0)
+		var allAmount int64 = 0
+		for _, v := range newPartPurchase {
+			contractId, _ := strconv.Atoi(v.ContractId)
+			newContract := &model.Contract{}
+			if err := tx.Model(new(model.Contract)).Where("id = ?", contractId).First(newContract).Error; err != nil {
+				fmt.Println("newContract", err)
+			}
+
+			bigContract := &model.BigContract{}
+			if err := tx.Model(new(model.BigContract)).Where("id = ?", newContract.BigID).First(bigContract).Error; err != nil {
+				fmt.Println("CreateSpecialtyPurchase", err)
+			}
+
+			department := &model.Department{}
+			if err := tx.Model(new(model.Department)).Where("pastureId = ?", newBigPartPurchase.PastureId).
+				Where("id = ?", newBigPartPurchase.DepartmentId).First(department).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+
+			price, _ := strconv.ParseFloat(v.Price, 64)
+			buyDetailList = append(buyDetailList, model.NewBuyDetail(int64(newBigBuyDetail.ID), int64(newBigBuyDetail.PastureID),
+				v.Amount, int64(contractId), v.BrandId, newContract.PartCode, bigContract.ContractCode, v.Purpose, department.Name, price))
+			allAmount += v.Amount
+		}
+
+		if err := s.d.DB.Model(new(model.BigBuyDetail)).Where("id = ?", newBigBuyDetail.ID).Updates(map[string]interface{}{
+			"zeroCou": allAmount,
+		}).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+
+		if len(buyDetailList) > 0 {
+			if err := tx.Model(new(model.BuyDetail)).Create(buyDetailList).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
 		return nil
 	})
 }

+ 1 - 1
go.mod

@@ -9,7 +9,7 @@ replace (
 )
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20230831025441-c47bafa20bde
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20230901024021-0130ae3343d8
 	gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584
 	github.com/360EntSecGroup-Skylar/excelize v1.4.1
 	github.com/Anderson-Lu/gofasion v0.0.0-20190530065914-6a05b679ee48

+ 2 - 0
go.sum

@@ -736,6 +736,8 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20230829090029-dcc108270e61 h1:BrfiZlhc
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230829090029-dcc108270e61/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230831025441-c47bafa20bde h1:eKYSpeFr3feWA4uEAW+8K8H9rtwy3Sg2dqrcoMc4d/M=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230831025441-c47bafa20bde/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20230901024021-0130ae3343d8 h1:sIa0CmbUXFlW/fV1iiibCo67DQQTsYYk5OHXxTkAdcM=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20230901024021-0130ae3343d8/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584 h1:5RE5yrMMvnDITrnoX821mFl7dNYfsFA1osDobUV/TDo=
 gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584/go.mod h1:VQ7WztVDQRlXE1dUu/Yqo3ZdhKsfv7IGJtV+vqNqJVw=
 github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=

+ 599 - 299
migration/v0002_alter_bigpartpurchase.sql

@@ -1,11 +1,14 @@
 ALTER TABLE `bigpartpurchase`
-    ADD COLUMN `purchase_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '申购类型 0 无效 1 暂估 2 垫付',
+    ADD COLUMN `purchase_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '申购类型 0 正常 1 暂估 2 垫付 3 赠品',
     ADD COLUMN `funder_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '垫资人id',
     ADD COLUMN `providerName` varchar(255) NOT NULL DEFAULT '' COMMENT '供应商名称';
 
 
 ALTER TABLE `bigpartuse` ADD COLUMN greenFodderNumber varchar(255) NOT NULL DEFAULT '' COMMENT '青贮单号';
 
+ALTER TABLE `bigbuydetail`
+    ADD COLUMN `purchase_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '申购类型 0 正常 1 暂估 2 垫付 3 赠品';
+
 # SELECT * FROM apisql WHERE sqlname = 'insertBigPartUse'
 INSERT INTO bigpartuse (
     pastureId,
@@ -445,309 +448,606 @@ ORDER BY bpl.storageTime DESC, bpl.`id` DESC;
 # select * from apisql where sqlname = 'getpartpurchaseWebListNO'    ## 新增返回备件状态字段
 
 SELECT * FROM (SELECT
-                   bpp.`buyStatu`,
-                   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
-                   bpp.`CGChargeId`,
-                   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
-                   bpp.`chargeId`,
-                   bpp.`createTime`,
-                   bpp.`departmentId`,
-                   bpp.`employeId`,
-                   bpp.`flowCompeleted`,
-                   bpp.`flowworkNote`,
-                   bpp.`id`,
-                   bpp.`isUrgent`,
-                   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
-                   bpp.`KGChargeId`,
-                   bpp.`orderNumber`,
-                   bpp.`pastureId`,
-                   bpp.`statue`,
-                   bpp.`workflowId`,
-                   bpp.`workflowNote`,
-                   bpp.purchase_type,
-                   p.`name` pastureName,
-                   e.empname ,
-                   e1.empname KGChargePerson,
-                   e2.empname chargePerson,
-                   e3.empname  CGChargePerson,
-                   d.`name` AS departmentName,
-                   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
-                   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
-               FROM
-                   bigpartpurchase bpp
-                       LEFT JOIN pasture p
-                                 ON p.id = bpp.pastureId
-                       LEFT JOIN emp e
-                                 ON e.id = bpp.employeId
-                       LEFT JOIN department d
-                                 ON d.id = bpp.departmentId
-                       LEFT JOIN emp e1
-                                 ON e1.id = bpp.KGChargeId
-                       LEFT JOIN emp e2
-                                 ON e2.id = bpp.chargeId
-                       LEFT JOIN emp e3
-                                 ON e3.id = bpp.CGChargeId
-                       LEFT JOIN emp e4
-                                 ON e4.id = bpp.financeId
-               WHERE  bpp.statue = 2 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
-                                                                                                      LEFT JOIN user_role ur
-                                                                                                                ON ur.`user_id`= u.`id`
-                                                                                                      LEFT JOIN role r
-                                                                                                                ON r.`id` = ur.`role_id`
-                                                                                                      LEFT JOIN role_menu rm
-                                                                                                                ON r.`id` = rm.`role_id`
-                                                                                                      LEFT JOIN menu m
-                                                                                                                ON m.`id` = rm.`menu_id`
-                                                                         WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='customs:subscribe:examineKG' LIMIT 1),-1)<> -1)
-
-               UNION ALL
-
-               SELECT
-                   bpp.`buyStatu`,
-                   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
-                   bpp.`CGChargeId`,
-                   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
-                   bpp.`chargeId`,
-                   bpp.`createTime`,
-                   bpp.`departmentId`,
-                   bpp.`employeId`,
-                   bpp.`flowCompeleted`,
-                   bpp.`flowworkNote`,
-                   bpp.`id`,
-                   bpp.`isUrgent`,
-                   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
-                   bpp.`KGChargeId`,
-                   bpp.`orderNumber`,
-                   bpp.`pastureId`,
-                   bpp.`statue`,
-                   bpp.`workflowId`,
-                   bpp.`workflowNote`,
-                   bpp.purchase_type,
-                   p.`name` pastureName,
-                   e.empname ,
-                   e1.empname KGChargePerson,
-                   e2.empname chargePerson,
-                   e3.empname  CGChargePerson,
-                   d.`name` AS departmentName,
-                   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
-                   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
-               FROM
-                   bigpartpurchase bpp
-                       LEFT JOIN pasture p
-                                 ON p.id = bpp.pastureId
-                       LEFT JOIN emp e
-                                 ON e.id = bpp.employeId
-                       LEFT JOIN department d
-                                 ON d.id = bpp.departmentId
-                       LEFT JOIN emp e1
-                                 ON e1.id = bpp.KGChargeId
-                       LEFT JOIN emp e2
-                                 ON e2.id = bpp.chargeId
-                       LEFT JOIN emp e3
-                                 ON e3.id = bpp.CGChargeId
-                       LEFT JOIN emp e4
-                                 ON e4.id = bpp.financeId
-               WHERE  bpp.statue = 3  AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
-                                                                                                       LEFT JOIN user_role ur
-                                                                                                                 ON ur.`user_id`= u.`id`
-                                                                                                       LEFT JOIN role r
-                                                                                                                 ON r.`id` = ur.`role_id`
-                                                                                                       LEFT JOIN role_menu rm
-                                                                                                                 ON r.`id` = rm.`role_id`
-                                                                                                       LEFT JOIN menu m
-                                                                                                                 ON m.`id` = rm.`menu_id`
-                                                                          WHERE u.`empid` = ? and m.enable = 1  AND m.`path`='customs:subscribe:examineSBZG' LIMIT 1),-1)<> -1)
-               UNION ALL
-               SELECT
-                   bpp.`buyStatu`,
-                   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
-                   bpp.`CGChargeId`,
-                   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
-                   bpp.`chargeId`,
-                   bpp.`createTime`,
-                   bpp.`departmentId`,
-                   bpp.`employeId`,
-                   bpp.`flowCompeleted`,
-                   bpp.`flowworkNote`,
-                   bpp.`id`,
-                   bpp.`isUrgent`,
-                   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
-                   bpp.`KGChargeId`,
-                   bpp.`orderNumber`,
-                   bpp.`pastureId`,
-                   bpp.`statue`,
-                   bpp.`workflowId`,
-                   bpp.`workflowNote`,
-                   bpp.purchase_type,
-                   p.`name` pastureName,
-                   e.empname ,
-                   e1.empname KGChargePerson,
-                   e2.empname chargePerson,
-                   e3.empname  CGChargePerson,
-                   d.`name` AS departmentName,
-                   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
-                   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
-
-               FROM
-                   bigpartpurchase bpp
-                       LEFT JOIN pasture p
-                                 ON p.id = bpp.pastureId
-                       LEFT JOIN emp e
-                                 ON e.id = bpp.employeId
-                       LEFT JOIN department d
-                                 ON d.id = bpp.departmentId
-                       LEFT JOIN emp e1
-                                 ON e1.id = bpp.KGChargeId
-                       LEFT JOIN emp e2
-                                 ON e2.id = bpp.chargeId
-                       LEFT JOIN emp e3
-                                 ON e3.id = bpp.CGChargeId
-                       LEFT JOIN emp e4
-                                 ON e4.id = bpp.financeId
-               WHERE  bpp.statue = 5 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
-                                                                                                      LEFT JOIN user_role ur
-                                                                                                                ON ur.`user_id`= u.`id`
-                                                                                                      LEFT JOIN role r
-                                                                                                                ON r.`id` = ur.`role_id`
-                                                                                                      LEFT JOIN role_menu rm
-                                                                                                                ON r.`id` = rm.`role_id`
-                                                                                                      LEFT JOIN menu m
-                                                                                                                ON m.`id` = rm.`menu_id`
-                                                                         WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='changzhangshenhe' LIMIT 1),-1)<> -1)
-
-               UNION ALL
-
-               SELECT
-                   bpp.`buyStatu`,
-                   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
-                   bpp.`CGChargeId`,
-                   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
-                   bpp.`chargeId`,
-                   bpp.`createTime`,
-                   bpp.`departmentId`,
-                   bpp.`employeId`,
-                   bpp.`flowCompeleted`,
-                   bpp.`flowworkNote`,
-                   bpp.`id`,
-                   bpp.`isUrgent`,
-                   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
-                   bpp.`KGChargeId`,
-                   bpp.`orderNumber`,
-                   bpp.`pastureId`,
-                   bpp.`statue`,
-                   bpp.`workflowId`,
-                   bpp.`workflowNote`,
-                   bpp.purchase_type,
-                   p.`name` pastureName,
-                   e.empname ,
-                   e1.empname KGChargePerson,
-                   e2.empname chargePerson,
-                   e3.empname  CGChargePerson,
-                   d.`name` AS departmentName,
-                   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
-                   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
-
-               FROM
-                   bigpartpurchase bpp
-                       LEFT JOIN pasture p
-                                 ON p.id = bpp.pastureId
-                       LEFT JOIN emp e
-                                 ON e.id = bpp.employeId
-                       LEFT JOIN department d
-                                 ON d.id = bpp.departmentId
-                       LEFT JOIN emp e1
-                                 ON e1.id = bpp.KGChargeId
-                       LEFT JOIN emp e2
-                                 ON e2.id = bpp.chargeId
-                       LEFT JOIN emp e3
-                                 ON e3.id = bpp.CGChargeId
-                       LEFT JOIN emp e4
-                                 ON e4.id = bpp.financeId
-               WHERE  bpp.statue = 9 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
-                                                                                                      LEFT JOIN user_role ur
-                                                                                                                ON ur.`user_id`= u.`id`
-                                                                                                      LEFT JOIN role r
-                                                                                                                ON r.`id` = ur.`role_id`
-                                                                                                      LEFT JOIN role_menu rm
-                                                                                                                ON r.`id` = rm.`role_id`
-                                                                                                      LEFT JOIN menu m
-                                                                                                                ON m.`id` = rm.`menu_id`
-                                                                         WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='customs:subscribe:examineZG' LIMIT 1),-1)<> -1)
-
-               UNION ALL
-
-               SELECT
-                   bpp.`buyStatu`,
-                   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
-                   bpp.`CGChargeId`,
-                   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
-                   bpp.`chargeId`,
-                   bpp.`createTime`,
-                   bpp.`departmentId`,
-                   bpp.`employeId`,
-                   bpp.`flowCompeleted`,
-                   bpp.`flowworkNote`,
-                   bpp.`id`,
-                   bpp.`isUrgent`,
-                   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
-                   bpp.`KGChargeId`,
-                   bpp.`orderNumber`,
-                   bpp.`pastureId`,
-                   bpp.`statue`,
-                   bpp.`workflowId`,
-                   bpp.`workflowNote`,
-                   bpp.purchase_type,
-                   p.`name` pastureName,
-                   e.empname ,
-                   e1.empname KGChargePerson,
-                   e2.empname chargePerson,
-                   e3.empname  CGChargePerson,
-                   d.`name` AS departmentName,
-                   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
-                   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
-
-               FROM
-                   bigpartpurchase bpp
-                       LEFT JOIN pasture p
-                                 ON p.id = bpp.pastureId
-                       LEFT JOIN emp e
-                                 ON e.id = bpp.employeId
-                       LEFT JOIN department d
-                                 ON d.id = bpp.departmentId
-                       LEFT JOIN emp e1
-                                 ON e1.id = bpp.KGChargeId
-                       LEFT JOIN emp e2
-                                 ON e2.id = bpp.chargeId
-                       LEFT JOIN emp e3
-                                 ON e3.id = bpp.CGChargeId
-                       LEFT JOIN emp e4
-                                 ON e4.id = bpp.financeId
-               WHERE  bpp.statue = 11 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
-                                                                                                       LEFT JOIN user_role ur
-                                                                                                                 ON ur.`user_id`= u.`id`
-                                                                                                       LEFT JOIN role r
-                                                                                                                 ON r.`id` = ur.`role_id`
-                                                                                                       LEFT JOIN role_menu rm
-                                                                                                                 ON r.`id` = rm.`role_id`
-                                                                                                       LEFT JOIN menu m
-                                                                                                                 ON m.`id` = rm.`menu_id`
-                                                                          WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='customs:subscribe:examineCG' LIMIT 1),-1)<> -1)
-
-              ) bpp
+bpp.`buyStatu`,
+DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
+bpp.`CGChargeId`,
+DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
+bpp.`chargeId`,
+bpp.`createTime`,
+bpp.`departmentId`,
+bpp.`employeId`,
+bpp.`flowCompeleted`,
+bpp.`flowworkNote`,
+bpp.`id`,
+bpp.`isUrgent`,
+DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
+bpp.`KGChargeId`,
+bpp.`orderNumber`,
+bpp.`pastureId`,
+bpp.`statue`,
+bpp.`workflowId`,
+bpp.`workflowNote`,
+bpp.purchase_type,
+p.`name` pastureName,
+e.empname ,
+e1.empname KGChargePerson,
+e2.empname chargePerson,
+e3.empname  CGChargePerson,
+d.`name` AS departmentName,
+DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
+bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
+FROM
+bigpartpurchase bpp
+LEFT JOIN pasture p
+    ON p.id = bpp.pastureId
+LEFT JOIN emp e
+    ON e.id = bpp.employeId
+LEFT JOIN department d
+    ON d.id = bpp.departmentId
+LEFT JOIN emp e1
+    ON e1.id = bpp.KGChargeId
+LEFT JOIN emp e2
+    ON e2.id = bpp.chargeId
+LEFT JOIN emp e3
+    ON e3.id = bpp.CGChargeId
+LEFT JOIN emp e4
+    ON e4.id = bpp.financeId
+WHERE  bpp.statue = 2 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
+LEFT JOIN user_role ur
+        ON ur.`user_id`= u.`id`
+LEFT JOIN role r
+        ON r.`id` = ur.`role_id`
+LEFT JOIN role_menu rm
+        ON r.`id` = rm.`role_id`
+LEFT JOIN menu m
+        ON m.`id` = rm.`menu_id`
+WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='customs:subscribe:examineKG' LIMIT 1),-1)<> -1)
+
+UNION ALL
+
+SELECT
+   bpp.`buyStatu`,
+   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
+   bpp.`CGChargeId`,
+   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
+   bpp.`chargeId`,
+   bpp.`createTime`,
+   bpp.`departmentId`,
+   bpp.`employeId`,
+   bpp.`flowCompeleted`,
+   bpp.`flowworkNote`,
+   bpp.`id`,
+   bpp.`isUrgent`,
+   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
+   bpp.`KGChargeId`,
+   bpp.`orderNumber`,
+   bpp.`pastureId`,
+   bpp.`statue`,
+   bpp.`workflowId`,
+   bpp.`workflowNote`,
+   bpp.purchase_type,
+   p.`name` pastureName,
+   e.empname ,
+   e1.empname KGChargePerson,
+   e2.empname chargePerson,
+   e3.empname  CGChargePerson,
+   d.`name` AS departmentName,
+   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
+   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
+FROM
+   bigpartpurchase bpp
+       LEFT JOIN pasture p
+                 ON p.id = bpp.pastureId
+       LEFT JOIN emp e
+                 ON e.id = bpp.employeId
+       LEFT JOIN department d
+                 ON d.id = bpp.departmentId
+       LEFT JOIN emp e1
+                 ON e1.id = bpp.KGChargeId
+       LEFT JOIN emp e2
+                 ON e2.id = bpp.chargeId
+       LEFT JOIN emp e3
+                 ON e3.id = bpp.CGChargeId
+       LEFT JOIN emp e4
+                 ON e4.id = bpp.financeId
+WHERE  bpp.statue = 3  AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
+LEFT JOIN user_role ur
+         ON ur.`user_id`= u.`id`
+LEFT JOIN role r
+         ON r.`id` = ur.`role_id`
+LEFT JOIN role_menu rm
+         ON r.`id` = rm.`role_id`
+LEFT JOIN menu m
+         ON m.`id` = rm.`menu_id`
+WHERE u.`empid` = ? and m.enable = 1  AND m.`path`='customs:subscribe:examineSBZG' LIMIT 1),-1)<> -1)
+UNION ALL
+SELECT
+   bpp.`buyStatu`,
+   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
+   bpp.`CGChargeId`,
+   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
+   bpp.`chargeId`,
+   bpp.`createTime`,
+   bpp.`departmentId`,
+   bpp.`employeId`,
+   bpp.`flowCompeleted`,
+   bpp.`flowworkNote`,
+   bpp.`id`,
+   bpp.`isUrgent`,
+   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
+   bpp.`KGChargeId`,
+   bpp.`orderNumber`,
+   bpp.`pastureId`,
+   bpp.`statue`,
+   bpp.`workflowId`,
+   bpp.`workflowNote`,
+   bpp.purchase_type,
+   p.`name` pastureName,
+   e.empname ,
+   e1.empname KGChargePerson,
+   e2.empname chargePerson,
+   e3.empname  CGChargePerson,
+   d.`name` AS departmentName,
+   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
+   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
+
+FROM
+   bigpartpurchase bpp
+       LEFT JOIN pasture p
+                 ON p.id = bpp.pastureId
+       LEFT JOIN emp e
+                 ON e.id = bpp.employeId
+       LEFT JOIN department d
+                 ON d.id = bpp.departmentId
+       LEFT JOIN emp e1
+                 ON e1.id = bpp.KGChargeId
+       LEFT JOIN emp e2
+                 ON e2.id = bpp.chargeId
+       LEFT JOIN emp e3
+                 ON e3.id = bpp.CGChargeId
+       LEFT JOIN emp e4
+                 ON e4.id = bpp.financeId
+WHERE  bpp.statue = 5 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
+LEFT JOIN user_role ur
+        ON ur.`user_id`= u.`id`
+LEFT JOIN role r
+        ON r.`id` = ur.`role_id`
+LEFT JOIN role_menu rm
+        ON r.`id` = rm.`role_id`
+LEFT JOIN menu m
+        ON m.`id` = rm.`menu_id`
+WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='changzhangshenhe' LIMIT 1),-1)<> -1)
+
+UNION ALL
+
+SELECT
+   bpp.`buyStatu`,
+   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
+   bpp.`CGChargeId`,
+   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
+   bpp.`chargeId`,
+   bpp.`createTime`,
+   bpp.`departmentId`,
+   bpp.`employeId`,
+   bpp.`flowCompeleted`,
+   bpp.`flowworkNote`,
+   bpp.`id`,
+   bpp.`isUrgent`,
+   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
+   bpp.`KGChargeId`,
+   bpp.`orderNumber`,
+   bpp.`pastureId`,
+   bpp.`statue`,
+   bpp.`workflowId`,
+   bpp.`workflowNote`,
+   bpp.purchase_type,
+   p.`name` pastureName,
+   e.empname ,
+   e1.empname KGChargePerson,
+   e2.empname chargePerson,
+   e3.empname  CGChargePerson,
+   d.`name` AS departmentName,
+   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
+   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
+
+FROM
+   bigpartpurchase bpp
+       LEFT JOIN pasture p
+                 ON p.id = bpp.pastureId
+       LEFT JOIN emp e
+                 ON e.id = bpp.employeId
+       LEFT JOIN department d
+                 ON d.id = bpp.departmentId
+       LEFT JOIN emp e1
+                 ON e1.id = bpp.KGChargeId
+       LEFT JOIN emp e2
+                 ON e2.id = bpp.chargeId
+       LEFT JOIN emp e3
+                 ON e3.id = bpp.CGChargeId
+       LEFT JOIN emp e4
+                 ON e4.id = bpp.financeId
+WHERE  bpp.statue = 9 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
+LEFT JOIN user_role ur
+        ON ur.`user_id`= u.`id`
+LEFT JOIN role r
+        ON r.`id` = ur.`role_id`
+LEFT JOIN role_menu rm
+        ON r.`id` = rm.`role_id`
+LEFT JOIN menu m
+        ON m.`id` = rm.`menu_id`
+WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='customs:subscribe:examineZG' LIMIT 1),-1)<> -1)
+
+UNION ALL
+
+SELECT
+   bpp.`buyStatu`,
+   DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
+   bpp.`CGChargeId`,
+   DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
+   bpp.`chargeId`,
+   bpp.`createTime`,
+   bpp.`departmentId`,
+   bpp.`employeId`,
+   bpp.`flowCompeleted`,
+   bpp.`flowworkNote`,
+   bpp.`id`,
+   bpp.`isUrgent`,
+   DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
+   bpp.`KGChargeId`,
+   bpp.`orderNumber`,
+   bpp.`pastureId`,
+   bpp.`statue`,
+   bpp.`workflowId`,
+   bpp.`workflowNote`,
+   bpp.purchase_type,
+   p.`name` pastureName,
+   e.empname ,
+   e1.empname KGChargePerson,
+   e2.empname chargePerson,
+   e3.empname  CGChargePerson,
+   d.`name` AS departmentName,
+   DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
+   bpp.financeId,e4.empname  financeName, DATE_FORMAT(bpp.financedate, '%Y-%m-%d') financedate
+
+FROM
+   bigpartpurchase bpp
+       LEFT JOIN pasture p
+                 ON p.id = bpp.pastureId
+       LEFT JOIN emp e
+                 ON e.id = bpp.employeId
+       LEFT JOIN department d
+                 ON d.id = bpp.departmentId
+       LEFT JOIN emp e1
+                 ON e1.id = bpp.KGChargeId
+       LEFT JOIN emp e2
+                 ON e2.id = bpp.chargeId
+       LEFT JOIN emp e3
+                 ON e3.id = bpp.CGChargeId
+       LEFT JOIN emp e4
+                 ON e4.id = bpp.financeId
+WHERE  bpp.statue = 11 AND bpp.pastureId = ?  AND (IFNULL((SELECT r.`datarole` FROM `user` u
+   LEFT JOIN user_role ur
+             ON ur.`user_id`= u.`id`
+   LEFT JOIN role r
+             ON r.`id` = ur.`role_id`
+   LEFT JOIN role_menu rm
+             ON r.`id` = rm.`role_id`
+   LEFT JOIN menu m
+             ON m.`id` = rm.`menu_id`
+WHERE u.`empid` = ?  and m.enable = 1 AND m.`path`='customs:subscribe:examineCG' LIMIT 1),-1)<> -1)
+
+) bpp
 WHERE
-    (
-                bpp.orderNumber LIKE CONCAT("%", ?, "%")
-            OR ? = ''
-        )
+(
+bpp.orderNumber LIKE CONCAT("%", ?, "%")
+OR ? = ''
+)
+AND (
+bpp.`pastureName` = ?
+OR ? = '现代牧业'
+)
+AND (
+bpp.departmentId = ?
+OR ? = ''
+)AND (
+(bpp.createTime >= ? AND bpp.createTime <= ? )
+OR ? = ''
+)
+ORDER BY bpp.id DESC;
+
+
+# select * from apisql  where sqlname = 'getbuydetailParts'   备件采购-采购配单过滤掉特殊申购数据
+(SELECT
+     CONCAT('uploads/thumbnail/',ep.`picpath`,'/',ep.`newpicname`) picpath,
+     CONCAT('uploads/image/',ep.`picpath`,'/',ep.`newpicname`) srcpath,
+     dd.purpose1 purpose,
+     (SELECT dd.sumAmount DIV rr.cou) amount,
+     dd.sumAmount % rr.cou amountPre,
+     rr.cou COUNT,
+     pd.`providerName`,
+     pd.id providerId,
+     dd.orderNumber,
+     dd.sumAmount,
+     dd.departmentName,
+     c.id,
+     c.bigId,
+     c.pastureId,
+     c.pastureName,
+     c.partId,
+     c.partName,
+     c.partCode,
+     c.specification,
+     TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.price))) price,
+     c.brandId,
+     c.brand,
+     c.inventoryType,
+     c.planAmount,
+     c.remark,
+     c.enable,
+     c.unit,
+     c.isZeroStock,
+     bc.contractCode,
+     dd.sgDateTime  sgDateTime
+FROM contract c
+    INNER JOIN
+(SELECT SUM(pp.`amount`) sumAmount,pp.*,GROUP_CONCAT(pp.purpose) purpose1,GROUP_CONCAT(bpp.orderNumber)orderNumber,GROUP_CONCAT(d.name)departmentName,bpp.createTime sgDateTime FROM  bigpartpurchase bpp
+                                                                                                                                                                                ON pp.`bigId` =  bpp.`id`
+WHERE bpp.pastureId = ? AND bpp.buyStatu = 0 AND bpp.statue = 7 AND bpp.purchase_type <= 0
+GROUP BY pp.partCode) dd
+ON dd.partCode = c.`partCode`
+LEFT JOIN  bigcontract bc
+         ON bc.`id` = c.`bigId`
+LEFT JOIN  provider pd
+         ON pd.`id` = bc.`providerId`
+
+LEFT JOIN (SELECT ww.partCode,COUNT(*) cou FROM(
+SELECT
+ (SELECT dd.sumAmount DIV dd.cou) amount,
+ dd.sumAmount % dd.cou amountPre,
+ dd.cou COUNT,
+ pd.`providerName`,pd.id providerId,dd.orderNumber,dd.sumAmount,c.id,c.bigId,c.pastureId,c.pastureName,c.partId,c.partName,c.partCode,c.specification,TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.price))) price,c.brandId
+     ,c.brand,c.inventoryType,c.planAmount,c.remark,c.enable,c.unit,c.isZeroStock,bc.contractCode FROM contract c
+   INNER JOIN
+(SELECT SUM(pp.`amount`) sumAmount,pp.*,bpp.orderNumber,COUNT(*) cou FROM  bigpartpurchase bpp
+                                                                              LEFT JOIN partpurchase pp
+                                                                                        ON pp.`bigId` =  bpp.`id`
+WHERE bpp.pastureId = ? AND bpp.buyStatu = 0 AND bpp.statue = 7 AND bpp.purchase_type <= 0
+GROUP BY pp.partCode) dd
+ON dd.partCode = c.`partCode`
+   LEFT JOIN  bigcontract bc
+              ON bc.`id` = c.`bigId`
+   LEFT JOIN  provider pd
+              ON pd.`id` = bc.`providerId`
+WHERE bc.pastureId = ? AND(bc.`stopTime`>=DATE_FORMAT(NOW(),'%Y-%m-%d') AND  bc.statue=1 AND bc.SHStatus = 7 )
+) ww GROUP BY ww.partCode) rr
+        ON rr.partCode = c.partCode
+LEFT JOIN parts ps
+        ON ps.id = c.partId
+LEFT JOIN eq_pic ep
+        ON ep.id = ps.picpath
+ WHERE bc.pastureId =? AND  (bc.`stopTime`>=DATE_FORMAT(NOW(),'%Y-%m-%d') AND  bc.statue=1 AND bc.SHStatus = 7 )
+   AND c.enable = 1 and pd.id is not null
+ ORDER BY dd.partCode,c.price)
+
+
+UNION
+
+
+(SELECT
+     CONCAT('uploads/thumbnail/',ep.`picpath`,'/',ep.`newpicname`) picpath,
+     CONCAT('uploads/image/',ep.`picpath`,'/',ep.`newpicname`) srcpath,
+     dd.purpose1 purpose,
+     (SELECT dd.sumAmount DIV rr.cou) amount,
+     dd.sumAmount % rr.cou amountPre,
+     rr.cou COUNT,
+     pd.`providerName`,
+     pd.id providerId,
+     dd.orderNumber,
+     dd.sumAmount,
+     dd.departmentName,
+     c.id,
+     c.bigId,
+     c.pastureId,
+     c.pastureName,
+     c.partId,
+     c.partName,
+     c.partCode,
+     c.specification,
+     TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.price))) price,
+     c.brandId,
+     c.brand,
+     c.inventoryType,
+     c.planAmount,
+     c.remark,
+     c.enable,
+     c.unit,
+     c.isZeroStock,
+     bc.contractCode,
+     dd.sgDateTime  sgDateTime
+
+ FROM contract c
+-- join bigcontract bc  on bc.id = c.bigid
+INNER JOIN
+(SELECT SUM(pp.`amount`) sumAmount,pp.*,GROUP_CONCAT(pp.purpose) purpose1,GROUP_CONCAT(bpp.orderNumber)orderNumber,GROUP_CONCAT(d.name)departmentName,bpp.createTime sgDateTime FROM  bigpartpurchase bpp                                                                                                                                                                                          ON pp.`bigId` =  bpp.`id`
+WHERE bpp.pastureId = ? AND bpp.buyStatu = 0 AND bpp.statue = 7 AND bpp.purchase_type <= 0
+GROUP BY pp.partCode) dd
+ON dd.partCode = c.`partCode`
+LEFT JOIN  bigcontract bc
+         ON bc.`id` = c.`bigId`
+LEFT JOIN  provider pd
+         ON pd.`id` = bc.`providerId`
+
+LEFT JOIN (SELECT ww.partCode,COUNT(*) cou FROM(
+SELECT
+ (SELECT dd.sumAmount DIV dd.cou) amount,
+ dd.sumAmount % dd.cou amountPre,
+ dd.cou COUNT,
+ pd.`providerName`,pd.id providerId,dd.orderNumber,dd.sumAmount,c.id,c.bigId,c.pastureId,c.pastureName,c.partId,c.partName,c.partCode,c.specification,TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.price))) price,c.brandId
+     ,c.brand,c.inventoryType,c.planAmount,c.remark,c.enable,c.unit,c.isZeroStock,bc.contractCode FROM contract c
+INNER JOIN
+(SELECT SUM(pp.`amount`) sumAmount,pp.*,bpp.orderNumber,COUNT(*) cou FROM  bigpartpurchase bpp
+LEFT JOIN partpurchase pp
+        ON pp.`bigId` =  bpp.`id`
+WHERE bpp.pastureId = ? AND bpp.buyStatu = 0 AND bpp.statue = 7 AND bpp.purchase_type <= 0
+GROUP BY pp.partCode) dd
+ON dd.partCode = c.`partCode`
+LEFT JOIN  bigcontract bc
+          ON bc.`id` = c.`bigId`
+LEFT JOIN  provider pd
+          ON pd.`id` = bc.`providerId`
+WHERE
+#bc.id in(select bigcontract_id from pasture_bigcontract  where pasture_id = ? )
+
+bc.pastureId = 18
+
+AND(bc.`stopTime`>=DATE_FORMAT(NOW(),'%Y-%m-%d') AND  bc.statue=1 AND bc.SHStatus = 7 )
+) ww GROUP BY ww.partCode) rr
+    ON rr.partCode = c.partCode
+
+LEFT JOIN parts ps
+    ON ps.id = c.partId
+LEFT JOIN eq_pic ep
+    ON ep.id = ps.picpath
+WHERE
+left(bc.contractCode,12) in (select left(contractCode,12) from bigcontract  where id in (select bigcontract_id from pasture_bigcontract  where pasture_id = ?) )
+and
+bc.pastureId =18
+AND  (bc.`stopTime`>=DATE_FORMAT(NOW(),'%Y-%m-%d') AND  bc.statue=1 AND bc.SHStatus = 7 )
+AND c.enable = 1  and  pd.id is not null
+ORDER BY dd.partCode,c.price);
+
+
+
+# select * from apisql  where sqlname = 'getBigbuydetailList'
+select t1.* from (
+SELECT
+ bbd.`id`,
+ bbd.arrivalStatu,
+ bbd.`buyeCode`,
+ p.`providerName`,
+ bbd.`matchCode`,
+ bbd.note,
+ pa.name pastureName,
+ e.`empname`,
+ bbd.purchase_type,  -- 这次添加的字段
+ DATE_FORMAT(bbd.buyerDate, '%Y-%m-%d')  buyerDate,
+ IF( bbd.statu = 0,
+     IF(bbd.arrivalStatu=0 AND DATEDIFF(NOW(),bbd.buyerDate)>7,3,
+        IF(bbd.arrivalStatu=1 AND DATEDIFF(NOW(),bbd.buyerDate)>7,5,
+           IF(bbd.arrivalStatu=2 AND DATEDIFF(bbd.DoneDate,bbd.buyerDate)>7,6,
+              bbd.arrivalStatu))
+         ),4) statu,
+ IF( bbd.statu = 0,
+     IF((bbd.arrivalStatu=0 AND DATEDIFF(NOW(),bbd.buyerDate)>7) OR bbd.arrivalStatu =3,DATEDIFF(NOW(),bbd.buyerDate)-7,
+        IF((bbd.arrivalStatu=1 AND DATEDIFF(NOW(),bbd.buyerDate)>7)OR bbd.arrivalStatu =5,DATEDIFF(NOW(),bbd.buyerDate)-7,
+           IF((bbd.arrivalStatu=2 AND DATEDIFF(bbd.DoneDate,bbd.buyerDate)>7) OR bbd.arrivalStatu =6,DATEDIFF(bbd.DoneDate,bbd.buyerDate)-7,
+              0))
+         ),0) extensionDays,
+ DATE_FORMAT(bbd.DoneDate, '%Y-%m-%d') DoneDate,if(sapStatus= 2,1,if(sapStatus = 1,0,-1) ) sapstatus,if(srmStatus= 2,1,if(srmStatus = 1,0,-1) ) srmstatus,sapNumber,srmError
+FROM
+ bigbuydetail bbd
+     LEFT JOIN provider p
+               ON p.id = bbd.`providerId`
+     LEFT JOIN emp e
+               ON e.id = bbd.`buyerPerson`
+     inner join pasture pa
+                on pa.id  = bbd.pastureId
+WHERE  (pa.name=? or ?='现代牧业')  and bbd.zeroCou>0 and  bbd.`enable`=0 AND  (
+         p.`providerName` = ?
+     OR ? = ''
+ )
+AND (
+     (bbd.`buyerDate` >= ? AND bbd.`buyerDate` <= ? )
+     OR ? = ''
+ )
+AND (
+         bbd.`buyeCode` LIKE CONCAT('%', ?, '%')
+     OR ? = ''
+ )
+)t1
+where
+        t1.statu = ?
+   OR ? = ''
+ORDER BY t1.`id` desc;
+
+# select * from apisql  where sqlname = 'getBigPartuseList'
+
+SELECT
+    (CASE bpu.issync
+         WHEN 0 THEN '同步失败'
+         WHEN 1 THEN '同步成功'
+         WHEN 2 THEN '关闭同步'
+         WHEN 3 THEN '同步成功'
+        END
+        ) easStatus,
+    e1.`empname`,
+    d.`name` AS departmentName,
+    bpu.id,
+    bpu.pastureId ,
+    bpu.departmentId ,
+    bpu.useForm ,
+    bpu.listType ,
+    bpu.planUpkeepId ,
+    bpu.maintainId ,
+    bpu.oddCode ,
+    bpu.applicatId ,
+    bpu.receiveTime ,
+    bpu.useStatus ,
+    bpu.refuseStatue ,
+    bpu.sumPrice  ,
+    bpu.workflowId ,
+    bpu.flowCompeleted ,
+    bpu.flowworkNote ,
+    bpu.fClassId ,
+    bpu.sClassId ,
+    bpu.useType ,
+    bpu.empId ,
+    bpu.creatDate ,
+    bpu.note ,
+    bpu.issync ,
+    bpu.msg ,
+    bpu.greenFodderNumber,   --- 这次新加的字段
+    ifnull(bpu.ProofCode,'') ProofCode,
+    p.`name` pastureName,
+    (SELECT COUNT(id) FROM partuse pu WHERE pu.bigId = bpu.`id` ) partKind,
+    e.empname AS appliname,
+    e.id employeId,
+    DATE_FORMAT(bpu.receiveTime, '%Y-%m-%d') creatTime,sterilisation
+FROM
+    bigpartuse bpu
+        LEFT JOIN pasture p
+                  ON p.id = bpu.pastureId
+        LEFT JOIN emp e
+                  ON e.id = bpu.applicatId
+        LEFT JOIN emp e1
+                  ON e1.id = bpu.`empId`
+        LEFT JOIN department d
+                  ON d.id = bpu.`departmentId`
+WHERE (
+            bpu.useForm LIKE CONCAT("%", ?, "%")
+        OR ? = ''
+    )
+  AND (
+        if(? = 0, bpu.`useType` in(0,2,3), bpu.`useType` = ?)
+        OR ? = ''
+    )
+  AND (
+        (bpu.receiveTime >= ? and bpu.receiveTime <= ?)
+        OR ? = ''
+    )
   AND (
-            bpp.`pastureName` = ?
+            p.`name` =?
         OR ? = '现代牧业'
     )
   AND (
-            bpp.departmentId = ?
+            d.`id` =?
         OR ? = ''
-    )AND (
-        (bpp.createTime >= ? AND bpp.createTime <= ? )
+    )
+  AND (
+        if(?=1,bpu.issync IN(1,3),bpu.issync =?)
         OR ? = ''
     )
-ORDER BY bpp.id DESC;
+  AND (
+    IF (	? = 1,bpu.ProofCode IS NOT NULL,	IF	( ? = 2, bpu.ProofCode IS NULL, bpu.id > 0 ) 	)
+    )
+ORDER BY bpu.receiveTime DESC,bpu.id desc;