OrderController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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.log.OperateType;
  9. import com.poteviohealth.cgp.common.facade.log.OperationLog;
  10. import com.poteviohealth.cgp.common.facade.time.MethodTime;
  11. import com.poteviohealth.cgp.common.filter.TokenContext;
  12. import com.poteviohealth.cgp.common.filter.repeatSubmit.RepeatSubmit;
  13. import com.poteviohealth.cgp.common.integrated.finance.model.CardAccTransRecharge;
  14. import com.poteviohealth.cgp.common.integrated.finance.model.MemberPlanDTO;
  15. import com.poteviohealth.cgp.common.integrated.finance.model.MemberPlanPageDTO;
  16. import com.poteviohealth.cgp.common.model.VaultsResponse;
  17. import com.poteviohealth.cgp.statistics.model.indto.*;
  18. import com.poteviohealth.cgp.statistics.model.outdto.DishesOrderWebOutDTO;
  19. import com.poteviohealth.cgp.statistics.model.outdto.DistinctionDTO;
  20. import com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO;
  21. import com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO;
  22. import com.poteviohealth.cgp.statistics.service.IDistinctionService;
  23. import com.poteviohealth.cgp.statistics.service.IOrderService;
  24. import com.poteviohealth.cgp.statistics.service.IWatermarkImgService;
  25. import com.poteviohealth.cgp.statistics.utils.ExcelUtils2;
  26. import com.poteviohealth.cgp.statistics.utils.OssUtils;
  27. import io.swagger.annotations.Api;
  28. import io.swagger.annotations.ApiOperation;
  29. import lombok.extern.log4j.Log4j2;
  30. import org.apache.commons.lang3.time.DateFormatUtils;
  31. import org.springframework.stereotype.Controller;
  32. import org.springframework.web.bind.annotation.*;
  33. import org.springframework.web.multipart.MultipartFile;
  34. import javax.annotation.Resource;
  35. import javax.servlet.http.HttpServletResponse;
  36. import java.io.IOException;
  37. import java.util.List;
  38. import java.util.Map;
  39. /**
  40. * 服务工单 前端控制器
  41. * @author Qin
  42. */
  43. @Controller
  44. @RequestMapping("/statistics/web/order")
  45. @Api(tags={"WEB端-工单相关接口"})
  46. @Log4j2
  47. public class OrderController extends BaseWebController {
  48. @Resource
  49. private OrgConstrainService orgConstrainService;
  50. @Resource
  51. private CacheService cacheService;
  52. @Resource
  53. private IOrderService orderService;
  54. @Resource
  55. private OssUtils ossUtils;
  56. @Resource
  57. private IWatermarkImgService watermarkImgService;
  58. @Resource
  59. private IDistinctionService distinctionService;
  60. @PostMapping(value = "/orderServiceExport")
  61. @ApiOperation(httpMethod = "POST", value = "工单Excel导出")
  62. @RepeatSubmit
  63. @MethodTime
  64. public void orderServiceExport(HttpServletResponse resp, @RequestBody OrderServiceWebInDTO orderServiceWebInDTO){
  65. String key ="orderServiceExport";
  66. String error = this.checkExcelExport(key);
  67. try {
  68. if ("".equals(error)) {
  69. orgConstrainService.fillOrgParams(orderServiceWebInDTO);
  70. List<OrderExcelDTO> list = orderService.orderExcel(orderServiceWebInDTO);
  71. ExcelUtils2.easyDownload("classpath:excel/order_service.xlsx", Maps.newHashMap(), list, "", resp);
  72. }else{
  73. throw new BusinessException(error);
  74. }
  75. }catch (Exception e){
  76. e.printStackTrace();
  77. throw new BusinessException(e.getMessage());
  78. }finally {
  79. if(cacheService.exists(key)){
  80. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  81. cacheService.del(key);
  82. }
  83. }
  84. }
  85. }
  86. @PostMapping(value = "/orderDishesExport")
  87. @ApiOperation(httpMethod = "POST", value = "餐单Excel导出")
  88. @RepeatSubmit
  89. @MethodTime
  90. public void orderDishesExport(HttpServletResponse resp, @RequestBody DishesOrderWebInDTO dto){
  91. String key ="orderDishesExport";
  92. String error = this.checkExcelExport(key);
  93. try{
  94. if ("".equals(error)) {
  95. orgConstrainService.fillOrgParams(dto);
  96. List<DishesOrderWebOutDTO> list = orderService.orderDishes(dto);
  97. ExcelUtils2.easyDownload("classpath:excel/order_dishes.xlsx", Maps.newHashMap(), list, "", resp);
  98. }else{
  99. throw new BusinessException(error);
  100. }
  101. }catch (Exception e){
  102. e.printStackTrace();
  103. throw new BusinessException(e.getMessage());
  104. }finally {
  105. if(cacheService.exists(key)){
  106. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  107. cacheService.del(key);
  108. }
  109. }
  110. }
  111. }
  112. @PostMapping(value = "/revenueExport")
  113. @ApiOperation(httpMethod = "POST", value = "成本核算Excel导出")
  114. @RepeatSubmit
  115. @MethodTime
  116. public void revenueExport(HttpServletResponse resp, @RequestBody OrderCostWebInDTO orderCostWebInDTO){
  117. String key ="revenueExport";
  118. String error = this.checkExcelExport(key);
  119. try{
  120. if ("".equals(error)) {
  121. String templateLocation = "classpath:excel/revenue.xlsx";
  122. String filename = "";
  123. Map<String, Object> data = Maps.newHashMap();
  124. String dateStr = "工单成本核算";
  125. if(orderCostWebInDTO.getStartDate() != null){
  126. dateStr = DateFormatUtils.format(orderCostWebInDTO.getStartDate(),"yyyy-MM-dd")+"~"+
  127. DateFormatUtils.format(orderCostWebInDTO.getEndDate(),"yyyy-MM-dd")+dateStr;
  128. }
  129. orgConstrainService.fillOrgParams(orderCostWebInDTO);
  130. List<OrderCostWebOutDTO> list = orderService.OrderCostList(orderCostWebInDTO);
  131. double totalActualCost = list.stream().mapToDouble(a-> Double.parseDouble(a.getStandard())).sum();
  132. double totalActualIncome =list.stream().mapToDouble(a-> Double.parseDouble(a.getActual())).sum();
  133. data.put("title",dateStr);
  134. data.put("title2","标准成本合计:"+totalActualCost+"元;成本金额合计:"+totalActualIncome+"元");
  135. ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
  136. }else{
  137. throw new BusinessException(error);
  138. }
  139. }catch (Exception e){
  140. e.printStackTrace();
  141. throw new BusinessException(e.getMessage());
  142. }finally {
  143. if(cacheService.exists(key)){
  144. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  145. cacheService.del(key);
  146. }
  147. }
  148. }
  149. }
  150. @PostMapping(value = "/orderExport")
  151. @ApiOperation(httpMethod = "POST", value = "订单Excel导出")
  152. public void orderExport(HttpServletResponse resp,@RequestBody OrderWebInDTO orderWebInDTO){
  153. String key ="orderExport";
  154. String error = this.checkExcelExport(key);
  155. try{
  156. if ("".equals(error)) {
  157. String templateLocation = "classpath:excel/order.xlsx";
  158. String filename = "";
  159. Map<String, Object> data = Maps.newHashMap();
  160. List<OrderExcelDTO> list = orderService.excelList(orderWebInDTO);
  161. ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
  162. }else{
  163. throw new BusinessException(error);
  164. }
  165. }catch (Exception e){
  166. e.printStackTrace();
  167. throw new BusinessException(e.getMessage());
  168. }finally {
  169. if(cacheService.exists(key)){
  170. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  171. cacheService.del(key);
  172. }
  173. }
  174. }
  175. }
  176. @DistributedLock(fairLock =true)
  177. private String checkExcelExport(String key){
  178. String returnVal = "";
  179. String user = TokenContext.cureWebUser().getUserId().toString();
  180. if (!cacheService.exists(key)) {
  181. cacheService.setex(key,300,user);
  182. } else {
  183. String val = cacheService.get(key);
  184. if(val.equals(user)){
  185. returnVal = "正在导出数据,请耐心等待...";
  186. }else{
  187. returnVal = "其他用户正在导出数据,请稍后再试";
  188. }
  189. }
  190. return returnVal;
  191. }
  192. @RequestMapping(value = "/uploadArrayFile", method = RequestMethod.POST)
  193. @ApiOperation(value = "阿里云图片上传")
  194. @MethodTime
  195. @ResponseBody
  196. public VaultsResponse<DistinctionDTO> uploadArrayFile(@RequestParam("file") MultipartFile file,@RequestParam("orderId") Long orderId,@RequestParam("uidList") List<String> uidList){
  197. log.info(orderId);
  198. //图片检查
  199. try {
  200. DistinctionDTO dto = distinctionService.checkImg(file,orderId,uidList);
  201. if(dto.getOrderId() ==null){
  202. VaultsResponse<String> vaultsResponse = ossUtils.uploadOneFile(file,orderId);
  203. log.info(vaultsResponse.getData());
  204. /* if(vaultsResponse.validate()){
  205. return orderService.updateOrderUrl(list);
  206. }*/
  207. dto.setUrl(vaultsResponse.getData());
  208. }
  209. return VaultsResponse.success(dto);
  210. } catch (IOException e) {
  211. e.printStackTrace();
  212. }
  213. return VaultsResponse.failed();
  214. }
  215. @PostMapping("/orderFile")
  216. @ApiOperation(value = "工单照片")
  217. @ResponseBody
  218. @OperationLog(type = OperateType.UPDATE, description = "工单照片处理")
  219. @MethodTime
  220. public VaultsResponse orderFile(@RequestBody List<PriceUploadDto> list) {
  221. //处理水印
  222. VaultsResponse<List<PriceUploadDto>> vaultsResponse = watermarkImgService.printingWatermark(list);
  223. if(!vaultsResponse.validate()){
  224. return vaultsResponse;
  225. }
  226. list = vaultsResponse.getData();
  227. //处理照片
  228. watermarkImgService.updateOrderUrl(list);
  229. return VaultsResponse.success();
  230. }
  231. @PostMapping(value = "/pageCardExport")
  232. @ApiOperation(httpMethod = "POST", value = "后台账户查询Excel导出")
  233. public void orderExport(HttpServletResponse resp,@RequestBody MemberPlanPageDTO dto){
  234. String key ="pageCardExport";
  235. String error = this.checkExcelExport(key);
  236. try{
  237. if ("".equals(error)) {
  238. String templateLocation = "classpath:excel/pageCard.xlsx";
  239. String filename = "客户账户.xlsx";
  240. Map<String, Object> data = Maps.newHashMap();
  241. orgConstrainService.fillOrgParams(dto);
  242. List<MemberPlanDTO> list = orderService.pageCardExcel(dto);
  243. ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
  244. }else{
  245. throw new BusinessException(error);
  246. }
  247. }catch (Exception e){
  248. e.printStackTrace();
  249. throw new BusinessException(e.getMessage());
  250. }finally {
  251. if(cacheService.exists(key)){
  252. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  253. cacheService.del(key);
  254. }
  255. }
  256. }
  257. }
  258. @PostMapping(value = "/transRechargeExcel")
  259. @ApiOperation(httpMethod = "POST", value = "账户充值Excel导出")
  260. @RepeatSubmit
  261. @MethodTime
  262. public void transRechargeExcel(HttpServletResponse resp, @RequestBody CardWebInDTO dto){
  263. String key ="transRechargeExcel";
  264. String error = this.checkExcelExport(key);
  265. try{
  266. if ("".equals(error)) {
  267. orgConstrainService.fillOrgParams(dto);
  268. Map<String,Object> maps = Maps.newHashMap();
  269. String start = DateFormatUtils.format(dto.getStartDate(), "yyyy-MM");
  270. String end = DateFormatUtils.format(dto.getEndDate(), "yyyy-MM");
  271. if(start.equals(end)){
  272. maps.put("title", start+"充值记录");
  273. }else{
  274. maps.put("title", start+"到"+end+"充值记录");
  275. }
  276. List<CardAccTransRecharge> list = orderService.transRechargeExcel(dto);
  277. ExcelUtils2.easyDownload("classpath:excel/trans_recharge.xlsx",maps, list, "", resp);
  278. }else{
  279. throw new BusinessException(error);
  280. }
  281. }catch (Exception e){
  282. e.printStackTrace();
  283. throw new BusinessException(e.getMessage());
  284. }finally {
  285. if(cacheService.exists(key)){
  286. if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
  287. cacheService.del(key);
  288. }
  289. }
  290. }
  291. }
  292. }