You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
4.0 KiB
Go
130 lines
4.0 KiB
Go
package service
|
|
|
|
import (
|
|
"cu-helper/cus-eng-con-sys/config"
|
|
"cu-helper/cus-eng-con-sys/cryptokit"
|
|
"cu-helper/cus-eng-con-sys/model"
|
|
"github.com/go-resty/resty/v2"
|
|
"github.com/mizuki1412/go-core-kit/class/exception"
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
"github.com/tidwall/gjson"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// AssignScrap 取消交付
|
|
/*
|
|
取消交付分两个步骤进行
|
|
1、searchAccSendList获取RemovalInfo
|
|
2、根据RemovalInfo判断哪个需要撤回和废除
|
|
4、
|
|
3、assignScrap
|
|
*/
|
|
|
|
func ReqWithdrawAssign(parenProcInsId string) {
|
|
list := searchAccSendList(parenProcInsId)
|
|
for _, v := range list {
|
|
if v.DeliveryId == "" {
|
|
continue
|
|
}
|
|
if v.DeliveryStatus == "COMPLETE" {
|
|
//先撤回,再废除
|
|
backFlow(v.Name, v.DeliveryId, parenProcInsId)
|
|
assignScrap(v.Name, v.DeliveryId, parenProcInsId)
|
|
} else {
|
|
//未完成的直接废除
|
|
assignScrap(v.Name, v.DeliveryId, parenProcInsId)
|
|
}
|
|
}
|
|
}
|
|
|
|
type RemovalInfo struct {
|
|
Name string
|
|
DeliveryId string
|
|
DeliveryStatus string
|
|
}
|
|
|
|
func searchAccSendList(parenProcInsId string) []RemovalInfo {
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
header := h.GenReqParam()
|
|
f := model.NewSearchAccSendList(parenProcInsId)
|
|
form := f.GenReqParam()
|
|
client := resty.New().SetRetryCount(5).SetRetryWaitTime(15 * time.Second)
|
|
resp, err := client.R().
|
|
SetHeaders(header).SetFormData(form).Post(config.UrlPrefix + "/zjgd/frm/acceptanceComfirmController/searchAccSendList")
|
|
if err != nil {
|
|
panic(exception.New(err.Error()))
|
|
}
|
|
data := strings.Trim(resp.String(), `"`)
|
|
decrypt := cryptokit.Decrypt(data)
|
|
ok := gjson.Get(decrypt, "data").Array()
|
|
var removalList []RemovalInfo
|
|
//seen := make(map[string]gjson.Result)
|
|
for _, v := range ok {
|
|
splitName := gjson.Get(v.String(), "splitName").String()
|
|
deliveryId := gjson.Get(v.String(), "deliveryId").String()
|
|
deliveryStatus := gjson.Get(v.String(), "deliveryStatus").String()
|
|
if deliveryStatus == "ABANDON" {
|
|
continue
|
|
}
|
|
//if existing, exists := seen[splitName]; exists {
|
|
// existingStatus := gjson.Get(existing.String(), "deliveryStatus").String()
|
|
//
|
|
// if existingStatus == "SUBMIT" && deliveryStatus == "COMPLETE" {
|
|
// removalList = append(removalList, RemovalInfo{
|
|
// Name: splitName,
|
|
// DeliveryId: existing.Get("deliveryId").String(),
|
|
// DeliveryStatus: existingStatus,
|
|
// })
|
|
// seen[splitName] = v
|
|
// } else {
|
|
// removalList = append(removalList, RemovalInfo{
|
|
// Name: splitName,
|
|
// DeliveryId: deliveryId,
|
|
// DeliveryStatus: deliveryStatus,
|
|
// })
|
|
// }
|
|
//} else {
|
|
// seen[splitName] = v
|
|
//}
|
|
removalList = append(removalList, RemovalInfo{
|
|
Name: splitName,
|
|
DeliveryId: deliveryId,
|
|
DeliveryStatus: deliveryStatus,
|
|
})
|
|
|
|
}
|
|
return removalList
|
|
}
|
|
|
|
func backFlow(name, deliveryId, parenProcInsId string) {
|
|
client := resty.New().SetRetryCount(5).SetRetryWaitTime(15 * time.Second)
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
header := h.GenReqParam()
|
|
f := model.NewBackFlow(deliveryId, parenProcInsId)
|
|
form := f.GenReqParam()
|
|
resp, err := client.R().
|
|
SetHeaders(header).SetFormData(form).Post(config.UrlPrefix + "/zjgd/frm/acceptanceComfirmController/backFlow")
|
|
if err != nil {
|
|
panic(exception.New(err.Error()))
|
|
}
|
|
data := strings.Trim(resp.String(), `"`)
|
|
logkit.Info("backFlow:" + name + cryptokit.Decrypt(data))
|
|
|
|
}
|
|
|
|
func assignScrap(name, deliveryId, parenProcInsId string) {
|
|
client := resty.New().SetRetryCount(5).SetRetryWaitTime(15 * time.Second)
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
header := h.GenReqParam()
|
|
f := model.NewAssignScrap(deliveryId, parenProcInsId)
|
|
form := f.GenReqParam()
|
|
resp, err := client.R().
|
|
SetHeaders(header).SetFormData(form).Post(config.UrlPrefix + "/zjgd/frm/acceptanceComfirmController/assignScrap")
|
|
if err != nil {
|
|
panic(exception.New(err.Error()))
|
|
}
|
|
data := strings.Trim(resp.String(), `"`)
|
|
logkit.Info("assignScarp:" + name + cryptokit.Decrypt(data))
|
|
}
|