|
|
@ -32,8 +32,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.yxt.supervise.portal.api.productinformation.ProductInformationVo; |
|
|
|
import com.yxt.supervise.portal.api.productnum.ProductNum; |
|
|
|
import com.yxt.supervise.portal.api.purchaserequisition.PurchaseRequisition; |
|
|
|
import com.yxt.supervise.portal.api.purchaserequisitionpro.PurchaseRequisitionPro; |
|
|
|
import com.yxt.supervise.portal.api.restrictedcategory.RestrictedCategory; |
|
|
|
import com.yxt.supervise.portal.api.storeinfo.StoreInfo; |
|
|
|
import com.yxt.supervise.portal.biz.inventoryinformation.InventoryInformationService; |
|
|
|
import com.yxt.supervise.portal.biz.productinformation.ProductInformationService; |
|
|
|
import com.yxt.supervise.portal.biz.restrictedcategory.RestrictedCategoryService; |
|
|
|
import com.yxt.supervise.portal.biz.storeinfo.StoreInfoService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
@ -48,20 +54,18 @@ import com.yxt.supervise.portal.api.salesdata.SalesDataDetailsVo; |
|
|
|
import com.yxt.supervise.portal.api.salesdata.SalesDataDto; |
|
|
|
import com.yxt.supervise.portal.api.salesdata.SalesDataFeign; |
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCell; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
import org.apache.poi.hssf.usermodel.*; |
|
|
|
import org.apache.poi.ss.usermodel.CellType; |
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment; |
|
|
|
import org.apache.poi.ss.util.CellRangeAddress; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* Project: yxt-supervise(宇信通监管) <br/> |
|
|
@ -81,6 +85,12 @@ import java.util.List; |
|
|
|
public class SalesDataService extends MybatisBaseService<SalesDataMapper, SalesData> { |
|
|
|
@Resource |
|
|
|
private InventoryInformationService inventoryInformationService; |
|
|
|
@Resource |
|
|
|
private RestrictedCategoryService restrictedCategoryService; |
|
|
|
@Resource |
|
|
|
private ProductInformationService productInformationService; |
|
|
|
@Resource |
|
|
|
private StoreInfoService storeInfoService; |
|
|
|
private QueryWrapper<SalesData> createQueryWrapper(SalesDataQuery query) { |
|
|
|
// todo: 这里根据具体业务调整查询条件
|
|
|
|
// 多字段Like示例:qw.and(wrapper -> wrapper.like("name", query.getName()).or().like("remark", query.getName()));
|
|
|
@ -256,4 +266,109 @@ public class SalesDataService extends MybatisBaseService<SalesDataMapper, SalesD |
|
|
|
System.out.println(x1); |
|
|
|
//return message;
|
|
|
|
} |
|
|
|
/** |
|
|
|
* |
|
|
|
* 分析销售数据 |
|
|
|
* @param pc |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public HSSFWorkbook analysisSalesData(String pc){ |
|
|
|
// 企业组织机构代码证 类型 销售订单号 商品编码 商品条码 商品名称 销售数量 销售渠道 销售价格 销售成本 利润 数据日期
|
|
|
|
|
|
|
|
String title = "销售数据"; |
|
|
|
String[] col1 = {"序号","销售订单号","类型","商品编码","商品条码","商品名称","销售数量","销售渠道","门店名称","销售价格","销售成本", |
|
|
|
"利润" ,"限定情况","数据日期","备注"}; |
|
|
|
//sheet名
|
|
|
|
String sheetName = pc+"销售数据"; |
|
|
|
List<SalesData> list=baseMapper.selectByDate(pc); |
|
|
|
//创建HSSFWorkbook
|
|
|
|
addProductNum(list); |
|
|
|
// 第一步,创建一个HSSFWorkbook,对应一个Excel文件
|
|
|
|
HSSFWorkbook wb = new HSSFWorkbook(); |
|
|
|
// 第二步,在workbook中添加一个sheet,对应Excel文件中的sheet
|
|
|
|
HSSFSheet sheet = wb.createSheet(sheetName); |
|
|
|
// 合并单元格:参数:起始行, 终止行, 起始列, 终止列
|
|
|
|
CellRangeAddress cra = new CellRangeAddress(0, 0, 0, 15); |
|
|
|
sheet.addMergedRegion(cra); |
|
|
|
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
|
|
|
|
|
|
|
|
HSSFRow row = sheet.createRow(0); |
|
|
|
// 第四步,创建单元格,并设置值表头 设置表头居中
|
|
|
|
HSSFCellStyle style = wb.createCellStyle(); |
|
|
|
style.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
|
|
|
|
HSSFCell titleRow = row.createCell(0); |
|
|
|
titleRow.setCellValue(title); |
|
|
|
titleRow.setCellStyle(style); |
|
|
|
//列头
|
|
|
|
createRow3(sheet, 1, col1, style); |
|
|
|
BigDecimal bigDecimal = new BigDecimal("0"); |
|
|
|
//创建内容
|
|
|
|
for(int i=0;i<list.size();i++){ |
|
|
|
SalesData salesData = list.get(i); |
|
|
|
row = sheet.createRow(i + 2); |
|
|
|
//将内容按顺序赋给对应的列对象
|
|
|
|
//"序号","销售订单号","类型","商品编码","商品条码","商品名称","销售数量","销售渠道","门店名称","销售价格","销售成本","利润" ,"限定情况","数据日期","备注"
|
|
|
|
row.createCell(0).setCellValue(i+1); |
|
|
|
row.createCell(1).setCellValue(salesData.getCode()); |
|
|
|
row.createCell(2).setCellValue(salesData.getType()); |
|
|
|
row.createCell(3).setCellValue(salesData.getProCode()); |
|
|
|
row.createCell(4).setCellValue(salesData.getProBarCode()); |
|
|
|
row.createCell(5).setCellValue(salesData.getProName()); |
|
|
|
row.createCell(6).setCellValue(salesData.getSaleNum()); |
|
|
|
row.createCell(7).setCellValue(salesData.getStoreCode()); |
|
|
|
StoreInfo storeInfo=storeInfoService.selectByCode(salesData.getStoreCode()); |
|
|
|
if(storeInfo!=null){ |
|
|
|
row.createCell(8).setCellValue(storeInfo.getName()); |
|
|
|
}else{ |
|
|
|
row.createCell(8).setCellValue(""); |
|
|
|
} |
|
|
|
row.createCell(9).setCellValue(salesData.getSalePrice());//"销售价格"
|
|
|
|
BigDecimal bigDecimal1 = new BigDecimal(salesData.getSalePrice()); |
|
|
|
bigDecimal.add(bigDecimal1); |
|
|
|
row.createCell(10).setCellValue(salesData.getSaleCost());//"销售成本"
|
|
|
|
row.createCell(11).setCellValue(salesData.getProfit()); |
|
|
|
row.createCell(12).setCellValue(salesData.getState()==1?"符合":"不符合"); |
|
|
|
row.createCell(13).setCellValue(salesData.getDataDate()); |
|
|
|
row.createCell(14).setCellValue(salesData.getRemarks()); |
|
|
|
} |
|
|
|
row = sheet.createRow(list.size() + 2+1); |
|
|
|
row.createCell(0).setCellValue("合计"); |
|
|
|
row.createCell(9).setCellValue(bigDecimal.toString()); |
|
|
|
return wb; |
|
|
|
} |
|
|
|
|
|
|
|
private List<SalesData> addProductNum( List<SalesData> list) { |
|
|
|
for(int i = 0; i < list.size(); i++){ |
|
|
|
SalesData pr=list.get(i); |
|
|
|
ProductInformationVo productInformation=productInformationService.selectByCode(pr.getProCode()); |
|
|
|
log.info("pr:{}",JSONObject.toJSONString(pr)); |
|
|
|
ProductInformationVo b=productInformationService.selectByCode(pr.getProCode()); |
|
|
|
log.info("b:{}",JSONObject.toJSONString(b)); |
|
|
|
String brandSid = b.getBrandSid(); |
|
|
|
String categoryKey = b.getCategoryKey(); |
|
|
|
List<RestrictedCategory> restrictedCategorys=restrictedCategoryService.limitJudgement(categoryKey,brandSid); |
|
|
|
if("081101,081102,081103".indexOf(categoryKey)>=0||(restrictedCategorys!=null&&restrictedCategorys.size()>0)){ |
|
|
|
pr.setState(1); |
|
|
|
}else{ |
|
|
|
pr.setState(0); |
|
|
|
String remarks=""; |
|
|
|
remarks=remarks+productInformation.getCategory()+"["+productInformation.getCategoryKey()+"]品类,"; |
|
|
|
remarks=remarks+productInformation.getBrand()+"["+productInformation.getBrandSid()+"]品牌不符合;"; |
|
|
|
pr.setRemarks(remarks); |
|
|
|
} |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
private void createRow3(HSSFSheet sheet, int rownum, String[] col1, HSSFCellStyle style) { |
|
|
|
//声明列对象
|
|
|
|
HSSFCell cell = null; |
|
|
|
//创建标题
|
|
|
|
HSSFRow row2 = sheet.createRow(rownum); |
|
|
|
for(int i = 0; i< col1.length; i++){ |
|
|
|
cell = row2.createCell(i); |
|
|
|
cell.setCellValue(col1[i]); |
|
|
|
cell.setCellStyle(style); |
|
|
|
} |
|
|
|
} |
|
|
|
} |