加载购物车

master
ghtMare 2 years ago
parent 6cd3b0cc22
commit 1abd6eb261

@ -56,7 +56,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<version>1.18.26</version>
</dependency>
<!--添加mybatis依赖-->
<dependency>

@ -44,6 +44,7 @@ public class CatProductController {
return map;
}
/**
*
*
@ -141,7 +142,7 @@ public class CatProductController {
file.transferTo(destFile);
}
map.put("flag", true);
map.put("data", "http://10.21.77.233:8081/uploaded/" + fileName);
map.put("data", "http://10.21.120.101:8081/uploaded/" + fileName);
return map;
} catch (Exception e) {
map.put("flag", false);

@ -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,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -62,13 +62,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
public void run() {
String username = usernameText.getText().toString();
String password = paswdEdit.getText().toString();
CatUser orangeUser = new CatUser();
orangeUser.setUsername(username);
orangeUser.setPassword(password);
CatUser catUser = new CatUser();
catUser.setUsername(username);
catUser.setPassword(password);
OkHttpUser okHttpUser = new OkHttpUser();
CatUser catUser1 = null;
try {
catUser1 = okHttpUser.userLogin(orangeUser);
catUser1 = okHttpUser.userLogin(catUser);
if (catUser1 != null) {
Intent intent1 = new Intent(MainActivity.this, IndexActivity.class);
Bundle bundle = new Bundle();
@ -76,6 +76,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
bundle.putString("password", catUser1.getPassword());
bundle.putString("city", catUser1.getCity());
bundle.putString("sex", catUser1.getSex());
bundle.putInt("id",catUser1.getId());
intent1.putExtras(bundle);
startActivity(intent1);
} else {

@ -98,7 +98,10 @@ public class IndexActivity extends Activity implements View.OnClickListener {
//开启事务fragment的控制是由事务来实现的
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (shoppingCartFragment == null) {
Intent intent = IndexActivity.this.getIntent();
Bundle bundle = intent.getExtras();
shoppingCartFragment = new ShoppingCartFragment();
shoppingCartFragment.setArguments(bundle);
}
transaction.replace(R.id.main_content0, shoppingCartFragment);
transaction.commit();

@ -136,6 +136,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
bundle.putString("password", password);
bundle.putString("sex", sexStr);
bundle.putString("city", city);
//add User
CatUser cateUser = new CatUser();
cateUser.setUsername(username);
cateUser.setPassword(password);

@ -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;
}
}

@ -26,12 +26,12 @@ public class ShoppingCart {
ProductId = productId;
}
public Integer getNumber() {
return number;
public Integer getNum() {
return num;
}
public void setNumber(Integer number) {
this.number = number;
public void setNum(Integer number) {
this.num = number;
}
private Integer id;
@ -40,5 +40,5 @@ public class ShoppingCart {
/**
*
*/
private Integer number;
private Integer 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;
}

