供应商资料

pull/451/head
starrysky 2019-08-03 14:27:43 +08:00
parent c5c96f715e
commit a1086d0bf0
9 changed files with 445 additions and 2 deletions

View File

@ -0,0 +1,70 @@
package me.zhengjie.modules.wms.bd.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author jie
* @date 2019-08-03
*/
@Entity
@Data
@Table(name="bd_supplier_info")
public class SupplierInfo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 供应商名称
@Column(name = "supplier_name")
private String supplierName;
// 期初预收款
@Column(name = "initial_pre_money")
private Long initialPreMoney;
// 供应商编号
@Column(name = "supplier_code")
private String supplierCode;
// 创建时间
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@Column(name = "update_time")
private Timestamp updateTime;
// 备注
@Column(name = "remark")
private String remark;
// 供应商地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
@Column(name = "supplier_address")
private String supplierAddress;
// 供应商联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
@Column(name = "supplier_contact")
private String supplierContact;
@Column(name = "status")
private Boolean status;
// 供应商类别主键
@Column(name = "supplier_category_id")
private Long supplierCategoryId;
// 供应商类别名称
@Column(name = "supplier_category_name")
private String supplierCategoryName;
public void copy(SupplierInfo source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -0,0 +1,30 @@
package me.zhengjie.modules.wms.bd.repository;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.domain.SupplierInfo;
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 SupplierInfoRepository extends JpaRepository<SupplierInfo, Long>, JpaSpecificationExecutor {
/**
*
* @param id
* @return
*/
SupplierInfo findByIdAndStatusTrue(long id);
/**
*
* @param id
*/
@Modifying
@Query(value = "update bd_supplier_info set status = 0 where id = ?1",nativeQuery = true)
void deleteSupplierInfo(long id);
}

View File

@ -0,0 +1,77 @@
package me.zhengjie.modules.wms.bd.rest;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.wms.bd.domain.SupplierInfo;
import me.zhengjie.modules.wms.bd.service.SupplierInfoService;
import me.zhengjie.modules.wms.bd.service.dto.SupplierInfoQueryCriteria;
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 SupplierInfoController {
@Autowired
private SupplierInfoService supplierInfoService;
@Log("分页查询供应商资料列表")
@ApiOperation(value = "分页查询供应商资料列表")
@GetMapping(value = "/supplierInfos")
@PreAuthorize("hasAnyRole('ADMIN','BDSUPPLIERINFO_ALL','BDSUPPLIERINFO_SELECT')")
public ResponseEntity getBdSupplierInfos(SupplierInfoQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(supplierInfoService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("查询供应商资料列表")
@ApiOperation(value = "分页查询供应商资料列表")
@GetMapping(value = "/getSupplierInfoList")
@PreAuthorize("hasAnyRole('ADMIN','BDSUPPLIERINFO_ALL','BDSUPPLIERINFO_SELECT')")
public ResponseEntity getBdSupplierInfoList(SupplierInfoQueryCriteria criteria){
return new ResponseEntity(supplierInfoService.queryAll(criteria),HttpStatus.OK);
}
@Log("查询供应商资料列表")
@ApiOperation(value = "分页查询供应商资料列表")
@GetMapping(value = "/supplierInfo/{id}")
@PreAuthorize("hasAnyRole('ADMIN','BDSUPPLIERINFO_ALL','BDSUPPLIERINFO_SELECT')")
public ResponseEntity findSupplierInfo(@PathVariable("id") Long id){
return new ResponseEntity(supplierInfoService.findById(id),HttpStatus.OK);
}
@Log("新增供应商资料")
@ApiOperation(value = "新增供应商资料")
@PostMapping(value = "/supplierInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDSUPPLIERINFO_ALL','BDSUPPLIERINFO_CREATE')")
public ResponseEntity create(@Validated @RequestBody SupplierInfo resources){
return new ResponseEntity(supplierInfoService.create(resources),HttpStatus.CREATED);
}
@Log("修改供应商资料")
@ApiOperation(value = "修改供应商资料")
@PutMapping(value = "/supplierInfo")
@PreAuthorize("hasAnyRole('ADMIN','BDSUPPLIERINFO_ALL','BDSUPPLIERINFO_EDIT')")
public ResponseEntity update(@Validated @RequestBody SupplierInfo resources){
supplierInfoService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@Log("删除供应商资料")
@ApiOperation(value = "删除供应商资料")
@DeleteMapping(value = "/supplierInfo/{id}")
@PreAuthorize("hasAnyRole('ADMIN','BDSUPPLIERINFO_ALL','BDSUPPLIERINFO_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
supplierInfoService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
}

View File

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

View File

@ -0,0 +1,49 @@
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 SupplierInfoDTO implements Serializable {
//主键
private Long id;
// 供应商名称
private String supplierName;
// 期初预收款
private Long initialPreMoney;
// 供应商编号
private String supplierCode;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
// 备注
private String remark;
// 供应商地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
private String supplierAddress;
// 供应商联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
private String supplierContact;
private Boolean status;
// 供应商类别主键
private Long supplierCategoryId;
// 供应商类别名称
private String supplierCategoryName;
}

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 SupplierInfoQueryCriteria {
}

View File

@ -93,8 +93,8 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
Optional<CustomerInfo> customerInfoOptional = customerInfoRepository.findById(id);
ValidationUtil.isNull(customerInfoOptional,"customerInfo","id",id);
CustomerInfo customerInfo = customerInfoOptional.get();
CustomerInfoDTO customerInfoDTO = customerInfoMapper.toDto(customerInfo);
return customerInfoDTO;
customerInfoMapper.toDto(customerInfo);
return customerInfoMapper.toDto(customerInfo);
}
@Override

View File

@ -0,0 +1,124 @@
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.SupplierInfo;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.wms.bd.repository.SupplierInfoRepository;
import me.zhengjie.modules.wms.bd.service.SupplierInfoService;
import me.zhengjie.modules.wms.bd.service.dto.SupplierInfoDTO;
import me.zhengjie.modules.wms.bd.service.dto.SupplierInfoQueryCriteria;
import me.zhengjie.modules.wms.bd.service.mapper.SupplierInfoMapper;
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 SupplierInfoServiceImpl implements SupplierInfoService {
@Autowired
private SupplierInfoRepository supplierInfoRepository;
@Autowired
private SupplierInfoMapper supplierInfoMapper;
@Override
public Object queryAll(SupplierInfoQueryCriteria criteria, Pageable pageable){
Specification<SupplierInfo> specification = new Specification<SupplierInfo>() {
@Override
public Predicate toPredicate(Root<SupplierInfo> 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<SupplierInfo> page = supplierInfoRepository.findAll(specification, pageable);
return PageUtil.toPage(page.map(supplierInfoMapper::toDto));
}
@Override
public Object queryAll(SupplierInfoQueryCriteria criteria){
Specification<SupplierInfo> specification = new Specification<SupplierInfo>() {
@Override
public Predicate toPredicate(Root<SupplierInfo> 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()]));
}
}
};
return supplierInfoMapper.toDto(supplierInfoRepository.findAll(specification));
}
@Override
public SupplierInfoDTO findById(Long id) {
Optional<SupplierInfo> bdSupplierInfo = supplierInfoRepository.findById(id);
ValidationUtil.isNull(bdSupplierInfo,"BdSupplierInfo","id",id);
return supplierInfoMapper.toDto(bdSupplierInfo.get());
}
@Override
@Transactional(rollbackFor = Exception.class)
public SupplierInfoDTO create(SupplierInfo resources) {
resources.setStatus(true);
SupplierInfo supplierInfo = supplierInfoRepository.save(resources);
SupplierInfoDTO supplierInfoDTO = supplierInfoMapper.toDto(supplierInfo);
return supplierInfoDTO;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SupplierInfo resources) {
Optional<SupplierInfo> optionalBdSupplierInfo = supplierInfoRepository.findById(resources.getId());
ValidationUtil.isNull( optionalBdSupplierInfo,"BdSupplierInfo","id",resources.getId());
SupplierInfo supplierInfo = optionalBdSupplierInfo.get();
supplierInfo.copy(resources);
supplierInfoRepository.save(supplierInfo);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
SupplierInfo supplierInfo = supplierInfoRepository.findByIdAndStatusTrue(id);
if (null == supplierInfo) {
throw new BadRequestException("供应商资料不存在!");
}
supplierInfoRepository.deleteSupplierInfo(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.SupplierInfo;
import me.zhengjie.modules.wms.bd.service.dto.SupplierInfoDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author jie
* @date 2019-08-03
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SupplierInfoMapper extends EntityMapper<SupplierInfoDTO, SupplierInfo> {
}