mirror of https://github.com/elunez/eladmin
物料资料
parent
2ce170501d
commit
ff5ec90246
|
@ -0,0 +1,55 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Data;
|
||||
import me.zhengjie.modules.wms.bd.domain.MaterialInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class CreateMaterialInfoRequest implements Serializable {
|
||||
// 所属物料分类主键
|
||||
private Long materialCategoryId;
|
||||
|
||||
// 物料分类名称
|
||||
private String materialCategoryName;
|
||||
|
||||
// 物料名称
|
||||
private String name;
|
||||
|
||||
// 物料编码
|
||||
private String materialCode;
|
||||
|
||||
// 物料规格
|
||||
private String specifications;
|
||||
|
||||
// 所属计量单位主键
|
||||
private Long measureUnitId;
|
||||
|
||||
// 所属计量单位名称
|
||||
private String measureUnitName;
|
||||
|
||||
// 产品库存预警
|
||||
private List<MaterialInventoryWarning> materialInventoryWarningList;
|
||||
|
||||
// 产品期初设置
|
||||
private List<MaterialInitialSetup> materialInitialSetupList;
|
||||
|
||||
// 物料期初合计期初总价格
|
||||
private Integer materialInitialSetupTotalPrice;
|
||||
|
||||
// 物料期初合计总数量
|
||||
private String materialInitialSetupTotalNumber;
|
||||
|
||||
private Boolean status;
|
||||
|
||||
public void copy(MaterialInfo source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-22
|
||||
* //[{“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”:””}]
|
||||
*/
|
||||
@Data
|
||||
public class MaterialInitialSetup implements Serializable {
|
||||
|
||||
private Integer sort;
|
||||
|
||||
private String wareHouseCode;
|
||||
|
||||
private String wareHouseName;
|
||||
|
||||
private String wareHouseTypeCode;
|
||||
|
||||
private String wareHouseTypeName;
|
||||
|
||||
private String materialCode;
|
||||
|
||||
private String materialName;
|
||||
|
||||
private String specifications;
|
||||
|
||||
private Long unitPrice;
|
||||
|
||||
private Long totalPrice;
|
||||
|
||||
private String minimumInventory;
|
||||
|
||||
private String highestInventory;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package me.zhengjie.modules.wms.bd.cons;
|
||||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -7,6 +7,9 @@ import java.io.Serializable;
|
|||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-22
|
||||
* //[{“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”:””}]
|
||||
*/
|
||||
@Data
|
||||
public class ProductInitialSetup implements Serializable {
|
||||
|
@ -20,4 +23,19 @@ public class ProductInitialSetup implements Serializable {
|
|||
private String wareHouseTypeCode;
|
||||
|
||||
private String wareHouseTypeName;
|
||||
|
||||
private String materialCode;
|
||||
|
||||
private String materialName;
|
||||
|
||||
private String specifications;
|
||||
|
||||
private Long unitPrice;
|
||||
|
||||
private Long totalPrice;
|
||||
|
||||
private String minimumInventory;
|
||||
|
||||
private String highestInventory;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,21 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-21
|
||||
*/
|
||||
public class ProductInventoryWarning {
|
||||
@Data
|
||||
public class ProductInventoryWarning implements Serializable {
|
||||
private String wareHouseCode;
|
||||
|
||||
private String wareHouseName;
|
||||
|
||||
private String minimumInventory;
|
||||
|
||||
private String highestInventory;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package me.zhengjie.modules.wms.bd.rest;
|
|||
|
||||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.modules.wms.bd.domain.MaterialInfo;
|
||||
import me.zhengjie.modules.wms.bd.request.CreateMaterialInfoRequest;
|
||||
import me.zhengjie.modules.wms.bd.service.MaterialInfoService;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.MaterialInfoQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -27,7 +28,7 @@ public class MaterialInfoController {
|
|||
|
||||
@Log("分页查询物料资料")
|
||||
@ApiOperation(value = "分页查询物料资料")
|
||||
@GetMapping(value = "/materialInfo")
|
||||
@GetMapping(value = "/queryMaterialInfoPage")
|
||||
public ResponseEntity queryMaterialInfoPage(MaterialInfoQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(materialInfoService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
@ -42,13 +43,13 @@ public class MaterialInfoController {
|
|||
@Log("新增物料资料")
|
||||
@ApiOperation(value = "新增物料资料")
|
||||
@PostMapping(value = "/materialInfo")
|
||||
public ResponseEntity create(@Validated @RequestBody MaterialInfo resources){
|
||||
return new ResponseEntity(materialInfoService.create(resources),HttpStatus.CREATED);
|
||||
public ResponseEntity create(@RequestBody CreateMaterialInfoRequest createMaterialInfoRequest){
|
||||
return new ResponseEntity(materialInfoService.create(createMaterialInfoRequest),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改物料资料")
|
||||
@ApiOperation(value = "修改物料资料")
|
||||
@PutMapping(value = "/materialInfo")
|
||||
@PutMapping(value = "/materialInfo/update")
|
||||
public ResponseEntity update(@Validated @RequestBody MaterialInfo resources){
|
||||
materialInfoService.update(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package me.zhengjie.modules.wms.bd.service;
|
||||
|
||||
import me.zhengjie.modules.wms.bd.domain.MaterialInfo;
|
||||
import me.zhengjie.modules.wms.bd.request.CreateMaterialInfoRequest;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.MaterialInfoDTO;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.MaterialInfoDetailDTO;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.MaterialInfoQueryCriteria;
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.CacheEvict;
|
||||
|
@ -38,15 +40,15 @@ public interface MaterialInfoService {
|
|||
* @return
|
||||
*/
|
||||
//@Cacheable(key = "#p0")
|
||||
MaterialInfoDTO findById(Long id);
|
||||
MaterialInfoDetailDTO findById(Long id);
|
||||
|
||||
/**
|
||||
* create
|
||||
* @param resources
|
||||
* @param createMaterialInfoRequest
|
||||
* @return
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
MaterialInfoDTO create(MaterialInfo resources);
|
||||
MaterialInfoDetailDTO create(CreateMaterialInfoRequest createMaterialInfoRequest);
|
||||
|
||||
/**
|
||||
* update
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package me.zhengjie.modules.wms.bd.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.modules.wms.bd.request.MaterialInitialSetup;
|
||||
import me.zhengjie.modules.wms.bd.request.MaterialInventoryWarning;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-08-03
|
||||
*/
|
||||
@Data
|
||||
public class MaterialInfoDetailDTO extends ProductInfoDTO implements Serializable {
|
||||
|
||||
private List<MaterialInventoryWarning> materialInventoryWarningList;
|
||||
|
||||
private List<MaterialInitialSetup> materialInitialSetupList;
|
||||
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
package me.zhengjie.modules.wms.bd.service.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
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.domain.*;
|
||||
import me.zhengjie.modules.wms.bd.repository.MaterialCategoryRepository;
|
||||
import me.zhengjie.modules.wms.bd.repository.MeasureUnitRepository;
|
||||
import me.zhengjie.modules.wms.bd.request.*;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.*;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.modules.wms.bd.repository.MaterialInfoRepository;
|
||||
import me.zhengjie.modules.wms.bd.service.MaterialInfoService;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.MaterialInfoDTO;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.MaterialInfoQueryCriteria;
|
||||
import me.zhengjie.modules.wms.bd.service.mapper.MaterialInfoMapper;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -125,44 +126,80 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MaterialInfoDTO findById(Long id) {
|
||||
Optional<MaterialInfo> bdMaterialInfo = materialInfoRepository.findById(id);
|
||||
ValidationUtil.isNull(bdMaterialInfo, "BdMaterialInfo", "id", id);
|
||||
return materialInfoMapper.toDto(bdMaterialInfo.get());
|
||||
public MaterialInfoDetailDTO findById(Long id) {
|
||||
MaterialInfoDetailDTO materialInfoDetailDTO = new MaterialInfoDetailDTO();
|
||||
|
||||
Optional<MaterialInfo> materialInfoOptional = materialInfoRepository.findById(id);
|
||||
MaterialInfo materialInfo = materialInfoOptional.get();
|
||||
MaterialInfoDTO materialInfoDTO = materialInfoMapper.toDto(materialInfo);
|
||||
if(null != materialInfoDTO){
|
||||
BeanUtils.copyProperties( materialInfoDTO, materialInfoDetailDTO);
|
||||
String productInventoryWarningStr = materialInfo.getMaterialInventoryWarning();
|
||||
if(StringUtils.hasLength(productInventoryWarningStr)){
|
||||
List<MaterialInventoryWarning> materialInventoryWarningList = new Gson().fromJson(productInventoryWarningStr,new TypeToken<ArrayList<MaterialInventoryWarning>>() {}.getType());
|
||||
materialInfoDetailDTO.setMaterialInventoryWarningList(materialInventoryWarningList);
|
||||
}
|
||||
|
||||
|
||||
String materialInitialSetupStr = materialInfo.getMaterialInitialSetup();
|
||||
if(StringUtils.hasLength(materialInitialSetupStr)){
|
||||
List<MaterialInitialSetup> materialInitialSetupList = new Gson().fromJson(materialInitialSetupStr,new TypeToken<ArrayList<MaterialInitialSetup>>() {}.getType());
|
||||
materialInfoDetailDTO.setMaterialInitialSetupList(materialInitialSetupList);
|
||||
}
|
||||
}
|
||||
return materialInfoDetailDTO;
|
||||
}
|
||||
|
||||
@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)) {
|
||||
public MaterialInfoDetailDTO create(CreateMaterialInfoRequest createMaterialInfoRequest) {
|
||||
Long measureUnitId = createMaterialInfoRequest.getMeasureUnitId();
|
||||
if(null == measureUnitId){
|
||||
throw new BadRequestException("计量单位不能为空!");
|
||||
}
|
||||
|
||||
MeasureUnit measureUnit = measureUnitRepository.findByIdAndStatusTrue(measureUnitId);
|
||||
if (null == measureUnit) {
|
||||
Optional<MeasureUnit> measureUnitOptional = measureUnitRepository.findById(measureUnitId);
|
||||
MeasureUnit measureUnit = measureUnitOptional.get();
|
||||
if(null == measureUnit){
|
||||
throw new BadRequestException("计量单位不存在!");
|
||||
}
|
||||
|
||||
// 物料编码
|
||||
String materialCode = resources.getMaterialCode();
|
||||
MaterialInfo byMaterialCodeAndStatusTrue = materialInfoRepository.findByMaterialCodeAndStatusTrue(materialCode);
|
||||
if (null != byMaterialCodeAndStatusTrue) {
|
||||
throw new BadRequestException("物料编码已存在!");
|
||||
Long materialCategoryId = createMaterialInfoRequest.getMaterialCategoryId();
|
||||
if(null == materialCategoryId){
|
||||
throw new BadRequestException("物料类别不能为空!");
|
||||
}
|
||||
return materialInfoMapper.toDto(materialInfoRepository.save(resources));
|
||||
Optional<MaterialCategory> materialCategoryOptional = materialCategoryRepository.findById(materialCategoryId);
|
||||
MaterialCategory materialCategory = materialCategoryOptional.get();
|
||||
if(null == materialCategory){
|
||||
throw new BadRequestException("物料类别不存在!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
MaterialInfoDetailDTO materialInfoDetailDTO = new MaterialInfoDetailDTO();
|
||||
|
||||
MaterialInfo materialInfo = new MaterialInfo();
|
||||
BeanUtils.copyProperties(createMaterialInfoRequest, materialInfo);
|
||||
materialInfo.setStatus(true);
|
||||
List<MaterialInventoryWarning> materialInventoryWarningList = createMaterialInfoRequest.getMaterialInventoryWarningList();
|
||||
if(!CollectionUtils.isEmpty(materialInventoryWarningList)){
|
||||
String materialInventoryWarningStr = new Gson().toJson(materialInventoryWarningList);
|
||||
materialInfo.setMaterialInventoryWarning(materialInventoryWarningStr);
|
||||
materialInfoDetailDTO.setMaterialInventoryWarningList(materialInventoryWarningList);
|
||||
}
|
||||
List<MaterialInitialSetup> materialInitialSetupList = createMaterialInfoRequest.getMaterialInitialSetupList();
|
||||
if(!CollectionUtils.isEmpty(materialInitialSetupList)){
|
||||
String materialInitialSetupStr = new Gson().toJson(materialInitialSetupList);
|
||||
materialInfo.setMaterialInitialSetup(materialInitialSetupStr);
|
||||
materialInfoDetailDTO.setMaterialInitialSetupList(materialInitialSetupList);
|
||||
}
|
||||
|
||||
materialInfo.setMaterialCategoryName(materialCategory.getName());
|
||||
materialInfo.setMeasureUnitName(measureUnit.getName());
|
||||
|
||||
materialInfo = materialInfoRepository.save(materialInfo);
|
||||
MaterialInfoDTO materialInfoDTO = materialInfoMapper.toDto(materialInfo);
|
||||
BeanUtils.copyProperties(materialInfoDTO, materialInfoDetailDTO);
|
||||
return materialInfoDetailDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue