From 28838581688159bf0d3686ccce97d1d3a205963e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=90=8D=E5=96=9C?= Date: Thu, 7 Nov 2024 11:14:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=A7=92=E8=89=B2=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ktg-admin/src/test/MdItemUnitTest.java | 149 +++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 ktg-admin/src/test/MdItemUnitTest.java diff --git a/ktg-admin/src/test/MdItemUnitTest.java b/ktg-admin/src/test/MdItemUnitTest.java new file mode 100644 index 0000000..1645903 --- /dev/null +++ b/ktg-admin/src/test/MdItemUnitTest.java @@ -0,0 +1,149 @@ +import com.alibaba.fastjson.JSON; +import com.ktg.RuoYiApplication; +import com.ktg.common.core.domain.entity.ItemType; +import com.ktg.common.utils.StringUtils; +import com.ktg.mes.md.domain.MdItem; +import com.ktg.mes.md.domain.MdUnitMeasure; +import com.ktg.mes.md.mapper.ItemTypeMapper; +import com.ktg.mes.md.service.IMdItemService; +import com.ktg.mes.md.service.IMdUnitMeasureService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 角色管理单元测试 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class MdItemUnitTest { + @Autowired + private IMdItemService mdItemService; + + @Autowired + private ItemTypeMapper itemTypeMapper; + + @Autowired + private IMdUnitMeasureService mdUnitMeasureService; + + @Test + public void add() { + MdItem mdItem = new MdItem(); + mdItem.setItemTypeId(288L); + mdItem.setItemCode("IF20241107002"); + mdItem.setItemName("单元测试物料002"); + mdItem.setStandardNumber(10); + mdItem.setEnableFlag("Y"); + mdItem.setSafeStockFlag("N"); + mdItem.setMinStock((double) 0); + mdItem.setMaxStock((double) 0); + mdItem.setAttr1(5); + mdItem.setUnitOfMeasure("PCS"); + ItemType type = itemTypeMapper.selectItemTypeById(mdItem.getItemTypeId()); + if (StringUtils.isNotNull(type)) { + mdItem.setItemTypeCode(type.getItemTypeCode()); + mdItem.setItemTypeName(type.getItemTypeName()); + mdItem.setItemOrProduct(type.getItemOrProduct()); + } + MdUnitMeasure measure = mdUnitMeasureService.selectMdUnitByCode(mdItem.getUnitOfMeasure()); + if (StringUtils.isNotNull(measure)) { + mdItem.setUnitName(measure.getMeasureName()); + } + mdItemService.insertMdItem(mdItem); + System.out.println("add:" + mdItem.getItemId()); // 102 + } + + @Test + public void list() { + List list = mdItemService.selectMdItemList(new MdItem()); + System.out.println("list:" + JSON.toJSONString(list)); + } + + @Test + public void getInfo() { + System.out.println("getInfo:" + JSON.toJSONString(mdItemService.selectMdItemById(102L))); + } + + @Test + public void edit() { + MdItem mdItem = new MdItem(); + mdItem.setItemId(102L); + mdItem.setItemTypeId(288L); + mdItem.setItemName("单元测试物料001"); + mdItem.setStandardNumber(10); + mdItem.setEnableFlag("Y"); + mdItem.setSafeStockFlag("N"); + mdItem.setMinStock((double) 0); + mdItem.setMaxStock((double) 0); + mdItem.setAttr1(5); + mdItem.setUnitOfMeasure("PCS"); + ItemType type = itemTypeMapper.selectItemTypeById(mdItem.getItemTypeId()); + if (StringUtils.isNotNull(type)) { + mdItem.setItemTypeCode(type.getItemTypeCode()); + mdItem.setItemTypeName(type.getItemTypeName()); + mdItem.setItemOrProduct(type.getItemOrProduct()); + } + if (StringUtils.isNotNull(mdItem.getSafeStockFlag()) && "N".equals(mdItem.getSafeStockFlag())) { + mdItem.setMinStock(0D); + mdItem.setMaxStock(0D); + } + MdUnitMeasure measure = mdUnitMeasureService.selectMdUnitByCode(mdItem.getUnitOfMeasure()); + if (StringUtils.isNotNull(measure)) { + mdItem.setUnitName(measure.getMeasureName()); + } + int count = mdItemService.updateMdItem(mdItem); + System.out.println("edit:" + count); + } + + @Test + public void remove() { + Long[] ids = {102L}; + int count = mdItemService.deleteByItemIds(ids); + System.out.println("remove:" + count); + } + + @Test + public void selectItem() { + MdItem mdItem = new MdItem(); + mdItem.setItemOrProduct("ITEM"); + List list = mdItemService.selectMdItemList(mdItem); + List> result = new ArrayList<>(); + list.forEach(item -> { + Map map = new HashMap<>(); + map.put("gid", item.getItemId().toString()); + map.put("code", item.getItemCode()); + map.put("safeInventory", item.getMinStock().toString().split("\\.")[0]); + map.put("pmbbMeasure", item.getItemTypeName()); + map.put("name", item.getItemName()); + map.put("count", mdItemService.getMdItemCount(item.getItemId()).toString()); + result.add(map); + }); + System.out.println("selectItem:" + JSON.toJSONString(list)); + } + + @Test + public void selectProduct() { + MdItem mdItem = new MdItem(); + mdItem.setItemOrProduct("PRODUCT"); + List list = mdItemService.selectMdItemList(mdItem); + List> result = new ArrayList<>(); + list.forEach(item -> { + Map map = new HashMap<>(); + map.put("gid", item.getItemId().toString()); + map.put("code", item.getItemCode()); + map.put("safeInventory", item.getMinStock().toString().split("\\.")[0]); + map.put("pmbbMeasure", item.getItemTypeName()); + map.put("name", item.getItemName()); + map.put("count", mdItemService.getMdItemCount(item.getItemId()).toString()); + result.add(map); + }); + System.out.println("selectProduct:" + JSON.toJSONString(list)); + } +}