产品资料

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 @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
private long id; private Long id;
// 所属物料分类主键 // 所属物料分类主键
@Column(name = "material_category_id",nullable = false) @Column(name = "material_category_id",nullable = false)
private long materialCategoryId; private Long materialCategoryId;
// 物料分类名称 // 物料分类名称
@Column(name = "material_category_name",nullable = false) @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.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.io.Serializable; import java.io.Serializable;
@ -20,11 +21,11 @@ public class ProductInfo implements Serializable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
private Integer id; private long id;
// 所属产品分类 // 所属产品分类
@Column(name = "product_category_id",nullable = false) @Column(name = "product_category_id",nullable = false)
private Integer productCategoryId; private long productCategoryId;
// 产品分类名称 // 产品分类名称
@Column(name = "product_category_name",nullable = false) @Column(name = "product_category_name",nullable = false)
@ -44,7 +45,7 @@ public class ProductInfo implements Serializable {
// 所属计量单位主键 // 所属计量单位主键
@Column(name = "measure_unit_id") @Column(name = "measure_unit_id")
private Integer measureUnitId; private long measureUnitId;
// 所属计量单位名称 // 所属计量单位名称
@Column(name = "measure_unit_name") @Column(name = "measure_unit_name")
@ -52,7 +53,7 @@ public class ProductInfo implements Serializable {
// 产品单价(保留两位小数) 单位:元 // 产品单价(保留两位小数) 单位:元
@Column(name = "unit_price") @Column(name = "unit_price")
private Integer unitPrice; private Long unitPrice;
// 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}] // 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}]
@Column(name = "product_inventory_warning") @Column(name = "product_inventory_warning")
@ -73,6 +74,9 @@ public class ProductInfo implements Serializable {
@Column(name = "update_time") @Column(name = "update_time")
private Timestamp updateTime; private Timestamp updateTime;
@NotNull
private Boolean status;
public void copy(ProductInfo source){ public void copy(ProductInfo source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); 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 me.zhengjie.modules.wms.bd.domain.ProductInfo;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/** /**
* @author * @author
* @date 2019-07-27 * @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 * @author
* @date 2019-07-27 * @date 2019-07-27
*/ */
@Api(tags = "BdMaterialInfo管理") @Api(tags = "物料资料管理")
@RestController @RestController
@RequestMapping("api") @RequestMapping("api")
public class MaterialInfoController { public class MaterialInfoController {
@ -25,18 +25,23 @@ public class MaterialInfoController {
@Autowired @Autowired
private MaterialInfoService materialInfoService; private MaterialInfoService materialInfoService;
@Log("查询物料资料") @Log("分页查询物料资料")
@ApiOperation(value = "查询物料资料") @ApiOperation(value = "分页查询物料资料")
@GetMapping(value = "/materialInfo") @GetMapping(value = "/materialInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_SELECT')")
public ResponseEntity getBdMaterialInfos(MaterialInfoQueryCriteria criteria, Pageable pageable){ public ResponseEntity getBdMaterialInfos(MaterialInfoQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(materialInfoService.queryAll(criteria,pageable),HttpStatus.OK); 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("新增物料资料") @Log("新增物料资料")
@ApiOperation(value = "新增物料资料") @ApiOperation(value = "新增物料资料")
@PostMapping(value = "/materialInfo") @PostMapping(value = "/materialInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_CREATE')")
public ResponseEntity create(@Validated @RequestBody MaterialInfo resources){ public ResponseEntity create(@Validated @RequestBody MaterialInfo resources){
return new ResponseEntity(materialInfoService.create(resources),HttpStatus.CREATED); return new ResponseEntity(materialInfoService.create(resources),HttpStatus.CREATED);
} }
@ -44,7 +49,6 @@ public class MaterialInfoController {
@Log("修改物料资料") @Log("修改物料资料")
@ApiOperation(value = "修改物料资料") @ApiOperation(value = "修改物料资料")
@PutMapping(value = "/materialInfo") @PutMapping(value = "/materialInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_EDIT')")
public ResponseEntity update(@Validated @RequestBody MaterialInfo resources){ public ResponseEntity update(@Validated @RequestBody MaterialInfo resources){
materialInfoService.update(resources); materialInfoService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT); return new ResponseEntity(HttpStatus.NO_CONTENT);
@ -53,7 +57,6 @@ public class MaterialInfoController {
@Log("删除物料资料") @Log("删除物料资料")
@ApiOperation(value = "删除物料资料") @ApiOperation(value = "删除物料资料")
@DeleteMapping(value = "/materialInfo/{id}") @DeleteMapping(value = "/materialInfo/{id}")
@PreAuthorize("hasAnyRole('ADMIN','BDMATERIALINFO_ALL','BDMATERIALINFO_DELETE')")
public ResponseEntity delete(@PathVariable Integer id){ public ResponseEntity delete(@PathVariable Integer id){
materialInfoService.delete(id); materialInfoService.delete(id);
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);

View File

@ -17,7 +17,7 @@ import io.swagger.annotations.*;
* @author * @author
* @date 2019-07-27 * @date 2019-07-27
*/ */
@Api(tags = "BdProductInfo管理") @Api(tags = "产品资料管理")
@RestController @RestController
@RequestMapping("api") @RequestMapping("api")
public class ProductInfoController { public class ProductInfoController {
@ -25,34 +25,41 @@ public class ProductInfoController {
@Autowired @Autowired
private ProductInfoService productInfoService; private ProductInfoService productInfoService;
@Log("查询BdProductInfo") @Log("分页查询产品资料")
@ApiOperation(value = "查询BdProductInfo") @ApiOperation(value = "分页查询产品资料")
@GetMapping(value = "/bdProductInfo") @GetMapping(value = "/productInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_SELECT')") @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); return new ResponseEntity(productInfoService.queryAll(criteria,pageable),HttpStatus.OK);
} }
@Log("新增BdProductInfo") @Log("查询产品资料列表")
@ApiOperation(value = "新增BdProductInfo") @ApiOperation(value = "查询产品资料列表")
@PostMapping(value = "/bdProductInfo") @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')") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_CREATE')")
public ResponseEntity create(@Validated @RequestBody ProductInfo resources){ public ResponseEntity create(@Validated @RequestBody ProductInfo resources){
return new ResponseEntity(productInfoService.create(resources),HttpStatus.CREATED); return new ResponseEntity(productInfoService.create(resources),HttpStatus.CREATED);
} }
@Log("修改BdProductInfo") @Log("修改产品资料")
@ApiOperation(value = "修改BdProductInfo") @ApiOperation(value = "修改产品资料")
@PutMapping(value = "/bdProductInfo") @PutMapping(value = "/productInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_EDIT')") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_EDIT')")
public ResponseEntity update(@Validated @RequestBody ProductInfo resources){ public ResponseEntity update(@Validated @RequestBody ProductInfo resources){
productInfoService.update(resources); productInfoService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT); return new ResponseEntity(HttpStatus.NO_CONTENT);
} }
@Log("删除BdProductInfo") @Log("删除产品资料")
@ApiOperation(value = "删除BdProductInfo") @ApiOperation(value = "删除产品资料")
@DeleteMapping(value = "/bdProductInfo/{id}") @DeleteMapping(value = "/productInfo/{id}")
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_DELETE')") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_DELETE')")
public ResponseEntity delete(@PathVariable Integer id){ public ResponseEntity delete(@PathVariable Integer id){
productInfoService.delete(id); productInfoService.delete(id);

View File

@ -49,13 +49,13 @@ public class WareHouseController {
} }
@Log("分页查询仓库") @Log("分页查询仓库")
@GetMapping(value = "/wareHouse") @GetMapping(value = "/wareHouses")
public ResponseEntity getWareHouses(WareHouseQueryCriteria wareHouseQueryCriteria, Pageable pageable){ public ResponseEntity getWareHouses(WareHouseQueryCriteria wareHouseQueryCriteria, Pageable pageable){
return new ResponseEntity(wareHouseService.queryAll(wareHouseQueryCriteria,pageable),HttpStatus.OK); return new ResponseEntity(wareHouseService.queryAll(wareHouseQueryCriteria,pageable),HttpStatus.OK);
} }
@Log("查询仓库列表") @Log("查询仓库列表")
@GetMapping(value = "/wareHouse/all") @GetMapping(value = "/queryWareHouseList")
public ResponseEntity queryWareHouseList(WareHouseQueryCriteria wareHouseQueryCriteria){ public ResponseEntity queryWareHouseList(WareHouseQueryCriteria wareHouseQueryCriteria){
return new ResponseEntity(wareHouseService.queryAll(wareHouseQueryCriteria),HttpStatus.OK); return new ResponseEntity(wareHouseService.queryAll(wareHouseQueryCriteria),HttpStatus.OK);
} }

View File

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

View File

@ -13,10 +13,10 @@ import java.io.Serializable;
public class MaterialInfoDTO implements Serializable { public class MaterialInfoDTO implements Serializable {
// 主键 // 主键
private Integer id; private Long id;
// 所属物料分类主键 // 所属物料分类主键
private Integer materialCategoryId; private Long materialCategoryId;
// 物料分类名称 // 物料分类名称
private String materialCategoryName; private String materialCategoryName;
@ -28,7 +28,7 @@ public class MaterialInfoDTO implements Serializable {
private String specifications; private String specifications;
// 所属计量单位主键 // 所属计量单位主键
private Integer measureUnitId; private Long measureUnitId;
// 所属计量单位名称 // 所属计量单位名称
private String measureUnitName; private String measureUnitName;
@ -41,7 +41,7 @@ public class MaterialInfoDTO implements Serializable {
// 物料期初合计期初总价格 // 物料期初合计期初总价格
private Integer materialInitialSetupTotalPrice; private Long materialInitialSetupTotalPrice;
// 物料期初合计总数量 // 物料期初合计总数量
private String materialInitialSetupTotalNumber; private String materialInitialSetupTotalNumber;

View File

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

View File

@ -13,10 +13,10 @@ import java.io.Serializable;
public class ProductInfoDTO implements Serializable { public class ProductInfoDTO implements Serializable {
// 主键 // 主键
private Integer id; private long id;
// 所属产品分类 // 所属产品分类
private Integer productCategoryId; private long productCategoryId;
// 产品分类名称 // 产品分类名称
private String productCategoryName; private String productCategoryName;
@ -31,13 +31,13 @@ public class ProductInfoDTO implements Serializable {
private String specifications; private String specifications;
// 所属计量单位主键 // 所属计量单位主键
private Integer measureUnitId; private long measureUnitId;
// 所属计量单位名称 // 所属计量单位名称
private String measureUnitName; private String measureUnitName;
// 产品单价(保留两位小数) 单位:元 // 产品单价(保留两位小数) 单位:元
private Integer unitPrice; private long unitPrice;
// 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}] // 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}]
private String productInventoryWarning; private String productInventoryWarning;

View File

@ -29,10 +29,7 @@ import me.zhengjie.utils.QueryHelp;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.*;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
/** /**
* @author * @author
@ -83,7 +80,6 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
} }
Predicate materialCategoryIdPredicate = null; Predicate materialCategoryIdPredicate = null;
Long materialCategoryId = criteria.getMaterialCategoryId(); Long materialCategoryId = criteria.getMaterialCategoryId();
if (null != materialCategoryId) { if (null != materialCategoryId) {
@ -91,6 +87,8 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
targetPredicateList.add(materialCategoryIdPredicate); targetPredicateList.add(materialCategoryIdPredicate);
} }
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
targetPredicateList.add(statusPredicate);
if(CollectionUtils.isEmpty(targetPredicateList)){ if(CollectionUtils.isEmpty(targetPredicateList)){
return null; return null;
@ -106,7 +104,24 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
@Override @Override
public Object queryAll(MaterialInfoQueryCriteria criteria) { 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 @Override

View File

@ -1,5 +1,7 @@
package me.zhengjie.modules.wms.bd.service.impl; 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.modules.wms.bd.domain.ProductInfo;
import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.wms.bd.repository.ProductInfoRepository; 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.dto.ProductInfoQueryCriteria;
import me.zhengjie.modules.wms.bd.service.mapper.ProductInfoMapper; import me.zhengjie.modules.wms.bd.service.mapper.ProductInfoMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp; 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 * @author
@ -33,17 +45,51 @@ public class ProductInfoServiceImpl implements ProductInfoService {
@Override @Override
public Object queryAll(ProductInfoQueryCriteria criteria, Pageable pageable){ 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)); return PageUtil.toPage(page.map(productInfoMapper::toDto));
} }
@Override @Override
public Object queryAll(ProductInfoQueryCriteria criteria){ 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 @Override
public ProductInfoDTO findById(Integer id) { public ProductInfoDTO findById(Long id) {
Optional<ProductInfo> bdProductInfo = productInfoRepository.findById(id); Optional<ProductInfo> bdProductInfo = productInfoRepository.findById(id);
ValidationUtil.isNull(bdProductInfo,"BdProductInfo","id",id); ValidationUtil.isNull(bdProductInfo,"BdProductInfo","id",id);
return productInfoMapper.toDto(bdProductInfo.get()); return productInfoMapper.toDto(bdProductInfo.get());
@ -52,6 +98,7 @@ public class ProductInfoServiceImpl implements ProductInfoService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ProductInfoDTO create(ProductInfo resources) { public ProductInfoDTO create(ProductInfo resources) {
productInfoRepository.save(resources);
return productInfoMapper.toDto(productInfoRepository.save(resources)); return productInfoMapper.toDto(productInfoRepository.save(resources));
} }
@ -59,7 +106,7 @@ public class ProductInfoServiceImpl implements ProductInfoService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(ProductInfo resources) { public void update(ProductInfo resources) {
Optional<ProductInfo> optionalBdProductInfo = productInfoRepository.findById(resources.getId()); 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 productInfo = optionalBdProductInfo.get();
productInfo.copy(resources); productInfo.copy(resources);
productInfoRepository.save(productInfo); productInfoRepository.save(productInfo);
@ -68,6 +115,10 @@ public class ProductInfoServiceImpl implements ProductInfoService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(Integer id) { public void delete(Integer id) {
productInfoRepository.deleteById(id); ProductInfo productInfo = productInfoRepository.findByIdAndStatusTrue(id);
if (null == productInfo) {
throw new BadRequestException("产品资料不存在!");
}
productInfoRepository.deleteProductInfo(id);
} }
} }