新增供应商资料

pull/451/head
starrysky 2019-08-18 22:43:47 +08:00
parent d2304e60d5
commit 4169db81ca
3 changed files with 55 additions and 7 deletions

View File

@ -37,12 +37,6 @@ public class SupplierInfoDTO implements Serializable {
// 备注
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;
// 供应商类别主键

View File

@ -0,0 +1,27 @@
package me.zhengjie.modules.wms.bd.service.dto;
import lombok.Data;
import me.zhengjie.modules.wms.bd.request.SupplierAddress;
import me.zhengjie.modules.wms.bd.request.SupplierContact;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
/**
* @author jie
* @date 2019-08-03
*/
@Data
public class SupplierInfoDetailDTO extends SupplierInfoDTO implements Serializable {
// 供应商地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
private List<SupplierAddress> supplierAddress;
// 供应商联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
private List<SupplierContact> supplierContact;
}

View File

@ -1,12 +1,17 @@
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.CustomerInfo;
import me.zhengjie.modules.wms.bd.domain.SupplierCategory;
import me.zhengjie.modules.wms.bd.domain.SupplierInfo;
import me.zhengjie.modules.wms.bd.repository.SupplierCategoryRepository;
import me.zhengjie.modules.wms.bd.request.CreateSupplierInfoRequest;
import me.zhengjie.modules.wms.bd.request.SupplierAddress;
import me.zhengjie.modules.wms.bd.request.SupplierContact;
import me.zhengjie.modules.wms.bd.service.dto.SupplierInfoDetailDTO;
import me.zhengjie.modules.wms.bd.service.mapper.SupplierCategoryMapper;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.wms.bd.repository.SupplierInfoRepository;
import me.zhengjie.modules.wms.bd.service.SupplierInfoService;
@ -28,6 +33,7 @@ import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
@ -48,6 +54,12 @@ public class SupplierInfoServiceImpl implements SupplierInfoService {
@Autowired
private SupplierInfoMapper supplierInfoMapper;
@Autowired
private SupplierCategoryMapper supplierCategoryMapper;
@Autowired
private SupplierCategoryRepository supplierCategoryRepository;
@Override
public Object queryAll(SupplierInfoQueryCriteria criteria, Pageable pageable){
Specification<SupplierInfo> specification = new Specification<SupplierInfo>() {
@ -101,6 +113,15 @@ public class SupplierInfoServiceImpl implements SupplierInfoService {
@Override
@Transactional(rollbackFor = Exception.class)
public SupplierInfoDTO create(CreateSupplierInfoRequest createSupplierInfoRequest) {
Long supplierCategoryId = createSupplierInfoRequest.getSupplierCategoryId();
if(null == supplierCategoryId){
throw new BadRequestException("供应商类别不存在!");
}
Optional<SupplierCategory> supplierCategoryOptional = supplierCategoryRepository.findById(supplierCategoryId);
SupplierCategory supplierCategory = supplierCategoryOptional.get();
SupplierInfoDetailDTO supplierInfoDetailDTO = new SupplierInfoDetailDTO();
SupplierInfo supplierInfo = new SupplierInfo();
BeanUtils.copyProperties(createSupplierInfoRequest, supplierInfo);
supplierInfo.setStatus(true);
@ -108,15 +129,21 @@ public class SupplierInfoServiceImpl implements SupplierInfoService {
if(!CollectionUtils.isEmpty(supplierAddressList)){
String supplierAddressStr = new Gson().toJson(supplierAddressList);
supplierInfo.setSupplierAddress(supplierAddressStr);
supplierInfoDetailDTO.setSupplierAddress(supplierAddressList);
}
List<SupplierContact> supplierContactList = createSupplierInfoRequest.getSupplierContact();
if(!CollectionUtils.isEmpty(supplierContactList)){
String supplierContactStr = new Gson().toJson(supplierContactList);
supplierInfo.setSupplierContact(supplierContactStr);
supplierInfoDetailDTO.setSupplierContact(supplierContactList);
}
supplierInfo.setSupplierCategoryName(supplierCategory.getName());
supplierInfo = supplierInfoRepository.save(supplierInfo);
SupplierInfoDTO supplierInfoDTO = supplierInfoMapper.toDto(supplierInfo);
return supplierInfoDTO;
BeanUtils.copyProperties(supplierInfoDTO, supplierInfoDetailDTO);
return supplierInfoDetailDTO;
}
@Override