user.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. package gn
  2. import (
  3. "eta_gn/eta_bridge/controller/resp"
  4. gnLogic "eta_gn/eta_bridge/logic/gn"
  5. "eta_gn/eta_bridge/models/gn"
  6. gnRequest "eta_gn/eta_bridge/models/request/gn"
  7. "eta_gn/eta_bridge/utils"
  8. "fmt"
  9. "github.com/gin-gonic/gin"
  10. "strings"
  11. "time"
  12. )
  13. func (gc *GuoNengController) AddAccount(c *gin.Context) {
  14. var req gnRequest.AddAccountReq
  15. if e := c.Bind(&req); e != nil {
  16. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", fmt.Sprintf("参数解析失败, %v", e), c)
  17. return
  18. }
  19. if req.UserId == nil || (req.UserId != nil && *req.UserId == "") {
  20. resp.Gn4AResultData(resp.FAIL_CODE, "登录账号标识不可为空", "登录账号标识不可为空", c)
  21. return
  22. }
  23. if req.FirstName == nil || (req.FirstName != nil && *req.FirstName == "") {
  24. resp.Gn4AResultData(resp.FAIL_CODE, "姓名不可为空", "姓名不可为空", c)
  25. return
  26. }
  27. if req.LastName == nil || (req.LastName != nil && *req.LastName == "") {
  28. resp.Gn4AResultData(resp.FAIL_CODE, "姓名不可为空", "姓名不可为空", c)
  29. return
  30. }
  31. if req.UserStatus == nil || (req.UserStatus != nil && *req.UserStatus == "") {
  32. resp.Gn4AResultData(resp.FAIL_CODE, "账号状态不可为空", "账号状态不可为空", c)
  33. return
  34. }
  35. if req.Password == nil || (req.Password != nil && *req.Password == "") {
  36. resp.Gn4AResultData(resp.FAIL_CODE, "密码不可为空", "密码不可为空", c)
  37. return
  38. }
  39. if req.UserStatus != nil {
  40. statsMap := map[string]int{gn.UserStatusActive: 1, gn.UserStatusDisable: 0}
  41. if _, ok := statsMap[*req.UserStatus]; !ok {
  42. resp.Gn4AResultData(resp.FAIL_CODE, "枚举值异常: UserStatus", fmt.Sprintf("枚举值异常, UserStatus: %s", *req.UserStatus), c)
  43. return
  44. }
  45. }
  46. if req.EmpNumber == nil || (req.EmpNumber != nil && *req.EmpNumber == "") {
  47. resp.Gn4AResultData(resp.FAIL_CODE, "员工编号不可为空", "员工编号不可为空", c)
  48. return
  49. }
  50. errMsg, e := gnLogic.AddAccount(req.UserEntity)
  51. if e != nil {
  52. resp.Gn4AResultData(resp.FAIL_CODE, errMsg, fmt.Sprintf("AddAccount: %v", e), c)
  53. return
  54. }
  55. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  56. }
  57. func (gc *GuoNengController) ModifyAccount(c *gin.Context) {
  58. var req gnRequest.ModifyAccountReq
  59. if e := c.Bind(&req); e != nil {
  60. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", fmt.Sprintf("参数解析失败, %v", e), c)
  61. return
  62. }
  63. if req.UserId == nil || (req.UserId != nil && *req.UserId == "") {
  64. resp.Gn4AResultData(resp.FAIL_CODE, "登录账号标识不可为空", "登录账号标识不可为空", c)
  65. return
  66. }
  67. if req.UserStatus != nil {
  68. statsMap := map[string]int{gn.UserStatusActive: 1, gn.UserStatusDisable: 0}
  69. if _, ok := statsMap[*req.UserStatus]; !ok {
  70. resp.Gn4AResultData(resp.FAIL_CODE, "枚举值异常: UserStatus", fmt.Sprintf("枚举值异常, UserStatus: %s", *req.UserStatus), c)
  71. return
  72. }
  73. }
  74. errMsg, e := gnLogic.ModifyAccount(req.UserEntity)
  75. if e != nil {
  76. resp.Gn4AResultData(resp.FAIL_CODE, errMsg, fmt.Sprintf("ModifyAccount: %v", e), c)
  77. return
  78. }
  79. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  80. }
  81. func (gc *GuoNengController) DeleteAccount(c *gin.Context) {
  82. var req gnRequest.DeleteAccountReq
  83. if e := c.Bind(&req); e != nil {
  84. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", fmt.Sprintf("参数解析失败, %v", e), c)
  85. return
  86. }
  87. if req.UserId == "" {
  88. resp.Gn4AResultData(resp.FAIL_CODE, "登录账号标识不可为空", "登录账号标识不可为空", c)
  89. return
  90. }
  91. errMsg, e := gnLogic.SuspendAccount(req.UserId)
  92. if e != nil {
  93. resp.Gn4AResultData(resp.FAIL_CODE, errMsg, fmt.Sprintf("DeleteAccount: %v", e), c)
  94. return
  95. }
  96. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  97. }
  98. func (gc *GuoNengController) SuspendAccount(c *gin.Context) {
  99. var req gnRequest.SuspendAccountReq
  100. if e := c.Bind(&req); e != nil {
  101. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", fmt.Sprintf("参数解析失败, %v", e), c)
  102. return
  103. }
  104. if req.UserId == "" {
  105. resp.Gn4AResultData(resp.FAIL_CODE, "登录账号标识不可为空", "登录账号标识不可为空", c)
  106. return
  107. }
  108. errMsg, e := gnLogic.SuspendAccount(req.UserId)
  109. if e != nil {
  110. resp.Gn4AResultData(resp.FAIL_CODE, errMsg, fmt.Sprintf("SuspendAccount: %v", e), c)
  111. return
  112. }
  113. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  114. }
  115. func (gc *GuoNengController) RestoreAccount(c *gin.Context) {
  116. var req gnRequest.RestoreAccountReq
  117. if e := c.Bind(&req); e != nil {
  118. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", fmt.Sprintf("参数解析失败, %v", e), c)
  119. return
  120. }
  121. if req.UserId == "" {
  122. resp.Gn4AResultData(resp.FAIL_CODE, "登录账号标识不可为空", "登录账号标识不可为空", c)
  123. return
  124. }
  125. errMsg, e := gnLogic.RestoreAccount(req.UserId)
  126. if e != nil {
  127. resp.Gn4AResultData(resp.FAIL_CODE, errMsg, fmt.Sprintf("RestoreAccount: %v", e), c)
  128. return
  129. }
  130. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  131. }
  132. func (gc *GuoNengController) ChangePassword(c *gin.Context) {
  133. var req gnRequest.ChangePasswordReq
  134. if e := c.Bind(&req); e != nil {
  135. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", fmt.Sprintf("参数解析失败, %v", e), c)
  136. return
  137. }
  138. if req.UserId == "" {
  139. resp.Gn4AResultData(resp.FAIL_CODE, "登录账号标识不可为空", "登录账号标识不可为空", c)
  140. return
  141. }
  142. req.NewPassword = strings.TrimSpace(req.NewPassword)
  143. if req.NewPassword == "" {
  144. resp.Gn4AResultData(resp.FAIL_CODE, "新密码不可为空", "新密码不可为空", c)
  145. return
  146. }
  147. errMsg, e := gnLogic.ChangePassword(req.UserId, req.NewPassword)
  148. if e != nil {
  149. resp.Gn4AResultData(resp.FAIL_CODE, errMsg, fmt.Sprintf("ChangePassword: %v", e), c)
  150. return
  151. }
  152. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  153. }
  154. func (gc *GuoNengController) SyncMdmOrganization(c *gin.Context) {
  155. var req gnRequest.SyncMdmOrganizationReq
  156. if e := c.Bind(&req); e != nil {
  157. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", "参数解析失败", c)
  158. return
  159. }
  160. req.MainFieldComstruCode = strings.TrimSpace(req.MainFieldComstruCode)
  161. if req.MainFieldComstruCode == "" {
  162. resp.Gn4AResultData(resp.FAIL_CODE, "组织机构编码不可为空", "组织机构编码不可为空", c)
  163. return
  164. }
  165. ob := new(gn.MDM_COMSTRU)
  166. cond := ` AND Main_Field_Comstru_Code = ?`
  167. pars := make([]interface{}, 0)
  168. pars = append(pars, req.MainFieldComstruCode)
  169. item, e := ob.GetItemByCondition(cond, pars)
  170. if e != nil && !utils.IsErrNoRow(e) {
  171. resp.Gn4AResultData(resp.FAIL_CODE, "组织信息异常", fmt.Sprintf("获取MDM组织信息失败, %v", e), c)
  172. return
  173. }
  174. if item != nil && item.Id > 0 {
  175. updateCols := []string{"Main_Field_Comstru_Code_HR", "Main_Field_Comstru_Type_HR", "ZDWLX", "Main_Field_Comstru_Name_HR", "Main_Field_Comstru_Short_Name_HR", "Main_Field_ParentAdmin_Comstru_Code_HR", "Main_Field_ParentAdmin_Comstru_Code", "Main_Field_ParentAdmin_Comstru_Name", "Main_Field_Company_Level", "Main_Field_Secondcomstrucodehr", "Main_Field_Sh_Business_Type", "Main_Field_YZGDWZCNDGX", "Main_Field_Order_HR", "Main_Field_Company_Code", "Main_Field_Company_Chain", "Main_Field_PARENTCOMPANYVIRTUAL", "ZQYZT", "ModifyTime"}
  176. item.MainFieldComstruCodeHR = req.MainFieldComstruCodeHR
  177. item.MainFieldComstruTypeHR = req.MainFieldComstruTypeHR
  178. item.ZDWLX = req.ZDWLX
  179. item.MainFieldComstruNameHR = req.MainFieldComstruNameHR
  180. item.MainFieldComstruShortNameHR = req.MainFieldComstruShortNameHR
  181. item.MainFieldParentAdminComstruCodeHR = req.MainFieldParentAdminComstruCodeHR
  182. item.MainFieldParentAdminComstruCode = req.MainFieldParentAdminComstruCode
  183. item.MainFieldParentAdminComstruName = req.MainFieldParentAdminComstruName
  184. item.MainFieldCompanyLevel = req.MainFieldCompanyLevel
  185. item.MainFieldSecondcomstrucodehr = req.MainFieldSecondcomstrucodehr
  186. item.MainFieldShBusinessType = req.MainFieldShBusinessType
  187. item.MainFieldYZGDWZCNDGX = req.MainFieldYZGDWZCNDGX
  188. item.MainFieldOrderHR = req.MainFieldOrderHR
  189. item.MainFieldCompanyCode = req.MainFieldCompanyCode
  190. item.MainFieldCompanyChain = req.MainFieldCompanyChain
  191. item.MainFieldPARENTCOMPANYVIRTUAL = req.MainFieldPARENTCOMPANYVIRTUAL
  192. item.ZQYZT = req.ZQYZT
  193. item.ModifyTime = time.Now()
  194. if e = item.Update(updateCols); e != nil {
  195. resp.Gn4AResultData(resp.FAIL_CODE, "同步失败", fmt.Sprintf("更新MDM组织信息失败, %v", e), c)
  196. return
  197. }
  198. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  199. return
  200. }
  201. newOrganizer := gn.MDM_COMSTRU{
  202. MainFieldComstruCode: req.MainFieldComstruCode,
  203. MainFieldComstruCodeHR: req.MainFieldComstruCodeHR,
  204. MainFieldComstruTypeHR: req.MainFieldComstruTypeHR,
  205. ZDWLX: req.ZDWLX,
  206. MainFieldComstruNameHR: req.MainFieldComstruNameHR,
  207. MainFieldComstruShortNameHR: req.MainFieldComstruShortNameHR,
  208. MainFieldParentAdminComstruCodeHR: req.MainFieldParentAdminComstruCodeHR,
  209. MainFieldParentAdminComstruCode: req.MainFieldParentAdminComstruCode,
  210. MainFieldParentAdminComstruName: req.MainFieldParentAdminComstruName,
  211. MainFieldCompanyLevel: req.MainFieldCompanyLevel,
  212. MainFieldSecondcomstrucodehr: req.MainFieldSecondcomstrucodehr,
  213. MainFieldShBusinessType: req.MainFieldShBusinessType,
  214. MainFieldYZGDWZCNDGX: req.MainFieldYZGDWZCNDGX,
  215. MainFieldOrderHR: req.MainFieldOrderHR,
  216. MainFieldCompanyCode: req.MainFieldCompanyCode,
  217. MainFieldCompanyChain: req.MainFieldCompanyChain,
  218. MainFieldPARENTCOMPANYVIRTUAL: req.MainFieldPARENTCOMPANYVIRTUAL,
  219. ZQYZT: req.ZQYZT,
  220. CreateTime: time.Now(),
  221. ModifyTime: time.Now(),
  222. }
  223. if e = newOrganizer.Create(); e != nil {
  224. resp.Gn4AResultData(resp.FAIL_CODE, "同步失败", fmt.Sprintf("新增MDM组织信息失败, %v", e), c)
  225. return
  226. }
  227. go func() {
  228. _ = gnLogic.SyncSysDepartment(&newOrganizer)
  229. }()
  230. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  231. }
  232. func (gc *GuoNengController) SyncMdmEmployee(c *gin.Context) {
  233. var req gnRequest.SyncMdmEmployeeReq
  234. if e := c.Bind(&req); e != nil {
  235. resp.Gn4AResultData(resp.FAIL_CODE, "参数有误", "参数解析失败", c)
  236. return
  237. }
  238. req.MainFieldEmployeeCode = strings.TrimSpace(req.MainFieldEmployeeCode)
  239. if req.MainFieldEmployeeCode == "" {
  240. resp.Gn4AResultData(resp.FAIL_CODE, "员工编码不可为空", "员工编码不可为空", c)
  241. return
  242. }
  243. ob := new(gn.MDM_EMPLOYEE)
  244. cond := ` AND Main_Field_Employee_Code = ?`
  245. pars := make([]interface{}, 0)
  246. pars = append(pars, req.MainFieldEmployeeCode)
  247. item, e := ob.GetItemByCondition(cond, pars)
  248. if e != nil && !utils.IsErrNoRow(e) {
  249. resp.Gn4AResultData(resp.FAIL_CODE, "员工信息异常", fmt.Sprintf("获取MDM员工信息失败, %v", e), c)
  250. return
  251. }
  252. relations := make([]*gn.MDM_RELA_COMSTRU_EMPLOYEE, 0)
  253. if len(req.MDM_MATERIAL_PROPS) > 0 {
  254. for _, v := range req.MDM_MATERIAL_PROPS {
  255. relations = append(relations, &gn.MDM_RELA_COMSTRU_EMPLOYEE{
  256. Main_Field_Employee_Code: req.MainFieldEmployeeCode,
  257. TuplesFieldCompanyCode: v.TuplesFieldCompanyCode,
  258. TuplesFieldCompanyName: v.TuplesFieldCompanyName,
  259. TuplesFieldDepartmentCode: v.TuplesFieldDepartmentCode,
  260. TuplesFieldDepartmentName: v.TuplesFieldDepartmentName,
  261. CreateTime: time.Now(),
  262. ModifyTime: time.Now(),
  263. })
  264. }
  265. }
  266. var isUpdate bool
  267. employeeOb := new(gn.MDM_EMPLOYEE)
  268. if item != nil && item.Id > 0 {
  269. isUpdate = true
  270. updateCols := []string{"Main_Field_Employee_FirstName", "Main_Field_Employee_LastName", "Main_Field_Gender", "Main_Field_Empolyee_Group", "Main_Field_Office_Telephone", "Main_Field_Date_Type", "Main_Field_Employee_Status", "Main_Field_Delete_Flag", "Main_Field_Email", "Main_Field_Company_code", "Main_Field_Secondcomstrucodehr", "Main_Field_Company_Chain", "ModifyTime"}
  271. item.MainFieldEmployeeFirstName = req.MainFieldEmployeeFirstName
  272. item.MainFieldEmployeeLastName = req.MainFieldEmployeeLastName
  273. item.MainFieldGender = req.MainFieldGender
  274. item.MainFieldEmpolyeeGroup = req.MainFieldEmpolyeeGroup
  275. item.MainFieldOfficeTelephone = req.MainFieldOfficeTelephone
  276. item.MainFieldDateType = req.MainFieldDateType
  277. item.MainFieldEmployeeStatus = req.MainFieldEmployeeStatus
  278. item.MainFieldDeleteFlag = req.MainFieldDeleteFlag
  279. item.MainFieldEmail = req.MainFieldEmail
  280. item.MainFieldCompanyCode = req.MainFieldCompanyCode
  281. item.MainFieldSecondcomstrucodehr = req.MainFieldSecondcomstrucodehr
  282. item.MainFieldCompanyChain = req.MainFieldCompanyChain
  283. item.ModifyTime = time.Now()
  284. if e = employeeOb.UpdateEmployee(item, updateCols, relations); e != nil {
  285. resp.Gn4AResultData(resp.FAIL_CODE, "同步失败", fmt.Sprintf("更新MDM组织信息失败, %v", e), c)
  286. return
  287. }
  288. }
  289. if !isUpdate {
  290. newEmployee := &gn.MDM_EMPLOYEE{
  291. MainFieldEmployeeCode: req.MainFieldEmployeeCode,
  292. MainFieldEmployeeFirstName: req.MainFieldEmployeeFirstName,
  293. MainFieldEmployeeLastName: req.MainFieldEmployeeLastName,
  294. MainFieldGender: req.MainFieldGender,
  295. MainFieldEmpolyeeGroup: req.MainFieldEmpolyeeGroup,
  296. MainFieldOfficeTelephone: req.MainFieldOfficeTelephone,
  297. MainFieldDateType: req.MainFieldDateType,
  298. MainFieldEmployeeStatus: req.MainFieldEmployeeStatus,
  299. MainFieldDeleteFlag: req.MainFieldDeleteFlag,
  300. MainFieldEmail: req.MainFieldEmail,
  301. MainFieldCompanyCode: req.MainFieldCompanyCode,
  302. MainFieldSecondcomstrucodehr: req.MainFieldSecondcomstrucodehr,
  303. MainFieldCompanyChain: req.MainFieldCompanyChain,
  304. CreateTime: time.Now(),
  305. ModifyTime: time.Now(),
  306. }
  307. if e = employeeOb.CreateEmployee(newEmployee, relations); e != nil {
  308. resp.Gn4AResultData(resp.FAIL_CODE, "同步失败", fmt.Sprintf("新增MDM员工信息失败, %v", e), c)
  309. return
  310. }
  311. }
  312. resp.Gn4AResultData(resp.GN_OK_CODE, "成功", "", c)
  313. }