新增物料资料

pull/451/head
starrysky 2019-07-28 09:59:26 +08:00
parent faea62a149
commit e07d04e1ba
7 changed files with 66 additions and 23 deletions

View File

@ -3,6 +3,8 @@ 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;
@ -20,11 +22,11 @@ public class MaterialInfo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
private long id;
// 所属物料分类主键
@Column(name = "material_category_id",nullable = false)
private Integer materialCategoryId;
private long materialCategoryId;
// 物料分类名称
@Column(name = "material_category_name",nullable = false)
@ -34,13 +36,17 @@ public class MaterialInfo implements Serializable {
@Column(name = "name")
private String name;
// 物料编码
@Column(name = "material_code")
private String materialCode;
// 物料规格
@Column(name = "specifications")
private String specifications;
// 所属计量单位主键
@Column(name = "measure_unit_id")
private Integer measureUnitId;
private Long measureUnitId;
// 所属计量单位名称
@Column(name = "measure_unit_name")
@ -65,10 +71,12 @@ public class MaterialInfo implements Serializable {
// 创建时间
@Column(name = "create_time")
@CreationTimestamp
private Timestamp createTime;
// 更新时间
@Column(name = "update_time")
@CreationTimestamp
private Timestamp updateTime;
public void copy(MaterialInfo source){

View File

@ -10,4 +10,10 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
*/
public interface MaterialCategoryRepository extends JpaRepository<MaterialCategory, Long >, JpaSpecificationExecutor {
/**
*
* @param id
* @return
*/
MaterialCategory findByIdAndStatusTrue(long id);
}

View File

@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author
* @date 2019-07-27
*/
public interface MaterialInfoRepository extends JpaRepository<MaterialInfo, Integer>, JpaSpecificationExecutor {
public interface MaterialInfoRepository extends JpaRepository<MaterialInfo, Long>, JpaSpecificationExecutor {
}

View File

@ -10,4 +10,10 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
*/
public interface MeasureUnitRepository extends JpaRepository<MeasureUnit, Long >, JpaSpecificationExecutor {
/**
*
* @param id
* @return
*/
MeasureUnit findByIdAndStatusTrue(long id);
}

View File

@ -38,7 +38,7 @@ public interface MaterialInfoService {
* @return
*/
//@Cacheable(key = "#p0")
MaterialInfoDTO findById(Integer id);
MaterialInfoDTO findById(Long id);
/**
* create
@ -60,5 +60,5 @@ public interface MaterialInfoService {
* @param id
*/
//@CacheEvict(allEntries = true)
void delete(Integer id);
void delete(long id);
}

View File

@ -43,20 +43,10 @@ public class ProductInfoDTO implements Serializable {
private String productInventoryWarning;
// 产品期初设置
[ {
sort:,
ware_house_code:,
ware_house_name:,
ware_house_type_code:,
ware_house_type_name:,
material_code:,
material_name:,
specifications:,
unit_price:,
total_price:,
minimum_inventory:,
highest_inventory:
}]
// [{“sort”:””,”ware_house_code”:””,”ware_house_name”:””,”ware_house_type_code”:””,“ ware_house_type_name”:””,
// “material_code”:””,“material_name”:””,“specifications”:””,“unit_price”:””,
// “total_price”:””,”minimum_inventory”:””,”highest_inventory”:””
// }]
private String productInitialSetup;
// 创建时间

View File

@ -1,6 +1,11 @@
package me.zhengjie.modules.wms.bd.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.MaterialCategory;
import me.zhengjie.modules.wms.bd.domain.MaterialInfo;
import me.zhengjie.modules.wms.bd.domain.MeasureUnit;
import me.zhengjie.modules.wms.bd.repository.MaterialCategoryRepository;
import me.zhengjie.modules.wms.bd.repository.MeasureUnitRepository;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.wms.bd.repository.MaterialInfoRepository;
import me.zhengjie.modules.wms.bd.service.MaterialInfoService;
@ -16,6 +21,7 @@ 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.StringUtils;
/**
* @author
@ -31,6 +37,12 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
@Autowired
private MaterialInfoMapper materialInfoMapper;
@Autowired
private MaterialCategoryRepository materialCategoryRepository;
@Autowired
private MeasureUnitRepository measureUnitRepository;
@Override
public Object queryAll(MaterialInfoQueryCriteria criteria, Pageable pageable){
Page<MaterialInfo> page = materialInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
@ -43,7 +55,7 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
}
@Override
public MaterialInfoDTO findById(Integer id) {
public MaterialInfoDTO findById(Long id) {
Optional<MaterialInfo> bdMaterialInfo = materialInfoRepository.findById(id);
ValidationUtil.isNull(bdMaterialInfo,"BdMaterialInfo","id",id);
return materialInfoMapper.toDto(bdMaterialInfo.get());
@ -52,6 +64,27 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
@Override
@Transactional(rollbackFor = Exception.class)
public MaterialInfoDTO create(MaterialInfo resources) {
Long materialCategoryId = resources.getMaterialCategoryId();
String materialCategoryName = resources.getMaterialCategoryName();
if(null == materialCategoryId || StringUtils.isEmpty(materialCategoryName)){
throw new BadRequestException("物料类别不能为空!");
}
MaterialCategory materialCategory = materialCategoryRepository.findByIdAndStatusTrue(materialCategoryId);
if(null == materialCategory){
throw new BadRequestException("物料类别不存在!");
}
Long measureUnitId = resources.getMeasureUnitId();
String measureUnitName = resources.getMeasureUnitName();
if(null == measureUnitId || StringUtils.isEmpty(measureUnitName)){
throw new BadRequestException("计量单位不能为空!");
}
MeasureUnit measureUnit = measureUnitRepository.findByIdAndStatusTrue(measureUnitId);
if(null == measureUnit){
throw new BadRequestException("计量单位不存在!");
}
return materialInfoMapper.toDto(materialInfoRepository.save(resources));
}
@ -59,7 +92,7 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
@Transactional(rollbackFor = Exception.class)
public void update(MaterialInfo resources) {
Optional<MaterialInfo> optionalBdMaterialInfo = materialInfoRepository.findById(resources.getId());
ValidationUtil.isNull( optionalBdMaterialInfo,"BdMaterialInfo","id",resources.getId());
ValidationUtil.isNull( optionalBdMaterialInfo,"MaterialInfo","id",resources.getId());
MaterialInfo materialInfo = optionalBdMaterialInfo.get();
materialInfo.copy(resources);
materialInfoRepository.save(materialInfo);
@ -67,7 +100,7 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Integer id) {
public void delete(long id) {
materialInfoRepository.deleteById(id);
}
}