分页查询客户信息

pull/451/head
starrysky 2019-08-03 13:56:04 +08:00
parent a795f29c1b
commit c5c96f715e
10 changed files with 443 additions and 0 deletions

View File

@ -0,0 +1,67 @@
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 javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author jie
* @date 2019-08-03
*/
@Entity
@Data
@Table(name="bd_customer_info")
public class CustomerInfo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 客户名称
@Column(name = "customer_name",nullable = false)
private String customerName;
// 期初预收款
@Column(name = "initial_pre_money")
private Long initialPreMoney;
// 客户编号
@Column(name = "customer_code",nullable = false)
private String customerCode;
// 创建时间
@Column(name = "create_time")
@CreationTimestamp
private Timestamp createTime;
// 更新时间
@Column(name = "update_time")
@CreationTimestamp
private Timestamp updateTime;
// 备注
@Column(name = "remark")
private String remark;
// 客户地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
@Column(name = "customer_address",nullable = false)
private String customerAddress;
// 客户联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
@Column(name = "customer_contact")
private String customerContact;
@NotNull
private Boolean status;
public void copy(CustomerInfo source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -0,0 +1,25 @@
package me.zhengjie.modules.wms.bd.repository;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
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 jie
* @date 2019-08-03
*/
public interface CustomerInfoRepository extends JpaRepository<CustomerInfo, Long>, JpaSpecificationExecutor {
CustomerInfo findByIdAndStatusTrue(long id);
/**
*
* @param id
*/
@Modifying
@Query(value = "update bd_customer_info set status = 0 where id = ?1",nativeQuery = true)
void deleteCustomerInfo(long id);
}

View File

@ -0,0 +1,75 @@
package me.zhengjie.modules.wms.bd.rest;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.service.CustomerInfoService;
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoQueryCriteria;
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-03
*/
@Api(tags = "客户信息管理")
@RestController
@RequestMapping("api")
public class CustomerInfoController {
@Autowired
private CustomerInfoService customerInfoService;
@Log("分页查询客户信息")
@ApiOperation(value = "分页查询客户信息")
@GetMapping(value = "/customerInfos")
@PreAuthorize("hasAnyRole('ADMIN','BDCUSTOMERINFO_ALL','BDCUSTOMERINFO_SELECT')")
public ResponseEntity getCustomerInfos(CustomerInfoQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(customerInfoService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("查询客户信息列表")
@ApiOperation(value = "查询客户信息列表")
@GetMapping(value = "/customerInfo/queryCustomerInfoList")
@PreAuthorize("hasAnyRole('ADMIN','BDCUSTOMERINFO_ALL','BDCUSTOMERINFO_SELECT')")
public ResponseEntity queryCustomerInfoList(CustomerInfoQueryCriteria criteria){
return new ResponseEntity(customerInfoService.queryAll(criteria),HttpStatus.OK);
}
@Log("查看客户信息资料详情")
@GetMapping(value = "/customerInfo/{id}")
public ResponseEntity getCustomerInfo(@PathVariable Long id){
return new ResponseEntity(customerInfoService.findById(id), HttpStatus.OK);
}
@Log("新增客户信息")
@ApiOperation(value = "新增客户信息")
@PostMapping(value = "/customerInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDCUSTOMERINFO_ALL','BDCUSTOMERINFO_CREATE')")
public ResponseEntity create(@Validated @RequestBody CustomerInfo resources){
return new ResponseEntity(customerInfoService.create(resources),HttpStatus.CREATED);
}
@Log("修改客户信息")
@ApiOperation(value = "修改客户信息")
@PutMapping(value = "/customerInfo/update")
@PreAuthorize("hasAnyRole('ADMIN','BDCUSTOMERINFO_ALL','BDCUSTOMERINFO_EDIT')")
public ResponseEntity update(@Validated @RequestBody CustomerInfo resources){
customerInfoService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@Log("删除客户信息")
@ApiOperation(value = "删除客户信息")
@DeleteMapping(value = "/customerInfo/{id}")
@PreAuthorize("hasAnyRole('ADMIN','BDCUSTOMERINFO_ALL','BDCUSTOMERINFO_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
customerInfoService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
}

View File

@ -61,4 +61,10 @@ public class MaterialInfoController {
materialInfoService.delete(id); materialInfoService.delete(id);
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);
} }
@Log("查看物料资料详情")
@GetMapping(value = "/materialInfo/{id}")
public ResponseEntity getMessureUnit(@PathVariable Long id){
return new ResponseEntity(materialInfoService.findById(id), HttpStatus.OK);
}
} }

View File

@ -65,4 +65,10 @@ public class ProductInfoController {
productInfoService.delete(id); productInfoService.delete(id);
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);
} }
@Log("查看产品资料详情")
@GetMapping(value = "/productInfo/{id}")
public ResponseEntity getMessureUnit(@PathVariable Long id){
return new ResponseEntity(productInfoService.findById(id), HttpStatus.OK);
}
} }

