diff --git a/youchain-system/src/main/java/com/youchain/basicdata/repository/BigItemRepository.java b/youchain-system/src/main/java/com/youchain/basicdata/repository/BigItemRepository.java index 50abd86..6855d01 100644 --- a/youchain-system/src/main/java/com/youchain/basicdata/repository/BigItemRepository.java +++ b/youchain-system/src/main/java/com/youchain/basicdata/repository/BigItemRepository.java @@ -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, JpaSpecificationExecutor { - @Query(value = "SELECT i FROM BigItem i WHERE i.code = ?1 and i.name=?2", nativeQuery = false) - List findRepeat(String completeCode, String completeName); -} \ No newline at end of file + @Query(value = "SELECT i FROM BigItem i WHERE i.code = ?1 ") + BigItem findByBigItemCode(String completeCode); +} diff --git a/youchain-system/src/main/java/com/youchain/basicdata/repository/ItemRepository.java b/youchain-system/src/main/java/com/youchain/basicdata/repository/ItemRepository.java index 1acfd71..60832c2 100644 --- a/youchain-system/src/main/java/com/youchain/basicdata/repository/ItemRepository.java +++ b/youchain-system/src/main/java/com/youchain/basicdata/repository/ItemRepository.java @@ -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, JpaSpecificationExecutor { - @Query(value = "SELECT i FROM Item i WHERE i.code = ?1 and i.name=?2", nativeQuery = false) - List findRepeat(String code, String name); -} \ No newline at end of file + @Query(value = "FROM Item i WHERE i.code = ?1 ") + Item findByItemCode(String code); +} diff --git a/youchain-system/src/main/java/com/youchain/businessdata/repository/GdRepository.java b/youchain-system/src/main/java/com/youchain/businessdata/repository/GdRepository.java index eca9172..ad77b08 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/repository/GdRepository.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/repository/GdRepository.java @@ -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, JpaSpecificationExecutor { - /** 查询重复数据*/ - @Query(value = "SELECT g FROM Gd g WHERE g.code=?1 and g.name=?2 and g.station=?3 ", nativeQuery = false) - List findRepeat(String code, String name, String station); -} \ No newline at end of file + /** + * 查询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); +} diff --git a/youchain-system/src/main/java/com/youchain/businessdata/rest/MesController.java b/youchain-system/src/main/java/com/youchain/businessdata/rest/MesController.java index 7354b63..d20ad77 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/rest/MesController.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/rest/MesController.java @@ -57,17 +57,17 @@ public class MesController { @AnonymousAccess public ResponseEntity 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 blzc = yclbl.getBlzc(); for (ZcData zcData : blzc) { /* 验证成套 物料*/ - BigItem bigItem = verifiedBigItem(zcData.getCompleteCode(), zcData.getCompleteName()); + BigItem bigItem = verifiedBigItem(zcData.getCompleteCode()); Set 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 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 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 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; } } diff --git a/youchain-system/src/main/java/com/youchain/businessdata/service/GdService.java b/youchain-system/src/main/java/com/youchain/businessdata/service/GdService.java index daab055..01def4d 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/service/GdService.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/service/GdService.java @@ -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 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); -} \ No newline at end of file + + /** + * 原材料备料 + * @param yclbl 原材料备料 + */ + void materialBL(Yclbl yclbl); +} diff --git a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/GdServiceImpl.java b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/GdServiceImpl.java index c46b460..cfa90c9 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/GdServiceImpl.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/GdServiceImpl.java @@ -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 queryAll(GdQueryCriteria criteria, Pageable pageable){ - Page page = gdRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + public Map queryAll(GdQueryCriteria criteria, Pageable pageable) { + Page page = gdRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); return PageUtil.toPage(page.map(gdMapper::toDto)); } @Override - public List queryAll(GdQueryCriteria criteria){ - return gdMapper.toDto(gdRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + public List 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 all, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); for (GdDto gd : all) { - Map map = new LinkedHashMap<>(); + Map 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 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 gdDetailList=gdDetailRepository.findByGdAndQty(gd.getId()); - if (gdDetailList.size()<1){ + int no = 1;// 序号 + while (true) { + List gdDetailList = gdDetailRepository.findByGdAndQty(gd.getId()); + if (gdDetailList.size() < 1) { break; - }else { - List arr=new ArrayList();//已分配过的行号 + } else { + List arr = new ArrayList();//已分配过的行号 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); } } } } -} \ No newline at end of file + + @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 blzc = yclbl.getBlzc(); + for (ZcData zcData : blzc) { + BigItem bigItem = validateBigItem(zcData.getCompleteCode());//验证成品是否存在 + Set 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; + } +}