|
@@ -24,6 +24,7 @@ import org.apache.poi.ss.usermodel.CellType;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -58,6 +59,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
private WxCorpInfoService wxCorpInfoService;
|
|
|
@Resource
|
|
|
private SysDictMapper sysDictMapper;
|
|
|
+ @Resource
|
|
|
+ private ExcelExportServiceImpl excelExportService;
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg getList(Integer companyId,String userId, String productName, String productCode, Integer pageIndex, Integer pageSize) {
|
|
@@ -76,6 +79,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
if(!StringUtils.isEmpty(productCode)){
|
|
|
queryWrapper.like(Product::getProductCode,productCode);
|
|
|
}
|
|
|
+ if(pageIndex==null&&pageSize==null){
|
|
|
+ pageIndex=-1;
|
|
|
+ pageSize=-1;
|
|
|
+ }
|
|
|
IPage<Product> productIPage = productMapper.selectPage(new Page<>(pageIndex, pageSize), queryWrapper);
|
|
|
List<Product> records = productIPage.getRecords();
|
|
|
records.forEach(r->{
|
|
@@ -300,4 +307,55 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportData(String userId, String productName, String productCode) throws Exception {
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+ SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCompanyId, user.getCompanyId()).eq(SysForm::getCode, "Product").eq(SysForm::getIsCurrent, 1));
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
|
|
|
+ String config = sysForm.getConfig();
|
|
|
+ JSONObject configOb = JSON.parseObject(config);
|
|
|
+ JSONArray configObJSONArray = configOb.getJSONArray("list");
|
|
|
+ List<List<String>> dataList=new ArrayList<>();
|
|
|
+ List<String> titleList=new ArrayList<>();
|
|
|
+ for (int i = 0; i < configObJSONArray.size(); i++) {
|
|
|
+ JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
+ titleList.add(item.getString("label"));
|
|
|
+ }
|
|
|
+ dataList.add(titleList);
|
|
|
+ HttpRespMsg respMsg = getList(user.getCompanyId(), userId, productName, productCode, null, null);
|
|
|
+ Map<String, Object> msgData = (Map<String, Object>) respMsg.getData();
|
|
|
+ List<Product> productList = (List<Product>) msgData.get("record");
|
|
|
+ for (Product product : productList) {
|
|
|
+ List<String> item=new ArrayList<>();
|
|
|
+ for (int i = 0; i < configObJSONArray.size(); i++) {
|
|
|
+ JSONObject target = configObJSONArray.getJSONObject(i);
|
|
|
+ String model = target.getString("model");
|
|
|
+ String targetName = model.substring(0, 1).toUpperCase() + model.substring(1);
|
|
|
+ Class<? extends Product> aClass = product.getClass();
|
|
|
+ String value = String.valueOf(aClass.getMethod("get" + targetName).invoke(product)==null?"":aClass.getMethod("get" + targetName).invoke(product));
|
|
|
+ if(model.equals("inchargerId")){
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ value = "$userName"+String.valueOf(aClass.getMethod("getInchargerName").invoke(product))+"$";
|
|
|
+ }else {
|
|
|
+ value = String.valueOf(aClass.getMethod("getInchargerName").invoke(product));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(model.equals("unit")){
|
|
|
+ value = String.valueOf(aClass.getMethod("getUnitName").invoke(product));
|
|
|
+ }
|
|
|
+ if(model.equals("type")){
|
|
|
+ value = String.valueOf(aClass.getMethod("getTypeName").invoke(product));
|
|
|
+ }
|
|
|
+ if(model.equals("status")){
|
|
|
+ value = Integer.valueOf(String.valueOf(aClass.getMethod("getStatus").invoke(product)))==0?"下架":"上架";
|
|
|
+ }
|
|
|
+ item.add(value);
|
|
|
+ }
|
|
|
+ dataList.add(item);
|
|
|
+ }
|
|
|
+ String fileName="产品表导出_"+ System.currentTimeMillis();
|
|
|
+ return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName,dataList,path);
|
|
|
+ }
|
|
|
}
|