增加商品导入的功能

This commit is contained in:
季圣华
2019-01-05 21:33:01 +08:00
parent 8a4d034743
commit 2b7a7bbdeb
11 changed files with 311 additions and 7 deletions

View File

@@ -343,7 +343,12 @@
//导出数据
function setOutputFun(){
window.location.href = "/supplier/exportExcel.action?browserType=" + getOs() + "&type=" + listTypeEn;
var supplier = $.trim($("#searchSupplier").val());
var phonenum = $.trim($("#searchPhonenum").val());
var telephone = $.trim($("#searchTelephone").val());
var description = $.trim($("#searchDesc").val());
window.location.href = "/supplier/exportExcel?browserType=" + getOs()
+ "&supplier=" + supplier + "&type=" + listType + "&phonenum=" + phonenum + "&telephone=" + telephone + "&description=" + description;
}
//增加单位

View File

@@ -244,7 +244,7 @@
<!-- 导入excel表格 -->
<div id="importExcelDlg" class="easyui-dialog" style="width:400px; padding:10px 20px;"
closed="true" buttons="#dlg-buttons5" modal="true" collapsible="false" closable="true">
<form id="importExcelFM" method="post" enctype="multipart/form-data" action="/material/importExcel.action">
<form id="importExcelFM" method="post" enctype="multipart/form-data" action="/material/importExcel">
<div class="fitem" style="padding:5px">
<label>文件名称&nbsp;&nbsp;</label>
<input name="materialFile" id="materialFile" type="file" style="width: 230px;height: 20px"/>
@@ -259,7 +259,6 @@
<option value="1" selected="selected"></option>
</select>
</div>
<input type="hidden" name="clientIp" id="clientIp" value="<%=clientIp %>"/>
<div id="dlg-buttons5">
<a href="javascript:void(0)" id="saveimport" class="easyui-linkbutton" iconCls="icon-ok">导入</a>
<a href="javascript:void(0)" id="cancelimport" class="easyui-linkbutton" iconCls="icon-cancel"
@@ -1041,7 +1040,15 @@
//导出数据
function setOutputFun() {
window.location.href = "/material/exportExcel.action?browserType=" + getOs();
var name = $.trim($("#searchName").val());
var model = $.trim($("#searchModel").val());
if (setCategoryId != "1") {
cid = 2;
} else {
cid = 1;
}
window.location.href = "/material/exportExcel?browserType=" + getOs()
+ "&name=" + name + "&model=" + model + "&categoryId=" + cid + "&categoryIds=" + setCategoryId;
}
//增加

View File

