OrderController.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package com.poteviohealth.cgp.statistics.controller;
  2. import com.google.common.collect.Maps;
  3. import com.poteviohealth.cgp.common.controller.BaseWebController;
  4. import com.poteviohealth.cgp.common.exception.BusinessException;
  5. import com.poteviohealth.cgp.common.facade.cache.CacheService;
  6. import com.poteviohealth.cgp.common.facade.constrain.OrgConstrainService;
  7. import com.poteviohealth.cgp.common.facade.lock.DistributedLock;
  8. import com.poteviohealth.cgp.common.facade.time.MethodTime;
  9. import com.poteviohealth.cgp.common.filter.TokenContext;
  10. import com.poteviohealth.cgp.common.filter.repeatSubmit.RepeatSubmit;
  11. import com.poteviohealth.cgp.common.model.VaultsResponse;
  12. import com.poteviohealth.cgp.statistics.model.indto.*;
  13. import com.poteviohealth.cgp.statistics.model.outdto.DishesOrderWebOutDTO;
  14. import com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO;
  15. import com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO;
  16. import com.poteviohealth.cgp.statistics.service.IOrderService;
  17. import com.poteviohealth.cgp.statistics.utils.ExcelUtils2;
  18. import com.poteviohealth.cgp.statistics.utils.OssUtils;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiOperation;
  21. import lombok.extern.log4j.Log4j2;
  22. import org.apache.commons.lang3.time.DateFormatUtils;
  23. import org.springframework.stereotype.Controller;
  24. import org.springframework.web.bind.annotation.*;
  25. import org.springframework.web.multipart.MultipartFile;
  26. import javax.annotation.Resource;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.util.List;
  29. import java.util.Map;
  30. /**
  31. * 服务工单 前端控制器
  32. * @author Qin
  33. */
  34. @Controller
  35. @RequestMapping("/statistics/web/order")
  36. @Api(tags={"WEB端-工单相关接口"})
  37. @Log4j2
  38. public class OrderController extends BaseWebController {
  39. @Resource
  40. private OrgConstrainService orgConstrainService;
  41. @Resource
  42. private CacheService cacheService;
  43. @Resource
  44. private IOrderService orderService;
  45. @Resource
  46. private OssUtils ossUtils;
  47. @PostMapping(value = "/orderServiceExport")
  48. @ApiOperation(httpMethod = "POST", value = "工单Excel导出")
  49. @RepeatSubmit
  50. @MethodTime
  51. public void orderServiceExport(HttpServletResponse resp, @RequestBody OrderServiceWebInDTO orderServiceWebInDTO){
  52. String key ="orderServiceExport";
  53. String error = this.checkExcelExport(key);
  54. try {
  55. if ("".equals(error)) {
  56. orgConstrainService.fillOrgParams(orderServiceWebInDTO);
  57. List<OrderExcelDTO> list = orderService.orderExcel(orderServiceWebInDTO);
  58. ExcelUtils2.easyDownload("classpath:excel/order_service.xlsx", Maps.newHashMap(), list, "", resp);
  59. }else{
  60. throw new BusinessException(error);
  61. }
  62. }catch (Exception e){
  63. e.printStackTrace();
  64. throw new BusinessException(e.getMessage());
  65. }finally {
  66. if(cacheService.exists(key)){
  67. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  68. cacheService.del(key);
  69. }
  70. }
  71. }
  72. }
  73. @PostMapping(value = "/orderDishesExport")
  74. @ApiOperation(httpMethod = "POST", value = "餐单Excel导出")
  75. @RepeatSubmit
  76. @MethodTime
  77. public void orderDishesExport(HttpServletResponse resp, @RequestBody DishesOrderWebInDTO dto){
  78. String key ="orderDishesExport";
  79. String error = this.checkExcelExport(key);
  80. try{
  81. if ("".equals(error)) {
  82. orgConstrainService.fillOrgParams(dto);
  83. List<DishesOrderWebOutDTO> list = orderService.orderDishes(dto);
  84. ExcelUtils2.easyDownload("classpath:excel/order_dishes.xlsx", Maps.newHashMap(), list, "", resp);
  85. }else{
  86. throw new BusinessException(error);
  87. }
  88. }catch (Exception e){
  89. e.printStackTrace();
  90. throw new BusinessException(e.getMessage());
  91. }finally {
  92. if(cacheService.exists(key)){
  93. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  94. cacheService.del(key);
  95. }
  96. }
  97. }
  98. }
  99. @PostMapping(value = "/revenueExport")
  100. @ApiOperation(httpMethod = "POST", value = "成本核算Excel导出")
  101. @RepeatSubmit
  102. @MethodTime
  103. public void revenueExport(HttpServletResponse resp, @RequestBody OrderCostWebInDTO orderCostWebInDTO){
  104. String key ="revenueExport";
  105. String error = this.checkExcelExport(key);
  106. try{
  107. if ("".equals(error)) {
  108. String templateLocation = "classpath:excel/revenue.xlsx";
  109. String filename = "";
  110. Map<String, Object> data = Maps.newHashMap();
  111. String dateStr = "工单成本核算";
  112. if(orderCostWebInDTO.getStartDate() != null){
  113. dateStr = DateFormatUtils.format(orderCostWebInDTO.getStartDate(),"yyyy-MM-dd")+"~"+
  114. DateFormatUtils.format(orderCostWebInDTO.getEndDate(),"yyyy-MM-dd")+dateStr;
  115. }
  116. orgConstrainService.fillOrgParams(orderCostWebInDTO);
  117. List<OrderCostWebOutDTO> list = orderService.OrderCostList(orderCostWebInDTO);
  118. double totalActualCost = list.stream().mapToDouble(a-> Double.parseDouble(a.getStandard())).sum();
  119. double totalActualIncome =list.stream().mapToDouble(a-> Double.parseDouble(a.getActual())).sum();
  120. data.put("title",dateStr);
  121. data.put("title2","标准成本合计:"+totalActualCost+"元;成本金额合计:"+totalActualIncome+"元");
  122. ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
  123. }else{
  124. throw new BusinessException(error);
  125. }
  126. }catch (Exception e){
  127. e.printStackTrace();
  128. throw new BusinessException(e.getMessage());
  129. }finally {
  130. if(cacheService.exists(key)){
  131. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  132. cacheService.del(key);
  133. }
  134. }
  135. }
  136. }
  137. @PostMapping(value = "/orderExport")
  138. @ApiOperation(httpMethod = "POST", value = "订单Excel导出")
  139. public void orderExport(HttpServletResponse resp,@RequestBody OrderWebInDTO orderWebInDTO){
  140. String key ="orderExport";
  141. String error = this.checkExcelExport(key);
  142. try{
  143. if ("".equals(error)) {
  144. String templateLocation = "classpath:excel/order.xlsx";
  145. String filename = "";
  146. Map<String, Object> data = Maps.newHashMap();
  147. List<OrderExcelDTO> list = orderService.excelList(orderWebInDTO);
  148. ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
  149. }else{
  150. throw new BusinessException(error);
  151. }
  152. }catch (Exception e){
  153. e.printStackTrace();
  154. throw new BusinessException(e.getMessage());
  155. }finally {
  156. if(cacheService.exists(key)){
  157. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  158. cacheService.del(key);
  159. }
  160. }
  161. }
  162. }
  163. @DistributedLock(fairLock =true)
  164. private String checkExcelExport(String key){
  165. String returnVal = "";
  166. String user = TokenContext.cureWebUser().getUserId().toString();
  167. if (!cacheService.exists(key)) {
  168. cacheService.setex(key,300,user);
  169. } else {
  170. String val = cacheService.get(key);
  171. if(val.equals(user)){
  172. returnVal = "正在导出数据,请耐心等待...";
  173. }else{
  174. returnVal = "其他用户正在导出数据,请稍后再试";
  175. }
  176. }
  177. return returnVal;
  178. }
  179. @RequestMapping(value = "/uploadArrayFile", method = RequestMethod.POST)
  180. @ApiOperation(value = "阿里云图片上传")
  181. @ResponseBody
  182. @MethodTime
  183. public VaultsResponse uploadArrayFile(@RequestParam("files") List<MultipartFile> files, @RequestBody List<PriceUploadDto> list){
  184. log.info(files);
  185. log.info(list);
  186. /* VaultsResponse<List<PriceUploadDto>> vaultsResponse = ossUtils.uploadArrayFile(list);
  187. if(vaultsResponse.validate()){
  188. return orderService.updateOrderUrl(list);
  189. }*/
  190. return VaultsResponse.success();
  191. }
  192. }