Skip to content
Permalink
Browse files
update
  • Loading branch information
汪前 committed Apr 5, 2023
1 parent e45b4b5 commit 931c725667ac4ba1a77419fc78609862cad94576
Show file tree
Hide file tree
Showing 23 changed files with 161 additions and 78 deletions.
@@ -1,8 +1,6 @@
package com.example.secondhandsneakerseller.controller;

import com.example.pojo.Item;
import com.example.pojo.Result;
import com.example.pojo.Type;
import com.example.pojo.*;
import com.example.secondhandsneakerseller.config.MQProducerService;
import com.example.secondhandsneakerseller.mapper.SaveMapper;
import com.example.secondhandsneakerseller.pages.PageParams;
@@ -28,7 +26,7 @@ public class ItemController {
private ItemSaveImpl itemSave;

@PostMapping("/InsertItems")
public Result<Long,String,String> SaveItems(@RequestBody @Validated Type type ){
public Result<Long,String,String> SaveItems(@RequestBody @Validated TypeBit type ){

Long res=itemSave.Save(type);

@@ -39,33 +37,33 @@ public class ItemController {
}
}
@GetMapping("/AllItems/{page}")
public Result<Integer, Integer, List<Item>> selectAllItems(@PathVariable("page") int page){
public Result<Integer, Integer, List<ItemBit>> selectAllItems(@PathVariable("page") int page){
return itemSave.SelectItem(page);
}
@GetMapping("/AllType/{page}")
public Result<Integer, Integer,List<Type>> selectAllTypes(@PathVariable("page")int page){
public Result<Integer, Integer,List<TypeBit>> selectAllTypes(@PathVariable("page")int page){
return itemSave.SelectType(page);
}
@GetMapping("/SelectBySeller/{id}/{page}")
public Result<Integer,Integer,List<Item>> selectBySeller(@PathVariable("id")Integer id,@PathVariable("page")Integer page){
public Result<Integer,Integer,List<ItemBit>> selectBySeller(@PathVariable("id")Integer id, @PathVariable("page")Integer page){
return itemSave.selectBySellerId(id,page);
}
//0: typeId
//1: sellerId
@GetMapping("/SelectByType/{typeId}")
public List<Item> selectByType(@PathVariable("typeId")Integer typeId){
public List<ItemBit> selectByType(@PathVariable("typeId")Integer typeId){

return saveMapper.selectItemByType(typeId);

}
@Autowired
RestTemplate restTemplate;
@GetMapping("/OneType/{id}")
public Type selectOneType (@PathVariable("id")Long id){
public TypeBit selectOneType (@PathVariable("id")Long id){
return itemSave.SelectOneType(id);
}
@GetMapping("/OneItem/{id}")
public Item selectOneItem(@PathVariable("id")Long id){
public ItemBit selectOneItem(@PathVariable("id")Long id){
return itemSave.SelectOneItem(id);
}
@GetMapping("/SearchItem/{title}/{page}")
@@ -77,11 +75,11 @@ public class ItemController {
@Autowired
private SaveMapper saveMapper;
@GetMapping("/SelectSellerHistory/{sellerid}/{page}")
public Result<Integer,Integer,List<Item>> SelectHistory(@PathVariable("sellerid")Long sellerid,@PathVariable("page")Integer page){
public Result<Integer,Integer,List<ItemBit>> SelectHistory(@PathVariable("sellerid")Long sellerid,@PathVariable("page")Integer page){
PageParams pageParam=new PageParams();
pageParam.setPage(page);
pageParam.setPageSize(4);
List<Item> listitem= saveMapper.selectByHistory(sellerid,pageParam);
List<ItemBit> listitem= saveMapper.selectByHistory(sellerid,pageParam);
return new Result<>(page,pageParam.getTotalPage(),listitem);
}

@@ -1,7 +1,9 @@
package com.example.secondhandsneakerseller.mapper;

import com.example.pojo.Item;
import com.example.pojo.ItemBit;
import com.example.pojo.Type;
import com.example.pojo.TypeBit;
import com.example.secondhandsneakerseller.pages.PageParams;
import com.example.secondhandsneakerseller.pages.PageParams;
import freemarker.ext.beans.IteratorModel;
@@ -15,15 +17,15 @@ public interface SaveMapper {
@Insert("insert into item(name,des,count,price,type,sellerid,pic) values(#{Item.name},#{Item.des},#{Item.count},#{Item.price}," +
"#{Type},#{Item.sellerid},#{Item.pic})")
@Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "Item.id")
public int InsertGoods(@Param("Item")Item item,@Param("Type")Long id);
public int InsertGoods(@Param("Item") ItemBit item, @Param("Type")Long id);
@Insert("insert into type(typename,pic) values(#{type.typename},#{type.pic})")
@Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "type.id")
public int InsertType(@Param("type")Type type);
public int InsertType(@Param("type")TypeBit type);
@Select("select * from item where id=#{id}")
public Item selectOneItem(@Param("id")Long id);
public ItemBit selectOneItem(@Param("id")Long id);

@Select("select * from item where type=#{type} and count>0")
public List<Item> selectItemByType(@Param("type")Integer sellerid);
public List<ItemBit> selectItemByType(@Param("type")Integer sellerid);
// @Select("select * from item where type=#{type}")
// public List<Item> selectTypeItem(@Param(""))
@Select("select * from type where id=#{id}")
@@ -35,19 +37,19 @@ public interface SaveMapper {
many = @Many(select = "com.example.secondhandsneakerseller.mapper.SaveMapper.selectItemByType")
)
})
public Type selectOneType(@Param("id")Long id);
public TypeBit selectOneType(@Param("id")Long id);
@Select("select * from item where count>0")
public List<Item> selectAllItem(PageParams pageParam);
public List<ItemBit> selectAllItem(PageParams pageParam);
@Select("select * from item where item.sellerid=#{id} and count>0")
public List<Item> selectBySellerId(@Param("id")int id,PageParams pageParams);
public List<ItemBit> selectBySellerId(@Param("id")int id,PageParams pageParams);
@Select("select * from type")
@Results({
@Result(id = true,property = "id",column = "id"),
@Result(property = "items",column = "id",
many = @Many(select = "com.example.secondhandsneakerseller.mapper.SaveMapper.selectItemByType")
)
})
public List<Type> selectAllType(PageParams pageParam);
public List<TypeBit> selectAllType(PageParams pageParam);
@Select("select id,typename from type where typename=#{typename}")
@Results({
@Result(id = true,property = "id",column = "id"),
@@ -57,9 +59,9 @@ public interface SaveMapper {
many = @Many(select = "com.example.secondhandsneakerseller.mapper.SaveMapper.selectItemByType")
)
})
public List<Type> selectByName(@Param("typename")String name);
public List<TypeBit> selectByName(@Param("typename")String name);


@Select("select * from item where item.id in (select itemid from shophistory where userid=#{userid})")
public List<Item> selectByHistory(@Param("userid")Long userid,PageParams pageParams);
public List<ItemBit> selectByHistory(@Param("userid")Long userid,PageParams pageParams);
}
@@ -1,15 +1,14 @@
package com.example.secondhandsneakerseller.serviceImpl;

import com.example.pojo.Item;
import com.example.pojo.Result;
import com.example.pojo.Type;
import com.example.pojo.*;
import com.example.secondhandsneakerseller.config.MQProducerService;
import com.example.secondhandsneakerseller.mapper.SaveMapper;

import com.example.secondhandsneakerseller.pages.PageParams;
import com.example.service.analizeservice.sellerservice.ItemSave;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
@@ -19,6 +18,8 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED)
@@ -30,6 +31,31 @@ public class ItemSaveImpl implements ItemSave {

@Autowired
private MQProducerService mqProducerService;
// public static byte[] getContent(String filePath) throws IOException {
// File file = new File(filePath);
// long fileSize = file.length();
// if (fileSize > Integer.MAX_VALUE) {
//
// return null;
// }
// FileInputStream fi = new FileInputStream(file);
// byte[] buffer = new byte[(int) fileSize];
// int offset = 0;
// int numRead = 0;
// while (offset < buffer.length
// && (numRead = fi.read(buffer, offset, buffer.length - offset)) >= 0) {
// offset += numRead;
// }
// // 确保所有数据均被读取
// if (offset != buffer.length) {
// throw new IOException("Could not completely read file "
// + file.getName());
// }
// fi.close();
// return buffer;
// }


@Override

@CachePut(cacheNames = "type",key = "#type.typename")
@@ -39,9 +65,15 @@ public class ItemSaveImpl implements ItemSave {
// threadPoolKey = "Saves",
// fallbackMethod = "fallback1"
// )
public Long Save(Type type) {
System.out.println("enter this");
List<Type> type1=saveMapper.selectByName(type.getTypename());


public Long Save(TypeBit type) {
byte [] bytes=null;




List<TypeBit> type1=saveMapper.selectByName(type.getTypename());
System.out.println("enter this");
if (type1.size()==0){
if (type.getItems()==null || type.getItems().size()==0){
@@ -62,9 +94,12 @@ public class ItemSaveImpl implements ItemSave {
}
}else {
Long id=type1.get(0).getId();
for (Item item: type.getItems()

for (ItemBit item: type.getItems()
) {
// mqProducerService.sendItems(item);


saveMapper.InsertGoods(item,id);
}

@@ -79,11 +114,11 @@ public class ItemSaveImpl implements ItemSave {
// threadPoolKey = "SelectTypes",
// fallbackMethod = "fallback2"
// )
public Result<Integer, Integer, List<Type>> SelectType(int page) {
public Result<Integer, Integer, List<TypeBit>> SelectType(int page) {
PageParams pageParam=new PageParams();
pageParam.setPage(page);
pageParam.setPageSize(4);
List<Type> typeList=saveMapper.selectAllType(pageParam);
List<TypeBit> typeList=saveMapper.selectAllType(pageParam);

return new Result<>(page,pageParam.getTotalPage(),typeList);
}
@@ -95,19 +130,19 @@ public class ItemSaveImpl implements ItemSave {
// threadPoolKey = "SelectItems",
// fallbackMethod = "fallback3"
// )
public Result<Integer, Integer, List<Item>> SelectItem(int page) {
public Result<Integer, Integer, List<ItemBit>> SelectItem(int page) {
PageParams pageParam=new PageParams();
pageParam.setPage(page);
pageParam.setPageSize(4);
List<Item> itemList=saveMapper.selectAllItem(pageParam);
List<ItemBit> itemList=saveMapper.selectAllItem(pageParam);
return new Result<>(page,pageParam.getTotalPage(),itemList);
}
@Cacheable(cacheNames = "items",key = "#id")
public Result<Integer,Integer,List< Item>> selectBySellerId(int id,int page){
public Result<Integer,Integer,List< ItemBit>> selectBySellerId(int id,int page){
PageParams pageParam=new PageParams();
pageParam.setPage(page);
pageParam.setPageSize(4);
List<Item> itemList=saveMapper.selectBySellerId(id,pageParam);
List<ItemBit> itemList=saveMapper.selectBySellerId(id,pageParam);
return new Result<>(page,pageParam.getTotalPage(),itemList);
}
@Override
@@ -118,7 +153,7 @@ public class ItemSaveImpl implements ItemSave {
// threadPoolKey = "SelectOneTypes",
// fallbackMethod = "fallback4"
// )
public Type SelectOneType(Long id) {
public TypeBit SelectOneType(Long id) {
return saveMapper.selectOneType(id);
}

@@ -130,7 +165,7 @@ public class ItemSaveImpl implements ItemSave {
// threadPoolKey = "SelectOneItems",
// fallbackMethod = "fallback5"
// )
public Item SelectOneItem(Long id) {
public ItemBit SelectOneItem(Long id) {
return saveMapper.selectOneItem(id);
}
public int fallback1(Type type,Throwable throwable){
@@ -1,6 +1,7 @@
package com.example.secondhandsneakerseller.serviceImpl;

import com.example.pojo.Item;
import com.example.pojo.ItemBit;
import com.example.pojo.Type;
import com.example.secondhandsneakerseller.mapper.SaveMapper;
import com.example.secondhandsneakerseller.mapper.UpdateMapper;
@@ -27,7 +28,7 @@ public class SellingServiceImpl implements SellingService {
// )
public int updateItem(@PathVariable("id") Long id) {
int res= updateMapper.updateItem(id);
Item item=saveMapper.selectOneItem(id);
ItemBit item=saveMapper.selectOneItem(id);
int re=updateMapper.insertHistory(item.getSellerid(),item.getId());
try {
if (item.getCount() <= 0) {
@@ -15,5 +15,5 @@ public class History implements Serializable {
private Long id;
private Long userid;
private Long itemid;
private Item item;
private ItemBit item;
}
@@ -0,0 +1,26 @@
package com.example.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "itemBit")
public class ItemBit implements Serializable {
@Id
private Long id;
@NotNull
private String name;
private String des;
private Long count;
private byte[] pic;
private Float price;
private Long sellerid;
}
@@ -0,0 +1,20 @@
package com.example.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TypeBit implements Serializable {
private Long id;
@NotNull
private String typename;
private byte[] pic;
private List<ItemBit> items;
}
@@ -2,12 +2,13 @@ package com.example.service.analizeservice;

import com.example.pojo.InsertItems;
import com.example.pojo.Item;
import com.example.pojo.ItemBit;
import com.example.pojo.Result;

import java.sql.SQLException;
import java.util.List;

public interface SearchService {
public InsertItems InsertItems(Item item) throws SQLException;
public List<Item> SelectItem(String stynx );
public List<ItemBit> SelectItem(String stynx );
}
@@ -1,15 +1,13 @@
package com.example.service.analizeservice.sellerservice;

import com.example.pojo.Item;
import com.example.pojo.Result;
import com.example.pojo.Type;
import com.example.pojo.*;

import java.util.List;

public interface ItemSave {
public Long Save(Type type);
public Result<Integer,Integer, List<Type>> SelectType(int page);
public Result<Integer,Integer,List<Item>> SelectItem(int page);
public Type SelectOneType(Long id);
public Item SelectOneItem(Long id);
public Long Save(TypeBit type);
public Result<Integer,Integer, List<TypeBit>> SelectType(int page);
public Result<Integer,Integer,List<ItemBit>> SelectItem(int page);
public TypeBit SelectOneType(Long id);
public ItemBit SelectOneItem(Long id);
}

0 comments on commit 931c725

Please sign in to comment.