ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java
@@ -109,6 +109,7 @@ @PostMapping(value = "/profitDetails") public AjaxResult<ProfitDetailsVO> profitDetails(@RequestBody ProfitDetailsQuery query) { Long objectId = tokenService.getLoginUser().getObjectId(); Integer roleType = tokenService.getLoginUser().getRoleType(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.nonNull(query.getTimeType())){ @@ -140,13 +141,20 @@ query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } } return AjaxResult.success(orderMealService.profitDetails(query)); ProfitDetailsVO profitDetailsVO; if(roleType.equals(2)){ profitDetailsVO = orderMealService.profitDetails(query); }else { profitDetailsVO = orderSaleService.profitDetails(query); } return AjaxResult.success(profitDetailsVO); } @ApiOperation( value = "盈利明细导出") @PostMapping(value = "/profitDetailsExport") public void profitDetailsExport(@RequestBody ProfitDetailsQuery query) { Long objectId = tokenService.getLoginUser().getObjectId(); Integer roleType = tokenService.getLoginUser().getRoleType(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ @@ -179,7 +187,12 @@ query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } } List<GoodsProfitVO> list = orderMealService.profitDetailsExport(query); List<GoodsProfitVO> list; if(roleType.equals(2)){ list = orderMealService.profitDetailsExport(query); }else { list = orderSaleService.profitDetailsExport(query); } Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), GoodsProfitVO.class, list); HttpServletResponse response = WebUtils.response(); response.setContentType("application/vnd.ms-excel"); @@ -256,38 +269,35 @@ Integer roleType = tokenService.getLoginUser().getRoleType(); Long objectId = tokenService.getLoginUser().getObjectId(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.isNull(query.getTimeType())){ query.setTimeType(3); } LocalDateTime startTime = null; LocalDateTime endTime = null; switch (query.getTimeType()){ case 1: // 今日 startTime = DateUtils.getDayStart(LocalDateTime.now()); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); LocalDateTime startTime = null; LocalDateTime endTime = null; switch (query.getTimeType()){ case 1: // 今日 startTime = DateUtils.getDayStart(LocalDateTime.now()); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); List<OrderTrendsVO> orderTrendsVOS; if(roleType == 2){ orderTrendsVOS = orderMealService.orderingTrends(query); @@ -342,9 +352,10 @@ List<PersonnelStatisticsVO> personnelStatisticsVOS = orderMealService.personnelStatistics(query); personnelStatisticsAndSumVO.setPersonnelStatisticsVOS(personnelStatisticsVOS); if(!CollectionUtils.isEmpty(personnelStatisticsVOS)){ personnelStatisticsAndSumVO.setPersonCountSum(personnelStatisticsVOS.stream().filter(e->e.getPersonCount() != null).mapToInt(PersonnelStatisticsVO::getPersonCount).sum()); int sum = personnelStatisticsVOS.stream().filter(e -> e.getPersonCount() != null).mapToInt(PersonnelStatisticsVO::getPersonCount).sum(); personnelStatisticsAndSumVO.setPersonCountSum(sum); // 计算列表中平均金额乘以人数的总和 personnelStatisticsAndSumVO.setTotalMoney(personnelStatisticsVOS.stream().filter(e->e.getPersonCount() != null).mapToDouble(personnelStatisticsVO -> personnelStatisticsVO.getAvgAmount().doubleValue() * personnelStatisticsVO.getPersonCount()).sum()); personnelStatisticsAndSumVO.setTotalMoney(personnelStatisticsVOS.stream().filter(e->e.getPersonCount() != null).mapToDouble(personnelStatisticsVO -> (personnelStatisticsVO.getAvgAmount().doubleValue() * personnelStatisticsVO.getPersonCount()) / sum).sum()); } return AjaxResult.success(personnelStatisticsAndSumVO); } ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TGoodsController.java
@@ -4,13 +4,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.CodeGenerateUtils; import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.domain.TGoods; import com.ruoyi.system.domain.TGoodsType; import com.ruoyi.system.domain.*; import com.ruoyi.system.query.TGoodsQuery; import com.ruoyi.system.service.TGoodsService; import com.ruoyi.system.service.TGoodsTypeService; import com.ruoyi.system.service.*; import com.ruoyi.system.vo.TGoodsVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -36,12 +35,18 @@ private final TGoodsService goodsService; private final TGoodsTypeService goodsTypeService; private final TokenService tokenService; private final TOrderStockGoodsService orderStockGoodsService; private final TOrderSaleGoodsService orderSaleGoodsService; private final TOrderMealGoodsService orderMealGoodsService; @Autowired public TGoodsController(TGoodsService goodsService, TGoodsTypeService goodsTypeService, TokenService tokenService) { public TGoodsController(TGoodsService goodsService, TGoodsTypeService goodsTypeService, TokenService tokenService, TOrderStockGoodsService orderStockGoodsService, TOrderSaleGoodsService orderSaleGoodsService, TOrderMealGoodsService orderMealGoodsService) { this.goodsService = goodsService; this.goodsTypeService = goodsTypeService; this.tokenService = tokenService; this.orderStockGoodsService = orderStockGoodsService; this.orderSaleGoodsService = orderSaleGoodsService; this.orderMealGoodsService = orderMealGoodsService; } /** @@ -64,6 +69,7 @@ @PostMapping(value = "/add") public AjaxResult<Boolean> add(@RequestBody TGoods dto) { dto.setShopId(tokenService.getLoginUser().getObjectId()); dto.setGoodsNum(CodeGenerateUtils.generateVolumeSn()); return AjaxResult.success(goodsService.save(dto)); } @@ -73,6 +79,24 @@ @ApiOperation( value = "修改商品管理") @PostMapping(value = "/update") public AjaxResult<Boolean> update(@RequestBody TGoods dto) { // 判断是否修改了名称 TGoods goods = goodsService.getById(dto.getId()); if(!goods.getGoodsName().equals(dto.getGoodsName())){ List<TOrderStockGoods> orderStockGoods = orderStockGoodsService.list(Wrappers.lambdaQuery(TOrderStockGoods.class) .eq(TOrderStockGoods::getGoodsNum, goods.getGoodsNum())); orderStockGoods.stream().forEach(tOrderStockGoods -> tOrderStockGoods.setGoodsNum(dto.getGoodsNum())); orderStockGoodsService.updateBatchById(orderStockGoods); List<TOrderMealGoods> orderMealGoods = orderMealGoodsService.list(Wrappers.lambdaQuery(TOrderMealGoods.class) .eq(TOrderMealGoods::getGoodsNum, goods.getGoodsNum())); orderMealGoods.stream().forEach(tOrderMealGoods -> tOrderMealGoods.setGoodsNum(dto.getGoodsNum())); orderMealGoodsService.updateBatchById(orderMealGoods); List<TOrderSaleGoods> list = orderSaleGoodsService.list(Wrappers.lambdaQuery(TOrderSaleGoods.class) .eq(TOrderSaleGoods::getGoodsNum, goods.getGoodsNum())); list.stream().forEach(tOrderSaleGoods -> tOrderSaleGoods.setGoodsNum(dto.getGoodsNum())); orderSaleGoodsService.updateBatchById(list); } return AjaxResult.success(goodsService.updateById(dto)); } ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TOrderSaleController.java
@@ -77,8 +77,9 @@ */ @ApiOperation( value = "查询销售金额统计") @PostMapping(value = "/amountSum") public AjaxResult<AmountSumVO> amountSum(@RequestBody TOrderMealQuery query) { public AjaxResult<AmountSumVO> amountSum(@RequestBody TOrderSaleQuery query) { query.setShopId(tokenService.getLoginUser().getObjectId()); orderSaleService.amountSum(query); return AjaxResult.success(orderSaleService.amountSum(query)); } @@ -94,6 +95,14 @@ List<TOrderSaleGoods> list = orderSaleGoodsService.list(Wrappers.lambdaQuery(TOrderSaleGoods.class) .eq(TOrderSaleGoods::getOrderId, orderSale.getId())); orderSaleVO.setOrderSaleGoods(list); BigDecimal sum = BigDecimal.ZERO; Integer count = 0; for (TOrderSaleGoods tOrderSaleGoods : list) { sum = sum.add(tOrderSaleGoods.getThisSalePrice().multiply(new BigDecimal(tOrderSaleGoods.getGoodsCount()))); count = count + tOrderSaleGoods.getGoodsCount(); } orderSaleVO.setGoodsAmount(sum); orderSaleVO.setGoodsCount(count); return AjaxResult.success(orderSaleVO); } ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
@@ -123,6 +123,7 @@ RoleInfoVO roleInfoVo = new RoleInfoVO(); roleInfoVo.setRoleId(role.getRoleId()); roleInfoVo.setRoleName(role.getRoleName()); roleInfoVo.setRemark(role.getRemark()); // 获取当前角色的菜单列表 List<SysMenu> menus = menuService.selectListByRoleId(roleId); @@ -132,7 +133,7 @@ List<Long> menusId = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList()); // 获取当前的权限菜单(有层级) List<SysMenu> levelMenus = roleService.getMenuLevelList(menusId); // List<SysMenu> levelMenus = roleService.getMenuLevelList(menusId); roleInfoVo.setMenus(menusId); return AjaxResult.success(roleInfoVo); ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
@@ -373,6 +373,15 @@ public static LocalDate stringToLocalDate(String time) { return LocalDate.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd")); } /** * 字符串转为localdate * * @param time localdate * @return 字符串 */ public static LocalDateTime stringToLocalDateTime(String time) { return LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); } /** * LocalDateTime转Date ruoyi-system/src/main/java/com/ruoyi/system/mapper/TGoodsMapper.java
@@ -5,6 +5,7 @@ import com.ruoyi.system.domain.TGoods; import com.ruoyi.system.query.TGoodsQuery; import com.ruoyi.system.vo.TGoodsVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -17,6 +18,7 @@ * @author xiaochen * @since 2024-08-14 */ @Mapper public interface TGoodsMapper extends BaseMapper<TGoods> { /** ruoyi-system/src/main/java/com/ruoyi/system/mapper/TOrderSaleMapper.java
@@ -36,7 +36,7 @@ * @param query * @return */ AmountSumVO amountSum(@Param("query") TOrderMealQuery query); AmountSumVO amountSum(@Param("query") TOrderSaleQuery query); /** * 查询销售销售量统计 @@ -79,4 +79,27 @@ * @return */ List<TDataGeneratorVO> saleGeneratorListExport(@Param("query")TDataGeneratorQuery query); /** * 销售利润详情列表 * @param query * @param pageInfo * @return */ List<GoodsProfitVO> profitDetails(@Param("query")ProfitDetailsQuery query, @Param("pageInfo")PageInfo<GoodsProfitVO> pageInfo); /** * 查询利润详情统计 * @param query * @return */ Map<String, Double> profitDetailsStatistics(@Param("query")ProfitDetailsQuery query); /** * 导出 * @param query * @return */ List<GoodsProfitVO> profitDetailsExport(@Param("query")ProfitDetailsQuery query); } ruoyi-system/src/main/java/com/ruoyi/system/mapper/TOrderStockGoodsMapper.java
@@ -1,10 +1,12 @@ package com.ruoyi.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ruoyi.system.domain.TOrderSaleGoods; import com.ruoyi.system.domain.TOrderStockGoods; import com.ruoyi.system.query.TDataGeneratorStockQuery; import org.apache.ibatis.annotations.Param; import java.util.List; import java.util.Map; /** @@ -17,4 +19,11 @@ */ public interface TOrderStockGoodsMapper extends BaseMapper<TOrderStockGoods> { /** * 根据时间获取商品列表 * @param orderTime * @param shopId * @return */ List<TOrderStockGoods> getListByTimeAndShopId(@Param("orderTime") String orderTime, @Param("shopId")Long shopId); } ruoyi-system/src/main/java/com/ruoyi/system/service/TOrderSaleService.java
@@ -40,7 +40,7 @@ * @param query * @return */ AmountSumVO amountSum(TOrderMealQuery query); AmountSumVO amountSum(TOrderSaleQuery query); /** * 查询销售销售量统计 @@ -102,4 +102,18 @@ * @return */ List<TDataGeneratorVO> saleGeneratorListExport(TDataGeneratorQuery query); /** * 盈利明细详情 * @param query * @return */ ProfitDetailsVO profitDetails(ProfitDetailsQuery query); /** * 明细导出 * @param query * @return */ List<GoodsProfitVO> profitDetailsExport(ProfitDetailsQuery query); } ruoyi-system/src/main/java/com/ruoyi/system/service/TOrderStockGoodsService.java
@@ -1,9 +1,12 @@ package com.ruoyi.system.service; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.system.domain.TOrderSaleGoods; import com.ruoyi.system.domain.TOrderStockGoods; import com.ruoyi.system.query.TDataGeneratorStockQuery; import java.time.LocalDate; import java.util.List; import java.util.Map; /** @@ -16,4 +19,12 @@ */ public interface TOrderStockGoodsService extends IService<TOrderStockGoods> { /** * 查询下单时间和店铺的id * @param orderTime * @param shopId * @return */ List<TOrderStockGoods> getListByTimeAndShopId(String orderTime, Long shopId); } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java
@@ -298,9 +298,13 @@ e.setGeneratorId(dataGenerator.getId()); e.setOrderNum(OrderNumConstants.SALE + CodeGenerateUtils.generateVolumeSn()); e.setIsCover(0); e.setStatus(2); }); List<TOrderSaleGoods> orderSaleGoods = orderSales.stream().map(TOrderSale::getOrderSaleGoods).flatMap(Collection::stream).collect(Collectors.toList()); TOrderStock orderStockLast = orderStockService.getOne(Wrappers.lambdaQuery(TOrderStock.class) .eq(TOrderStock::getShopId, dto.getShopId()) .orderByDesc(TOrderStock::getStockTime) .last("LIMIT 1")); // 生成进货数据 List<TOrderStock> stockList = new ArrayList<>(); stockDataSets.stream().sorted(Comparator.comparing(TStockDataSet::getStockDate)); @@ -342,45 +346,52 @@ stockList.add(orderStock); }else if(i==0 && Objects.nonNull(stockDataSet)){ // 第一次 第一次的进货时间为上一次的结束时间 开始时间为上一次的开始时间 LocalDate startTime1 = stockDataSet.getStockDate(); List<TOrderSale> collect = orderSales.stream().filter(e -> e.getOrderTime().compareTo(startTime) < 0).collect(Collectors.toList()); List<TOrderSaleGoods> orderSaleGoodsList = new ArrayList<>(); collect.forEach(e->orderSaleGoodsList.addAll(e.getOrderSaleGoods())); // 查询上一次开始之后的订单数据 List<TOrderSale> orderSales1 = orderSaleService.list(new LambdaQueryWrapper<TOrderSale>().gt(TOrderSale::getOrderTime, startTime1)); List<Long> saleIds1 = orderSales1.stream().map(TOrderSale::getId).collect(Collectors.toList()); // 查询上一次的商品 List<TOrderSaleGoods> list = orderSaleGoodsService.list(new LambdaQueryWrapper<TOrderSaleGoods>().in(TOrderSaleGoods::getOrderId, saleIds1)); // 结合上次最后一次的数据 list.addAll(orderSaleGoodsList); // 删除上一次的数据生成 新生成一条数据 TOrderStock orderStock = new TOrderStock(); orderStock.setStockNum(OrderNumConstants.STOCK + CodeGenerateUtils.generateVolumeSn()); orderStock.setStockTime(startTime); orderStock.setIsCover(0); orderStock.setGeneratorId(dataGenerator.getId()); orderStock.setShopId(dto.getShopId()); if(Objects.nonNull(orderStockLast)){ // 查询商品进价 List<TOrderStockGoods> orderStockGoodsList = orderStockGoodsService.list(Wrappers.lambdaQuery(TOrderStockGoods.class).eq(TOrderStockGoods::getOrderId, orderStockLast.getId())); // 第一次 第一次的进货时间为上一次的结束时间 开始时间为上一次的开始时间 LocalDate startTime1 = stockDataSet.getStockDate(); List<TOrderSale> collect = orderSales.stream().filter(e -> e.getOrderTime().compareTo(startTime) < 0).collect(Collectors.toList()); List<TOrderSaleGoods> orderSaleGoodsList = new ArrayList<>(); collect.forEach(e->orderSaleGoodsList.addAll(e.getOrderSaleGoods())); // 查询上一次开始之后的订单数据 List<TOrderSale> orderSales1 = orderSaleService.list(new LambdaQueryWrapper<TOrderSale>().gt(TOrderSale::getOrderTime, startTime1)); List<Long> saleIds1 = orderSales1.stream().map(TOrderSale::getId).collect(Collectors.toList()); // 查询上一次的商品 List<TOrderSaleGoods> list = orderSaleGoodsService.list(new LambdaQueryWrapper<TOrderSaleGoods>().in(TOrderSaleGoods::getOrderId, saleIds1)); // 结合上次最后一次的数据 list.addAll(orderSaleGoodsList); // 删除上一次的数据生成 新生成一条数据 TOrderStock orderStock = new TOrderStock(); orderStock.setStockNum(OrderNumConstants.STOCK + CodeGenerateUtils.generateVolumeSn()); orderStock.setStockTime(orderStockLast.getStockTime()); orderStock.setIsCover(0); orderStock.setGeneratorId(orderStockLast.getGeneratorId()); orderStock.setShopId(dto.getShopId()); Map<String, List<TOrderSaleGoods>> goodsList = list.stream().collect(Collectors.groupingBy(TOrderSaleGoods::getGoodsName)); List<TOrderStockGoods> orderStockGoods = new ArrayList<>(); goodsList.forEach((k,v)->{ TOrderStockGoods tOrderStockGoods = new TOrderStockGoods(); tOrderStockGoods.setGoodsName(k); tOrderStockGoods.setGoodsNum(v.get(0).getGoodsNum()); tOrderStockGoods.setCostPrice(v.get(0).getGoodsCostPrice()); tOrderStockGoods.setSalePrice(v.get(0).getGoodsSalePrice()); // tOrderStockGoods.setThisCostPrice(v.get(0).getThisSalePrice()); tOrderStockGoods.setGoodsPicture(v.get(0).getGoodsPicture()); tOrderStockGoods.setGoodsId(v.get(0).getGoodsId()); int sum = v.stream().mapToInt(TOrderSaleGoods::getGoodsCount).sum(); BigDecimal rate = new BigDecimal(100).subtract(start.getLossRate()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal bigDecimal = new BigDecimal(sum).divide(rate,2,BigDecimal.ROUND_HALF_UP).setScale(0, BigDecimal.ROUND_HALF_UP); tOrderStockGoods.setStockCount(Integer.parseInt(bigDecimal.toString().split("\\.")[0])); orderStockGoods.add(tOrderStockGoods); }); orderStock.setOrderStockGoods(orderStockGoods); stockList.add(orderStock); Map<String, List<TOrderSaleGoods>> goodsList = list.stream().collect(Collectors.groupingBy(TOrderSaleGoods::getGoodsName)); List<TOrderStockGoods> orderStockGoods = new ArrayList<>(); goodsList.forEach((k,v)->{ TOrderStockGoods tOrderStockGoods = new TOrderStockGoods(); tOrderStockGoods.setGoodsName(k); tOrderStockGoods.setGoodsNum(v.get(0).getGoodsNum()); tOrderStockGoods.setCostPrice(v.get(0).getGoodsCostPrice()); tOrderStockGoods.setSalePrice(v.get(0).getGoodsSalePrice()); TOrderStockGoods orderStockGoods1 = orderStockGoodsList.stream().filter(e -> e.getGoodsName().equals(k)).findFirst().orElse(null); if(Objects.nonNull(orderStockGoods1)){ tOrderStockGoods.setThisCostPrice(orderStockGoods1.getThisCostPrice()); } tOrderStockGoods.setGoodsPicture(v.get(0).getGoodsPicture()); tOrderStockGoods.setGoodsId(v.get(0).getGoodsId()); int sum = v.stream().mapToInt(TOrderSaleGoods::getGoodsCount).sum(); BigDecimal rate = new BigDecimal(100).subtract(start.getLossRate()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal bigDecimal = new BigDecimal(sum).divide(rate,2,BigDecimal.ROUND_HALF_UP).setScale(0, BigDecimal.ROUND_HALF_UP); tOrderStockGoods.setStockCount(Integer.parseInt(bigDecimal.toString().split("\\.")[0])); orderStockGoods.add(tOrderStockGoods); }); orderStock.setOrderStockGoods(orderStockGoods); stockList.add(orderStock); } // 处理第一次到下一次的数据 TStockDataSet end = stockDataSets.get(i + 1); @@ -457,12 +468,8 @@ return; } // 删除上一次的数据生成 TOrderStock orderStock = orderStockService.getOne(Wrappers.lambdaQuery(TOrderStock.class) .eq(TOrderStock::getShopId, dto.getShopId()) .orderByDesc(TOrderStock::getStockTime) .last("LIMIT 1")); if(Objects.nonNull(orderStock)){ orderStockService.removeById(orderStock); if(Objects.nonNull(orderStockLast)){ orderStockService.removeById(orderStockLast); } orderSaleService.saveBatch(orderSales); for (TOrderSale orderSale : orderSales) { ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOrderMealServiceImpl.java
@@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; @@ -58,7 +59,6 @@ orderMeal.setMealType(dto.getMealType()); orderMeal.setMealPerson(dto.getMealPerson()); orderMeal.setMealTime(dto.getMealTime()); orderMeal.setOrderMoney(dto.getOrderMoney()); // 查询菜品分类 List<TGoodsType> list1 = goodsTypeService.list(); @@ -75,20 +75,30 @@ List<Long> goodsIds = dto.getMealOrderGoodsDTOS().stream().map(MealOrderGoodsDTO::getGoodsId).collect(Collectors.toList()); List<TGoods> list = goodsService.list(Wrappers.lambdaQuery(TGoods.class) .in(TGoods::getId, goodsIds)); // 查询已存在的菜品 List<TOrderMealGoods> list2 = orderMealGoodsService.list(Wrappers.lambdaQuery(TOrderMealGoods.class) .in(TOrderMealGoods::getOrderId, dto.getId())); dto.getMealOrderGoodsDTOS().forEach(item -> { list.stream().filter(item1 -> item1.getId().equals(item.getGoodsId())).findFirst().ifPresent(item1 -> { TOrderMealGoods orderMealGood = new TOrderMealGoods(); orderMealGood.setGoodsName(item1.getGoodsName()); orderMealGood.setGoodsNum(item1.getGoodsNum()); orderMealGood.setGoodsPicture(item1.getGoodsPicture()); orderMealGood.setGoodsCount(item.getGoodsCount()); orderMealGood.setGoodsSalePrice(item1.getSalePrice()); orderMealGood.setCostPrice(item1.getCostPrice()); orderMealGood.setTypeId(item1.getTypeId()); orderMealGood.setGoodsId(item1.getId()); orderMealGood.setTypeName(list1.stream().filter(item2 -> item2.getId().equals(item1.getTypeId())).findFirst().get().getTypeName()); orderMealGoods.add(orderMealGood); }); if(CollectionUtils.isEmpty(list2)){ list.stream().filter(item1 -> item1.getId().equals(item.getGoodsId())).findFirst().ifPresent(item1 -> { TOrderMealGoods orderMealGood = new TOrderMealGoods(); orderMealGood.setGoodsName(item1.getGoodsName()); orderMealGood.setGoodsNum(item1.getGoodsNum()); orderMealGood.setGoodsPicture(item1.getGoodsPicture()); orderMealGood.setGoodsCount(item.getGoodsCount()); orderMealGood.setGoodsSalePrice(item1.getSalePrice()); orderMealGood.setCostPrice(item1.getCostPrice()); orderMealGood.setTypeId(item1.getTypeId()); orderMealGood.setGoodsId(item1.getId()); orderMealGood.setTypeName(list1.stream().filter(item2 -> item2.getId().equals(item1.getTypeId())).findFirst().get().getTypeName()); orderMealGoods.add(orderMealGood); }); }else { list2.stream().filter(item1 -> item1.getGoodsId().equals(item.getGoodsId())).findFirst().ifPresent(item1 -> { item1.setGoodsCount(item1.getGoodsCount()+item.getGoodsCount()); orderMealGoods.add(item1); }); } }); BigDecimal orderMoney = BigDecimal.ZERO; // 添加菜品 @@ -96,7 +106,7 @@ orderMealGood.setOrderId(dto.getId()); orderMoney = orderMoney.add(orderMealGood.getGoodsSalePrice().multiply(new BigDecimal(orderMealGood.getGoodsCount()))); } orderMealGoodsService.saveBatch(orderMealGoods); orderMealGoodsService.saveOrUpdateBatch(orderMealGoods); orderMeal.setOrderMoney(orderMoney); this.updateById(orderMeal); // 添加备注 @@ -221,7 +231,8 @@ List<TOrderMeal> list = this.list(Wrappers.lambdaQuery(TOrderMeal.class) .eq(TOrderMeal::getShopId, query.getShopId()) .ge(TOrderMeal::getMealTime, query.getStartTime()) .le(TOrderMeal::getMealTime, query.getEndTime())); .le(TOrderMeal::getMealTime, query.getEndTime()) .eq(TOrderMeal::getStatus,2)); List<Long> ids = list.stream().map(TOrderMeal::getId).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(ids)){ BigDecimal costTotal = orderMealGoodsService.costTotal(ids); @@ -298,7 +309,31 @@ @Override public List<OrderTrendsVO> orderingTrends(TDataStatisticsQuery query) { return this.baseMapper.orderingTrends(query); List<OrderTrendsVO> orderTrendsVOS = this.baseMapper.orderingTrends(query); LocalDate localDate = LocalDate.now(); for (int i = 0; i < 7; i++) { if(i == 0){ LocalDate finalLocalDate = localDate; OrderTrendsVO orderTrendsVO = orderTrendsVOS.stream().filter(e -> DateUtils.stringToLocalDate(e.getDayTime()).compareTo(finalLocalDate) == 0).findFirst().orElse(null); if(Objects.isNull(orderTrendsVO)){ orderTrendsVO = new OrderTrendsVO(); orderTrendsVO.setDayTime(DateUtils.localDateToString(localDate)); orderTrendsVO.setOrderCount(0); orderTrendsVOS.add(orderTrendsVO); } }else { localDate = localDate.minusDays(1); LocalDate finalLocalDate1 = localDate; OrderTrendsVO orderTrendsVO = orderTrendsVOS.stream().filter(e -> DateUtils.stringToLocalDate(e.getDayTime()).compareTo(finalLocalDate1) == 0).findFirst().orElse(null); if(Objects.isNull(orderTrendsVO)){ orderTrendsVO = new OrderTrendsVO(); orderTrendsVO.setDayTime(DateUtils.localDateToString(finalLocalDate1)); orderTrendsVO.setOrderCount(0); orderTrendsVOS.add(orderTrendsVO); } } } return orderTrendsVOS.stream().sorted(Comparator.comparing(OrderTrendsVO::getDayTime)).collect(Collectors.toList()); } @Override ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOrderSaleServiceImpl.java
@@ -6,16 +6,14 @@ import com.ruoyi.common.constant.OrderNumConstants; import com.ruoyi.common.utils.CodeGenerateUtils; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.*; import com.ruoyi.system.dto.CheckoutDTO; import com.ruoyi.system.dto.TOrderSaleDTO; import com.ruoyi.system.mapper.TOrderSaleGoodsMapper; import com.ruoyi.system.mapper.TOrderSaleMapper; import com.ruoyi.system.query.*; import com.ruoyi.system.service.TGoodsService; import com.ruoyi.system.service.TGoodsTypeService; import com.ruoyi.system.service.TOrderSaleGoodsService; import com.ruoyi.system.service.TOrderSaleService; import com.ruoyi.system.service.*; import com.ruoyi.system.vo.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -44,32 +42,43 @@ @Autowired private TOrderSaleGoodsService orderSaleGoodsService; @Autowired private TOrderStockGoodsService orderStockGoodsService; @Autowired private TOrderSaleGoodsMapper orderSaleGoodsMapper; @Autowired private TGoodsTypeService goodsTypeService; @Autowired private TGoodsService goodsService; @Override public void add(TOrderSaleDTO dto) { // 查询菜品分类 List<TGoodsType> list1 = goodsTypeService.list(); // List<TGoodsType> list1 = goodsTypeService.list(); // 销售单号 dto.setOrderNum(OrderNumConstants.SALE + CodeGenerateUtils.generateVolumeSn()); List<TOrderSaleGoods> orderSaleGoods = dto.getOrderSaleGoods(); BigDecimal sum = orderSaleGoods.stream().map(TOrderSaleGoods::getGoodsSalePrice).reduce(BigDecimal::add).get(); BigDecimal sum = BigDecimal.ZERO; for (TOrderSaleGoods orderSaleGood : orderSaleGoods) { sum = sum.add(orderSaleGood.getThisSalePrice().multiply(new BigDecimal(orderSaleGood.getGoodsCount()))); } dto.setOrderMoney(sum); this.save(dto); // 查询进货数据 List<TOrderStockGoods> orderStockGoodsList = orderStockGoodsService.getListByTimeAndShopId(DateUtils.localDateToString(dto.getOrderTime()), dto.getShopId()); // 添加商品 orderSaleGoods.forEach(orderSaleGoods1 -> { orderSaleGoods1.setOrderId(dto.getId()); orderSaleGoods1.setId(null); TOrderStockGoods orderStockGoods = orderStockGoodsList.stream().filter(m -> m.getGoodsNum().equals(orderSaleGoods1.getGoodsNum())).findFirst().orElse(null); if(Objects.nonNull(orderStockGoods)){ orderSaleGoods1.setGoodsCostPrice(orderStockGoods.getThisCostPrice()); }else { orderSaleGoods1.setGoodsCostPrice(BigDecimal.ZERO); } }); orderSaleGoodsService.saveBatch(orderSaleGoods); } @Override public PageInfo<TOrderSaleVO> pageList(TOrderSaleQuery query) { if(Objects.nonNull(query.getStartTime()) && Objects.nonNull(query.getEndTime())){ if(Objects.isNull(query.getStartTime()) && Objects.isNull(query.getEndTime())){ if(Objects.nonNull(query.getTimeType())){ LocalDateTime startTime = null; LocalDateTime endTime = null; @@ -109,10 +118,13 @@ List<TOrderSaleGoods> collect = list1.stream().filter(m -> m.getOrderId().equals(e.getId())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(collect)){ BigDecimal goodsAmount = BigDecimal.ZERO; Integer count = 0; for (TOrderSaleGoods tOrderSaleGoods : collect) { goodsAmount = goodsAmount.add(tOrderSaleGoods.getThisSalePrice().multiply(new BigDecimal(tOrderSaleGoods.getGoodsCount()))); count = count+tOrderSaleGoods.getGoodsCount(); } e.setGoodsAmount(goodsAmount); e.setGoodsCount(count); e.setOrderSaleGoods(collect); } }); @@ -122,8 +134,12 @@ } @Override public AmountSumVO amountSum(TOrderMealQuery query) { return this.baseMapper.amountSum(query); public AmountSumVO amountSum(TOrderSaleQuery query) { AmountSumVO amountSumVO = this.baseMapper.amountSum(query); if(amountSumVO.getObligation().compareTo(BigDecimal.ZERO) < 0){ amountSumVO.setObligation(BigDecimal.ZERO); } return amountSumVO; } @Override @@ -133,7 +149,10 @@ .add(salesVolumeVO.getMoneyPay()).add(salesVolumeVO.getAliPay())); // 查询成本 List<TOrderSale> list = this.list(Wrappers.lambdaQuery(TOrderSale.class) .eq(TOrderSale::getShopId, query.getShopId())); .eq(TOrderSale::getShopId, query.getShopId()) .ge(TOrderSale::getOrderTime, query.getStartTime()) .le(TOrderSale::getOrderTime, query.getEndTime()) .eq(TOrderSale::getStatus,2)); List<Long> ids = list.stream().map(TOrderSale::getId).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(ids)){ BigDecimal costTotal = orderSaleGoodsService.costTotal(ids); @@ -160,33 +179,35 @@ @Override public List<TOrderSaleVO> exportOrderSale(TOrderMealQuery query) { if(Objects.nonNull(query.getTimeType())){ LocalDateTime startTime = null; LocalDateTime endTime = null; switch (query.getTimeType()){ case 1: // 今日 startTime = DateUtils.getDayStart(LocalDateTime.now()); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.nonNull(query.getTimeType())){ LocalDateTime startTime = null; LocalDateTime endTime = null; switch (query.getTimeType()){ case 1: // 今日 startTime = DateUtils.getDayStart(LocalDateTime.now()); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } List<TOrderSaleVO> list = this.baseMapper.exportOrderSale(query); List<Long> ids = list.stream().map(TOrderSaleVO::getId).collect(Collectors.toList()); @@ -207,7 +228,7 @@ @Override public Map<String, Double> getDataGeneratorSaleDetail(TDataGeneratorSaleQuery query) { if(Objects.nonNull(query.getStartTime()) && Objects.nonNull(query.getEndTime())){ if(Objects.isNull(query.getStartTime()) && Objects.isNull(query.getEndTime())){ if(Objects.nonNull(query.getTimeType())){ LocalDateTime startTime = null; LocalDateTime endTime = null; @@ -326,4 +347,26 @@ } return list; } @Override public ProfitDetailsVO profitDetails(ProfitDetailsQuery query) { ProfitDetailsVO profitDetailsVO = new ProfitDetailsVO(); // 查询商品盈利明细 PageInfo<GoodsProfitVO> pageInfo = new PageInfo<>(query.getPageNum(),query.getPageSize()); List<GoodsProfitVO> list = this.baseMapper.profitDetails(query,pageInfo); pageInfo.setRecords(list); profitDetailsVO.setGoodsProfitVOS(pageInfo); // 统计商品金额 Map<String,Double> map = this.baseMapper.profitDetailsStatistics(query); profitDetailsVO.setTotalProfits(new BigDecimal(map.get("totalProfits").toString())); profitDetailsVO.setTotalCosts(new BigDecimal(map.get("totalCosts").toString())); profitDetailsVO.setTotalSales(new BigDecimal(map.get("totalSales").toString())); return profitDetailsVO; } @Override public List<GoodsProfitVO> profitDetailsExport(ProfitDetailsQuery query) { return this.baseMapper.profitDetailsExport(query); } } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOrderStockGoodsServiceImpl.java
@@ -1,12 +1,14 @@ package com.ruoyi.system.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.system.domain.TOrderSaleGoods; import com.ruoyi.system.domain.TOrderStockGoods; import com.ruoyi.system.mapper.TOrderStockGoodsMapper; import com.ruoyi.system.query.TDataGeneratorStockQuery; import com.ruoyi.system.service.TOrderStockGoodsService; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; /** @@ -20,4 +22,8 @@ @Service public class TOrderStockGoodsServiceImpl extends ServiceImpl<TOrderStockGoodsMapper, TOrderStockGoods> implements TOrderStockGoodsService { @Override public List<TOrderStockGoods> getListByTimeAndShopId(String orderTime, Long shopId) { return this.baseMapper.getListByTimeAndShopId(orderTime,shopId); } } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOrderStockServiceImpl.java
@@ -9,10 +9,7 @@ import com.ruoyi.system.domain.*; import com.ruoyi.system.dto.TOrderSaleDTO; import com.ruoyi.system.dto.TOrderStockDTO; import com.ruoyi.system.mapper.TDataGeneratorMapper; import com.ruoyi.system.mapper.TOrderSaleGoodsMapper; import com.ruoyi.system.mapper.TOrderSaleMapper; import com.ruoyi.system.mapper.TOrderStockMapper; import com.ruoyi.system.mapper.*; import com.ruoyi.system.query.TDataGeneratorQuery; import com.ruoyi.system.query.TDataGeneratorStockQuery; import com.ruoyi.system.query.TOrderStockQuery; @@ -50,6 +47,8 @@ private TStockDataSetService stockDataSetService; @Autowired private TDataGeneratorMapper dataGeneratorMapper; @Autowired private TGoodsService goodsService; @Override public void add(TOrderStockDTO dto) { // 进货单号 @@ -61,11 +60,22 @@ dto.setIsCover(0); } this.save(dto); // 添加商品 List<TGoods> goods = goodsService.list(Wrappers.lambdaQuery(TGoods.class)); List<TGoods> goodsUpdateList = new ArrayList<>(); // 添加商品 orderStockGoods.forEach(orderSaleGoods1 -> { orderSaleGoods1.setId(null); orderSaleGoods1.setOrderId(dto.getId()); for (TGoods good : goods) { if(good.getGoodsNum().equals(orderSaleGoods1.getGoodsNum())){ good.setInventory(orderSaleGoods1.getStockCount()+good.getInventory()); goodsUpdateList.add(good); }else { break; } } }); goodsService.updateBatchById(goodsUpdateList); tOrderStockGoodsService.saveBatch(orderStockGoods); } @@ -88,7 +98,7 @@ @Override public PageInfo<TOrderStockVO> pageList(TOrderStockQuery query) { if(Objects.nonNull(query.getStartTime()) && Objects.nonNull(query.getEndTime())){ if(Objects.isNull(query.getStartTime()) && Objects.isNull(query.getEndTime())){ // 判断时间 if(Objects.nonNull(query.getTimeType())){ LocalDateTime startTime = null; @@ -130,8 +140,13 @@ List<TOrderStockGoods> collect = orderStockGoods.stream().filter(orderSaleGoods -> orderSaleGoods.getOrderId().equals(orderStockVO.getId())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(collect)){ orderStockVO.setOrderStockGoods(collect); orderStockVO.setOrderStockCount(collect.size()); orderStockVO.setTotalPrice(collect.stream().map(TOrderStockGoods::getCostPrice).reduce(BigDecimal::add).get()); int sum = collect.stream().mapToInt(TOrderStockGoods::getStockCount).sum(); orderStockVO.setOrderStockCount(sum); BigDecimal money = BigDecimal.ZERO; for (TOrderStockGoods tOrderStockGoods : collect) { money = money.add(tOrderStockGoods.getThisCostPrice().multiply(new BigDecimal(tOrderStockGoods.getStockCount()))); } orderStockVO.setTotalPrice(money); } }); } ruoyi-system/src/main/java/com/ruoyi/system/vo/RoleInfoVO.java
@@ -10,6 +10,7 @@ private Long roleId; private String roleName; private String remark; @ApiModelProperty("菜单id") private List<Long> menus; ruoyi-system/src/main/java/com/ruoyi/system/vo/TOrderSaleVO.java
@@ -15,6 +15,8 @@ @ApiModelProperty(value = "货品总价") private BigDecimal goodsAmount; @ApiModelProperty(value = "货品数量") private Integer goodsCount; @ApiModelProperty(value = "菜品集合") private List<TOrderSaleGoods> orderSaleGoods; ruoyi-system/src/main/resources/mapper/system/TOrderMealGoodsMapper.xml
@@ -44,6 +44,7 @@ </foreach> </if> AND tom.isCover = 1 AND tom.status = 2 </where> GROUP BY tomg.typeName </select> ruoyi-system/src/main/resources/mapper/system/TOrderMealMapper.xml
@@ -108,6 +108,7 @@ </if> AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND isCover = 1 AND status = 2 </where> </select> <select id="exportOrderMeal" resultType="com.ruoyi.system.vo.TOrderMealVO"> @@ -153,6 +154,7 @@ </if> AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND isCover = 1 AND status = 2 </where> </select> <select id="personnelStatistics" resultType="com.ruoyi.system.vo.PersonnelStatisticsVO"> @@ -169,6 +171,7 @@ </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 AND tom.status = 2 </where> </select> <select id="pageListGenerator" resultType="com.ruoyi.system.vo.TOrderMealVO"> @@ -190,7 +193,7 @@ </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} </where> ORDER BY tom.createTime DESC ORDER BY tom.mealTime DESC </select> <select id="getDataGeneratorMealDetail" resultType="java.util.Map"> SELECT @@ -280,7 +283,7 @@ LEFT JOIN t_order_meal tom ON tom.id = tomg.orderId <where> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (tom.createTime BETWEEN #{query.startTime} AND #{query.endTime}) AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> <if test="query.goodsName != null and query.goodsName != ''"> AND tomg.goodsName like concat('%', #{query.goodsName}, '%') @@ -293,6 +296,7 @@ </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 AND tom.status = 2 </where> GROUP BY tomg.goodsName </select> @@ -326,6 +330,7 @@ </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 AND tom.status = 2 </where> GROUP BY tomg.goodsName) a </select> @@ -341,7 +346,7 @@ LEFT JOIN t_order_meal tom ON tom.id = tomg.orderId <where> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (tom.createTime BETWEEN #{query.startTime} AND #{query.endTime}) AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> <if test="query.goodsName != null and query.goodsName != ''"> AND tomg.goodsName like concat('%', #{query.goodsName}, '%') @@ -353,6 +358,8 @@ AND tom.shopId = #{query.shopId} </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 AND tom.status = 2 </where> GROUP BY tomg.goodsName </select> ruoyi-system/src/main/resources/mapper/system/TOrderSaleGoodsMapper.xml
@@ -33,7 +33,7 @@ </where> </select> <select id="salesRanking" resultType="com.ruoyi.system.vo.SalesRankingVO"> SELECT tgt.typeName,SUM(tosg.goodsSalePrice*tosg.goodsCount) AS salesVolume SELECT tgt.typeName,SUM(tosg.thisSalePrice*tosg.goodsCount) AS salesVolume FROM t_order_sale_goods tosg LEFT JOIN t_order_sale tos on tosg.orderId=tos.id LEFT JOIN t_goods_type tgt ON tosg.typeId = tgt.id @@ -45,6 +45,7 @@ </foreach> </if> AND tos.isCover = 1 AND tos.status = 2 </where> GROUP BY tgt.typeName </select> ruoyi-system/src/main/resources/mapper/system/TOrderSaleMapper.xml
@@ -58,9 +58,9 @@ <select id="amountSum" resultType="com.ruoyi.system.vo.AmountSumVO"> select COUNT(id) AS orderCount, SUM(orderMoney) AS saleAmount, SUM(payMoney) AS payAmount, SUM(orderMoney - payMoney) AS obligation IFNULL(SUM(orderMoney),0) AS saleAmount, IFNULL(SUM(payMoney),0) AS payAmount, IFNULL(SUM(orderMoney - IFNULL(payMoney,0)),0) AS obligation from t_order_sale <where> <if test="query.orderNum != null and query.orderNum != ''"> @@ -99,10 +99,11 @@ </if> AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND isCover = 1 AND status = 2 </where> </select> <select id="exportOrderSale" resultType="com.ruoyi.system.vo.TOrderSaleVO"> select id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId select id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId,payType from t_order_sale <where> <if test="query.orderNum != null and query.orderNum != ''"> @@ -135,10 +136,11 @@ AND shopId = #{query.shopId} </if> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (createTime BETWEEN #{query.startTime} AND #{query.endTime}) AND (orderTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND isCover = 1 AND status = 2 </where> </select> <select id="getDataGeneratorSaleDetail" resultType="java.util.Map"> @@ -217,5 +219,96 @@ and tdg.orderType = 2 </where> </select> <select id="profitDetails" resultType="com.ruoyi.system.vo.GoodsProfitVO"> SELECT tomg.goodsName, (select typeName from t_goods_type where id = tomg.typeId) AS typeName, IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount, IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount, IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount, IFNULL(SUM(tomg.goodsCount *(tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount FROM t_order_sale_goods tomg LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId <where> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (tom.orderTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> <if test="query.goodsName != null and query.goodsName != ''"> AND tomg.goodsName like concat('%', #{query.goodsName}, '%') </if> <if test="query.typeId != null and query.typeId != ''"> AND tomg.typeId = #{query.typeId} </if> <if test="query.shopId != null"> AND tom.shopId = #{query.shopId} </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 AND tom.status = 2 </where> GROUP BY tomg.goodsName </select> <select id="profitDetailsStatistics" resultType="java.util.Map"> SELECT IFNULL(SUM(a.goodsSaleAmount),0) AS totalSales, IFNULL(SUM(a.goodsCostAmount),0) AS totalCosts, IFNULL(SUM(a.goodsProfitAmount),0) AS totalProfits FROM ( SELECT tomg.goodsName, IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount, IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount, IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount, IFNULL(SUM(tomg.goodsCount * (tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount FROM t_order_sale_goods tomg LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId <where> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (tom.orderTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> <if test="query.goodsName != null and query.goodsName != ''"> AND tomg.goodsName like concat('%', #{query.goodsName}, '%') </if> <if test="query.typeId != null and query.typeId != ''"> AND tomg.typeId = #{query.typeId} </if> <if test="query.shopId != null"> AND tom.shopId = #{query.shopId} </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 AND tom.status = 2 </where> GROUP BY tomg.goodsName) a </select> <select id="profitDetailsExport" resultType="com.ruoyi.system.vo.GoodsProfitVO"> SELECT tomg.goodsName, (select typeName from t_goods_type where id = tomg.typeId) AS typeName, IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount, IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount, IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount, IFNULL(SUM(tomg.goodsCount *(tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount FROM t_order_sale_goods tomg LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId <where> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (tom.orderTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> <if test="query.goodsName != null and query.goodsName != ''"> AND tomg.goodsName like concat('%', #{query.goodsName}, '%') </if> <if test="query.typeId != null and query.typeId != ''"> AND tomg.typeId = #{query.typeId} </if> <if test="query.shopId != null"> AND tom.shopId = #{query.shopId} </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 AND tom.status = 2 </where> GROUP BY tomg.goodsName </select> </mapper> ruoyi-system/src/main/resources/mapper/system/TOrderStockGoodsMapper.xml
@@ -20,5 +20,10 @@ <sql id="Base_Column_List"> id, orderId, goodsNum, goodsName, costPrice, salePrice, goodsPicture, stockCount,thisCostPrice,goodsId </sql> <select id="getListByTimeAndShopId" resultType="com.ruoyi.system.domain.TOrderStockGoods"> select t.id, t.orderId, t.goodsNum, t.goodsName, t.costPrice, t.salePrice, t.goodsPicture, t.stockCount,t.thisCostPrice,t.goodsId from t_order_stock_goods t where t.orderId in (select id from t_order_stock where DATE_FORMAT(orderTime, '%Y-%m-%d')) = #{orderTime} and shopId = #{shopId}) </select> </mapper>