coverage.html 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>service: Go Coverage Report</title>
  6. <style>
  7. body {
  8. background: black;
  9. color: rgb(80, 80, 80);
  10. }
  11. body, pre, #legend span {
  12. font-family: Menlo, monospace;
  13. font-weight: bold;
  14. }
  15. #topbar {
  16. background: black;
  17. position: fixed;
  18. top: 0; left: 0; right: 0;
  19. height: 42px;
  20. border-bottom: 1px solid rgb(80, 80, 80);
  21. }
  22. #content {
  23. margin-top: 50px;
  24. }
  25. #nav, #legend {
  26. float: left;
  27. margin-left: 10px;
  28. }
  29. #legend {
  30. margin-top: 12px;
  31. }
  32. #nav {
  33. margin-top: 10px;
  34. }
  35. #legend span {
  36. margin: 0 5px;
  37. }
  38. .cov0 { color: rgb(192, 0, 0) }
  39. .cov1 { color: rgb(128, 128, 128) }
  40. .cov2 { color: rgb(116, 140, 131) }
  41. .cov3 { color: rgb(104, 152, 134) }
  42. .cov4 { color: rgb(92, 164, 137) }
  43. .cov5 { color: rgb(80, 176, 140) }
  44. .cov6 { color: rgb(68, 188, 143) }
  45. .cov7 { color: rgb(56, 200, 146) }
  46. .cov8 { color: rgb(44, 212, 149) }
  47. .cov9 { color: rgb(32, 224, 152) }
  48. .cov10 { color: rgb(20, 236, 155) }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="topbar">
  53. <div id="nav">
  54. <select id="files">
  55. <option value="file0">userCenter/service/entService.go (0.0%)</option>
  56. <option value="file1">userCenter/service/user.go (70.8%)</option>
  57. <option value="file2">userCenter/service/workDesktop.go (87.5%)</option>
  58. </select>
  59. </div>
  60. <div id="legend">
  61. <span>not tracked</span>
  62. <span class="cov0">not covered</span>
  63. <span class="cov8">covered</span>
  64. </div>
  65. </div>
  66. <div id="content">
  67. <pre class="file" id="file0" style="display: none">package service
  68. import (
  69. "fmt"
  70. "strconv"
  71. "time"
  72. "app.yhyue.com/moapp/jybase/common"
  73. "userCenter/entity"
  74. userCenter "userCenter/rpc/usercenter"
  75. )
  76. type EntService struct {
  77. Url string
  78. }
  79. //创建企业用户
  80. /*
  81. 根据统一社会信用代码判断
  82. 查询是否已存在该企业
  83. 若无该企业
  84. 创建新企业
  85. 存在该企业
  86. 老企业更新
  87. */
  88. const (
  89. EXAMINEINGMSG = "该机构正在审核中,无法提交认证申请"
  90. APPROVEDMSG = "该机构已完成认证,无法提交认证申请"
  91. OKMSG = "提交成功"
  92. )
  93. //return error_code error_msg status entid
  94. func (this *EntService) CreateEnt(data *userCenter.EntAuthReq) (int64, string, int64, int64) <span class="cov0" title="0">{
  95. if data.Name == "" || data.Phone == "" || data.CreditCode == "" </span><span class="cov0" title="0">{
  96. return entity.ErrorCode, "参数异常", entity.ErrorCode, 0
  97. }</span>
  98. <span class="cov0" title="0">authType, _ := strconv.Atoi(data.ComPanyType)
  99. entinfo := &amp;entity.EntInfo{
  100. Name: data.Name, //企业名称
  101. Phone: data.Phone, //注册人手机号
  102. Code: data.CreditCode, //统一社会信用代码
  103. Createtime: time.Now().Format("2006-01-02 15:04:05"),
  104. Organization_type: data.OrganizationType, //机构类型 1投标企业 2招标采购单位 3厂商 4招标代理机构 5经销商 6服务提供商 7其他
  105. Auth_type: authType, // 认证类型 1-事业单位 0-企业
  106. License: data.Business, //营业执照
  107. Official_letter: data.OfficialLetter, //认证公函
  108. Linkman_phone: data.AuthPhone, //联系人手机号
  109. Linkman_name: data.AuthName, //联系人姓名
  110. AreaNumber: data.AreaNumber, //
  111. Frozen_status: 1,
  112. Auth_status: 0,
  113. Audit_status: 1,
  114. Mysql: entity.Mysql,
  115. }
  116. //存在统一社会信用代码
  117. r := entity.Mysql.SelectBySql(`select id,audit_status,auth_status,name,phone from entniche_info where code =?`, data.CreditCode)
  118. if r != nil &amp;&amp; len(*r) &gt; 0 </span><span class="cov0" title="0">{
  119. //记录所有的统一社会信用代码相同的企业
  120. sameCode := map[int64]interface{}{}
  121. for _, v := range *r </span><span class="cov0" title="0">{
  122. id, _ := v["id"].(int64)
  123. audit_status, _ := v["audit_status"].(int64)
  124. auth_status, _ := v["auth_status"].(int64)
  125. ent_name, _ := v["name"].(string)
  126. // phone, _ := v["phone"].(string)
  127. if audit_status == 1 </span><span class="cov0" title="0">{ //根据统一社会信用代码查看该企业正在审核中
  128. return entity.ErrorCode, EXAMINEINGMSG, entity.ErrorCode, 0
  129. }</span>
  130. <span class="cov0" title="0">if auth_status == 1 </span><span class="cov0" title="0">{
  131. sameCode[id] = map[string]interface{}{
  132. "name": ent_name,
  133. "authStatus": auth_status,
  134. "auditStatus": audit_status,
  135. }
  136. }</span>
  137. }
  138. <span class="cov0" title="0">if len(sameCode) &gt; 0 </span><span class="cov0" title="0">{
  139. entids := ""
  140. i := 0
  141. for k, _ := range sameCode </span><span class="cov0" title="0">{
  142. //判断企业是否已认证
  143. entids += fmt.Sprint(k)
  144. if i != len(sameCode)-1 </span><span class="cov0" title="0">{
  145. entids += ","
  146. }</span>
  147. <span class="cov0" title="0">i++</span>
  148. }
  149. //查看该用户是否在已认证的企业机构下,如果在机构下则可以重新发起认证(编辑)如果不在则提示已被认证
  150. <span class="cov0" title="0">list := entity.Mysql.SelectBySql(`
  151. SELECT a.ent_id,b.name FROM entniche_user a inner join entniche_info b
  152. on a.ent_id = b.id WHERE a.ent_id IN(?) AND a.phone = ?`, entids, entinfo.Phone)
  153. if len(*list) &lt;= 0 </span><span class="cov0" title="0">{
  154. return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode, 0
  155. }</span>
  156. //log.Println(fmt.Printf("查询到该统一社会信用代码存在%v个认证企业中,默认获取第一个企业进行认证,该企业企业id为%v", len(*list), (*list)[0]["ent_id"]))
  157. <span class="cov0" title="0">entinfo.Id = common.IntAll((*list)[0]["ent_id"])
  158. if entinfo.Update() </span><span class="cov0" title="0">{
  159. return entity.SuccessCode, OKMSG, 1, int64(entinfo.Id)
  160. }</span>
  161. }
  162. }
  163. //不存在统一社会信用代码
  164. <span class="cov0" title="0">r = entity.Mysql.SelectBySql(`select id,audit_status,auth_status,name,phone from entniche_info where id =?`, data.EntId)
  165. if r != nil &amp;&amp; len(*r) &gt; 0 </span><span class="cov0" title="0">{
  166. for _, v := range *r </span><span class="cov0" title="0">{
  167. id, _ := v["id"].(int64)
  168. audit_status, _ := v["audit_status"].(int64)
  169. auth_status, _ := v["auth_status"].(int64)
  170. ent_name, _ := v["name"].(string)
  171. // phone, _ := v["phone"].(string)
  172. //该企业下员工 可以重新认证
  173. if ent_name != entinfo.Name </span><span class="cov0" title="0">{ //企业名称不同 创建全新企业
  174. if ok, entid := entinfo.Add(); ok </span><span class="cov0" title="0">{
  175. return entity.SuccessCode, OKMSG, 1, entid
  176. }</span>
  177. }
  178. <span class="cov0" title="0">if audit_status == 1 </span><span class="cov0" title="0">{ //审核中
  179. return entity.ErrorCode, EXAMINEINGMSG, entity.ErrorCode, 0
  180. }</span>
  181. <span class="cov0" title="0">if auth_status == 1 </span><span class="cov0" title="0">{ //已认证
  182. list := entity.Mysql.SelectBySql(`select * from entniche_user where ent_id =? and phone =?`, id, entinfo.Phone)
  183. if len(*list) &lt;= 0 </span><span class="cov0" title="0">{
  184. return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode, 0
  185. }</span>
  186. }
  187. <span class="cov0" title="0">entinfo.Id = int(id)
  188. // entinfo.Phone = phone //更换注册人手机号为管理员手机号
  189. if entinfo.Update() </span><span class="cov0" title="0">{
  190. return entity.SuccessCode, OKMSG, 1, int64(entinfo.Id)
  191. }</span>
  192. }
  193. }
  194. <span class="cov0" title="0">if ok, id := entinfo.Add(); ok </span><span class="cov0" title="0">{
  195. return entity.SuccessCode, OKMSG, 1, id
  196. }</span>
  197. <span class="cov0" title="0">return entity.ErrorCode, "", entity.ErrorCode, 0</span>
  198. }
  199. //机构审核
  200. func (this *EntService) Examinet(data *userCenter.ExamineReq) (int64, string, int64) <span class="cov0" title="0">{
  201. if data.EntId == 0 || data.ExamineId == "" </span><span class="cov0" title="0">{
  202. return -1, "参数异常", 0
  203. }</span>
  204. <span class="cov0" title="0">info := &amp;entity.Examine{
  205. ExamineId: data.ExamineId,
  206. EntId: data.EntId,
  207. Reason: data.Reason,
  208. AuthType: data.AuthType,
  209. AuditUser: data.AuditUser,
  210. Mysql: entity.Mysql,
  211. ResourceLib: entity.ResourceLib,
  212. }
  213. if info.EntExamine() </span><span class="cov0" title="0">{
  214. return 1, "", 0
  215. }</span>
  216. //修改状态
  217. <span class="cov0" title="0">return -1, "修改失败", -1</span>
  218. }
  219. //企业列表
  220. func (this *EntService) EntList(data *userCenter.EntListReq) (int64, string, *userCenter.EntData) <span class="cov0" title="0">{
  221. info := &amp;entity.List{
  222. Name: data.Name,
  223. AuthStatus: data.AuthStatus,
  224. PageNum: data.PageNum,
  225. PageSize: data.PageSize,
  226. CreditCode: data.CreditCode,
  227. CreateStartTime: data.CreateStartTime,
  228. CreateEndTime: data.CreateEndTime,
  229. ValidStartTime: data.ValidStartTime,
  230. ValidEndTime: data.ValidEndTime,
  231. FrozenStatus: data.FrozenStatus,
  232. RegPhone: data.RegPhone,
  233. AuthPhone: data.AuthPhone,
  234. Mysql: entity.Mysql,
  235. }
  236. r, count := info.List()
  237. pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string)
  238. i_pageSize, _ := strconv.Atoi(pageSize)
  239. list := []*userCenter.EntList{}
  240. for _, v := range *r </span><span class="cov0" title="0">{
  241. list = append(list, &amp;userCenter.EntList{
  242. Id: common.Int64All(v["id"]), //机构id
  243. ComPanyType: common.Int64All(v["comPanyType"]), // 机构性质 1企业 2党政机关事业单位及其他
  244. Name: common.ObjToString(v["name"]), //机构名称
  245. OrganizationType: common.ObjToString(v["organizationType"]), //机构类型 1企业 2党政机关事业单位及其他
  246. Createtime: common.ObjToString(v["createTime"]), //创建时间
  247. ValidTime: common.ObjToString(v["validTime"]), //有效截至日期
  248. AuthStatus: common.Int64All(v["authStatus"]), //认证状态
  249. FrozenStatus: common.Int64All(v["frozenStatus"]),
  250. })
  251. }</span>
  252. <span class="cov0" title="0">return 0, "", &amp;userCenter.EntData{
  253. Count: count,
  254. PageSize: int64(i_pageSize),
  255. List: list,
  256. }</span>
  257. }
  258. //审核列表
  259. func (this *EntService) ExamineList(data *userCenter.ExamineListReq) (int64, string, *userCenter.ExamineListData) <span class="cov0" title="0">{
  260. info := &amp;entity.ExamineList{
  261. Name: data.Name,
  262. AuthPhone: data.AuthPhone,
  263. RegPhone: data.RegPhone,
  264. AuthType: data.AuthType, //审核状态 1:待审核 2:审核通过 3:审核不通过
  265. AuthStartTime: data.AuthStartTime, //申请开始时间
  266. AuthEndTime: data.AuthEndTime, //申请结束时间
  267. PageNum: data.PageNum, //页码
  268. PageSize: data.PageSize, //每页展示条数
  269. Mysql: entity.Mysql,
  270. }
  271. r, count := info.List()
  272. pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string)
  273. i_pageSize, _ := strconv.Atoi(pageSize)
  274. list := []*userCenter.ExamineList{}
  275. for _, v := range *r </span><span class="cov0" title="0">{
  276. list = append(list, &amp;userCenter.ExamineList{
  277. Id: common.Int64All(v["id"]),
  278. EntId: common.Int64All(v["entId"]),
  279. ComPanyType: common.Int64All(v["comPanyType"]), // 机构性质 1企业 2党政机关事业单位及其他
  280. Name: common.ObjToString(v["name"]), //机构名称
  281. CreditCode: common.ObjToString(v["creditCode"]), //统一社会信用代码
  282. AuthPhone: common.ObjToString(v["authPhone"]), //联系人手机号
  283. ApplyTime: common.ObjToString(v["authTime"]), //申请时间戳
  284. AuthType: common.Int64All(v["authStatus"]), //审核状态
  285. RegPhone: common.ObjToString(v["regPhone"]),
  286. })
  287. }</span>
  288. <span class="cov0" title="0">return 0, "", &amp;userCenter.ExamineListData{
  289. Count: count,
  290. PageSize: int64(i_pageSize),
  291. List: list,
  292. }</span>
  293. }
  294. func (this *EntService) CheckEnt(data *userCenter.CheckEntReq) (int64, int64, string, int64) <span class="cov0" title="0">{
  295. info := &amp;entity.CheckEnt{
  296. EntId: data.EntId,
  297. Mysql: entity.Mysql,
  298. }
  299. authStatus, frozenStatus, msg := info.Check()
  300. return authStatus, frozenStatus, msg, common.Int64All(common.If(msg == "", entity.SuccessCode, entity.ErrorCode))
  301. }</span>
  302. //企业信息
  303. func (this *EntService) Info(data *userCenter.CheckEntReq) (int64, string, *userCenter.EntInfoData) <span class="cov0" title="0">{
  304. info := &amp;entity.CheckEnt{
  305. EntId: data.EntId,
  306. Mysql: entity.Mysql,
  307. Url: this.Url,
  308. }
  309. rdata := info.Info()
  310. entInfoData := &amp;userCenter.EntInfoData{
  311. Name: rdata.Name,
  312. OrganizationType: rdata.OrganizationType,
  313. CreditCode: rdata.CreditCode,
  314. CompanyType: rdata.CompanyType,
  315. AreaNumber: rdata.AreaNumber,
  316. Business: rdata.Business,
  317. OfficialLetter: rdata.OfficialLetter,
  318. AuthStartTime: rdata.AuthStartTime,
  319. AuthEndTime: rdata.AuthEndTime,
  320. ForzenStatus: rdata.ForzenStatus,
  321. AuthState: rdata.AuthState,
  322. ContactPerson: rdata.ContactPerson,
  323. ContactPhone: rdata.ContactPhone,
  324. AuthType: rdata.AuthType,
  325. CreateTime: rdata.CreateTime,
  326. AuthReason: rdata.AuthReason,
  327. }
  328. return 0, "", entInfoData
  329. }</span>
  330. func (this *EntService) UpdateEnt(data *userCenter.EntUpdateReq) (int64, string, int64) <span class="cov0" title="0">{
  331. info := &amp;entity.UpdateEnt{
  332. EntId: data.EntId,
  333. UpdateType: data.UpdateType,
  334. Mysql: entity.Mysql,
  335. ResourceLib: entity.ResourceLib,
  336. }
  337. status, msg := info.UpdateEnt()
  338. return 0, msg, status
  339. }</span>
  340. func (this *EntService) ExamineInfo(data *userCenter.CheckExamineReq) (int64, string, *userCenter.EntInfoData) <span class="cov0" title="0">{
  341. info := &amp;entity.ExamineInfo{
  342. ExamineId: data.ExamineId,
  343. Mysql: entity.Mysql,
  344. }
  345. rdata := info.Info()
  346. entInfoData := &amp;userCenter.EntInfoData{
  347. Name: rdata.Name,
  348. OrganizationType: rdata.OrganizationType,
  349. CreditCode: rdata.CreditCode,
  350. CompanyType: rdata.CompanyType,
  351. AreaNumber: rdata.AreaNumber,
  352. Business: rdata.Business,
  353. OfficialLetter: rdata.OfficialLetter,
  354. AuthState: rdata.AuthState,
  355. ContactPerson: rdata.ContactPerson,
  356. ContactPhone: rdata.ContactPhone,
  357. RegPhone: rdata.RegPhone,
  358. AuthTime: rdata.AuthTime,
  359. AuthReason: rdata.AuthReason,
  360. AuditUser: rdata.AuditUser,
  361. AuditTime: rdata.AuditTime,
  362. }
  363. return 0, "", entInfoData
  364. }</span>
  365. func (this *EntService) GetStatusByCode(data *userCenter.GetStatusByCodeReq) (int, bool, string) <span class="cov0" title="0">{
  366. info := &amp;entity.GetStatusByCodeStruct{
  367. Mysql: entity.Mysql,
  368. Code: data.Code,
  369. Phone: data.Phone,
  370. }
  371. return info.GetStatusByCode()
  372. }</span>
  373. </pre>
  374. <pre class="file" id="file1" style="display: none">package service
  375. import (
  376. "database/sql"
  377. "time"
  378. "userCenter/entity"
  379. . "userCenter/rpc/usercenter"
  380. )
  381. func UserAdd(this *UserAddReq) *UserAddResp <span class="cov8" title="1">{
  382. userId := entity.BaseMysql.Insert(entity.UserTable, map[string]interface{}{
  383. "appid": this.Appid,
  384. "phone": this.Phone,
  385. "nickname": this.Nickname,
  386. "headimg": this.Headimg,
  387. "company": this.Company,
  388. "position": this.Position,
  389. "password": this.Password,
  390. "s_openid": this.SOpenid,
  391. "a_openid": this.AOpenid,
  392. "unionid": this.Unionid,
  393. "create_time": time.Now().Format("2006-01-02 15:04:05"),
  394. })
  395. status, msg := 0, ""
  396. if userId &gt; 0 </span><span class="cov8" title="1">{
  397. status = 1
  398. }</span> else<span class="cov0" title="0"> {
  399. msg = "新增用户失败"
  400. }</span>
  401. <span class="cov8" title="1">return &amp;UserAddResp{
  402. ErrorCode: entity.SuccessCode,
  403. ErrorMsg: msg,
  404. Data: &amp;UserAdds{Status: int64(status), Id: userId},
  405. }</span>
  406. }
  407. func UserUpdate(this *UserIdReq) *ExamineResp <span class="cov8" title="1">{
  408. ok := UserUpdates(this)
  409. status, msg := 0, ""
  410. if ok </span><span class="cov8" title="1">{
  411. status = 1
  412. }</span> else<span class="cov0" title="0"> {
  413. msg = "更新用户失败"
  414. }</span>
  415. <span class="cov8" title="1">return &amp;ExamineResp{
  416. ErrorCode: entity.SuccessCode,
  417. ErrorMsg: msg,
  418. Data: &amp;ExamineData{Status: int64(status)},
  419. }</span>
  420. }
  421. func UserDel(this *UserIdReq) *ExamineResp <span class="cov8" title="1">{
  422. ok := UserDels(this)
  423. status, msg := 0, ""
  424. if ok </span><span class="cov0" title="0">{
  425. status = 1
  426. }</span> else<span class="cov8" title="1"> {
  427. msg = "删除用户失败"
  428. }</span>
  429. <span class="cov8" title="1">return &amp;ExamineResp{
  430. ErrorCode: entity.SuccessCode,
  431. ErrorMsg: msg,
  432. Data: &amp;ExamineData{Status: int64(status)},
  433. }</span>
  434. }
  435. func UserUpdates(this *UserIdReq) bool <span class="cov8" title="1">{
  436. ok := false
  437. flag := entity.BaseMysql.ExecTx("", func(tx *sql.Tx) bool </span><span class="cov8" title="1">{
  438. set := map[string]interface{}{}
  439. if this.Phone != "" </span><span class="cov8" title="1">{
  440. set["phone"] = this.Phone
  441. }</span> else<span class="cov0" title="0"> {
  442. set["phone"] = ""
  443. }</span>
  444. <span class="cov8" title="1">if this.Nickname != "" </span><span class="cov8" title="1">{
  445. set["nickname"] = this.Nickname
  446. }</span> else<span class="cov0" title="0"> {
  447. set["nickname"] = ""
  448. }</span>
  449. <span class="cov8" title="1">if this.Headimg != "" </span><span class="cov0" title="0">{
  450. set["headimg"] = this.Headimg
  451. }</span> else<span class="cov8" title="1"> {
  452. set["headimg"] = ""
  453. }</span>
  454. <span class="cov8" title="1">if this.Company != "" </span><span class="cov8" title="1">{
  455. set["company"] = this.Company
  456. }</span> else<span class="cov0" title="0"> {
  457. set["company"] = ""
  458. }</span>
  459. <span class="cov8" title="1">if this.Position != "" </span><span class="cov0" title="0">{
  460. set["position"] = this.Position
  461. }</span> else<span class="cov8" title="1"> {
  462. set["position"] = ""
  463. }</span>
  464. <span class="cov8" title="1">if this.Password != "" </span><span class="cov0" title="0">{
  465. set["password"] = this.Password
  466. }</span> else<span class="cov8" title="1"> {
  467. set["password"] = ""
  468. }</span>
  469. <span class="cov8" title="1">if this.AOpenid != "" </span><span class="cov0" title="0">{
  470. set["a_openid"] = this.AOpenid
  471. }</span> else<span class="cov8" title="1"> {
  472. set["a_openid"] = ""
  473. }</span>
  474. <span class="cov8" title="1">if this.SOpenid != "" </span><span class="cov0" title="0">{
  475. set["s_openid"] = this.SOpenid
  476. }</span> else<span class="cov8" title="1"> {
  477. set["s_openid"] = ""
  478. }</span>
  479. <span class="cov8" title="1">if this.Unionid != "" </span><span class="cov0" title="0">{
  480. set["unionid"] = this.Unionid
  481. }</span> else<span class="cov8" title="1"> {
  482. set["unionid"] = ""
  483. }</span>
  484. <span class="cov8" title="1">ok1 := entity.BaseMysql.UpdateByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id}, set)
  485. snapshot := entity.BaseMysql.InsertByTx(tx, entity.UserSnapshotTable, map[string]interface{}{
  486. "appid": this.Appid,
  487. "user_id": this.Id,
  488. "phone": this.Phone,
  489. "nickname": this.Nickname,
  490. "headimg": this.Headimg,
  491. "company": this.Company,
  492. "position": this.Position,
  493. "password": this.Password,
  494. "s_openid": this.SOpenid,
  495. "a_openid": this.AOpenid,
  496. "unionid": this.Unionid,
  497. "create_time": time.Now().Format("2006-01-02 15:04:05"),
  498. })
  499. return ok1 &amp;&amp; snapshot &gt; 0</span>
  500. })
  501. <span class="cov8" title="1">if flag </span><span class="cov8" title="1">{
  502. ok = true
  503. }</span>
  504. <span class="cov8" title="1">return ok</span>
  505. }
  506. func UserDels(this *UserIdReq) bool <span class="cov8" title="1">{
  507. ok := false
  508. userData := entity.BaseMysql.FindOne(entity.UserTable, map[string]interface{}{"id": this.Id}, "", "")
  509. if userData != nil &amp;&amp; len(*userData) &gt; 0 </span><span class="cov0" title="0">{
  510. flag := entity.BaseMysql.ExecTx("", func(tx *sql.Tx) bool </span><span class="cov0" title="0">{
  511. thisdata := *userData
  512. ok1 := entity.BaseMysql.DeleteByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id})
  513. snapshot := entity.BaseMysql.InsertByTx(tx, entity.UserSnapshotTable, map[string]interface{}{
  514. "appid": thisdata["appid"],
  515. "user_id": this.Id,
  516. "phone": thisdata["phone"],
  517. "nickname": thisdata["nickname"],
  518. "headimg": thisdata["headimg"],
  519. "company": thisdata["company"],
  520. "position": thisdata["position"],
  521. "password": thisdata["password"],
  522. "s_openid": thisdata["s_openid"],
  523. "a_openid": thisdata["a_openid"],
  524. "unionid": thisdata["unionid"],
  525. "create_time": time.Now().Format("2006-01-02 15:04:05"),
  526. })
  527. return ok1 &amp;&amp; snapshot &gt; 0
  528. }</span>)
  529. <span class="cov0" title="0">if flag </span><span class="cov0" title="0">{
  530. ok = true
  531. }</span>
  532. }
  533. <span class="cov8" title="1">return ok</span>
  534. }
  535. </pre>
  536. <pre class="file" id="file2" style="display: none">package service
  537. import (
  538. MC "app.yhyue.com/moapp/jybase/common"
  539. "app.yhyue.com/moapp/jybase/redis"
  540. "encoding/json"
  541. "errors"
  542. "fmt"
  543. "github.com/zeromicro/go-zero/core/logx"
  544. "math/rand"
  545. "strings"
  546. "time"
  547. "userCenter/entity"
  548. "userCenter/rpc/pb"
  549. . "userCenter/rpc/usercenter"
  550. )
  551. //工作桌面--菜单当前选择模式--全部:all/可用:usable
  552. //工作桌面--常用功能更新
  553. //工作桌面--常用功能列表
  554. func RenewWorkDesktopMenuModeOrCommonly(in *WorkDesktopComprehensiveReq) (r *WorkDesktopComprehensiveResp) <span class="cov8" title="1">{
  555. r = &amp;WorkDesktopComprehensiveResp{}
  556. switch in.ActionMode </span>{
  557. case "commonlyRenew":<span class="cov8" title="1"> //常用功能更新
  558. //in.MenuIds 为空;删除
  559. if in.MenuIds == "" </span><span class="cov8" title="1">{
  560. count := entity.BaseMysql.CountBySql(`SELECT COUNT(id) FROM `+entity.WorkCommonly+` WHERE userid = ? AND appid = ? AND platform = ? AND field = ?`, in.UserId, in.AppId, in.Platform, in.ActionMode)
  561. if count &gt; 0 </span><span class="cov8" title="1">{
  562. if count := entity.BaseMysql.UpdateOrDeleteBySql(`DELETE FROM `+entity.WorkCommonly+` WHERE userid = ? AND appid = ? AND platform = ? AND field = ?`, in.UserId, in.AppId, in.Platform, in.ActionMode); count &lt;= 0 </span><span class="cov0" title="0">{
  563. r.ErrorCode = -1
  564. r.ErrorMsg = "常用功能-清空常用功能异常"
  565. }</span>
  566. }
  567. } else<span class="cov8" title="1"> {
  568. //in.MenuIds 不为空:更新
  569. if b, m := entity.CommonlyUpdate(in); !b </span><span class="cov0" title="0">{
  570. r.ErrorCode = -1
  571. r.ErrorMsg = m
  572. }</span>
  573. }
  574. case "commonlyList":<span class="cov8" title="1">
  575. //查询常用功能列表
  576. in.ActionMode = "commonlyRenew"
  577. existingData := entity.BaseMysql.SelectBySql(`SELECT value FROM `+entity.WorkCommonly+` WHERE userid = ? AND appid = ? AND field = ? AND platform = ? ORDER BY id DESC `, in.UserId, in.AppId, in.ActionMode, in.Platform)
  578. if existingData != nil &amp;&amp; len(*existingData) &gt; 0 </span><span class="cov8" title="1">{
  579. eData := (*existingData)[0]
  580. if MC.ObjToString(eData["value"]) != "" </span><span class="cov8" title="1">{
  581. var (
  582. params []string
  583. pIds []interface{}
  584. )
  585. for _, pv := range strings.Split(MC.ObjToString(eData["value"]), ",") </span><span class="cov8" title="1">{
  586. params = append(params, "?")
  587. pIds = append(pIds, pv)
  588. }</span>
  589. <span class="cov8" title="1">menuData := entity.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT * from %s WHERE id IN (%s) AND status = 0`, entity.WorkMenu, strings.Join(params, ",")), pIds...)
  590. if menuData != nil &amp;&amp; len(*menuData) &gt; 0 </span><span class="cov8" title="1">{
  591. var menuList = []*pb.ThreeLevelMenu{}
  592. var m = &amp;entity.WorkDesktopMenu{
  593. MenuTree: nil,
  594. UserId: in.UserId,
  595. AppId: in.AppId,
  596. TimeOut: int(in.RedisOutTime),
  597. BigMemberOff: in.BigMemberOff,
  598. }
  599. for _, mv := range *menuData </span><span class="cov8" title="1">{
  600. //0:默认展示;1:需验证权限,有权限展示;2:需验证权限,无权限也可展示(可用服务无权限不展示)
  601. usable := m.VerifyPermissions(MC.ObjToString(mv["powerids"]))
  602. menu := &amp;pb.ThreeLevelMenu{
  603. Name: MC.ObjToString(mv["name"]),
  604. Icon: MC.ObjToString(mv["icon"]),
  605. AppType: MC.ObjToString(mv["apptype"]),
  606. Usable: MC.If(MC.ObjToString(mv["powerids"]) != "", usable &amp;&amp; MC.IntAll(mv["checkcode"]) == 1, true).(bool),
  607. OpenType: MC.ObjToString(mv["opentype"]),
  608. }
  609. switch in.Platform </span>{
  610. case "WX":<span class="cov8" title="1">
  611. menu.Url = MC.ObjToString(mv["wxurl"])</span>
  612. case "APP":<span class="cov8" title="1">
  613. menu.Url = MC.ObjToString(mv["appurl"])</span>
  614. default:<span class="cov8" title="1">
  615. menu.Url = MC.ObjToString(mv["pcurl"])</span>
  616. }
  617. <span class="cov8" title="1">if additionalInfo := MC.ObjToString(mv["additionalinfo"]); additionalInfo != "" </span><span class="cov8" title="1">{
  618. additional := pb.TipInfo{}
  619. if json.Unmarshal([]byte(additionalInfo), &amp;additional) == nil </span><span class="cov8" title="1">{
  620. menu.TipInfo = &amp;additional
  621. }</span>
  622. }
  623. <span class="cov8" title="1">menuList = append(menuList, menu)</span>
  624. }
  625. <span class="cov8" title="1">r.Data = menuList</span>
  626. }
  627. }
  628. }
  629. case "menuMode":<span class="cov8" title="1"> //菜单模式更新
  630. if in.MenuMode == "" || (in.MenuMode != "usable" &amp;&amp; in.MenuMode != "all") </span><span class="cov8" title="1">{
  631. r.ErrorCode = -1
  632. r.ErrorMsg = "菜单模式-参数异常"
  633. }</span> else<span class="cov8" title="1"> {
  634. menuModes := entity.BaseMysql.SelectBySql(`SELECT id,value FROM `+entity.WorkCommonly+` WHERE appid=? AND userid=? AND field = ? AND platform = ? LIMIT 1`, in.AppId, in.UserId, in.ActionMode, in.Platform)
  635. if menuModes != nil &amp;&amp; len(*menuModes) &gt; 0 </span><span class="cov8" title="1">{
  636. menuMode := (*menuModes)[0]
  637. if MC.ObjToString(menuMode["value"]) != in.MenuMode </span><span class="cov8" title="1">{
  638. if entity.BaseMysql.UpdateOrDeleteBySql(`UPDATE `+entity.WorkCommonly+` SET value = ? WHERE id = ?`, in.MenuMode, MC.IntAll(menuMode["id"])) &lt; 0 </span><span class="cov0" title="0">{
  639. r.ErrorCode = -1
  640. r.ErrorMsg = "菜单模式-更新异常"
  641. }</span>
  642. }
  643. } else<span class="cov0" title="0"> {
  644. if entity.BaseMysql.Insert(entity.WorkCommonly, map[string]interface{}{
  645. "appid": in.AppId,
  646. "userid": in.UserId,
  647. "field": in.ActionMode,
  648. "platform": in.Platform,
  649. "value": in.MenuMode,
  650. }) &lt; 0 </span><span class="cov0" title="0">{
  651. r.ErrorCode = -1
  652. r.ErrorMsg = "菜单模式-插入异常"
  653. }</span>
  654. }
  655. }
  656. }
  657. <span class="cov8" title="1">return</span>
  658. }
  659. //
  660. func GetWorkDesktopMenuMode(in *WorkDesktopMenuInfoReq) (str string, err error) <span class="cov8" title="1">{
  661. if in.UserId == "" </span><span class="cov8" title="1">{
  662. return "", fmt.Errorf("参数异常")
  663. }</span>
  664. <span class="cov8" title="1">str = "all"
  665. menuModes := entity.BaseMysql.SelectBySql(`SELECT value FROM `+entity.WorkCommonly+` WHERE appid=? AND userid=? AND field = 'menuMode' AND platform = ? LIMIT 1`, in.AppId, in.UserId, in.Platform)
  666. if menuModes != nil &amp;&amp; len(*menuModes) &gt; 0 </span><span class="cov8" title="1">{
  667. menuMode := (*menuModes)[0]
  668. if MC.ObjToString(menuMode["value"]) != "" </span><span class="cov8" title="1">{
  669. str = MC.ObjToString(menuMode["value"])
  670. }</span>
  671. }
  672. <span class="cov8" title="1">return</span>
  673. }
  674. //获取工作桌面菜单树
  675. func GetWordDesktopMenuTree(in *WorkDesktopMenuInfoReq) ([]*pb.MenuList, error) <span class="cov8" title="1">{
  676. t1 := time.Now()
  677. //redis缓存
  678. var menuList []*pb.MenuList
  679. RedisMenuKey := fmt.Sprintf(entity.RedisMenuKey, in.AppId, in.Platform, in.UserId)
  680. menuBytes, err := redis.GetBytes(entity.RedisCode, RedisMenuKey)
  681. if err == nil &amp;&amp; len(*menuBytes) &gt; 0 </span><span class="cov8" title="1">{
  682. if json.Unmarshal(*menuBytes, &amp;menuList) == nil </span><span class="cov8" title="1">{
  683. return menuList, nil
  684. }</span>
  685. }
  686. //tidb数据
  687. <span class="cov8" title="1">menuData := entity.BaseMysql.SelectBySql(`SELECT * FROM `+entity.WorkMenu+` WHERE status=0 AND appid=? ORDER BY id ASC`, in.AppId)
  688. if menuData == nil || len(*menuData) == 0 </span><span class="cov0" title="0">{
  689. return nil, errors.New("查询数据异常")
  690. }</span>
  691. <span class="cov8" title="1">wdm := &amp;entity.WorkDesktopMenu{
  692. MenuTree: []*entity.JYMenu{},
  693. UserId: in.UserId,
  694. AppId: in.AppId,
  695. TimeOut: int(in.RedisOutTime),
  696. BigMemberOff: in.BigMemberOff,
  697. }
  698. for _, v := range *menuData </span><span class="cov8" title="1">{
  699. menu := &amp;entity.JYMenu{
  700. Id: MC.IntAll(v["id"]),
  701. Name: MC.ObjToString(v["name"]),
  702. OrderId: MC.IntAll(v["orderid"]),
  703. ParentId: MC.IntAll(v["parentid"]),
  704. PowerIds: MC.ObjToString(v["powerids"]),
  705. CheckCode: MC.IntAll(v["checkcode"]),
  706. Icon: MC.ObjToString(v["icon"]),
  707. AppType: MC.ObjToString(v["apptype"]),
  708. OpenType: MC.ObjToString(v["opentype"]),
  709. }
  710. switch in.Platform </span>{
  711. case "WX":<span class="cov8" title="1">
  712. menu.Url = MC.ObjToString(v["wxurl"])</span>
  713. case "APP":<span class="cov8" title="1">
  714. menu.Url = MC.ObjToString(v["appurl"])</span>
  715. default:<span class="cov8" title="1">
  716. menu.Url = MC.ObjToString(v["pcurl"])</span>
  717. }
  718. <span class="cov8" title="1">if additionalInfo := MC.ObjToString(v["additionalinfo"]); additionalInfo != "" </span><span class="cov8" title="1">{
  719. additional := entity.Additional{}
  720. if json.Unmarshal([]byte(additionalInfo), &amp;additional) == nil </span><span class="cov8" title="1">{
  721. menu.AdditionalInfo = additional
  722. }</span>
  723. }
  724. <span class="cov8" title="1">if menu.Id &gt; 0 </span><span class="cov8" title="1">{
  725. wdm.MenuTree = append(wdm.MenuTree, menu)
  726. }</span>
  727. }
  728. <span class="cov8" title="1">logx.Info("数据长度:", len(wdm.MenuTree), "-- 查询菜单数据耗时:", time.Since(t1))
  729. //jyMenu := wdm.WorkMenuTree(0)
  730. wdm.MenuTree = wdm.WorkMenuTree(0)
  731. logx.Info("菜单树生成耗时:", time.Since(t1))
  732. menuList, err = wdm.WorkMenuFormat()
  733. logx.Info("菜单格式化耗时:", time.Since(t1))
  734. if err == nil &amp;&amp; len(menuList) &gt; 0 </span><span class="cov8" title="1">{
  735. if menuBytes, err := json.Marshal(menuList); err == nil </span><span class="cov8" title="1">{
  736. redisOutTime := int(in.RedisOutTime) + rand.Intn(60*60)
  737. if redis.PutBytes(entity.RedisCode, RedisMenuKey, &amp;menuBytes, redisOutTime) != nil </span><span class="cov0" title="0">{
  738. logx.Info("工作桌面菜单 redis缓存异常")
  739. }</span>
  740. } else<span class="cov0" title="0"> {
  741. logx.Info("菜单数据序列化异常")
  742. }</span>
  743. }
  744. <span class="cov8" title="1">logx.Info("整体耗时:", time.Since(t1))
  745. return menuList, err</span>
  746. }
  747. </pre>
  748. </div>
  749. </body>
  750. <script>
  751. (function() {
  752. var files = document.getElementById('files');
  753. var visible;
  754. files.addEventListener('change', onChange, false);
  755. function select(part) {
  756. if (visible)
  757. visible.style.display = 'none';
  758. visible = document.getElementById(part);
  759. if (!visible)
  760. return;
  761. files.value = part;
  762. visible.style.display = 'block';
  763. location.hash = part;
  764. }
  765. function onChange() {
  766. select(files.value);
  767. window.scrollTo(0, 0);
  768. }
  769. if (location.hash != "") {
  770. select(location.hash.substr(1));
  771. }
  772. if (!visible) {
  773. select("file0");
  774. }
  775. })();
  776. </script>
  777. </html>