TbLocationController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.ruoyi.asset.controller;
  2. import java.sql.Array;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collections;
  6. import java.util.List;
  7. import java.util.stream.Collectors;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.ruoyi.common.core.domain.TreeSelect;
  10. import com.ruoyi.common.utils.ServletUtils;
  11. import com.ruoyi.common.utils.file.Folder2ZipUtils;
  12. import com.ruoyi.common.utils.http.HttpHelper;
  13. import com.ruoyi.common.utils.http.HttpUtils;
  14. import io.swagger.v3.oas.annotations.Parameter;
  15. import org.springframework.http.MediaType;
  16. import org.springframework.security.access.prepost.PreAuthorize;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import com.ruoyi.common.annotation.Log;
  20. import com.ruoyi.common.core.controller.BaseController;
  21. import com.ruoyi.common.core.domain.AjaxResult;
  22. import com.ruoyi.common.enums.BusinessType;
  23. import com.ruoyi.asset.domain.TbLocation;
  24. import com.ruoyi.asset.service.ITbLocationService;
  25. import com.ruoyi.common.utils.poi.ExcelUtil;
  26. import com.ruoyi.common.core.page.TableDataInfo;
  27. /**
  28. * 所属位置Controller
  29. *
  30. * @author 原动力
  31. * @date 2023-05-15
  32. */
  33. @RestController
  34. @RequestMapping("/asset/location")
  35. public class TbLocationController extends BaseController
  36. {
  37. @Autowired
  38. private ITbLocationService tbLocationService;
  39. /**
  40. * 查询所属位置列表
  41. */
  42. @PreAuthorize("@ss.hasPermi('asset:location:list')")
  43. @GetMapping("/list")
  44. public TableDataInfo list(TbLocation tbLocation)
  45. {
  46. startPage();
  47. List<TbLocation> list = tbLocationService.selectTbLocationList(tbLocation);
  48. return getDataTable(list);
  49. }
  50. //@PreAuthorize("@ss.hasPermi('asset:location:list')")
  51. @PostMapping("/tree")
  52. public TableDataInfo tree(@RequestBody(required = false) TbLocation tbLocation) {
  53. startPage();
  54. List<TbLocation> tbLocations = tbLocationService.selectTree(tbLocation);
  55. return getDataTable(tbLocations);
  56. }
  57. @PreAuthorize("@ss.hasPermi('asset:location:list')")
  58. @GetMapping("/treeSelect")
  59. public AjaxResult treeSelect(@Parameter(name = "id") Long id) {
  60. List<TreeSelect> tbLocations = tbLocationService.selectTreeSelect(id);
  61. return success(tbLocations);
  62. }
  63. /**
  64. * 导出所属位置列表
  65. */
  66. @PreAuthorize("@ss.hasPermi('asset:location:export')")
  67. @Log(title = "所属位置", businessType = BusinessType.EXPORT)
  68. @PostMapping("/export")
  69. public void export(HttpServletResponse response, TbLocation tbLocation)
  70. {
  71. List<TbLocation> list = tbLocationService.selectTbLocationList(tbLocation);
  72. ExcelUtil<TbLocation> util = new ExcelUtil<TbLocation>(TbLocation.class);
  73. util.exportExcel(response, list, "所属位置数据");
  74. }
  75. /**
  76. * 获取所属位置详细信息
  77. */
  78. @PreAuthorize("@ss.hasPermi('asset:location:query')")
  79. @GetMapping(value = "/{id}")
  80. public AjaxResult getInfo(@PathVariable("id") Long id)
  81. {
  82. return success(tbLocationService.selectTbLocationById(id));
  83. }
  84. /**
  85. * 新增所属位置
  86. */
  87. @PreAuthorize("@ss.hasPermi('asset:location:add')")
  88. @Log(title = "所属位置", businessType = BusinessType.INSERT)
  89. @PostMapping
  90. public AjaxResult add(@RequestBody TbLocation tbLocation)
  91. {
  92. return toAjax(tbLocationService.insertTbLocation(tbLocation));
  93. }
  94. /**
  95. * 修改所属位置
  96. */
  97. @PreAuthorize("@ss.hasPermi('asset:location:edit')")
  98. @Log(title = "所属位置", businessType = BusinessType.UPDATE)
  99. @PutMapping
  100. public AjaxResult edit(@RequestBody TbLocation tbLocation)
  101. {
  102. return toAjax(tbLocationService.updateTbLocation(tbLocation));
  103. }
  104. /**
  105. * 删除所属位置
  106. */
  107. @PreAuthorize("@ss.hasPermi('asset:location:remove')")
  108. @Log(title = "所属位置", businessType = BusinessType.DELETE)
  109. @DeleteMapping("/{ids}")
  110. public AjaxResult remove(@PathVariable Long[] ids)
  111. {
  112. return toAjax(tbLocationService.deleteTbLocationByIds(ids));
  113. }
  114. /**
  115. * 查看位置二维码
  116. */
  117. @GetMapping(value = "/code/{number}", produces = MediaType.IMAGE_PNG_VALUE)
  118. public byte[] selectQrCode(@PathVariable("number") String locationNumber) {
  119. return tbLocationService.selectQrCodeByLocationNumber(locationNumber);
  120. }
  121. /**
  122. * 下载指定二维码
  123. */
  124. @PostMapping(value = "/download/code/{ids}")
  125. public void downloadZip(@PathVariable Long[] ids, HttpServletResponse response) {
  126. List<Long> idList = Arrays.stream(ids).collect(Collectors.toList());
  127. String sourceName = tbLocationService.downloadQrCode(idList);
  128. Folder2ZipUtils.zip(sourceName, response);
  129. }
  130. }