产品资料

pull/451/head
starrysky 2019-08-03 12:53:24 +08:00
parent 9dfb94433f
commit a795f29c1b
12 changed files with 149 additions and 50 deletions

View File

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

View File

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

View File

@ -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<ProductInfo, Integer>, JpaSpecificationExecutor {
public interface ProductInfoRepository extends JpaRepository<ProductInfo, Long>, 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);
}

View File

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

View File

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

View File

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

View File

@ -38,7 +38,7 @@ public interface ProductInfoService {
* @return
*/
//@Cacheable(key = "#p0")
ProductInfoDTO findById(Integer id);
ProductInfoDTO findById(Long id);
/**
* create

View File

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

View File

@ -19,4 +19,6 @@ public class MaterialInfoQueryCriteria {
private Long materialCategoryId;
private Boolean status;
}

View File

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

View File

@ -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<MaterialInfo> specification = new Specification<MaterialInfo>() {
@Override
public Predicate toPredicate(Root<MaterialInfo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> 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<MaterialInfo> materialInfoList = materialInfoRepository.findAll(specification);
return materialInfoMapper.toDto(materialInfoList);
}
@Override

View File

@ -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<ProductInfo> page = productInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
Specification<ProductInfo> specification = new Specification<ProductInfo>() {
@Override
public Predicate toPredicate(Root<ProductInfo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> 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<ProductInfo> 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<ProductInfo> specification = new Specification<ProductInfo>() {
@Override
public Predicate toPredicate(Root<ProductInfo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> 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<ProductInfo> productInfoList = productInfoRepository.findAll(specification);
return productInfoMapper.toDto(productInfoList);
}
@Override
public ProductInfoDTO findById(Integer id) {
public ProductInfoDTO findById(Long id) {
Optional<ProductInfo> 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<ProductInfo> 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);
}
}