| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- 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.log.OperateType;
- import com.poteviohealth.cgp.common.facade.log.OperationLog;
- 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.integrated.finance.model.CardAccTransRecharge;
- import com.poteviohealth.cgp.common.integrated.finance.model.MemberPlanDTO;
- import com.poteviohealth.cgp.common.integrated.finance.model.MemberPlanPageDTO;
- 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.DistinctionDTO;
- import com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO;
- import com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO;
- import com.poteviohealth.cgp.statistics.service.IDistinctionService;
- import com.poteviohealth.cgp.statistics.service.IOrderService;
- import com.poteviohealth.cgp.statistics.service.IWatermarkImgService;
- 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.mock.web.MockMultipartFile;
- 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.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- 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;
- @Resource
- private IWatermarkImgService watermarkImgService;
- @Resource
- private IDistinctionService distinctionService;
- @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 = "阿里云图片上传")
- @MethodTime
- @ResponseBody
- public VaultsResponse<DistinctionDTO> uploadArrayFile(@RequestParam("file") MultipartFile file,@RequestParam("orderId") Long orderId,@RequestParam("uidList") List<String> uidList){
- log.info(orderId);
- //图片检查
- try {
- DistinctionDTO dto;
- Integer pos = file.getOriginalFilename().lastIndexOf('.');
- String suffix = "";
- if (pos != -1) {
- suffix = file.getOriginalFilename().substring(pos);
- }
- if(suffix.indexOf("mp4") != -1){
- //视频处理
- File tempFile = File.createTempFile("temp_", ".mp4");
- file.transferTo(tempFile);
- MultipartFile videoFile = new MockMultipartFile(tempFile.getName(), new FileInputStream(tempFile));
- File imageFile = ossUtils.generateCover(tempFile);
- MultipartFile tempMultipartFile = new MockMultipartFile(imageFile.getName(), new FileInputStream(imageFile));
- dto = distinctionService.checkImg(tempMultipartFile,orderId,uidList);
- if(dto.getOrderId() ==null){
- VaultsResponse<String> vaultsResponse = ossUtils.uploadOneFile(videoFile,orderId);
- dto.setUrl(vaultsResponse.getData());
- }
- tempFile.delete();
- imageFile.delete();
- }else{
- //图片处理
- dto = distinctionService.checkImg(file,orderId,uidList);
- if(dto.getOrderId() ==null){
- VaultsResponse<String> vaultsResponse = ossUtils.uploadOneFile(file,orderId);
- dto.setUrl(vaultsResponse.getData());
- }
- }
- return VaultsResponse.success(dto);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return VaultsResponse.failed();
- }
- @PostMapping("/orderFile")
- @ApiOperation(value = "工单照片")
- @ResponseBody
- @OperationLog(type = OperateType.UPDATE, description = "工单照片处理")
- @MethodTime
- public VaultsResponse orderFile(@RequestBody List<PriceUploadDto> list) {
- //处理水印
- VaultsResponse<List<PriceUploadDto>> vaultsResponse = watermarkImgService.printingWatermark(list);
- if(!vaultsResponse.validate()){
- return vaultsResponse;
- }
- list = vaultsResponse.getData();
- //处理照片
- watermarkImgService.updateOrderUrl(list);
- return VaultsResponse.success();
- }
- @PostMapping(value = "/pageCardExport")
- @ApiOperation(httpMethod = "POST", value = "后台账户查询Excel导出")
- public void orderExport(HttpServletResponse resp,@RequestBody MemberPlanPageDTO dto){
- String key ="pageCardExport";
- String error = this.checkExcelExport(key);
- try{
- if ("".equals(error)) {
- String templateLocation = "classpath:excel/pageCard.xlsx";
- String filename = "客户账户.xlsx";
- Map<String, Object> data = Maps.newHashMap();
- orgConstrainService.fillOrgParams(dto);
- List<MemberPlanDTO> list = orderService.pageCardExcel(dto);
- 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 = "/transRechargeExcel")
- @ApiOperation(httpMethod = "POST", value = "账户充值Excel导出")
- @RepeatSubmit
- @MethodTime
- public void transRechargeExcel(HttpServletResponse resp, @RequestBody CardWebInDTO dto){
- String key ="transRechargeExcel";
- String error = this.checkExcelExport(key);
- try{
- if ("".equals(error)) {
- orgConstrainService.fillOrgParams(dto);
- Map<String,Object> maps = Maps.newHashMap();
- String start = DateFormatUtils.format(dto.getStartDate(), "yyyy-MM");
- String end = DateFormatUtils.format(dto.getEndDate(), "yyyy-MM");
- if(start.equals(end)){
- maps.put("title", start+"充值记录");
- }else{
- maps.put("title", start+"到"+end+"充值记录");
- }
- List<CardAccTransRecharge> list = orderService.transRechargeExcel(dto);
- ExcelUtils2.easyDownload("classpath:excel/trans_recharge.xlsx",maps, 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);
- }
- }
- }
- }
- }
|