Commit ad9ee39c authored by 季圣华's avatar 季圣华
Browse files

优化商品的excel导入

parent b4db7c67
......@@ -305,6 +305,27 @@ public class ExceptionConstants {
//抱歉,文件扩展名必须为xls
public static final int MATERIAL_EXTENSION_ERROR_CODE = 8000009;
public static final String MATERIAL_EXTENSION_ERROR_MSG = "抱歉,文件扩展名必须为xls";
//名称为空
public static final int MATERIAL_NAME_EMPTY_CODE = 8000010;
public static final String MATERIAL_NAME_EMPTY_MSG = "第%s行名称为空";
//基本单位为空
public static final int MATERIAL_UNIT_EMPTY_CODE = 8000011;
public static final String MATERIAL_UNIT_EMPTY_MSG = "第%s行基本单位为空";
//状态格式错误
public static final int MATERIAL_ENABLED_ERROR_CODE = 8000012;
public static final String MATERIAL_ENABLED_ERROR_MSG = "第%s行状态格式错误";
//单次导入超出1000条
public static final int MATERIAL_IMPORT_OVER_LIMIT_CODE = 8000013;
public static final String MATERIAL_IMPORT_OVER_LIMIT_MSG = "抱歉,单次导入不能超出1000条";
//基础重量格式错误
public static final int MATERIAL_WEIGHT_NOT_DECIMAL_CODE = 8000014;
public static final String MATERIAL_WEIGHT_NOT_DECIMAL_MSG = "第%s行基础重量格式错误";
//保质期格式错误
public static final int MATERIAL_EXPIRY_NUM_NOT_INTEGER_CODE = 8000015;
public static final String MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG = "第%s行保质期格式错误";
//比例格式错误
public static final int MATERIAL_RATIO_NOT_INTEGER_CODE = 8000016;
public static final String MATERIAL_RATIO_NOT_INTEGER_MSG = "第%s行比例格式错误";
/**
* 单据信息
* type = 85
......
......@@ -179,7 +179,7 @@ public class DepotController {
DepotEx de = new DepotEx();
if(mId!=0) {
BigDecimal initStock = materialService.getInitStock(mId, depot.getId());
BigDecimal currentStock = materialService.getCurrentStock(mId, depot.getId());
BigDecimal currentStock = materialService.getCurrentStockByMaterialIdAndDepotId(mId, depot.getId());
de.setInitStock(initStock);
de.setCurrentStock(currentStock);
MaterialInitialStock materialInitialStock = materialService.getSafeStock(mId, depot.getId());
......
package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.MaterialCurrentStock;
import com.jsh.erp.datasource.entities.MaterialCurrentStockExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface MaterialCurrentStockMapperEx {
int batchInsert(List<MaterialCurrentStock> list);
List<MaterialCurrentStock> getCurrentStockMapByIdList(
@Param("materialIdList") List<Long> materialIdList);
}
\ No newline at end of file
package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.MaterialCurrentStock;
import com.jsh.erp.datasource.entities.MaterialInitialStock;
import com.jsh.erp.datasource.entities.MaterialInitialStockExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface MaterialInitialStockMapperEx {
int batchInsert(List<MaterialInitialStock> list);
}
\ No newline at end of file
......@@ -19,15 +19,13 @@ import java.util.Map;
public interface MaterialMapperEx {
List<MaterialVo4Unit> selectByConditionMaterial(
@Param("barCode") String barCode,
@Param("name") String name,
@Param("standard") String standard,
@Param("model") String model,
@Param("materialParam") String materialParam,
@Param("color") String color,
@Param("weight") String weight,
@Param("expiryNum") String expiryNum,
@Param("enableSerialNumber") String enableSerialNumber,
@Param("enableBatchNumber") String enableBatchNumber,
@Param("enabled") String enabled,
@Param("remark") String remark,
@Param("idList") List<Long> idList,
@Param("mpList") String mpList,
......@@ -35,19 +33,19 @@ public interface MaterialMapperEx {
@Param("rows") Integer rows);
Long countsByMaterial(
@Param("barCode") String barCode,
@Param("name") String name,
@Param("standard") String standard,
@Param("model") String model,
@Param("materialParam") String materialParam,
@Param("color") String color,
@Param("weight") String weight,
@Param("expiryNum") String expiryNum,
@Param("enableSerialNumber") String enableSerialNumber,
@Param("enableBatchNumber") String enableBatchNumber,
@Param("enabled") String enabled,
@Param("remark") String remark,
@Param("idList") List<Long> idList,
@Param("mpList") String mpList);
Long insertSelectiveEx(Material record);
List<Unit> findUnitList(@Param("mId") Long mId);
List<MaterialVo4Unit> findById(@Param("id") Long id);
......
......@@ -34,38 +34,34 @@ public class MaterialComponent implements ICommonQuery {
private List<?> getMaterialList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String categoryId = StringUtil.getInfo(search, "categoryId");
String barCode = StringUtil.getInfo(search, "barCode");
String name = StringUtil.getInfo(search, "name");
String standard = StringUtil.getInfo(search, "standard");
String model = StringUtil.getInfo(search, "model");
String materialParam = StringUtil.getInfo(search, "materialParam");
String color = StringUtil.getInfo(search, "color");
String weight = StringUtil.getInfo(search, "weight");
String expiryNum = StringUtil.getInfo(search, "expiryNum");
String enableSerialNumber = StringUtil.getInfo(search, "enableSerialNumber");
String enableBatchNumber = StringUtil.getInfo(search, "enableBatchNumber");
String enabled = StringUtil.getInfo(search, "enabled");
String remark = StringUtil.getInfo(search, "remark");
String mpList = StringUtil.getInfo(search, "mpList");
return materialService.select(barCode, name, standard, model, color, weight, expiryNum,
enableSerialNumber, enableBatchNumber, remark, categoryId, mpList, QueryUtils.offset(map), QueryUtils.rows(map));
return materialService.select(materialParam, color, weight, expiryNum,
enableSerialNumber, enableBatchNumber, enabled, remark, categoryId, mpList, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String categoryId = StringUtil.getInfo(search, "categoryId");
String barCode = StringUtil.getInfo(search, "barCode");
String name = StringUtil.getInfo(search, "name");
String standard = StringUtil.getInfo(search, "standard");
String model = StringUtil.getInfo(search, "model");
String materialParam = StringUtil.getInfo(search, "materialParam");
String color = StringUtil.getInfo(search, "color");
String weight = StringUtil.getInfo(search, "weight");
String expiryNum = StringUtil.getInfo(search, "expiryNum");
String enableSerialNumber = StringUtil.getInfo(search, "enableSerialNumber");
String enableBatchNumber = StringUtil.getInfo(search, "enableBatchNumber");
String enabled = StringUtil.getInfo(search, "enabled");
String remark = StringUtil.getInfo(search, "remark");
String mpList = StringUtil.getInfo(search, "mpList");
return materialService.countMaterial(barCode, name, standard, model, color, weight, expiryNum,
enableSerialNumber, enableBatchNumber, remark, categoryId, mpList);
return materialService.countMaterial(materialParam, color, weight, expiryNum,
enableSerialNumber, enableBatchNumber, enabled, remark, categoryId, mpList);
}
@Override
......
......@@ -347,7 +347,7 @@ public class MaterialExtendService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public Long selectIdByMaterialIdAndDefaultFlag(Long materialId, String defaultFlag)throws Exception {
public Long selectIdByMaterialIdAndDefaultFlag(Long materialId, String defaultFlag) {
Long id = 0L;
MaterialExtendExample example = new MaterialExtendExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDefaultFlagEqualTo(defaultFlag)
......
......@@ -8,6 +8,7 @@ import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
......@@ -316,6 +317,24 @@ public class StringUtil {
}
}
/**
* 判断对象是否为数字(含小数)
* @param str
* @return
*/
public static boolean isPositiveBigDecimal(String str){
Pattern pattern = Pattern.compile("[0-9]*");
if(str.indexOf(".")>0){//判断是否有小数点
if(str.indexOf(".")==str.lastIndexOf(".") && str.split("\\.").length==2){ //判断是否只有一个小数点
return pattern.matcher(str.replace(".","")).matches();
}else {
return false;
}
}else {
return pattern.matcher(str).matches();
}
}
/**
* sql注入过滤,保障sql的安全执行
* @param originStr
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jsh.erp.datasource.mappers.MaterialCurrentStockMapperEx">
<insert id="batchInsert" parameterType="java.util.List">
insert into jsh_material_current_stock (material_id, depot_id, current_number)
values
<foreach collection="list" item="item" separator=",">
(#{item.materialId,jdbcType=BIGINT}, #{item.depotId,jdbcType=BIGINT},#{item.currentNumber,jdbcType=DECIMAL})
</foreach >
</insert>
<select id="getCurrentStockMapByIdList" resultType="com.jsh.erp.datasource.entities.MaterialCurrentStock">
select material_id, sum(current_number) current_number from jsh_material_current_stock
where 1=1
and ifnull(delete_flag,'0') !='1'
and material_id in
<foreach collection="materialIdList" item="materialId" index="index" separator="," open="(" close=")">
#{materialId}
</foreach>
group by material_id
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jsh.erp.datasource.mappers.MaterialInitialStockMapperEx">
<insert id="batchInsert" parameterType="java.util.List">
insert into jsh_material_initial_stock (material_id, depot_id, number)
values
<foreach collection="list" item="item" separator=",">
(#{item.materialId,jdbcType=BIGINT}, #{item.depotId,jdbcType=BIGINT},#{item.number,jdbcType=DECIMAL})
</foreach >
</insert>
</mapper>
\ No newline at end of file
......@@ -39,21 +39,9 @@
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
where 1=1
and me.default_flag=1
<if test="barCode != null and barCode !=''">
<bind name="bindBarCode" value="'%'+barCode+'%'"/>
and me.bar_code like #{bindBarCode}
</if>
<if test="name != null and name !=''">
<bind name="bindName" value="'%'+name+'%'"/>
and m.name like #{bindName}
</if>
<if test="standard != null and standard !=''">
<bind name="bindStandard" value="'%'+standard+'%'"/>
and m.standard like #{bindStandard}
</if>
<if test="model != null and model !=''">
<bind name="bindModel" value="'%'+model+'%'"/>
and m.model like #{bindModel}
<if test="materialParam != null and materialParam !=''">
<bind name="bindKey" value="'%'+materialParam+'%'"/>
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
</if>
<if test="color != null and color !=''">
<bind name="bindColor" value="'%'+color+'%'"/>
......@@ -71,6 +59,9 @@
<if test="enableBatchNumber != null and enableBatchNumber !=''">
and m.enable_batch_number = #{enableBatchNumber}
</if>
<if test="enabled != null">
and m.enabled = #{enabled}
</if>
<if test="remark != null and remark !=''">
<bind name="bindRemark" value="'%'+remark+'%'"/>
and m.remark like #{bindRemark}
......@@ -97,21 +88,9 @@
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
WHERE 1=1
and me.default_flag=1
<if test="barCode != null and barCode !=''">
<bind name="bindBarCode" value="'%'+barCode+'%'"/>
and me.bar_code like #{bindBarCode}
</if>
<if test="name != null and name !=''">
<bind name="bindName" value="'%'+name+'%'"/>
and m.name like #{bindName}
</if>
<if test="standard != null and standard !=''">
<bind name="bindStandard" value="'%'+standard+'%'"/>
and m.standard like #{bindStandard}
</if>
<if test="model != null and model !=''">
<bind name="bindModel" value="'%'+model+'%'"/>
and m.model like #{bindModel}
<if test="materialParam != null and materialParam !=''">
<bind name="bindKey" value="'%'+materialParam+'%'"/>
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
</if>
<if test="color != null and color !=''">
<bind name="bindColor" value="'%'+color+'%'"/>
......@@ -129,6 +108,9 @@
<if test="enableBatchNumber != null and enableBatchNumber !=''">
and m.enable_batch_number = #{enableBatchNumber}
</if>
<if test="enabled != null and enabled !=''">
and m.enabled = #{enabled}
</if>
<if test="remark != null and remark !=''">
<bind name="bindRemark" value="'%'+remark+'%'"/>
and m.remark like #{bindRemark}
......@@ -142,6 +124,140 @@
and ifnull(m.delete_flag,'0') !='1'
</select>
<insert id="insertSelectiveEx" parameterType="com.jsh.erp.datasource.entities.Material" useGeneratedKeys="true" keyProperty="id">
insert into jsh_material
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="categoryId != null">
category_id,
</if>
<if test="name != null">
name,
</if>
<if test="mfrs != null">
mfrs,
</if>
<if test="model != null">
model,
</if>
<if test="standard != null">
standard,
</if>
<if test="color != null">
color,
</if>
<if test="unit != null">
unit,
</if>
<if test="remark != null">
remark,
</if>
<if test="imgName != null">
img_name,
</if>
<if test="unitId != null">
unit_id,
</if>
<if test="expiryNum != null">
expiry_num,
</if>
<if test="weight != null">
weight,
</if>
<if test="enabled != null">
enabled,
</if>
<if test="otherField1 != null">
other_field1,
</if>
<if test="otherField2 != null">
other_field2,
</if>
<if test="otherField3 != null">
other_field3,
</if>
<if test="enableSerialNumber != null">
enable_serial_number,
</if>
<if test="enableBatchNumber != null">
enable_batch_number,
</if>
<if test="tenantId != null">
tenant_id,
</if>
<if test="deleteFlag != null">
delete_flag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="categoryId != null">
#{categoryId,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="mfrs != null">
#{mfrs,jdbcType=VARCHAR},
</if>
<if test="model != null">
#{model,jdbcType=VARCHAR},
</if>
<if test="standard != null">
#{standard,jdbcType=VARCHAR},
</if>
<if test="color != null">
#{color,jdbcType=VARCHAR},
</if>
<if test="unit != null">
#{unit,jdbcType=VARCHAR},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="imgName != null">
#{imgName,jdbcType=VARCHAR},
</if>
<if test="unitId != null">
#{unitId,jdbcType=BIGINT},
</if>
<if test="expiryNum != null">
#{expiryNum,jdbcType=INTEGER},
</if>
<if test="weight != null">
#{weight,jdbcType=DECIMAL},
</if>
<if test="enabled != null">
#{enabled,jdbcType=BIT},
</if>
<if test="otherField1 != null">
#{otherField1,jdbcType=VARCHAR},
</if>
<if test="otherField2 != null">
#{otherField2,jdbcType=VARCHAR},
</if>
<if test="otherField3 != null">
#{otherField3,jdbcType=VARCHAR},
</if>
<if test="enableSerialNumber != null">
#{enableSerialNumber,jdbcType=VARCHAR},
</if>
<if test="enableBatchNumber != null">
#{enableBatchNumber,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
#{tenantId,jdbcType=BIGINT},
</if>
<if test="deleteFlag != null">
#{deleteFlag,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="findUnitList" resultType="com.jsh.erp.datasource.entities.Unit">
select u.* from jsh_unit u
left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment