@ -0,0 +1,89 @@ | |||
package wxfunc | |||
import ( | |||
"crypto/sha1" | |||
"encoding/json" | |||
"fmt" | |||
"errors" | |||
"github.com/xlstudio/wxbizdatacrypt" | |||
"net/http" | |||
) | |||
/** | |||
* 常量 | |||
* @param appid string 小程序的appid | |||
*/ | |||
const appId = "wxe0d79550e7f33316" | |||
const secret = "2bb0e3104b315def0db87c131bbc351f" | |||
//加密数据解密算法 | |||
/** | |||
* 检验数据的真实性,并且获取解密后的明文. | |||
* @param encryptedData string 加密的用户数据 | |||
* @param iv string 与用户数据一同返回的初始向量 | |||
* @param sessionKey string 与用户数据一同返回的初始向量 | |||
* | |||
* @return map type. | |||
*/ | |||
func DecryptData(encryptedData string, iv string, sessionKey string) (interface{}, error) { | |||
pc := wxbizdatacrypt.WxBizDataCrypt{AppId: appId, SessionKey: sessionKey} | |||
result, err := pc.Decrypt(encryptedData, iv, true) //第三个参数解释: 需要返回 JSON 数据类型时 使用 true, 需要返回 map 数据类型时 使用 false | |||
if err != nil { | |||
return nil, err | |||
} | |||
return result, nil | |||
} | |||
type WXLoginResp struct { | |||
OpenId string `json:"openid"` | |||
SessionKey string `json:"session_key"` | |||
UnionId string `json:"unionid"` | |||
ErrCode int `json:"errcode"` | |||
ErrMsg string `json:"errmsg"` | |||
} | |||
// 这个函数以 code 作为输入, 返回调用微信接口得到的对象指针和异常情况 | |||
func WXLogin(code string) (*WXLoginResp, error) { | |||
url := "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code" | |||
// 合成url, 这里的appId和secret是在微信公众平台上获取的 | |||
url = fmt.Sprintf(url, appId, secret, code) | |||
// 创建http get请求 | |||
resp,err := http.Get(url) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer resp.Body.Close() | |||
// 解析http请求中body 数据到我们定义的结构体中 | |||
wxResp := WXLoginResp{} | |||
decoder := json.NewDecoder(resp.Body) | |||
if err := decoder.Decode(&wxResp); err != nil { | |||
return nil, err | |||
} | |||
// 判断微信接口返回的是否是一个异常情况 | |||
if wxResp.ErrCode != 0 { | |||
return nil, errors.New(fmt.Sprintf("ErrCode:%s ErrMsg:%s", wxResp.ErrCode, wxResp.ErrMsg)) | |||
} | |||
return &wxResp, nil | |||
} | |||
// 校验微信返回的用户数据 | |||
func ValidateUserInfo(rawData, sessionKey, signature string) bool { | |||
signature2 := GetSha1(rawData + sessionKey) | |||
return signature == signature2 | |||
} | |||
// SHA-1 加密 | |||
func GetSha1(str string) string { | |||
data := []byte(str) | |||
has := sha1.Sum(data) | |||
res := fmt.Sprintf("%x", has) //将[]byte转成16进制 | |||
return res | |||
} |
@ -0,0 +1,130 @@ | |||
package wxSmall | |||
import ( | |||
"SSW_WebPlatform/utils" | |||
"SSW_WebPlatform/web/middleware/glog" | |||
"SSW_WebPlatform/web/models" | |||
"SSW_WebPlatform/web/models/wxSmall" | |||
"SSW_WebPlatform/web/supports" | |||
"github.com/kataras/iris/v12" | |||
"strings" | |||
"time" | |||
) | |||
//查询楼栋信息 | |||
func GetBuildings(ctx iris.Context) { | |||
me := new(models.Buildingtab) | |||
me.Cid, _ = ctx.URLParamInt("cid") | |||
if utils.ValueIsEmpty(me.Cid) { | |||
supports.Error(ctx, iris.StatusBadRequest, "项目编号不能为空!", nil) | |||
return | |||
} | |||
result, err := me.SelectAll() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) | |||
return | |||
} | |||
supports.Ok(ctx, supports.OptionSuccess, result) | |||
} | |||
//查询调查问卷 | |||
func GetWxCSurveysheet(ctx iris.Context) { | |||
me := new(models.CSurveysheet) | |||
me.Cid, _ = ctx.URLParamInt("cid") | |||
me.Cnr, _ = ctx.URLParamInt("cid") | |||
me.Surveysheetid = ctx.URLParam("surveysheetid") | |||
result, err := me.WxSelectOne() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) | |||
return | |||
} | |||
//查询缓存 | |||
wx := new(wxSmall.WxUserCache) | |||
wx.Cid, _ = ctx.URLParamInt("cid") | |||
wx.Uid, _ = ctx.URLParamInt("uid") | |||
wx.Surveysheetid = ctx.URLParam("surveysheetid") | |||
data, err := wx.SelectCacheInfo() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) | |||
return | |||
} | |||
cache := make(map[string]wxSmall.WxCacheSurveysheetResultlst) | |||
for _, v := range data { | |||
key := strings.TrimSpace(v.Subjectid) | |||
value := v | |||
cache[key] = value | |||
} | |||
for kk, vv := range result.Valst { | |||
key := strings.TrimSpace(vv.Subjectid) | |||
val, ok := cache[key] | |||
if ok { | |||
result.Valst[kk].QuestionNaireItem.Subjectid = val.Subjectid | |||
result.Valst[kk].QuestionNaireItem.Optioninput = val.Optioninput | |||
result.Valst[kk].QuestionNaireItem.Selected_options = val.SelectedOptions | |||
} | |||
} | |||
supports.Ok(ctx, supports.OptionSuccess, result) | |||
} | |||
//提交试卷 | |||
func InsertWXCSurveysheetResult(ctx iris.Context) { | |||
data := new(models.CSurveysheetResult) | |||
if err := ctx.ReadJSON(data); err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, "json解析错误", nil) | |||
return | |||
} | |||
data.Lastmodifyby = "wx" | |||
data.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") | |||
data.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") | |||
err := data.Add() | |||
if err != nil { | |||
glog.InfoExt("问题调研", "add err is :", err) | |||
supports.Error(ctx, iris.StatusBadRequest, "添加失败!", nil) | |||
return | |||
} | |||
//删除缓存 | |||
cache := new(wxSmall.WxUserCache) | |||
cache.Uid = data.Uid | |||
cache.Surveysheetid = data.Surveysheetid | |||
cache.Cid = data.Cid | |||
cache.DelCache() | |||
supports.Ok(ctx, supports.OptionSuccess, "") | |||
} | |||
//缓存试卷 | |||
func AddWxCacheSurveysheetResult(ctx iris.Context) { | |||
var data models.CSurveysheetResult | |||
if err := ctx.ReadJSON(&data); err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, "json解析错误", nil) | |||
return | |||
} | |||
//第一步:查询缓存用户关联表,有就更新,没有就插入 | |||
cache := new(wxSmall.WxUserCache) | |||
cache.Uid = data.Uid | |||
cache.Surveysheetid = data.Surveysheetid | |||
cache.Cid = data.Cid | |||
cache.Status = 0 | |||
cache.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") | |||
cache.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") | |||
_, err := cache.LoadInfo() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, "查询缓存失败", nil) | |||
return | |||
} | |||
//第二步:题目信息,插入缓存表里,有就更新,没有就插入 | |||
wxsurvey := new(wxSmall.WxCacheSurveysheetResult) | |||
wxsurvey.Lastmodifyby = "wx" | |||
wxsurvey.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") | |||
wxsurvey.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") | |||
wxsurvey.Surveynr = data.Surveynr | |||
wxsurvey.Uid = data.Uid | |||
err = wxsurvey.Add(data) | |||
if err != nil { | |||
glog.InfoExt("问题调研", "add err is :", err) | |||
supports.Error(ctx, iris.StatusBadRequest, "添加失败!", nil) | |||
return | |||
} | |||
supports.Ok(ctx, supports.OptionSuccess, "") | |||
} |
@ -0,0 +1,140 @@ | |||
package wxSmall | |||
import ( | |||
"SSW_WebPlatform/utils" | |||
"SSW_WebPlatform/utils/wxfunc" | |||
"SSW_WebPlatform/web/models" | |||
"SSW_WebPlatform/web/models/wxSmall" | |||
"SSW_WebPlatform/web/supports" | |||
"fmt" | |||
"github.com/kataras/iris/v12" | |||
"time" | |||
) | |||
//微信授权登录 | |||
func Wxlogin(ctx iris.Context) { | |||
data := new(wxSmall.UserData) | |||
if err := ctx.ReadJSON(data); err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, "json解析错误", nil) | |||
return | |||
} | |||
//code := data.Code // 获取code | |||
// 根据code获取 openID 和 session_key | |||
//wxLoginResp, err := wxfunc.WXLogin(code) | |||
//if err != nil { | |||
// supports.Error(ctx, iris.StatusBadRequest, "获取session_key失败", nil) | |||
// return | |||
//} | |||
//判断数据库里用户表是否存在此用户 | |||
user := new(wxSmall.WxUser) | |||
//user.Openid = wxLoginResp.OpenId | |||
user.Openid = "123456" | |||
wxuser, err := user.SelectOneByOpenid() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) | |||
return | |||
} | |||
if wxuser == nil { | |||
//添加信息 | |||
//userInfo, err := wxfunc.DecryptData(data.EncryptedData,data.Iv,wxLoginResp.SessionKey) | |||
//if err != nil { | |||
// supports.Error(ctx, iris.StatusBadRequest, "数据解密失败", nil) | |||
// return | |||
//} | |||
//Info := userInfo.(map[string]interface{}) | |||
//user.Nickname = utils.ValueToString(Info["nickName"],"") | |||
//user.Gender = utils.ValueToInt(Info["gender"],0) | |||
//user.Avatarurl = utils.ValueToString(Info["avatarUrl"],"") | |||
//user.Province = utils.ValueToString(Info["province"],"") | |||
//user.City =utils.ValueToString(Info["city"],"") | |||
//user.Country =utils.ValueToString(Info["country"],"") | |||
//user.Sessionkey = wxLoginResp.SessionKey | |||
//user.Openid = wxLoginResp.OpenId | |||
//user.Unionid = wxLoginResp.UnionId | |||
user.Gender = 1 | |||
user.Nickname = "风云争霸" | |||
user.Sessionkey = "123456" | |||
user.Openid = "123456" | |||
user.Unionid = "123456" | |||
err = user.Add() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, "用户信息录入失败", nil) | |||
return | |||
} | |||
wxuser, err = user.SelectOneByOpenid() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, "用户信息查询失败", nil) | |||
return | |||
} | |||
} else { | |||
ok := wxfunc.ValidateUserInfo(data.RawData, wxuser.Sessionkey, data.Signatrue) | |||
if !ok { | |||
//过期,更新 | |||
user.Uid = wxuser.Uid | |||
//user.Sessionkey = wxLoginResp.SessionKey | |||
user.Sessionkey = "123456" | |||
err = user.Update() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, "用户信息更新失败", nil) | |||
return | |||
} | |||
} | |||
} | |||
supports.Ok(ctx, supports.OptionSuccess, wxuser) | |||
} | |||
//查询是否已经做过调查 | |||
func WxCheckResult(ctx iris.Context) { | |||
cache := new(wxSmall.WxUserCache) | |||
cache.Cid, _ = ctx.URLParamInt("cid") | |||
cache.Uid, _ = ctx.URLParamInt("uid") | |||
cache.Surveysheetid = ctx.URLParam("surveysheetid") | |||
ok, err := cache.SelectResultInfo() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) | |||
return | |||
} | |||
if ok { | |||
supports.Ok(ctx, supports.OptionSuccess, true) | |||
} else { | |||
supports.Ok(ctx, supports.OptionSuccess, false) | |||
} | |||
} | |||
//判断二维码是否过期 | |||
func WxCheckBarcode(ctx iris.Context) { | |||
me := new(models.CSurveysheet) | |||
me.Cid, _ = ctx.URLParamInt("cid") | |||
me.Cnr, _ = ctx.URLParamInt("cid") | |||
lenDays, _ := ctx.URLParamInt("lenDays") | |||
me.Surveysheetid = ctx.URLParam("surveysheetid") | |||
result, err := me.SelectInfo() | |||
if err != nil { | |||
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) | |||
return | |||
} | |||
fmt.Println(result) | |||
if utils.ValueIsEmpty(result.Surveydate) { | |||
supports.Ok(ctx, supports.OptionSuccess, "没有设置调研时间!") | |||
return | |||
} | |||
nowDate := time.Now() | |||
begDate,_ := utils.TimeParseyyyyMMdd(result.Surveydate) | |||
endDate := begDate.AddDate(0,0,lenDays) | |||
//判断 | |||
if nowDate.Before(begDate){ | |||
supports.Ok(ctx, supports.OptionSuccess, "未开始") | |||
} | |||
if nowDate.After(begDate) && nowDate.Before(endDate){ | |||
supports.Ok(ctx, supports.OptionSuccess, "未过期") | |||
} else { | |||
supports.Ok(ctx, supports.OptionSuccess, "已过期") | |||
} | |||
} |
@ -0,0 +1,285 @@ | |||
// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved. | |||
package wxSmall | |||
import ( | |||
"SSW_WebPlatform/db" | |||
"SSW_WebPlatform/utils" | |||
"SSW_WebPlatform/web/middleware/glog" | |||
"SSW_WebPlatform/web/models" | |||
"strings" | |||
"time" | |||
"xorm.io/core" | |||
) | |||
type WxCacheSurveysheetResult struct { | |||
Cid int `json:"cid" xorm:"not null pk comment('公司ID') INT(11)"` | |||
Cnr int `json:"cnr" xorm:"not null pk comment('小区编号') INT(11)"` | |||
Surveysheetid string `json:"surveysheetid" xorm:"not null pk VARCHAR(40)"` | |||
Surveynr int `json:"surveynr" xorm:"not null pk comment('调研问卷流水号') INT(11)"` | |||
Uid int `json:"uid" xorm:"not NULL pk INT(10)"` | |||
Room string `json:"room" xorm:"default 'NULL' VARCHAR(32)"` | |||
Unit string `json:"unit" xorm:"default 'NULL' VARCHAR(32)"` | |||
Buildingid string `json:"buildingid" xorm:"default 'NULL' VARCHAR(32)"` | |||
Surveyperson string `json:"surveyperson" xorm:"default 'NULL' comment('指定调研人') VARCHAR(40)"` | |||
Surveysamplecount int `json:"surveysamplecount" xorm:"not null comment('调研取样数') INT(11)"` | |||
Surveyfinishedcount int `json:"surveyfinishedcount" xorm:"not null comment('调研问卷实际已完成数') INT(11)"` | |||
Planstartdate string `json:"planstartdate" xorm:"default '''' VARCHAR(20)"` | |||
Planendate string `json:"planendate" xorm:"default '''' VARCHAR(20)"` | |||
Actstartdate string `json:"actstartdate" xorm:"default '''' VARCHAR(20)"` | |||
Actenddate string `json:"actenddate" xorm:"default '''' VARCHAR(20)"` | |||
Status int `json:"status" xorm:"not null comment('状态') INT(11)"` | |||
Remark string `json:"remark" xorm:"default 'NULL' comment('备注') VARCHAR(255)"` | |||
Signature string `json:"signature" xorm:"default 'NULL' comment('电子签名') VARCHAR(255)"` | |||
Createtime string `json:"createtime" xorm:"default '''' comment('创建时间') VARCHAR(40)"` | |||
Lastmodifytime string `json:"lastmodifytime" xorm:"default '''' comment('最近更新时间') VARCHAR(40)"` | |||
Lastmodifyby string `json:"lastmodifyby" xorm:"default 'NULL' comment('修改人员') VARCHAR(40)"` | |||
Sex string `json:"sex" xorm:"default '''' comment('被访问者性别 male 和female') VARCHAR(10)"` | |||
Persontype int `json:"persontype" xorm:"default NULL comment('被访问者类型 业主1 租户2') TINYINT(1)"` | |||
Age int `json:"age" xorm:"default NULL comment('被访问者年龄 1-22岁以下 2-22到59岁 3-60岁以上') TINYINT(1)"` | |||
Livetime int `json:"livetime" xorm:"default NULL comment('被访问者居住时间 1-1年以内 2-1到3年 2-3到5年 3-5年以上') TINYINT(1)"` | |||
Personname string `json:"personname" xorm:"default '''' comment('被访问者姓名') VARCHAR(40)"` | |||
Valst []WxCacheSurveysheetResultlst `json:"valst" xorm:"-"` | |||
} | |||
/******数据表名******/ | |||
func (t *WxCacheSurveysheetResult) TableName() string { | |||
return "wx_cache_surveysheet_result" | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据添加 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResult) Add(data models.CSurveysheetResult) error { | |||
engine := db.MasterEngine() | |||
session := engine.NewSession() | |||
defer session.Close() | |||
// add Begin() before any action | |||
err := session.Begin() | |||
if err != nil { | |||
return err | |||
} | |||
//查询信息 | |||
subject := new(models.CSurveysheet) | |||
subject.Cid = data.Cid | |||
subject.Surveysheetid = data.Surveysheetid | |||
subject.Cnr = data.Cnr | |||
_, err = engine.Table("c_surveysheet").ID(core.PK{subject.Cid, subject.Cnr, subject.Surveysheetid}).Get(subject) | |||
if err != nil { | |||
session.Rollback() | |||
return err | |||
} | |||
//判断是否已经添加缓存 | |||
cache := new(WxCacheSurveysheetResult) | |||
ok,err := session.Table("wx_cache_surveysheet_result").Where("cid =? and uid = ? and surveysheetid = ?", t.Cid, t.Uid, t.Surveysheetid).Get(cache) | |||
if err != nil { | |||
session.Rollback() | |||
return err | |||
} | |||
surveynr := 0 | |||
if ok{ | |||
//更新 | |||
surveynr = data.Surveynr | |||
}else{ | |||
snr := new(models.Snrtab) | |||
snr.Cid = data.Cid | |||
id, err := snr.GetNextSnr("Cachenr") | |||
if err != nil { | |||
session.Rollback() | |||
return err | |||
} | |||
surveynr = utils.ValueToInt(id, 0) | |||
//添加答题 | |||
Survey := new(WxCacheSurveysheetResult) | |||
Survey.Surveyperson = subject.Surveyperson | |||
Survey.Surveysamplecount = subject.Surveysamplecount | |||
Survey.Surveyfinishedcount = subject.Surveyfinishedcount | |||
Survey.Cid = data.Cid | |||
Survey.Cnr = data.Cnr | |||
Survey.Uid = t.Uid | |||
Survey.Surveysheetid = data.Surveysheetid | |||
Survey.Buildingid = data.Buildingid | |||
Survey.Unit = data.Unit | |||
Survey.Room = data.Room | |||
Survey.Surveynr = surveynr | |||
Survey.Remark = data.Remark | |||
Survey.Signature = data.Signature | |||
Survey.Planstartdate = data.Planstartdate | |||
Survey.Planendate = data.Planendate | |||
Survey.Actenddate = utils.TimeFormat(time.Now(), "yyyy-MM-dd HH:mm:ss") | |||
//查询是否存在, | |||
_, err = session.Table("wx_cache_surveysheet_result").Insert(Survey) | |||
if err != nil { | |||
glog.InfoExt("问题调研", "添加题目 err1 is :", err) | |||
session.Rollback() | |||
return err | |||
} | |||
} | |||
//记录答案 | |||
for _, v := range data.Valst { | |||
//查询答案分值 | |||
datalist := make([]models.CSurveysheetOptionlst, 0) | |||
SelectedOptions := strings.Split(v.SelectedOptions, ",") | |||
glog.InfoExt("问题调研", "添加问题 SelectedOptionsis :", SelectedOptions) | |||
err = engine.Table("c_surveysheet_optionlst").Where("cid = ? and subjectid = ?", data.Cid, v.Subjectid).In("optionid", SelectedOptions).Find(&datalist) | |||
glog.InfoExt("问题调研", "添加问题 datalist :", datalist) | |||
for _, vv := range datalist { | |||
//判断是否已经添加缓存 | |||
cachelst := new(WxCacheSurveysheetResultlst) | |||
ok,err := session.Table("wx_cache_surveysheet_resultlst").Where("cid =? and uid = ? and surveysheetid = ? and surveynr = ? and subjectid = ?", t.Cid, t.Uid, t.Surveysheetid,surveynr,vv.Subjectid).Get(cachelst) | |||
if err != nil { | |||
session.Rollback() | |||
return err | |||
} | |||
if ok{ | |||
//更新 | |||
subject := new(WxCacheSurveysheetResultlst) | |||
subject.Cid = data.Cid | |||
subject.Cnr = data.Cnr | |||
subject.Uid = t.Uid | |||
subject.Subjectid = vv.Subjectid | |||
subject.Surveynr = surveynr | |||
subject.Surveysheetid = data.Surveysheetid | |||
subject.Status = v.Status | |||
subject.SelectedOptions = vv.Optionid | |||
subject.Assessmentvalue = vv.Optionvalue | |||
subject.Remark = v.Remark | |||
subject.Optiontype = vv.Optiontype | |||
subject.Optioninput = v.Optioninput | |||
subject.Lastmodifyby = data.Lastmodifyby | |||
subject.Createtime = data.Createtime | |||
subject.Lastmodifytime = data.Lastmodifytime | |||
_, err = session.Table("wx_cache_surveysheet_resultlst").Where("cid =? and uid = ? and surveysheetid = ? and surveynr = ? and subjectid = ?", t.Cid, t.Uid, t.Surveysheetid,surveynr,vv.Subjectid).Update(subject) | |||
if err != nil { | |||
glog.InfoExt("问题调研", "添加问题 err2 is :", err) | |||
session.Rollback() | |||
return err | |||
} | |||
}else{ | |||
subject := new(WxCacheSurveysheetResultlst) | |||
subject.Cid = data.Cid | |||
subject.Cnr = data.Cnr | |||
subject.Uid = t.Uid | |||
subject.Subjectid = vv.Subjectid | |||
subject.Surveynr = surveynr | |||
subject.Surveysheetid = data.Surveysheetid | |||
subject.Status = v.Status | |||
subject.SelectedOptions = vv.Optionid | |||
subject.Assessmentvalue = vv.Optionvalue | |||
subject.Remark = v.Remark | |||
subject.Optiontype = vv.Optiontype | |||
subject.Optioninput = v.Optioninput | |||
subject.Lastmodifyby = data.Lastmodifyby | |||
subject.Createtime = data.Createtime | |||
subject.Lastmodifytime = data.Lastmodifytime | |||
_, err = session.Table("wx_cache_surveysheet_resultlst").Insert(subject) | |||
if err != nil { | |||
glog.InfoExt("问题调研", "添加问题 err2 is :", err) | |||
session.Rollback() | |||
return err | |||
} | |||
} | |||
} | |||
} | |||
err = session.Commit() | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据删除 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResult) Del() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveysheetid, t.Surveynr}).Delete(&WxCacheSurveysheetResult{}) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据修改 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResult) Update() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveysheetid, t.Surveynr}).Update(t) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据查找 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResult) SelectOne() (WxCacheSurveysheetResult, error) { | |||
e := db.MasterEngine() | |||
var data WxCacheSurveysheetResult | |||
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveysheetid, t.Surveynr}).Get(&data) | |||
if err != nil { | |||
return data, err | |||
} | |||
return data, nil | |||
} |
@ -0,0 +1,141 @@ | |||
// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved. | |||
package wxSmall | |||
import ( | |||
"errors" | |||
"SSW_WebPlatform/db" | |||
"xorm.io/core" | |||
) | |||
type WxCacheSurveysheetResultlst struct { | |||
Cid int `json:"cid" xorm:"not null pk comment('公司ID') INT(11)"` | |||
Cnr int `json:"cnr" xorm:"not null pk comment('小区编号') INT(11)"` | |||
Surveynr int `json:"surveynr" xorm:"not null pk comment('流水号') INT(11)"` | |||
Surveysheetid string `json:"surveysheetid" xorm:"not null pk VARCHAR(40)"` | |||
Subjectid string `json:"subjectid" xorm:"not null pk comment('问题ID') VARCHAR(20)"` | |||
Uid int `json:"uid" xorm:"default NULL INT(10)"` | |||
Optioninput string `json:"optioninput" xorm:"default 'NULL' VARCHAR(255)"` | |||
Optiontype int `json:"optiontype" xorm:"default NULL INT(8)"` | |||
Status int `json:"status" xorm:"not null comment('状态') INT(11)"` | |||
SelectedOptions string `json:"selected_options" xorm:"not null pk comment('用户选择项') VARCHAR(40)"` | |||
Assessmentvalue int `json:"assessmentvalue" xorm:"default NULL comment('评估值') INT(11)"` | |||
Remark string `json:"remark" xorm:"default 'NULL' comment('备注') VARCHAR(255)"` | |||
Createtime string `json:"createtime" xorm:"default '''' comment('创建时间') VARCHAR(40)"` | |||
Lastmodifytime string `json:"lastmodifytime" xorm:"default '''' comment('最近更新时间') VARCHAR(40)"` | |||
Lastmodifyby string `json:"lastmodifyby" xorm:"default 'NULL' comment('修改人员') VARCHAR(40)"` | |||
} | |||
/******数据表名******/ | |||
func (t *WxCacheSurveysheetResultlst) TableName() string { | |||
return "wx_cache_surveysheet_resultlst" | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据添加 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResultlst) Add() error { | |||
e := db.MasterEngine() | |||
count := new(WxCacheSurveysheetResultlst) | |||
affw, err := e.Table(t.TableName()).ID(core.PK{t.Cid, t.Cnr, t.Surveynr, t.Surveysheetid, t.Subjectid, t.SelectedOptions}).Count(count) | |||
if err != nil { | |||
return err | |||
} | |||
if affw > 0 { | |||
return errors.New("数据已经存在!") | |||
} | |||
_, err = e.Table(t.TableName()).Insert(t) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据删除 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResultlst) Del() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveynr, t.Surveysheetid, t.Subjectid, t.SelectedOptions}).Delete(&WxCacheSurveysheetResultlst{}) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据修改 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResultlst) Update() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveynr, t.Surveysheetid, t.Subjectid, t.SelectedOptions}).Update(t) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据查找 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxCacheSurveysheetResultlst) SelectOne() (WxCacheSurveysheetResultlst, error) { | |||
e := db.MasterEngine() | |||
var data WxCacheSurveysheetResultlst | |||
_, err := e.ID(core.PK{t.Cid, t.Cnr, t.Surveynr, t.Surveysheetid, t.Subjectid, t.SelectedOptions}).Get(&data) | |||
if err != nil { | |||
return data, err | |||
} | |||
return data, nil | |||
} |
@ -0,0 +1,187 @@ | |||
// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved. | |||
package wxSmall | |||
import ( | |||
"SSW_WebPlatform/db" | |||
"xorm.io/core" | |||
) | |||
type WxUser struct { | |||
Uid int `json:"uid" xorm:"not null pk autoincr INT(11)"` | |||
Openid string `json:"openid" xorm:"not null VARCHAR(128)"` | |||
Cid int `json:"cid" xorm:"default NULL INT(11)"` | |||
Name string `json:"name" xorm:"default 'NULL' VARCHAR(32)"` | |||
Phone string `json:"phone" xorm:"default 'NULL' VARCHAR(16)"` | |||
Nickname string `json:"nickname" xorm:"default 'NULL' VARCHAR(32)"` | |||
Gender int `json:"gender" xorm:"default NULL comment('性别') INT(1)"` | |||
Language string `json:"language" xorm:"default 'NULL' VARCHAR(16)"` | |||
City string `json:"city" xorm:"default 'NULL' VARCHAR(16)"` | |||
Province string `json:"province" xorm:"default 'NULL' VARCHAR(16)"` | |||
Country string `json:"country" xorm:"default 'NULL' VARCHAR(16)"` | |||
Avatarurl string `json:"avatarurl" xorm:"default 'NULL' VARCHAR(255)"` | |||
Unionid string `json:"unionid" xorm:"default 'NULL' VARCHAR(128)"` | |||
Sessionkey string `json:"sessionkey" xorm:"default 'NULL' VARCHAR(128)"` | |||
Building string `json:"building" xorm:"default 'NULL' VARCHAR(10)"` | |||
Uint string `json:"uint" xorm:"default 'NULL' VARCHAR(10)"` | |||
Room string `json:"room" xorm:"default 'NULL' VARCHAR(10)"` | |||
Remark string `json:"remark" xorm:"default 'NULL' VARCHAR(128)"` | |||
Createtime string `json:"createtime" xorm:"default '''' comment('创建时间') VARCHAR(40)"` | |||
Lastmodifytime string `json:"lastmodifytime" xorm:"default '''' comment('最近更新时间') VARCHAR(40)"` | |||
Lastmodifyby string `json:"lastmodifyby" xorm:"default 'NULL' comment('修改人员') VARCHAR(40)"` | |||
} | |||
type UserInfo struct { | |||
NickName string `json:"nickName"` | |||
Country string `json:"country"` | |||
Province string `json:"province"` | |||
City string `json:"city"` | |||
Language string `json:"language"` | |||
Gender int `json:"gender"` | |||
AvatarUrl string `json:"avatarUrl"` | |||
} | |||
type UserData struct { | |||
UserInfo UserInfo | |||
RawData string `json:"rawData"` | |||
Signatrue string `json:"signature"` | |||
EncryptedData string `json:"encryptedData"` | |||
Iv string `json:"iv"` | |||
CloudId string `json:"cloudID"` | |||
Code string `json:"code"` | |||
} | |||
/******数据表名******/ | |||
func (t *WxUser) TableName() string { | |||
return "wx_user" | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据添加 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUser) Add() error { | |||
e := db.MasterEngine() | |||
_, err := e.Table(t.TableName()).Insert(t) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据删除 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUser) Del() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Uid}).Delete(&WxUser{}) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据修改 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUser) Update() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Uid}).Update(t) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据查找 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUser) SelectOne() (WxUser, error) { | |||
e := db.MasterEngine() | |||
var data WxUser | |||
_, err := e.ID(core.PK{t.Uid}).Get(&data) | |||
if err != nil { | |||
return data, err | |||
} | |||
return data, nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据查找 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUser) SelectOneByOpenid() (*WxUser, error) { | |||
e := db.MasterEngine() | |||
data := new(WxUser) | |||
ok, err := e.Where("openid = ?", t.Openid).Get(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if !ok { | |||
return nil, err | |||
} | |||
return data, nil | |||
} |
@ -0,0 +1,246 @@ | |||
// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved. | |||
package wxSmall | |||
import ( | |||
"SSW_WebPlatform/db" | |||
"xorm.io/core" | |||
) | |||
type WxUserCache struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Uid int `json:"uid" xorm:"default NULL INT(10)"` | |||
Cid int `json:"cid" xorm:"default NULL INT(6)"` | |||
Surveysheetid string `json:"surveysheetid" xorm:"default NULL VARCHAR(40)"` | |||
Status int `json:"status" xorm:"default NULL INT(1)"` | |||
Createtime string `json:"createtime" xorm:"default '''' comment('创建时间') VARCHAR(40)"` | |||
Lastmodifytime string `json:"lastmodifytime" xorm:"default '''' comment('最近更新时间') VARCHAR(40)"` | |||
Lastmodifyby string `json:"lastmodifyby" xorm:"default 'NULL' comment('修改人员') VARCHAR(40)"` | |||
} | |||
/******数据表名******/ | |||
func (t *WxUserCache) TableName() string { | |||
return "wx_user_cache" | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据添加 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) Add() error { | |||
e := db.MasterEngine() | |||
_, err := e.Table(t.TableName()).Insert(t) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据删除 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) Del() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Id}).Delete(&WxUserCache{}) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据修改 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) Update() error { | |||
e := db.MasterEngine() | |||
_, err := e.ID(core.PK{t.Id}).Update(t) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据查找 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) SelectOne() (WxUserCache, error) { | |||
e := db.MasterEngine() | |||
var data WxUserCache | |||
_, err := e.ID(core.PK{t.Id}).Get(&data) | |||
if err != nil { | |||
return data, err | |||
} | |||
return data, nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据查找 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) LoadInfo() (WxUserCache, error) { | |||
e := db.MasterEngine() | |||
var data WxUserCache | |||
ok, err := e.Where("cid =? and uid = ? and surveysheetid = ?", t.Cid, t.Uid, t.Surveysheetid).Get(&data) | |||
if err != nil { | |||
return data, err | |||
} | |||
if ok { | |||
return data, nil | |||
} | |||
_, err = e.Table(t.TableName()).Insert(t) | |||
if err != nil { | |||
return data, err | |||
} | |||
return *t, nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 查询缓存数据 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) SelectCacheInfo() ([]WxCacheSurveysheetResultlst, error) { | |||
e := db.MasterEngine() | |||
data := make([]WxCacheSurveysheetResultlst, 0) | |||
err := e.Table("wx_cache_surveysheet_resultlst").Join("INNER", "wx_user_cache", "wx_cache_surveysheet_resultlst.cid = wx_user_cache.cid and wx_cache_surveysheet_resultlst.uid = wx_user_cache.uid and wx_cache_surveysheet_resultlst.surveysheetid = wx_user_cache.surveysheetid").Where("wx_user_cache.cid =? and wx_user_cache.uid = ? and wx_user_cache.surveysheetid = ? and wx_user_cache.status = ?", t.Cid, t.Uid, t.Surveysheetid,0).Find(&data) | |||
if err != nil { | |||
return data, err | |||
} | |||
return data, nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 数据删除缓存 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) DelCache() error { | |||
e := db.MasterEngine() | |||
//更新状态为已经完成 | |||
_, err := e.Table("wx_user_cache").Where("cid =? and uid = ? and surveysheetid = ?", t.Cid, t.Uid, t.Surveysheetid).Update(map[string]interface{}{"status":1}) | |||
if err != nil { | |||
return err | |||
} | |||
_, err = e.Table("wx_cache_surveysheet_result").Where("cid =? and uid = ? and surveysheetid = ?", t.Cid, t.Uid, t.Surveysheetid).Delete(&WxCacheSurveysheetResult{}) | |||
if err != nil { | |||
return err | |||
} | |||
_, err = e.Table("wx_cache_surveysheet_resultlst").Where("cid =? and uid = ? and surveysheetid = ?", t.Cid, t.Uid, t.Surveysheetid).Delete(&WxCacheSurveysheetResultlst{}) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
/****************************************************************************** | |||
* | |||
* @Function Name : | |||
*----------------------------------------------------------------------------- | |||
* | |||
* @Description : 查询缓存数据 | |||
* | |||
* @Function Parameters: | |||
* | |||
* @Return Value : | |||
* | |||
* @Author : Lou Wenzhi | |||
* | |||
* @Date : 2021/3/6 8:47 | |||
* | |||
******************************************************************************/ | |||
func (t *WxUserCache) SelectResultInfo() (bool, error) { | |||
e := db.MasterEngine() | |||
var data WxUserCache | |||
ok,err := e.Table("wx_user_cache").Where("cid =? and uid = ? and surveysheetid = ? and status = ?", t.Cid, t.Uid, t.Surveysheetid,1).Get(&data) | |||
if err != nil { | |||
return false, err | |||
} | |||
return ok, nil | |||
} |