From 6f46a259f4a136b88141a4cb09162dcf0e2f82f7 Mon Sep 17 00:00:00 2001 From: starrysky <838252223@qq.com> Date: Thu, 29 Aug 2019 18:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=B4=A7=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customerOrder/domain/CustomerOrder.java | 4 + .../sr/productCount/domain/ProductCount.java | 46 ++++++++++++ .../repository/ProductCountRepository.java | 12 +++ .../rest/ProductCountController.java | 67 +++++++++++++++++ .../service/ProductCountService.java | 64 ++++++++++++++++ .../service/dto/ProductCountDTO.java | 26 +++++++ .../dto/ProductCountQueryCriteria.java | 13 ++++ .../service/impl/ProductCountServiceImpl.java | 73 +++++++++++++++++++ .../service/mapper/ProductCountMapper.java | 16 ++++ .../src/main/resources/config/application.yml | 2 +- 10 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/domain/ProductCount.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/repository/ProductCountRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/rest/ProductCountController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/ProductCountService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountDTO.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/impl/ProductCountServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/mapper/ProductCountMapper.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/customerOrder/domain/CustomerOrder.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/customerOrder/domain/CustomerOrder.java index 7b4c9f5b..a1fa5843 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/customerOrder/domain/CustomerOrder.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/customerOrder/domain/CustomerOrder.java @@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.customerOrder.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; @@ -83,10 +85,12 @@ public class CustomerOrder implements Serializable { // 创建时间 @Column(name = "create_time") + @CreationTimestamp private Timestamp createTime; // 更新时间 @Column(name = "update_time") + @CreationTimestamp private Timestamp updateTime; // 总额 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/domain/ProductCount.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/domain/ProductCount.java new file mode 100644 index 00000000..c73d948a --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/domain/ProductCount.java @@ -0,0 +1,46 @@ +package me.zhengjie.modules.wms.sr.productCount.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 jie +* @date 2019-08-29 +*/ +@Entity +@Data +@Table(name="sr_product_count") +public class ProductCount implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Column(name = "product_id") + private Long productId; + + @Column(name = "product_name") + private String productName; + + @Column(name = "total_number") + private Long totalNumber; + + @Column(name = "gmt_create") + @CreationTimestamp + private Timestamp gmtCreate; + + @Column(name = "gmt_update") + @CreationTimestamp + private Timestamp gmtUpdate; + + public void copy(ProductCount source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/repository/ProductCountRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/repository/ProductCountRepository.java new file mode 100644 index 00000000..b34486f7 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/repository/ProductCountRepository.java @@ -0,0 +1,12 @@ +package me.zhengjie.modules.wms.sr.productCount.repository; + +import me.zhengjie.modules.wms.sr.productCount.domain.ProductCount; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @author jie +* @date 2019-08-29 +*/ +public interface ProductCountRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/rest/ProductCountController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/rest/ProductCountController.java new file mode 100644 index 00000000..0216d809 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/rest/ProductCountController.java @@ -0,0 +1,67 @@ +package me.zhengjie.modules.wms.sr.productCount.rest; + +import me.zhengjie.aop.log.Log; +import me.zhengjie.modules.wms.sr.productCount.domain.ProductCount; +import me.zhengjie.modules.wms.sr.productCount.service.ProductCountService; +import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountQueryCriteria; +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 jie +* @date 2019-08-29 +*/ +@Api(tags = "产品统计管理") +@RestController +@RequestMapping("api") +public class ProductCountController { + + @Autowired + private ProductCountService productCountService; + + @Log("分页查询产品统计列表") + @ApiOperation(value = "分页查询产品统计列表") + @GetMapping(value = "/queryProductCountPage") + @PreAuthorize("hasAnyRole('ADMIN','SRPRODUCTCOUNT_ALL','SRPRODUCTCOUNT_SELECT')") + public ResponseEntity queryProductCountPage(ProductCountQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity(productCountService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @Log("新增产品统计") + @ApiOperation(value = "新增产品统计") + @PostMapping(value = "/productCount") + @PreAuthorize("hasAnyRole('ADMIN','SRPRODUCTCOUNT_ALL','SRPRODUCTCOUNT_CREATE')") + public ResponseEntity create(@RequestBody ProductCount resources){ + return new ResponseEntity(productCountService.create(resources),HttpStatus.CREATED); + } + + @Log("修改产品统计") + @ApiOperation(value = "修改产品统计") + @PutMapping(value = "/productCount") + @PreAuthorize("hasAnyRole('ADMIN','SRPRODUCTCOUNT_ALL','SRPRODUCTCOUNT_EDIT')") + public ResponseEntity update(@RequestBody ProductCount resources){ + productCountService.update(resources); + return new ResponseEntity(HttpStatus.NO_CONTENT); + } + + @Log("删除产品统计") + @ApiOperation(value = "删除产品统计") + @DeleteMapping(value = "/productCount/{id}") + @PreAuthorize("hasAnyRole('ADMIN','SRPRODUCTCOUNT_ALL','SRPRODUCTCOUNT_DELETE')") + public ResponseEntity delete(@PathVariable Long id){ + productCountService.delete(id); + return new ResponseEntity(HttpStatus.OK); + } + + @Log("查看产品统计详情") + @GetMapping(value = "/productCount/{id}") + public ResponseEntity getProductCountInfo(@PathVariable Long id){ + return new ResponseEntity(productCountService.findById(id), HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/ProductCountService.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/ProductCountService.java new file mode 100644 index 00000000..d27666c1 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/ProductCountService.java @@ -0,0 +1,64 @@ +package me.zhengjie.modules.wms.sr.productCount.service; + +import me.zhengjie.modules.wms.sr.productCount.domain.ProductCount; +import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountDTO; +import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountQueryCriteria; +//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 jie +* @date 2019-08-29 +*/ +//@CacheConfig(cacheNames = "srProductCount") +public interface ProductCountService { + + /** + * queryAll 分页 + * @param criteria + * @param pageable + * @return + */ + //@Cacheable(keyGenerator = "keyGenerator") + Object queryAll(ProductCountQueryCriteria criteria, Pageable pageable); + + /** + * queryAll 不分页 + * @param criteria + * @return + */ + //@Cacheable(keyGenerator = "keyGenerator") + public Object queryAll(ProductCountQueryCriteria criteria); + + /** + * findById + * @param id + * @return + */ + //@Cacheable(key = "#p0") + ProductCountDTO findById(Long id); + + /** + * create + * @param resources + * @return + */ + //@CacheEvict(allEntries = true) + ProductCountDTO create(ProductCount resources); + + /** + * update + * @param resources + */ + //@CacheEvict(allEntries = true) + void update(ProductCount resources); + + /** + * delete + * @param id + */ + //@CacheEvict(allEntries = true) + void delete(Long id); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountDTO.java new file mode 100644 index 00000000..f9960759 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountDTO.java @@ -0,0 +1,26 @@ +package me.zhengjie.modules.wms.sr.productCount.service.dto; + +import lombok.Data; +import java.sql.Timestamp; +import java.io.Serializable; + + +/** +* @author jie +* @date 2019-08-29 +*/ +@Data +public class ProductCountDTO implements Serializable { + + private Long id; + + private Long productId; + + private String productName; + + private Long totalNumber; + + private Timestamp gmtCreate; + + private Timestamp gmtUpdate; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountQueryCriteria.java new file mode 100644 index 00000000..3524d14e --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/dto/ProductCountQueryCriteria.java @@ -0,0 +1,13 @@ +package me.zhengjie.modules.wms.sr.productCount.service.dto; + +import lombok.Data; +import java.sql.Timestamp; +import me.zhengjie.annotation.Query; + +/** +* @author jie +* @date 2019-08-29 +*/ +@Data +public class ProductCountQueryCriteria { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/impl/ProductCountServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/impl/ProductCountServiceImpl.java new file mode 100644 index 00000000..f91420d3 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/impl/ProductCountServiceImpl.java @@ -0,0 +1,73 @@ +package me.zhengjie.modules.wms.sr.productCount.service.impl; + +import me.zhengjie.modules.wms.sr.productCount.domain.ProductCount; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.modules.wms.sr.productCount.repository.ProductCountRepository; +import me.zhengjie.modules.wms.sr.productCount.service.ProductCountService; +import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountDTO; +import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountQueryCriteria; +import me.zhengjie.modules.wms.sr.productCount.service.mapper.ProductCountMapper; +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 org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import me.zhengjie.utils.PageUtil; +import me.zhengjie.utils.QueryHelp; + +/** +* @author jie +* @date 2019-08-29 +*/ +@Service +@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) +public class ProductCountServiceImpl implements ProductCountService { + + @Autowired + private ProductCountRepository productCountRepository; + + @Autowired + private ProductCountMapper productCountMapper; + + @Override + public Object queryAll(ProductCountQueryCriteria criteria, Pageable pageable){ + Page page = productCountRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(productCountMapper::toDto)); + } + + @Override + public Object queryAll(ProductCountQueryCriteria criteria){ + return productCountMapper.toDto(productCountRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + public ProductCountDTO findById(Long id) { + Optional srProductCount = productCountRepository.findById(id); + ValidationUtil.isNull(srProductCount,"SrProductCount","id",id); + return productCountMapper.toDto(srProductCount.get()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public ProductCountDTO create(ProductCount resources) { + return productCountMapper.toDto(productCountRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(ProductCount resources) { + Optional optionalSrProductCount = productCountRepository.findById(resources.getId()); + ValidationUtil.isNull( optionalSrProductCount,"SrProductCount","id",resources.getId()); + ProductCount productCount = optionalSrProductCount.get(); + productCount.copy(resources); + productCountRepository.save(productCount); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long id) { + productCountRepository.deleteById(id); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/mapper/ProductCountMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/mapper/ProductCountMapper.java new file mode 100644 index 00000000..5d91c6fc --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/sr/productCount/service/mapper/ProductCountMapper.java @@ -0,0 +1,16 @@ +package me.zhengjie.modules.wms.sr.productCount.service.mapper; + +import me.zhengjie.mapper.EntityMapper; +import me.zhengjie.modules.wms.sr.productCount.domain.ProductCount; +import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountDTO; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @author jie +* @date 2019-08-29 +*/ +@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface ProductCountMapper extends EntityMapper { + +} \ No newline at end of file diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index a52de8aa..33e004d7 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -3,7 +3,7 @@ server: spring: profiles: - active: prod + active: dev jackson: time-zone: GMT+8 data: