From 2fcd97552d16718cc7997629fd637a73a5a4483f Mon Sep 17 00:00:00 2001 From: 郑永安 <zyazyz250@sina.com> Date: 星期一, 19 六月 2023 14:44:19 +0800 Subject: [PATCH] 删除 --- src/main/java/com/gk/firework/Service/ServiceImpl/SaleOrderDetailServiceImpl.java | 615 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 615 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/gk/firework/Service/ServiceImpl/SaleOrderDetailServiceImpl.java b/src/main/java/com/gk/firework/Service/ServiceImpl/SaleOrderDetailServiceImpl.java new file mode 100644 index 0000000..a3c9b18 --- /dev/null +++ b/src/main/java/com/gk/firework/Service/ServiceImpl/SaleOrderDetailServiceImpl.java @@ -0,0 +1,615 @@ +package com.gk.firework.Service.ServiceImpl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gk.firework.Domain.*; +import com.gk.firework.Domain.Exception.BusinessException; +import com.gk.firework.Domain.Utils.PageInfo; +import com.gk.firework.Domain.Utils.StringUtils; +import com.gk.firework.Domain.Vo.*; +import com.gk.firework.Mapper.SaleOrderDetailInfoMapper; +import com.gk.firework.Service.*; +import com.spire.doc.interfaces.IField; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.util.*; + + +/** + * @author : jingjy + * @date : 2021/3/30 17:34 + */ +@Service("SaleOrderDetailService") +public class SaleOrderDetailServiceImpl extends ServiceImpl<SaleOrderDetailInfoMapper, SaleOrderDetailInfo> implements SaleOrderDetailService { + @Autowired + SaleOrderDetailInfoMapper saleOrderDetailInfoMapper; + @Autowired + SaleOrderService saleOrderService; + @Autowired + EnterpriseService enterpriseService; + @Autowired + ProductService productService; + @Autowired + private EntryDetailService entryDetailService; + @Autowired + private EntryService entryService; + @Autowired + private StockService stockService; + @Autowired + UserService userService; + @Autowired + DistrictService districtService; + + @Override + public void selectByCustomId(PageInfo pageInfo) { + Page<SaleDetailVo> page = new Page<>(pageInfo.getPageIndex(), pageInfo.getPageSize()); + List<OrderItem> orderItems = new ArrayList<>(); + OrderItem orderItem = new OrderItem(); + if (StringUtils.isNotBlank(pageInfo.getSort()) && StringUtils.isNotBlank(pageInfo.getOrder())) { + orderItem.setAsc(pageInfo.getOrder().equalsIgnoreCase("ascending")); + orderItem.setColumn(pageInfo.getSort()); + }else { + orderItem.setAsc(false); + orderItem.setColumn("createdat"); + } + orderItems.add(orderItem); + page.setOrders(orderItems); + List<SaleDetailVo> list = saleOrderDetailInfoMapper.selectByCustomId(page,pageInfo.getCondition()); + pageInfo.setResult(list); + pageInfo.setTotalCount(page.getTotal()); + } + + + /** + * @Description: 近n天销售数据统计 + * @date 2021/4/16 16:21 + */ + @Override + public List<Map> getSaleDataInDays(Integer days) { + Date startTime = moveForwardDays(days); + int[] index = new int[days]; + for (int i = 0; i < days; i++) { + index[i] = i + 1; + } + return saleOrderDetailInfoMapper.getSaleDataInDays(startTime,null,index); + } + + + /** + * @Description: 销售数量按地区统计 n天 默认90 + * @date 2021/4/16 16:21 + */ + @Override + public List<Map> getSaleDataAreaInDays(Integer days) { + Date startTime = moveForwardDays(days); + Map<String, Object> params = new HashMap<>(); + params.put("province", "新疆维吾尔自治区"); + return saleOrderDetailInfoMapper.getSaleDataAreaInDays(startTime,null,params); + } + + + /** + * @Description: 销售数量按品种统计 n天 默认90 + * @date 2021/4/16 17:03 + */ + @Override + public List<Map> getSaleDataProductTypeInDays(Integer days) { + Date startTime = moveForwardDays(days); + return saleOrderDetailInfoMapper.getSaleDataProductTypeInDays(startTime,null); + } + + /** + * @Description: 销售量同年对比 + * @date 2021/4/22 15:13 + */ + @Override + public Map getSaleDataCompareInYear(String province, String city) { + //今年数据 + Calendar cal = Calendar.getInstance(); + int thisYear = cal.get(Calendar.YEAR); + List<Map> thisYearData = this.getSaleDataInYear(province, city, thisYear); + //去年数据 + cal.add(Calendar.YEAR, -1); + int lastYear = cal.get(Calendar.YEAR); + List<Map> lastYearData = this.getSaleDataInYear(province, city, lastYear); + //生成结果 + Map<Object, Object> result = new HashMap<>(); + result.put(thisYear, thisYearData); + result.put(lastYear, lastYearData); + return result; + } + + /** + * @Description: 获取{xxxx}年的销售数据 + * @date 2021/4/22 15:50 + */ + @Override + public List<Map> getSaleDataInYear(String province, String city, Integer year) { + Map<String, Object> params = new HashMap<>(); + params.put("province", province); + params.put("city", city); + params.put("year", year); + return saleOrderDetailInfoMapper.getSaleDataInYear(params); + } + + /** + * @Description: 进货量同年对比 + * @date 2021/4/23 9:28 + */ + @Override + public Map getInboundCompareInYear(String province, String city) { + //今年数据 + Calendar cal = Calendar.getInstance(); + int thisYear = cal.get(Calendar.YEAR); + List<Map> thisYearData = this.getInboundInYear(province, city, thisYear); + //去年数据 + cal.add(Calendar.YEAR, -1); + int lastYear = cal.get(Calendar.YEAR); + List<Map> lastYearData = this.getInboundInYear(province, city, lastYear); + //生成结果 + Map<Object, Object> result = new HashMap<>(); + result.put(thisYear, thisYearData); + result.put(lastYear, lastYearData); + return result; + } + + /** + * @Description: 获取{xxxx}年的进货量 + * @date 2021/4/23 9:31 + */ + @Override + public List<Map> getInboundInYear(String province, String city, Integer year) { + Map<String, Object> params = new HashMap<>(); + params.put("province", province); + params.put("city", city); + params.put("year", year); + return saleOrderDetailInfoMapper.getInboundInYear(params); + } + @Override + public List<SaleOrderDetailInfo> selectByOrderCode(String code) { + LambdaQueryWrapper<SaleOrderDetailInfo>wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SaleOrderDetailInfo::getOrdercode,code); + return saleOrderDetailInfoMapper.selectList(wrapper); + } + + /** + * @Description: 标题数据 (零售店数量 今日销售数量 今年销售总量 今年购买人次) + * @date 2021/4/25 9:44 + */ + @Override + public Map getTitleData() { + //1.零售店数量 + int saleShopNum = enterpriseService.getSaleNum(); + //2.今日销售数量 + int thisDaySaleNum = saleOrderDetailInfoMapper.getSaleNumThisDay(); + //3.今年销售数量 + int thisYearSaleNum = saleOrderDetailInfoMapper.getSaleNumThisYear(); + //今年购买人数 + int thisYearPurchasersNum = saleOrderDetailInfoMapper.getPurchasersNum(); + Map<String, Integer> result = new HashMap<>(); + result.put("saleShopNum", saleShopNum); + result.put("thisDaySaleNum", thisDaySaleNum); + result.put("thisYearSaleNum", thisYearSaleNum); + result.put("thisYearPurchasersNum", thisYearPurchasersNum); + return result; + } + + @Override + public IPage getCityInAndOut(Page<Map> page, Map filter) { + + Map<String, Object> params = new HashMap<>(); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("province", "新疆维吾尔自治区"); + params.put("safetysupervision", filter.get("safetysupervision")); + List<Map> list = saleOrderDetailInfoMapper.selectCityInAndOut(page, params); + page.setRecords(list); + return page; + } + + @Override + public IPage getGenderSale(Page<Map> page, Map filter, UserInfo userInfo) { + + Map<String, Object> params = new HashMap<>(); + //可视权限 + UserInfo user = userService.getById(userInfo.getId()); + if (user.getCompanynumber() != null) { + params.put("enterprisenumber", user.getCompanynumber()); + }else { + if (StringUtils.isNotBlank(user.getProvince())) { + params.put("province", user.getProvince()); + } + if (StringUtils.isNotBlank(user.getCity())) { + params.put("city", user.getCity()); + } + if (StringUtils.isNotBlank(user.getArea())) { + params.put("district", user.getArea()); + } + if (StringUtils.isNotBlank(user.getTown())) { + params.put("street", user.getTown()); + } + + if (StringUtils.isNotBlank(user.getCommunity())) { + params.put("committee", user.getCommunity()); + } + } + + params.put("enterprisename", filter.get("enterprisename")); + params.put("producttype", filter.get("producttype")); + params.put("secondarytype", filter.get("secondarytype")); + params.put("productname", filter.get("productname")); + params.put("provinceFilter", filter.get("province")); + params.put("cityFilter", filter.get("city")); + params.put("districtFilter", filter.get("district")); + params.put("streetFilter", filter.get("street")); + params.put("committeeFilter", filter.get("committee")); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + List<Map> records = saleOrderDetailInfoMapper.getGenderSale(page,params); + return page.setRecords(records); + } + + @Override + public IPage getRaceSale(Page<Map> page, Map filter, UserInfo userInfo) { + + + Map<String, Object> params = new HashMap<>(); + + UserInfo user = userService.getById(userInfo.getId()); + { + params.put("enterprisenumber", user.getCompanynumber()); + params.put("province", user.getProvince()); + params.put("city", user.getCity()); + params.put("district", user.getArea()); + params.put("street", user.getTown()); + params.put("committee", user.getCommunity()); + } + + params.put("enterprisename", filter.get("enterprisename")); + params.put("producttype", filter.get("producttype")); + params.put("secondarytype", filter.get("secondarytype")); + params.put("productname", filter.get("productname")); + params.put("provinceFilter", filter.get("province")); + params.put("cityFilter", filter.get("city")); + params.put("districtFilter", filter.get("city")); + params.put("streetFilter", filter.get("street")); + params.put("committeeFilter", filter.get("committee")); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + List<Map> records = saleOrderDetailInfoMapper.getRaceSale(page,params); + return page.setRecords(records); + } + + @Override + public List<Map> getGenerationSale(Map filter, UserInfo userInfo) { + UserInfo user = userService.getById(userInfo.getId()); + String[] generations = {"0-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70"}; + List<Map> table = new ArrayList<>(); + Map<String, Object> row = null; + for (String generation : generations) { + Integer head = null; + Integer tail = null; + String[] split = generation.split("-"); + head = Integer.valueOf(split[0]); + if (split.length > 1) { + tail = Integer.valueOf(split[1]); + } + int num = this.getSaleInfoByGeneration(head,tail,filter,user); + row = new HashMap<>(); + row.put("generation", generation); + row.put("num", num); + table.add(row); + } + return table; + } + + + /** + * @Description: 年龄段购买数量 + * @date 2021/5/15 17:05 + */ + @Override + public int getSaleInfoByGeneration(Integer head, Integer tail, Map filter,UserInfo user) { + + Map<String, Object> params = new HashMap<>(); + { + params.put("enterprisenumber", user.getCompanynumber()); + params.put("province", user.getProvince()); + params.put("city", user.getCity()); + params.put("district", user.getArea()); + params.put("street", user.getTown()); + params.put("committee", user.getCommunity()); + } + params.put("enterprisename", filter.get("enterprisename")); + params.put("producttype", filter.get("producttype")); + params.put("secondarytype", filter.get("secondarytype")); + params.put("productname", filter.get("productname")); + params.put("provinceFilter", filter.get("province")); + params.put("cityFilter", filter.get("city")); + params.put("districtFilter", filter.get("city")); + params.put("streetFilter", filter.get("street")); + params.put("committeeFilter", filter.get("committee")); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + //年龄段头尾 + params.put("head", head); + params.put("tail", tail); + return saleOrderDetailInfoMapper.getSaleInfoByGeneration(params); + } + + @Override + public List<SaleDetailVo> getDetailList(String directionCode) { + if (StringUtils.isBlank(directionCode)|| FireworkDeal.isNotDirectionCode(directionCode)) { + throw new BusinessException("流向码不符合规则"); + } + List<String> codes= new ArrayList<>(); + //22位 + if (FireworkDeal.is22Characters(directionCode)){ + DirectionDetail directionDetail = FireworkDeal.dealDirectionCode(directionCode); + List<ProductVo> productVos = new ArrayList<>(); + ProductVo productVo = productService.selectVoByDirection(directionCode); + FireworkDeal.getProductVos(directionCode,directionDetail,directionDetail,productVos,productVo); + if (productVos.size() > 0) { + for (ProductVo product : productVos) { + codes.add(product.getDirectionCode()); + } + } + }else{ + //19位 + codes.add(directionCode); + } + + + if (codes.size() < 1) { + throw new BusinessException("流向码有误"); + } + + //循环查询 + List<SaleDetailVo> details = new ArrayList<>(); + for (String code : codes) { + SaleDetailVo saleDetailVo = saleOrderDetailInfoMapper.selectOneByDirectionCode(code); + if (saleDetailVo != null) { + details.add(saleDetailVo); + } + } + return details; + } + + @Override + @Transactional + public void returnAndStorage(String directionCodes, String userId, String auth) { + + + if (StringUtils.isBlank(userId)) { + throw new BusinessException("用户信息不能为空"); + } + UserInfo userInfo = userService.getById(userId); + if (userInfo == null) { + throw new BusinessException("用户不存在"); + } + + List<String> directionCodeList = new ArrayList<>(); + if (FireworkDeal.is22Characters(directionCodes)){ + DirectionDetail directionDetail = FireworkDeal.dealDirectionCode(directionCodes); + List<ProductVo> productVos = new ArrayList<>(); + ProductVo productVo = productService.selectVoByDirection(directionCodes); + FireworkDeal.getProductVos(directionCodes,directionDetail,directionDetail,productVos,productVo); + if (productVos.size() > 0) { + for (ProductVo product : productVos) { + directionCodeList.add(product.getDirectionCode()); + } + } + }else{ + //19位 + directionCodeList.add(directionCodes); + } + + + if (directionCodeList.size() < 1) { + throw new BusinessException("流向码有误"); + } + for (String directionCode : directionCodeList) { + + if (StringUtils.isBlank(directionCode) || FireworkDeal.isNotDirectionCode(directionCode)) { + throw new BusinessException("流向码不符合规则,退货失败!"); + } + StockInfo stockInfo = stockService.selectStockByDirection(directionCode); +// if (stockInfo == null || !stockInfo.getOwner().equals(customerInfo.getId().toString())) { +// msg.setCode(ErrorCode.ERROR_CODE); +// msg.setMessage("库存状态异常,退货失败!"); +// return msg; +// } + ProductInfo productInfo = productService.selectByDirection(directionCode.substring(0, 10)); + + // 创建入库单,type为2,创建入库明细,修改stock + EntryOrderInfo entryOrderInfo = entryService.generateEntryOrderInfo(EntryUtils.TH_ENTRY, userInfo, new Date(), "", auth); + EntryDetailInfo entryDetailInfo = new EntryDetailInfo(entryOrderInfo.getCode(), directionCode, productInfo.getDirectionCode(), + productInfo.getName(), productInfo.getManufacturer(), new Date(),userInfo.getCompanynumber()); + entryOrderInfo.setNum(1); + entryDetailInfo.setNum(1); + //查找未退货的商品记录 + SaleOrderDetailInfo detailInfo = saleOrderService.selectOrderByDirectionReturnflag(directionCode,(byte) 0, null); + if (detailInfo == null) { + throw new BusinessException("条码:" + directionCode + ",已退货入库或者记录不存在"); + } + Byte flag = 1; + detailInfo.setReturnflag(flag); + this.updateById(detailInfo); + + int i = stockService.doReturn(stockInfo,userInfo,null, new Date()); + if (i != 1){ + throw new BusinessException("更新失败"); + }else { + entryService.save(entryOrderInfo); + entryDetailService.save(entryDetailInfo); + } + } + + + } + + @Override + public IPage selectSaleNumInfo(Page<SaleNumVo> page, Map<String, Object> filter, UserInfo user) { + + List<SaleNumVo> records = saleOrderDetailInfoMapper.selectSaleNumInfo(page, filter); + page.setRecords(records); + return page; + } + + @Override + public IPage selectSaleNumInfoDetail(Page<SaleOrderDetailInfo> page, Map<String, Object> filter, UserInfo user) { + List<SaleOrderDetailInfo> records = saleOrderDetailInfoMapper.selectSaleNumInfoDetail(page, filter); + page.setRecords(records); + return page; + } + + @Override + public IPage getCityInAndOutDetail(Page<Map> page, Map<String, Object> filter) { + + Map<String, Object> params = new HashMap<>(); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("province", "新疆维吾尔自治区"); + params.put("city", filter.get("city")); + params.put("safetysupervision", filter.get("safetysupervision")); + List<Map> list = saleOrderDetailInfoMapper.selectCityInAndOutDetail(page, params); + return page.setRecords(list); + } + + @Override + public List<Map> getCityInAndOutExport(Map<String, Object> filter) { + Map<String, Object> params = new HashMap<>(); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("province", "新疆维吾尔自治区"); + params.put("safetysupervision", filter.get("safetysupervision")); + return saleOrderDetailInfoMapper.selectCityInAndOut(params); + } + + @Override + public IPage selectCityTypeSale(Page<Map> page, Map<String, Object> filter) { + Map<String, Object> params = new HashMap<>(); + params.put("province", "新疆维吾尔自治区"); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("enterprisename", filter.get("enterprisename")); + params.put("safetysupervision", filter.get("safetysupervision")); + List<String> list = productService.selectTypes(); + List<Map> res = saleOrderDetailInfoMapper.selectCityTypeSale(page,params,list); + Map totalRow = saleOrderDetailInfoMapper.selectAllType(list, params); + ArrayList<Map> result = new ArrayList<>(res); + result.add(totalRow); + return page.setRecords(result); + } + + @Override + public List<Map> selectCityTypeSaleExport(Map<String, Object> filter) { + Map<String, Object> params = new HashMap<>(); + params.put("province", "新疆维吾尔自治区"); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("enterprisename", filter.get("enterprisename")); + params.put("safetysupervision", filter.get("safetysupervision")); + List<String> list = productService.selectTypes(); + List<Map> res = saleOrderDetailInfoMapper.selectCityTypeSale(params, list); + Map totalRow = saleOrderDetailInfoMapper.selectAllType(list, params); + ArrayList<Map> result = new ArrayList<>(res); + result.add(totalRow); + return result; + } + + @Override + public IPage selectEnterpriseTypeSale(Page<Map> page, Map<String, Object> filter, UserInfo user) { + Map<String, Object> params = new HashMap<>(); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("enterprisename", filter.get("enterprisename")); + params.put("safetysupervision", filter.get("safetysupervision")); + params.put("province", filter.get("province")); + params.put("city", filter.get("city")); + params.put("district", filter.get("district")); + List<String> list = productService.selectTypes(); + List<Map> res = saleOrderDetailInfoMapper.selectEnterpriseTypeSale(page,params,list); + //合计行 + Map totalRow = saleOrderDetailInfoMapper.selectAllType(list, params); + ArrayList<Map> result = new ArrayList<>(res); + result.add(totalRow); + return page.setRecords(result); + } + + @Override + public List<Map> selectExportEnterpriseTypeSale(Map<String, Object> filter, UserInfo user) { + Map<String, Object> params = new HashMap<>(); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("enterprisename", filter.get("enterprisename")); + params.put("safetysupervision", filter.get("safetysupervision")); + params.put("province", filter.get("province")); + params.put("city", filter.get("city")); + params.put("district", filter.get("district")); + List<String> list = productService.selectTypes(); + List<Map> res = saleOrderDetailInfoMapper.selectEnterpriseTypeSale(params,list); + //合计行 + Map totalRow = saleOrderDetailInfoMapper.selectAllType(list, params); + ArrayList<Map> result = new ArrayList<>(res); + result.add(totalRow); + return result; + } + + + private Date moveForwardDays(Integer days) { + Calendar calendar = new GregorianCalendar(); + calendar.setTime(new Date()); + //当前日期往前推days天 + calendar.add(Calendar.DATE, -days); + return calendar.getTime(); + } + + @Override + public IPage selectDistrictTypeSale(Page<Map> page, Map<String, Object> filter) { + Map<String, Object> params = new HashMap<>(); + params.put("province", "新疆维吾尔自治区"); + params.put("city", filter.get("city")); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("enterprisename", filter.get("enterprisename")); + params.put("safetysupervision", filter.get("safetysupervision")); + List<String> list = productService.selectTypes(); + List<Map> res = saleOrderDetailInfoMapper.selectDistrictTypeSale(page,params,list); + Map totalRow = saleOrderDetailInfoMapper.selectAllDistrictType(list, params); + ArrayList<Map> result = new ArrayList<>(res); + result.add(totalRow); + return page.setRecords(result); + } + + @Override + public List<Map> selectDistrictTypeSaleExport(Map<String, Object> filter) { + Map<String, Object> params = new HashMap<>(); + params.put("province", "新疆维吾尔自治区"); + params.put("city", filter.get("city")); + params.put("starttime", filter.get("starttime")); + params.put("endtime", filter.get("endtime")); + params.put("enterprisename", filter.get("enterprisename")); + params.put("safetysupervision", filter.get("safetysupervision")); + List<String> list = productService.selectTypes(); + List<Map> res = saleOrderDetailInfoMapper.selectDistrictTypeSale(params, list); + Map totalRow = saleOrderDetailInfoMapper.selectAllDistrictType(list, params); + ArrayList<Map> result = new ArrayList<>(res); + result.add(totalRow); + return result; + } + + @Override + public void saveBatchOrderDetailInfo(List<SaleOrderDetailInfo> detailInfoList) { + if (detailInfoList == null || detailInfoList.size() == 0) { + throw new BusinessException("系统参数为空"); + } + int i = saleOrderDetailInfoMapper.saveBatchOrderDetailInfo(detailInfoList); + } +} -- Gitblit v1.9.2