feat: automatic access to all information

main
zggsong 2 years ago
parent 5c821745e1
commit 1123b695fc

@ -91,6 +91,10 @@ type Config struct {
MailTo []string
}
//
// HeaderUser
// @Description: Header User Model
//
type HeaderUser struct {
CompanyOwner int `json:"CompanyOwner"`
CompanyCode string `json:"CompanyCode"`
@ -109,3 +113,122 @@ type HeaderUser struct {
LoginType int `json:"LoginType"`
DataSource string `json:"DataSource"`
}
//
// LVIQuestInitModel
// @Description: 获取以前填写过的信息
//
type LVIQuestInitModel struct {
IsSuccess bool `json:"IsSuccess"`
ErrMsg string `json:"ErrMsg"`
Data LVIQuestInitModelData `json:"Data"`
}
type LVIQuestInitModelData struct {
LviImages []string `json:"LviImages"`
EpidemicQuestLVI EpidemicQuestLVI `json:"EpidemicQuestLVI"`
NoVaccineReasons []string `json:"NoVaccineReasons"`
HealthCodeColors []string `json:"HealthCodeColors"`
Contacts []interface{} `json:"Contacts"`
VaccinTypeList []string `json:"VaccinTypeList"`
VaccinType string `json:"VaccinType"`
IsLuxSan bool `json:"IsLuxSan"`
IsDongGuan bool `json:"IsDongGuan"`
IsTodaySubmit bool `json:"IsTodaySubmit"`
IsKeyDorm bool `json:"IsKeyDorm"`
DormAreas []interface{} `json:"DormAreas"`
Towns []string `json:"Towns"`
CanRefresh bool `json:"CanRefresh"`
ProvinceList []string `json:"ProvinceList"`
QuList []QuList `json:"QuList"`
IsLz bool `json:"IsLz"`
EpidemicDayConfig interface{} `json:"EpidemicDayConfig"`
}
type QuList struct {
HighAreaProvince string `json:"HighAreaProvince"`
HighAreaQu string `json:"HighAreaQu"`
}
type EpidemicQuestLVI struct {
Id string `json:"Id"`
RegistrationTime string `json:"RegistrationTime"`
CompanyCode string `json:"CompanyCode"`
CompanyName string `json:"CompanyName"`
DeptCode string `json:"DeptCode"`
DeptName string `json:"DeptName"`
Line string `json:"Line"`
Telephone string `json:"Telephone"`
EmpCode string `json:"EmpCode"`
EmpName string `json:"EmpName"`
IdentityCard string `json:"IdentityCard"`
NowAddress string `json:"NowAddress"`
Street string `json:"Street"`
IsRisk string `json:"IsRisk"`
IsWork string `json:"IsWork"`
IsRoom string `json:"IsRoom"`
IsRiskContact1 string `json:"IsRiskContact1"`
IsRiskContact2 string `json:"IsRiskContact2"`
IsDays14 string `json:"IsDays14"`
IsSymptom string `json:"IsSymptom"`
IsVaccination string `json:"IsVaccination"`
VaccinationCount int `json:"VaccinationCount"`
Contacts string `json:"Contacts"`
ResidCity string `json:"ResidCity"`
VaccineDt string `json:"VaccineDt"`
VaccineDt2 string `json:"VaccineDt2"`
VaccineDt3 string `json:"VaccineDt3"`
NoVaccineReason string `json:"NoVaccineReason"`
HealthCodeColor string `json:"HealthCodeColor"`
IsDisabled bool `json:"IsDisabled"`
Image1 string `json:"Image1"`
Image2 string `json:"Image2"`
Image3 string `json:"Image3"`
IsOutSidePerson bool `json:"IsOutSidePerson"`
IsNewPerson bool `json:"IsNewPerson"`
VaccinType string `json:"VaccinType"`
Temperature string `json:"Temperature"`
IsGtPerson string `json:"IsGtPerson"`
GtAddress string `json:"GtAddress"`
GtShenzhenTime string `json:"GtShenzhenTime"`
GtDongguanTime string `json:"GtDongguanTime"`
StartCitys string `json:"StartCitys"`
IsStart string `json:"IsStart"`
JianKangColor string `json:"JianKangColor"`
IsPhoneSame string `json:"IsPhoneSame"`
UpPhone string `json:"UpPhone"`
IsOCR bool `json:"IsOCR"`
OCRTime string `json:"OCRTime"`
ErrMsg string `json:"ErrMsg"`
DormArea string `json:"DormArea"`
DormBuilding string `json:"DormBuilding"`
DormRoom string `json:"DormRoom"`
IsDoor bool `json:"IsDoor"`
IsDoorRecover bool `json:"IsDoorRecover"`
DoorRecoverTime string `json:"DoorRecoverTime"`
DoorRecoverMsg string `json:"DoorRecoverMsg"`
IsSanDoor bool `json:"IsSanDoor"`
SanLZCode string `json:"SanLZCode"`
IsSanDoorRecover bool `json:"IsSanDoorRecover"`
SanDoorRecoverTime string `json:"SanDoorRecoverTime"`
ByCity string `json:"ByCity"`
Latitude string `json:"Latitude"`
Longitude string `json:"Longitude"`
RegistLocal string `json:"RegistLocal"`
EmpDormRoom string `json:"EmpDormRoom"`
IsXinGuanHistory string `json:"IsXinGuanHistory"`
HistoryDate string `json:"HistoryDate"`
IsForeigner string `json:"IsForeigner"`
IsEntry string `json:"IsEntry"`
EntryDate string `json:"EntryDate"`
IsTravelToShangHai string `json:"IsTravelToShangHai"`
IsEntryBefor bool `json:"IsEntryBefor"`
EnteryBeforeResultNG bool `json:"EnteryBeforeResultNG"`
EntryBeforeNGRemark string `json:"EntryBeforeNGRemark"`
EpiFlag bool `json:"EpiFlag"`
EpiDay string `json:"EpiDay"`
EpiCheck string `json:"EpiCheck"`
IsOnJob bool `json:"IsOnJob"`
OnJobDate string `json:"OnJobDate"`
IsCheckHSOk bool `json:"IsCheckHSOk"`
FengXianDiId string `json:"FengXianDiId"`
}

@ -10,6 +10,7 @@ import (
"luxshare-daily-report/util"
"net/http"
"net/url"
"strconv"
"strings"
)
@ -36,14 +37,14 @@ func Login(userName, passwd string) (string, string, error) {
resp, err := http.Post(loginUrl, contentType, strings.NewReader(postData.Encode()))
defer resp.Body.Close()
if err != nil {
return "", "", errors.New(fmt.Sprintf("[ERROR] (Login) Request Error: %v", err))
return "", "", errors.New(fmt.Sprintf("(Login) Request Error: %v", err))
}
body, _ := ioutil.ReadAll(resp.Body)
//fmt.Println(string(body))
var loginModel model.LoginResp
err = json.Unmarshal(body, &loginModel)
if err != nil {
return "", "", errors.New(fmt.Sprintf("[ERROR] (Login) Resp Json Unmarshal Error: %v", err))
return "", "", errors.New(fmt.Sprintf("(Login) Resp Json Unmarshal Error: %v", err))
}
//失败
if !loginModel.IsSuccess {
@ -54,7 +55,7 @@ func Login(userName, passwd string) (string, string, error) {
data, user := model.LoginRespData{}, model.UserInfo{}
if loginModel.Data == data || loginModel.Data.UserInfo == user {
err = errors.New(fmt.Sprintf("[ERROR] Login not return user information"))
err = errors.New(fmt.Sprintf("Login not return user information"))
return ticket, "", err
}
userStr := convert(loginModel.Data.UserInfo)
@ -107,7 +108,7 @@ func Upload2Azure(auth, user string, images map[string]string) ([]string, error)
request, err := http.NewRequest("POST", uploadUrl, strings.NewReader(postData.Encode()))
if err != nil {
return nil, errors.New(fmt.Sprintf("[ERROR] (Upload2Azure) Error creating upload request: %v", err))
return nil, errors.New(fmt.Sprintf("(Upload2Azure) Error creating upload request: %v", err))
}
request.Header.Set("Content-Type", contentType)
request.Header.Set("__user__", user)
@ -115,7 +116,7 @@ func Upload2Azure(auth, user string, images map[string]string) ([]string, error)
resp, err := client.Do(request)
if err != nil {
return nil, errors.New(fmt.Sprintf("[ERROR] (Upload2Azure) Request Error: %v", err))
return nil, errors.New(fmt.Sprintf("(Upload2Azure) Request Error: %v", err))
}
//resp, err := http.Post(uploadUrl, contentType, strings.NewReader(postData.Encode()))
defer resp.Body.Close()
@ -124,11 +125,46 @@ func Upload2Azure(auth, user string, images map[string]string) ([]string, error)
var uploadModel model.Upload2AzureResp
err = json.Unmarshal(body, &uploadModel)
if err != nil {
return nil, errors.New(fmt.Sprintf("[ERROR] (Upload2Azure) Resp Json Unmarshal Error: %v", err))
return nil, errors.New(fmt.Sprintf("(Upload2Azure) Resp Json Unmarshal Error: %v", err))
}
return uploadModel.Data.ImagePaths, nil
}
//
// GetLVIQuestInitModel
// @Description: 获取以往个人信息
// @param auth
// @param user
// @return model.LVIQuestInitModelData
// @return error
//
func GetLVIQuestInitModel(auth, user string) (model.EpidemicQuestLVI, error) {
var nilModel model.EpidemicQuestLVI
var client = &http.Client{}
url := "https://m.luxshare-ict.com/api/EpidemicSys/EpidemicRegistration/LVIQuestInit"
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return nilModel, errors.New(fmt.Sprintf("(GetLVIQuestInitModel) Error creating request: %v", err))
}
request.Header.Set("__user__", user)
request.Header.Set("Authorization", fmt.Sprintf("BaseAuth %v", auth))
resp, err := client.Do(request)
if err != nil {
return nilModel, errors.New(fmt.Sprintf("(GetLVIQuestInitModel) Request Error: %v", err))
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var livModel model.LVIQuestInitModel
err = json.Unmarshal(body, &livModel)
if err != nil {
return nilModel, errors.New(fmt.Sprintf("(GetLVIQuestInitModel) Resp Json Unmarshal Error: %v", err))
}
return livModel.Data.EpidemicQuestLVI, nil
}
//
// EpidemicRegistration
// @Description: 申报
@ -136,54 +172,54 @@ func Upload2Azure(auth, user string, images map[string]string) ([]string, error)
// @param images
// @return error
//
func EpidemicRegistration(auth, user string, images []string) error {
func EpidemicRegistration(auth, user string, images []string, data model.EpidemicQuestLVI) error {
var client = &http.Client{}
uploadUrl := "https://m.luxshare-ict.com/api/EpidemicSys/EpidemicRegistration/LVIQuestSave2"
contentType := "application/x-www-form-urlencoded"
postData := url.Values{}
postData.Add("nowAddress", "鑫河湾")
postData.Add("street", "锦溪镇")
postData.Add("isRisk", "否")
postData.Add("isWork", "是")
postData.Add("isRoom", "否")
postData.Add("isRiskContact1", "否")
postData.Add("isRiskContact2", "否")
postData.Add("isDays14", "否")
postData.Add("isSymptom", "否")
postData.Add("isVaccination", "是")
postData.Add("vaccinationCount", "3")
postData.Add("nowAddress", data.NowAddress)
postData.Add("street", data.Street)
postData.Add("isRisk", data.IsRisk)
postData.Add("isWork", data.IsWork)
postData.Add("isRoom", data.IsRoom)
postData.Add("isRiskContact1", data.IsRiskContact1)
postData.Add("isRiskContact2", data.IsRiskContact2)
postData.Add("isDays14", data.IsDays14)
postData.Add("isSymptom", data.IsSymptom)
postData.Add("isVaccination", data.IsVaccination)
postData.Add("vaccinationCount", strconv.Itoa(data.VaccinationCount))
postData.Add("imagePaths[]", images[0])
postData.Add("imagePaths[]", images[1])
postData.Add("residCity", "江苏省+苏州市+昆山市")
postData.Add("vaccineDt", "2021/05/13")
postData.Add("vaccineDt2", "2021/06/11")
postData.Add("vaccineDt3", "2021/12/18")
postData.Add("noVaccineReason", "")
postData.Add("healthCodeColor", "绿色")
postData.Add("vaccinType", "三针型")
postData.Add("temperature", "")
postData.Add("isGtPerson", "")
postData.Add("gtAddress", "")
postData.Add("gtShenzhenTime", "")
postData.Add("gtDongguanTime", "")
postData.Add("dormArea", "")
postData.Add("dormBuilding", "")
postData.Add("dormRoom", "")
postData.Add("byCity", "江苏省苏州市")
postData.Add("latitude", "31.17725")
postData.Add("longitude", "120.9165")
postData.Add("registLocal", "江苏省苏州市昆山市学苑路")
postData.Add("isXinGuanHistory", "")
postData.Add("historyDate", "")
postData.Add("isForeigner", "")
postData.Add("isEntry", "")
postData.Add("entryDate", "")
postData.Add("isTravelToShangHai", "")
postData.Add("residCity", data.ResidCity)
postData.Add("vaccineDt", data.VaccineDt[:10])
postData.Add("vaccineDt2", data.VaccineDt2[:10])
postData.Add("vaccineDt3", data.VaccineDt3[:10])
postData.Add("noVaccineReason", data.NoVaccineReason)
postData.Add("healthCodeColor", data.HealthCodeColor)
postData.Add("vaccinType", data.VaccinType)
postData.Add("temperature", data.Temperature)
postData.Add("isGtPerson", data.IsGtPerson)
postData.Add("gtAddress", data.GtAddress)
postData.Add("gtShenzhenTime", data.GtShenzhenTime)
postData.Add("gtDongguanTime", data.GtDongguanTime)
postData.Add("dormArea", data.DormArea)
postData.Add("dormBuilding", data.DormBuilding)
postData.Add("dormRoom", data.DormRoom)
postData.Add("byCity", data.ByCity)
postData.Add("latitude", data.Latitude)
postData.Add("longitude", data.Longitude)
postData.Add("registLocal", data.RegistLocal)
postData.Add("isXinGuanHistory", data.IsXinGuanHistory)
postData.Add("historyDate", data.HistoryDate)
postData.Add("isForeigner", data.IsForeigner)
postData.Add("isEntry", data.IsEntry)
postData.Add("entryDate", data.EntryDate)
postData.Add("isTravelToShangHai", data.IsTravelToShangHai)
request, err := http.NewRequest("POST", uploadUrl, strings.NewReader(postData.Encode()))
if err != nil {
return errors.New(fmt.Sprintf("[ERROR] (EpidemicRegistration) Error creating upload request: %v", err))
return errors.New(fmt.Sprintf("(EpidemicRegistration) Error creating upload request: %v", err))
}
request.Header.Set("Content-Type", contentType)
request.Header.Set("__user__", user)
@ -193,18 +229,18 @@ func EpidemicRegistration(auth, user string, images []string) error {
defer resp.Body.Close()
if err != nil {
return errors.New(fmt.Sprintf("[ERROR] (EpidemicRegistration) Request Error: %v", err))
return errors.New(fmt.Sprintf("(EpidemicRegistration) Request Error: %v", err))
}
body, _ := ioutil.ReadAll(resp.Body)
var epidemicRegistrationModel model.UniverseResp
err = json.Unmarshal(body, &epidemicRegistrationModel)
if err != nil {
return errors.New(fmt.Sprintf("[ERROR] (EpidemicRegistration) Resp Json Unmarshal Error: %v", err))
return errors.New(fmt.Sprintf("(EpidemicRegistration) Resp Json Unmarshal Error: %v", err))
}
if !epidemicRegistrationModel.IsSuccess {
return errors.New(fmt.Sprintf("[ERROR] (EpidemicRegistration) Resp ErrMsg: %v", epidemicRegistrationModel.ErrMsg))
return errors.New(fmt.Sprintf("(EpidemicRegistration) Resp ErrMsg: %v", epidemicRegistrationModel.ErrMsg))
}
return nil
}
@ -221,7 +257,7 @@ func RefreshDoor(auth, user string) error {
request, err := http.NewRequest("POST", refreshUrl, nil)
if err != nil {
return errors.New(fmt.Sprintf("[ERROR] (RefreshDoor) Error creating upload request: %v", err))
return errors.New(fmt.Sprintf("(RefreshDoor) Error creating upload request: %v", err))
}
request.Header.Set("__user__", user)
request.Header.Set("Authorization", fmt.Sprintf("BaseAuth %v", auth))
@ -230,18 +266,18 @@ func RefreshDoor(auth, user string) error {
defer resp.Body.Close()
if err != nil {
return errors.New(fmt.Sprintf("[ERROR] (RefreshDoor) Request Error: %v", err))
return errors.New(fmt.Sprintf("(RefreshDoor) Request Error: %v", err))
}
body, _ := ioutil.ReadAll(resp.Body)
var refreshDoorResp model.UniverseResp
err = json.Unmarshal(body, &refreshDoorResp)
if err != nil {
return errors.New(fmt.Sprintf("[ERROR] (RefreshDoor) Resp Json Unmarshal Error: %v", err))
return errors.New(fmt.Sprintf("(RefreshDoor) Resp Json Unmarshal Error: %v", err))
}
if !refreshDoorResp.IsSuccess {
return errors.New(fmt.Sprintf("[ERROR] (RefreshDoor) Resp ErrMsg: %v", refreshDoorResp.ErrMsg))
return errors.New(fmt.Sprintf("(RefreshDoor) Resp ErrMsg: %v", refreshDoorResp.ErrMsg))
}
return nil
}

@ -93,9 +93,9 @@ https://github.com/zggsong`))
//
func DeclarationService(files map[string]string) {
//登陆获取auth
ticket, userStr, err := core.Login(global.GLO_CONFIG.UserName, global.GLO_CONFIG.PassWord)
if ticket == "" || err != nil {
log.Errorf("Ticket: %v, err:%v", ticket, err.Error())
auth, __user__, err := core.Login(global.GLO_CONFIG.UserName, global.GLO_CONFIG.PassWord)
if auth == "" || err != nil {
log.Errorf("Ticket: %v, err:%v", auth, err.Error())
util.SendMessageError(err)
return
}
@ -108,7 +108,7 @@ func DeclarationService(files map[string]string) {
resJkm := base64.StdEncoding.EncodeToString(srcJkm)
m["xcm"] = resXcm
m["jkm"] = resJkm
imagesLinks, err := core.Upload2Azure(ticket, userStr, m)
imagesLinks, err := core.Upload2Azure(auth, __user__, m)
//log.Printf("[DEBUG] get images links: %s", imagesLinks)
if err != nil {
log.Errorf(err.Error())
@ -116,15 +116,21 @@ func DeclarationService(files map[string]string) {
return
}
if imagesLinks == nil {
err = errors.New("[ERROR] Get no images links")
err = errors.New("get no images links")
log.Errorf(err.Error())
util.SendMessageError(err)
return
}
//TODO: if model is nil
epidemicQuestLVIData, err := core.GetLVIQuestInitModel(auth, __user__)
if err != nil {
log.Errorf("获取个人初始化信息失败: %v", err.Error())
}
//申报
for i := 0; i < 3; i++ {
err = core.EpidemicRegistration(ticket, userStr, imagesLinks)
err = core.EpidemicRegistration(auth, __user__, imagesLinks, epidemicQuestLVIData)
if err != nil && i > 1 {
log.Errorf("重试3次失败%v", err.Error())
util.SendMessageError(err)
@ -134,11 +140,11 @@ func DeclarationService(files map[string]string) {
}
}
log.Infof("[INFO] 每日申报成功")
log.Infof("每日申报成功")
//刷新门禁
for i := 0; i < 3; i++ {
err = core.RefreshDoor(ticket, userStr)
err = core.RefreshDoor(auth, __user__)
if err != nil && i > 1 {
log.Errorf("重试3次失败%v", err.Error())
util.SendMessageError(err)
@ -147,7 +153,7 @@ func DeclarationService(files map[string]string) {
break
}
}
log.Infof("[INFO] 刷新门禁成功")
log.Infof("刷新门禁成功")
util.SendSuccess("【成功】每日申报、刷新门禁")
}

Loading…
Cancel
Save