Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
6
651project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
651project
651project
Commits
c72a9125
Commit
c72a9125
authored
3 years ago
by
Josh
Browse files
Options
Downloads
Patches
Plain Diff
fix bugs
parent
ad03a310
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/example/freshonline/service/StockedGoodsService.java
+3
-152
3 additions, 152 deletions
.../com/example/freshonline/service/StockedGoodsService.java
src/main/resources/application.properties
+1
-1
1 addition, 1 deletion
src/main/resources/application.properties
with
4 additions
and
153 deletions
src/main/java/com/example/freshonline/service/StockedGoodsService.java
+
3
−
152
View file @
c72a9125
...
...
@@ -56,158 +56,9 @@ public class StockedGoodsService {
* price_range: List<BigDecimal> price_range: Arrays.asList(minInit: MAX_PRICE, maxInit: MIN_PRICE)
* goods_total: Integer goods_total
*/
// Integer numPerRow = 4, rowsPerPage = 5;
public
JSONObject
getSearch
(
SearchParams
param
){
// try {
// Class.forName("com.mysql.cj.jdbc.Driver");
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// }
//
// Properties pros;
// Connection conn = null;
// try {
// pros = new Properties();
// pros.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"));
// Class.forName(pros.getProperty("spring.datasource.driver-class-name"));
// conn = DriverManager.getConnection(pros.getProperty("spring.datasource.url"), pros.getProperty("spring.datasource.username"), pros.getProperty("spring.datasource.password"));
// }
// catch (Exception e){
// e.printStackTrace();
// }
//
// String sql_base = "select * from stocked_goods";
//
// Integer price_low = param.getInteger("price_low");
// Integer price_high = param.getInteger("price_high");
// Integer category_id = param.getInteger("category_id");
// String keyword = param.getString("keyword");
// String brands;
// try{
// String[] brands_list = param.getString("brands").split(",");
// brands = "('" + String.join("','", brands_list) + "')";
// } catch (NullPointerException e) {brands = null;}
// /**
// * brands: ('brand1', 'brand2')
// */
// Integer sort_type = param.getInteger("sort_type");
// Integer page = param.getInteger("page");
//
// String sql_condition = " where true";
// if (price_low != null) sql_condition += " and price > " + price_low;
// if (price_high != null) sql_condition += " and price < " + price_high;
// if (category_id != null) sql_condition += " and category_id = " + category_id;
// if (keyword != null) sql_condition += " and name like '%" + keyword + "%'";
// if (brands != null) sql_condition += " and brand in " + brands;
// if (sort_type != null){
// /**
// * @sort_type
// * 1: min(price, sale_price) 升序
// * 2: min(price, sale_price) 降序
// */
// if (sort_type == 1 || sort_type == 2) {
// sql_condition += " \norder by case \n" +
// "\twhen COALESCE(sale_price, 10000) < price then sale_price\n" +
// "\telse price\n" +
// "end ";
// if (sort_type == 1) sql_condition += "asc ";
// else sql_condition += "desc ";
// }
// /**
// * 3: sales 升序
// * 4: sales 降序
// */
// if (sort_type == 3 || sort_type == 4) {
// sql_condition += " \norder by sales ";
// if (sort_type == 3) sql_condition += "asc ";
// else sql_condition += "desc ";
// }
// }
//
// String sql_page;
// Integer item_low = (page-1) * numPerRow * rowsPerPage, item_high = page * numPerRow * rowsPerPage;
// sql_page = "\n limit " + item_low + "," + item_high;
//
// String sql_with_page = sql_base + sql_condition + sql_page + ";";
// System.out.println("sql_with_page = " + sql_with_page);
//
// List<StockedGoods> goods_list = new ArrayList<>();
// try {
// PreparedStatement ps = conn.prepareStatement(sql_with_page);
// ResultSet result = ps.executeQuery();
// while (result.next()) {
// StockedGoods tmp = new StockedGoods();
// tmp.setId(result.getInt("id"));
// tmp.setName(result.getString("name"));
// tmp.setType(result.getByte("type"));
// tmp.setPrice(result.getBigDecimal("price"));
// tmp.setStorage(result.getBigDecimal("storage"));
// tmp.setSales(result.getBigDecimal("sales"));
// tmp.setDescription(result.getString("description"));
// tmp.setOnsale(result.getByte("onsale"));
// tmp.setBrand(result.getString("brand"));
// tmp.setCategoryId(result.getInt("category_id"));
// tmp.setIsNew(result.getByte("is_new"));
// tmp.setPic(result.getString("pic"));
// tmp.setSalePrice(result.getBigDecimal("sale_price"));
// tmp.setRate(result.getBigDecimal("rate"));
// tmp.setRateCount(result.getInt("rate_count"));
// System.out.println("result = " + tmp.toString());
// goods_list.add(tmp);
// }
// result.close();
// ps.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// String sql_base_raw = "select count(*) from stocked_goods";
// String sql_raw = sql_base_raw + sql_condition + ";";
// System.out.println("sql_raw = " + sql_raw);
// Integer goods_total = 0;
// try {
// PreparedStatement ps = conn.prepareStatement(sql_raw);
// ResultSet result = ps.executeQuery();
// while (result.next()) {
// goods_total = result.getInt(1);
// }
// result.close();
// ps.close();
// conn.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
//
// Set<String> brand_set = new HashSet<>();
// List<BigDecimal> price_range = new ArrayList<>(Arrays.asList(MAX_PRICE, MIN_PRICE));
// for (int i = 0; i < goods_list.size(); i ++) {
// StockedGoods tmp = goods_list.get(i);
// brand_set.add(tmp.getBrand());
// if (tmp.getOnsale() != 0){
// price_range.set(0, price_range.get(0).min(tmp.getSalePrice()));
// price_range.set(1, price_range.get(1).max(tmp.getSalePrice()));
// }
// else{
// price_range.set(0, price_range.get(0).min(tmp.getPrice()));
// price_range.set(1, price_range.get(1).max(tmp.getPrice()));
// }
// }
//
// System.out.println(price_range);
// System.out.println(brand_set);
// System.out.println(goods_total);
//
// JSONObject output = new JSONObject();
// output.put("goods_list", JSONObject.toJSONString(goods_list));
// output.put("price_range", JSONObject.toJSONString(price_range));
// output.put("brand_list", JSONObject.toJSONString(new ArrayList<>(brand_set)));
// output.put("goods_total", goods_total);
// output.put("page", page);
List
<
StockedGoods
>
stockedGoods
=
stockedGoodsMapper
.
selectByFilter
(
param
);
SearchResultInfo
info
=
stockedGoodsMapper
.
searchInfo
(
param
);
System
.
out
.
println
(
info
);
...
...
@@ -221,9 +72,9 @@ public class StockedGoodsService {
}
JSONObject
output
=
new
JSONObject
();
output
.
put
(
"goods_list"
,
JSONObject
.
toJSONString
(
stockedGoods
)
)
;
output
.
put
(
"price_range"
,
JSONObject
.
toJSONString
(
price_range
)
)
;
output
.
put
(
"brand_list"
,
JSONObject
.
toJSONString
(
brand_list
)
)
;
output
.
put
(
"goods_list"
,
stockedGoods
);
output
.
put
(
"price_range"
,
price_range
);
output
.
put
(
"brand_list"
,
brand_list
);
output
.
put
(
"goods_total"
,
goods_total
);
output
.
put
(
"page"
,
param
.
getPage
());
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/application.properties
+
1
−
1
View file @
c72a9125
spring.datasource.url
=
jdbc:mysql://localhost:3306/FreshOnline?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.username
=
root
spring.datasource.password
=
root
spring.datasource.password
=
spring.datasource.type
=
com.alibaba.druid.pool.DruidDataSource
mybatis.mapper-locations
=
classpath:mapper/*.xml
mybatis.type-aliases-package
=
com.example.freshonline.dao
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment