物料产品导出导入功能

This commit is contained in:
yinjinlu-pc\尹金路 2024-09-06 15:25:02 +08:00
parent 1b1215080e
commit 902814c027
12 changed files with 120 additions and 42 deletions

View File

@ -62,7 +62,7 @@ public class MdItemController extends BaseController {
@PostMapping("/export")
public void export(HttpServletResponse response, MdItem mdItem)
{
List<MdItem> list = mdItemService.selectMdItemList(mdItem);
List<MdItem> list = mdItemService.getExeportList(mdItem);
ExcelUtil<MdItem> util = new ExcelUtil<MdItem>(MdItem.class);
util.exportExcel(response, list, "物料产品数据");
}

View File

@ -25,7 +25,6 @@ public class MdItem extends BaseEntity {
private String unitName;
private String itemOrProduct;
private Long itemTypeId;
@Excel(name = "分类编码")
private String itemTypeCode;
@Excel(name = "分类名称")
private String itemTypeName;
@ -47,7 +46,6 @@ public class MdItem extends BaseEntity {
this.itemId = itemId;
}
@NotBlank(message = "物料产品编码不能为空")
@Size(min = 0,max = 64,message = "物料产品编码长度不能超过64个字符")
public String getItemCode() {
return itemCode;
@ -76,7 +74,7 @@ public class MdItem extends BaseEntity {
this.specification = specification;
}
@NotBlank(message = "单位不能为空")
@NotBlank(message = "单位编码不能为空")
public String getUnitOfMeasure() {
return unitOfMeasure;
}

View File

@ -21,6 +21,14 @@ public interface ItemTypeMapper {
*/
public ItemType selectItemTypeById(Long itemTypeId);
/**
* 根据分类名称查找分类
* 在重名的情况下支持按上级分类/下级分类的模式进行查找
* @param itemTypeName
* @return
*/
public List<ItemType> selectItemTypeByName(String itemTypeName);
/**
* 根据父类ID查询是否有子类
* @param parentTypeId

View File

@ -19,6 +19,9 @@ public interface MdItemMapper {
public List<MdItem> selectMdItemAll();
public List<MdItem> getExeportList(MdItem mdItem);
/**
* 根据物料ID查询物料
* @param itemId

View File

@ -9,6 +9,8 @@ public interface IItemTypeService {
public List<ItemType> selectItemTypeList(ItemType itemType);
public ItemType selectItemTypeByName(String typeName);
public ItemType selectItemTypeById(Long itemTypeId);
public List<TreeSelect> buildTreeSelect(List<ItemType> list);

View File

@ -20,10 +20,18 @@ public interface IMdItemService {
*/
public List<MdItem> selectMdItemAll();
/**
* 获取导出格式的物料产品清单
* 主要区别是物料分类会以父级分类/子集分类的方式组合
* @param mdItem
* @return
*/
public List<MdItem> getExeportList(MdItem mdItem);
/**
* 导入物料信息
* @param vendorList
* @param itemList
* @param isUpdateSupport
* @param operName
* @return

View File

@ -8,6 +8,7 @@ import com.ktg.mes.md.mapper.ItemTypeMapper;
import com.ktg.mes.md.service.IItemTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Iterator;
@ -25,6 +26,21 @@ public class ItemTypeServiceImpl implements IItemTypeService {
return itemTypeMapper.selectItemTypeList(itemType);
}
/**
* 根据分类名称查找分类
* 在重名的情况下支持按上级分类/下级分类的模式进行查找
* @param itemTypeName
* @return
*/
@Override
public ItemType selectItemTypeByName(String itemTypeName) {
List<ItemType> types = itemTypeMapper.selectItemTypeByName(itemTypeName);
if(!CollectionUtils.isEmpty(types)){
return types.get(0);
}
return null;
}
@Override
public ItemType selectItemTypeById(Long itemTypeId) {
return itemTypeMapper.selectItemTypeById(itemTypeId);

View File

@ -189,6 +189,7 @@ public class MdClientServiceImpl implements IMdClientService
String msg = "<br/>" + failureNum + "、客户 " + client.getClientName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0)
{
failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
@ -198,7 +199,6 @@ public class MdClientServiceImpl implements IMdClientService
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + "");
}
}
return successMsg.toString();
}
}

View File

