mirror of https://github.com/elunez/eladmin
更新委外验收单
parent
f90fae0fd2
commit
72175a7d9a
|
@ -0,0 +1,41 @@
|
|||
package me.zhengjie.modules.wms.outSourceProductSheet.request;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Data;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.service.dto.OutSourceInspectionCertificateProductDTO;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-10-01
|
||||
*/
|
||||
@Data
|
||||
public class UpdateOutSourceInspectionCertificateRequest implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
|
||||
// 所属委外加工单
|
||||
private Long outSourceProcessSheetId;
|
||||
|
||||
// 制单人
|
||||
private Long makePeopleId;
|
||||
|
||||
// 制单人姓名
|
||||
private String makePeopleName;
|
||||
|
||||
// 委外加工验收单单据编号
|
||||
private String outSourceInspectionCertificateCode;
|
||||
|
||||
private String remark;
|
||||
|
||||
// 委外验收单产品信息
|
||||
private List<OutSourceInspectionCertificateProductDTO> outSourceInspectionCertificateProductList;
|
||||
|
||||
public void copy(UpdateOutSourceInspectionCertificateRequest source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package me.zhengjie.modules.wms.outSourceProductSheet.rest;
|
|||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.domain.OutSourceInspectionCertificate;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.CreateOutSourceInspectionCertificateRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.UpdateOutSourceInspectionCertificateRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.service.OutSourceInspectionCertificateService;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.service.dto.OutSourceInspectionCertificateQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -46,8 +47,8 @@ public class OutSourceInspectionCertificateController {
|
|||
@ApiOperation(value = "修改委外验收单")
|
||||
@PutMapping(value = "/outSourceInspectionCertificate")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','SOUTSOURCEINSPECTIONCERTIFICATE_ALL','SOUTSOURCEINSPECTIONCERTIFICATE_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody OutSourceInspectionCertificate resources){
|
||||
outSourceInspectionCertificateService.update(resources);
|
||||
public ResponseEntity update(@Validated @RequestBody UpdateOutSourceInspectionCertificateRequest updateOutSourceInspectionCertificateRequest){
|
||||
outSourceInspectionCertificateService.update(updateOutSourceInspectionCertificateRequest);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package me.zhengjie.modules.wms.outSourceProductSheet.service;
|
|||
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.domain.OutSourceInspectionCertificate;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.CreateOutSourceInspectionCertificateRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.UpdateOutSourceInspectionCertificateRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.service.dto.OutSourceInspectionCertificateDTO;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.service.dto.OutSourceInspectionCertificateQueryCriteria;
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
|
@ -51,10 +52,10 @@ public interface OutSourceInspectionCertificateService {
|
|||
|
||||
/**
|
||||
* update
|
||||
* @param resources
|
||||
* @param updateOutSourceInspectionCertificateRequest
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void update(OutSourceInspectionCertificate resources);
|
||||
void update(UpdateOutSourceInspectionCertificateRequest updateOutSourceInspectionCertificateRequest);
|
||||
|
||||
/**
|
||||
* delete
|
||||
|
|
|
@ -6,10 +6,7 @@ import me.zhengjie.modules.wms.outSourceProductSheet.domain.OutSourceInspectionC
|
|||
import me.zhengjie.modules.wms.outSourceProductSheet.domain.OutSourceProcessSheet;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.domain.OutSourceProcessSheetProduct;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.repository.OutSourceInspectionCertificateProductRepository;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.CreateOutSourceInspectionCertificateRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.CreateOutSourceProcessSheetRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.OutSourceInspectionCertificateProductRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.OutSourceProcessSheetProductRequest;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.request.*;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.service.dto.*;
|
||||
import me.zhengjie.modules.wms.outSourceProductSheet.service.mapper.OutSourceInspectionCertificateProductMapper;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
|
@ -25,7 +22,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
|
@ -167,12 +168,63 @@ public class OutSourceInspectionCertificateServiceImpl implements OutSourceInspe
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(OutSourceInspectionCertificate resources) {
|
||||
Optional<OutSourceInspectionCertificate> optionalSOutSourceInspectionCertificate = outSourceInspectionCertificateRepository.findById(resources.getId());
|
||||
ValidationUtil.isNull( optionalSOutSourceInspectionCertificate,"SOutSourceInspectionCertificate","id",resources.getId());
|
||||
OutSourceInspectionCertificate outSourceInspectionCertificate = optionalSOutSourceInspectionCertificate.get();
|
||||
outSourceInspectionCertificate.copy(resources);
|
||||
public void update(UpdateOutSourceInspectionCertificateRequest updateOutSourceInspectionCertificateRequest) {
|
||||
OutSourceInspectionCertificate outSourceInspectionCertificate = new OutSourceInspectionCertificate();
|
||||
BeanUtils.copyProperties(updateOutSourceInspectionCertificateRequest, outSourceInspectionCertificate);
|
||||
|
||||
outSourceInspectionCertificate.setStatus(true);
|
||||
|
||||
outSourceInspectionCertificateRepository.save(outSourceInspectionCertificate);
|
||||
|
||||
// 修改产品信息之前,查询该订单中原来的产品信息,key为产品code
|
||||
List<OutSourceInspectionCertificateProduct> outSourceInspectionCertificateProductListBeforeUpdate = outSourceInspectionCertificateProductRepository.queryByOutSourceInspectionCertificateIdAndStatusTrue(outSourceInspectionCertificate.getId());
|
||||
Map<String, OutSourceInspectionCertificateProduct> outSourceInspectionCertificateProductMapBefore = outSourceInspectionCertificateProductListBeforeUpdate.stream().collect(Collectors.toMap(OutSourceInspectionCertificateProduct::getProductCode, Function.identity()));
|
||||
|
||||
List<OutSourceInspectionCertificateProductDTO> outSourceInspectionCertificateProductRequestList = updateOutSourceInspectionCertificateRequest.getOutSourceInspectionCertificateProductList();
|
||||
if(CollectionUtils.isEmpty(outSourceInspectionCertificateProductRequestList)){
|
||||
throw new BadRequestException("委外验收单产品不能为空!");
|
||||
}
|
||||
|
||||
Map<String, OutSourceInspectionCertificateProductDTO> invoiceProductMapAfter = outSourceInspectionCertificateProductRequestList.stream().collect(Collectors.toMap(OutSourceInspectionCertificateProductDTO::getProductCode, Function.identity()));
|
||||
|
||||
//需要将订单中原来订单对应的产品删除了的数据
|
||||
List<String> deleteTargetList = new ArrayList<>();
|
||||
//比较量个map中,key不一样的数据
|
||||
for(Map.Entry<String, OutSourceInspectionCertificateProduct> entry:outSourceInspectionCertificateProductMapBefore.entrySet()){
|
||||
String productCode = entry.getKey();
|
||||
//修改后的map记录对应的key在原来中是否存在
|
||||
OutSourceInspectionCertificateProductDTO outSourceInspectionCertificateProductDTOTemp = invoiceProductMapAfter.get(productCode);
|
||||
if(null == outSourceInspectionCertificateProductDTOTemp){
|
||||
deleteTargetList.add(entry.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
List<OutSourceInspectionCertificateProduct> outSourceInspectionCertificateProductList = new ArrayList<>();
|
||||
for(OutSourceInspectionCertificateProductDTO outSourceInspectionCertificateProductDTO : outSourceInspectionCertificateProductRequestList){
|
||||
OutSourceInspectionCertificateProduct outSourceInspectionCertificateProduct = new OutSourceInspectionCertificateProduct();
|
||||
BeanUtils.copyProperties(outSourceInspectionCertificateProductDTO, outSourceInspectionCertificateProduct);
|
||||
outSourceInspectionCertificateProduct.setOutSourceInspectionCertificateId(outSourceInspectionCertificate.getId());
|
||||
outSourceInspectionCertificateProduct.setStatus(true);
|
||||
|
||||
if(!(!CollectionUtils.isEmpty(deleteTargetList) && deleteTargetList.contains(outSourceInspectionCertificateProductDTO.getId()))){
|
||||
outSourceInspectionCertificateProductList.add(outSourceInspectionCertificateProduct);
|
||||
}
|
||||
}
|
||||
outSourceInspectionCertificateProductRepository.saveAll(outSourceInspectionCertificateProductList);
|
||||
|
||||
/**
|
||||
* 场景描述:
|
||||
* 1.刚开始新增了 a b c三种产品
|
||||
* 2.修改的时候删除了 a c两种产品
|
||||
* 3.所以需要查修改前数据库中有的产品,再比较修改传过来的产品数据,如果修改后的在原来里面没有,需要将原来里面对应的删除
|
||||
*/
|
||||
if(!CollectionUtils.isEmpty(deleteTargetList)){
|
||||
for(String prductCode : deleteTargetList){
|
||||
outSourceInspectionCertificateProductRepository.deleteByProductCodeAndOutSourceInspectionCertificateId(prductCode, outSourceInspectionCertificate.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue