entities.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. package main
  2. import (
  3. "encoding/json"
  4. "time"
  5. )
  6. type AttendanceState = int
  7. const (
  8. 出勤 = iota
  9. 请假
  10. 出差
  11. 外出
  12. 缺卡
  13. 加班
  14. 休息
  15. 调班
  16. )
  17. const (
  18. 年假 = iota
  19. 调休
  20. )
  21. const (
  22. 小时 = iota
  23. )
  24. type EmailSetting struct {
  25. Id string //ID
  26. Host string //邮件服务器地址
  27. Port string //端口
  28. Sender string //发送者账号
  29. SenderPassword string //发送者密码
  30. }
  31. type DomainSetting struct {
  32. Id string //ID
  33. Domain string //域名
  34. }
  35. type ViewCode struct {
  36. Id string //Code Id
  37. Code string //Code内容
  38. Receiver string //接收者
  39. WorkingDayStatisticsIds []string //统计ID列表
  40. ExpiredTime time.Time //Code 过期时间
  41. }
  42. func (viewCode ViewCode) MarshalJSON() ([]byte, error) {
  43. type Alias ViewCode
  44. return json.Marshal(&struct {
  45. Alias
  46. ExpiredTime string `json:"ExpiredTime"`
  47. }{Alias: Alias(viewCode), ExpiredTime: dateTimeToStr(viewCode.ExpiredTime)})
  48. }
  49. func (viewCode *ViewCode) UnmarshalJSON(data []byte) (err error) {
  50. type Alias ViewCode
  51. temp := new(struct {
  52. Alias
  53. ExpiredTime string `json:"ExpiredTime"`
  54. })
  55. err = json.Unmarshal(data, temp)
  56. if err == nil {
  57. viewCode.Id = temp.Id
  58. viewCode.Code = temp.Code
  59. viewCode.Receiver = temp.Receiver
  60. viewCode.WorkingDayStatisticsIds = make([]string, len(temp.WorkingDayStatisticsIds))
  61. copy(viewCode.WorkingDayStatisticsIds, temp.WorkingDayStatisticsIds)
  62. viewCode.ExpiredTime = strToDateTime(temp.ExpiredTime)
  63. }
  64. return err
  65. }
  66. type Admin struct {
  67. Id string //管理员ID
  68. Name string //管理员名
  69. Password string //管理员密码
  70. }
  71. type HolidayInfo struct {
  72. Id string //调休日ID
  73. Title string //调休日标题
  74. Holiday time.Time //被调休日
  75. IsAdjusted bool //是否调班
  76. IsNationalLegal bool //是否国家法定
  77. AdjustedDay time.Time //调整到哪天上班
  78. }
  79. func (holidayInfo HolidayInfo) MarshalJSON() ([]byte, error) {
  80. type Alias HolidayInfo
  81. return json.Marshal(&struct {
  82. Alias
  83. Holiday string `json:"Holiday"`
  84. AdjustedDay string `json:"AdjustedDay"`
  85. }{Alias: Alias(holidayInfo), Holiday: dateTimeToStr(holidayInfo.Holiday), AdjustedDay: dateTimeToStr(holidayInfo.AdjustedDay)})
  86. }
  87. func (holidayInfo *HolidayInfo) UnmarshalJSON(data []byte) (err error) {
  88. type Alias HolidayInfo
  89. temp := new(struct {
  90. Alias
  91. Holiday string `json:"Holiday"`
  92. AdjustedDay string `json:"AdjustedDay"`
  93. })
  94. err = json.Unmarshal(data, temp)
  95. if err == nil {
  96. holidayInfo.Id = temp.Id
  97. holidayInfo.Title = temp.Title
  98. holidayInfo.Holiday = strToDateTime(temp.Holiday)
  99. holidayInfo.IsAdjusted = temp.IsAdjusted
  100. holidayInfo.IsNationalLegal = temp.IsNationalLegal
  101. holidayInfo.AdjustedDay = strToDateTime(temp.AdjustedDay)
  102. }
  103. return err
  104. }
  105. type AttendanceRules struct {
  106. Title string //班次名
  107. Start time.Time //班次开始时间
  108. End time.Time //班次结束时间
  109. }
  110. func (attendanceRules AttendanceRules) MarshalJSON() ([]byte, error) {
  111. type Alias AttendanceRules
  112. return json.Marshal(&struct {
  113. Alias
  114. Start string `json:"Start"`
  115. End string `json:"End"`
  116. }{Alias: Alias(attendanceRules), Start: dateTimeToStr(attendanceRules.Start), End: dateTimeToStr(attendanceRules.End)})
  117. }
  118. func (attendanceRules *AttendanceRules) UnmarshalJSON(data []byte) (err error) {
  119. type Alias AttendanceRules
  120. temp := new(struct {
  121. Alias
  122. Start string `json:"Start"`
  123. End string `json:"End"`
  124. })
  125. err = json.Unmarshal(data, temp)
  126. if err == nil {
  127. attendanceRules.Title = temp.Title
  128. attendanceRules.Start = strToDateTime(temp.Start)
  129. attendanceRules.End = strToDateTime(temp.End)
  130. }
  131. return err
  132. }
  133. type Department struct {
  134. Id int //部门ID
  135. Name string //部门名
  136. ParentId int //上级部门ID
  137. }
  138. type Employee struct {
  139. Id string //员工ID
  140. Name string //员工名
  141. Title string //职位
  142. DepartmentId int //部门Id
  143. Email string //电子邮箱
  144. AttendanceRules AttendanceRules //考勤班次
  145. IsReviewer bool //是否审核人员
  146. IsStruggle bool //是否参加奋斗计划
  147. }
  148. // AttendanceData From 钉钉
  149. type AttendanceData struct {
  150. EmployeeId string
  151. Day time.Time
  152. Start string
  153. End string
  154. StartTime time.Time
  155. EndTime time.Time
  156. StartResult string
  157. EndResult string
  158. Approve string
  159. State AttendanceState
  160. }
  161. type WorkingDayInfo struct {
  162. Id string //工作日记录ID
  163. StatisticsId string //统计表ID
  164. EmployeeId string //员工ID
  165. Day time.Time //日期
  166. Start time.Time //上班时间
  167. StartResult string //开始说明
  168. End time.Time //下班时间
  169. EndResult string //结束说明
  170. RequiredWorkingHours float64 //当天需要工作的标准时间
  171. WorkingHours float64 //实际工作小时数
  172. IsHoliday bool //是否节假日
  173. HolidayAdjusted bool //节假日已调整
  174. HolidayName string //节假日名
  175. AdjustedDay time.Time //调整日期,如果是调班的
  176. IsWeekend bool //是否是周末
  177. State AttendanceState //出勤状态
  178. ObtainedUnits int //加班的单位数,以2.5为单位
  179. AdjustedObtainedUnits int //调整过的加班单位数
  180. AdjustDescription string //调整说明
  181. Adjusted bool //是否调整过
  182. }
  183. func (workingDayInfo WorkingDayInfo) MarshalJSON() ([]byte, error) {
  184. type Alias WorkingDayInfo
  185. return json.Marshal(&struct {
  186. Alias
  187. Day string `json:"Day"`
  188. Start string `json:"Start"`
  189. End string `json:"End"`
  190. AdjustedDay string `json:"AdjustedDay"`
  191. }{Alias: Alias(workingDayInfo), Day: dateTimeToStr(workingDayInfo.Day), Start: dateTimeToStr(workingDayInfo.Start), End: dateTimeToStr(workingDayInfo.End), AdjustedDay: dateTimeToStr(workingDayInfo.AdjustedDay)})
  192. }
  193. func (workingDayInfo *WorkingDayInfo) UnmarshalJSON(data []byte) (err error) {
  194. type Alias WorkingDayInfo
  195. temp := new(struct {
  196. Alias
  197. Day string `json:"Day"`
  198. Start string `json:"Start"`
  199. End string `json:"End"`
  200. AdjustedDay string `json:"AdjustedDay"`
  201. })
  202. err = json.Unmarshal(data, temp)
  203. if err == nil {
  204. workingDayInfo.Id = temp.Id
  205. workingDayInfo.StatisticsId = temp.StatisticsId
  206. workingDayInfo.EmployeeId = temp.EmployeeId
  207. workingDayInfo.Day = dateTimeToDate(strToDateTime(temp.Day))
  208. workingDayInfo.Start = dateTimeToTime(strToDateTime(temp.Start))
  209. workingDayInfo.StartResult = temp.StartResult
  210. workingDayInfo.End = dateTimeToTime(strToDateTime(temp.End))
  211. workingDayInfo.EndResult = temp.EndResult
  212. workingDayInfo.RequiredWorkingHours = temp.RequiredWorkingHours
  213. workingDayInfo.WorkingHours = temp.WorkingHours
  214. workingDayInfo.IsHoliday = temp.IsHoliday
  215. workingDayInfo.HolidayName = temp.HolidayName
  216. workingDayInfo.HolidayAdjusted = temp.HolidayAdjusted
  217. workingDayInfo.AdjustedDay = dateTimeToDate(strToDateTime(temp.AdjustedDay))
  218. workingDayInfo.IsWeekend = temp.IsWeekend
  219. workingDayInfo.State = temp.State
  220. workingDayInfo.ObtainedUnits = temp.ObtainedUnits
  221. workingDayInfo.AdjustedObtainedUnits = temp.AdjustedObtainedUnits
  222. workingDayInfo.AdjustDescription = temp.AdjustDescription
  223. workingDayInfo.Adjusted = temp.Adjusted
  224. }
  225. return err
  226. }
  227. type WorkingDayStatistics struct {
  228. Id string
  229. Employee Employee //员工信息
  230. DepartmentId int //部门ID
  231. DepartmentName string //部门名
  232. Start time.Time //开始时间
  233. End time.Time //结束时间
  234. RequiredReachedCount int //需达标次数
  235. ReachedCount int //达标次数
  236. AdjustedReachedCount int //调整后增加的次数
  237. Adjusted bool //是否已经调整过
  238. AdjustDescription string //调整说明
  239. AdjustedBy string //调整人
  240. Comment string //备注
  241. Reviewer string //审核人
  242. }
  243. func (workingDayStatistics WorkingDayStatistics) MarshalJSON() ([]byte, error) {
  244. type Alias WorkingDayStatistics
  245. return json.Marshal(&struct {
  246. Alias
  247. Start string `json:"Start"`
  248. End string `json:"End"`
  249. }{Alias: Alias(workingDayStatistics), Start: dateTimeToStr(workingDayStatistics.Start), End: dateTimeToStr(workingDayStatistics.End)})
  250. }
  251. func (workingDayStatistics *WorkingDayStatistics) UnmarshalJSON(data []byte) (err error) {
  252. type Alias WorkingDayStatistics
  253. temp := new(struct {
  254. Alias
  255. Start string `json:"Start"`
  256. End string `json:"End"`
  257. })
  258. err = json.Unmarshal(data, temp)
  259. if err == nil {
  260. workingDayStatistics.Id = temp.Id
  261. workingDayStatistics.Employee = temp.Employee
  262. workingDayStatistics.DepartmentId = temp.DepartmentId
  263. workingDayStatistics.DepartmentName = temp.DepartmentName
  264. workingDayStatistics.Start = strToDateTime(temp.Start)
  265. workingDayStatistics.End = strToDateTime(temp.End)
  266. workingDayStatistics.RequiredReachedCount = temp.RequiredReachedCount
  267. workingDayStatistics.ReachedCount = temp.ReachedCount
  268. workingDayStatistics.AdjustedReachedCount = temp.AdjustedReachedCount
  269. workingDayStatistics.Adjusted = temp.Adjusted
  270. workingDayStatistics.AdjustDescription = temp.AdjustDescription
  271. workingDayStatistics.AdjustedBy = temp.AdjustedBy
  272. workingDayStatistics.Comment = temp.Comment
  273. workingDayStatistics.Reviewer = temp.Reviewer
  274. }
  275. return err
  276. }
  277. type StatisticsTable struct {
  278. Id string //工作统计集合ID
  279. Title string //工作统计集合名称
  280. RequiredReachedCount int //需达标的次数
  281. WorkingDayStatisticsIds []string //工作统计ID集合
  282. CreateTime time.Time //创建时间
  283. }
  284. func (workingDayStatisticsCollection StatisticsTable) MarshalJSON() ([]byte, error) {
  285. type Alias StatisticsTable
  286. return json.Marshal(&struct {
  287. Alias
  288. CreateTime string `json:"CreateTime"`
  289. }{Alias: Alias(workingDayStatisticsCollection), CreateTime: dateTimeToStr(workingDayStatisticsCollection.CreateTime)})
  290. }
  291. func (workingDayStatisticsCollection *StatisticsTable) UnmarshalJSON(data []byte) (err error) {
  292. type Alias StatisticsTable
  293. temp := new(struct {
  294. Alias
  295. CreateTime string `json:"CreateTime"`
  296. })
  297. err = json.Unmarshal(data, temp)
  298. if err == nil {
  299. workingDayStatisticsCollection.Id = temp.Id
  300. workingDayStatisticsCollection.Title = temp.Title
  301. workingDayStatisticsCollection.RequiredReachedCount = temp.RequiredReachedCount
  302. workingDayStatisticsCollection.WorkingDayStatisticsIds = temp.WorkingDayStatisticsIds
  303. workingDayStatisticsCollection.CreateTime = strToDateTime(temp.CreateTime)
  304. }
  305. return err
  306. }
  307. type CheckHistory struct {
  308. CheckDay time.Time //查询时间
  309. TotalUnits int //当前达标次数
  310. }
  311. type MessageTemplate struct {
  312. Id string //模板ID
  313. Name string //模板名
  314. Content string //模板内容
  315. }
  316. type LeaveQuota struct {
  317. Id string //员工ID
  318. LeaveType string //假期类型
  319. Unit int //单位
  320. Quota int //余额
  321. Used int //已使用
  322. }
  323. type DashBoardItem struct {
  324. Id string //ID
  325. ItemName string //数据类型
  326. Data int //数值
  327. }