Salary.go 19 KB

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