package TaxSb

import (
	"context"
	"fmt"
	"git.listensoft.net/tool/jspkit/common"
	"git.listensoft.net/tool/jspkit/common/models"
	"git.listensoft.net/tool/jspkit/common/models/sb"
	"git.listensoft.net/tool/jspkit/common/variable"
	"git.listensoft.net/tool/jspkit/taxerr"
	"math"
	"strings"
	"time"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/utils"
)

func SbQysds(ctx context.Context, newp *rod.Page, info models.CompanyInfo, task *models.TaxTask) {
	var A200000 sb.GsTaxQuarter
	if ok := common.GetData(variable.GsTaxQuarter, task.Data, &A200000); !ok {
		panic(taxerr.QysdsEmpty)
	}
	a7 := []sb.GsTaxQuarterFb1{}
	if ok := common.GetData(variable.GsTaxQuarterFb1, task.Data, &a7); !ok {
		panic(taxerr.QysdsFb1Empty)
	}
	a8 := []sb.GsTaxQuarterFb2{}
	if ok := common.GetData(variable.GsTaxQuarterFb2, task.Data, &a8); !ok {
		panic(taxerr.QysdsFb2Empty)
	}
	a13 := []sb.GsTaxQuarterFb3{}
	if ok := common.GetData(variable.GsTaxQuarterFb3, task.Data, &a13); !ok {
		panic(taxerr.QysdsFb3Empty)
	}
	err := rod.Try(func() {
		//是否简易模式
		if newp.Timeout(common.ClickTimeOut).MustHas(`body > div.t-dialog__ctx.t-dialog__ctx--fixed > div.t-dialog__wrap > div > div > div.t-dialog__header > div`) {
			newp.Timeout(common.ClickTimeOut).MustElement(`body > div.t-dialog__ctx.t-dialog__ctx--fixed > div.t-dialog__wrap > div > div > div.t-dialog__footer > div > button.t-button.t-button--variant-base.t-button--theme-default`).MustClick()
		}
		utils.Sleep(3)
		//span[contains(text(), "继续办理")]
		if newp.Timeout(common.ClickTimeOut).MustHasX(`//span[contains(text(), "继续办理")]`) {
			newp.Timeout(common.ClickTimeOut).MustElementX(`//span[contains(text(), "继续办理")]`).MustClick()
		}
		if newp.MustHasX(`//span[contains(text(), "您本属期已申报")]`) {
			task.Result.BusinessStatus = variable.TaxSuccess
			task.Result.BusinessImg = SaveErrImg(newp, info)
			return
		}
		if newp.MustHasR(`body > section > section > section > main > div > div > div > div.gov-inspect > div.gov-inspect-header > div.gov-inspect-header__status-text`, "检测不通过") {
			errMsg := newp.Timeout(common.ClickTimeOut).MustElement(`body > section > section > section > main > div > div > div > div.gov-inspect > div.gov-inspect-table > div > div > div > div > span.gov-inspect-item__text > span`).MustText()
			task.Result.BusinessStatus = variable.TaxFail
			task.Result.BusinessImg = SaveErrImg(newp, info)
			panic(taxerr.NewUserV3(errMsg, "请核实后重试"))
		}
		//检测不通过 返回首页
		if newp.Timeout(common.ClickTimeOut).MustHasX(`//span[contains(text(), "返回首页")]`) {
			task.Result.BusinessStatus = variable.TaxFail
			task.Result.BusinessLog = "检测不通过"
			task.Result.BusinessImg = SaveErrImg(newp, info)
			return
		}
		utils.Sleep(1)
		//您符合简易申报条件,是否确定简易申报?
		if newp.Timeout(common.ClickTimeOut).MustHas(`body > div.t-dialog__ctx.t-dialog__ctx--fixed > div.t-dialog__wrap > div > div > div.t-dialog__header > div`) {
			newp.Timeout(common.ClickTimeOut).MustElement(`body > div.t-dialog__ctx.t-dialog__ctx--fixed > div.t-dialog__wrap > div > div > div.t-dialog__footer > div > button`).MustClick()
		}
		utils.Sleep(5)

		if newp.Timeout(common.ClickTimeOut).MustHasR(`body > div.t-dialog__ctx.t-dialog__ctx--fixed > div.t-dialog__wrap > div > div > div.t-dialog__body.t-dialog__body--icon`, "您符合简易申报条件,是否确定简易申报?") {
			//取消
			newp.Timeout(common.ClickTimeOut).MustSearch(`取消`).MustClick()
			utils.Sleep(3)
		}

		if newp.Timeout(common.ClickTimeOut).MustHas(`body > div.t-dialog__ctx.t-dialog__ctx--fixed > div.t-dialog__wrap > div > div > div.t-dialog__header > div`) {
			newp.Timeout(common.ClickTimeOut).MustElement(`body > div.t-dialog__ctx.t-dialog__ctx--fixed > div.t-dialog__wrap > div > div > div.t-dialog__footer > div > button.t-button.t-button--variant-base.t-button--theme-default`).MustClick() //取消
		}
		qysdsDeclareDo(ctx, newp, info, A200000, a7, a8, a13, task)
	})
	if err != nil {
		task.Result.BusinessStatus = variable.TaxFail
		task.Result.BusinessLog = common.HandleError(ctx, err).Error()
		return
	}
}