@ -1,6 +1,7 @@
package com.example.catapp.fragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -32,6 +33,7 @@ public class IndexFragment extends Fragment implements View.OnClickListener {
private ProductAdapter productAdapter;
private List<Product> productList;
private List<CatProductPack> list = new ArrayList<>();
private ProductFragment productFragment;
@Nullable
@Override
@ -71,7 +73,17 @@ public class IndexFragment extends Fragment implements View.OnClickListener {
@Override
public void onClick(View v) {
// switch (v.getId()) {
// case R.id.index_famous_gridview:
// //开启事务fragment的控制是由事务来实现的
// FragmentTransaction transaction = getFragmentManager().beginTransaction();
// if (productFragment == null) {
// productFragment = new ProductFragment();
// }
// transaction.replace(R.id.main_content0, productFragment);
// transaction.commit();
// break;
// }
}
/**
@ -143,4 +155,5 @@ public class IndexFragment extends Fragment implements View.OnClickListener {
gridView.setAdapter(productAdapter);
}
}
}

@ -1,27 +1,37 @@
package com.example.catapp.fragment;
import android.app.Fragment;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.catapp.MainActivity;
import com.example.catapp.R;
import com.example.catapp.activity.IndexActivity;
import com.example.catapp.adapter.ListViewAdapter;
import com.example.catapp.adapter.ProductAdapter;
import com.example.catapp.entity.CatProductPack;
import com.example.catapp.entity.CatUser;
import com.example.catapp.entity.Condition;
import com.example.catapp.netrequest.OkHttpClientProduct;
import com.example.catapp.netrequest.OkHttpUser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.LogRecord;
public class ProductFragment extends Fragment {
private Spinner conditonListSpinner;
@ -29,12 +39,13 @@ public class ProductFragment extends Fragment {
private List<Condition> conditionList;
private GridView productGridView;
private List<CatProductPack> catProductList = new ArrayList<>();
Handler h=null;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_product, container, false);
init(view);
linkHttp();
return view;
}
@ -49,7 +60,8 @@ public class ProductFragment extends Fragment {
listViewAdapter = new ListViewAdapter(getActivity(), conditionList);
conditonListSpinner.setAdapter(listViewAdapter);
productGridView = view.findViewById(R.id.product_list);
new SearchProductTask().execute();
//new SearchProductTask().execute();
}
/**
@ -75,6 +87,36 @@ public class ProductFragment extends Fragment {
conditionList.add(priceCondition);
}
/**
*
*/
public void linkHttp(){
h =new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
ProductAdapter productAdapter = new ProductAdapter(getActivity(), catProductList);
System.out.println(catProductList.size());
System.out.println(catProductList.size());
productGridView.setAdapter(productAdapter);
}
};
new Thread(new Runnable() {
@Override
public void run() {
OkHttpClientProduct okHttpClientProduct=new OkHttpClientProduct();
try {
catProductList=okHttpClientProduct.getProductPack();
} catch (IOException e) {
throw new RuntimeException(e);
}
Message message=new Message();
h.sendMessage(message);
}
}).start();
}
/**
*
*/

@ -3,36 +3,54 @@ package com.example.catapp.fragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.catapp.R;
import com.example.catapp.adapter.ProductAdapter;
import com.example.catapp.adapter.ShoppingCartAdapter;
import com.example.catapp.entity.CatProductPack;
import com.example.catapp.entity.ShoppingCart;
import com.example.catapp.entity.ShoppingCartPack;
import com.example.catapp.netrequest.OkHttpClientProduct;
import com.example.catapp.netrequest.OkHttpShoppingcart;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ShoppingCartFragment extends Fragment implements View.OnClickListener {
private Button walkButton;
private List<ShoppingCart> cartList = new ArrayList<>();
private List<ShoppingCartPack> cartList = new ArrayList<>();
private ProductFragment productFragment;
private GridView productGridView;
private TextView usernameText;
private Integer userId=2;
private List<CatProductPack> catProductList= new ArrayList<>();
Handler h=null;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view;
if (cartList.size() > 0) {
//有商品
// if (cartList.size() > 0) {
// //有商品
view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_have_product, container, false);
} else {
view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_no_product, container, false);
}
// } else {
// view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_no_product, container, false);
// }
init(view);
check();
// if (cartList.size() > 0)
linkHttp();
return view;
}
@ -40,12 +58,25 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
*
*/
private void init(View view) {
walkButton = view.findViewById(R.id.random_search);
walkButton.setOnClickListener(this);
}
usernameText=view.findViewById(R.id.username);
productGridView = view.findViewById(R.id.cart_productList);
// walkButton = view.findViewById(R.id.random_search);
// walkButton.setOnClickListener(this);
//productGridView = view.findViewById(R.id.cart_productList);
setData();
}
private void setData() {
Bundle bundle = getArguments();
usernameText.setText(String.format("用户名:%s", bundle.getString("username")));
userId=(Integer)bundle.getInt("id");
System.out.println(userId);
}
@Override
public void onClick(View v) {
if (cartList.size() > 0) {}
else {
switch (v.getId()) {
case R.id.random_search:
//开启事务fragment的控制是由事务来实现的
@ -58,4 +89,53 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
break;
}
}
}
/**
*
*/
public void check(){
new Thread(new Runnable() {
@Override
public void run() {
OkHttpShoppingcart okHttpShoppingcart=new OkHttpShoppingcart();
try {
// catProductList= okHttpShoppingcart.getProductPack(userId);
System.out.println(cartList.size() );
cartList=okHttpShoppingcart.getShoppingCartPack(userId);
System.out.println(cartList.get(0).getNum());
System.out.println(cartList.size());
System.out.println(cartList.size());
System.out.println(cartList.size());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}).start();
}
public void linkHttp(){
h =new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
ShoppingCartAdapter shoppingCartAdapter = new ShoppingCartAdapter(getActivity(), catProductList,cartList);
productGridView.setAdapter(shoppingCartAdapter);
}
};
new Thread(new Runnable() {
@Override
public void run() {
OkHttpShoppingcart okHttpShoppingcart=new OkHttpShoppingcart();
try {
catProductList= okHttpShoppingcart.getProductPack(userId);
//cartList=okHttpShoppingcart.getShoppingCartPack(userId);
} catch (IOException e) {
throw new RuntimeException(e);
}
Message message=new Message();
h.sendMessage(message);
}
}).start();
}
}

