SecQcodeController.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.railway.business.safetool.controller;
  2. import com.railway.business.safetool.domain.BaseSafetyTool;
  3. import com.railway.business.safetool.service.IBaseSafetyToolService;
  4. import com.railway.common.annotation.Log;
  5. import com.railway.common.core.controller.BaseController;
  6. import com.railway.common.core.domain.AjaxResult;
  7. import com.railway.common.enums.BusinessType;
  8. import com.railway.common.utils.QrCodeUtil;
  9. import com.railway.common.utils.SecurityUtils;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import java.util.Arrays;
  13. import java.util.List;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.springframework.validation.annotation.Validated;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import org.springframework.web.servlet.ModelAndView;
  20. /**
  21. * @author ZhaoMn
  22. */
  23. @Slf4j
  24. @Api(value = "rest/safetool/base/safety/tool", tags = "安全工具 - 二维码")
  25. @RestController
  26. @Validated
  27. @RequestMapping(value = "st")
  28. public class SecQcodeController extends BaseController {
  29. private final IBaseSafetyToolService safetyToolService;
  30. public SecQcodeController(IBaseSafetyToolService safetyToolService) {
  31. this.safetyToolService = safetyToolService;
  32. }
  33. @ApiOperation(value = "单个")
  34. @GetMapping(value = {"/", "/{qcode}"})
  35. public AjaxResult getInfo(String qcode) {
  36. BaseSafetyTool tool = safetyToolService.getInfoByQcode(qcode);
  37. if (null == tool) {
  38. return AjaxResult.error("二维码已失效,请检查!");
  39. }
  40. if(SecurityUtils.isNotLabUser()){
  41. Long deptId = SecurityUtils.getDeptId();
  42. if (tool.getDeptId().compareTo(deptId) != 0) {
  43. return AjaxResult.error("非本车间安全工具,请检查!");
  44. }
  45. }
  46. AjaxResult ajax = AjaxResult.success();
  47. ajax.put("info", tool);
  48. return ajax;
  49. }
  50. @ApiOperation(value = "更新二维码")
  51. @GetMapping(value = {"/refresh"})
  52. public AjaxResult refresh() {
  53. safetyToolService.refresh();
  54. return AjaxResult.success();
  55. }
  56. @ApiOperation(value = "重新生成二维码")
  57. @GetMapping(value = {"/rebuild"})
  58. public AjaxResult rebuild() {
  59. safetyToolService.rebuild();
  60. return AjaxResult.success();
  61. }
  62. /**
  63. * 生成二维码
  64. */
  65. @ApiOperation(value = "二维码生成", notes = "二维码生成", response = ModelAndView.class)
  66. @GetMapping("/qcodeImage")
  67. public AjaxResult getCode(Long toolId) {
  68. AjaxResult ajax = AjaxResult.success();
  69. BaseSafetyTool tool = safetyToolService.getInfo(toolId);
  70. if (null == tool) {
  71. return ajax;
  72. }
  73. List<String> bottomDes = Arrays.asList(tool.getDeptName(), tool.getStorePlace(),
  74. tool.getToolName() + " - " + tool.getToolCode());
  75. String base64Code;
  76. try {
  77. base64Code = QrCodeUtil.encodeStr(tool.getToolQcode(), bottomDes);
  78. } catch (Exception e) {
  79. return AjaxResult.error(e.getMessage());
  80. }
  81. ajax.put("img", base64Code);
  82. return ajax;
  83. }
  84. @ApiOperation(value = "批量导出二维码")
  85. @Log(title = "批量导出二维码", businessType = BusinessType.EXPORT)
  86. @GetMapping("/export")
  87. public AjaxResult export(Long[] id) {
  88. return safetyToolService.export(id);
  89. }
  90. @ApiOperation(value = "批量导出二维码")
  91. @Log(title = "批量导出二维码", businessType = BusinessType.EXPORT)
  92. @GetMapping("/exportAll")
  93. public AjaxResult exportAll(BaseSafetyTool safetyTool) {
  94. return safetyToolService.export(safetyTool);
  95. }
  96. }