no message

main
HUOJIN\92525 2024-06-21 17:59:43 +08:00
parent c3dcafc53f
commit 7a418eda87
6 changed files with 212 additions and 131 deletions

View File

@ -1,18 +1,18 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.repository;
import com.youchain.basicdata.domain.BigItem;
@ -24,11 +24,11 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @website https://eladmin.vip
* @author shenyinan
* @date 2024-02-21
**/
* @author shenyinan
* @website https://eladmin.vip
* @date 2024-02-21
**/
public interface BigItemRepository extends JpaRepository<BigItem, Long>, JpaSpecificationExecutor<BigItem> {
@Query(value = "SELECT i FROM BigItem i WHERE i.code = ?1 and i.name=?2", nativeQuery = false)
List<BigItem> findRepeat(String completeCode, String completeName);
@Query(value = "SELECT i FROM BigItem i WHERE i.code = ?1 ")
BigItem findByBigItemCode(String completeCode);
}

View File

@ -1,18 +1,18 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.repository;
import com.youchain.basicdata.domain.Item;
@ -23,11 +23,11 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @website https://eladmin.vip
* @author houjianlan
* @date 2023-08-16
**/
* @author houjianlan
* @website https://eladmin.vip
* @date 2023-08-16
**/
public interface ItemRepository extends JpaRepository<Item, Long>, JpaSpecificationExecutor<Item> {
@Query(value = "SELECT i FROM Item i WHERE i.code = ?1 and i.name=?2", nativeQuery = false)
List<Item> findRepeat(String code, String name);
@Query(value = "FROM Item i WHERE i.code = ?1 ")
Item findByItemCode(String code);
}

View File

@ -1,18 +1,18 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.businessdata.repository;
import com.youchain.businessdata.domain.Gd;
@ -23,12 +23,18 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @website https://eladmin.vip
* @author huojin
* @date 2024-06-06
**/
* @author huojin
* @website https://eladmin.vip
* @date 2024-06-06
**/
public interface GdRepository extends JpaRepository<Gd, Long>, JpaSpecificationExecutor<Gd> {
/** 查询重复数据*/
@Query(value = "SELECT g FROM Gd g WHERE g.code=?1 and g.name=?2 and g.station=?3 ", nativeQuery = false)
List<Gd> findRepeat(String code, String name, String station);
/**
* gd
* @param code
* @param name
* @param station
* @return
*/
@Query(value = " FROM Gd g WHERE g.code=?1 and g.name=?2 and g.station=?3 ")
Gd findByGdList(String code, String name, String station);
}

View File