View File

@ -0,0 +1,64 @@
package me.zhengjie.modules.wms.bd.service;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoDTO;
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoQueryCriteria;
//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-03
*/
//@CacheConfig(cacheNames = "bdCustomerInfo")
public interface CustomerInfoService {
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
//@Cacheable(keyGenerator = "keyGenerator")
Object queryAll(CustomerInfoQueryCriteria criteria, Pageable pageable);
/**
* queryAll
* @param criteria
* @return
*/
//@Cacheable(keyGenerator = "keyGenerator")
public Object queryAll(CustomerInfoQueryCriteria criteria);
/**
* findById
* @param id
* @return
*/
//@Cacheable(key = "#p0")
CustomerInfoDTO findById(Long id);
/**
* create
* @param resources
* @return
*/
//@CacheEvict(allEntries = true)
CustomerInfoDTO create(CustomerInfo resources);
/**
* update
* @param resources
*/
//@CacheEvict(allEntries = true)
void update(CustomerInfo resources);
/**
* delete
* @param id
*/
//@CacheEvict(allEntries = true)
void delete(Long id);
}

View File

@ -0,0 +1,43 @@
package me.zhengjie.modules.wms.bd.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author jie
* @date 2019-08-03
*/
@Data
public class CustomerInfoDTO implements Serializable {
private Long id;
// 客户名称
private String customerName;
// 期初预收款
private Long initialPreMoney;
// 客户编号
private String customerCode;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
// 备注
private String remark;
// 状态
private Boolean status;
// 客户地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
private String customerAddress;
// 客户联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
private String customerContact;
}

View File

@ -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 jie
* @date 2019-08-03
*/
@Data
public class CustomerInfoQueryCriteria {
}

View File

@ -0,0 +1,128 @@
package me.zhengjie.modules.wms.bd.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.wms.bd.repository.CustomerInfoRepository;
import me.zhengjie.modules.wms.bd.service.CustomerInfoService;
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoDTO;
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoQueryCriteria;
import me.zhengjie.modules.wms.bd.service.mapper.CustomerInfoMapper;
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 jie
* @date 2019-08-03
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class CustomerInfoServiceImpl implements CustomerInfoService {
@Autowired
private CustomerInfoRepository customerInfoRepository;
@Autowired
private CustomerInfoMapper customerInfoMapper;
@Override
public Object queryAll(CustomerInfoQueryCriteria criteria, Pageable pageable){
Specification<CustomerInfo> specification = new Specification<CustomerInfo>() {
@Override
public Predicate toPredicate(Root<CustomerInfo> 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<CustomerInfo> page = customerInfoRepository.findAll(specification, pageable);
return PageUtil.toPage(page.map(customerInfoMapper::toDto));
}
@Override
public Object queryAll(CustomerInfoQueryCriteria criteria){
Specification<CustomerInfo> specification = new Specification<CustomerInfo>() {
@Override
public Predicate toPredicate(Root<CustomerInfo> 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<CustomerInfo> productInfoList = customerInfoRepository.findAll(specification);
return customerInfoMapper.toDto(productInfoList);
}
@Override
public CustomerInfoDTO findById(Long id) {
Optional<CustomerInfo> customerInfoOptional = customerInfoRepository.findById(id);
ValidationUtil.isNull(customerInfoOptional,"customerInfo","id",id);
CustomerInfo customerInfo = customerInfoOptional.get();
CustomerInfoDTO customerInfoDTO = customerInfoMapper.toDto(customerInfo);
return customerInfoDTO;
}
@Override
@Transactional(rollbackFor = Exception.class)
public CustomerInfoDTO create(CustomerInfo resources) {
resources.setStatus(true);
CustomerInfo customerInfo = customerInfoRepository.save(resources);
CustomerInfoDTO customerInfoDTO = customerInfoMapper.toDto(customerInfo);
return customerInfoDTO;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(CustomerInfo resources) {
Optional<CustomerInfo> optionalBdCustomerInfo = customerInfoRepository.findById(resources.getId());
ValidationUtil.isNull( optionalBdCustomerInfo,"BdCustomerInfo","id",resources.getId());
CustomerInfo customerInfo = optionalBdCustomerInfo.get();
customerInfo.copy(resources);
customerInfoRepository.save(customerInfo);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
CustomerInfo customerInfo = customerInfoRepository.findByIdAndStatusTrue(id);
if (null == customerInfo) {
throw new BadRequestException("客户信息不存在!");
}
customerInfoRepository.deleteCustomerInfo(id);
}
}

View File

@ -0,0 +1,16 @@
package me.zhengjie.modules.wms.bd.service.mapper;
import me.zhengjie.mapper.EntityMapper;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author jie
* @date 2019-08-03
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CustomerInfoMapper extends EntityMapper<CustomerInfoDTO, CustomerInfo> {
}