CommonController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package com.zhongzheng.controller.common;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.zhongzheng.common.config.RuoYiConfig;
  4. import com.zhongzheng.common.constant.Constants;
  5. import com.zhongzheng.common.core.domain.AjaxResult;
  6. import com.zhongzheng.common.core.domain.model.LoginBody;
  7. import com.zhongzheng.common.utils.ServletUtils;
  8. import com.zhongzheng.common.utils.ToolsUtils;
  9. import com.zhongzheng.common.utils.file.FileUploadUtils;
  10. import com.zhongzheng.common.utils.file.FileUtils;
  11. import com.zhongzheng.common.utils.poi.ExcelUtil;
  12. import com.zhongzheng.framework.config.ServerConfig;
  13. import com.zhongzheng.modules.course.vo.CourseMenuVo;
  14. import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
  15. import com.zhongzheng.modules.goods.service.IGoodsService;
  16. import com.zhongzheng.modules.goods.vo.GoodsJzsVo;
  17. import com.zhongzheng.modules.grade.bo.RollBackPeriodBo;
  18. import com.zhongzheng.modules.grade.bo.UserPeriodEditBo;
  19. import com.zhongzheng.modules.grade.service.IUserPeriodService;
  20. import com.zhongzheng.modules.grade.vo.ClassPeriodStudentExportAllVo;
  21. import com.zhongzheng.modules.grade.vo.SyncGoodsExport;
  22. import com.zhongzheng.modules.order.bo.OrderAddBo;
  23. import com.zhongzheng.modules.order.service.IOrderService;
  24. import com.zhongzheng.modules.order.service.impl.OrderServiceImpl;
  25. import com.zhongzheng.modules.system.service.ISysUserService;
  26. import com.zhongzheng.modules.user.vo.UserExportVo;
  27. import io.swagger.annotations.ApiOperation;
  28. import org.slf4j.Logger;
  29. import org.slf4j.LoggerFactory;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.http.MediaType;
  32. import org.springframework.web.bind.annotation.GetMapping;
  33. import org.springframework.web.bind.annotation.PostMapping;
  34. import org.springframework.web.bind.annotation.RequestBody;
  35. import org.springframework.web.bind.annotation.RestController;
  36. import org.springframework.web.multipart.MultipartFile;
  37. import javax.servlet.http.HttpServletRequest;
  38. import javax.servlet.http.HttpServletResponse;
  39. import java.util.ArrayList;
  40. import java.util.List;
  41. /**
  42. * 通用请求处理
  43. *
  44. * @author zhongzheng
  45. */
  46. @RestController
  47. public class CommonController
  48. {
  49. private static final Logger log = LoggerFactory.getLogger(CommonController.class);
  50. @Autowired
  51. private ServerConfig serverConfig;
  52. @Autowired
  53. private IGoodsService iGoodsService;
  54. @Autowired
  55. private IUserPeriodService iUserPeriodService;
  56. @Autowired
  57. private IOrderService iOrderService;
  58. /**
  59. * 通用下载请求
  60. *
  61. * @param fileName 文件名称
  62. * @param delete 是否删除
  63. */
  64. @GetMapping("common/download")
  65. public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
  66. {
  67. try
  68. {
  69. if (!FileUtils.checkAllowDownload(fileName))
  70. {
  71. throw new Exception(StrUtil.format("文件名称({})非法,不允许下载。 ", fileName));
  72. }
  73. String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
  74. String filePath = RuoYiConfig.getDownloadPath() + fileName;
  75. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  76. FileUtils.setAttachmentResponseHeader(response, realFileName);
  77. FileUtils.writeBytes(filePath, response.getOutputStream());
  78. /* if (delete)
  79. {
  80. FileUtils.deleteFile(filePath);
  81. }*/
  82. FileUtils.deleteFile(filePath);
  83. }
  84. catch (Exception e)
  85. {
  86. log.error("下载文件失败", e);
  87. }
  88. }
  89. /**
  90. * 通用上传请求
  91. */
  92. @PostMapping("/common/upload")
  93. public AjaxResult uploadFile(MultipartFile file) throws Exception
  94. {
  95. try
  96. {
  97. // 上传文件路径
  98. String filePath = RuoYiConfig.getUploadPath();
  99. // 上传并返回新文件名称
  100. String fileName = FileUploadUtils.upload(filePath, file);
  101. String url = serverConfig.getUrl() + fileName;
  102. AjaxResult ajax = AjaxResult.success();
  103. ajax.put("fileName", fileName);
  104. ajax.put("url", url);
  105. return ajax;
  106. }
  107. catch (Exception e)
  108. {
  109. return AjaxResult.error(e.getMessage());
  110. }
  111. }
  112. /**
  113. * 本地资源通用下载
  114. */
  115. @GetMapping("/common/download/resource")
  116. public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
  117. throws Exception
  118. {
  119. try
  120. {
  121. if (!FileUtils.checkAllowDownload(resource))
  122. {
  123. throw new Exception(StrUtil.format("资源文件({})非法,不允许下载。 ", resource));
  124. }
  125. // 本地资源路径
  126. String localPath = RuoYiConfig.getProfile();
  127. // 数据库资源地址
  128. String downloadPath = localPath + StrUtil.subAfter(resource, Constants.RESOURCE_PREFIX,false);
  129. // 下载名称
  130. String downloadName = StrUtil.subAfter(downloadPath, "/",true);
  131. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  132. FileUtils.setAttachmentResponseHeader(response, downloadName);
  133. FileUtils.writeBytes(downloadPath, response.getOutputStream());
  134. }
  135. catch (Exception e)
  136. {
  137. log.error("下载文件失败", e);
  138. }
  139. }
  140. @ApiOperation("获取继教二建的商品结构列表")
  141. @GetMapping("common/jzs/goodsList")
  142. public AjaxResult<GoodsJzsVo> goodsList()
  143. {
  144. GoodsQueryBo queryBo = new GoodsQueryBo();
  145. List<SyncGoodsExport> goodsJzsVoList = iGoodsService.selectRjJzsList(queryBo);
  146. ExcelUtil<SyncGoodsExport> util = new ExcelUtil<SyncGoodsExport>(SyncGoodsExport.class);
  147. // ExcelUtil<SyncGoodsExport> util = new ExcelUtil<>(SyncGoodsExport.class);
  148. return util.exportEasyExcel(util.exportEasyData(goodsJzsVoList), "继建商品");
  149. }
  150. @ApiOperation("测试列表")
  151. @GetMapping("common/jzs/test")
  152. public AjaxResult<Void> testList()
  153. {
  154. UserPeriodEditBo queryBo = new UserPeriodEditBo();
  155. queryBo.setGoodsId(916L);
  156. queryBo.setGradeId(794L);
  157. queryBo.setUserId(114L);
  158. iUserPeriodService.syncStudyLogToOld(queryBo);
  159. return AjaxResult.success();
  160. }
  161. @ApiOperation("旧系统打回重审")
  162. @PostMapping("common/rollback/period")
  163. public AjaxResult<Void> rollbackPeriod(@RequestBody RollBackPeriodBo bo)
  164. {
  165. String sign = bo.getStamp().toString()+"pubilc2022";
  166. if(!bo.getSign().equals(ToolsUtils.EncoderByMd5(sign))){
  167. return AjaxResult.error("签名错误");
  168. }
  169. return AjaxResult.success();
  170. }
  171. @ApiOperation("测试分班")
  172. @GetMapping("common/jzs/grade")
  173. public AjaxResult<Void> testGrade()
  174. {
  175. iOrderService.arrangeGrade("安管继续教育网络班B类",890L,3097L,null,114L,"",174L);
  176. return AjaxResult.success();
  177. }
  178. }