1
This commit is contained in:
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@RestController()
|
||||
@@ -95,4 +96,15 @@ public class ReportController {
|
||||
log.info("销量排名top10:{},{}", begin, end);
|
||||
return Result.success(reportService.getSalesTop10(begin, end));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出运营数据报表
|
||||
* @param response
|
||||
*/
|
||||
@GetMapping("/export")
|
||||
@ApiOperation("导出运营数据报表")
|
||||
public void export(HttpServletResponse response){
|
||||
reportService.exportBusinessData(response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +56,18 @@ public class ShoppingCartController {
|
||||
shoppingCartService.cleanShoppingCart();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除购物车中一个商品
|
||||
* @param shoppingCartDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/sub")
|
||||
@ApiOperation("删除购物车中一个商品")
|
||||
public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||
log.info("删除购物车中一个商品,商品:{}", shoppingCartDTO);
|
||||
shoppingCartService.subShoppingCart(shoppingCartDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,4 +49,11 @@ public interface ShoppingCartMapper {
|
||||
* @param shoppingCartList
|
||||
*/
|
||||
void insertBatch(List<ShoppingCart> shoppingCartList);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id删除购物车数据
|
||||
*/
|
||||
@Delete("delete from shopping_cart where id = #{id}")
|
||||
void deleteById(Long id);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.sky.vo.SalesTop10ReportVO;
|
||||
import com.sky.vo.TurnoverReportVO;
|
||||
import com.sky.vo.UserReportVO;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public interface ReportService {
|
||||
@@ -44,4 +45,11 @@ public interface ReportService {
|
||||
* @return
|
||||
*/
|
||||
SalesTop10ReportVO getSalesTop10(LocalDate begin, LocalDate end);
|
||||
|
||||
|
||||
/**
|
||||
* 导出运营数据报表
|
||||
* @param response
|
||||
*/
|
||||
void exportBusinessData(HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,12 @@ import java.util.List;
|
||||
public interface ShoppingCartService {
|
||||
|
||||
|
||||
/**
|
||||
* 删除购物车中一个商品
|
||||
* @param shoppingCartDTO
|
||||
*/
|
||||
void subShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||
|
||||
/**
|
||||
* 添加购物车
|
||||
* @param shoppingCartDTO
|
||||
|
||||
@@ -5,15 +5,20 @@ import com.sky.entity.Orders;
|
||||
import com.sky.mapper.OrderMapper;
|
||||
import com.sky.mapper.UserMapper;
|
||||
import com.sky.service.ReportService;
|
||||
import com.sky.vo.OrderReportVO;
|
||||
import com.sky.vo.SalesTop10ReportVO;
|
||||
import com.sky.vo.TurnoverReportVO;
|
||||
import com.sky.vo.UserReportVO;
|
||||
import com.sky.service.WorkspaceService;
|
||||
import com.sky.vo.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
@@ -32,6 +37,8 @@ public class ReportServiceImpl implements ReportService {
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
@Autowired
|
||||
private WorkspaceService workspaceService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -224,4 +231,75 @@ public class ReportServiceImpl implements ReportService {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出运营数据报表
|
||||
* @param response
|
||||
*/
|
||||
@Override
|
||||
public void exportBusinessData(HttpServletResponse response) {
|
||||
//1、查询数据库 获取营业数据 查询最近30天的数据
|
||||
LocalDate dateBegin = LocalDate.now().minusDays(30);
|
||||
LocalDate dateEnd = LocalDate.now().minusDays(1);
|
||||
|
||||
BusinessDataVO businessDataVO = workspaceService.getBusinessData(LocalDateTime.of(dateBegin, LocalTime.MIN), LocalDateTime.of(dateEnd, LocalTime.MAX));
|
||||
|
||||
//2、通过POI将数据写入Excel文件中
|
||||
InputStream in = this.getClass().getClassLoader().getResourceAsStream("template/运营数据报表模板.xlsx");
|
||||
|
||||
try {
|
||||
//基于模板文件创建一个新的excel文件
|
||||
XSSFWorkbook excel = new XSSFWorkbook(in);
|
||||
|
||||
//获取表格文件的标签页
|
||||
XSSFSheet sheet = excel.getSheet("Sheet1");
|
||||
|
||||
//填充数据--时间
|
||||
sheet.getRow(1).getCell(1).setCellValue("时间" + dateBegin + "至" + dateEnd);
|
||||
|
||||
//获得第四行
|
||||
XSSFRow row = sheet.getRow(3);
|
||||
row.getCell(2).setCellValue(businessDataVO.getTurnover());
|
||||
row.getCell(4).setCellValue(businessDataVO.getOrderCompletionRate());
|
||||
row.getCell(6).setCellValue(businessDataVO.getNewUsers());
|
||||
|
||||
//获得第五行
|
||||
row = sheet.getRow(4);
|
||||
row.getCell(2).setCellValue(businessDataVO.getValidOrderCount());
|
||||
row.getCell(4).setCellValue(businessDataVO.getUnitPrice());
|
||||
|
||||
//填充明细数据
|
||||
for(int i = 0; i < 30; i ++){
|
||||
LocalDate date = dateBegin.plusDays(i);
|
||||
//查询某一天的营业数据
|
||||
BusinessDataVO businessData = workspaceService.getBusinessData(LocalDateTime.of(date, LocalTime.MIN), LocalDateTime.of(date, LocalTime.MAX));
|
||||
|
||||
//获得某一行
|
||||
row = sheet.getRow(7 + i);
|
||||
row.getCell(1).setCellValue(date.toString());
|
||||
row.getCell(2).setCellValue(businessData.getTurnover());
|
||||
row.getCell(3).setCellValue(businessData.getValidOrderCount());
|
||||
row.getCell(4).setCellValue(businessData.getOrderCompletionRate());
|
||||
row.getCell(5).setCellValue(businessData.getUnitPrice());
|
||||
row.getCell(6).setCellValue(businessData.getNewUsers());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//3、通过输出流将Excel文件下载到客户端浏览器
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
excel.write(out);
|
||||
|
||||
//关闭资源
|
||||
out.close();
|
||||
excel.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||
private SetmealMapper setmealMapper;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加购物车
|
||||
* @param shoppingCartDTO
|
||||
@@ -107,4 +109,34 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
shoppingCartMapper.deleteByUserId(userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除购物车中的商品
|
||||
* @param shoppingCartDTO
|
||||
*/
|
||||
@Override
|
||||
public void subShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||
ShoppingCart shoppingCart = new ShoppingCart();
|
||||
BeanUtils.copyProperties(shoppingCartDTO,shoppingCart);
|
||||
|
||||
//设置查询条件 查询当前用户的购物车数据
|
||||
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||
|
||||
if (list != null && list.size() > 0) {
|
||||
ShoppingCart cart = list.get(0);
|
||||
|
||||
Integer number = cart.getNumber();
|
||||
if(number == 1){
|
||||
//当前商品在购物车中的份数为1,直接删除当前记录
|
||||
shoppingCartMapper.deleteById(shoppingCart.getId());
|
||||
}else{
|
||||
//当前商品在购物车中的份数不为1,修改份数即可
|
||||
cart.setNumber(number-1);
|
||||
shoppingCartMapper.updateNumberById(cart);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BIN
sky-server/src/main/resources/template/运营数据报表模板.xlsx
Normal file
BIN
sky-server/src/main/resources/template/运营数据报表模板.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user