|
|
package service
|
|
|
|
|
|
import (
|
|
|
"cu-helper/cus-eng-con-sys/config"
|
|
|
"cu-helper/cus-eng-con-sys/cryptokit"
|
|
|
"cu-helper/cus-eng-con-sys/model"
|
|
|
"cu-helper/cus-eng-con-sys/util"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/go-resty/resty/v2"
|
|
|
"github.com/mizuki1412/go-core-kit/class/exception"
|
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
|
"github.com/spf13/cast"
|
|
|
"github.com/tidwall/gjson"
|
|
|
)
|
|
|
|
|
|
// ReqAccConfirm 验收确认请求
|
|
|
/*
|
|
|
验收确认分3个步骤进行
|
|
|
1、判断五达标
|
|
|
2、更新ACC信息
|
|
|
3、提交验收确认
|
|
|
*/
|
|
|
|
|
|
// ReqAccConfirm parenProcInsId=processInstanceId
|
|
|
func ReqAccConfirm(ctx *model.Ctx) {
|
|
|
//判断五达标是否有已废弃
|
|
|
parenProcInsId := ctx.Data.Get("processInstanceId").String()
|
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
header := h.GenReqParam()
|
|
|
f := model.NewSearchAccSendList(parenProcInsId)
|
|
|
form := f.GenReqParam()
|
|
|
client := ctx.RestyClient
|
|
|
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()
|
|
|
// ===================== 核心逻辑开始 =====================
|
|
|
// 只要有一个状态 不是空 也不是 ABANDON → 直接退出整个函数,不往下走
|
|
|
hasInvalid := false
|
|
|
for _, v := range ok {
|
|
|
deliveryStatus := gjson.Get(v.String(), "deliveryStatus").String()
|
|
|
if deliveryStatus != "" && deliveryStatus != "ABANDON" {
|
|
|
hasInvalid = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 有无效状态 → 直接结束函数,后面两个方法不调用
|
|
|
if hasInvalid {
|
|
|
logkit.Info("已分发五达标,无需再分发五达标")
|
|
|
return
|
|
|
}
|
|
|
// ===================== 核心逻辑结束 =====================
|
|
|
|
|
|
// ↓↓↓↓ 只有 全空 / 全ABANDON / 混合(空,ABANDON) 才会走到这里 ↓↓↓↓
|
|
|
//更新ACC信息
|
|
|
actOrgName, accInvestment := updateAccInfo(ctx)
|
|
|
processDefinitionName := ctx.Data.Get("processDefinitionName").String()
|
|
|
switch processDefinitionName {
|
|
|
case config.ProcessNameXQXJ:
|
|
|
//如果是小区新建,一定要进行五达标
|
|
|
saveProAndStart(ctx, actOrgName)
|
|
|
case config.ProcessNameKR:
|
|
|
if cast.ToInt64(accInvestment) >= 3000 {
|
|
|
//大于等于3000才进行五达标
|
|
|
logkit.Info("accInvestment=" + accInvestment + " 需要进行五达标!")
|
|
|
saveProAndStart(ctx, actOrgName)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func updateAccInfo(ctx *model.Ctx) (string, string) {
|
|
|
processDefinitionName := ctx.Data.Get("processDefinitionName").String()
|
|
|
processDefinitionKey := ctx.Data.Get("processDefinitionKey").String()
|
|
|
remandId := getRemandId(ctx)
|
|
|
html1 := toAcceptanceConfirm(ctx, remandId)
|
|
|
token := getToken(ctx.RestyClient)
|
|
|
html2 := toRemandShowCommon(ctx.RestyClient, remandId)
|
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
header := h.GenReqParam()
|
|
|
f := model.NewUpdateAccInfo(token, remandId, html1, html2, processDefinitionName, processDefinitionKey)
|
|
|
form := f.GenReqParam()
|
|
|
client := ctx.RestyClient
|
|
|
resp, err := client.R().
|
|
|
SetHeaders(header).SetFormData(form).Post(config.UrlPrefix + "/zjgd/frm/acceptanceController/udpateAccInfo.action")
|
|
|
if err != nil {
|
|
|
panic(exception.New(err.Error()))
|
|
|
}
|
|
|
data := strings.Trim(resp.String(), `"`)
|
|
|
logkit.Info("updateAccInfo:" + cryptokit.Decrypt(data))
|
|
|
return util.HTMLContentFindFirst(html2, "actOrgName"), cryptokit.Decrypt(f.AccInvestment)
|
|
|
}
|
|
|
|
|
|
func saveProAndStart(ctx *model.Ctx, actOrgName string) {
|
|
|
parenProcInsId := ctx.Data.Get("processInstanceId").String()
|
|
|
client := ctx.RestyClient
|
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
header := h.GenReqParam()
|
|
|
f := model.NewSaveProAndStart(parenProcInsId, actOrgName)
|
|
|
form := f.GenReqParam()
|
|
|
resp, err := client.R().
|
|
|
SetHeaders(header).SetFormData(form).Post(config.UrlPrefix + "/zjgd/frm/acceptanceComfirmController/saveProAndStart")
|
|
|
if err != nil {
|
|
|
panic(exception.New(err.Error()))
|
|
|
}
|
|
|
data := strings.Trim(resp.String(), `"`)
|
|
|
logkit.Info("saveProAndStart:" + cryptokit.Decrypt(data))
|
|
|
}
|
|
|
|
|
|
func getToken(client *resty.Client) string {
|
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
header := h.GenReqParam()
|
|
|
f := model.NewGetToken()
|
|
|
form := f.GenReqParam()
|
|
|
resp, err := client.R().
|
|
|
SetHeaders(header).SetFormData(form).Post(config.UrlPrefix + "/zjgd/frm/commonController/getToken?T=" + form["timestamp"])
|
|
|
if err != nil {
|
|
|
panic(exception.New(err.Error()))
|
|
|
}
|
|
|
data := strings.Trim(resp.String(), `"`)
|
|
|
decrypt := cryptokit.Decrypt(data)
|
|
|
token := gjson.Get(decrypt, "token").String()
|
|
|
logkit.Debug("拿到了Token:" + token)
|
|
|
return token
|
|
|
}
|
|
|
|
|
|
// businessKey=remandId,taskId=id
|
|
|
func toAcceptanceConfirm(ctx *model.Ctx, businessKey string) string {
|
|
|
processInstId := ctx.Data.Get("processInstanceId").String()
|
|
|
taskId := ctx.Data.Get("id").String()
|
|
|
taskDefinitionKey := ctx.Data.Get("taskdefinitionKey").String()
|
|
|
client := ctx.RestyClient
|
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
header := h.GenReqParam()
|
|
|
query := model.NewCommonFormGetHtml(businessKey, processInstId, taskDefinitionKey, taskId)
|
|
|
resp, err := client.R().
|
|
|
SetHeaders(header).Get(config.UrlPrefix + "/zjgd/frm/acceptanceComfirmController/toAcceptanceComfirm?businessKey=" + query.BusinessKey + "&processInstanceId=" + query.ProcessInstanceId + "&taskId=" + query.TaskId + "&startLink=" + query.StartLink + "&endLink=" + query.EndLink + "&taskflag=" + query.TaskFlag + "&ranstr=" + query.Ranstr + "×tamp=" + query.Timestamp + "&_=" + query.TimestampPro)
|
|
|
if err != nil {
|
|
|
panic(exception.New(err.Error()))
|
|
|
}
|
|
|
return resp.String()
|
|
|
}
|
|
|
|
|
|
func toRemandShowCommon(client *resty.Client, remandId string) string {
|
|
|
h := model.NewHeader("application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
header := h.GenReqParam()
|
|
|
query := model.NewToRemandShowCommon(remandId)
|
|
|
resp, err := client.R().
|
|
|
SetHeaders(header).Get(config.UrlPrefix + "/zjgd/frm/remandInfoController/toRemandShowCommon?remandId=" + query.RemandId + "&ranstr=" + query.Ranstr + "×tamp=" + query.Timestamp + "&_=" + query.TimestampPro)
|
|
|
if err != nil {
|
|
|
panic(exception.New(err.Error()))
|
|
|
}
|
|
|
return resp.String()
|
|
|
}
|