|
@@ -0,0 +1,210 @@
|
|
|
+package compatible
|
|
|
+
|
|
|
+import (
|
|
|
+ "log"
|
|
|
+ "strings"
|
|
|
+
|
|
|
+ util "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/mysql"
|
|
|
+ . "app.yhyue.com/moapp/jypkg/middleground"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
+)
|
|
|
+
|
|
|
+type Compatible struct {
|
|
|
+ Mgo *MongodbSim
|
|
|
+ BaseService *mysql.Mysql
|
|
|
+ MainMysql *mysql.Mysql
|
|
|
+ Middleground *Middleground
|
|
|
+}
|
|
|
+
|
|
|
+func NewCompatible(mgo *MongodbSim, baseService, mainMysql *mysql.Mysql, middleground *Middleground) *Compatible {
|
|
|
+ if middleground.UserCenter == nil {
|
|
|
+ log.Fatalln("NewCompatible的时候,Middleground没有注册用户中台!")
|
|
|
+ }
|
|
|
+ return &Compatible{
|
|
|
+ Mgo: mgo,
|
|
|
+ BaseService: baseService,
|
|
|
+ MainMysql: mainMysql,
|
|
|
+ Middleground: middleground,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//根据mgo库user表_id,或者企业身份的职位id查询
|
|
|
+func (c *Compatible) Select(id string, field interface{}) *map[string]interface{} {
|
|
|
+ var identity *pb.Identity
|
|
|
+ if !IsObjectIdHex(id) {
|
|
|
+ identity = c.Middleground.UserCenter.IdentityByPositionId(util.Int64All(id))
|
|
|
+ }
|
|
|
+ return c.selectDo(id, identity, field)
|
|
|
+}
|
|
|
+
|
|
|
+//根据mgo库user表_id,或者企业身份的企业员工id查询
|
|
|
+func (c *Compatible) SelectByEntUserId(id string, field interface{}) *map[string]interface{} {
|
|
|
+ var identity *pb.Identity
|
|
|
+ if !IsObjectIdHex(id) {
|
|
|
+ identity = c.Middleground.UserCenter.IdentityByEntUserId(util.Int64All(id))
|
|
|
+ }
|
|
|
+ return c.selectDo(id, identity, field)
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (c *Compatible) selectDo(id string, identity *pb.Identity, fd interface{}) *map[string]interface{} {
|
|
|
+ field := ObjToOth(fd)
|
|
|
+ user := map[string]interface{}{}
|
|
|
+ if field == nil || len(*field) == 0 {
|
|
|
+ return &user
|
|
|
+ }
|
|
|
+ (*field)["_id"] = 0
|
|
|
+ if IsObjectIdHex(id) {
|
|
|
+ temp, ok := c.Mgo.FindById("user", id, field)
|
|
|
+ if ok && temp != nil && len(*temp) > 0 {
|
|
|
+ user = *temp
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if identity == nil {
|
|
|
+ return &user
|
|
|
+ }
|
|
|
+ if identity.UserId > 0 {
|
|
|
+ ufd := map[string]interface{}{}
|
|
|
+ for _, k := range []string{"s_m_openid", "s_phone", "s_m_phone", "s_unionid", "s_headimage", "s_headimageurl", "s_nickname", "l_registedate", "s_appversion", "i_ispush", "s_jyname", "s_jpushid", "s_opushid", "s_appponetype", "i_applystatus"} {
|
|
|
+ if v, ok := (*field)[k]; ok {
|
|
|
+ ufd[k] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(ufd) > 0 {
|
|
|
+ ufd["_id"] = 0
|
|
|
+ data, ok := c.Mgo.FindOneByField("user", map[string]interface{}{"base_user_id": identity.UserId}, ufd)
|
|
|
+ if ok && data != nil && len(*data) > 0 {
|
|
|
+ for k, v := range *data {
|
|
|
+ user[k] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if identity.EntUserId > 0 {
|
|
|
+ if (*field)["o_entniche"] != nil || (*field)["o_vipjy"] != nil || (*field)["o_member_jy"] != nil || (*field)["o_jy"] != nil {
|
|
|
+ entniche_rule, ok := c.Mgo.Find("entniche_rule", map[string]interface{}{
|
|
|
+ "i_userid": identity.EntUserId,
|
|
|
+ }, nil, `{"_id":0,"o_entniche":1,"i_type":1}`, false, -1, -1)
|
|
|
+ if ok && entniche_rule != nil && len(*entniche_rule) > 0 {
|
|
|
+ for _, v := range *entniche_rule {
|
|
|
+ i_type := util.IntAll(v["i_type"])
|
|
|
+ if i_type == 0 {
|
|
|
+ if (*field)["o_entniche"] != nil {
|
|
|
+ user["o_entniche"] = v["o_entniche"]
|
|
|
+ }
|
|
|
+ } else if i_type == 1 {
|
|
|
+ if (*field)["o_vipjy"] != nil {
|
|
|
+ user["o_vipjy"] = v["o_entniche"]
|
|
|
+ }
|
|
|
+ if (*field)["o_member_jy"] != nil {
|
|
|
+ user["o_member_jy"] = v["o_entniche"]
|
|
|
+ }
|
|
|
+ } else if i_type == 2 {
|
|
|
+ if (*field)["o_jy"] != nil {
|
|
|
+ user["o_jy"] = v["o_entniche"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ delete((*field), "o_jy")
|
|
|
+ delete((*field), "o_vipjy")
|
|
|
+ delete((*field), "o_member_jy")
|
|
|
+ delete((*field), "o_entniche")
|
|
|
+ if len((*field)) > 0 {
|
|
|
+ ent_user, ok := c.Mgo.FindOneByField("ent_user", map[string]interface{}{
|
|
|
+ "i_userid": identity.EntUserId,
|
|
|
+ }, field)
|
|
|
+ if ok && ent_user != nil && len(*ent_user) > 0 {
|
|
|
+ for k, v := range *ent_user {
|
|
|
+ user[k] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return &user
|
|
|
+}
|
|
|
+
|
|
|
+//根据mgo库user表_id,或者企业身份的职位id更新
|
|
|
+func (c *Compatible) Update(id string, update map[string]interface{}) bool {
|
|
|
+ var identity *pb.Identity
|
|
|
+ if !IsObjectIdHex(id) {
|
|
|
+ identity = c.Middleground.UserCenter.IdentityByPositionId(util.Int64All(id))
|
|
|
+ }
|
|
|
+ return c.updateDo(id, identity, update)
|
|
|
+}
|
|
|
+
|
|
|
+//根据mgo库user表_id,或者企业身份的企业员工id更新
|
|
|
+func (c *Compatible) UpdateByEntUserId(id string, update map[string]interface{}) bool {
|
|
|
+ var identity *pb.Identity
|
|
|
+ if !IsObjectIdHex(id) {
|
|
|
+ identity = c.Middleground.UserCenter.IdentityByEntUserId(util.Int64All(id))
|
|
|
+ }
|
|
|
+ return c.updateDo(id, identity, update)
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (c *Compatible) updateDo(id string, identity *pb.Identity, update map[string]interface{}) bool {
|
|
|
+ if IsObjectIdHex(id) {
|
|
|
+ return c.Mgo.UpdateById("user", id, update)
|
|
|
+ } else {
|
|
|
+ if identity == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ up1, up2 := map[string]interface{}{}, map[string]interface{}{}
|
|
|
+ var tp int
|
|
|
+ for k, v := range update {
|
|
|
+ vm, ok := v.(map[string]interface{})
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ up11, up22 := map[string]interface{}{}, map[string]interface{}{}
|
|
|
+ key := ""
|
|
|
+ for kk, vv := range vm {
|
|
|
+ if (key == "" || key == "o_jy") && (kk == "o_jy" || strings.HasPrefix(kk, "o_jy.")) {
|
|
|
+ key = "o_jy"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 2
|
|
|
+ } else if (key == "" || key == "o_vipjy") && (kk == "o_vipjy" || strings.HasPrefix(kk, "o_vipjy.")) {
|
|
|
+ key = "o_vipjy"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 1
|
|
|
+ } else if (key == "" || key == "o_member_jy") && (kk == "o_member_jy" || strings.HasPrefix(kk, "o_member_jy.")) {
|
|
|
+ key = "o_member_jy"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 1
|
|
|
+ } else if (key == "" || key == "o_entniche") && (kk == "o_entniche" || strings.HasPrefix(kk, "o_entniche.")) {
|
|
|
+ key = "o_entniche"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 0
|
|
|
+ } else {
|
|
|
+ up11[kk] = vv
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(up11) > 0 {
|
|
|
+ up1[k] = up11
|
|
|
+ }
|
|
|
+ if len(up22) > 0 {
|
|
|
+ up2[k] = up22
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ok1, ok2 := false, false
|
|
|
+ if len(up1) > 0 {
|
|
|
+ ok1 = c.Mgo.Update("ent_user", map[string]interface{}{
|
|
|
+ "i_entid": identity.EntId,
|
|
|
+ "i_userid": identity.EntUserId,
|
|
|
+ }, up1, true, false)
|
|
|
+ }
|
|
|
+ if len(up2) > 0 {
|
|
|
+ ok2 = c.Mgo.Update("entniche_rule", map[string]interface{}{
|
|
|
+ "i_entid": identity.EntId,
|
|
|
+ "i_userid": identity.EntUserId,
|
|
|
+ "i_type": tp,
|
|
|
+ }, up2, false, false)
|
|
|
+ }
|
|
|
+ return ok1 || ok2
|
|
|
+ }
|
|
|
+}
|