Salary.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. package controllers
  2. import (
  3. "ERP_salary/Nats"
  4. "ERP_salary/Nats/NatsServer"
  5. "ERP_salary/conf"
  6. "ERP_salary/logs"
  7. "ERP_salary/models/Account"
  8. "ERP_salary/models/Salary"
  9. "fmt"
  10. "github.com/beego/beego/v2/adapter/orm"
  11. beego "github.com/beego/beego/v2/server/web"
  12. natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats"
  13. userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
  14. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  15. "math"
  16. "os"
  17. "strings"
  18. "time"
  19. )
  20. type SalaryController struct {
  21. beego.Controller
  22. User userlibs.User
  23. }
  24. func (c *SalaryController) Prepare() {
  25. c.User = *Account.User_r
  26. }
  27. // 管理员工资列表 默认显示上月工资
  28. func (c *SalaryController) Salary_List() {
  29. var r_jsons lib.R_JSONS
  30. T_date := c.GetString("T_date")
  31. var err error
  32. // 年月 2023-01
  33. if len(T_date) == 0 {
  34. T_date = time.Now().AddDate(0, -1, 0).Format("2006-01")
  35. }
  36. _, err = time.Parse("2006-01", T_date)
  37. if err != nil {
  38. c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
  39. c.ServeJSON()
  40. return
  41. }
  42. userList, _ := NatsServer.Read_User_List_All()
  43. Account.Read_User_All_Map(userList)
  44. var salary_r Salary.Salary_R
  45. salary_List, num := Salary.Read_Salary_List("", T_date, 0, 0, 9999)
  46. for _, salary := range salary_List {
  47. salary_r.T_base += salary.T_base
  48. salary_r.T_post += salary.T_post
  49. salary_r.T_seniority += salary.T_seniority
  50. salary_r.T_actual_Perf += salary.T_actual_Perf
  51. salary_r.T_back_payment += salary.T_back_payment
  52. salary_r.T_attendance += salary.T_attendance
  53. salary_r.T_cut_payment += salary.T_cut_payment
  54. salary_r.T_laballot += salary.T_laballot
  55. salary_r.T_pension_insurance += salary.T_pension_insurance
  56. salary_r.T_unemployment_insurance += salary.T_unemployment_insurance
  57. salary_r.T_medical_insurance += salary.T_medical_insurance
  58. salary_r.T_large_medical_insurance += salary.T_large_medical_insurance
  59. salary_r.T_housing_fund += salary.T_housing_fund
  60. salary_r.T_tax += salary.T_tax
  61. salary_r.T_laborage += salary.T_laborage
  62. salary_r.T_total += salary.T_total
  63. }
  64. salary_r.T_user_name = "合计"
  65. salary_r.T_user_dept = "合计"
  66. salary_r.T_user_post = "合计"
  67. salary_List = append(salary_List, salary_r)
  68. r_jsons.Data = salary_List
  69. r_jsons.Num = num
  70. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  71. c.ServeJSON()
  72. return
  73. }
  74. func (c *SalaryController) Salary_Get() {
  75. T_uuid := c.GetString("T_uuid")
  76. T_date := c.GetString("T_date")
  77. salary, err := Salary.Read_Salary_ByT_uuid_T_date(T_uuid, T_date)
  78. if err != nil {
  79. if err.Error() == orm.ErrNoRows.Error() {
  80. salary_new, err := Salary.Read_Latest_Salary_ByT_uid(T_uuid)
  81. if err != nil {
  82. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  83. c.ServeJSON()
  84. return
  85. }
  86. salary_new.T_State = 3
  87. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: salary_new}
  88. c.ServeJSON()
  89. return
  90. }
  91. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  92. c.ServeJSON()
  93. return
  94. }
  95. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Salary.SalaryToSalary_R(salary)}
  96. c.ServeJSON()
  97. return
  98. }
  99. func (c *SalaryController) Salary_User_Get() {
  100. T_date := c.GetString("T_date")
  101. var err error
  102. // 年月 2023-01
  103. if len(T_date) == 0 {
  104. T_date = time.Now().AddDate(0, -1, 0).Format("2006-01")
  105. }
  106. salary, err := Salary.Read_Salary_ByT_date(c.User.T_uuid, T_date)
  107. if err != nil {
  108. if err.Error() == orm.ErrNoRows.Error() {
  109. c.Data["json"] = lib.JSONS{Code: 202, Msg: "暂无当月数据!"}
  110. c.ServeJSON()
  111. return
  112. }
  113. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  114. c.ServeJSON()
  115. return
  116. }
  117. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Salary.SalaryToSalary_R(salary)}
  118. c.ServeJSON()
  119. return
  120. }
  121. func (c *SalaryController) Salary_User_List() {
  122. var r_jsons lib.R_JSONS
  123. page, _ := c.GetInt("page")
  124. if page < 1 {
  125. page = 1
  126. }
  127. page_z, _ := c.GetInt("page_z")
  128. if page_z < 1 {
  129. page_z = conf.Page_size
  130. }
  131. r_jsons.Data, r_jsons.Num = Salary.Read_Salary_List(c.User.T_uuid, "", 2, page, page_z)
  132. r_jsons.Page = page
  133. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  134. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  135. c.ServeJSON()
  136. return
  137. }
  138. // 添加或修改
  139. func (c *SalaryController) Salary_Post() {
  140. T_uuid := c.GetString("T_uuid")
  141. // 年月 2023-01
  142. T_date := c.GetString("T_date")
  143. if len(T_date) > 0 {
  144. _, err := time.Parse("2006-01", T_date)
  145. if err != nil {
  146. c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
  147. c.ServeJSON()
  148. return
  149. }
  150. }
  151. T_base, _ := c.GetFloat("T_base")
  152. T_post, _ := c.GetFloat("T_post")
  153. T_seniority, _ := c.GetFloat("T_seniority")
  154. T_perf, _ := c.GetFloat("T_perf")
  155. T_perf_score, _ := c.GetInt("T_perf_score")
  156. T_back_payment, _ := c.GetFloat("T_back_payment")
  157. T_attendance, _ := c.GetFloat("T_attendance")
  158. T_cut_payment, _ := c.GetFloat("T_cut_payment")
  159. T_pension_insurance, _ := c.GetFloat("T_pension_insurance")
  160. T_unemployment_insurance, _ := c.GetFloat("T_unemployment_insurance")
  161. T_medical_insurance, _ := c.GetFloat("T_medical_insurance")
  162. T_Large_medical_insurance, _ := c.GetFloat("T_large_medical_insurance")
  163. T_housing_fund, _ := c.GetFloat("T_housing_fund")
  164. T_tax, _ := c.GetFloat("T_tax")
  165. T_remark := c.GetString("T_remark")
  166. salary, err := Salary.Read_Salary_ByT_uuid_T_date(T_uuid, T_date)
  167. if err != nil && err.Error() != orm.ErrNoRows.Error() {
  168. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  169. c.ServeJSON()
  170. return
  171. }
  172. var_ := Salary.Salary{
  173. T_uid: T_uuid,
  174. T_date: T_date,
  175. T_base: float32(T_base),
  176. T_post: float32(T_post),
  177. T_seniority: float32(T_seniority),
  178. T_perf: float32(T_perf),
  179. T_perf_score: T_perf_score,
  180. T_back_payment: float32(T_back_payment),
  181. T_attendance: float32(T_attendance),
  182. T_cut_payment: float32(T_cut_payment),
  183. T_pension_insurance: float32(T_pension_insurance),
  184. T_unemployment_insurance: float32(T_unemployment_insurance),
  185. T_medical_insurance: float32(T_medical_insurance),
  186. T_large_medical_insurance: float32(T_Large_medical_insurance),
  187. T_housing_fund: float32(T_housing_fund),
  188. T_tax: float32(T_tax),
  189. T_remark: T_remark,
  190. T_State: 1,
  191. }
  192. if salary.Id == 0 {
  193. var_.Id, err = Salary.Add_Salary(var_)
  194. if err != nil {
  195. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
  196. c.ServeJSON()
  197. return
  198. }
  199. } else {
  200. var_.Id = salary.Id
  201. cols := []string{"T_base", "T_post", "T_seniority", "T_perf", "T_perf_score", "T_back_payment", "T_attendance", "T_cut_payment",
  202. "T_pension_insurance", "T_unemployment_insurance", "T_medical_insurance", "T_large_medical_insurance", "T_housing_fund", "T_tax",
  203. "T_remark"}
  204. _, err = Salary.Update_Salary(var_, cols...)
  205. if err != nil {
  206. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  207. c.ServeJSON()
  208. return
  209. }
  210. }
  211. NatsServer.AddUserLogs(c.User.T_uuid, "薪资管理", "添加", var_)
  212. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: var_.Id}
  213. c.ServeJSON()
  214. return
  215. }
  216. // 发送工资条
  217. func (c *SalaryController) Send_Salary() {
  218. T_id, _ := c.GetInt("T_id")
  219. salary, err := Salary.Read_Salary_ById(T_id)
  220. id, err := Salary.Send_Salary(salary)
  221. year, month := strings.Split(salary.T_date, "-")[0], strings.Split(salary.T_date, "-")[1]
  222. if err != nil {
  223. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  224. c.ServeJSON()
  225. return
  226. }
  227. NatsServer.AddUserLogs(c.User.T_uuid, "薪资管理", "发送工资条", id)
  228. if salary.T_State == 1 {
  229. NatsServer.AddNews(salary.T_uid, fmt.Sprintf("【工资条】您的%s年%s月工资条已送达,请查收!", year, month), conf.MySalaryNewsUrl)
  230. }
  231. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  232. c.ServeJSON()
  233. return
  234. }
  235. // 导出工资数据列表
  236. func (c *SalaryController) Salary_Excel() {
  237. // 年月 2023-01
  238. T_date := c.GetString("T_date")
  239. var da time.Time
  240. var err error
  241. if len(T_date) == 0 {
  242. T_date = time.Now().AddDate(0, -1, 0).Format("2006-01")
  243. }
  244. da, err = time.Parse("2006-01", T_date)
  245. if err != nil {
  246. c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
  247. c.ServeJSON()
  248. return
  249. }
  250. year, month := strings.Split(T_date, "-")[0], strings.Split(T_date, "-")[1]
  251. f := excelize.NewFile() // 设置单元格的值
  252. Style1, _ := f.NewStyle(
  253. &excelize.Style{
  254. Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
  255. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  256. })
  257. Style2, _ := f.NewStyle(
  258. &excelize.Style{
  259. Font: &excelize.Font{Bold: true, Size: 11, Family: "宋体"},
  260. Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
  261. })
  262. f.MergeCell("Sheet1", "A1", "W1")
  263. f.SetRowStyle("Sheet1", 1, 1, Style1)
  264. f.SetRowHeight("Sheet1", 1, 50)
  265. f.SetCellValue("Sheet1", "A1", fmt.Sprintf("贵州宝智达网络科技有限公司%s年%s月工资表", year, month))
  266. f.MergeCell("Sheet1", "A2", "W2")
  267. f.SetRowHeight("Sheet1", 2, 30)
  268. f.SetRowStyle("Sheet1", 2, 2, Style2)
  269. day := da.AddDate(0, 1, -1).Day()
  270. f.SetCellValue("Sheet1", "A2", fmt.Sprintf("工资期间:%s年%s月01日至%s年%s月%02d日", year, month, year, month, day))
  271. Style3, _ := f.NewStyle(
  272. &excelize.Style{
  273. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  274. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  275. Border: []excelize.Border{
  276. {Type: "left", Color: "000000", Style: 1},
  277. {Type: "top", Color: "000000", Style: 1},
  278. {Type: "bottom", Color: "000000", Style: 1},
  279. {Type: "right", Color: "000000", Style: 1},
  280. },
  281. })
  282. f.SetCellStyle("Sheet1", "A3", "W3", Style3)
  283. f.SetRowHeight("Sheet1", 3, 60)
  284. // 这里设置表头
  285. f.SetCellValue("Sheet1", "A3", "序号")
  286. f.SetCellValue("Sheet1", "B3", "姓名")
  287. f.SetCellValue("Sheet1", "C3", "部门")
  288. f.SetCellValue("Sheet1", "D3", "岗位")
  289. f.SetCellValue("Sheet1", "E3", "基本工资")
  290. f.SetCellValue("Sheet1", "F3", "岗位工资")
  291. f.SetCellValue("Sheet1", "G3", "工龄工资")
  292. f.SetCellValue("Sheet1", "H3", "绩效金额")
  293. f.SetCellValue("Sheet1", "I3", "绩效得分")
  294. f.SetCellValue("Sheet1", "J3", "实发绩效")
  295. f.SetCellValue("Sheet1", "K3", "其他补款")
  296. f.SetCellValue("Sheet1", "L3", "考勤扣款")
  297. f.SetCellValue("Sheet1", "M3", "其他扣款")
  298. f.SetCellValue("Sheet1", "N3", "应发合计")
  299. f.SetCellValue("Sheet1", "O3", "养老保险")
  300. f.SetCellValue("Sheet1", "P3", "失业保险")
  301. f.SetCellValue("Sheet1", "Q3", "基本医疗保险")
  302. f.SetCellValue("Sheet1", "R3", "大额医疗保险")
  303. f.SetCellValue("Sheet1", "S3", "公积金")
  304. f.SetCellValue("Sheet1", "T3", "个税扣款")
  305. f.SetCellValue("Sheet1", "U3", "扣款合计")
  306. f.SetCellValue("Sheet1", "V3", "实发合计")
  307. f.SetCellValue("Sheet1", "W3", "备注")
  308. // 设置列宽
  309. f.SetColWidth("Sheet1", "A", "D", 10)
  310. f.SetColWidth("Sheet1", "E", "I", 5)
  311. f.SetColWidth("Sheet1", "J", "J", 10)
  312. f.SetColWidth("Sheet1", "K", "M", 5)
  313. f.SetColWidth("Sheet1", "O", "P", 5)
  314. f.SetColWidth("Sheet1", "Q", "R", 6)
  315. f.SetColWidth("Sheet1", "S", "T", 5)
  316. f.SetColWidth("Sheet1", "U", "V", 12)
  317. f.SetColWidth("Sheet1", "W", "W", 20)
  318. // 冻结1-3行
  319. f.SetPanes("Sheet1", &excelize.Panes{
  320. Freeze: true,
  321. Split: false,
  322. XSplit: 2,
  323. YSplit: 3,
  324. TopLeftCell: "A1",
  325. ActivePane: "topRight",
  326. })
  327. // 过滤器
  328. f.AutoFilter("Sheet1", "A3:V3", nil)
  329. userList, _ := NatsServer.Read_User_List_All()
  330. Account.Read_User_All_Map(userList)
  331. salary_List, _ := Salary.Read_Salary_List("", T_date, 0, 0, 9999)
  332. if len(salary_List) == 0 {
  333. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("暂无%s年%s月工资数据", year, month)}
  334. c.ServeJSON()
  335. return
  336. }
  337. // 循环写入数据
  338. line := 4
  339. var base, post, seniority, actual_Perf, back_payment, attendance, cut_payment, laballot float32
  340. var pension_insurance, unemployment_insurance, medical_insurance, Large_medical_insurance, housing_fund, tax, laborage, total float32
  341. for i, salary := range salary_List {
  342. if len(salary.T_user_post) < 7 {
  343. f.SetRowHeight("Sheet1", line, 22)
  344. }
  345. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  346. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), salary.T_user_name)
  347. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), salary.T_user_dept)
  348. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), salary.T_user_post)
  349. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), salary.T_base)
  350. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), salary.T_post)
  351. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), salary.T_seniority)
  352. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), salary.T_perf)
  353. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), salary.T_perf_score)
  354. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), salary.T_actual_Perf)
  355. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), salary.T_back_payment)
  356. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), salary.T_attendance)
  357. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), salary.T_cut_payment)
  358. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), salary.T_laballot)
  359. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), salary.T_pension_insurance)
  360. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), salary.T_unemployment_insurance)
  361. f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), salary.T_medical_insurance)
  362. f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), salary.T_large_medical_insurance)
  363. f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), salary.T_housing_fund)
  364. f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), salary.T_tax)
  365. f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), salary.T_laborage)
  366. f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), salary.T_total)
  367. f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line), salary.T_remark)
  368. base += salary.T_base
  369. post += salary.T_post
  370. seniority += salary.T_seniority
  371. actual_Perf += salary.T_actual_Perf
  372. back_payment += salary.T_back_payment
  373. attendance += salary.T_attendance
  374. cut_payment += salary.T_cut_payment
  375. laballot += salary.T_laballot
  376. pension_insurance += salary.T_pension_insurance
  377. unemployment_insurance += salary.T_unemployment_insurance
  378. medical_insurance += salary.T_medical_insurance
  379. Large_medical_insurance += salary.T_large_medical_insurance
  380. housing_fund += salary.T_housing_fund
  381. tax += salary.T_tax
  382. laborage += salary.T_laborage
  383. total += salary.T_total
  384. line++
  385. }
  386. // ------------- 最后一行 合计 ------------------------
  387. f.SetRowHeight("Sheet1", line, 22)
  388. f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("D%d", line))
  389. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "合计")
  390. // 代码统计
  391. //f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), base)
  392. //f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), post)
  393. //f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), seniority)
  394. //f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), actual_Perf)
  395. //f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), back_payment)
  396. //f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), attendance)
  397. //f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), cut_payment)
  398. //f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), laballot)
  399. //f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), pension_insurance)
  400. //f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), unemployment_insurance)
  401. //f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), medical_insurance)
  402. //f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), Large_medical_insurance)
  403. //f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), housing_fund)
  404. //f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), tax)
  405. //f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), laborage)
  406. //f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), total)
  407. // 函数统计
  408. f.SetCellFormula("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("SUM(E4:E%d)", line-1))
  409. f.SetCellFormula("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("SUM(F4:F%d)", line-1))
  410. f.SetCellFormula("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("SUM(G4:G%d)", line-1))
  411. f.SetCellFormula("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("SUM(J4:J%d)", line-1))
  412. f.SetCellFormula("Sheet1", fmt.Sprintf("K%d", line), fmt.Sprintf("SUM(K4:K%d)", line-1))
  413. f.SetCellFormula("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("SUM(L4:L%d)", line-1))
  414. f.SetCellFormula("Sheet1", fmt.Sprintf("M%d", line), fmt.Sprintf("SUM(M4:M%d)", line-1))
  415. f.SetCellFormula("Sheet1", fmt.Sprintf("N%d", line), fmt.Sprintf("SUM(N4:N%d)", line-1))
  416. f.SetCellFormula("Sheet1", fmt.Sprintf("O%d", line), fmt.Sprintf("SUM(O4:O%d)", line-1))
  417. f.SetCellFormula("Sheet1", fmt.Sprintf("P%d", line), fmt.Sprintf("SUM(P4:P%d)", line-1))
  418. f.SetCellFormula("Sheet1", fmt.Sprintf("Q%d", line), fmt.Sprintf("SUM(Q4:Q%d)", line-1))
  419. f.SetCellFormula("Sheet1", fmt.Sprintf("R%d", line), fmt.Sprintf("SUM(R4:R%d)", line-1))
  420. f.SetCellFormula("Sheet1", fmt.Sprintf("S%d", line), fmt.Sprintf("SUM(S4:S%d)", line-1))
  421. f.SetCellFormula("Sheet1", fmt.Sprintf("T%d", line), fmt.Sprintf("SUM(T4:T%d)", line-1))
  422. f.SetCellFormula("Sheet1", fmt.Sprintf("U%d", line), fmt.Sprintf("SUM(U4:U%d)", line-1))
  423. f.SetCellFormula("Sheet1", fmt.Sprintf("V%d", line), fmt.Sprintf("SUM(V4:V%d)", line-1))
  424. Style4, _ := f.NewStyle(
  425. &excelize.Style{
  426. Font: &excelize.Font{Size: 10, Family: "宋体"},
  427. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  428. Border: []excelize.Border{
  429. {Type: "left", Color: "000000", Style: 1},
  430. {Type: "top", Color: "000000", Style: 1},
  431. {Type: "bottom", Color: "000000", Style: 1},
  432. {Type: "right", Color: "000000", Style: 1},
  433. },
  434. })
  435. // 黄色填充
  436. StyleYullowFill, _ := f.NewStyle(
  437. &excelize.Style{
  438. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  439. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  440. Border: []excelize.Border{
  441. {Type: "left", Color: "000000", Style: 1},
  442. {Type: "top", Color: "000000", Style: 1},
  443. {Type: "bottom", Color: "000000", Style: 1},
  444. {Type: "right", Color: "000000", Style: 1},
  445. },
  446. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFFF00"}, Pattern: 1},
  447. })
  448. // 绿色填充
  449. StyleGreenFill, _ := f.NewStyle(
  450. &excelize.Style{
  451. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  452. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  453. Border: []excelize.Border{
  454. {Type: "left", Color: "000000", Style: 1},
  455. {Type: "top", Color: "000000", Style: 1},
  456. {Type: "bottom", Color: "000000", Style: 1},
  457. {Type: "right", Color: "000000", Style: 1},
  458. },
  459. Fill: excelize.Fill{Type: "pattern", Color: []string{"#92D050"}, Pattern: 1},
  460. })
  461. f.SetCellStyle("Sheet1", "A4", fmt.Sprintf("W%d", line), Style4)
  462. f.SetCellStyle("Sheet1", "N3", fmt.Sprintf("N%d", line-1), StyleYullowFill)
  463. f.SetCellStyle("Sheet1", "U3", fmt.Sprintf("U%d", line-1), StyleYullowFill)
  464. f.SetCellStyle("Sheet1", "V3", fmt.Sprintf("V%d", line-1), StyleGreenFill)
  465. filename := fmt.Sprintf("贵州宝智达网络科技有限公司%s年%s月工资表(%s)", year, month, lib.GetRandstring(6, "0123456789", 0))
  466. // 保存文件
  467. if err = f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
  468. fmt.Println(err)
  469. }
  470. // 上传 OSS
  471. nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
  472. url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
  473. if !is {
  474. c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
  475. c.ServeJSON()
  476. return
  477. }
  478. //删除目录
  479. err = os.Remove("ofile/" + filename + ".xlsx")
  480. if err != nil {
  481. logs.Error(lib.FuncName(), err)
  482. }
  483. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  484. c.ServeJSON()
  485. return
  486. }