物料单位显示问题修复
This commit is contained in:
parent
5bd5dd9e95
commit
1b1215080e
@ -7,7 +7,8 @@ create table md_item (
|
||||
item_code varchar(64) not null comment '产品物料编码',
|
||||
item_name varchar(255) not null comment '产品物料名称',
|
||||
specification varchar(500) default null comment '规格型号',
|
||||
unit_of_measure varchar(64) not null comment '单位',
|
||||
unit_of_measure varchar(64) not null comment '单位编码',
|
||||
unit_name varchar(64) comment '单位名称'
|
||||
item_or_product varchar(20) not null comment '产品物料标识',
|
||||
item_type_id bigint(20) default 0 comment '物料类型ID',
|
||||
item_type_code varchar(64) default '' comment '物料类型编码',
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.ktg.mes.md.controller;
|
||||
|
||||
import com.ktg.common.utils.poi.ExcelUtil;
|
||||
import com.ktg.mes.aspect.BarcodeGen;
|
||||
import com.ktg.mes.md.domain.MdUnitMeasure;
|
||||
import com.ktg.mes.md.domain.MdVendor;
|
||||
import com.ktg.mes.md.service.IMdItemService;
|
||||
import com.ktg.common.annotation.Log;
|
||||
import com.ktg.common.constant.UserConstants;
|
||||
@ -12,12 +15,15 @@ import com.ktg.common.enums.BusinessType;
|
||||
import com.ktg.common.utils.StringUtils;
|
||||
import com.ktg.mes.md.domain.MdItem;
|
||||
import com.ktg.mes.md.service.IItemTypeService;
|
||||
import com.ktg.mes.md.service.IMdUnitMeasureService;
|
||||
import com.ktg.mes.wm.utils.WmBarCodeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@ -30,6 +36,9 @@ public class MdItemController extends BaseController {
|
||||
@Autowired
|
||||
private IItemTypeService iItemTypeService;
|
||||
|
||||
@Autowired
|
||||
private IMdUnitMeasureService mdUnitMeasureService;
|
||||
|
||||
@Autowired
|
||||
private WmBarCodeUtil barcodeUtil;
|
||||
|
||||
@ -45,6 +54,53 @@ public class MdItemController extends BaseController {
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出物料列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('mes:md:mditem:export')")
|
||||
@Log(title = "物料管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, MdItem mdItem)
|
||||
{
|
||||
List<MdItem> list = mdItemService.selectMdItemList(mdItem);
|
||||
ExcelUtil<MdItem> util = new ExcelUtil<MdItem>(MdItem.class);
|
||||
util.exportExcel(response, list, "物料产品数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载导入模板
|
||||
* @param response
|
||||
*/
|
||||
@PostMapping("/importTemplate")
|
||||
public void importTemplate(HttpServletResponse response)
|
||||
{
|
||||
ExcelUtil<MdItem> util = new ExcelUtil<MdItem>(MdItem.class);
|
||||
util.importTemplateExcel(response, "物料产品数据");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从模板导入供应商数据
|
||||
* @param file
|
||||
* @param updateSupport
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Log(title = "物料管理", businessType = BusinessType.IMPORT)
|
||||
@PreAuthorize("@ss.hasPermi('mes:md:mditem:import')")
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
||||
{
|
||||
ExcelUtil<MdItem> util = new ExcelUtil<MdItem>(MdItem.class);
|
||||
List<MdItem> mdItemList = util.importExcel(file.getInputStream());
|
||||
String operName = getUsername();
|
||||
String message = mdItemService.importItem(mdItemList, updateSupport, operName);
|
||||
return AjaxResult.success(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 主键查询
|
||||
* @param itemId
|
||||
@ -79,6 +135,11 @@ public class MdItemController extends BaseController {
|
||||
mdItem.setItemTypeName(type.getItemTypeName());
|
||||
mdItem.setItemOrProduct(type.getItemOrProduct());
|
||||
}
|
||||
|
||||
MdUnitMeasure measure = mdUnitMeasureService.selectMdUnitByCode(mdItem.getUnitOfMeasure());
|
||||
if(StringUtils.isNotNull(measure)){
|
||||
mdItem.setUnitName(measure.getMeasureName());
|
||||
}
|
||||
mdItem.setCreateBy(getUsername());
|
||||
mdItemService.insertMdItem(mdItem);
|
||||
barcodeUtil.generateBarCode(UserConstants.BARCODE_TYPE_ITEM,mdItem.getItemId(),mdItem.getItemCode(), mdItem.getItemName());
|
||||
@ -110,6 +171,10 @@ public class MdItemController extends BaseController {
|
||||
mdItem.setMinStock(0D);
|
||||
mdItem.setMaxStock(0D);
|
||||
}
|
||||
MdUnitMeasure measure = mdUnitMeasureService.selectMdUnitByCode(mdItem.getUnitOfMeasure());
|
||||
if(StringUtils.isNotNull(measure)){
|
||||
mdItem.setUnitName(measure.getMeasureName());
|
||||
}
|
||||
|
||||
mdItem.setUpdateBy(getUsername());
|
||||
return toAjax(mdItemService.updateMdItem(mdItem));
|
||||
@ -121,6 +186,4 @@ public class MdItemController extends BaseController {
|
||||
public AjaxResult remove(@PathVariable Long[] itemIds){
|
||||
return toAjax(mdItemService.deleteByItemIds(itemIds));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.ktg.mes.md.domain;
|
||||
|
||||
import com.ktg.common.annotation.Excel;
|
||||
import com.ktg.common.core.domain.BaseEntity;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
@ -12,19 +13,27 @@ public class MdItem extends BaseEntity {
|
||||
|
||||
|
||||
private Long itemId;
|
||||
@Excel(name = "物料/产品编码")
|
||||
private String itemCode;
|
||||
@Excel(name = "物料/产品名称")
|
||||
private String itemName;
|
||||
@Excel(name = "规格型号")
|
||||
private String specification;
|
||||
@Excel(name = "单位编码")
|
||||
private String unitOfMeasure;
|
||||
@Excel(name = "单位名称")
|
||||
private String unitName;
|
||||
private String itemOrProduct;
|
||||
private Long itemTypeId;
|
||||
@Excel(name = "分类编码")
|
||||
private String itemTypeCode;
|
||||
@Excel(name = "分类名称")
|
||||
private String itemTypeName;
|
||||
private String enableFlag;
|
||||
private String safeStockFlag;
|
||||
private Double minStock;
|
||||
private Double maxStock;
|
||||
private String hightValue;
|
||||
private String highValue;
|
||||
private String attr1;
|
||||
private String attr2;
|
||||
private String attr3;
|
||||
@ -76,6 +85,13 @@ public class MdItem extends BaseEntity {
|
||||
this.unitOfMeasure = unitOfMeasure;
|
||||
}
|
||||
|
||||
public String getUnitName() {
|
||||
return unitName;
|
||||
}
|
||||
|
||||
public void setUnitName(String unitName) {
|
||||
this.unitName = unitName;
|
||||
}
|
||||
|
||||
public String getItemOrProduct() {
|
||||
return itemOrProduct;
|
||||
@ -142,12 +158,12 @@ public class MdItem extends BaseEntity {
|
||||
this.maxStock = maxStock;
|
||||
}
|
||||
|
||||
public String getHightValue() {
|
||||
return hightValue;
|
||||
public String getHighValue() {
|
||||
return highValue;
|
||||
}
|
||||
|
||||
public void setHightValue(String hightValue) {
|
||||
this.hightValue = hightValue;
|
||||
public void setHighValue(String highValue) {
|
||||
this.highValue = highValue;
|
||||
}
|
||||
|
||||
public String getAttr1() {
|
||||
|
@ -28,6 +28,8 @@ public interface MdUnitMeasureMapper
|
||||
*/
|
||||
public List<MdUnitMeasure> selectMdUnitMeasureList(MdUnitMeasure mdUnitMeasure);
|
||||
|
||||
public MdUnitMeasure selectMdUnitByCode(String unitCode);
|
||||
|
||||
/**
|
||||
* 新增单位
|
||||
*
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.ktg.mes.md.service;
|
||||
|
||||
import com.ktg.mes.md.domain.MdItem;
|
||||
import com.ktg.mes.md.domain.MdVendor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -20,6 +21,15 @@ public interface IMdItemService {
|
||||
public List<MdItem> selectMdItemAll();
|
||||
|
||||
|
||||
/**
|
||||
* 导入物料信息
|
||||
* @param vendorList
|
||||
* @param isUpdateSupport
|
||||
* @param operName
|
||||
* @return
|
||||
*/
|
||||
public String importItem(List<MdItem> itemList, Boolean isUpdateSupport, String operName);
|
||||
|
||||
/**
|
||||
* 根据主键查询物料编码
|
||||
* @param itemId
|
||||
|
@ -28,6 +28,13 @@ public interface IMdUnitMeasureService
|
||||
*/
|
||||
public List<MdUnitMeasure> selectMdUnitMeasureList(MdUnitMeasure mdUnitMeasure);
|
||||
|
||||
/**
|
||||
* 根据单位编码查询单位名称
|
||||
* @param unitCode
|
||||
* @return
|
||||
*/
|
||||
public MdUnitMeasure selectMdUnitByCode(String unitCode);
|
||||
|
||||
/**
|
||||
* 新增单位
|
||||
*
|
||||
|
@ -1,13 +1,22 @@
|
||||
package com.ktg.mes.md.service.impl;
|
||||
|
||||
import com.ktg.common.core.domain.entity.ItemType;
|
||||
import com.ktg.common.exception.ServiceException;
|
||||
import com.ktg.common.utils.bean.BeanValidators;
|
||||
import com.ktg.mes.md.domain.MdVendor;
|
||||
import com.ktg.mes.md.mapper.ItemTypeMapper;
|
||||
import com.ktg.mes.md.service.IMdItemService;
|
||||
import com.ktg.common.constant.UserConstants;
|
||||
import com.ktg.common.utils.StringUtils;
|
||||
import com.ktg.mes.md.domain.MdItem;
|
||||
import com.ktg.mes.md.mapper.MdItemMapper;
|
||||
import com.ktg.mes.wm.utils.WmBarCodeUtil;
|
||||
import com.ktg.system.strategy.AutoCodeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.validation.Validator;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -16,6 +25,18 @@ public class MdItemServiceImpl implements IMdItemService {
|
||||
@Autowired
|
||||
private MdItemMapper mdItemMapper;
|
||||
|
||||
@Autowired
|
||||
private ItemTypeMapper itemTypeMapper;
|
||||
|
||||
@Autowired
|
||||
protected Validator validator;
|
||||
|
||||
@Autowired
|
||||
private WmBarCodeUtil barCodeUtil;
|
||||
|
||||
@Autowired
|
||||
private AutoCodeUtil autoCodeUtil;
|
||||
|
||||
@Override
|
||||
public List<MdItem> selectMdItemList(MdItem mdItem) {
|
||||
return mdItemMapper.selectMdItemList(mdItem);
|
||||
@ -26,6 +47,73 @@ public class MdItemServiceImpl implements IMdItemService {
|
||||
return mdItemMapper.selectMdItemAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String importItem(List<MdItem> itemList, Boolean isUpdateSupport, String operName) {
|
||||
if (StringUtils.isNull(itemList) || itemList.size() == 0)
|
||||
{
|
||||
throw new ServiceException("导入供应商数据不能为空!");
|
||||
}
|
||||
int successNum = 0;
|
||||
int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
for (MdItem item : itemList)
|
||||
{
|
||||
try{
|
||||
//物料分类是否正确
|
||||
if(StringUtils.isNotNull(item.getItemTypeCode())){
|
||||
ItemType q = new ItemType();
|
||||
q.setItemTypeCode(item.getItemTypeCode());
|
||||
List<ItemType> types = itemTypeMapper.selectItemTypeList(q);
|
||||
if(CollectionUtils.isEmpty(types)){
|
||||
item.setItemTypeId(types.get(0).getItemTypeId());
|
||||
item.setItemTypeName(types.get(0).getItemTypeName());
|
||||
|
||||
//是否存在
|
||||
MdItem v = mdItemMapper.checkItemCodeUnique(item);
|
||||
if(StringUtils.isNull(v)){
|
||||
BeanValidators.validateWithException(validator, item);
|
||||
String itemCode = autoCodeUtil.genSerialCode(UserConstants.ITEM_CODE,"");
|
||||
item.setItemCode(itemCode);
|
||||
this.insertMdItem(item);
|
||||
barCodeUtil.generateBarCode(UserConstants.BARCODE_TYPE_ITEM,item.getItemId(),item.getItemCode(),item.getItemName());
|
||||
successNum++;
|
||||
}else if (isUpdateSupport){
|
||||
BeanValidators.validateWithException(validator, item);
|
||||
item.setUpdateBy(operName);
|
||||
item.setItemId(v.getItemId());
|
||||
this.updateMdItem(item);
|
||||
successNum++;
|
||||
}else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、物料/产品 " + item.getItemName() + " 已存在");
|
||||
}
|
||||
}else{
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、物料/产品 " + item.getItemName() + " 请填写正确的分类编码");
|
||||
}
|
||||
}else {
|
||||
failureNum++;
|
||||
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 + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条");
|
||||
}
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MdItem selectMdItemById(Long itemId) {
|
||||
|
@ -45,6 +45,11 @@ public class MdUnitMeasureServiceImpl implements IMdUnitMeasureService
|
||||
return mdUnitMeasureMapper.selectMdUnitMeasureList(mdUnitMeasure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MdUnitMeasure selectMdUnitByCode(String unitCode) {
|
||||
return mdUnitMeasureMapper.selectMdUnitByCode(unitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单位
|
||||
*
|
||||
|
@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="itemName" column="item_name" />
|
||||
<result property="specification" column="specification" />
|
||||
<result property="unitOfMeasure" column="unit_of_measure" />
|
||||
<result property="unitName" column="unit_name" />
|
||||
<result property="itemOrProduct" column="item_or_product" />
|
||||
<result property="itemTypeId" column="item_type_id" />
|
||||
<result property="itemTypeCode" column="item_type_code" />
|
||||
@ -31,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectMdItemVo">
|
||||
select item_id, item_code, item_name, specification, unit_of_measure, item_or_product,
|
||||
select item_id, item_code, item_name, specification, unit_of_measure,unit_name, item_or_product,
|
||||
item_type_id,item_type_code,item_type_name,enable_flag,safe_stock_flag,min_stock,max_stock,high_value, create_by, create_time, remark
|
||||
from md_item
|
||||
</sql>
|
||||
@ -79,6 +80,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>
|
||||
item_or_product,
|
||||
item_type_id,
|
||||
<if test="itemTypeCode !=null and itemTypeCode !=''">item_type_code,</if>
|
||||
@ -101,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{itemName},
|
||||
<if test="specification !=null and specification !=''">#{specification},</if>
|
||||
#{unitOfMeasure},
|
||||
<if test="unitName != null and unitName !=''">#{unitName},</if>
|
||||
#{itemOrProduct},
|
||||
#{itemTypeId},
|
||||
<if test="itemTypeCode !=null and itemTypeCode !=''">#{itemTypeCode},</if>
|
||||
@ -129,6 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="itemTypeName !=null and itemTypeName !=''">item_type_name = #{itemTypeName},</if>
|
||||
<if test="specification !=null and specification !=''">specification = #{specification},</if>
|
||||
<if test="unitOfMeasure !=null and unitOfMeasure !=''">unit_of_measure = #{unitOfMeasure},</if>
|
||||
<if test="unitName != null and unitName !=''">unit_name = #{unitName},</if>
|
||||
<if test="itemOrProduct !=null and itemOrProduct !=''">item_or_product = #{itemOrProduct},</if>
|
||||
<if test="enableFlag !=null and enableFlag !=''">enable_flag = #{enableFlag},</if>
|
||||
<if test="safeStockFlag !=null and safeStockFlag !=''">safe_stock_flag = #{safeStockFlag},</if>
|
||||
|
@ -47,7 +47,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectMdUnitMeasureVo"/>
|
||||
where measure_id = #{measureId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectMdUnitByCode" parameterType="String" resultMap="MdUnitMeasureResult">
|
||||
<include refid="selectMdUnitMeasureVo"/>
|
||||
where measure_code = #{unitCode}
|
||||
</select>
|
||||
|
||||
<insert id="insertMdUnitMeasure" parameterType="MdUnitMeasure" useGeneratedKeys="true" keyProperty="measureId">
|
||||
insert into md_unit_measure
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
Loading…
Reference in New Issue
Block a user