| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package com.poteviohealth.cgp.statistics.controller;
- import com.google.common.collect.Maps;
- import com.poteviohealth.cgp.common.controller.BaseWebController;
- import com.poteviohealth.cgp.common.exception.BusinessException;
- import com.poteviohealth.cgp.common.facade.cache.CacheService;
- import com.poteviohealth.cgp.common.facade.constrain.OrgConstrainService;
- import com.poteviohealth.cgp.common.facade.lock.DistributedLock;
- import com.poteviohealth.cgp.common.facade.time.MethodTime;
- import com.poteviohealth.cgp.common.filter.TokenContext;
- import com.poteviohealth.cgp.common.filter.repeatSubmit.RepeatSubmit;
- import com.poteviohealth.cgp.common.model.VaultsResponse;
- import com.poteviohealth.cgp.statistics.model.indto.*;
- import com.poteviohealth.cgp.statistics.model.outdto.DishesOrderWebOutDTO;
- import com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO;
- import com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO;
- import com.poteviohealth.cgp.statistics.service.IOrderService;
- import com.poteviohealth.cgp.statistics.utils.ExcelUtils2;
- import com.poteviohealth.cgp.statistics.utils.OssUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.log4j.Log4j2;
- import org.apache.commons.lang3.time.DateFormatUtils;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import java.util.List;
- import java.util.Map;
- /**
- * 服务工单 前端控制器
- * @author Qin
- */
- @Controller
- @RequestMapping("/statistics/web/order")
- @Api(tags={"WEB端-工单相关接口"})
- @Log4j2
- public class OrderController extends BaseWebController {
- @Resource
- private OrgConstrainService orgConstrainService;
- @Resource
- private CacheService cacheService;
- @Resource
- private IOrderService orderService;
- @Resource
- private OssUtils ossUtils;
- @PostMapping(value = "/orderServiceExport")
- @ApiOperation(httpMethod = "POST", value = "工单Excel导出")
- @RepeatSubmit
- @MethodTime
- public void orderServiceExport(HttpServletResponse resp, @RequestBody OrderServiceWebInDTO orderServiceWebInDTO){
- String key ="orderServiceExport";
- String error = this.checkExcelExport(key);
- try {
- if ("".equals(error)) {
- orgConstrainService.fillOrgParams(orderServiceWebInDTO);
- List<OrderExcelDTO> list = orderService.orderExcel(orderServiceWebInDTO);
- ExcelUtils2.easyDownload("classpath:excel/order_service.xlsx", Maps.newHashMap(), list, "", resp);
- }else{
- throw new BusinessException(error);
- }
- }catch (Exception e){
- e.printStackTrace();
- throw new BusinessException(e.getMessage());
- }finally {
- if(cacheService.exists(key)){
- if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
- cacheService.del(key);
- }
- }
- }
- }
- @PostMapping(value = "/orderDishesExport")
- @ApiOperation(httpMethod = "POST", value = "餐单Excel导出")
- @RepeatSubmit
- @MethodTime
- public void orderDishesExport(HttpServletResponse resp, @RequestBody DishesOrderWebInDTO dto){
- String key ="orderDishesExport";
- String error = this.checkExcelExport(key);
- try{
- if ("".equals(error)) {
- orgConstrainService.fillOrgParams(dto);
- List<DishesOrderWebOutDTO> list = orderService.orderDishes(dto);
- ExcelUtils2.easyDownload("classpath:excel/order_dishes.xlsx", Maps.newHashMap(), list, "", resp);
- }else{
- throw new BusinessException(error);
- }
- }catch (Exception e){
- e.printStackTrace();
- throw new BusinessException(e.getMessage());
- }finally {
- if(cacheService.exists(key)){
- if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
- cacheService.del(key);
- }
- }
- }
- }
- @PostMapping(value = "/revenueExport")
- @ApiOperation(httpMethod = "POST", value = "成本核算Excel导出")
- @RepeatSubmit
- @MethodTime
- public void revenueExport(HttpServletResponse resp, @RequestBody OrderCostWebInDTO orderCostWebInDTO){
- String key ="revenueExport";
- String error = this.checkExcelExport(key);
- try{
- if ("".equals(error)) {
- String templateLocation = "classpath:excel/revenue.xlsx";
- String filename = "";
- Map<String, Object> data = Maps.newHashMap();
- String dateStr = "工单成本核算";
- if(orderCostWebInDTO.getStartDate() != null){
- dateStr = DateFormatUtils.format(orderCostWebInDTO.getStartDate(),"yyyy-MM-dd")+"~"+
- DateFormatUtils.format(orderCostWebInDTO.getEndDate(),"yyyy-MM-dd")+dateStr;
- }
- orgConstrainService.fillOrgParams(orderCostWebInDTO);
- List<OrderCostWebOutDTO> list = orderService.OrderCostList(orderCostWebInDTO);
- double totalActualCost = list.stream().mapToDouble(a-> Double.parseDouble(a.getStandard())).sum();
- double totalActualIncome =list.stream().mapToDouble(a-> Double.parseDouble(a.getActual())).sum();
- data.put("title",dateStr);
- data.put("title2","标准成本合计:"+totalActualCost+"元;成本金额合计:"+totalActualIncome+"元");
- ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
- }else{
- throw new BusinessException(error);
- }
- }catch (Exception e){
- e.printStackTrace();
- throw new BusinessException(e.getMessage());
- }finally {
- if(cacheService.exists(key)){
- if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
- cacheService.del(key);
- }
- }
- }
- }
- @PostMapping(value = "/orderExport")
- @ApiOperation(httpMethod = "POST", value = "订单Excel导出")
- public void orderExport(HttpServletResponse resp,@RequestBody OrderWebInDTO orderWebInDTO){
- String key ="orderExport";
- String error = this.checkExcelExport(key);
- try{
- if ("".equals(error)) {
- String templateLocation = "classpath:excel/order.xlsx";
- String filename = "";
- Map<String, Object> data = Maps.newHashMap();
- List<OrderExcelDTO> list = orderService.excelList(orderWebInDTO);
- ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
- }else{
- throw new BusinessException(error);
- }
- }catch (Exception e){
- e.printStackTrace();
- throw new BusinessException(e.getMessage());
- }finally {
- if(cacheService.exists(key)){
- if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
- cacheService.del(key);
- }
- }
- }
- }
- @DistributedLock(fairLock =true)
- private String checkExcelExport(String key){
- String returnVal = "";
- String user = TokenContext.cureWebUser().getUserId().toString();
- if (!cacheService.exists(key)) {
- cacheService.setex(key,300,user);
- } else {
- String val = cacheService.get(key);
- if(val.equals(user)){
- returnVal = "正在导出数据,请耐心等待...";
- }else{
- returnVal = "其他用户正在导出数据,请稍后再试";
- }
- }
- return returnVal;
- }
- @RequestMapping(value = "/uploadArrayFile", method = RequestMethod.POST)
- @ApiOperation(value = "阿里云图片上传")
- @ResponseBody
- @MethodTime
- public VaultsResponse uploadArrayFile(@RequestParam("files") List<MultipartFile> files, @RequestBody List<PriceUploadDto> list){
- log.info(files);
- log.info(list);
- /* VaultsResponse<List<PriceUploadDto>> vaultsResponse = ossUtils.uploadArrayFile(list);
- if(vaultsResponse.validate()){
- return orderService.updateOrderUrl(list);
- }*/
- return VaultsResponse.success();
- }
- }
|