func qysdsDeclareDo(ctx context.Context, newp *rod.Page, info models.CompanyInfo, A200000 sb.GsTaxQuarter, a7 []sb.GsTaxQuarterFb1, a8 []sb.GsTaxQuarterFb2, a13 []sb.GsTaxQuarterFb3, task *models.TaxTask) {
	err := rod.Try(func() {
		curperiodFl := common.StrToFloat(info.Period[4:])
		//判断当前第几季度   按季度填报信息
		jd := 0
		i := 0
		var jccyrs string //季初从业人数
		var jmcyrs string //季末从业人数
		var jczcze string //季初资产总额
		var jmzcze string //季末资产总额
		err2 := checkQysds20000(newp, A200000, curperiodFl)
		if err2 != nil {
			return
		}

		if math.Ceil(curperiodFl/3) == 1 {
			jd = 1
			i = 1
			jccyrs = A200000.Qccyrs1
			jmcyrs = A200000.Qmcyrs1
			jczcze = A200000.Qczcze1
			jmzcze = A200000.Qmzcze1
		}
		if math.Ceil(curperiodFl/3) == 2 {
			jd = 2
			i = 3
			jccyrs = A200000.Qccyrs2
			jmcyrs = A200000.Qmcyrs2
			jczcze = A200000.Qczcze2
			jmzcze = A200000.Qmzcze2
		}
		if math.Ceil(curperiodFl/3) == 3 {
			jd = 3
			i = 5
			jccyrs = A200000.Qccyrs3
			jmcyrs = A200000.Qmcyrs3
			jczcze = A200000.Qczcze3
			jmzcze = A200000.Qmzcze3
		}
		if math.Ceil(curperiodFl/3) == 4 {
			jd = 4
			i = 7
			jccyrs = A200000.Qccyrs4
			jmcyrs = A200000.Qmcyrs4
			jczcze = A200000.Qczcze4
			jmzcze = A200000.Qmzcze4
		}
		fmt.Println(jd)
		var arr []string
		if common.StrToFloat(jczcze) <= 0 {
			arr = append(arr, `季初资产总额必须大于0`)
		}
		if common.StrToFloat(jmzcze) <= 0 {
			arr = append(arr, `季末资产总额必须大于0`)
		}
		if common.StrToFloat(jccyrs) <= 0 {
			arr = append(arr, `季初从业人数必须大于0`)
		}
		if common.StrToFloat(jmcyrs) <= 0 {
			arr = append(arr, `季末从业人数必须大于0`)
		}
		if len(arr) != 0 {
			panic(taxerr.NewUserV3(strings.Join(arr, `;`), "请核实后重试"))
		}
		//
		common.Input(newp, `(//td[contains(text(), "从业人数")]/..//input)[`+common.IntToStr(i)+`]`, jccyrs)
		common.Input(newp, `(//td[contains(text(), "从业人数")]/..//input)[`+common.IntToStr(i+1)+`]`, jmcyrs)

		common.Input(newp, `(//td[contains(text(), "资产总额(万元)")]/..//input)[`+common.IntToStr(i)+`]`, jczcze)
		common.Input(newp, `(//td[contains(text(), "资产总额(万元)")]/..//input)[`+common.IntToStr(i+1)+`]`, jmzcze)
		//失去焦距后后会有弹窗
		newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`//td[contains(text(), "从业人数")]`).MustClick()
		utils.Sleep(1)
		if common.MustHas(newp, `//div[text()="您申报的资产总额同资产负债表数据不一致,请确认填报的单位是否为万元,数据填报是否准确。"]`) {
			common.MustElementX(newp, `//div[text()="您申报的资产总额同资产负债表数据不一致,请确认填报的单位是否为万元,数据填报是否准确。"]/..//button/span`).MustClick()
			utils.Sleep(2)
		}
		//资产总额填报单位是万元,币种为人民币。请您确认填写的是否正确
		if newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustHas(`div[class="layui-layer-title"]`) {
			//
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`a[class="layui-layer-btn0"]`).MustClick()
		}

		if A200000.Xzhy == 1 { //1是0否  是否限制行业
			wait1 := newp.MustWaitRequestIdle()
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElement(`#viewCtrlId > div:nth-child(8) > table:nth-child(2) > tbody > tr:nth-child(6) > td.edit.left > label:nth-child(1) > input`).MustClick()
			wait1()
			if newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustHasR(`#layui-layer2 > div.layui-layer-btn.layui-layer-btn- > a.layui-layer-btn0`, "确定") {
				newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#layui-layer2 > div.layui-layer-btn.layui-layer-btn- > a.layui-layer-btn0`).MustClick()
			}
		}

		common.Input(newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame(), `//td[contains(text(), "营业收入")]/..//input`, A200000.Yysr)
		common.Input(newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame(), `//td[contains(text(), "营业成本")]/..//input`, A200000.Yycb)
		common.Input(newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame(), `//td[contains(text(), "利润总额")]/..//input`, A200000.Lrze)
		common.Input(newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame(), `//td[contains(text(), "加:特定业务计算的应纳税所得额")]/..//input`, A200000.Tdywjsdynssde)
		common.Input(newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame(), `//td[contains(text(), "减:不征税收入")]/..//input`, A200000.Bzssr)

		//a7
		var g int
		for _, v1 := range a7 {
			if v1.Status == 1 {
				g = 1
				break
			}
		}

		if g == 1 {
			wait3 := newp.MustWaitRequestIdle()
			//填写优惠事项
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`(//a[contains(text(), "减:免税收入、减计收入、加计扣除")]/..//a)[2]`).MustClick()
			wait3()
			for kk := range a7 {
				if a7[kk].Code != "" {
					if has, el, _ := newp.HasX(fmt.Sprintf("(//td[contains(text(),'%s')]/../td/input)[2]", a7[kk].Code)); has {
						inputStr(el, a7[kk].Amount)
					}
				}
			} //确认 保存
			MustElementX(newp, `//a[contains(text(),"确定")]`).MustClick()
		}
		//a8
		g1 := false
		for _, vv := range a8 {
			if vv.Status == 1 {
				g1 = true
				break
			}
		}
		//g1 = true
		if g1 {
			wait5 := newp.MustWaitRequestIdle()
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`(//a[contains(text(), "减:所得减免")]/..//a)[2]`).MustClick()
			wait5()
			for kk := range a8 {
				if a8[kk].Code != "" {
					if has, el, _ := newp.HasX(fmt.Sprintf("(//td[contains(text(),'%s')]/..//input)[2]", a8[kk].Code)); has {
						inputStr(el, a8[kk].Amount)
					}
				}
			}
			//确认 保存
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`//a[contains(text(),"确定")]`).MustClick()
		}
		//数据对比 //弥补以前年度亏损
		sjmbyqndks := newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`//td[contains(text(), "减:弥补以前年度亏损")]/..//input`).MustText()
		if common.StrToFloat(sjmbyqndks) != common.StrToFloat(A200000.Mbyqndks) { //弥补以前年度亏损
			panic(taxerr.NewUserV3(`弥补以前年度亏损税局为`+sjmbyqndks, "请核实后重试"))
		}
		//第10行大于0 再填写13行优惠事项
		mustText10 := newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`(//td[contains(text(), "实际利润额")]/..//input)[1]`).MustText()
		if common.StrToFloat(mustText10) > 0 {
			//填写优惠事项
			wait13 := newp.MustWaitRequestIdle()
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`(//a[contains(text(), "减:减免所得税额")]/..//a)[2]`).MustClick()
			utils.Sleep(1)
			wait13()
			for kk := range a13 {
				if common.StrToFloat(a13[kk].Amount) > 0 && a13[kk].Code == "JMSE99999" { //只有其他能填
					if has, el, _ := newp.HasX(`(//td[contains(text(), "JMSE99999")]/..//input)[2]`); has {
						inputStr(el, a13[kk].Amount)
					}
					//newp.MustElementX("(//td[contains(text()," + a13[kk].Code + ")]/..//input)[2]").MustInput(a13[kk].Amount)
				}
			}
			// 保存
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().MustElementX(`//a[contains(text(),"确定")]`).MustClick()
		}

		//报表列表
		if newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustHas(`body > div.TableMain > table > tbody > tr > td.biao_leftmenu > div > table > tbody > tr > td.dropdownBtn > span > i`) {
			newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`body > div.TableMain > table > tbody > tr > td.biao_leftmenu > div > table > tbody > tr > td.dropdownBtn > span > i`).MustClick()
		}
		utils.Sleep(1)
		//点击
		newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElementX(`//a[@title="《A201020固定资产加速折旧(扣除)优惠明细表》"]`).MustClick()
		utils.Sleep(2)
		//提交申报
		newp.Timeout(common.ClickTimeOut).MustElement(`#page-content > div > section > main > div > div > div > div.gt-layout-footerbar > div > div > div > div > div > div.fxgt-wrap-submitfooter-right > div > div:nth-child(2) > button > span`).MustClick()
		//如果有错误
		if newp.MustHas(`body > section > section > section > main > div > div > div > div > div.gt-layout-footerbar > div > div.gov-validate-dialog > div > div.gov-validate-dialog-content > ul > li > span`) {
			text := newp.MustElement(`body > section > section > section > main > div > div > div > div > div.gt-layout-footerbar > div > div.gov-validate-dialog > div > div.gov-validate-dialog-content > ul > li > span`).MustText()
			panic(taxerr.NewUserV3(text, "请核实后重试"))
		}

		if newp.MustHasX(`//div[@class="t-dialog__body t-dialog__body__icon"]`) {
			text := newp.MustElementX(`//div[@class="t-dialog__body t-dialog__body__icon"]`).MustText()
			if strings.Contains(text, "不符") {
				panic(taxerr.NewUserV3(text, "请核实后重试"))
			}
		}
		if newp.MustHasX(`//div[@class="drawer-body"]//li`) && newp.MustElementX(`//div[@class="drawer-body"]//li`).MustVisible() {
			elementsX := newp.MustElementsX(`//div[@class="drawer-body"]//li`)
			text := ""
			for _, e := range elementsX {
				text += e.MustElement(`p`).MustText()
			}
			panic(taxerr.NewUserV3(text, "请核实后重试"))
		}
		utils.Sleep(3)
		if newp.MustHasX(`//span[text()="核实无误,提交申报"]`) {
			MustElementX(newp, `//span[text()="核实无误,提交申报"]`).MustClick()
		}
		//确认 提交申报
		//if newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustHas(`//div[text()="提示"]`) {
		//}
		MustElementX(newp, `//a[contains(text(),"提交申报")]`).MustClick()
		//newp.Timeout(common.ClickTimeOut).MustElement(`#frmFrame`).MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`//a[contains(text(),"提交申报")]`).MustClick()
		utils.Sleep(3)
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='真']`).MustClick()
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='真']`).MustInput("真")
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='实']`).MustClick()
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='实']`).MustInput("实")
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='责']`).MustClick()
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='责']`).MustInput("责")
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='任']`).MustClick()
		newp.Timeout(common.ClickTimeOut).MustElementX(`//input[@placeholder='任']`).MustInput("任")

		newp.Timeout(common.ClickTimeOut).MustElementX(`//span[contains(text(),"确定")]`).MustClick()

		text := newp.Timeout(10 * common.ClickTimeOut).MustElementX(`//div[@class="gt-result-title"]`).MustText()

		path := SaveErrImg(newp, info)
		task.Result.BusinessImg = path
		task.Result.BusinessLog = text
	})
	if err != nil {
		task.Result.BusinessStatus = variable.TaxFail
		task.Result.BusinessLog = common.HandleError(ctx, err).Error()
		return
	}
}