@ -47,11 +47,16 @@ public class MdItemServiceImpl implements IMdItemService {
return mdItemMapper.selectMdItemAll();
}
@Override
public List<MdItem> getExeportList(MdItem mdItem) {
return mdItemMapper.getExeportList(mdItem);
}
@Override
public String importItem(List<MdItem> itemList, Boolean isUpdateSupport, String operName) {
if (StringUtils.isNull(itemList) || itemList.size() == 0)
{
throw new ServiceException("导入供应商数据不能为空!");
throw new ServiceException("导入物料产品数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
@ -61,13 +66,17 @@ public class MdItemServiceImpl implements IMdItemService {
{
try{
//物料分类是否正确
if(StringUtils.isNotNull(item.getItemTypeCode())){
ItemType q = new ItemType();
q.setItemTypeCode(item.getItemTypeCode());
List<ItemType> types = itemTypeMapper.selectItemTypeList(q);
if(CollectionUtils.isEmpty(types)){
if(StringUtils.isNotNull(item.getItemTypeName())){
List<ItemType> types = itemTypeMapper.selectItemTypeByName(item.getItemTypeName());
if(!CollectionUtils.isEmpty(types)){
item.setItemTypeId(types.get(0).getItemTypeId());
item.setItemTypeCode(types.get(0).getItemTypeCode());
item.setItemTypeName(types.get(0).getItemTypeName());
item.setItemOrProduct(types.get(0).getItemOrProduct());
item.setSafeStockFlag(UserConstants.NO);
item.setEnableFlag(UserConstants.YES);
item.setHighValue(UserConstants.NO);
//是否存在
MdItem v = mdItemMapper.checkItemCodeUnique(item);
@ -90,17 +99,18 @@ public class MdItemServiceImpl implements IMdItemService {
}
}else{
failureNum++;
failureMsg.append("<br/>" + failureNum + "、物料/产品 " + item.getItemName() + " 请填写正确的分类编码");
failureMsg.append("<br/>" + failureNum + "、物料/产品 " + item.getItemName() + " 请填写正确的分类");
}
}else {
failureNum++;
failureMsg.append("<br/>" + failureNum + "、物料/产品 " + item.getItemName() + " 请填写分类编码");
failureMsg.append("<br/>" + failureNum + "、物料/产品 " + item.getItemName() + " 请填写分类");
}
}catch (Exception e){
failureNum++;
String msg = "<br/>" + failureNum + "、物料/产品 " + item.getItemName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0)
{
failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
@ -110,7 +120,6 @@ public class MdItemServiceImpl implements IMdItemService {
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + "");
}
}
return successMsg.toString();
}

View File

@ -132,6 +132,7 @@ public class MdVendorServiceImpl implements IMdVendorService
String msg = "<br/>" + failureNum + "、供应商 " + vendor.getVendorName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0)
{
failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
@ -141,7 +142,6 @@ public class MdVendorServiceImpl implements IMdVendorService
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + "");
}
}
return successMsg.toString();
}

View File

@ -83,6 +83,18 @@
<include refid="selectItemTypeVo"/>
where item_type_name=#{itemTypeName} and parent_type_id = #{parentTypeId} limit 1
</select>
<select id="selectItemTypeByName" parameterType="String" resultMap="ItemTypeResult">
select *
from (
select CONCAT((select group_concat(item_type_name separator '/')
from md_item_type b
where FIND_IN_SET(CAST(item_type_id as CHAR),a.ancestors)>0),'/',a.item_type_name) as fullType,a.*
from md_item_type a
) t
where fullType = #{itemTypeName} or t.item_type_name = #{itemTypeName}
</select>
<select id="checkItemTypeCodeUnique" resultMap="ItemTypeResult">
<include refid="selectItemTypeVo"/>
where item_type_code=#{itemTypeCode} and parent_type_id = #{parentTypeId} limit 1

View File

@ -55,6 +55,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="getExeportList" parameterType="MdItem" resultMap="MdItemResult">
select i.item_id, i.item_code, i.item_name, i.specification, i.unit_of_measure,i.unit_name, i.item_or_product,
i.item_type_id,i.item_type_code,i.enable_flag,i.safe_stock_flag,i.min_stock,i.max_stock,i.high_value, i.create_by, i.create_time, i.remark,CONCAT((select group_concat(item_type_name separator '/') from md_item_type b where FIND_IN_SET(CAST(item_type_id as CHAR),a.ancestors)>0),'/',a.item_type_name) as item_type_name
from md_item i
left join md_item_type a
on i.item_type_id = a.item_type_id
<where>
<if test="itemCode != null and itemCode != ''">
AND i.item_code like concat('%', #{itemCode}, '%')
</if>
<if test="itemTypeId != null and itemTypeId != 0 ">
AND (i.item_type_id = #{itemTypeId} OR i.item_type_id in (select item_type_id from md_item_type where find_in_set(#{itemTypeId},ancestors)))
</if>
<if test="itemName != null and itemName != ''">
AND i.item_name like concat('%', #{itemName}, '%')
</if>
<if test="enableFlag != null and enableFlag != ''">
AND i.enable_flag = #{enableFlag}
</if>
</where>
</select>
<select id="selectMdItemAll" resultMap="MdItemResult">
<include refid="selectMdItemVo"></include>
</select>
@ -80,7 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
item_name,
<if test="specification !=null and specification !=''">specification,</if>
unit_of_measure,
<if test="unitName != null and unitName !=''">unitName,</if>
<if test="unitName != null and unitName !=''">unit_name,</if>
item_or_product,
item_type_id,
<if test="itemTypeCode !=null and itemTypeCode !=''">item_type_code,</if>
@ -89,7 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
safe_stock_flag,
<if test="safeStockFlag =='Y'.toString()">min_stock,</if>
<if test="safeStockFlag =='Y'.toString()">max_stock,</if>
<if test="highValue !=null and highValue !=''">#{high_value},</if>
<if test="highValue !=null and highValue !=''">high_value,</if>
<if test="remark !=null and remark !=''">remark,</if>
<if test="attr1 !=null and attr1 !=''">attr1,</if>
<if test="attr2 !=null and attr2 !=''">attr2,</if>