data-server/src/main/java/com/yuanchu/mom/controller/DataReportingController.java
@@ -148,8 +148,7 @@ return Result.success(dataReportingService.getDataList()); } @ValueAuth @ApiOperation(value = "å¯¼å ¥") @ApiOperation(value = "å¯¼å ¥æ°æ®ä¸æ¥å表") @PostMapping("/inputCsv") public Result<?> inputCsv(@RequestParam("file") MultipartFile file) throws IOException { CsvReader reader = CsvUtil.getReader(); @@ -188,7 +187,23 @@ public Result downDataReportingFile(@RequestBody Map<String, Object> data) { Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); DataReportingPageDto dataReportingPageDto = JSON.parseObject(JSON.toJSONString(data.get("entity")), DataReportingPageDto.class); return Result.success(dataReportingService.downDataReportingFile(page, dataReportingPageDto)); return Result.success("å¯¼åºæå", dataReportingService.downDataReportingFile(page, dataReportingPageDto)); } @ApiOperation(value = "导åºé¡¹ç®æ°æ®ç»è®¡å表") @PostMapping("/downProductCountFile") public Result downProductCountFile(@RequestBody Map<String, Object> data) { Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); ProductCountDto productCountDto = JSON.parseObject(JSON.toJSONString(data.get("entity")), ProductCountDto.class); return Result.success("å¯¼åºæå", dataReportingService.downProductCountFile(page, productCountDto)); } @ApiOperation(value = "导åºåå·¥æ°æ®ç»è®¡å表") @PostMapping("/downRegistrantCountFile") public Result downRegistrantCountFile(@RequestBody Map<String, Object> data) { Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); RegistrantCountDto registrantCountDto = JSON.parseObject(JSON.toJSONString(data.get("entity")), RegistrantCountDto.class); return Result.success("å¯¼åºæå", dataReportingService.downRegistrantCountFile(page, registrantCountDto)); } } data-server/src/main/java/com/yuanchu/mom/dto/RegistrantCountDto.java
@@ -59,7 +59,7 @@ */ @ApiModelProperty("å±ç°é") @ValueTableShow(6) private Integer show; private Integer showNum; /** * ç¹å»é */ data-server/src/main/java/com/yuanchu/mom/service/DataReportingService.java
@@ -33,4 +33,8 @@ String downDataReportingFile(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto); String downProductCountFile(IPage<ProductCountDto> page, ProductCountDto productCountDto); String downRegistrantCountFile(IPage<RegistrantCountDto> page, RegistrantCountDto registrantCountDto); } data-server/src/main/java/com/yuanchu/mom/service/impl/DataReportingServiceImpl.java
@@ -1,5 +1,9 @@ package com.yuanchu.mom.service.impl; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.file.FileReader; import cn.hutool.core.net.URLDecoder; import cn.hutool.core.text.csv.CsvUtil; import cn.hutool.core.text.csv.CsvWriter; import cn.hutool.core.util.CharsetUtil; @@ -22,9 +26,13 @@ import com.yuanchu.mom.utils.QueryWrappers; import com.yuanchu.mom.utils.ServletUtils; import lombok.AllArgsConstructor; import org.apache.tomcat.util.http.fileupload.IOUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.*; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; @@ -41,13 +49,17 @@ * @createDate 2023-12-23 10:39:43 */ @Service @AllArgsConstructor public class DataReportingServiceImpl extends ServiceImpl<DataReportingMapper, DataReporting> implements DataReportingService { @Resource private DataReportingMapper dataReportingMapper; @Resource private GetLook getLook; @Value("${outPath}") private String outPath; @Override public Map<String, Object> selectDataReportingList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto) { @@ -161,9 +173,10 @@ @Override public String downDataReportingFile(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto) { Map<String, Object> map = selectDataReportingList(page, dataReportingPageDto); String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd HH_mm_ss")); String name = "D:\\Download\\æ°æ®ä¸æ¥ " + time + ".csv"; CsvWriter writer = CsvUtil.getWriter(name, CharsetUtil.CHARSET_GBK); String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); String name = "æ°æ®ä¸æ¥" + time + ".csv"; String path = outPath + name; CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); writer.write(new String[]{"å¯¼åºæ¶é´ï¼"+time}); writer.write(new String[]{}); writer.write(new String[]{}); @@ -183,7 +196,65 @@ writer.write(str); }); writer.close(); return null; return name; } @Override public String downProductCountFile(IPage<ProductCountDto> page, ProductCountDto productCountDto) { Map<String, Object> map = selectProductCountDtoPageList(page, productCountDto); String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); String name = "é¡¹ç®æ°æ®ç»è®¡" + time + ".csv"; String path = outPath + name; CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); writer.write(new String[]{"å¯¼åºæ¶é´ï¼"+time}); writer.write(new String[]{}); writer.write(new String[]{}); writer.write(new String[]{}); writer.write(new String[]{}); List<Map<String, String>> head = JSON.parseObject(JSON.toJSONString(map.get("head")), List.class); String[] str = new String[head.size()]; for (int i = 0; i < head.size(); i++) { str[i] = head.get(i).get("value"); } writer.write(str); JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a->{ Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(a), Map.class); for (int i = 0; i < head.size(); i++) { str[i] = map1.get(head.get(i).get("label"))==null?null:map1.get(head.get(i).get("label"))+""; } writer.write(str); }); writer.close(); return name; } @Override public String downRegistrantCountFile(IPage<RegistrantCountDto> page, RegistrantCountDto registrantCountDto) { Map<String, Object> map = selectRegistrantCountDtoPageList(page, registrantCountDto); String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); String name = "åå·¥æ°æ®ç»è®¡" + time + ".csv"; String path = outPath + name; CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); writer.write(new String[]{"å¯¼åºæ¶é´ï¼"+time}); writer.write(new String[]{}); writer.write(new String[]{}); writer.write(new String[]{}); writer.write(new String[]{}); List<Map<String, String>> head = JSON.parseObject(JSON.toJSONString(map.get("head")), List.class); String[] str = new String[head.size()]; for (int i = 0; i < head.size(); i++) { str[i] = head.get(i).get("value"); } writer.write(str); JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a->{ Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(a), Map.class); for (int i = 0; i < head.size(); i++) { str[i] = map1.get(head.get(i).get("label"))==null?null:map1.get(head.get(i).get("label"))+""; } writer.write(str); }); writer.close(); return name; } } data-server/src/main/resources/mapper/DataReportingMapper.xml
@@ -53,7 +53,7 @@ </select> <select id="selectRegistrantCountDtoPageList" resultType="com.yuanchu.mom.dto.RegistrantCountDto"> select * from ( select id, department, registrant, product, name, sum(`show`) `show`, sum(click) click, sum(account_consumption)account_consumption, sum(rebate_consumption) rebate_consumption,(sum(rebate_consumption)+sum(remark)) rebate_consumption2, sum(discounted_consumption) discounted_consumption, sum(fans_add) fans_add, sum(actual_cost) actual_cost, sum(customer_costs) customer_costs, sum(profit) profit, sum(agent_rebate) agent_rebate, sum(customer_rebate) customer_rebate, sum(remark) remark, create_time, update_time, create_user select id, department, registrant, product, name, sum(show_num) show_num, sum(click) click, sum(account_consumption)account_consumption, sum(rebate_consumption) rebate_consumption,(sum(rebate_consumption)+sum(remark)) rebate_consumption2, sum(discounted_consumption) discounted_consumption, sum(fans_add) fans_add, sum(actual_cost) actual_cost, sum(customer_costs) customer_costs, sum(profit) profit, sum(agent_rebate) agent_rebate, sum(customer_rebate) customer_rebate, sum(remark) remark, create_time, update_time, create_user from data_reporting group by registrant ) a framework/src/main/java/com/yuanchu/mom/config/FiferConfig.java
@@ -33,9 +33,13 @@ response.setStatus(HttpServletResponse.SC_OK); return true; } HandlerMethod h = (HandlerMethod)handler; ValueAuth annotation = h.getMethodAnnotation(ValueAuth.class); if(annotation!=null){ try { HandlerMethod h = (HandlerMethod)handler; ValueAuth annotation = h.getMethodAnnotation(ValueAuth.class); if(annotation!=null){ return true; } }catch (Exception e){ return true; } String[] strs = request.getRequestURL().toString().split(serverPort); @@ -96,6 +100,7 @@ list.add("/user/enter"); list.add("/user/refresh"); list.add("/outPath/**"); this.list = list; } framework/src/main/java/com/yuanchu/mom/config/OpenFifer.java
@@ -1,8 +1,10 @@ package com.yuanchu.mom.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import javax.annotation.Resource; @@ -16,6 +18,25 @@ @Resource private PowerConfig powerConfig; @Value("${file.path}") private String filePath; @Value("${outPath}") private String outPath; public void addResourceHandlers(ResourceHandlerRegistry registry) { //é ç½®æ¦æªå¨è®¿é®éæèµæº registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); //设置æä»¶èæè·¯å¾æ å° registry.addResourceHandler("/img/**").addResourceLocations("file:"+filePath+"/"); registry.addResourceHandler("/outPath/**").addResourceLocations("file:"+outPath); } @Override protected void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(fiferConfig).addPathPatterns("/**"); framework/src/main/java/com/yuanchu/mom/config/PowerConfig.java
@@ -30,7 +30,7 @@ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if(handler instanceof HandlerMethod) { if(request.getRequestURL().toString().equals("http://127.0.0.1:8001/error")){ if(request.getRequestURL().toString().contains("/error") || request.getRequestURL().toString().contains("/outPath")){ return HandlerInterceptor.super.preHandle(request, response, handler); } HandlerMethod h = (HandlerMethod)handler; framework/src/main/java/com/yuanchu/mom/config/WebMvcConfig.java
ÎļþÒÑɾ³ý system-run/src/main/java/com/yuanchu/mom/SystemRunApplication.java
@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Configuration; import javax.annotation.Resource; system-run/src/main/resources/application.yml
@@ -25,3 +25,5 @@ enabled: false # å ³é httpclient okhttp: enabled: true # å¼å¯ okhttp outPath: D:/Download/