parent
6cd3b0cc22
commit
1abd6eb261
@ -1,15 +1,100 @@
|
||||
package com.example.cat.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.example.cat.entity.CatProduct;
|
||||
import com.example.cat.entity.CatShoppingCart;
|
||||
import com.example.cat.service.ShoppingCartService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author zhijun
|
||||
* @Date 2019/12/13
|
||||
* @Author longyanyi
|
||||
* @Date 2023/5/9
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/orange/shoppingCart")
|
||||
@RequestMapping("/orange/shoppingcart")
|
||||
@CrossOrigin
|
||||
public class CatShoppingCartController {
|
||||
@Autowired
|
||||
private ShoppingCartService shoppingCartService;
|
||||
|
||||
@Value("${uploadFilePath}")
|
||||
private String uploadFilePath;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/search1", method = RequestMethod.POST)
|
||||
public Map<String, Object> searchProduct(@RequestBody String userId) {
|
||||
|
||||
List<CatProduct> productList = shoppingCartService.selectCatProduct(Integer.valueOf(userId));
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (CollectionUtils.isEmpty(productList)) {
|
||||
map.put("flag", false);
|
||||
map.put("msg", "search error");
|
||||
return map;
|
||||
}
|
||||
map.put("flag", true);
|
||||
map.put("data", productList);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/sharecropping", method = RequestMethod.POST)
|
||||
public Map<String, Object> searchShoppingCart(@RequestBody String userId) {
|
||||
List<CatShoppingCart> productList = shoppingCartService.selectShoppingCart(Integer.valueOf(userId));
|
||||
System.out.println(Integer.valueOf(userId));
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (CollectionUtils.isEmpty(productList)) {
|
||||
map.put("flag", false);
|
||||
map.put("msg", "search error");
|
||||
return map;
|
||||
}
|
||||
map.put("flag", true);
|
||||
map.put("data", productList);
|
||||
System.out.println("1111"+productList.get(1).getNum());
|
||||
System.out.println("1111"+productList.get(0).getNum());
|
||||
return map;
|
||||
}
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @param file 上传文件
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/uploadCover1")
|
||||
public Map<String, Object> uploadCover(@RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
try {
|
||||
String fileName = file.getOriginalFilename();
|
||||
String changeFileName = uploadFilePath + fileName;
|
||||
File destFile = new File(changeFileName);
|
||||
if (!destFile.exists()) {
|
||||
destFile.getParentFile().mkdirs();
|
||||
file.transferTo(destFile);
|
||||
}
|
||||
map.put("flag", true);
|
||||
map.put("data", "http://10.21.120.101:8081/uploaded/" + fileName);
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
map.put("flag", false);
|
||||
map.put("msg", "upload error");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,32 @@
|
||||
package com.example.cat.mapper;
|
||||
|
||||
import com.example.cat.entity.CatProduct;
|
||||
import com.example.cat.entity.CatShoppingCart;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author zhijun
|
||||
* @Date 2019/12/13
|
||||
* @Author longyanyi
|
||||
* @Date 2023/5/9
|
||||
*/
|
||||
@Mapper
|
||||
public interface ShoppingCartMapper {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CatProduct> selectCatProduct(@Param("userId") Integer userId);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CatShoppingCart> selectShoppingCart(@Param("userId") Integer userId);
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,39 @@
|
||||
package com.example.cat.service;
|
||||
|
||||
import com.example.cat.entity.CatProduct;
|
||||
import com.example.cat.entity.CatShoppingCart;
|
||||
import com.example.cat.mapper.ShoppingCartMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author zhijun
|
||||
* @Date 2019/12/13
|
||||
* @Author longyanyi
|
||||
* @Date 20123/5/9
|
||||
*/
|
||||
@Service
|
||||
public class ShoppingCartService {
|
||||
@Autowired
|
||||
private ShoppingCartMapper shoppingCartMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
|
||||
public List<CatProduct> selectCatProduct(Integer userId) {
|
||||
return shoppingCartMapper.selectCatProduct(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public List<CatShoppingCart> selectShoppingCart(Integer userId) {
|
||||
return shoppingCartMapper.selectShoppingCart(userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.cat.mapper.ShoppingCartMapper">
|
||||
<select id="selectCatProduct" resultType="com.example.cat.entity.CatProduct">
|
||||
select a.id,a.name,a.img_url,a.price,a.add_time from orange_product a,orange_shoppingcart b where b.user_id=#{userId} and a.id=b.product_id
|
||||
</select>
|
||||
<select id="selectShoppingCart" resultType="com.example.cat.entity.CatShoppingCart">
|
||||
select id,user_id,product_id,num from orange_shoppingcart where user_id=#{userId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1 @@
|
||||
CatApp
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,73 @@
|
||||
package com.example.catapp.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.catapp.R;
|
||||
import com.example.catapp.entity.CatProductPack;
|
||||
import com.example.catapp.entity.ShoppingCart;
|
||||
import com.example.catapp.entity.ShoppingCartPack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ShoppingCartAdapter extends BaseAdapter {
|
||||
private List<ShoppingCartPack> shoppingCartList;
|
||||
|
||||
private List<CatProductPack> catProductList;
|
||||
private LayoutInflater layoutInflater;
|
||||
|
||||
public ShoppingCartAdapter(Context context, List<CatProductPack> catProductList,List<ShoppingCartPack> shoppingCartList) {
|
||||
this.catProductList = catProductList;
|
||||
this.shoppingCartList=shoppingCartList;
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return catProductList.size();
|
||||
}
|
||||
|
||||
public Object getItem(int position) {
|
||||
return catProductList.get(position);
|
||||
}
|
||||
|
||||
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ShoppingCartAdapter.ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
convertView = layoutInflater.inflate(R.layout.shoppingcart_detail_content, null);
|
||||
viewHolder = new ShoppingCartAdapter.ViewHolder();
|
||||
viewHolder.productImage = convertView.findViewById(R.id.category_product_image);
|
||||
viewHolder.productName = convertView.findViewById(R.id.category_product_name);
|
||||
viewHolder.productPrice = convertView.findViewById(R.id.category_product_price);
|
||||
viewHolder.num = convertView.findViewById(R.id.num);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ShoppingCartAdapter.ViewHolder) convertView.getTag();
|
||||
}
|
||||
CatProductPack product = catProductList.get(position);
|
||||
if (product != null) {
|
||||
viewHolder.productImage.setImageBitmap(product.getImgBitmap());
|
||||
viewHolder.productName.setText(product.getName());
|
||||
viewHolder.productPrice.setText(String.format("%s元", String.valueOf(product.getPrice())));
|
||||
}
|
||||
ShoppingCartPack shoppingCart=shoppingCartList.get(position);
|
||||
if(shoppingCart!=null)
|
||||
viewHolder.num.setText(""+shoppingCart.getNum());
|
||||
return convertView;
|
||||
}
|
||||
class ViewHolder {
|
||||
ImageView productImage;
|
||||
TextView productName, productPrice,num;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.example.catapp.entity;
|
||||
|
||||
public class ShoppingCartPack {
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Integer getProductId() {
|
||||
return ProductId;
|
||||
}
|
||||
|
||||
public void setProductId(Integer productId) {
|
||||
ProductId = productId;
|
||||
}
|
||||
|
||||
public Integer getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(Integer number) {
|
||||
this.num = number;
|
||||
}
|
||||
|
||||
private Integer id;
|
||||
private Integer userId;
|
||||
private Integer ProductId;
|
||||
/**
|
||||
* 购买数量
|
||||
*/
|
||||
private Integer num;
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package com.example.catapp.netrequest;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.example.catapp.entity.CatProduct;
|
||||
import com.example.catapp.entity.CatProductPack;
|
||||
import com.example.catapp.entity.ShoppingCart;
|
||||
import com.example.catapp.entity.ShoppingCartPack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class OkHttpShoppingcart {
|
||||
//shoppingCart
|
||||
/**
|
||||
* 查询商品信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
public List<CatProduct> getProduct(Integer userId) throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
//数据类型为json格式
|
||||
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
||||
//将对象转为JSON字符串
|
||||
String jsonStr = JSONObject.toJSONString(userId);
|
||||
RequestBody requestBody = RequestBody.create(jsonStr, mediaType);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url("http://10.21.120.101:8081/orange/shoppingcart/search1")
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
System.out.println(response.isSuccessful());
|
||||
System.out.println(response.isSuccessful());
|
||||
System.out.println(response.isSuccessful());
|
||||
JSONObject jsonObject = JSON.parseObject(Objects.requireNonNull(response.body()).string());
|
||||
List<CatProduct> list = JSON.parseObject(jsonObject.getString("data"), new TypeReference<List<CatProduct>>() {
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ShoppingCart> getShoppingCart(Integer userId) throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
|
||||
//数据类型为json格式
|
||||
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
||||
//将对象转为JSON字符串
|
||||
String jsonStr = JSONObject.toJSONString(userId);
|
||||
RequestBody requestBody = RequestBody.create(jsonStr, mediaType);
|
||||
Request request = new Request.Builder()
|
||||
.url("http://10.21.120.101:8081/orange/shoppingcart/sharecropping")
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
System.out.println(response.isSuccessful());
|
||||
System.out.println(response.isSuccessful());
|
||||
String responseStr = response.body().string();
|
||||
JSONObject jsonObject = JSON.parseObject(Objects.requireNonNull(responseStr));
|
||||
List<ShoppingCart> list = JSON.parseObject(jsonObject.getString("data"), new TypeReference<List<ShoppingCart>>() {
|
||||
});
|
||||
System.out.println(list.get(0).getNum());
|
||||
System.out.println(list.get(0).getNum());
|
||||
System.out.println(list.get(0).getNum());
|
||||
System.out.println(list.get(0).getNum());
|
||||
System.out.println(list.get(0).getNum());
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片
|
||||
*
|
||||
* @param imgUrl
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public Bitmap getImageBitMap(String imgUrl) throws IOException {
|
||||
Bitmap bitmap;
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(imgUrl)
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
byte[] bytes = Objects.requireNonNull(response.body()).bytes();
|
||||
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||
return bitmap;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装信息
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
public List<CatProductPack> getProductPack(Integer userId) throws IOException {
|
||||
List<CatProductPack> packList = new ArrayList<>();
|
||||
List<CatProduct> list = getProduct(userId);
|
||||
|
||||
for (CatProduct catProduct : list) {
|
||||
CatProductPack catProductPack = new CatProductPack();
|
||||
catProductPack.setId(catProduct.getId());
|
||||
catProductPack.setName(catProduct.getName());
|
||||
catProductPack.setImgBitmap(getImageBitMap(catProduct.getImgUrl()));
|
||||
catProductPack.setAddTime(catProduct.getAddTime());
|
||||
catProductPack.setPrice(catProduct.getPrice());
|
||||
System.out.println(catProduct.getPrice());
|
||||
System.out.println(catProduct.getPrice());
|
||||
System.out.println(catProduct.getPrice());
|
||||
System.out.println(catProduct.getPrice());
|
||||
System.out.println(catProduct.getPrice());
|
||||
System.out.println(catProduct.getPrice());
|
||||
packList.add(catProductPack);
|
||||
}
|
||||
return packList;
|
||||
}
|
||||
|
||||
public List<ShoppingCartPack> getShoppingCartPack(Integer userId) throws IOException {
|
||||
List<ShoppingCartPack> packList = new ArrayList<>();
|
||||
List<ShoppingCart> list = getShoppingCart(userId);
|
||||
for (ShoppingCart catProduct : list) {
|
||||
ShoppingCartPack catProductPack = new ShoppingCartPack();
|
||||
catProductPack.setId(catProduct.getId());
|
||||
catProductPack.setUserId(catProduct.getUserId());
|
||||
catProductPack.setProductId(catProduct.getProductId());
|
||||
catProductPack.setNum(catProduct.getNum());
|
||||
packList.add(catProductPack);
|
||||
}
|
||||
return packList;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 186 B |
After Width: | Height: | Size: 877 B |
After Width: | Height: | Size: 240 B |
After Width: | Height: | Size: 811 B |
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#14FFEB3B"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/category_product_image"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="5dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/category_product_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30dp"
|
||||
android:layout_toRightOf="@+id/category_product_image"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="25dp"
|
||||
android:textColor="#050505"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/category_product_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30dp"
|
||||
android:layout_toRightOf="@+id/category_product_name"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="60dp"
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center"
|
||||
android:textColor="#050505"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/left"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:layout_marginTop="55dp"
|
||||
android:layout_toRightOf="@id/category_product_price"
|
||||
android:src="@drawable/left" />
|
||||
<TextView
|
||||
android:id="@+id/num"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_toRightOf="@+id/left"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="50dp"
|
||||
android:gravity="center"
|
||||
android:background="#00FEFEFE"
|
||||
android:textColor="#050505"
|
||||
android:textSize="16sp" />
|
||||
<ImageView
|
||||
android:id="@+id/right"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="50dp"
|
||||
android:layout_toRightOf="@id/num"
|
||||
android:src="@drawable/right" />
|
||||
|
||||
</RelativeLayout>
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "CatApp_android_frontEnd",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue