从jsh远程仓库更新

(cherry picked from commit 36139e26a4)
This commit is contained in:
cjl
2019-01-15 11:48:38 +08:00
parent 1e1e5f6ed5
commit 693a7558ba
39 changed files with 12153 additions and 10992 deletions

View File

@@ -5,13 +5,18 @@ import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.App;
import com.jsh.erp.service.app.AppService;
import com.jsh.erp.service.userBusiness.UserBusinessService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.FileUtils;
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 java.io.*;
import java.util.List;
import java.util.Properties;
/**
* @author ji_sheng_hua 752*718*920
@@ -26,14 +31,7 @@ public class AppController {
@Resource
private UserBusinessService userBusinessService;
/**
* create by: cjl
* description:
* 桌面菜单按钮初始化
* create time: 2019/1/11 17:01
* @Param: request
* @return com.alibaba.fastjson.JSONObject
*/
@GetMapping(value = "/findDesk")
public JSONObject findDesk(HttpServletRequest request) {
JSONObject obj = new JSONObject();
@@ -123,4 +121,38 @@ public class AppController {
}
return arr;
}
/**
* 上传图片
* @param fileInfo
* @param request
*/
@PostMapping(value = "/uploadImg")
public BaseResponseInfo uploadImg(MultipartFile fileInfo, @RequestParam("fileInfoName") String fileName,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
try {
if (fileInfo != null) {
String basePath = request.getSession().getServletContext().getRealPath("/"); //默认windows文件路径linux环境下生成的目录与项目同级而不是下级
String path = basePath + "upload/images/deskIcon/"; //windows环境下的路径
Properties pro = System.getProperties();
String osName = pro.getProperty("os.name");//获得当前操作系统的名称
if("Linux".equals(osName) || "linux".equals(osName) || "LINUX".equals(osName)){
path = basePath + "/upload/images/deskIcon/"; //linux环境下的路径
}
FileUtils.SaveFileFromInputStream(fileInfo.getInputStream(), path, fileName);
res.code = 200;
res.data = "上传图片成功";
}
} catch (FileNotFoundException e) {
e.printStackTrace();
res.code = 500;
res.data = "获取图片失败";
} catch (IOException e) {
e.printStackTrace();
res.code = 500;
res.data = "上传图片失败";
}
return res;
}
}

View File