@@ -845,7 +845,14 @@ public class DepotItemController {
/**
* 导出excel表格
* @param currentPage
* @param pageSize
* @param projectId
* @param monthTime
* @param headIds
* @param materialIds
* @param request
* @param response
* @return
*/
@GetMapping(value = "/exportExcel")
@@ -868,7 +875,7 @@ public class DepotItemController {
List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
String[] objs = new String[13];
String[] objs = new String[9];
Double prevSum = sumNumber("入库", pid, diEx.getMaterialid(), monthTime, true) - sumNumber("出库", pid, diEx.getMaterialid(), monthTime, true);
Double InSum = sumNumber("入库", pid, diEx.getMaterialid(), monthTime, false);
Double OutSum = sumNumber("出库", pid, diEx.getMaterialid(), monthTime, false);

View File

@@ -1,18 +1,24 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.Material;
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
import com.jsh.erp.service.material.MaterialService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.utils.*;
import jxl.Sheet;
import jxl.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -177,4 +183,127 @@ public class MaterialController {
}
return res;
}
/**
* 生成excel表格
* @param name
* @param model
* @param categoryId
* @param categoryIds
* @param request
* @param response
* @return
*/
@GetMapping(value = "/exportExcel")
public BaseResponseInfo exportExcel(@RequestParam("name") String name,
@RequestParam("model") String model,
@RequestParam("categoryId") Long categoryId,
@RequestParam("categoryIds") String categoryIds,
HttpServletRequest request, HttpServletResponse response) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
String message = "成功";
try {
List<MaterialVo4Unit> dataList = materialService.findByAll(name, model, categoryId, categoryIds);
String[] names = {"品名", "类型", "型号", "安全存量", "单位", "零售价", "最低售价", "预计采购价", "批发价", "备注", "状态"};
String title = "商品信息";
List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) {
for (MaterialVo4Unit m : dataList) {
String[] objs = new String[11];
objs[0] = m.getName();
objs[1] = m.getCategoryName();
objs[2] = m.getModel();
objs[3] = m.getSafetystock() == null? "" : m.getSafetystock().toString();
objs[4] = m.getUnit();
objs[5] = m.getRetailprice() == null ? "" : m.getRetailprice().toString();
objs[6] = m.getLowprice() == null ? "" : m.getLowprice().toString();
objs[7] = m.getPresetpriceone() == null ? "" : m.getPresetpriceone().toString();
objs[8] = m.getPresetpricetwo() == null ? "" : m.getPresetpricetwo().toString();
objs[9] = m.getRemark();
objs[10] = m.getEnabled() ? "启用" : "禁用";
objects.add(objs);
}
}
File file = ExcelUtils.exportObjectsWithoutTitle(title, names, title, objects);
ExportExecUtil.showExec(file, file.getName(), response);
res.code = 200;
} catch (Exception e) {
e.printStackTrace();
message = "导出失败";
res.code = 500;
} finally {
map.put("message", message);
res.data = map;
}
return res;
}
/**
* excel表格导入
* @param materialFile
* @param request
* @param response
* @return
*/
@PostMapping(value = "/importExcel")
public void importExcel(MultipartFile materialFile,
HttpServletRequest request, HttpServletResponse response) throws Exception{
BaseResponseInfo info = new BaseResponseInfo();
Map<String, Object> data = new HashMap<String, Object>();
String message = "成功";
try {
Sheet src = null;
//文件合法性校验
try {
Workbook workbook = Workbook.getWorkbook(materialFile.getInputStream());
src = workbook.getSheet(0);
} catch (Exception e) {
message = "导入文件不合法,请检查";
data.put("message", message);
info.code = 400;
info.data = data;
}
//读取所有的摄像机编码
//每行中数据顺序 "品名","类型","型号","安全存量","单位","零售价","最低售价","预计采购价","批发价","备注","状态"
List<Material> mList = new ArrayList<Material>();
for (int i = 1; i < src.getRows(); i++) {
Material m = new Material();
m.setName(ExcelUtils.getContent(src, i, 0));
m.setCategoryid(1l); //根目录
m.setModel(ExcelUtils.getContent(src, i, 2));
String safetyStock = ExcelUtils.getContent(src, i, 3);
m.setSafetystock(parseDoubleEx(safetyStock));
m.setUnit(ExcelUtils.getContent(src, i, 4));
String retailprice = ExcelUtils.getContent(src, i, 5);
m.setRetailprice(parseDoubleEx(retailprice));
String lowPrice = ExcelUtils.getContent(src, i, 6);
m.setLowprice(parseDoubleEx(lowPrice));
String presetpriceone = ExcelUtils.getContent(src, i, 7);
m.setPresetpriceone(parseDoubleEx(presetpriceone));
String presetpricetwo = ExcelUtils.getContent(src, i, 8);
m.setPresetpricetwo(parseDoubleEx(presetpricetwo));
m.setRemark(ExcelUtils.getContent(src, i, 9));
String enabled = ExcelUtils.getContent(src, i, 10);
m.setEnabled(enabled.equals("启用")? true: false);
mList.add(m);
}
info = materialService.importExcel(mList);
} catch (Exception e) {
e.printStackTrace();
message = "导入失败";
info.code = 500;
data.put("message", message);
info.data = data;
}
response.sendRedirect("../pages/materials/material.html");
}
public Double parseDoubleEx(String str){
if(!StringUtil.isEmpty(str)) {
return Double.parseDouble(str);
} else {
return null;
}
}
}

View File

@@ -7,6 +7,8 @@ import com.jsh.erp.service.supplier.SupplierService;
import com.jsh.erp.service.userBusiness.UserBusinessService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.utils.ExcelUtils;
import com.jsh.erp.utils.ExportExecUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
@@ -14,6 +16,9 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -259,4 +264,67 @@ public class SupplierController {
}
return arr;
}
/**
* 生成excel表格
* @param supplier
* @param type
* @param phonenum
* @param telephone
* @param description
* @param request
* @param response
* @return
*/
@GetMapping(value = "/exportExcel")
public BaseResponseInfo exportExcel(@RequestParam("supplier") String supplier,
@RequestParam("type") String type,
@RequestParam("phonenum") String phonenum,
@RequestParam("telephone") String telephone,
@RequestParam("description") String description,
HttpServletRequest request, HttpServletResponse response) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
String message = "成功";
try {
List<Supplier> dataList = supplierService.findByAll(supplier, type, phonenum, telephone, description);
String[] names = {"名称", "类型", "联系人", "电话", "电子邮箱", "预收款", "期初应收", "期初应付", "备注", "传真", "手机", "地址", "纳税人识别号", "开户行", "账号", "税率", "状态"};
String title = "信息报表";
List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) {
for (Supplier s : dataList) {
String[] objs = new String[17];
objs[0] = s.getSupplier();
objs[1] = s.getType();
objs[2] = s.getContacts();
objs[3] = s.getPhonenum();
objs[4] = s.getEmail();
objs[5] = s.getAdvancein() == null? "" : s.getAdvancein().toString();
objs[6] = s.getBeginneedget() == null? "" : s.getBeginneedget().toString();
objs[7] = s.getBeginneedpay() == null? "" : s.getBeginneedpay().toString();
objs[8] = s.getDescription();
objs[9] = s.getFax();
objs[10] = s.getTelephone();
objs[11] = s.getAddress();
objs[12] = s.getTaxnum();
objs[13] = s.getBankname();
objs[14] = s.getAccountnumber();
objs[15] = s.getTaxrate() == null? "" : s.getTaxrate().toString();
objs[16] = s.getEnabled() ? "启用" : "禁用";
objects.add(objs);
}
}
File file = ExcelUtils.exportObjectsWithoutTitle(title, names, title, objects);
ExportExecUtil.showExec(file, file.getName(), response);
res.code = 200;
} catch (Exception e) {
e.printStackTrace();
message = "导出失败";
res.code = 500;
} finally {
map.put("message", message);
res.data = map;
}
return res;
}
}

