Commit 2a24fb92 authored by 覃振观's avatar 覃振观 👶

Product 查询

parent 27d11442
package com.huigou.topsun.config;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
* JPAUtils 用于管理 JPA EntityManager 创建工厂
*
* @author qinzhenguan
* @create 2023/11/28 08:58
**/
public class JPAUtils {
public static EntityManagerFactory emf = createEntityManagerFactory();
private static EntityManagerFactory createEntityManagerFactory() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("mysql-jpa");
return emf;
}
public static EntityManager getEntityManger(){
EntityManager entityManager = emf.createEntityManager();
return entityManager;
}
}
\ No newline at end of file
package com.huigou.topsun.product.application; package com.huigou.topsun.product.application;
import com.huigou.topsun.product.domain.Brand;
import java.util.ArrayList;
import java.util.Map;
/** /**
* @author 16508 * @author 16508
* @description 针对表【brand(品牌)】的数据库操作Service * @description 针对表【brand(品牌)】的数据库操作Service
...@@ -8,4 +13,8 @@ package com.huigou.topsun.product.application; ...@@ -8,4 +13,8 @@ package com.huigou.topsun.product.application;
*/ */
public interface BrandApplication { public interface BrandApplication {
Map<String, Object> querySelectableInFactoryName();
ArrayList<Brand> findAll();
} }
package com.huigou.topsun.product.application; package com.huigou.topsun.product.application;
import com.huigou.topsun.product.domain.Product;
import org.springframework.data.domain.Page;
import java.util.Map;
/** /**
* @author 16508 * @author 16508
* @description 针对表【product(产品)】的数据库操作Service * @description 针对表【product(产品)】的数据库操作Service
* @createDate 2023-11-22 10:24:31 * @createDate 2023-11-22 10:24:31
*/ */
public interface ProductApplication { public interface ProductApplication {
/**
* description 查询产品列表
* @param page 当前页
* @param size 页大小
* @return org.springframework.data.domain.Page<com.huigou.topsun.product.domain.Product>
* @author qinzhenguan
* @create: 2023/11/29 9:34
*/
Page<Product> findProductPage(int page, int size);
/**
* description 获取产品所有信息
* @param productId 产品ID
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author qinzhenguan
* @create: 2023/11/29 9:33
*/
Map<String, Object> queryDetailAll(int productId);
} }
package com.huigou.topsun.product.application.impl; package com.huigou.topsun.product.application.impl;
import com.huigou.topsun.product.application.BrandApplication; import com.huigou.topsun.product.application.BrandApplication;
import com.huigou.topsun.product.domain.Brand;
import com.huigou.topsun.product.repository.BrandRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author 16508 * @author 16508
* @description 针对表【brand(品牌)】的数据库操作Service实现 * @description 针对表【brand(品牌)】的数据库操作Service实现
...@@ -11,6 +19,25 @@ import org.springframework.stereotype.Service; ...@@ -11,6 +19,25 @@ import org.springframework.stereotype.Service;
@Service @Service
public class BrandApplicationImpl implements BrandApplication { public class BrandApplicationImpl implements BrandApplication {
@Autowired
private BrandRepository brandRepository;
@Override
public Map<String, Object> querySelectableInFactoryName() {
ArrayList<Brand> brands = this.findAll();
Map<String, Brand> map = brands.stream().collect(Collectors.toMap(Brand::getBrandName, (b) -> b));
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("map", map);
resultMap.put("list", brands);
return resultMap;
}
@Override
public ArrayList<Brand> findAll() {
return (ArrayList<Brand>) brandRepository.findAll();
}
} }
......
package com.huigou.topsun.product.controller;
import com.huigou.topsun.product.domain.Product;
import com.huigou.topsun.product.application.ProductApplication;
import org.springframework.data.domain.Page;
import com.huigou.uasp.annotation.ControllerMapping;
import com.huigou.uasp.client.CommonController;
import com.huigou.util.SDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.util.Map;
/**
* ProductController
*
* @author qinzhenguan
* @date 2023/11/27 11:19
**/
@Controller
@ControllerMapping("/product")
public class ProductController extends CommonController {
@Autowired
private ProductApplication productService;
/**
* description
* @author qinzhenguan
* @date 2023/11/27 11:49
* @return null
*/
public String findProduct() {//需要特定返回值
SDO sdo = this.getSDO();
int page = sdo.getInteger("page");
int size = sdo.getInteger("size");
Page<Product> productPage = productService.findProductPage(page, size);
return toResult(productPage);
}
public String queryDetailAll() {
SDO sdo = this.getSDO();
int productId = sdo.getInteger("productId");
Map<String, Object> map = productService.queryDetailAll(productId);
return toResult(map);
}
}
\ No newline at end of file
...@@ -54,13 +54,13 @@ public class ProductDetail implements Serializable { ...@@ -54,13 +54,13 @@ public class ProductDetail implements Serializable {
* 产品背面ID * 产品背面ID
*/ */
@Column(name = "back_product_face_id") @Column(name = "back_product_face_id")
private Long backProductFaceId; private String backProductFaceId;
/** /**
* 产品正面ID * 产品正面ID
*/ */
@Column(name = "right_product_face_id") @Column(name = "right_product_face_id")
private Long rightProductFaceId; private String rightProductFaceId;
/** /**
* 产品承印物 * 产品承印物
......
...@@ -4,7 +4,6 @@ import java.io.Serializable; ...@@ -4,7 +4,6 @@ import java.io.Serializable;
import javax.persistence.*; import javax.persistence.*;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
/** /**
* 产品外观 * 产品外观
...@@ -18,13 +17,7 @@ public class ProductLooked implements Serializable { ...@@ -18,13 +17,7 @@ public class ProductLooked implements Serializable {
* 产品外观ID * 产品外观ID
*/ */
@Id @Id
@GeneratedValue( // @GeneratedValue(strategy = GenerationType.IDENTITY) // 使用自增策略
generator = "system-uuid"
)
@GenericGenerator(
name = "system-uuid",
strategy = "guid"
)
@Column(name = "product_looked_id") @Column(name = "product_looked_id")
private String productLookedId; private String productLookedId;
......
...@@ -35,7 +35,7 @@ public class ProductLoss implements Serializable { ...@@ -35,7 +35,7 @@ public class ProductLoss implements Serializable {
/** /**
* loss比率(单位%) * loss比率(单位%)
*/ */
@Column(name = "product_loss_ rate") @Column(name = "product_loss_rate")
private Double productLossRate; private Double productLossRate;
/** /**
......
...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductDetailRepository extends JpaRepository<ProductDetail,String> { public interface ProductDetailRepository extends JpaRepository<ProductDetail,String> {
ProductDetail findByProductIdEquals(Long productId);
} }
...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductFaceColorRepository extends JpaRepository<ProductFaceColor,String> { public interface ProductFaceColorRepository extends JpaRepository<ProductFaceColor,String> {
ProductFaceColor findByProductFaceIdEquals(String productFaceId);
} }
...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductFaceRepository extends JpaRepository<ProductFace,String> { public interface ProductFaceRepository extends JpaRepository<ProductFace,String> {
ProductFace findByProductFaceIdEquals(String productFaceId);
} }
...@@ -4,11 +4,15 @@ import com.huigou.topsun.product.domain.ProductLooked; ...@@ -4,11 +4,15 @@ import com.huigou.topsun.product.domain.ProductLooked;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
/** /**
* @author qinzhenguan
* @Auther: xin.lu * @Auther: xin.lu
* @Date: 2023/11/22/10:42 * @Date: 2023/11/22/10:42
* @Description: * @Description:
*/ */
public interface ProductLookedRepository extends JpaRepository<ProductLooked,String> { public interface ProductLookedRepository extends JpaRepository<ProductLooked,String> {
ProductLooked findByProductId(String productId);
ProductLooked findByProductIdEquals(String productId);
ProductLooked getProductLookedByProductId(String productId); ProductLooked getProductLookedByProductId(String productId);
} }
...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductLossRepository extends JpaRepository<ProductLoss,String> { public interface ProductLossRepository extends JpaRepository<ProductLoss,String> {
ProductLoss findByProductIdEquals(String productId);
} }
...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductMaterialRepository extends JpaRepository<ProductMaterial,String> { public interface ProductMaterialRepository extends JpaRepository<ProductMaterial,String> {
ProductMaterial findByProductIdEquals(String productId);
} }
...@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductPublishedConfRepository extends JpaRepository<ProductPublishedConf,String> { public interface ProductPublishedConfRepository extends JpaRepository<ProductPublishedConf,String> {
ProductPublishedConf findByProductIdEquals(String productId);
ProductPublishedConf getProductPublishedConfByProductId(String productId); ProductPublishedConf getProductPublishedConfByProductId(String productId);
} }
...@@ -2,11 +2,13 @@ package com.huigou.topsun.product.repository; ...@@ -2,11 +2,13 @@ package com.huigou.topsun.product.repository;
import com.huigou.topsun.product.domain.Product; import com.huigou.topsun.product.domain.Product;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/** /**
* @Auther: xin.lu * @author: xin.lu
* @Date: 2023/11/22/10:40 * @Date: 2023/11/22/10:40
* @Description: * @Description:
*/ */
@Repository
public interface ProductRepository extends JpaRepository<Product,String> { public interface ProductRepository extends JpaRepository<Product,String> {
} }
...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductTypesetConfRepository extends JpaRepository<ProductTypesetConf,String> { public interface ProductTypesetConfRepository extends JpaRepository<ProductTypesetConf,String> {
ProductTypesetConf findByProductIdEquals(String productId);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment