diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/MaterialInfo.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/MaterialInfo.java index f86f1daf..55fe3cc0 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/MaterialInfo.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/MaterialInfo.java @@ -23,11 +23,11 @@ public class MaterialInfo implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") - private long id; + private Long id; // 所属物料分类主键 @Column(name = "material_category_id",nullable = false) - private long materialCategoryId; + private Long materialCategoryId; // 物料分类名称 @Column(name = "material_category_name",nullable = false) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java index d42932e7..4dc5502a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java @@ -4,6 +4,7 @@ import lombok.Data; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import javax.persistence.*; +import javax.validation.constraints.NotNull; import java.sql.Timestamp; import java.io.Serializable; @@ -20,11 +21,11 @@ public class ProductInfo implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") - private Integer id; + private long id; // 所属产品分类 @Column(name = "product_category_id",nullable = false) - private Integer productCategoryId; + private long productCategoryId; // 产品分类名称 @Column(name = "product_category_name",nullable = false) @@ -44,7 +45,7 @@ public class ProductInfo implements Serializable { // 所属计量单位主键 @Column(name = "measure_unit_id") - private Integer measureUnitId; + private long measureUnitId; // 所属计量单位名称 @Column(name = "measure_unit_name") @@ -52,7 +53,7 @@ public class ProductInfo implements Serializable { // 产品单价(保留两位小数) 单位:元 @Column(name = "unit_price") - private Integer unitPrice; + private Long unitPrice; // 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}] @Column(name = "product_inventory_warning") @@ -73,6 +74,9 @@ public class ProductInfo implements Serializable { @Column(name = "update_time") private Timestamp updateTime; + @NotNull + private Boolean status; + public void copy(ProductInfo source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/repository/ProductInfoRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/repository/ProductInfoRepository.java index 44440ca8..a50a0938 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/repository/ProductInfoRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/repository/ProductInfoRepository.java @@ -3,10 +3,27 @@ package me.zhengjie.modules.wms.bd.repository; import me.zhengjie.modules.wms.bd.domain.ProductInfo; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; /** * @author 黄星星 * @date 2019-07-27 */ -public interface ProductInfoRepository extends JpaRepository, JpaSpecificationExecutor { +public interface ProductInfoRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 根据转查询状态正常的产品资料 + * @param id + * @return + */ + ProductInfo findByIdAndStatusTrue(long id); + + /** + * 删除产品资料 + * @param id + */ + @Modifying + @Query(value = "update bd_product_info set status = 0 where id = ?1",nativeQuery = true) + void deleteProductInfo(long id); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/MaterialInfoController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/MaterialInfoController.java index bb5fd48a..9fe35875 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/MaterialInfoController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/MaterialInfoController.java @@ -17,7 +17,7 @@ import io.swagger.annotations.*; * @author 黄星星 * @date 2019-07-27 */ -@Api(tags = "BdMaterialInfo管理") +@Api(tags = "物料资料管理") @RestController @RequestMapping("api") public class MaterialInfoController { @@ -25,18 +25,23 @@ public class MaterialInfoController { @Autowired private MaterialInfoService materialInfoService; - @Log("查询物料资料") - @ApiOperation(value = "查询物料资料") + @Log("分页查询物料资料") + @ApiOperation(value = "分页查询物料资料") @GetMapping(value = "/materialInfo") - @PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_SELECT')") public ResponseEntity getBdMaterialInfos(MaterialInfoQueryCriteria criteria, Pageable pageable){ return new ResponseEntity(materialInfoService.queryAll(criteria,pageable),HttpStatus.OK); } + @Log("查询所有物料资料") + @ApiOperation(value = "查询所有物料资料") + @GetMapping(value = "/queryMaterialInfoList") + public ResponseEntity queryMaterialInfoList(MaterialInfoQueryCriteria criteria){ + return new ResponseEntity(materialInfoService.queryAll(criteria),HttpStatus.OK); + } + @Log("新增物料资料") @ApiOperation(value = "新增物料资料") @PostMapping(value = "/materialInfo") - @PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_CREATE')") public ResponseEntity create(@Validated @RequestBody MaterialInfo resources){ return new ResponseEntity(materialInfoService.create(resources),HttpStatus.CREATED); } @@ -44,7 +49,6 @@ public class MaterialInfoController { @Log("修改物料资料") @ApiOperation(value = "修改物料资料") @PutMapping(value = "/materialInfo") - @PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_EDIT')") public ResponseEntity update(@Validated @RequestBody MaterialInfo resources){ materialInfoService.update(resources); return new ResponseEntity(HttpStatus.NO_CONTENT); @@ -53,7 +57,6 @@ public class MaterialInfoController { @Log("删除物料资料") @ApiOperation(value = "删除物料资料") @DeleteMapping(value = "/materialInfo/{id}") - @PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_DELETE')") public ResponseEntity delete(@PathVariable Integer id){ materialInfoService.delete(id); return new ResponseEntity(HttpStatus.OK); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java index d31ab56a..93f36013 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java @@ -17,7 +17,7 @@ import io.swagger.annotations.*; * @author 黄星星 * @date 2019-07-27 */ -@Api(tags = "BdProductInfo管理") +@Api(tags = "产品资料管理") @RestController @RequestMapping("api") public class ProductInfoController { @@ -25,34 +25,41 @@ public class ProductInfoController { @Autowired private ProductInfoService productInfoService; - @Log("查询BdProductInfo") - @ApiOperation(value = "查询BdProductInfo") - @GetMapping(value = "/bdProductInfo") + @Log("分页查询产品资料") + @ApiOperation(value = "分页查询产品资料") + @GetMapping(value = "/productInfo") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_SELECT')") - public ResponseEntity getBdProductInfos(ProductInfoQueryCriteria criteria, Pageable pageable){ + public ResponseEntity getProductInfos(ProductInfoQueryCriteria criteria, Pageable pageable){ return new ResponseEntity(productInfoService.queryAll(criteria,pageable),HttpStatus.OK); } - @Log("新增BdProductInfo") - @ApiOperation(value = "新增BdProductInfo") - @PostMapping(value = "/bdProductInfo") + @Log("查询产品资料列表") + @ApiOperation(value = "查询产品资料列表") + @GetMapping(value = "/productInfo/all") + public ResponseEntity queryProductInfoList(ProductInfoQueryCriteria criteria){ + return new ResponseEntity(productInfoService.queryAll(criteria),HttpStatus.OK); + } + + @Log("新增产品资料") + @ApiOperation(value = "新增产品资料") + @PostMapping(value = "/productInfo") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_CREATE')") public ResponseEntity create(@Validated @RequestBody ProductInfo resources){ return new ResponseEntity(productInfoService.create(resources),HttpStatus.CREATED); } - @Log("修改BdProductInfo") - @ApiOperation(value = "修改BdProductInfo") - @PutMapping(value = "/bdProductInfo") + @Log("修改产品资料") + @ApiOperation(value = "修改产品资料") + @PutMapping(value = "/productInfo") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_EDIT')") public ResponseEntity update(@Validated @RequestBody ProductInfo resources){ productInfoService.update(resources); return new ResponseEntity(HttpStatus.NO_CONTENT); } - @Log("删除BdProductInfo") - @ApiOperation(value = "删除BdProductInfo") - @DeleteMapping(value = "/bdProductInfo/{id}") + @Log("删除产品资料") + @ApiOperation(value = "删除产品资料") + @DeleteMapping(value = "/productInfo/{id}") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_DELETE')") public ResponseEntity delete(@PathVariable Integer id){ productInfoService.delete(id); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/WareHouseController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/WareHouseController.java index a9b60afd..7fba14e0 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/WareHouseController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/WareHouseController.java @@ -49,13 +49,13 @@ public class WareHouseController { } @Log("分页查询仓库") - @GetMapping(value = "/wareHouse") + @GetMapping(value = "/wareHouses") public ResponseEntity getWareHouses(WareHouseQueryCriteria wareHouseQueryCriteria, Pageable pageable){ return new ResponseEntity(wareHouseService.queryAll(wareHouseQueryCriteria,pageable),HttpStatus.OK); } @Log("查询仓库列表") - @GetMapping(value = "/wareHouse/all") + @GetMapping(value = "/queryWareHouseList") public ResponseEntity queryWareHouseList(WareHouseQueryCriteria wareHouseQueryCriteria){ return new ResponseEntity(wareHouseService.queryAll(wareHouseQueryCriteria),HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java index 462efa0c..4fed9a69 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java @@ -38,7 +38,7 @@ public interface ProductInfoService { * @return */ //@Cacheable(key = "#p0") - ProductInfoDTO findById(Integer id); + ProductInfoDTO findById(Long id); /** * create diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoDTO.java index 75ad69d6..f0fbd20e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoDTO.java @@ -13,10 +13,10 @@ import java.io.Serializable; public class MaterialInfoDTO implements Serializable { // 主键 - private Integer id; + private Long id; // 所属物料分类主键 - private Integer materialCategoryId; + private Long materialCategoryId; // 物料分类名称 private String materialCategoryName; @@ -28,7 +28,7 @@ public class MaterialInfoDTO implements Serializable { private String specifications; // 所属计量单位主键 - private Integer measureUnitId; + private Long measureUnitId; // 所属计量单位名称 private String measureUnitName; @@ -41,7 +41,7 @@ public class MaterialInfoDTO implements Serializable { // 物料期初合计期初总价格 - private Integer materialInitialSetupTotalPrice; + private Long materialInitialSetupTotalPrice; // 物料期初合计总数量 private String materialInitialSetupTotalNumber; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoQueryCriteria.java index b56759e5..16e83327 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/MaterialInfoQueryCriteria.java @@ -19,4 +19,6 @@ public class MaterialInfoQueryCriteria { private Long materialCategoryId; + private Boolean status; + } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java index a07fdef5..2ce68fec 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java @@ -13,10 +13,10 @@ import java.io.Serializable; public class ProductInfoDTO implements Serializable { // 主键 - private Integer id; + private long id; // 所属产品分类 - private Integer productCategoryId; + private long productCategoryId; // 产品分类名称 private String productCategoryName; @@ -31,13 +31,13 @@ public class ProductInfoDTO implements Serializable { private String specifications; // 所属计量单位主键 - private Integer measureUnitId; + private long measureUnitId; // 所属计量单位名称 private String measureUnitName; // 产品单价(保留两位小数) 单位:元 - private Integer unitPrice; + private long unitPrice; // 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}] private String productInventoryWarning; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/MaterialInfoServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/MaterialInfoServiceImpl.java index 4e00b1a6..ac11b7a4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/MaterialInfoServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/MaterialInfoServiceImpl.java @@ -29,10 +29,7 @@ import me.zhengjie.utils.QueryHelp; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; +import javax.persistence.criteria.*; /** * @author 黄星星 @@ -83,7 +80,6 @@ public class MaterialInfoServiceImpl implements MaterialInfoService { } - Predicate materialCategoryIdPredicate = null; Long materialCategoryId = criteria.getMaterialCategoryId(); if (null != materialCategoryId) { @@ -91,6 +87,8 @@ public class MaterialInfoServiceImpl implements MaterialInfoService { targetPredicateList.add(materialCategoryIdPredicate); } + Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1); + targetPredicateList.add(statusPredicate); if(CollectionUtils.isEmpty(targetPredicateList)){ return null; @@ -106,7 +104,24 @@ public class MaterialInfoServiceImpl implements MaterialInfoService { @Override public Object queryAll(MaterialInfoQueryCriteria criteria) { - return materialInfoMapper.toDto(materialInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); + Specification specification = new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { + + List targetPredicateList = new ArrayList<>(); + + Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1); + targetPredicateList.add(statusPredicate); + + if(CollectionUtils.isEmpty(targetPredicateList)){ + return null; + }else{ + return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()])); + } + } + }; + List materialInfoList = materialInfoRepository.findAll(specification); + return materialInfoMapper.toDto(materialInfoList); } @Override diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java index 28233fbf..e7f35b7a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java @@ -1,5 +1,7 @@ package me.zhengjie.modules.wms.bd.service.impl; +import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.wms.bd.domain.MaterialInfo; import me.zhengjie.modules.wms.bd.domain.ProductInfo; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.modules.wms.bd.repository.ProductInfoRepository; @@ -8,14 +10,24 @@ import me.zhengjie.modules.wms.bd.service.dto.ProductInfoDTO; import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria; import me.zhengjie.modules.wms.bd.service.mapper.ProductInfoMapper; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.QueryHelp; +import org.springframework.util.CollectionUtils; + +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; /** * @author 黄星星 @@ -33,17 +45,51 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override public Object queryAll(ProductInfoQueryCriteria criteria, Pageable pageable){ - Page page = productInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + Specification specification = new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { + + List targetPredicateList = new ArrayList<>(); + + Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1); + targetPredicateList.add(statusPredicate); + + if(CollectionUtils.isEmpty(targetPredicateList)){ + return null; + }else{ + return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()])); + } + } + }; + Page page = productInfoRepository.findAll(specification,pageable); + return PageUtil.toPage(page.map(productInfoMapper::toDto)); } @Override public Object queryAll(ProductInfoQueryCriteria criteria){ - return productInfoMapper.toDto(productInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + Specification specification = new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { + + List targetPredicateList = new ArrayList<>(); + + Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1); + targetPredicateList.add(statusPredicate); + + if(CollectionUtils.isEmpty(targetPredicateList)){ + return null; + }else{ + return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()])); + } + } + }; + List productInfoList = productInfoRepository.findAll(specification); + return productInfoMapper.toDto(productInfoList); } @Override - public ProductInfoDTO findById(Integer id) { + public ProductInfoDTO findById(Long id) { Optional bdProductInfo = productInfoRepository.findById(id); ValidationUtil.isNull(bdProductInfo,"BdProductInfo","id",id); return productInfoMapper.toDto(bdProductInfo.get()); @@ -52,6 +98,7 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override @Transactional(rollbackFor = Exception.class) public ProductInfoDTO create(ProductInfo resources) { + productInfoRepository.save(resources); return productInfoMapper.toDto(productInfoRepository.save(resources)); } @@ -59,7 +106,7 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Transactional(rollbackFor = Exception.class) public void update(ProductInfo resources) { Optional optionalBdProductInfo = productInfoRepository.findById(resources.getId()); - ValidationUtil.isNull( optionalBdProductInfo,"BdProductInfo","id",resources.getId()); + ValidationUtil.isNull( optionalBdProductInfo,"productInfo","id",resources.getId()); ProductInfo productInfo = optionalBdProductInfo.get(); productInfo.copy(resources); productInfoRepository.save(productInfo); @@ -68,6 +115,10 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override @Transactional(rollbackFor = Exception.class) public void delete(Integer id) { - productInfoRepository.deleteById(id); + ProductInfo productInfo = productInfoRepository.findByIdAndStatusTrue(id); + if (null == productInfo) { + throw new BadRequestException("产品资料不存在!"); + } + productInfoRepository.deleteProductInfo(id); } } \ No newline at end of file