View File

@@ -121,4 +121,10 @@ public interface MaterialMapper {
int updatePriceNullByPrimaryKey(Long id);
int updateUnitIdNullByPrimaryKey(Long id);
List<MaterialVo4Unit> findByAll(
@Param("name") String name,
@Param("model") String model,
@Param("categoryId") Long categoryId,
@Param("categoryIds") String categoryIds);
}

View File

@@ -109,4 +109,11 @@ public interface SupplierMapper {
@Param("phonenum") String phonenum,
@Param("telephone") String telephone,
@Param("description") String description);
List<Supplier> findByAll(
@Param("supplier") String supplier,
@Param("type") String type,
@Param("phonenum") String phonenum,
@Param("telephone") String telephone,
@Param("description") String description);
}

View File

@@ -5,6 +5,7 @@ import com.jsh.erp.datasource.entities.Material;
import com.jsh.erp.datasource.entities.MaterialExample;
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
import com.jsh.erp.datasource.mappers.MaterialMapper;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,7 +14,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class MaterialService {
@@ -154,4 +157,33 @@ public class MaterialService {
return materialMapper.selectByExample(example);
}
public List<MaterialVo4Unit> findByAll(String name, String model, Long categoryId, String categoryIds) {
List<MaterialVo4Unit> resList = new ArrayList<MaterialVo4Unit>();
List<MaterialVo4Unit> list = materialMapper.findByAll(name, model, categoryId, categoryIds);
if (null != list) {
for (MaterialVo4Unit m : list) {
resList.add(m);
}
}
return resList;
}
public BaseResponseInfo importExcel(List<Material> mList) throws Exception {
BaseResponseInfo info = new BaseResponseInfo();
Map<String, Object> data = new HashMap<String, Object>();
try {
for(Material m: mList) {
materialMapper.insertSelective(m);
}
info.code = 200;
data.put("message", "成功");
} catch (Exception e) {
e.printStackTrace();
info.code = 500;
data.put("message", e.getMessage());
}
info.data = data;
return info;
}
}

View File

@@ -116,4 +116,8 @@ public class SupplierService {
List<Supplier> list = supplierMapper.selectByExample(example);
return list;
}
public List<Supplier> findByAll(String supplier, String type, String phonenum, String telephone, String description) {
return supplierMapper.findByAll(supplier, type, phonenum, telephone, description);
}
}

View File

@@ -77,4 +77,22 @@
UnitId = null
where Id = #{id,jdbcType=BIGINT}
</update>
<select id="findByAll" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
select m.*,u.uname unitName, mc.name categoryName
FROM jsh_material m
left JOIN jsh_unit u on m.UnitId = u.id
left JOIN jsh_materialcategory mc on m.CategoryId = mc.id
where 1=1
<if test="name != null">
and m.name like '%${name}%'
</if>
<if test="model != null">
and m.model like '%${model}%'
</if>
<if test="categoryId != 1">
and m.CategoryId in (${categoryIds})
</if>
order by m.id asc
</select>
</mapper>

View File

@@ -45,4 +45,25 @@
and description like '%${description}%'
</if>
</select>
<select id="findByAll" parameterType="com.jsh.erp.datasource.entities.SupplierExample" resultMap="BaseResultMap">
select *
FROM jsh_supplier
where 1=1
<if test="supplier != null">
and supplier like '%${supplier}%'
</if>
<if test="type != null">
and type='${type}'
</if>
<if test="phonenum != null">
and phonenum like '%${phonenum}%'
</if>
<if test="telephone != null">
and telephone like '%${telephone}%'
</if>
<if test="description != null">
and description like '%${description}%'
</if>
</select>
</mapper>