OrderConfigController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package com.phm.manage.controller;
  2. import java.io.IOException;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import javax.xml.bind.JAXBContext;
  6. import javax.xml.bind.JAXBException;
  7. import javax.xml.bind.Unmarshaller;
  8. import org.apache.commons.lang3.ObjectUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.security.access.prepost.PreAuthorize;
  11. import org.springframework.web.bind.annotation.DeleteMapping;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.PathVariable;
  14. import org.springframework.web.bind.annotation.PostMapping;
  15. import org.springframework.web.bind.annotation.PutMapping;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import com.phm.common.annotation.Log;
  21. import com.phm.common.core.controller.BaseController;
  22. import com.phm.common.core.domain.AjaxResult;
  23. import com.phm.common.core.page.TableDataInfo;
  24. import com.phm.common.enums.BusinessType;
  25. import com.phm.common.exception.GlobalException;
  26. import com.phm.common.utils.bean.BeanUtils;
  27. import com.phm.common.utils.poi.ExcelUtil;
  28. import com.phm.manage.domain.OrderConfig;
  29. import com.phm.manage.domain.common.CommonResult;
  30. import com.phm.manage.domain.common.OrderXmlVO;
  31. import com.phm.manage.service.IOrderConfigService;
  32. import com.phm.manage.util.JaxbUtil;
  33. import cn.hutool.core.bean.BeanUtil;
  34. /**
  35. * 指令配置Controller
  36. *
  37. * @author phm
  38. * @date 2023-10-07
  39. */
  40. @RestController
  41. @RequestMapping("/manage/orderConfig")
  42. public class OrderConfigController extends BaseController {
  43. @Autowired
  44. private IOrderConfigService orderConfigService;
  45. /**
  46. * 查询指令配置列表
  47. */
  48. @PreAuthorize("@ss.hasPermi('manage:orderConfig:list')")
  49. @GetMapping("/list")
  50. public TableDataInfo list(OrderConfig orderConfig) {
  51. startPage();
  52. List<OrderConfig> list = orderConfigService.selectOrderConfigList(orderConfig);
  53. return getDataTable(list);
  54. }
  55. /**
  56. * 导出指令配置列表
  57. */
  58. @PreAuthorize("@ss.hasPermi('manage:orderConfig:export')")
  59. @Log(title = "指令配置", businessType = BusinessType.EXPORT)
  60. @PostMapping("/export")
  61. public void export(HttpServletResponse response, OrderConfig orderConfig) {
  62. List<OrderConfig> list = orderConfigService.selectOrderConfigList(orderConfig);
  63. ExcelUtil<OrderConfig> util = new ExcelUtil<OrderConfig>(OrderConfig.class);
  64. util.exportExcel(response, list, "指令配置数据");
  65. }
  66. /**
  67. * 获取指令配置详细信息
  68. */
  69. @PreAuthorize("@ss.hasPermi('manage:orderConfig:query')")
  70. @GetMapping(value = "/{id}")
  71. public AjaxResult getInfo(@PathVariable("id") Long id) {
  72. return success(orderConfigService.selectOrderConfigById(id));
  73. }
  74. @PreAuthorize("@ss.hasPermi('manage:orderConfig:query')")
  75. @GetMapping(value = "/xml/{id}")
  76. public CommonResult<String> getInfoXml(@PathVariable("id") Long id) throws Exception {
  77. OrderConfig orderConfig = orderConfigService.selectOrderConfigById(id);
  78. OrderXmlVO xmlVO = new OrderXmlVO();
  79. BeanUtil.copyProperties(orderConfig, xmlVO);
  80. return CommonResult.success(JaxbUtil.convertToXml(xmlVO));
  81. }
  82. /**
  83. * 新增指令配置
  84. */
  85. @PreAuthorize("@ss.hasPermi('manage:orderConfig:add')")
  86. @Log(title = "指令配置", businessType = BusinessType.INSERT)
  87. @PostMapping
  88. public CommonResult<Object> add(@RequestBody OrderConfig orderConfig) {
  89. OrderConfig order = orderConfigService.selectOrderConfigByCode(orderConfig.getOrderCode());
  90. if (ObjectUtils.isNotEmpty(order)) {
  91. return CommonResult.error("指令编码已存在,请重新输入!");
  92. }
  93. return CommonResult.success(orderConfigService.insertOrderConfig(orderConfig));
  94. }
  95. /**
  96. * 修改指令配置
  97. */
  98. @PreAuthorize("@ss.hasPermi('manage:orderConfig:edit')")
  99. @Log(title = "指令配置", businessType = BusinessType.UPDATE)
  100. @PutMapping
  101. public AjaxResult edit(@RequestBody OrderConfig orderConfig) {
  102. return toAjax(orderConfigService.updateOrderConfig(orderConfig));
  103. }
  104. /**
  105. * 删除指令配置
  106. */
  107. @PreAuthorize("@ss.hasPermi('manage:orderConfig:remove')")
  108. @Log(title = "指令配置", businessType = BusinessType.DELETE)
  109. @DeleteMapping("/{ids}")
  110. public AjaxResult remove(@PathVariable Long[] ids) {
  111. return toAjax(orderConfigService.deleteOrderConfigByIds(ids));
  112. }
  113. /**
  114. * 导入xml
  115. *
  116. * @param file file
  117. * @param updateSupport updateSupport
  118. * @return res
  119. */
  120. @PostMapping(value = "/import/xml")
  121. public CommonResult<Integer> importData(MultipartFile file, boolean updateSupport) {
  122. OrderXmlVO orderXmlVO = new OrderXmlVO();
  123. OrderConfig orderConfig = new OrderConfig();
  124. try {
  125. JAXBContext jaxbContext = JAXBContext.newInstance(OrderXmlVO.class);
  126. Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
  127. orderXmlVO = (OrderXmlVO)jaxbUnmarshaller.unmarshal(file.getInputStream());
  128. } catch (JAXBException | IOException exception) {
  129. logger.error("XML解析错误,信息:{}", exception.getMessage());
  130. throw new GlobalException("XML解析错误,请检查XMl格式");
  131. }
  132. BeanUtils.copyBeanProp(orderConfig, orderXmlVO);
  133. OrderConfig order = orderConfigService.selectOrderConfigByCode(orderConfig.getOrderCode());
  134. if (ObjectUtils.isNotEmpty(order)) {
  135. return CommonResult.error("指令编码已存在,请重新输入!");
  136. }
  137. return CommonResult.success(orderConfigService.insertOrderConfig(orderConfig));
  138. }
  139. }