@ -57,17 +57,17 @@ public class MesController {
@AnonymousAccess
public ResponseEntity<Object> yclbl(@Validated @RequestBody Yclbl yclbl) {
/* 添加工单单头*/
Gd gd = gdService.save(yclbl.getOrderNo(), yclbl.getTaskCode(), yclbl.getStation());
Gd gd = gdService.createGd(yclbl.getOrderNo(), yclbl.getTaskCode(), yclbl.getStation());
if (yclbl.getBlzc() != null) {
String orderType = BaseStatus.GD_TYPE_CT;
Set<ZcData> blzc = yclbl.getBlzc();
for (ZcData zcData : blzc) {
/* 验证成套 物料*/
BigItem bigItem = verifiedBigItem(zcData.getCompleteCode(), zcData.getCompleteName());
BigItem bigItem = verifiedBigItem(zcData.getCompleteCode());
Set<ItemDate> itemDates = zcData.getBlzcmx();
for (ItemDate itemDate : itemDates) {
/* 验证单品 物料*/
Item item = verifiedItem(itemDate.getItemCode(), itemDate.getItemName());
Item item = verifiedItem(itemDate.getItemCode());
/* 验证BOM*/
BigBom bigBom = verifiedBigBom(bigItem, item, itemDate.getItemQty());
/* 添加工单明细*/
@ -80,7 +80,7 @@ public class MesController {
Set<ItemDate> itemDateList = yclbl.getBlzcmx();
for (ItemDate itemDate : itemDateList) {
/* 验证单品物料*/
Item item = verifiedItem(itemDate.getItemCode(), itemDate.getItemName());
Item item = verifiedItem(itemDate.getItemCode());
/* 添加工单明细*/
GdDetail gdDetail = gdDetailService.save(itemDate.getLineNo(), gd, orderType, null, null, item, itemDate.getItemQty(), itemDate.getItemQty());
}
@ -156,21 +156,21 @@ public class MesController {
/**
*
*/
private BigItem verifiedBigItem(String completeCode, String completeName) {
List<BigItem> bigItemList = bigItemRepository.findRepeat(completeCode, completeName);
if (bigItemList.size() > 0) {
return bigItemList.get(0);
} else {
private BigItem verifiedBigItem(String completeCode) {
BigItem bigItem = bigItemRepository.findByBigItemCode(completeCode);
if (bigItem == null) {
throw new BadRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "未维护成套物料" + completeCode);
} else {
return bigItem;
}
}
private Item verifiedItem(String itemCode, String itemName) {
List<Item> itemList = itemRepository.findRepeat(itemCode, itemName);
if (itemList.size() > 0) {
return itemList.get(0);
} else {
private Item verifiedItem(String itemCode) {
Item item = itemRepository.findByItemCode(itemCode);
if (item == null) {
throw new BadRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "未维护单品物料" + itemCode);
} else {
return item;
}
}

View File

@ -15,6 +15,7 @@
*/
package com.youchain.businessdata.service;
import com.youchain.RequestData.Yclbl;
import com.youchain.businessdata.domain.Gd;
import com.youchain.businessdata.service.dto.GdDto;
import com.youchain.businessdata.service.dto.GdQueryCriteria;
@ -81,8 +82,14 @@ public interface GdService {
*/
void download(List<GdDto> all, HttpServletResponse response) throws IOException;
Gd save(String orderNo, String taskCode, String station);
Gd createGd(String orderNo, String taskCode, String station);
/** 根据工单,申城出库明细*/
void addPickDetail(Gd gd);
/**
*
* @param yclbl
*/
void materialBL(Yclbl yclbl);
}

View File

@ -1,21 +1,28 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.businessdata.service.impl;
import com.youchain.RequestData.ItemDate;
import com.youchain.RequestData.Yclbl;
import com.youchain.RequestData.ZcData;
import com.youchain.basicdata.domain.BigItem;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.repository.BigItemRepository;
import com.youchain.basicdata.repository.ItemRepository;
import com.youchain.basicdata.repository.PointRepository;
import com.youchain.businessdata.domain.Gd;
import com.youchain.businessdata.domain.GdDetail;
@ -24,7 +31,7 @@ import com.youchain.businessdata.repository.GdDetailRepository;
import com.youchain.businessdata.repository.PickRepository;
import com.youchain.businessdata.service.PickDetailService;
import com.youchain.businessdata.service.PickService;
import com.youchain.modules.system.domain.Dept;
import com.youchain.exception.BadRequestException;
import com.youchain.modules.system.service.DeptService;
import com.youchain.utils.*;
import lombok.RequiredArgsConstructor;
@ -33,6 +40,7 @@ import com.youchain.businessdata.service.GdService;
import com.youchain.businessdata.service.dto.GdDto;
import com.youchain.businessdata.service.dto.GdQueryCriteria;
import com.youchain.businessdata.service.mapstruct.GdMapper;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
@ -43,40 +51,43 @@ import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @description
* @author huojin
* @date 2024-06-06
**/
* @author huojin
* @website https://eladmin.vip
* @description
* @date 2024-06-06
**/
@Service
@RequiredArgsConstructor
public class GdServiceImpl implements GdService {
private final GdRepository gdRepository;
private final GdDetailRepository gdDetailRepository;
private final BigItemRepository bigItemRepository;
private final ItemRepository itemRepository;
private final PickService pickService;
private final PickRepository pickRepository;
private final PointRepository pointRepository;
private final PickDetailService pickDetailService;
private final DeptService deptService;
private final GdMapper gdMapper;
private final RedisObjectUtils redisObjectUtils;
@Override
public Map<String,Object> queryAll(GdQueryCriteria criteria, Pageable pageable){
Page<Gd> page = gdRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
public Map<String, Object> queryAll(GdQueryCriteria criteria, Pageable pageable) {
Page<Gd> page = gdRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
return PageUtil.toPage(page.map(gdMapper::toDto));
}
@Override
public List<GdDto> queryAll(GdQueryCriteria criteria){
return gdMapper.toDto(gdRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
public List<GdDto> queryAll(GdQueryCriteria criteria) {
return gdMapper.toDto(gdRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
}
@Override
@Transactional
public GdDto findById(Long id) {
Gd gd = gdRepository.findById(id).orElseGet(Gd::new);
ValidationUtil.isNull(gd.getId(),"Gd","id",id);
ValidationUtil.isNull(gd.getId(), "Gd", "id", id);
return gdMapper.toDto(gd);
}
@ -90,7 +101,7 @@ public class GdServiceImpl implements GdService {
@Transactional(rollbackFor = Exception.class)
public void update(Gd resources) {
Gd gd = gdRepository.findById(resources.getId()).orElseGet(Gd::new);
ValidationUtil.isNull( gd.getId(),"Gd","id",resources.getId());
ValidationUtil.isNull(gd.getId(), "Gd", "id", resources.getId());
gd.copy(resources);
gdRepository.save(gd);
}
@ -106,7 +117,7 @@ public class GdServiceImpl implements GdService {
public void download(List<GdDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (GdDto gd : all) {
Map<String,Object> map = new LinkedHashMap<>();
Map<String, Object> map = new LinkedHashMap<>();
map.put("创建人", gd.getCreateBy());
map.put("修改人", gd.getUpdateBy());
map.put("创建时间", gd.getCreateTime());
@ -121,49 +132,106 @@ public class GdServiceImpl implements GdService {
}
@Override
public Gd save(String orderNo, String taskCode, String station) {
List<Gd> gdList=gdRepository.findRepeat(orderNo,taskCode,station);
if (gdList.size()>0){
return gdList.get(0);
}else {
Gd gd=new Gd();
gd.setCode(orderNo);
gd.setName(taskCode);
gd.setStation(station);
gd.setStatus(BizStatus.OPEN);
gd.setDept(deptService.isDept());
gdRepository.save(gd);
return gd;
}
@Transactional(rollbackFor = Exception.class)
public Gd createGd(String orderNo, String taskCode, String station) {
Gd gd = new Gd();
gd.setCode(orderNo);
gd.setName(taskCode);
gd.setStation(station);
gd.setStatus(BizStatus.OPEN);
gd.setDept(deptService.isDept());
gdRepository.save(gd);
return gd;
}
@Override
public void addPickDetail(Gd gd) {
int no=1;// 序号
while (true){
List<GdDetail> gdDetailList=gdDetailRepository.findByGdAndQty(gd.getId());
if (gdDetailList.size()<1){
int no = 1;// 序号
while (true) {
List<GdDetail> gdDetailList = gdDetailRepository.findByGdAndQty(gd.getId());
if (gdDetailList.size() < 1) {
break;
}else {
List<Integer> arr=new ArrayList<Integer>();//已分配过的行号
} else {
List<Integer> arr = new ArrayList<Integer>();//已分配过的行号
for (GdDetail gdDetail : gdDetailList) {
/*本次循环已拆分过 工单明细行*/
if (arr.contains(gdDetail.getLineNo())){
if (arr.contains(gdDetail.getLineNo())) {
continue;
}
/*生成出库单*/
Pick pick = pickService.save(gdDetail, no);
/* 去重*/
arr.add(gdDetail.getLineNo());
no=no+1;
no = no + 1;
/*生成出库明细*/
pickDetailService.save(pick);
/*添加 默认目标备料点位*/
Point point=pointRepository.getById(2195l);
Point point = pointRepository.getById(2195l);
pick.setPoint(point);
pickRepository.save(pick);
}
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void materialBL(Yclbl yclbl) {
validateGd(yclbl);//验证参数有效性
Gd gd = gdRepository.findByGdList(yclbl.getOrderNo(), yclbl.getTaskCode(), yclbl.getStation());//查询备料工单是否存在
if (gd != null) {
throw new IllegalArgumentException(yclbl.getOrderNo() + "备料工单已存在!");
}
this.createGd(yclbl.getOrderNo(), yclbl.getTaskCode(), yclbl.getStation());//创建备料工单
//添加备料明细
if (!yclbl.getBlzc().isEmpty()) {
String orderType = BaseStatus.GD_TYPE_CT;
Set<ZcData> blzc = yclbl.getBlzc();
for (ZcData zcData : blzc) {
BigItem bigItem = validateBigItem(zcData.getCompleteCode());//验证成品是否存在
Set<ItemDate> itemDates = zcData.getBlzcmx();
for (ItemDate itemDate : itemDates) {
Item item = validateItem(itemDate.getItemCode());//验证单品是否存在
}
}
}
}
private void validateGd(Yclbl yclbl) {
if (StringUtils.isEmpty(yclbl.getOrderNo())) {
throw new IllegalArgumentException("工单号不能为空!");
}
if (StringUtils.isEmpty(yclbl.getTaskCode())) {
throw new IllegalArgumentException("任务号不能为空!");
}
if (StringUtils.isEmpty(yclbl.getStation())) {
throw new IllegalArgumentException("需求工位不能为空!");
}
if (yclbl.getBlzc().isEmpty() && yclbl.getBlzcmx().isEmpty()) {
throw new IllegalArgumentException("成品明细和单品明细不能为空!");
}
if (!yclbl.getBlzc().isEmpty()) {
for (ZcData zcData : yclbl.getBlzc()) {
if (zcData.getBlzcmx().isEmpty()) {
throw new IllegalArgumentException("成品明细里面的单品明细不能为空!");
}
}
}
}
private BigItem validateBigItem(String completeCode) {
BigItem bigItem = redisObjectUtils.getObjectFromCache(completeCode, () -> bigItemRepository.findByBigItemCode(completeCode), completeCode + "成品物料不存在,请维护!");
return bigItem;
}
private Item validateItem(String itemCode) {
Item item = redisObjectUtils.getObjectFromCache(itemCode, () -> itemRepository.findByItemCode(itemCode), itemCode + "单品物料不存在,请维护!");
return item;
}
}