| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package com.railway.business.safetool.controller;
- import com.railway.business.safetool.domain.BaseSafetyTool;
- import com.railway.business.safetool.service.IBaseSafetyToolService;
- import com.railway.common.annotation.Log;
- import com.railway.common.core.controller.BaseController;
- import com.railway.common.core.domain.AjaxResult;
- import com.railway.common.enums.BusinessType;
- import com.railway.common.utils.QrCodeUtil;
- import com.railway.common.utils.SecurityUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import java.util.Arrays;
- import java.util.List;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.servlet.ModelAndView;
- /**
- * @author ZhaoMn
- */
- @Slf4j
- @Api(value = "rest/safetool/base/safety/tool", tags = "安全工具 - 二维码")
- @RestController
- @Validated
- @RequestMapping(value = "st")
- public class SecQcodeController extends BaseController {
- private final IBaseSafetyToolService safetyToolService;
- public SecQcodeController(IBaseSafetyToolService safetyToolService) {
- this.safetyToolService = safetyToolService;
- }
- @ApiOperation(value = "单个")
- @GetMapping(value = {"/", "/{qcode}"})
- public AjaxResult getInfo(String qcode) {
- BaseSafetyTool tool = safetyToolService.getInfoByQcode(qcode);
- if (null == tool) {
- return AjaxResult.error("二维码已失效,请检查!");
- }
- if(SecurityUtils.isNotLabUser()){
- Long deptId = SecurityUtils.getDeptId();
- if (tool.getDeptId().compareTo(deptId) != 0) {
- return AjaxResult.error("非本车间安全工具,请检查!");
- }
- }
- AjaxResult ajax = AjaxResult.success();
- ajax.put("info", tool);
- return ajax;
- }
- @ApiOperation(value = "更新二维码")
- @GetMapping(value = {"/refresh"})
- public AjaxResult refresh() {
- safetyToolService.refresh();
- return AjaxResult.success();
- }
- @ApiOperation(value = "重新生成二维码")
- @GetMapping(value = {"/rebuild"})
- public AjaxResult rebuild() {
- safetyToolService.rebuild();
- return AjaxResult.success();
- }
- /**
- * 生成二维码
- */
- @ApiOperation(value = "二维码生成", notes = "二维码生成", response = ModelAndView.class)
- @GetMapping("/qcodeImage")
- public AjaxResult getCode(Long toolId) {
- AjaxResult ajax = AjaxResult.success();
- BaseSafetyTool tool = safetyToolService.getInfo(toolId);
- if (null == tool) {
- return ajax;
- }
- List<String> bottomDes = Arrays.asList(tool.getDeptName(), tool.getStorePlace(),
- tool.getToolName() + " - " + tool.getToolCode());
- String base64Code;
- try {
- base64Code = QrCodeUtil.encodeStr(tool.getToolQcode(), bottomDes);
- } catch (Exception e) {
- return AjaxResult.error(e.getMessage());
- }
- ajax.put("img", base64Code);
- return ajax;
- }
- @ApiOperation(value = "批量导出二维码")
- @Log(title = "批量导出二维码", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(Long[] id) {
- return safetyToolService.export(id);
- }
- @ApiOperation(value = "批量导出二维码")
- @Log(title = "批量导出二维码", businessType = BusinessType.EXPORT)
- @GetMapping("/exportAll")
- public AjaxResult exportAll(BaseSafetyTool safetyTool) {
- return safetyToolService.export(safetyTool);
- }
- }
|