@@ -9,11 +9,12 @@ import com.jsh.erp.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Transactional;
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;
@@ -32,7 +33,8 @@ public class DepotItemController {
@Resource
private DepotItemService depotItemService;
@Resource
private MaterialService materialService;
/**
* 根据材料信息获取
@@ -267,7 +269,26 @@ public class DepotItemController {
}
}
/**
* 查询计量单位信息
*
* @return
*/
public String findUnitName(Long mId) {
String unitName = "";
try {
unitName = materialService.findUnitName(mId);
if (unitName != null) {
unitName = unitName.substring(1, unitName.length() - 1);
if (unitName.equals("null")) {
unitName = "";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return unitName;
}
@GetMapping(value = "/getDetailList")
public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId,
@@ -403,14 +424,12 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
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);
Double prevPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, true) - sumPrice("出库", pid, diEx.getMaterialid(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMaterialid(), monthTime, false);
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
Double prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true) - sumNumber("出库", pid, diEx.getMId(), monthTime, true);
Double InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
Double OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMColor());
//扩展信息
@@ -464,9 +483,9 @@ public class DepotItemController {
Double thisAllPrice = 0.0;
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
Double prevPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, true) - sumPrice("出库", pid, diEx.getMaterialid(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMaterialid(), monthTime, false);
Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
thisAllPrice = thisAllPrice + (prevPrice + InPrice - OutPrice);
}
}
@@ -512,12 +531,10 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
Double InSum = sumNumberBuyOrSale("入库", "采购", diEx.getMaterialid(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "采购退货", diEx.getMaterialid(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "采购", diEx.getMaterialid(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", diEx.getMaterialid(), monthTime);
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
Double InSum = sumNumberBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel());
//扩展信息
@@ -574,16 +591,14 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
Double OutSumRetail = sumNumberBuyOrSale("出库", "零售", diEx.getMaterialid(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "销售", diEx.getMaterialid(), monthTime);
Double InSumRetail = sumNumberBuyOrSale("入库", "零售退货", diEx.getMaterialid(), monthTime);
Double InSum = sumNumberBuyOrSale("入库", "销售退货", diEx.getMaterialid(), monthTime);
Double OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", diEx.getMaterialid(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "销售", diEx.getMaterialid(), monthTime);
Double InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", diEx.getMaterialid(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "销售退货", diEx.getMaterialid(), monthTime);
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
Double OutSumRetail = sumNumberBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
Double InSumRetail = sumNumberBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
Double InSum = sumNumberBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
Double OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
Double InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel());
//扩展信息
@@ -640,10 +655,8 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
Double InSum = sumNumberGift("礼品充值", pid, diEx.getMaterialid(), "in");
Double OutSum = sumNumberGift("礼品销售", pid, diEx.getMaterialid(), "out");
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
Double InSum = sumNumberGift("礼品充值", pid, diEx.getMId(), "in");
Double OutSum = sumNumberGift("礼品销售", pid, diEx.getMId(), "out");
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel());
//扩展信息
@@ -666,6 +679,77 @@ public class DepotItemController {
return res;
}
/**
* 导出excel表格
* @param currentPage
* @param pageSize
* @param projectId
* @param monthTime
* @param headIds
* @param materialIds
* @param request
* @param response
* @return
*/
@GetMapping(value = "/exportExcel")
public BaseResponseInfo exportExcel(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("projectId") Integer projectId,
@RequestParam("monthTime") String monthTime,
@RequestParam("headIds") String headIds,
@RequestParam("materialIds") String materialIds,
HttpServletRequest request, HttpServletResponse response) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
String message = "成功";
try {
List<DepotItemVo4WithInfoEx> dataList = depotItemService.findByAll(headIds, materialIds, currentPage, pageSize);
//存放数据json数组
Integer pid = projectId;
String[] names = {"名称", "型号", "单位", "单价", "上月结存数量", "入库数量", "出库数量", "本月结存数量", "结存金额"};
String title = "库存报表";
List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
String[] objs = new String[9];
Double prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true) - sumNumber("出库", pid, diEx.getMId(), monthTime, true);
Double InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
Double OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
Double unitPrice = 0.0;
if (prevSum + InSum - OutSum != 0.0) {
unitPrice = (prevPrice + InPrice - OutPrice) / (prevSum + InSum - OutSum);
}
Double thisSum = prevSum + InSum - OutSum;
Double thisAllPrice = prevPrice + InPrice - OutPrice;
objs[0] = diEx.getMName().toString();
objs[1] = diEx.getMModel().toString();
objs[2] = diEx.getMaterialUnit().toString();
objs[3] = unitPrice.toString();
objs[4] = prevSum.toString();
objs[5] = InSum.toString();
objs[6] = OutSum.toString();
objs[7] = thisSum.toString();
objs[8] = thisAllPrice.toString();
objects.add(objs);
}
}
File file = ExcelUtils.exportObjectsWithoutTitle(title, names, title, objects);
ExportExecUtil.showExec(file, file.getName() + "-" + monthTime, 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

@@ -1,180 +1,309 @@
package com.jsh.erp.controller;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji|sheng|hua 华夏ERP
*/
@RestController
@RequestMapping(value = "/material")
public class MaterialController {
private Logger logger = LoggerFactory.getLogger(MaterialController.class);
@Resource
private MaterialService materialService;
@GetMapping(value = "/checkIsExist")
public String checkIsExist(@RequestParam("id") Long id, @RequestParam("name") String name,
@RequestParam("model") String model, @RequestParam("color") String color,
@RequestParam("standard") String standard, @RequestParam("mfrs") String mfrs,
@RequestParam("otherField1") String otherField1, @RequestParam("otherField2") String otherField2,
@RequestParam("otherField3") String otherField3, @RequestParam("unit") String unit,@RequestParam("unitId") Long unitId,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int exist = materialService.checkIsExist(id, name, model, color, standard, mfrs,
otherField1, otherField2, otherField3, unit, unitId);
if(exist > 0) {
objectMap.put("status", true);
} else {
objectMap.put("status", false);
}
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
}
/**
* 批量设置状态-启用或者禁用
* @param enabled
* @param materialIDs
* @param request
* @return
*/
@PostMapping(value = "/batchSetEnable")
public String batchSetEnable(@RequestParam("enabled") Boolean enabled,
@RequestParam("materialIDs") String materialIDs,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = materialService.batchSetEnable(enabled, materialIDs);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 根据id来查询商品名称
* @param id
* @param request
* @return
*/
@GetMapping(value = "/findById")
public BaseResponseInfo findById(@RequestParam("id") Long id, HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
try {
List<MaterialVo4Unit> list = materialService.findById(id);
res.code = 200;
res.data = list;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查找商品信息-下拉框
* @param mpList
* @param request
* @return
*/
@GetMapping(value = "/findBySelect")
public JSONArray findBySelect(@RequestParam("mpList") String mpList, HttpServletRequest request) {
JSONArray dataArray = new JSONArray();
try {
List<MaterialVo4Unit> dataList = materialService.findBySelect();
String[] mpArr = mpList.split(",");
//存放数据json数组
if (null != dataList) {
for (MaterialVo4Unit material : dataList) {
JSONObject item = new JSONObject();
item.put("Id", material.getId());
String ratio; //比例
if (material.getUnitid() == null || material.getUnitid().equals("")) {
ratio = "";
} else {
ratio = material.getUnitName();
ratio = ratio.substring(ratio.indexOf("("));
}
//品名/型号/扩展信息/包装
String MaterialName = material.getName() + ((material.getModel() == null || material.getModel().equals("")) ? "" : "(" + material.getModel() + ")");
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("颜色")) {
MaterialName = MaterialName + ((material.getColor() == null || material.getColor().equals("")) ? "" : "(" + material.getColor() + ")");
}
if (mpArr[i].equals("规格")) {
MaterialName = MaterialName + ((material.getStandard() == null || material.getStandard().equals("")) ? "" : "(" + material.getStandard() + ")");
}
if (mpArr[i].equals("制造商")) {
MaterialName = MaterialName + ((material.getMfrs() == null || material.getMfrs().equals("")) ? "" : "(" + material.getMfrs() + ")");
}
if (mpArr[i].equals("自定义1")) {
MaterialName = MaterialName + ((material.getOtherfield1() == null || material.getOtherfield1().equals("")) ? "" : "(" + material.getOtherfield1() + ")");
}
if (mpArr[i].equals("自定义2")) {
MaterialName = MaterialName + ((material.getOtherfield2() == null || material.getOtherfield2().equals("")) ? "" : "(" + material.getOtherfield2() + ")");
}
if (mpArr[i].equals("自定义3")) {
MaterialName = MaterialName + ((material.getOtherfield3() == null || material.getOtherfield3().equals("")) ? "" : "(" + material.getOtherfield3() + ")");
}
}
MaterialName = MaterialName + ((material.getUnit() == null || material.getUnit().equals("")) ? "" : "(" + material.getUnit() + ")") + ratio;
item.put("MaterialName", MaterialName);
dataArray.add(item);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return dataArray;
}
/**
* 查找商品信息-统计排序
* @param request
* @return
*/
@GetMapping(value = "/findByOrder")
public BaseResponseInfo findByOrder(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<Material> dataList = materialService.findByOrder();
String mId = "";
if (null != dataList) {
for (Material material : dataList) {
mId = mId + material.getId() + ",";
}
}
if (mId != "") {
mId = mId.substring(0, mId.lastIndexOf(","));
}
map.put("mIds", mId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
}
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.*;
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;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji|sheng|hua 华夏ERP
*/
@RestController
@RequestMapping(value = "/material")
public class MaterialController {
private Logger logger = LoggerFactory.getLogger(MaterialController.class);
@Resource
private MaterialService materialService;
@GetMapping(value = "/checkIsExist")
public String checkIsExist(@RequestParam("id") Long id, @RequestParam("name") String name,
@RequestParam("model") String model, @RequestParam("color") String color,
@RequestParam("standard") String standard, @RequestParam("mfrs") String mfrs,
@RequestParam("otherField1") String otherField1, @RequestParam("otherField2") String otherField2,
@RequestParam("otherField3") String otherField3, @RequestParam("unit") String unit,@RequestParam("unitId") Long unitId,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int exist = materialService.checkIsExist(id, name, model, color, standard, mfrs,
otherField1, otherField2, otherField3, unit, unitId);
if(exist > 0) {
objectMap.put("status", true);
} else {
objectMap.put("status", false);
}
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
}
/**
* 批量设置状态-启用或者禁用
* @param enabled
* @param materialIDs
* @param request
* @return
*/
@PostMapping(value = "/batchSetEnable")
public String batchSetEnable(@RequestParam("enabled") Boolean enabled,
@RequestParam("materialIDs") String materialIDs,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = materialService.batchSetEnable(enabled, materialIDs);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 根据id来查询商品名称
* @param id
* @param request
* @return
*/
@GetMapping(value = "/findById")
public BaseResponseInfo findById(@RequestParam("id") Long id, HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
try {
List<MaterialVo4Unit> list = materialService.findById(id);
res.code = 200;
res.data = list;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查找商品信息-下拉框
* @param mpList
* @param request
* @return
*/
@GetMapping(value = "/findBySelect")
public JSONArray findBySelect(@RequestParam("mpList") String mpList, HttpServletRequest request) {
JSONArray dataArray = new JSONArray();
try {
List<MaterialVo4Unit> dataList = materialService.findBySelect();
String[] mpArr = mpList.split(",");
//存放数据json数组
if (null != dataList) {
for (MaterialVo4Unit material : dataList) {
JSONObject item = new JSONObject();
item.put("Id", material.getId());
String ratio; //比例
if (material.getUnitid() == null || material.getUnitid().equals("")) {
ratio = "";
} else {
ratio = material.getUnitName();
ratio = ratio.substring(ratio.indexOf("("));
}
//品名/型号/扩展信息/包装
String MaterialName = material.getName() + ((material.getModel() == null || material.getModel().equals("")) ? "" : "(" + material.getModel() + ")");
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("颜色")) {
MaterialName = MaterialName + ((material.getColor() == null || material.getColor().equals("")) ? "" : "(" + material.getColor() + ")");
}
if (mpArr[i].equals("规格")) {
MaterialName = MaterialName + ((material.getStandard() == null || material.getStandard().equals("")) ? "" : "(" + material.getStandard() + ")");
}
if (mpArr[i].equals("制造商")) {
MaterialName = MaterialName + ((material.getMfrs() == null || material.getMfrs().equals("")) ? "" : "(" + material.getMfrs() + ")");
}
if (mpArr[i].equals("自定义1")) {
MaterialName = MaterialName + ((material.getOtherfield1() == null || material.getOtherfield1().equals("")) ? "" : "(" + material.getOtherfield1() + ")");
}
if (mpArr[i].equals("自定义2")) {
MaterialName = MaterialName + ((material.getOtherfield2() == null || material.getOtherfield2().equals("")) ? "" : "(" + material.getOtherfield2() + ")");
}
if (mpArr[i].equals("自定义3")) {
MaterialName = MaterialName + ((material.getOtherfield3() == null || material.getOtherfield3().equals("")) ? "" : "(" + material.getOtherfield3() + ")");
}
}
MaterialName = MaterialName + ((material.getUnit() == null || material.getUnit().equals("")) ? "" : "(" + material.getUnit() + ")") + ratio;
item.put("MaterialName", MaterialName);
dataArray.add(item);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return dataArray;
}
/**
* 查找商品信息-统计排序
* @param request
* @return
*/
@GetMapping(value = "/findByOrder")
public BaseResponseInfo findByOrder(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<Material> dataList = materialService.findByOrder();
String mId = "";
if (null != dataList) {
for (Material material : dataList) {
mId = mId + material.getId() + ",";
}
}
if (mId != "") {
mId = mId.substring(0, mId.lastIndexOf(","));
}
map.put("mIds", mId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
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

@@ -1,262 +1,434 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.Supplier;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji|sheng|hua 华夏erp
*/
@RestController
@RequestMapping(value = "/supplier")
public class SupplierController {
private Logger logger = LoggerFactory.getLogger(SupplierController.class);
@Resource
private SupplierService supplierService;
@Resource
private UserBusinessService userBusinessService;
/**
* 更新供应商-只更新预付款,其余用原来的值
* @param supplierId
* @param advanceIn
* @param request
* @return
*/
@PostMapping(value = "/updateAdvanceIn")
public String updateAdvanceIn(@RequestParam("supplierId") Long supplierId,
@RequestParam("advanceIn") Double advanceIn,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = supplierService.updateAdvanceIn(supplierId, advanceIn);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 查找客户信息-下拉框
* @param request
* @return
*/
@PostMapping(value = "/findBySelect_cus")
public JSONArray findBySelectCus(HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> supplierList = supplierService.findBySelectCus();
JSONArray dataArray = new JSONArray();
if (null != supplierList) {
for (Supplier supplier : supplierList) {
JSONObject item = new JSONObject();
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(null, null, "[" + supplier.getId().toString() + "]");
} catch (DataAccessException e) {
logger.error(">>>>>>>>>>>>>>>>>查询用户对应的客户:存在异常!");
}
if (flag == true) {
item.put("id", supplier.getId());
item.put("supplier", supplier.getSupplier()); //客户名称
dataArray.add(item);
}
}
}
arr = dataArray;
} catch(Exception e){
e.printStackTrace();
}
return arr;
}
/**
* 查找供应商信息-下拉框
* @param request
* @return
*/
@PostMapping(value = "/findBySelect_sup")
public JSONArray findBySelectSup(HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> supplierList = supplierService.findBySelectSup();
JSONArray dataArray = new JSONArray();
if (null != supplierList) {
for (Supplier supplier : supplierList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
//供应商名称
item.put("supplier", supplier.getSupplier());
dataArray.add(item);
}
}
arr = dataArray;
} catch(Exception e){
e.printStackTrace();
}
return arr;
}
/**
* 查找会员信息-下拉框
* @param request
* @return
*/
@PostMapping(value = "/findBySelect_retail")
public JSONArray findBySelectRetail(HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> supplierList = supplierService.findBySelectRetail();
JSONArray dataArray = new JSONArray();
if (null != supplierList) {
for (Supplier supplier : supplierList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
//客户名称
item.put("supplier", supplier.getSupplier());
item.put("advanceIn", supplier.getAdvancein()); //预付款金额
dataArray.add(item);
}
}
arr = dataArray;
} catch(Exception e){
e.printStackTrace();
}
return arr;
}
/**
* 根据id查找信息
* @param supplierId
* @param request
* @return
*/
@GetMapping(value = "/findById")
public BaseResponseInfo findById(@RequestParam("supplierId") Long supplierId,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
try {
JSONArray dataArray = new JSONArray();
List<Supplier> dataList = supplierService.findById(supplierId);
if (null != dataList) {
for (Supplier supplier : dataList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
//名称
item.put("supplier", supplier.getSupplier());
item.put("type", supplier.getType());
item.put("contacts", supplier.getContacts());
item.put("phonenum", supplier.getPhonenum());
item.put("email", supplier.getEmail());
item.put("AdvanceIn", supplier.getAdvancein());
item.put("BeginNeedGet", supplier.getBeginneedget());
item.put("BeginNeedPay", supplier.getBeginneedpay());
item.put("isystem", supplier.getIsystem() == (short) 0 ? "" : "");
item.put("description", supplier.getDescription());
item.put("fax", supplier.getFax());
item.put("telephone", supplier.getTelephone());
item.put("address", supplier.getAddress());
item.put("taxNum", supplier.getTaxnum());
item.put("bankName", supplier.getBankname());
item.put("accountNumber", supplier.getAccountnumber());
item.put("taxRate", supplier.getTaxrate());
item.put("enabled", supplier.getEnabled());
dataArray.add(item);
}
res.code = 200;
res.data = dataArray;
}
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 批量设置状态-启用或者禁用
* @param enabled
* @param supplierIDs
* @param request
* @return
*/
@PostMapping(value = "/batchSetEnable")
public String batchSetEnable(@RequestParam("enabled") Boolean enabled,
@RequestParam("supplierIDs") String supplierIDs,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = supplierService.batchSetEnable(enabled, supplierIDs);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 用户对应客户显示
* @param type
* @param keyId
* @param request
* @return
*/
@PostMapping(value = "/findUserCustomer")
public JSONArray findUserCustomer(@RequestParam("UBType") String type, @RequestParam("UBKeyId") String keyId,
HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> dataList = supplierService.findUserCustomer();
//开始拼接json数据
JSONObject outer = new JSONObject();
outer.put("id", 1);
outer.put("text", "客户列表");
outer.put("state", "open");
//存放数据json数
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (Supplier supplier : dataList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
item.put("text", supplier.getSupplier());
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(type, keyId, "[" + supplier.getId().toString() + "]");
} catch (Exception e) {
logger.error(">>>>>>>>>>>>>>>>>设置用户对应的客户:类型" + type + " KeyId为 " + keyId + " 存在异常!");
}
if (flag == true) {
item.put("checked", true);
}
//结束
dataArray.add(item);
}
}
outer.put("children", dataArray);
arr.add(outer);
} catch (Exception e) {
e.printStackTrace();
}
return arr;
}
}
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.Supplier;
import com.jsh.erp.service.supplier.SupplierService;
import com.jsh.erp.service.userBusiness.UserBusinessService;
import com.jsh.erp.utils.*;
import jxl.Sheet;
import jxl.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
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;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji|sheng|hua 华夏erp
*/
@RestController
@RequestMapping(value = "/supplier")
public class SupplierController {
private Logger logger = LoggerFactory.getLogger(SupplierController.class);
@Resource
private SupplierService supplierService;
@Resource
private UserBusinessService userBusinessService;
/**
* 更新供应商-只更新预付款,其余用原来的值
* @param supplierId
* @param advanceIn
* @param request
* @return
*/
@PostMapping(value = "/updateAdvanceIn")
public String updateAdvanceIn(@RequestParam("supplierId") Long supplierId,
@RequestParam("advanceIn") Double advanceIn,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = supplierService.updateAdvanceIn(supplierId, advanceIn);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 查找客户信息-下拉框
* @param request
* @return
*/
@PostMapping(value = "/findBySelect_cus")
public JSONArray findBySelectCus(HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> supplierList = supplierService.findBySelectCus();
JSONArray dataArray = new JSONArray();
if (null != supplierList) {
for (Supplier supplier : supplierList) {
JSONObject item = new JSONObject();
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(null, null, "[" + supplier.getId().toString() + "]");
} catch (DataAccessException e) {
logger.error(">>>>>>>>>>>>>>>>>查询用户对应的客户:存在异常!");
}
if (flag == true) {
item.put("id", supplier.getId());
item.put("supplier", supplier.getSupplier()); //客户名称
dataArray.add(item);
}
}
}
arr = dataArray;
} catch(Exception e){
e.printStackTrace();
}
return arr;
}
/**
* 查找供应商信息-下拉框
* @param request
* @return
*/
@PostMapping(value = "/findBySelect_sup")
public JSONArray findBySelectSup(HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> supplierList = supplierService.findBySelectSup();
JSONArray dataArray = new JSONArray();
if (null != supplierList) {
for (Supplier supplier : supplierList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
//供应商名称
item.put("supplier", supplier.getSupplier());
dataArray.add(item);
}
}
arr = dataArray;
} catch(Exception e){
e.printStackTrace();
}
return arr;
}
/**
* 查找会员信息-下拉框
* @param request
* @return
*/
@PostMapping(value = "/findBySelect_retail")
public JSONArray findBySelectRetail(HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> supplierList = supplierService.findBySelectRetail();
JSONArray dataArray = new JSONArray();
if (null != supplierList) {
for (Supplier supplier : supplierList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
//客户名称
item.put("supplier", supplier.getSupplier());
item.put("advanceIn", supplier.getAdvancein()); //预付款金额
dataArray.add(item);
}
}
arr = dataArray;
} catch(Exception e){
e.printStackTrace();
}
return arr;
}
/**
* 根据id查找信息
* @param supplierId
* @param request
* @return
*/
@GetMapping(value = "/findById")
public BaseResponseInfo findById(@RequestParam("supplierId") Long supplierId,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
try {
JSONArray dataArray = new JSONArray();
List<Supplier> dataList = supplierService.findById(supplierId);
if (null != dataList) {
for (Supplier supplier : dataList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
//名称
item.put("supplier", supplier.getSupplier());
item.put("type", supplier.getType());
item.put("contacts", supplier.getContacts());
item.put("phonenum", supplier.getPhonenum());
item.put("email", supplier.getEmail());
item.put("AdvanceIn", supplier.getAdvancein());
item.put("BeginNeedGet", supplier.getBeginneedget());
item.put("BeginNeedPay", supplier.getBeginneedpay());
item.put("isystem", supplier.getIsystem() == (short) 0 ? "" : "");
item.put("description", supplier.getDescription());
item.put("fax", supplier.getFax());
item.put("telephone", supplier.getTelephone());
item.put("address", supplier.getAddress());
item.put("taxNum", supplier.getTaxnum());
item.put("bankName", supplier.getBankname());
item.put("accountNumber", supplier.getAccountnumber());
item.put("taxRate", supplier.getTaxrate());
item.put("enabled", supplier.getEnabled());
dataArray.add(item);
}
res.code = 200;
res.data = dataArray;
}
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 批量设置状态-启用或者禁用
* @param enabled
* @param supplierIDs
* @param request
* @return
*/
@PostMapping(value = "/batchSetEnable")
public String batchSetEnable(@RequestParam("enabled") Boolean enabled,
@RequestParam("supplierIDs") String supplierIDs,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = supplierService.batchSetEnable(enabled, supplierIDs);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 用户对应客户显示
* @param type
* @param keyId
* @param request
* @return
*/
@PostMapping(value = "/findUserCustomer")
public JSONArray findUserCustomer(@RequestParam("UBType") String type, @RequestParam("UBKeyId") String keyId,
HttpServletRequest request) {
JSONArray arr = new JSONArray();
try {
List<Supplier> dataList = supplierService.findUserCustomer();
//开始拼接json数
JSONObject outer = new JSONObject();
outer.put("id", 1);
outer.put("text", "客户列表");
outer.put("state", "open");
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (Supplier supplier : dataList) {
JSONObject item = new JSONObject();
item.put("id", supplier.getId());
item.put("text", supplier.getSupplier());
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(type, keyId, "[" + supplier.getId().toString() + "]");
} catch (Exception e) {
logger.error(">>>>>>>>>>>>>>>>>设置用户对应的客户:类型" + type + " KeyId为 " + keyId + " 存在异常!");
}
if (flag == true) {
item.put("checked", true);
}
//结束
dataArray.add(item);
}
}
outer.put("children", dataArray);
arr.add(outer);
} catch (Exception e) {
e.printStackTrace();
}
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;
}
/**
* 导入excel表格-供应商
* @param supplierFile
* @param request
* @param response
* @return
*/
@PostMapping(value = "/importExcelVendor")
public void importExcelVendor(MultipartFile supplierFile,
HttpServletRequest request, HttpServletResponse response) throws Exception{
importFun(supplierFile);
response.sendRedirect("../pages/manage/vendor.html");
}
/**
* 导入excel表格-客户
* @param supplierFile
* @param request
* @param response
* @return
*/
@PostMapping(value = "/importExcelCustomer")
public void importExcelCustomer(MultipartFile supplierFile,
HttpServletRequest request, HttpServletResponse response) throws Exception{
importFun(supplierFile);
response.sendRedirect("../pages/manage/customer.html");
}
/**
* 导入excel表格-会员
* @param supplierFile
* @param request
* @param response
* @return
*/
@PostMapping(value = "/importExcelMember")
public void importExcelMember(MultipartFile supplierFile,
HttpServletRequest request, HttpServletResponse response) throws Exception{
importFun(supplierFile);
response.sendRedirect("../pages/manage/member.html");
}
public String importFun(MultipartFile supplierFile){
BaseResponseInfo info = new BaseResponseInfo();
Map<String, Object> data = new HashMap<String, Object>();
String message = "成功";
try {
Sheet src = null;
//文件合法性校验
try {
Workbook workbook = Workbook.getWorkbook(supplierFile.getInputStream());
src = workbook.getSheet(0);
} catch (Exception e) {
message = "导入文件不合法,请检查";
data.put("message", message);
info.code = 400;
info.data = data;
}
//读取所有的摄像机编码
//每行中数据顺序 "名称","类型","联系人","电话","电子邮箱","预收款","期初应收","期初应付","备注","传真","手机","地址","纳税人识别号","开户行","账号","税率","状态"
List<Supplier> sList = new ArrayList<Supplier>();
for (int i = 1; i < src.getRows(); i++) {
Supplier s = new Supplier();
s.setSupplier(ExcelUtils.getContent(src, i, 0));
s.setType(ExcelUtils.getContent(src, i, 1));
s.setContacts(ExcelUtils.getContent(src, i, 2));
s.setPhonenum(ExcelUtils.getContent(src, i, 3));
s.setEmail(ExcelUtils.getContent(src, i, 4));
s.setAdvancein(parseDoubleEx(ExcelUtils.getContent(src, i, 5)));
s.setBeginneedget(parseDoubleEx(ExcelUtils.getContent(src, i, 6)));
s.setBeginneedpay(parseDoubleEx(ExcelUtils.getContent(src, i, 7)));
s.setDescription(ExcelUtils.getContent(src, i, 8));
s.setFax(ExcelUtils.getContent(src, i, 9));
s.setTelephone(ExcelUtils.getContent(src, i, 10));
s.setAddress(ExcelUtils.getContent(src, i, 11));
s.setTaxnum(ExcelUtils.getContent(src, i, 12));
s.setBankname(ExcelUtils.getContent(src, i, 13));
s.setAccountnumber(ExcelUtils.getContent(src, i, 14));
s.setTaxrate(parseDoubleEx(ExcelUtils.getContent(src, i, 15)));
String enabled = ExcelUtils.getContent(src, i, 16);
s.setEnabled(enabled.equals("启用")? true: false);
s.setIsystem(Byte.parseByte("1"));
sList.add(s);
}
info = supplierService.importExcel(sList);
} catch (Exception e) {
e.printStackTrace();
message = "导入失败";
info.code = 500;
data.put("message", message);
info.data = data;
}
return null;
}
public Double parseDoubleEx(String str){
if(!StringUtil.isEmpty(str)) {
return Double.parseDouble(str);
} else {
return null;
}
}
}