提交 29ae01b4 authored 作者: 任建宇's avatar 任建宇

总体一版

上级 d6509a85
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Eclipse template
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
.apt_generated_test/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
.idea/
*.iml
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Eclipse template
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
target/
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
.apt_generated_test/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
/target/
\ No newline at end of file
......@@ -46,5 +46,12 @@
<artifactId>okhttp</artifactId>
<version>3.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.zrqx.resource.bg.controller.commodity;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.zrqx.core.enums.resource.PriceOptionEnum;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.util.bean.BeanUtils;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.util.response.CallBack;
import com.zrqx.resource.bg.service.commodity.CommodityService;
import com.zrqx.resource.commons.form.bg.commodity.CommodityForm;
import com.zrqx.resource.commons.form.bg.courselibrary.QueryCourseLibraryForm;
import com.zrqx.resource.commons.form.bg.ebook.SaveUpdateEbookForm;
import com.zrqx.resource.commons.model.commodity.Commodity;
import com.zrqx.resource.commons.model.courcelibrary.CourseLibrary;
import com.zrqx.resource.commons.model.courcelibrary.CourseLibraryDiyType;
import com.zrqx.resource.commons.util.ImportExcelUtil;
import com.zrqx.resource.commons.vo.bg.commodity.ExcelCommodityVo;
import com.zrqx.resource.commons.vo.bg.courselibrary.CourseLibraryListVO;
import com.zrqx.resource.commons.vo.bg.courselibrary.CourseLibraryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import tk.mybatis.mapper.entity.Example;
/**
* 商品库Controller
*/
@RestController
@RequestMapping("/bg/commodity")
@Api(description = "商品")
public class CommodityController {
@Autowired
private CommodityService service;
@ApiOperation("保存商品")
@PostMapping("/save")
public CallBack<?> saveBook(@RequestBody CommodityForm form) {
if (!service.saveOrUpdate(form)) {
throw new BaseException("操作失败");
}
return CallBack.success(true);
}
@ApiOperation(value = "批量删除", notes = "批量删除")
@PostMapping(value = "/batch/delete")
public CallBack<Boolean> deleteByIds(@RequestBody List<String> ids) {
Example example = service.createExample();
example.createCriteria().andIn("id", ids);
service.deleteByExample(example);
return CallBack.success(true);
}
@ApiOperation(value = "查询", notes = "根据ID查询")
@GetMapping(value = "/get/{oid}")
public CallBack<Commodity> getById(@PathVariable String oid) {
return CallBack.success(service.selectByPrimaryKey(oid));
}
@ApiOperation(value = "分页查询", notes = "查询列表")
@GetMapping(value = "/page")
public CallBack<PageInfo<Commodity>> page(CommodityForm form, PageParam pageParam) {
return CallBack.success(service.page(form, pageParam));
}
@ApiOperation(value = "导入商品信息", notes = "导入商品信息")
@PostMapping(value = "/impor/excel", produces = "application/json;charset=UTF-8")
public CallBack<Integer> imporCommodity(@RequestParam("file") MultipartFile file) throws Exception {
List<ExcelCommodityVo> list = ImportExcelUtil.importExcel(file.getInputStream(), ExcelCommodityVo.class,
file.getOriginalFilename());
for (ExcelCommodityVo excelCommodityVo : list) {
Commodity commodity = new Commodity();
BeanUtils.copyProperties(excelCommodityVo, commodity);
commodity.setUpdateTime(new Date());
commodity.setUploadTime(new Date());
service.insert(commodity);
}
return CallBack.success();
}
}
package com.zrqx.resource.bg.controller.shop;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.util.bean.BeanUtils;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.util.response.CallBack;
import com.zrqx.resource.bg.service.shop.ShopService;
import com.zrqx.resource.commons.form.bg.shop.ShopForm;
import com.zrqx.resource.commons.model.shop.Shop;
import com.zrqx.resource.commons.util.ImportExcelUtil;
import com.zrqx.resource.commons.vo.bg.commodity.CommodityVo;
import com.zrqx.resource.commons.vo.bg.shop.ExcelShopVo;
import com.zrqx.resource.commons.vo.bg.shop.ShopVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import tk.mybatis.mapper.entity.Example;
/**
* 店铺库Controller
*/
@RestController
@RequestMapping("/bg/shop")
@Api(description = "店铺")
public class ShopController {
@Autowired
private ShopService service;
@ApiOperation("保存商品")
@PostMapping("/save")
public CallBack<?> saveBook(@RequestBody ShopForm form) {
if (!service.saveOrUpdate(form)) {
throw new BaseException("操作失败");
}
return CallBack.success(true);
}
@ApiOperation(value = "批量删除", notes = "批量删除")
@PostMapping(value = "/batch/delete")
public CallBack<Boolean> deleteByIds(@RequestBody List<String> ids) {
Example example = service.createExample();
example.createCriteria().andIn("id", ids);
service.deleteByExample(example);
return CallBack.success(true);
}
@ApiOperation(value = "查询", notes = "根据ID查询")
@GetMapping(value = "/get/{oid}")
public CallBack<Shop> getById(@PathVariable String oid) {
return CallBack.success(service.selectByPrimaryKey(oid));
}
@ApiOperation(value = "根据店铺id分页查询图书信息", notes = "根据店铺id分页查询图书信息")
@GetMapping(value = "/book/page")
public CallBack<PageInfo<CommodityVo>> bookpage(ShopForm form, PageParam pageParam) {
return CallBack.success(service.bookpage(form, pageParam));
}
@ApiOperation(value = "查询所有店铺", notes = "查询所有店铺")
@GetMapping(value = "/get/platAll")
public CallBack<List<String>> getplatAll() {
return CallBack.success(service.platAll());
}
@ApiOperation(value = "分页查询", notes = "查询列表")
@GetMapping(value = "/page")
public CallBack<PageInfo<ShopVo>> page(ShopForm form, PageParam pageParam) {
return CallBack.success(service.page(form, pageParam));
}
@ApiOperation(value = "导入店铺信息", notes = "导入店铺信息")
@PostMapping(value = "/impor/excel", produces = "application/json;charset=UTF-8")
public CallBack<Integer> imporShop(@RequestParam("file") MultipartFile file)
throws Exception {
List<ExcelShopVo> list = ImportExcelUtil.importExcel(file.getInputStream(), ExcelShopVo.class,
file.getOriginalFilename());
for (ExcelShopVo excelShopVo : list) {
Shop shop = new Shop();
BeanUtils.copyProperties(excelShopVo, shop);
shop.setUpdateTime(new Date());
shop.setUploadTime(new Date());
service.insert(shop);
}
return CallBack.success();
}
}
package com.zrqx.resource.bg.controller.shopCommodity;
import java.io.File;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.util.response.CallBack;
import com.zrqx.resource.bg.mapper.shopCommodity.ShopCommodityMapper;
import com.zrqx.resource.bg.service.shopCommodity.ShopCommodityService;
import com.zrqx.resource.commons.form.bg.shopCommodity.ShopCommodityForm;
import com.zrqx.resource.commons.util.ExportExcelShop;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityAllVo;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* 店铺图书关联Controller
*/
@RestController
@RequestMapping("/bg/shop/Commodity")
@Api(description = "店铺图书关联")
public class ShopCommodityController {
@Autowired
private ShopCommodityService service;
@Autowired
private ShopCommodityMapper mapper;
@ApiOperation(value = "分页查询", notes = "查询列表")
@GetMapping(value = "/page")
public CallBack<PageInfo<ShopCommodityVo>> page(ShopCommodityForm form, PageParam pageParam) {
return CallBack.success(service.page(form, pageParam));
}
@ApiOperation(value = "工作台头部", notes = "工作台头部")
@GetMapping(value = "/get/workbench")
public CallBack<ShopCommodityAllVo> workbench() {
return CallBack.success(service.workbench());
}
@ApiOperation(value = "导出", notes = "导出")
@GetMapping(value = "/export")
public CallBack<List<String>> exportList(HttpServletRequest request, HttpServletResponse response,ShopCommodityForm form) {
List<ShopCommodityVo> queryAllList = mapper.page(form);
if (queryAllList == null || queryAllList.size() == 0) {
throw new BaseException("未查询到资源!");
}
ExportExcelShop exportExcelTemplate =new ExportExcelShop();
String modelPath ="/opt/upload/jgjk/temp"+File.separator+"采集结果.xls";
try {
exportExcelTemplate.exportXls(ShopCommodityVo.class,modelPath, queryAllList, 0, 1, 0, response,
request);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return CallBack.success();
}
@ApiOperation(value = "爬虫", notes = "爬虫")
@PostMapping(value = "/reptile")
public CallBack<Boolean> reptile() {
return CallBack.success(service.reptile());
}
}
package com.zrqx.resource.bg.mapper.commodity;
import java.util.List;
import com.zrqx.resource.bg.mapper.MapperConstants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.resource.commons.form.bg.QueryResourceForPoPForm;
import com.zrqx.resource.commons.form.bg.audiolibrary.QueryAudioLibraryForm;
import com.zrqx.resource.commons.form.bg.resource.SearchForm;
import com.zrqx.resource.commons.model.audiolibrary.AudioLibrary;
import com.zrqx.resource.commons.model.commodity.Commodity;
import com.zrqx.resource.commons.vo.bg.StatisticsResourceExportVO;
import com.zrqx.resource.commons.vo.bg.StatisticsResourceVO;
import com.zrqx.resource.commons.vo.bg.audiolibrary.AudioLibraryListVO;
/**
* 商品库
*/
public interface CommodityMapper extends BaseMapper<Commodity> {
}
package com.zrqx.resource.bg.mapper.shop;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.resource.commons.form.bg.shop.ShopForm;
import com.zrqx.resource.commons.model.shop.Shop;
import com.zrqx.resource.commons.vo.bg.commodity.CommodityVo;
import com.zrqx.resource.commons.vo.bg.shop.ShopVo;
/**
* 店铺库
*/
public interface ShopMapper extends BaseMapper<Shop> {
/**
* 查询
* @Title page
* @param form
* @return List<BookVo>
* @author rjy
* @date 2021年7月13日 下午2:33:32
*/
@Select("<script>"
+ " select * from res_shop s "
+ " where 1 = 1 "
+ "<if test='form.bookName != null or form.isbn != null '>"
+ " id in "
+ " (select shopid from res_shop_commodity sc join res_commodity c on c.id = sc.commodityId where 1 = 1"
+ " eq(c.isbn,form.isbn) "
+ " like(c.bookName,form.bookName) "
+ " )"
+ "</if>"
+ " eq(s.platform,form.platform) "
+ " like(s.shopName,form.shopName) "
+ "</script>")
List<ShopVo> page(@Param("form")ShopForm form);
/**
* 查询
* @Title page
* @param form
* @return List<BookVo>
* @author rjy
* @date 2021年7月13日 下午2:33:32
*/
@Select("<script>"
+ " select bookname,sellingprice,price,isbn from "
+ " res_shop_commodity a INNER JOIN res_commodity b on a.commodityId = b.id where 1 = 1 "
+ " eq(a.shopid,form.id) "
+ "</script>")
List<CommodityVo> bookpage(@Param("form")ShopForm form);
/**
* 查询
* @Title page
* @param form
* @return List<BookVo>
* @author rjy
* @date 2021年7月13日 下午2:33:32
*/
@Select("<script>"
+ " select platform from res_shop GROUP BY platform "
+ "</script>")
List<String> platAll();
}
package com.zrqx.resource.bg.mapper.shopCommodity;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.resource.commons.form.bg.ebook.QueryEbookInfoForm;
import com.zrqx.resource.commons.form.bg.shop.ShopForm;
import com.zrqx.resource.commons.form.bg.shopCommodity.ShopCommodityForm;
import com.zrqx.resource.commons.model.shop.Shop;
import com.zrqx.resource.commons.model.shopCommodity.ShopCommodity;
import com.zrqx.resource.commons.vo.bg.ebook.EbookListVO;
import com.zrqx.resource.commons.vo.bg.shop.ShopVo;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityAllVo;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityVo;
/**
* 店铺关联的商品
*/
public interface ShopCommodityMapper extends BaseMapper<ShopCommodity> {
/**
* 查询
* @Title page
* @param form
* @return List<ShopCommodityVo>
* @author Conan
* @date 2021年7月15日 下午2:33:32
*/
@Select("<script>"
+ " select a.id,c.platform,c.shopname,bookname,currentprice,sellingprice,price,isbn from res_shop_commodity a "
+ " INNER JOIN res_commodity b on a.commodityId = b.id "
+ " INNER JOIN res_shop c on c.id = a.shopid where 1 = 1"
+ " eq(b.isbn,form.isbn) "
+ " like(b.bookName,form.bookName) "
+ " eq(c.platform,form.platform) "
+ " like(c.shopName,form.shopName) "
+ "<if test='form.ids != null and form.ids.size > 0'>"
+ "and a.id in "
+ " <foreach collection=\"form.ids\" index=\"index\" item=\"id\" open=\"(\" separator=\",\" close=\")\">"
+ "#{id}"
+ "</foreach>"
+ "</if>"
+ " ORDER BY (case when currentprice >=sellingprice then 2 else 1 end)asc, bookname desc"
+ "</script>")
List<ShopCommodityVo> page(@Param("form")ShopCommodityForm form);
/**
* 查询
* @Title page
* @param form
* @return List<ShopCommodityVo>
* @author Conan
* @date 2021年7月15日 下午2:33:32
*/
@Select("<script>"
+ " select count(*)monitorCommodity,"
+ " (select count(*) from res_shop) monitorShop,"
+ " (select count(*) from res_shop_commodity a INNER JOIN res_commodity b on a.commodityId = b.id where sellingprice &gt; currentprice ) abnormalPrice,"
+ " (select count(*) from (select a.shopid from res_shop_commodity a INNER JOIN res_commodity b on a.commodityId = b.id where sellingprice &gt; currentprice GROUP BY a.shopid) tt)abnormalShop"
+ " from res_commodity "
+ "</script>")
ShopCommodityAllVo workbench();
}
package com.zrqx.resource.bg.service.commodity;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.bean.BeanUtils;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.resource.bg.mapper.commodity.CommodityMapper;
import com.zrqx.resource.commons.form.bg.commodity.CommodityForm;
import com.zrqx.resource.commons.model.commodity.Commodity;
import com.zrqx.resource.commons.vo.bg.ebook.EbookListVO;
import tk.mybatis.mapper.entity.Example;
/**
* 商品库
*/
@Service
public class CommoditySerivceImpl extends BaseServiceImpl<Commodity,String> implements CommodityService {
@Autowired
private CommodityMapper mapper;
@Override
public BaseMapper<Commodity> getMapper() {
return mapper;
}
@Override
public PageInfo<Commodity> page(CommodityForm form, PageParam pageParam) {
if (null != pageParam && StringUtils.isBlank(pageParam.getOrderBy())) {
pageParam.setOrderBy("uploadTime desc");
}
startPage(pageParam);
Example example = this.createExample();
example.createCriteria().andEqualTo("isbn", form.getIsbn()).andEqualTo("bookName", form.getBookName());
List <Commodity> list= this.selectByExample(example);
return new PageInfo<Commodity>(list);
}
@Override
public boolean saveOrUpdate(CommodityForm form) {
if(StringUtils.isNotBlank(form.getId())) {
//修改
Commodity commodity = this.selectByPrimaryKey(form.getId());
BeanUtils.copyProperties(form, commodity);
commodity.setUpdateTime(new Date());
this.updateByPrimaryKeySelective(commodity);
}else {
//新增
Commodity commodity = new Commodity();
BeanUtils.copyProperties(form, commodity);
commodity.setUpdateTime(new Date());
commodity.setUploadTime(new Date());
this.insert(commodity);
}
return true;
}
}
package com.zrqx.resource.bg.service.commodity;
import com.zrqx.core.service.BaseService;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.resource.commons.form.bg.commodity.CommodityForm;
import com.zrqx.resource.commons.form.bg.ebook.SaveUpdateEbookForm;
import com.zrqx.resource.commons.model.commodity.Commodity;
/**
* 商品库
*/
public interface CommodityService extends BaseService<Commodity,String>{
/**
* 分页查询
* @param form
* @param pageParam
* @return
*/
PageInfo<Commodity> page(CommodityForm form, PageParam pageParam);
/**
* 保存或修改
* @param form
* @return
* @author rjy
* @date: 2020年07月12日 下午2:38:56
*/
boolean saveOrUpdate(CommodityForm form);
}
package com.zrqx.resource.bg.service.shop;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.bean.BeanUtils;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.util.response.CallBack;
import com.zrqx.resource.bg.mapper.shop.ShopMapper;
import com.zrqx.resource.commons.form.bg.commodity.CommodityForm;
import com.zrqx.resource.commons.form.bg.shop.ShopForm;
import com.zrqx.resource.commons.model.commodity.Commodity;
import com.zrqx.resource.commons.model.shop.Shop;
import com.zrqx.resource.commons.vo.bg.commodity.CommodityVo;
import com.zrqx.resource.commons.vo.bg.shop.ShopVo;
import io.swagger.annotations.ApiOperation;
import tk.mybatis.mapper.entity.Example;
/**
* 店铺库
*/
@Service
public class ShopSerivceImpl extends BaseServiceImpl<Shop,String> implements ShopService {
@Autowired
private ShopMapper mapper;
@Override
public BaseMapper<Shop> getMapper() {
return mapper;
}
@Override
public PageInfo<ShopVo> page(ShopForm form, PageParam pageParam) {
if (null != pageParam && StringUtils.isBlank(pageParam.getOrderBy())) {
pageParam.setOrderBy("uploadTime desc");
}
startPage(pageParam);
List<ShopVo> list = mapper.page(form);
return new PageInfo<ShopVo>(list);
}
@Override
public PageInfo<CommodityVo> bookpage(ShopForm form, PageParam pageParam) {
if (null != pageParam && StringUtils.isBlank(pageParam.getOrderBy())) {
pageParam.setOrderBy("b.uploadTime desc");
}
startPage(pageParam);
List<CommodityVo> list = mapper.bookpage(form);
return new PageInfo<CommodityVo>(list);
}
@Override
public boolean saveOrUpdate(ShopForm form) {
if(StringUtils.isNotBlank(form.getId())) {
//修改
Shop shop = this.selectByPrimaryKey(form.getId());
BeanUtils.copyProperties(form, shop);
shop.setUpdateTime(new Date());
this.updateByPrimaryKeySelective(shop);
}else {
//新增
Shop shop = new Shop();
BeanUtils.copyProperties(form, shop);
shop.setUpdateTime(new Date());
shop.setUploadTime(new Date());
this.insert(shop);
}
return true;
}
@Override
public List<String> platAll(){
return mapper.platAll();
}
}
package com.zrqx.resource.bg.service.shop;
import java.util.List;
import com.zrqx.core.service.BaseService;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.resource.commons.form.bg.shop.ShopForm;
import com.zrqx.resource.commons.model.shop.Shop;
import com.zrqx.resource.commons.vo.bg.commodity.CommodityVo;
import com.zrqx.resource.commons.vo.bg.shop.ShopVo;
/**
* 店铺库
*/
public interface ShopService extends BaseService<Shop,String>{
/**
* 分页查询
* @param form
* @param pageParam
* @return
*/
PageInfo<ShopVo> page(ShopForm form, PageParam pageParam);
/**
* 分页查询
* @param form
* @param pageParam
* @return
*/
PageInfo<CommodityVo> bookpage(ShopForm form, PageParam pageParam);
/**
* 保存或修改
* @param form
* @return
* @author rjy
* @date: 2020年07月12日 下午2:38:56
*/
boolean saveOrUpdate(ShopForm form);
/**
* 查询平台
* @param form
* @return
* @author rjy
* @date: 2020年07月132日 下午2:38:56
*/
List<String> platAll();
}
package com.zrqx.resource.bg.service.shopCommodity;
import java.math.BigDecimal;
import java.net.URL;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.openqa.selenium.support.ui.Sleeper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zrqx.core.enums.ResponseCodeEnum;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.http.HttpsUtils;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.resource.bg.mapper.shopCommodity.ShopCommodityMapper;
import com.zrqx.resource.bg.service.commodity.CommodityService;
import com.zrqx.resource.bg.service.shop.ShopService;
import com.zrqx.resource.commons.form.bg.shopCommodity.ShopCommodityForm;
import com.zrqx.resource.commons.model.commodity.Commodity;
import com.zrqx.resource.commons.model.shop.Shop;
import com.zrqx.resource.commons.model.shopCommodity.ShopCommodity;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityAllVo;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityVo;
import tk.mybatis.mapper.entity.Example;
/**
* 店铺关联的商品
*/
@Service
public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, String> implements ShopCommodityService {
@Autowired
private ShopCommodityMapper mapper;
@Autowired
private CommodityService commodityService;
@Autowired
private ShopService shopService;
@Override
public BaseMapper<ShopCommodity> getMapper() {
return mapper;
}
@Override
public PageInfo<ShopCommodityVo> page(ShopCommodityForm form, PageParam pageParam) {
startPage(pageParam);
List<ShopCommodityVo> list = mapper.page(form);
return new PageInfo<ShopCommodityVo>(list);
}
@Override
public ShopCommodityAllVo workbench() {
ShopCommodityAllVo vo = mapper.workbench();
return vo;
}
@Override
public boolean reptile() {
List<Shop> list = shopService.selectAll();
for (Shop shop : list) {
if (shop.getPlatform().equals("当当1")) {
List<Commodity> listCommdoity = commodityService.selectAll();
for (Commodity commdoity : listCommdoity) {
String url = "http://shop.dangdang.com/14937/list.html?key="+commdoity.getIsbn();
try {
Document doc = Jsoup.parse(new URL(url), 300000);
// 图书信息
Elements elements = doc.getElementsByTag("ul");
// System.out.println(elements);
Element tempElement = null;
for (Element element : elements) {
if (element.className().equals("list_aa bigimg")) {
tempElement = element;
// System.out.println(element.className());
break;
}
}
System.out.println(tempElement);
Elements li = tempElement.getElementsByTag("li");
for (Element element : li) {
// 获取标题
String title = element.getElementsByTag("a").attr("title");
if(title.contains(commdoity.getIsbn())) {
// 获取价格
String price = element.getElementsByClass("preis").text();
Example example = this.createExample();
example.createCriteria().andEqualTo("commodityId", commdoity.getId()).andEqualTo("shopId", shop.getId());
List<ShopCommodity> listShop = this.selectByExample(example);
ShopCommodity shopCommodity = new ShopCommodity();
BigDecimal price1= new BigDecimal(price.substring(1, price.length()));
shopCommodity.setCurrentprice(price1);
if(listShop.size() > 0) {
//修改售价
shopCommodity.setUpdateTime(new Date());
this.UpdateByExampleSelective(shopCommodity, example);
continue;
}
shopCommodity.setShopId(shop.getId());
shopCommodity.setCommodityId(commdoity.getId());
shopCommodity.setUpdateTime(new Date());
shopCommodity.setUploadTime(new Date());
this.insert(shopCommodity);
}
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
if (shop.getPlatform().equals("蔚蓝")) {
List<Commodity> listCommdoity = commodityService.selectAll();
for (Commodity commdoity : listCommdoity) {
String url = "https://www.welan.com/search/ajax?keywords=";
String result=HttpsUtils.sendGet(url,commdoity.getIsbn());
JSONObject object = (JSONObject)JSON.parse(result);
//唯一标识用户的 openId
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(Integer.parseInt(object.get("dataCount").toString()) > 0) {
System.out.println();
if(commdoity.getIsbn().equals(object.getJSONArray("books").getJSONObject(0).get("isbn"))) {
Example example = this.createExample();
example.createCriteria().andEqualTo("commodityId", commdoity.getId()).andEqualTo("shopId", shop.getId());
List<ShopCommodity> listShop = this.selectByExample(example);
ShopCommodity shopCommodity = new ShopCommodity();
BigDecimal price1= new BigDecimal(object.getJSONArray("books").getJSONObject(0).get("wlPrice").toString());
shopCommodity.setCurrentprice(price1);
if(listShop.size() > 0) {
//修改售价
shopCommodity.setUpdateTime(new Date());
this.UpdateByExampleSelective(shopCommodity, example);
continue;
}
shopCommodity.setShopId(shop.getId());
shopCommodity.setCommodityId(commdoity.getId());
shopCommodity.setUpdateTime(new Date());
shopCommodity.setUploadTime(new Date());
this.insert(shopCommodity);
}
}
}
}
}
return false;
}
}
package com.zrqx.resource.bg.service.shopCommodity;
import com.zrqx.core.service.BaseService;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.resource.commons.form.bg.commodity.CommodityForm;
import com.zrqx.resource.commons.form.bg.shopCommodity.ShopCommodityForm;
import com.zrqx.resource.commons.model.shopCommodity.ShopCommodity;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityAllVo;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityVo;
/**
* 店铺关联商品
*/
public interface ShopCommodityService extends BaseService<ShopCommodity,String>{
/**
* 分页查询
* @param form
* @param pageParam
* @return
*/
PageInfo<ShopCommodityVo> page(ShopCommodityForm form, PageParam pageParam);
/**
* 分页查询
* @return
*/
ShopCommodityAllVo workbench();
/**
* 爬虫
* @return
*/
boolean reptile();
}
package com.zrqx.resource.commons.form.bg.commodity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.Data;
@Data
@ApiModel(value="CommodityForm",description="商品库")
public class CommodityForm {
@ApiModelProperty("id,新增时不需要填写")
private String id;
@ApiModelProperty(value = "isbn")
private String isbn;
@ApiModelProperty(value = "图书名称")
private String bookName;
@ApiModelProperty(value = "供货商")
private String supplier;
@ApiModelProperty(value = "售价")
private BigDecimal sellingPrice;
@ApiModelProperty(value = "定价")
private BigDecimal price;
}
package com.zrqx.resource.commons.form.bg.shop;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 店铺信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="Shop",description="店铺管理")
public class ShopForm {
@ApiModelProperty("店铺id,新增时不需要填写")
private String id;
@ApiModelProperty(value = "平台")
private String platform;
@ApiModelProperty(value = "店铺名称")
private String shopName;
@ApiModelProperty(value = "网址")
private String urlWebsite;
@ApiModelProperty(value = "联系人")
private String contacts;
@ApiModelProperty(value = "联系方式")
private String contactsMode;
@ApiModelProperty(value = "电话")
private String phone;
@ApiModelProperty(value = "图书名称")
private String bookName;
@ApiModelProperty(value = "图书名称")
private String isbn;
}
package com.zrqx.resource.commons.form.bg.shopCommodity;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 店铺关联信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="ShopCommodityForm",description="店铺关联信息")
public class ShopCommodityForm {
@ApiModelProperty("id")
private List<String> ids;
@ApiModelProperty(value = "平台")
private String platform;
@ApiModelProperty(value = "店铺名称")
private String shopName;
@ApiModelProperty(value = "isbn")
private String isbn;
@ApiModelProperty(value = "图书名称")
private String bookName;
}
package com.zrqx.resource.commons.model.commodity;
import java.math.BigDecimal;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.zrqx.core.util.excelutil.ExcelResources;
import lombok.Data;
/**
* 图书商品信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="Commodity",description="商品管理")
@Table(name = "res_commodity")
public class Commodity {
@Id
@GeneratedValue(strategy =GenerationType.IDENTITY, generator = "SELECT REPLACE (UUID(), '-', '')")
@ApiModelProperty("id,新增时不需要填写")
private String id;
@ApiModelProperty(value = "isbn")
private String isbn;
@ApiModelProperty(value = "图书名称")
private String bookName;
@ApiModelProperty(value = "供货商")
private String supplier;
@ApiModelProperty(value = "售价")
private BigDecimal sellingPrice;
@ApiModelProperty(value = "定价")
private BigDecimal price;
@ApiModelProperty(value = "创建时间")
private Date uploadTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
}
package com.zrqx.resource.commons.model.shop;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 店铺信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="Shop",description="店铺管理")
@Table(name = "res_shop")
public class Shop {
@Id
@GeneratedValue(strategy =GenerationType.IDENTITY, generator = "SELECT REPLACE (UUID(), '-', '')")
@ApiModelProperty("店铺id,新增时不需要填写")
private String id;
@ApiModelProperty(value = "平台")
private String platform;
@ApiModelProperty(value = "店铺名称")
private String shopName;
@ApiModelProperty(value = "网址")
private String urlWebsite;
@ApiModelProperty(value = "联系人")
private String contacts;
@ApiModelProperty(value = "联系方式")
private String contactsMode;
@ApiModelProperty(value = "电话")
private String phone;
@ApiModelProperty(value = "创建时间")
private Date uploadTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
}
package com.zrqx.resource.commons.model.shopCommodity;
import java.math.BigDecimal;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 店铺关联商品
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="ShopCommodity",description="店铺关联商品")
@Table(name = "res_shop_commodity")
public class ShopCommodity {
@Id
@GeneratedValue(strategy =GenerationType.IDENTITY, generator = "SELECT REPLACE (UUID(), '-', '')")
@ApiModelProperty("id,新增时不需要填写")
private String id;
@ApiModelProperty(value = "店铺id")
private String shopId;
@ApiModelProperty(value = "商品id")
private String commodityId;
@ApiModelProperty(value = "当前售价")
private BigDecimal currentprice;
@ApiModelProperty(value = "创建时间")
private Date uploadTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
}
package com.zrqx.resource.commons.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.formula.functions.T;
import com.zrqx.core.util.http.HttpUtils;
import com.zrqx.resource.commons.vo.bg.shopCommodity.ShopCommodityVo;
public class ExportExcelShop {
public static final String DEFAULT_TEMPLATE_PATH = File.separator + "template" + File.separator + "temp.xls";
/**
* @throws Exception
*
* 根据模板导出excel, 这种方法是 通过给模板中指定的位置赋值,然后重新生成excel,来导出excel的,
* 而且不会修改模板本身。 感觉不太合适去导出有大量数据的excel。 POIFSFileSystem: poi里面的类,
* 可以把Excel文件作为数据流来进行传入传出。这里介绍下POIFSFileSystem类,这个类是专门用来读取excel表格的。
*
*
* 模板文件路径:项目内,src/main/resource/template/xxx.xls
*/
public static void exportXls(Class clz, String path, List<ShopCommodityVo> list, Integer sheetNum,
Integer startRow, Integer startCellNum, HttpServletResponse response, HttpServletRequest request)
throws Exception {
// 项目模板路径
String tempPath = path;
// 模板文件
File file = new File(tempPath);
String filename = file.getName();
// 读取项目模板文件
POIFSFileSystem poifsFileSystem = new POIFSFileSystem(file);
HSSFWorkbook workbook = new HSSFWorkbook(poifsFileSystem);
HSSFSheet sheet = workbook.getSheetAt(sheetNum);
if (sheet == null) {
sheet = workbook.createSheet();
}
// 赋值单元格
for (int i = 0; i < list.size(); i++) {
HSSFRow row = sheet.getRow(startRow + i);
if (row == null) {
row = sheet.createRow(startRow + i);
}
ShopCommodityVo vo = list.get(i);
int cellNum = 0;
// 取第一个值放到第一个单元格 依此类推
HSSFCell cell = row.getCell(startCellNum + cellNum); // 第一个单元格
if (cell == null) {
cell = row.createCell(startCellNum + cellNum);
}
String name = vo.getPlatform();
cell.setCellValue(name);
cellNum++;
cell = row.getCell(startCellNum + cellNum);// 第二个单元格
if (cell == null) {
cell = row.createCell(startCellNum + cellNum);
}
cell.setCellValue(vo.getShopName());
cellNum++;
cell = row.getCell(startCellNum + cellNum);
if (cell == null) {
cell = row.createCell(startCellNum + cellNum);
}
cell.setCellValue(vo.getIsbn());
cellNum++;
cell = row.getCell(startCellNum + cellNum);
if (cell == null) {
cell = row.createCell(startCellNum + cellNum);
}
cell.setCellValue(vo.getBookName());
cellNum++;
cell = row.getCell(startCellNum + cellNum);
if (cell == null) {
cell = row.createCell(startCellNum + cellNum);
}
cell.setCellValue(vo.getCurrentprice());
cellNum++;
cell = row.getCell(startCellNum + cellNum);
if (cell == null) {
cell = row.createCell(startCellNum + cellNum);
}
cell.setCellValue(vo.getSellingPrice());
continue;
}
response.setContentType("application/octet-stream");
// 设置response参数,可以打开下载页面
response.reset();
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + HttpUtils.transCharacter(request, filename));
OutputStream os = new BufferedOutputStream(response.getOutputStream());
workbook.write(os);// 输出文件
os.flush();
os.close();
// FileOutputStream out = new FileOutputStream("E:"+File.separator+"export.xls");
// workbook.write(out);
// out.close();
// ServletOutputStream os = response.getOutputStream();
// HashMap<String, String> map = new HashMap<String, String>();
// ExcelUtil.getInstance().exportObj2ExcelByTemplate(map, tempPath, os, list,clz, true);
}
public void exportXls() throws Exception {
String path = this.getClass().getClassLoader().getResource("").getPath();
File file = new File(path + File.separator + "template" + File.separator + "temp.xls");
System.out.println(file.exists());
// 读取项目根目录中的模板
InputStream in = this.getClass().getResourceAsStream(path + "/template/temp.xls");
System.out.println(in);
// File file = new File("E:\\template.xls"); 电脑硬盘上的模板,,一般模板都在项目里
POIFSFileSystem poifsFileSystem = new POIFSFileSystem(file);
HSSFWorkbook workbook = new HSSFWorkbook(poifsFileSystem);
HSSFSheet sheet = workbook.getSheetAt(0);
sheet.setForceFormulaRecalculation(true);
HSSFRow row = null;
row = sheet.getRow(3);
if (row == null) {
row = sheet.createRow(3);
}
// 根据模板中表达式位置, 修改对应单元格的值
HSSFCell cell = row.getCell(0);// 第3行 第1列, 下标是0开始的
if (cell == null) {
cell = row.createCell(0);
}
cell.setCellValue("张三");
cell = row.getCell(1);
if (cell == null) {
cell = row.createCell(1);
}
cell.setCellValue(23);
// row.getCell(2).setCellValue("180cm");
// row.getCell(3).setCellValue("未婚");
// row.getCell(4).setCellValue("男");
// 修改模板内容导出新模板
// '/' 分隔符 采用 File.separator 统一表示
FileOutputStream out = new FileOutputStream("E:" + File.separator + "export.xls");
workbook.write(out);
out.close();
}
public static void main(String[] args) throws Exception {
// new ExportExcelTemplate().exportXls();
List<ExportEntity> list = new ArrayList<ExportEntity>();
for (int i = 0; i < 20; i++) {
ExportEntity ee = new ExportEntity();
ee.setField1(i + "_field1");
ee.setField2(i + "_field2");
ee.setField3(i + "_field3");
ee.setField4(i + "_field4");
ee.setField5(i + "_field5");
ee.setField6(i + "_field6");
ee.setField7(i + "_field7");
list.add(ee);
}
// ExportExcelTemplate.exportXls(DEFAULT_TEMPLATE_PATH, list, 0, 3, 0);
}
public static void printClass(T t) throws Exception {
Class<? extends T> clazz = null;
clazz = t.getClass();
Field[] fields = clazz.getFields();
for (Field f : fields) {
f.get(t);
}
}
/**
* 打印类的信息,包括类的成员函数,成员变量
*
* @param obj 该对象所属类的信息
*/
public static void printClassMessage(Object obj) {
// 要获取类的信息,首先要获取类的类类型
Class c = obj.getClass();// 传递的是哪个子类的对象,c就是该子类的类类型
// 获取类的名称
System.out.println("类的名称是:" + c.getName());
/*
* Method类,方法的对象 一个成员方法就是一个Method对象 getMethods()方法获取的是所有的public的函数,包括父类继承而来的
* getDeclaredMethods()获取的是多有该类自己声明的方法,不问访问权限
*/
Method[] ms = c.getMethods();// c.getDeclaredMethods();
for (int i = 0; i < ms.length; i++) {
// 得到方法的返回值类型的类类型
Class retrunType = ms[i].getReturnType();
System.out.print(retrunType.getName() + " ");
// 得到方法的名称
System.out.print(ms[i].getName() + "(");
// 获取的参数类型--->得到的是参数列表的类型的类类型
Class[] paraTypes = ms[i].getParameterTypes();
for (Class class1 : paraTypes) {
System.out.print(class1.getName() + ",");
}
System.out.println(")");
}
}
}
/**
* @author ray
* @date 2018年8月24日 下午3:22:57
*/
package com.zrqx.resource.commons.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
/** java模拟 post get请求发送
* @author ray
* @date 2018年8月24日下午3:22:57
*/
public class HttpsUtils {
/**
* java模拟get请求
* @param out_trade_no
* @return
* @throws Exception
* @author ray
* @date: 2018年8月24日 下午3:25:34
*/
public static String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
//设置连接主机超时
connection.setConnectTimeout(30000);
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
/**
* java模拟post请求
* @param out_trade_no
* @return
* @throws Exception
* @author ray
* @date: 2018年8月24日 下午3:25:34
*/
public static String sendPost(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!"+e);
e.printStackTrace();
}
//使用finally块来关闭输出流、输入流
finally{
try{
if(out!=null){
out.close();
}
if(in!=null){
in.close();
}
}
catch(IOException ex){
ex.printStackTrace();
}
}
return result;
}
public static String sendPost(String url, Map<String,? extends Object> paramsMap) {
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
//配置连接超时时间
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000)
.setConnectionRequestTimeout(5000)
.setSocketTimeout(5000)
.setRedirectsEnabled(true)
.build();
HttpPost httpPost = new HttpPost(url);
//设置超时时间
httpPost.setConfig(requestConfig);
//装配post请求参数
List<NameValuePair> list = new ArrayList<NameValuePair>();
for (String key : paramsMap.keySet()) {
list.add(new BasicNameValuePair(key, String.valueOf(paramsMap.get(key))));
}
try {
//将参数进行编码为合适的格式,如将键值对编码为param1=value1&param2=value2
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, "utf-8");
httpPost.setEntity(urlEncodedFormEntity);
//执行 post请求
CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpPost);
String strRequest = "";
if (null != closeableHttpResponse && !"".equals(closeableHttpResponse)) {
System.out.println(closeableHttpResponse.getStatusLine().getStatusCode());
if (closeableHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity httpEntity = closeableHttpResponse.getEntity();
strRequest = EntityUtils.toString(httpEntity,"utf-8");
} else {
strRequest = "Error Response" + closeableHttpResponse.getStatusLine().getStatusCode();
}
}
return strRequest;
} catch (ClientProtocolException e) {
e.printStackTrace();
return "协议异常";
} catch (ParseException e) {
e.printStackTrace();
return "解析异常";
} catch (IOException e) {
e.printStackTrace();
return "传输异常";
} finally {
try {
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.zrqx.resource.commons.vo.bg.commodity;
import java.math.BigDecimal;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.zrqx.core.util.excelutil.ExcelResources;
import lombok.Data;
/**
* 图书商品信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="CommodityVo",description="商品管理")
public class CommodityVo {
@ApiModelProperty("id,新增时不需要填写")
private String id;
@ApiModelProperty(value = "isbn")
private String isbn;
@ApiModelProperty(value = "图书名称")
private String bookName;
@ApiModelProperty(value = "供货商")
private String supplier;
@ApiModelProperty(value = "售价")
private BigDecimal sellingPrice;
@ApiModelProperty(value = "定价")
private BigDecimal price;
@ApiModelProperty(value = "创建时间")
private Date uploadTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
}
package com.zrqx.resource.commons.vo.bg.commodity;
import java.math.BigDecimal;
import com.zrqx.core.util.excelutil.ExcelResources;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel(value="ExcelCommodityVo",description="导入店铺信息")
public class ExcelCommodityVo {
@ExcelResources(title = "书号")
private String isbn;
@ExcelResources(title = "供货商")
private String supplier;
@ExcelResources(title = "书名")
private String bookName;
@ExcelResources(title = "限价")
private BigDecimal sellingPrice;
@ExcelResources(title = "定价")
private BigDecimal price;
}
package com.zrqx.resource.commons.vo.bg.shop;
import com.zrqx.core.util.excelutil.ExcelResources;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel(value="ExcelShopVo",description="导入店铺信息")
public class ExcelShopVo {
@ExcelResources(title = "平台名称")
private String platform;
@ExcelResources(title = "店名")
private String shopName;
@ExcelResources(title = "网址")
private String urlWebsite;
@ExcelResources(title = "联系人")
private String contacts;
@ExcelResources(title = "联系方式QQ")
private String contactsMode;
@ExcelResources(title = "电话")
private String phone;
}
package com.zrqx.resource.commons.vo.bg.shop;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 店铺信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="ShopVo",description="店铺管理")
public class ShopVo {
@ApiModelProperty("店铺id,新增时不需要填写")
private String id;
@ApiModelProperty(value = "平台")
private String platform;
@ApiModelProperty(value = "店铺名称")
private String shopName;
@ApiModelProperty(value = "网址")
private String urlWebsite;
@ApiModelProperty(value = "联系人")
private String contacts;
@ApiModelProperty(value = "联系方式")
private String contactsMode;
@ApiModelProperty(value = "电话")
private String phone;
@ApiModelProperty(value = "创建时间")
private Date uploadTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
}
package com.zrqx.resource.commons.vo.bg.shopCommodity;
import java.math.BigDecimal;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 店铺关联信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="ShopCommodityAllVo",description="店铺关联信息")
public class ShopCommodityAllVo {
@ApiModelProperty(value = "当日价格异常(件)")
private String abnormalPrice;
@ApiModelProperty(value = "价格异常店铺")
private String abnormalShop;
@ApiModelProperty(value = "监控店铺")
private String monitorShop;
@ApiModelProperty(value = "监控商品")
private String monitorCommodity;
}
package com.zrqx.resource.commons.vo.bg.shopCommodity;
import java.math.BigDecimal;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 店铺关联信息
* @author rjy
* @date 2021年7月12日上午9:43:38
*/
@Data
@ApiModel(value="ShopCommodityVo",description="店铺关联信息")
public class ShopCommodityVo {
@ApiModelProperty("id")
private String id;
@ApiModelProperty(value = "平台")
private String platform;
@ApiModelProperty(value = "店铺名称")
private String shopName;
@ApiModelProperty(value = "isbn")
private String isbn;
@ApiModelProperty(value = "图书名称")
private String bookName;
@ApiModelProperty(value = "售价")
private String sellingPrice;
@ApiModelProperty(value = "定价")
private String price;
@ApiModelProperty(value = "当前售价")
private String currentprice;
}
......@@ -48,7 +48,16 @@ public class StringUtil{
return flag;
}
/**
* 去掉英文和中文的空格
* @param str
* @return
* @author ycw
* @date: 2019年9月17日 上午10:53:32
*/
public static String filterBlankSpace(String str){
return str.replaceAll(" ", "").replaceAll(" ", "");
}
/**
* 给定指定字符串res,去除字符串首尾的指定字符c
*
......
/**
* @author ray
* @date 2018年8月24日 下午3:22:57
*/
package com.zrqx.core.util.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
/** java模拟 post get请求发送
* @author ray
* @date 2018年8月24日下午3:22:57
*/
public class HttpsUtils {
/**
* java模拟get请求
* @param out_trade_no
* @return
* @throws Exception
* @author ray
* @date: 2018年8月24日 下午3:25:34
*/
public static String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
//设置连接主机超时
connection.setConnectTimeout(30000);
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
/**
* java模拟post请求
* @param out_trade_no
* @return
* @throws Exception
* @author ray
* @date: 2018年8月24日 下午3:25:34
*/
public static String sendPost(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!"+e);
e.printStackTrace();
}
//使用finally块来关闭输出流、输入流
finally{
try{
if(out!=null){
out.close();
}
if(in!=null){
in.close();
}
}
catch(IOException ex){
ex.printStackTrace();
}
}
return result;
}
public static String sendPost(String url, Map<String,? extends Object> paramsMap) {
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
//配置连接超时时间
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000)
.setConnectionRequestTimeout(5000)
.setSocketTimeout(5000)
.setRedirectsEnabled(true)
.build();
HttpPost httpPost = new HttpPost(url);
//设置超时时间
httpPost.setConfig(requestConfig);
//装配post请求参数
List<NameValuePair> list = new ArrayList<NameValuePair>();
for (String key : paramsMap.keySet()) {
list.add(new BasicNameValuePair(key, String.valueOf(paramsMap.get(key))));
}
try {
//将参数进行编码为合适的格式,如将键值对编码为param1=value1&param2=value2
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, "utf-8");
httpPost.setEntity(urlEncodedFormEntity);
//执行 post请求
CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpPost);
String strRequest = "";
if (null != closeableHttpResponse && !"".equals(closeableHttpResponse)) {
System.out.println(closeableHttpResponse.getStatusLine().getStatusCode());
if (closeableHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity httpEntity = closeableHttpResponse.getEntity();
strRequest = EntityUtils.toString(httpEntity,"utf-8");
} else {
strRequest = "Error Response" + closeableHttpResponse.getStatusLine().getStatusCode();
}
}
return strRequest;
} catch (ClientProtocolException e) {
e.printStackTrace();
return "协议异常";
} catch (ParseException e) {
e.printStackTrace();
return "解析异常";
} catch (IOException e) {
e.printStackTrace();
return "传输异常";
} finally {
try {
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
......@@ -2,7 +2,7 @@
### 测试环境搭建
```shell script
# 1. svn 检出
svn co http://192.168.2.203/repos/java-yanfa/5.0/hxwza/com.zrqx.pom
svn co http://192.168.2.203/repos/java-yanfa/5.0/jgjk/com.zrqx.pom
# 2. 项目初始化,生成各服务启动,关闭脚本
cd com.zrqx.pom/bin
sh init.sh
......
......@@ -2,7 +2,7 @@
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd"
debug="false" scan="true" scanPeriod="30 second">
<property name="ROOT" value="/opt/logs/hxwza/eureka/" />
<property name="ROOT" value="/opt/logs/jgjk/eureka/" />
<property name="FILESIZE" value="10MB" />
<property name="MAXHISTORY" value="10" />
<timestamp key="DATETIME" datePattern="yyyy-MM-dd HH:mm:ss" />
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论