@ -27,10 +27,12 @@ public class OkHttpClientProduct {
*/
public List<CatProduct> getProduct() throws IOException {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder()
.url("http://10.21.77.233:8081/orange/product/search")
.url("http://10.21.120.101:8081/orange/product/search")
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(Objects.requireNonNull(response.body()).string());
List<CatProduct> list = JSON.parseObject(jsonObject.getString("data"), new TypeReference<List<CatProduct>>() {
});
@ -70,6 +72,7 @@ public class OkHttpClientProduct {
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());

@ -22,7 +22,7 @@ public class OkHttpMessage {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder()
//.url("http://192.168.0.102:8081/orange/message/consumeMessage")
.url("http://10.21.77.233:8081/orange/message/consumeMessage")
.url("http://10.21.120.101:8081/orange/message/consumeMessage")
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(Objects.requireNonNull(response.body()).string());
@ -31,7 +31,7 @@ public class OkHttpMessage {
*
*/
Request request1 = new Request.Builder()
.url("http://10.21.77.233:8081/orange/message/updateMessage")
.url("http://10.21.120.101:8081/orange/message/updateMessage")
.build();
okHttpClient.newCall(request1).execute();
return orangeMessage;

@ -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;
}
}

@ -29,7 +29,7 @@ public class OkHttpUser {
RequestBody requestBody = RequestBody.create(jsonStr, mediaType);
Request request = new Request.Builder()
.url("http://10.21.77.233:8081/orange/user/login")
.url("http://10.21.120.101:8081/orange/user/login")
.post(requestBody)
.build();
@ -58,7 +58,7 @@ public class OkHttpUser {
String jsonStr = JSONObject.toJSONString(catUser);
RequestBody requestBody = RequestBody.create(jsonStr, mediaType);
Request request = new Request.Builder()
.url("http://10.21.77.233:8081/orange/user/register")
.url("http://10.21.120.101:8081/orange/user/register")
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute();

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 877 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

@ -1,22 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<ImageView
android:id="@+id/category_product_image"
android:layout_width="120dp"
android:layout_marginTop="5dp"
android:layout_height="120dp"
android:layout_gravity="center" />
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_marginTop="2dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="25dp"
android:textColor="#050505"
android:textSize="16sp" />
@ -24,9 +27,11 @@
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_marginTop="2dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="25dp"
android:gravity="center"
android:textColor="#050505"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>

@ -23,6 +23,6 @@
android:verticalSpacing="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:numColumns="2"/>
android:numColumns="1"/>
</LinearLayout>

@ -16,6 +16,7 @@
android:orientation="horizontal">
<TextView
android:id="@+id/hotproduct"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
@ -49,7 +50,7 @@
android:background="#E8E8E8"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="2" />
android:numColumns="1" />
</LinearLayout>

@ -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>

@ -17,7 +17,17 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/arrow_left" />
<TextView
android:id="@+id/username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:gravity="center"
android:text="shopping cart"
android:layout_marginRight="0dp"
android:textColor="#FFF"
android:textSize="20sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"

@ -0,0 +1,6 @@
{
"name": "CatApp_android_frontEnd",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save