mirror of https://github.com/elunez/eladmin
客户资料
parent
1a35ef814a
commit
dccf6e9908
|
@ -0,0 +1,40 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class CreateCustomerInfoRequest implements Serializable {
|
||||
|
||||
// 客户名称
|
||||
private String customerName;
|
||||
|
||||
// 期初预收款
|
||||
private Long initialPreMoney;
|
||||
|
||||
// 客户编号
|
||||
private String customerCode;
|
||||
|
||||
// 创建时间
|
||||
private Timestamp createTime;
|
||||
|
||||
// 更新时间
|
||||
private Timestamp updateTime;
|
||||
|
||||
// 备注
|
||||
private String remark;
|
||||
|
||||
// 客户地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
|
||||
private List<CustomerAddress> supplierAddress;
|
||||
|
||||
// 客户联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
|
||||
private List<CustomerContact> customerContact;
|
||||
|
||||
}
|
|
@ -2,10 +2,6 @@ package me.zhengjie.modules.wms.bd.request;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-18
|
||||
*/
|
||||
@Data
|
||||
public class CustomerAddress implements Serializable {
|
||||
private String province;
|
||||
|
||||
private String city;
|
||||
|
||||
private String area;
|
||||
|
||||
private String addressDetail;
|
||||
|
||||
private Integer sort;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* [{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
|
||||
* @date 2019-08-18
|
||||
*/
|
||||
@Data
|
||||
public class CustomerContact implements Serializable {
|
||||
|
||||
private Integer sort;
|
||||
|
||||
private String name;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String email;
|
||||
|
||||
private String qq;
|
||||
|
||||
private String weixin;
|
||||
|
||||
private Integer firstTag;
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-08-03
|
||||
*/
|
||||
@Data
|
||||
public class UpdateCustomerInfoRequest implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
// 客户名称
|
||||
private String customerName;
|
||||
|
||||
// 期初预收款
|
||||
private Long initialPreMoney;
|
||||
|
||||
// 客户编号
|
||||
private String customerCode;
|
||||
|
||||
// 备注
|
||||
private String remark;
|
||||
|
||||
// 客户地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
|
||||
private List<CustomerAddress> customerAddress;
|
||||
|
||||
// 客户联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
|
||||
private List<CustomerContact> customerContact;
|
||||
|
||||
private Boolean status;
|
||||
|
||||
public void copy(UpdateCustomerInfoRequest source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@ 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.request.CreateCustomerInfoRequest;
|
||||
import me.zhengjie.modules.wms.bd.request.UpdateCustomerInfoRequest;
|
||||
import me.zhengjie.modules.wms.bd.service.CustomerInfoService;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -51,16 +53,16 @@ public class CustomerInfoController {
|
|||
@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);
|
||||
public ResponseEntity create(@RequestBody CreateCustomerInfoRequest createCustomerInfoRequest){
|
||||
return new ResponseEntity(customerInfoService.create(createCustomerInfoRequest),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);
|
||||
public ResponseEntity update(@RequestBody UpdateCustomerInfoRequest updateCustomerInfoRequest){
|
||||
customerInfoService.update(updateCustomerInfoRequest);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package me.zhengjie.modules.wms.bd.service;
|
||||
|
||||
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
|
||||
import me.zhengjie.modules.wms.bd.request.CreateCustomerInfoRequest;
|
||||
import me.zhengjie.modules.wms.bd.request.UpdateCustomerInfoRequest;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoDTO;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoDetailDTO;
|
||||
import me.zhengjie.modules.wms.bd.service.dto.CustomerInfoQueryCriteria;
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.CacheEvict;
|
||||
|
@ -38,22 +41,22 @@ public interface CustomerInfoService {
|
|||
* @return
|
||||
*/
|
||||
//@Cacheable(key = "#p0")
|
||||
CustomerInfoDTO findById(Long id);
|
||||
CustomerInfoDetailDTO findById(Long id);
|
||||
|
||||
/**
|
||||
* create
|
||||
* @param resources
|
||||
* @param createCustomerInfoRequest
|
||||
* @return
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
CustomerInfoDTO create(CustomerInfo resources);
|
||||
CustomerInfoDTO create(CreateCustomerInfoRequest createCustomerInfoRequest);
|
||||
|
||||
/**
|
||||
* update
|
||||
* @param resources
|
||||
* @param updateCustomerInfoRequest
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void update(CustomerInfo resources);
|
||||
void update(UpdateCustomerInfoRequest updateCustomerInfoRequest);
|
||||
|
||||
/**
|
||||
* delete
|
||||
|
|
|
@ -35,9 +35,4 @@ public class CustomerInfoDTO implements Serializable {
|
|||
// 状态
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package me.zhengjie.modules.wms.bd.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.modules.wms.bd.request.CustomerAddress;
|
||||
import me.zhengjie.modules.wms.bd.request.CustomerContact;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class CustomerInfoDetailDTO extends CustomerInfoDTO implements Serializable {
|
||||
|
||||
// 客户地址地址数组[{“province”:””,”city”:””,”area”:””,”address_detail”:””,”sort”:””}]
|
||||
private List<CustomerAddress> customerAddress;
|
||||
|
||||
// 客户联系人[{“sort”:””,”name”:””,”mobile”:””,”phone”:””,”email”:””,”qq”:””,”weixin”:””,”firstTag”:””}]firstTag 0:非首要联系人 1:首要联系人
|
||||
private List<CustomerContact> customerContact;
|
||||
}
|
|
@ -1,21 +1,29 @@
|
|||
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.ProductInfo;
|
||||
import me.zhengjie.modules.wms.bd.domain.SupplierCategory;
|
||||
import me.zhengjie.modules.wms.bd.domain.SupplierInfo;
|
||||
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.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.BeanUtils;
|
||||
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.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -104,30 +112,101 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CustomerInfoDTO findById(Long id) {
|
||||
public CustomerInfoDetailDTO findById(Long id) {
|
||||
CustomerInfoDetailDTO customerInfoDetailDTO = new CustomerInfoDetailDTO();
|
||||
|
||||
Optional<CustomerInfo> customerInfoOptional = customerInfoRepository.findById(id);
|
||||
ValidationUtil.isNull(customerInfoOptional,"customerInfo","id",id);
|
||||
CustomerInfo customerInfo = customerInfoOptional.get();
|
||||
customerInfoMapper.toDto(customerInfo);
|
||||
return customerInfoMapper.toDto(customerInfo);
|
||||
}
|
||||
|
||||
@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;
|
||||
if(null != customerInfoDTO){
|
||||
BeanUtils.copyProperties( customerInfoDTO, customerInfoDetailDTO);
|
||||
String customerAddressJsonStr = customerInfo.getCustomerAddress();
|
||||
if(StringUtils.hasLength(customerAddressJsonStr)){
|
||||
List<CustomerAddress> customerAddressList = new Gson().fromJson(customerAddressJsonStr,new TypeToken<ArrayList<SupplierAddress>>() {}.getType());
|
||||
customerInfoDetailDTO.setCustomerAddress(customerAddressList);
|
||||
}
|
||||
|
||||
|
||||
String customerContactJsonStr = customerInfo.getCustomerContact();
|
||||
if(StringUtils.hasLength(customerContactJsonStr)){
|
||||
List<CustomerContact> customerContactList = new Gson().fromJson(customerContactJsonStr,new TypeToken<ArrayList<SupplierContact>>() {}.getType());
|
||||
customerInfoDetailDTO.setCustomerContact(customerContactList);
|
||||
}
|
||||
}
|
||||
return customerInfoDetailDTO;
|
||||
}
|
||||
|
||||
@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);
|
||||
public CustomerInfoDTO create(CreateCustomerInfoRequest createCustomerInfoRequest) {
|
||||
CustomerInfoDetailDTO customerInfoDetailDTO = new CustomerInfoDetailDTO();
|
||||
|
||||
CustomerInfo customerInfo = new CustomerInfo();
|
||||
BeanUtils.copyProperties(createCustomerInfoRequest, customerInfo);
|
||||
customerInfo.setStatus(true);
|
||||
List<CustomerAddress> customerAddressList = createCustomerInfoRequest.getSupplierAddress();
|
||||
if(!CollectionUtils.isEmpty(customerAddressList)){
|
||||
String customerAddressStr = new Gson().toJson(customerAddressList);
|
||||
customerInfo.setCustomerAddress(customerAddressStr);
|
||||
customerInfoDetailDTO.setCustomerAddress(customerAddressList);
|
||||
}
|
||||
List<CustomerContact> customerContactList = createCustomerInfoRequest.getCustomerContact();
|
||||
if(!CollectionUtils.isEmpty(customerContactList)){
|
||||
String customerContactStr = new Gson().toJson(customerContactList);
|
||||
customerInfo.setCustomerContact(customerContactStr);
|
||||
customerInfoDetailDTO.setCustomerContact(customerContactList);
|
||||
}
|
||||
|
||||
customerInfo = customerInfoRepository.save(customerInfo);
|
||||
CustomerInfoDTO customerInfoDTO = customerInfoMapper.toDto(customerInfo);
|
||||
BeanUtils.copyProperties(customerInfoDTO, customerInfoDetailDTO);
|
||||
return customerInfoDetailDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(UpdateCustomerInfoRequest updateCustomerInfoRequest) {
|
||||
Long customerInfoId = updateCustomerInfoRequest.getId();
|
||||
if(null == customerInfoId){
|
||||
throw new BadRequestException("客户主键不能为空!");
|
||||
}
|
||||
|
||||
// 客户资料-客户联系地址修改目标
|
||||
List<CustomerAddress> customerAddressListUpdateTarget = updateCustomerInfoRequest.getCustomerAddress();
|
||||
// 供应商资料-供应商联系方式修改目标
|
||||
List<CustomerContact> customerContactListUpdateTarget = updateCustomerInfoRequest.getCustomerContact();
|
||||
|
||||
CustomerInfo customerInfo = customerInfoRepository.findByIdAndStatusTrue(customerInfoId);
|
||||
|
||||
if(null == customerInfo){
|
||||
throw new BadRequestException("客户不存在");
|
||||
}
|
||||
|
||||
Timestamp createTime = customerInfo.getCreateTime();
|
||||
|
||||
// 将需要修改的值复制到数据库对象中
|
||||
BeanUtils.copyProperties(updateCustomerInfoRequest, customerInfo);
|
||||
|
||||
// 判断提前获取的供应商联系地址和联系方式是否是空
|
||||
if(CollectionUtils.isEmpty(customerAddressListUpdateTarget)){
|
||||
customerInfo.setCustomerAddress(null);
|
||||
}else{
|
||||
String supplierAddressStr = new Gson().toJson(customerAddressListUpdateTarget);
|
||||
customerInfo.setCustomerContact(supplierAddressStr);
|
||||
}
|
||||
|
||||
if(CollectionUtils.isEmpty(customerContactListUpdateTarget)){
|
||||
customerInfo.setCustomerContact(null);
|
||||
}else{
|
||||
String supplierContactStr = new Gson().toJson(customerContactListUpdateTarget);
|
||||
customerInfo.setCustomerContact(supplierContactStr);
|
||||
}
|
||||
|
||||
customerInfo.setCreateTime(createTime);
|
||||
customerInfo.setStatus(true);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
customerInfo.setUpdateTime(Timestamp.valueOf(sdf.format(new Date())));
|
||||
// 修改客户资料
|
||||
customerInfoRepository.save(customerInfo);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue