mirror of https://github.com/elunez/eladmin
产品系列
parent
34f27a5bfe
commit
bfbfc28246
|
@ -0,0 +1,48 @@
|
|||
package me.zhengjie.modules.wms.bd.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author huangxingxing
|
||||
* @date 2020-01-04
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="bd_product_series")
|
||||
public class ProductSeries implements Serializable {
|
||||
|
||||
// 主键
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
// 产品系列名称
|
||||
@Column(name = "product_series_name")
|
||||
private String productSeriesName;
|
||||
|
||||
// 状态
|
||||
@Column(name = "status")
|
||||
private Boolean status;
|
||||
|
||||
// 创建时间
|
||||
@Column(name = "create_time")
|
||||
@CreationTimestamp
|
||||
private Timestamp createTime;
|
||||
|
||||
// 更新时间
|
||||
@Column(name = "update_time")
|
||||
@CreationTimestamp
|
||||
private Timestamp updateTime;
|
||||
|
||||
public void copy(ProductSeries source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package me.zhengjie.modules.wms.bd.repository;
|
||||
|
||||
import me.zhengjie.modules.wms.bd.domain.ProductSeries;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author huangxingxing
|
||||
* @date 2020-01-04
|
||||
*/
|
||||
public interface ProductSeriesRepository extends JpaRepository<ProductSeries, Long>, JpaSpecificationExecutor {
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package me.zhengjie.modules.wms.bd.rest;
|
||||
|
||||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.modules.wms.bd.domain.ProductSeries;
|
||||
import me.zhengjie.modules.wms.bd.service.ProductSeriesService;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.ProductSeriesQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
/**
|
||||
* @author huangxingxing
|
||||
* @date 2020-01-04
|
||||
*/
|
||||
@Api(tags = "产品系列管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class ProductSeriesController {
|
||||
|
||||
@Autowired
|
||||
private ProductSeriesService productSeriesService;
|
||||
|
||||
@Log("分页查询产品系列")
|
||||
@ApiOperation(value = "分页查询产品系列")
|
||||
@GetMapping(value = "/queryProductSeriesPage")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTSERIES_ALL','BDPRODUCTSERIES_SELECT')")
|
||||
public ResponseEntity queryProductSeriesPage(ProductSeriesQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(productSeriesService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("产品系列列表")
|
||||
@ApiOperation(value = "产品系列列表")
|
||||
@GetMapping(value = "/queryProductSeriesList")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTSERIES_ALL','BDPRODUCTSERIES_SELECT')")
|
||||
public ResponseEntity queryProductSeriesList(ProductSeriesQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(productSeriesService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增产品系列")
|
||||
@ApiOperation(value = "新增产品系列")
|
||||
@PostMapping(value = "/productSeries")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTSERIES_ALL','BDPRODUCTSERIES_CREATE')")
|
||||
public ResponseEntity create(@Validated @RequestBody ProductSeries resources){
|
||||
return new ResponseEntity(productSeriesService.create(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改产品系列")
|
||||
@ApiOperation(value = "修改产品系列")
|
||||
@PutMapping(value = "/productSeries")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTSERIES_ALL','BDPRODUCTSERIES_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody ProductSeries resources){
|
||||
productSeriesService.update(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除产品系列")
|
||||
@ApiOperation(value = "删除产品系列")
|
||||
@DeleteMapping(value = "/productSeries/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTSERIES_ALL','BDPRODUCTSERIES_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
productSeriesService.delete(id);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package me.zhengjie.modules.wms.bd.service;
|
||||
|
||||
import me.zhengjie.modules.wms.bd.domain.ProductSeries;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.ProductSeriesDTO;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.ProductSeriesQueryCriteria;
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.CacheEvict;
|
||||
//import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* @author huangxingxing
|
||||
* @date 2020-01-04
|
||||
*/
|
||||
//@CacheConfig(cacheNames = "bdProductSeries")
|
||||
public interface ProductSeriesService {
|
||||
|
||||
/**
|
||||
* queryAll 分页
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(ProductSeriesQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll 不分页
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(ProductSeriesQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* findById
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(key = "#p0")
|
||||
ProductSeriesDTO findById(Long id);
|
||||
|
||||
/**
|
||||
* create
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
ProductSeriesDTO create(ProductSeries resources);
|
||||
|
||||
/**
|
||||
* update
|
||||
* @param resources
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void update(ProductSeries resources);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* @param id
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
}
|
|
@ -24,7 +24,7 @@ public class ProductSeriesDTO implements Serializable {
|
|||
private String productSeriesName;
|
||||
|
||||
// 状态
|
||||
private Integer status;
|
||||
private Boolean status;
|
||||
|
||||
// 创建时间
|
||||
private Timestamp createTime;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package me.zhengjie.modules.wms.bd.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author huangxingxing
|
||||
* @date 2020-01-04
|
||||
*/
|
||||
@Data
|
||||
public class ProductSeriesQueryCriteria {
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package me.zhengjie.modules.wms.bd.service.impl;
|
||||
|
||||
import me.zhengjie.modules.wms.bd.domain.ProductSeries;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.ProductSeriesDTO;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.modules.wms.bd.repository.ProductSeriesRepository;
|
||||
import me.zhengjie.modules.wms.bd.service.ProductSeriesService;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.ProductSeriesDTO;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.ProductSeriesQueryCriteria;
|
||||
import me.zhengjie.modules.wms.bd.service.mapper.ProductSeriesMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Optional;
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
|
||||
/**
|
||||
* @author huangxingxing
|
||||
* @date 2020-01-04
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class ProductSeriesServiceImpl implements ProductSeriesService {
|
||||
|
||||
@Autowired
|
||||
private ProductSeriesRepository productSeriesRepository;
|
||||
|
||||
@Autowired
|
||||
private ProductSeriesMapper productSeriesMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(ProductSeriesQueryCriteria criteria, Pageable pageable){
|
||||
Page<ProductSeries> page = productSeriesRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(productSeriesMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(ProductSeriesQueryCriteria criteria){
|
||||
return productSeriesMapper.toDto(productSeriesRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductSeriesDTO findById(Long id) {
|
||||
Optional<ProductSeries> bdProductSeries = productSeriesRepository.findById(id);
|
||||
ValidationUtil.isNull(bdProductSeries,"BdProductSeries","id",id);
|
||||
return productSeriesMapper.toDto(bdProductSeries.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ProductSeriesDTO create(ProductSeries resources) {
|
||||
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||
resources.setId(snowflake.nextId());
|
||||
resources.setStatus(true);
|
||||
return productSeriesMapper.toDto(productSeriesRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(ProductSeries resources) {
|
||||
Optional<ProductSeries> optionalBdProductSeries = productSeriesRepository.findById(resources.getId());
|
||||
ValidationUtil.isNull( optionalBdProductSeries,"BdProductSeries","id",resources.getId());
|
||||
ProductSeries productSeries = optionalBdProductSeries.get();
|
||||
productSeries.copy(resources);
|
||||
productSeriesRepository.save(productSeries);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
productSeriesRepository.deleteById(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package me.zhengjie.modules.wms.bd.service.mapper;
|
||||
|
||||
import me.zhengjie.mapper.EntityMapper;
|
||||
import me.zhengjie.modules.wms.bd.domain.ProductSeries;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.ProductSeriesDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author huangxingxing
|
||||
* @date 2020-01-04
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ProductSeriesMapper extends EntityMapper<ProductSeriesDTO, ProductSeries> {
|
||||
|
||||
}
|
Loading…
Reference in New Issue