func checkQysds20000(page *rod.Page, A200000 sb.GsTaxQuarter, curperiodFl float64) error {
	jd := math.Ceil(curperiodFl / 3)
	errMsg := ""
	for i := 0; i < 5; i++ {
		x := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[1]`)
		readonly := x.MustAttribute("readonly")
		if readonly == nil && x.MustText() == "" {
			time.Sleep(5 * time.Second)
		} else {
			break
		}
	}
	if jd > 1 && MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[1]`).MustAttribute("readonly") == nil {
		jccyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[1]`).MustText()
		if common.StrToFloat(jccyrs) != common.StrToFloat(A200000.Qccyrs1) {
			errMsg += fmt.Sprintf("一季度季初从业人数[%s]与系统[%s]不符 , ", jccyrs, A200000.Qccyrs1)
		}
		jmcyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[2]`).MustText()
		if common.StrToFloat(jmcyrs) != common.StrToFloat(A200000.Qmcyrs1) {
			errMsg += fmt.Sprintf("一季度季末从业人数[%s]与系统[%s]不符 , ", jmcyrs, A200000.Qmcyrs1)
		}

		jczcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[1]`).MustText()
		if common.StrToFloat(jczcze) != common.StrToFloat(A200000.Qczcze1) {
			errMsg += fmt.Sprintf("一季度季初资产总额(万元)[%s]与系统[%s]不符 , ", jczcze, A200000.Qczcze1)
		}
		jmzcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[2]`).MustText()
		if common.StrToFloat(jmzcze) != common.StrToFloat(A200000.Qmzcze1) {
			errMsg += fmt.Sprintf("一季度季末资产总额(万元)[%s]与系统[%s]不符 , ", jmzcze, A200000.Qmzcze1)
		}
	}

	if jd == 2 {
		jccyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[3]`).MustText()
		if common.StrToInt(jccyrs) != 0 && common.StrToFloat(jccyrs) != common.StrToFloat(A200000.Qccyrs2) {
			errMsg += fmt.Sprintf("一季度季末从业人数[%s]与系统二季度季初从业人数[%s]不符 , ", jccyrs, A200000.Qccyrs2)
		}
		jmzcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[2]`).MustText()
		if common.StrToInt(jmzcze) != 0 && common.StrToFloat(jmzcze) != common.StrToFloat(A200000.Qczcze2) {
			errMsg += fmt.Sprintf("一季度季末资产总额(万元)[%s]与系统二季度季初资产总额(万元)[%s]不符 , ", jmzcze, A200000.Qczcze2)
		}
	}

	if jd > 2 && MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[3]`).MustAttribute("readonly") == nil {
		jccyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[3]`).MustText()
		if common.StrToFloat(jccyrs) != common.StrToFloat(A200000.Qccyrs2) {
			errMsg += fmt.Sprintf("二季度季初从业人数[%s]与系统[%s]不符 , ", jccyrs, A200000.Qccyrs2)
		}
		jmcyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[4]`).MustText()
		if common.StrToFloat(jmcyrs) != common.StrToFloat(A200000.Qmcyrs2) {
			errMsg += fmt.Sprintf("二季度季末从业人数[%s]与系统[%s]不符 , ", jmcyrs, A200000.Qmcyrs2)
		}

		jczcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[3]`).MustText()
		if common.StrToFloat(jczcze) != common.StrToFloat(A200000.Qczcze2) {
			errMsg += fmt.Sprintf("二季度季初资产总额(万元)[%s]与系统[%s]不符 , ", jczcze, A200000.Qczcze2)
		}
		jmzcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[4]`).MustText()
		if common.StrToFloat(jmzcze) != common.StrToFloat(A200000.Qmzcze2) {
			errMsg += fmt.Sprintf("二季度季末资产总额(万元)[%s]与系统[%s]不符 , ", jmzcze, A200000.Qmzcze2)
		}
	}

	if jd == 3 {
		jmcyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[4]`).MustText()
		if common.StrToInt(jmcyrs) != 0 && common.StrToFloat(jmcyrs) != common.StrToFloat(A200000.Qccyrs3) {
			errMsg += fmt.Sprintf("二季度季末从业人数[%s]与系统三季度季初从业人数[%s]不符 , ", jmcyrs, A200000.Qccyrs3)
		}
		jmzcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[4]`).MustText()
		if common.StrToInt(jmzcze) != 0 && common.StrToFloat(jmzcze) != common.StrToFloat(A200000.Qczcze3) {
			errMsg += fmt.Sprintf("二季度季末资产总额(万元)[%s]与系统三季度季初资产总额(万元)[%s]不符 , ", jmzcze, A200000.Qczcze3)
		}
	}
	if jd > 3 && MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[5]`).MustAttribute("readonly") == nil {
		jccyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[5]`).MustText()
		if common.StrToFloat(jccyrs) != common.StrToFloat(A200000.Qccyrs3) {
			errMsg += fmt.Sprintf("三季度季初从业人数[%s]与系统[%s]不符 , ", jccyrs, A200000.Qccyrs3)
		}
		jmcyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[6]`).MustText()
		if common.StrToFloat(jmcyrs) != common.StrToFloat(A200000.Qmcyrs3) {
			errMsg += fmt.Sprintf("三季度季末从业人数[%s]与系统[%s]不符 , ", jmcyrs, A200000.Qmcyrs3)
		}

		jczcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[5]`).MustText()
		if common.StrToFloat(jczcze) != common.StrToFloat(A200000.Qczcze3) {
			errMsg += fmt.Sprintf("三季度季初资产总额(万元)[%s]与系统[%s]不符 , ", jczcze, A200000.Qczcze3)
		}
		jmzcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[6]`).MustText()
		if common.StrToFloat(jmzcze) != common.StrToFloat(A200000.Qmzcze3) {
			errMsg += fmt.Sprintf("三季度季末资产总额(万元)[%s]与系统[%s]不符 , ", jmzcze, A200000.Qmzcze3)
		}
	}

	if jd == 4 {
		jmcyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[6]`).MustText()
		if common.StrToInt(jmcyrs) != 0 && common.StrToFloat(jmcyrs) != common.StrToFloat(A200000.Qccyrs4) {
			errMsg += fmt.Sprintf("三季度季末从业人数[%s]与系统四季度季初从业人数[%s]不符 , ", jmcyrs, A200000.Qccyrs4)
		}
		jmzcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[6]`).MustText()
		if common.StrToInt(jmzcze) != 0 && common.StrToFloat(jmzcze) != common.StrToFloat(A200000.Qczcze4) {
			errMsg += fmt.Sprintf("三季度季末资产总额(万元)[%s]与系统四季度季初资产总额(万元)[%s]不符 , ", jmzcze, A200000.Qczcze4)
		}
	}
	if jd > 4 {
		jccyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[7]`).MustText()
		if common.StrToFloat(jccyrs) != common.StrToFloat(A200000.Qccyrs4) {
			errMsg += fmt.Sprintf("四季度季初从业人数[%s]与系统[%s]不符 , ", jccyrs, A200000.Qccyrs4)
		}
		jmcyrs := MustElementX(page, `(//td[contains(text(), "从业人数")]/..//input)[8]`).MustText()
		if common.StrToFloat(jmcyrs) != common.StrToFloat(A200000.Qmcyrs4) {
			errMsg += fmt.Sprintf("四季度季末从业人数[%s]与系统[%s]不符 , ", jmcyrs, A200000.Qmcyrs4)
		}

		jczcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[7]`).MustText()
		if common.StrToFloat(jczcze) != common.StrToFloat(A200000.Qczcze4) {
			errMsg += fmt.Sprintf("四季度季初资产总额(万元)[%s]与系统[%s]不符 , ", jczcze, A200000.Qczcze4)
		}
		jmzcze := MustElementX(page, `(//td[contains(text(), "资产总额(万元)")]/..//input)[8]`).MustText()
		if common.StrToFloat(jmzcze) != common.StrToFloat(A200000.Qmzcze4) {
			errMsg += fmt.Sprintf("四季度季末资产总额(万元)[%s]与系统[%s]不符 , ", jmzcze, A200000.Qmzcze4)
		}
	}
	if errMsg != "" {
		return taxerr.NewUserV3("季报数据不一致: "+errMsg, "请核实后重试")
	}
	return nil
}