Excel 导入遍历
package com.founder.ec.cms.service.impl;
import com.founder.ec.cms.service.ProductListImportService;
import com.founder.ec.common.page.JspPage;
import com.founder.ec.common.page.Page;
import com.founder.ec.common.service.impl.BaseClassServiceImpl;
import com.founder.ec.goods_no.Goods;
import com.founder.ec.goods_no.ProductBrand;
import com.founder.ec.goods_no.ProductExpand;
import com.founder.ec.goods_no.ProductList;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by wangchuanfu on 17/9/5.
*/
@Service
public class ProductListImportServiceImpl extends
BaseClassServiceImpl implements ProductListImportService {
/**
* 批量导入
*
* @param
* @param is
* @return
* @throws Exception
*/
@Override
public String saveData(Goods goods, InputStream is) throws Exception {
ProductList productList=new ProductList();
//String fieldValues = "";
String nogoods = "";
goods.setAddTime(goods.getAddTime());
goods.setAddUserId(goods.getAddUserId());
// .xlsx的Excel文件
if (goods.getFileName().indexOf(".xlsx") > -1) {
XSSFWorkbook xssfWorkbook = null;
try {
xssfWorkbook = new XSSFWorkbook(is);
} catch (Exception e) {
e.printStackTrace();
}
XSSFRow row;
XSSFCell cell;
// 获取第一个sheet
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
int rowNum = xssfSheet.getLastRowNum();
for (int i = 1; i <= rowNum; i++) {
String fieldValues = "";
row = xssfSheet.getRow(i);
if(row!=null){
// 商品编码 1
cell = row.getCell(0);//
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}else{
return "empty";
}
productList.setProductCode((cell == null ? null : fieldValues));
nogoods += fieldValues + ",";
}else{
return "empty";
}
}
String[] goodsnos = nogoods.split(",");
for (int j = 0; j < goodsnos.length; j++) {
if ("null".equals(goodsnos[j]) || goodsnos[j] == "") {
return "empty";
}else{
ProductList goodsAbraod = getGoodsByGoodsNo(goodsnos[j]);
if (goodsAbraod == null) {
return "empty";
}
}
}
/**
* 数据在导入之前,先判断该商品编码是都为空,如果有一条为空,则整个excel不进行导入,
* 再根据商品编码查询数据,如果有一条为空,则整个excel依然不进行数据的导入,
* 此时,数据才是完全符合需求的,进行数据的导入
*/
for (int i = 1; i <= rowNum; i++) {
String fieldValues = "";
row = xssfSheet.getRow(i);
// 商品编码 1
cell = row.getCell(0);//
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
productList.setProductCode((cell == null ? null : fieldValues));
//通过商品编码查询productId,通过productId进行更新
/**
* --product 进行更新的时用PRODUCT_CODE,先根据product表中PRODUCT_CODE查询goods表中对应的product_id
--goods 进行更新的时用PRODUCT_ID;
--product : 商品编码:product_code,商品名称:product_name,最小订购量:product_least_order
--限购量:product_limit_amount
--goods :包装规格:stand_package, 重量:weight,市场价:market_price,售价:ec_price,
--库存:available_stock
*/
//商品名称
cell = row.getCell(1);//
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
productList.setProductName((cell == null ? null : fieldValues));
//最小订购量小于1不更新,
cell = row.getCell(2);
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null||cell.toString()=="" ){
productList.setProductLeastOrder(null);
}
else if(Integer.parseInt(fieldValues)<1){
productList.setProductLeastOrder(null);
}
else{
productList.setProductLeastOrder(new BigDecimal( fieldValues));
}
//每单订购量小于1不更新
cell = row.getCell(3);//
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null || cell.toString()==""){
productList.setOrderLimitAmount(null);
}
else if(Integer.parseInt(fieldValues)<1 ){
productList.setOrderLimitAmount(null);
}else{
productList.setOrderLimitAmount( new BigDecimal(fieldValues));
}
//包装规格
cell = row.getCell(4);//
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
goods.setPackageStandard((cell == null ? null : fieldValues));
//重量(kg)小于0时不更新
cell = row.getCell(5);//
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
//fieldValues = new DecimalFormat("#").format(cellValue);
BigDecimal bg = new BigDecimal(cellValue);
fieldValues=bg.setScale(2, BigDecimal.ROUND_HALF_UP).toString().trim();
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null ||cell.toString()==""){
goods.setWeight(null);
}else{
//重量保留两位小数
BigDecimal wei= new BigDecimal(fieldValues);
goods.setWeight((cell == null ? null :wei));
int d=wei.compareTo(BigDecimal.ZERO);
if(d==-1){
goods.setWeight(null);
}
}
//库存小于0不更新
cell = row.getCell(6);//
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null||cell.toString()==""){
goods.setAvailableStock(null);
}
else if(Integer.parseInt(fieldValues)<0){
goods.setAvailableStock(null);
}else{
goods.setAvailableStock((new BigDecimal(fieldValues)));
}
//售价小于10不更新
cell = row.getCell(7);//
/**
*
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null|| cell.toString()==""){
goods.setEcPrice(null);
}
else if(Integer.parseInt(fieldValues)<10){
goods.setEcPrice(null);
}else {
goods.setEcPrice(( new BigDecimal(fieldValues)));
}
*/
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
//fieldValues = new DecimalFormat("#").format(cellValue);
BigDecimal bg = new BigDecimal(cellValue);
fieldValues=bg.setScale(2, BigDecimal.ROUND_HALF_UP).toString().trim();
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null ||cell.toString()=="" ){
goods.setEcPrice(null);
}else{
//售价保留两位小数
BigDecimal wei= new BigDecimal(fieldValues);
if(wei.intValue()<10){
goods.setEcPrice(null);
}
goods.setEcPrice((cell == null ? null :wei));
int d=wei.compareTo(BigDecimal.ZERO);
if(d==-1){
goods.setEcPrice(null);
}
}
//市场价小于0不更新
cell = row.getCell(8);//
/**
*
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
fieldValues = new DecimalFormat("#").format(cellValue);
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null|| cell.toString()==""){
goods.setMarketPrice(null);
}
else if(Integer.parseInt(fieldValues)<0){
goods.setMarketPrice(null);
}
else{
goods.setMarketPrice(( new BigDecimal(fieldValues)));
}
*/
if (null != cell) {
fieldValues = "";
if (cell.getCellType() == 0) {
double cellValue = cell.getNumericCellValue();
//fieldValues = new DecimalFormat("#").format(cellValue);
BigDecimal bg = new BigDecimal(cellValue);
fieldValues=bg.setScale(2, BigDecimal.ROUND_HALF_UP).toString().trim();
} else if (cell.getCellType() == 1) {
fieldValues = cell.getStringCellValue();
}
}
if(cell==null ||cell.toString()==""){
goods.setMarketPrice(null);
}else{
//市场价保留两位小数
BigDecimal wei= new BigDecimal(fieldValues);
goods.setMarketPrice((cell == null ? null :wei));
int d=wei.compareTo(BigDecimal.ZERO);
if(d==-1){
goods.setMarketPrice(null);
}
}
if(productList!=null ||productList.getProductCode()!=null){
/**
* 更新PRODUCT表,根据PRODUCT_CODE
*/
commonDao.update("ProductList.updateImportProductList",productList);
}
/**
*更新GOODS表,根据productId
*/
ProductList p= getGoodsByGoodsNo(productList.getProductCode()) ;
if(p!=null){
goods.setProductID(p.getProductID());
}
/**
* 分别查询prefixName,suffixName,brandName,productCommonName的值
*/
/**
* 查询品牌名称
*/
String brandName="";
String prefixName="";
String suffixName="";
String productNames="";
ProductBrand brand=getProductBrandByProductId(p.getProductBrandID());
if(brand!=null){
brandName=brand.getProductBrandName()==null?"":brand.getProductBrandName();
}
ProductExpand productExpand=getProductExpandByProId(p.getProductID());
if(productExpand!=null){
prefixName=(productExpand.getStandby2()==null)?"":productExpand.getStandby2();
suffixName=(productExpand.getStandby3()==null)?"":productExpand.getStandby3();
}
String productCommonName=(p.getProductCommonName()==null)?"":p.getProductCommonName();
productNames=productList.getProductName()==null?"":productList.getProductName();
if(productNames==null ||productNames==""){
goods.setGoodsName(null);
}else{
goods.setGoodsName(prefixName+" "+brandName+" "+productNames+" "+productCommonName+" "+suffixName);
}
if(p.getProductID()!=null ){
commonDao.update("ProductList.updateImportGoods", goods);
}
}
}
return "ok";
}
private ProductExpand getProductExpandByProId(Long productID) {
return (ProductExpand) commonDao.queryForObject(
"ProductList.getProductExpandByProductId", productID);
}
/**
* 根据excel所给的商品编码查询是否符合该商品
* @param goodsNo
* @return
*/
public ProductList getGoodsByGoodsNo(String goodsNo) {
return (ProductList) commonDao.queryForObject(
"ProductList.getGoodsByGoodsNoImport", goodsNo);
}
private ProductBrand getProductBrandByProductId(Long productBrandID) {
return (ProductBrand) commonDao.queryForObject(
"ProductList.getProductBrandByProductId", productBrandID);
}
@Override
public Map<String, Object> getProductListPage(ProductList productList, Integer pageNo, Integer pageSize) {
productList.setStartRow((pageNo - 1) * pageSize + 1);
productList.setEndRow(productList.getStartRow() + pageSize
- 1);
List<ProductList> lmt = getProductListPage(productList);
Integer count = getProductListCount(productList);
// 实际起始位置
int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
Page page = new JspPage(skipResults, count, pageSize, lmt);
Map<String, Object> resMap = new HashMap<String, Object>();
resMap.put("total", page.getTotalCount());
resMap.put("rows", page.getResult());
return resMap;
}
private Integer getProductListCount(
ProductList productList) {
return (Integer) commonDao.queryForObject(
"ProductList.getProductListCount",
productList);
}
private List<ProductList> getProductListPage(
ProductList pharmacistComment) {
List<ProductList> ttmList = commonDao
.queryForList("ProductList.getProductListPage",
pharmacistComment);
return ttmList;
}
}
package com.founder.ec.cms.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jxl.Cell;
import jxl.Sheet;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.founder.ec.cms.model.MedicineDose;
import com.founder.ec.cms.service.MedicineDoseService;
import com.founder.ec.common.dao.CommonDao;
import com.founder.ec.common.service.impl.BaseClassServiceImpl;
import com.founder.ec.common.utils.StringUtil;
import com.founder.ec.product.model.Goods;
/**
* 类 <code>MedicineDoseServiceImpl</code>{商品用药信息 实体service 实现}
*
* @author dongqing
* @version 2014-7-24下午3:14:49
*/
@Service
public class MedicineDoseServiceImpl extends BaseClassServiceImpl<MedicineDose> implements MedicineDoseService {
// @Autowired
// private GoodsService goodsService;
@Autowired
private CommonDao commonDao;
@Override
public Map<String, Object> importMedicineDose(Sheet sheet) {
HashMap<String, Object> rslt = new HashMap<String, Object>();
//保存重复添加的商品编码
List<String> goodsNoList = new ArrayList<String>();
//保存在Goods表不存在的商品编码
List<String> goodsNotExistsList = new ArrayList<String>();
try {
int countColumn = sheet.getColumns();
int countRow = sheet.getRows();
if (countColumn < 10) {
rslt.put("code", -2);// Excel表格应该等于10列
} else if (countRow <= 1) {
rslt.put("code", -2);// Excel表格应该大于1行
} else {
StringBuffer msg = new StringBuffer(); // 记录错误消息
MedicineDose medicineDose = new MedicineDose();
Cell cell = null;
out: for (int i = 1; i < countRow; i++) {
for (int j = 0; j < countColumn; j++) {
cell = sheet.getCell(j, i);
String content = null == cell.getContents() ? "" : cell.getContents().trim();
switch (j) {
case 0: // 这里的商品Id修改为商品编码
try {
//medicineDose.setGoodsId(Long.parseLong(content));
medicineDose.setGoodsNo(content);
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,商品编码有误。").append("<br>");
break out;
}
break;
case 1:// 每次最低用量
try {
medicineDose.setLowestDoseTime(Double.parseDouble(content));
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,每次最低用量有误。").append("<br>");
break out;
}
break;
case 2:// 每天最低用药次数
try {
medicineDose.setLowestDoseDay(Long.parseLong(content));
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,每天最低用药次数有误。").append("<br>");
break out;
}
break;
case 3:// 每次最高用量
try {
medicineDose.setHighestDoseTime(Double.parseDouble(content));
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,每次最高用量有误。").append("<br>");
break out;
}
break;
case 4:// 每天最高用药次数
try {
medicineDose.setHighestDoseDay(Long.parseLong(content));
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,每天最高用药次数有误。").append("<br>");
break out;
}
break;
case 5:// 每盒总量
try {
medicineDose.setTotalDose(Double.parseDouble(content));
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,每盒总量有误。").append("<br>");
break out;
}
break;
case 6:// 是否为二次营销用药
try {
if (content.length() == 1) {
medicineDose.setIsTwice(content);
} else {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,是否为二次营销用药有误。").append("<br>");
break out;
}
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,是否为二次营销用药有误。").append("<br>");
break out;
}
break;
case 7:// 药品等级
try {
medicineDose.setMedicineGrade(content);
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,药品等级有误。").append("<br>");
break out;
}
break;
case 8:// 药品对应疾病
try {
medicineDose.setMedicineToDisease(content);
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,药品对应疾病有误。").append("<br>");
break out;
}
break;
case 9:// 药品最小单位
try {
medicineDose.setUnit(content);
} catch (Exception e) {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,药品最小单位有误。").append("<br>");
break out;
}
break;
default:
break;
}
}
// 当没有错误消息的时候保存
if (StringUtils.isEmpty(msg.toString())) {
//根据商品编码查询到此商品Id
Goods goods = new Goods();
goods.setGoodsNo(medicineDose.getGoodsNo());
goods=(Goods) commonDao.queryForObject("Goods.getProductIdByGoodsNo", goods);
if(goods!=null){
//根据商品Id查询medicine_Dose表是否有这个商品记录
MedicineDose md=(MedicineDose) commonDao.queryForObject("MedicineDose.getMedicineDoseByGoodsId", goods.getGoodsId());
if(md!=null){ //若有则将原来的记录标记为Y
goodsNoList.add(md.getGoodsNo());
md.setIsDelete("Y") ;
super.update(md);
}
medicineDose.setGoodsId(goods.getGoodsId());// 设置商品Id
super.save(medicineDose);
}else{
//将在goods表不存在的商品编码加入到集合中
goodsNotExistsList.add(medicineDose.getGoodsNo());
}
}
}
if (StringUtil.isEmpty(msg.toString())) {
rslt.put("code", 0);
//处理重复导入
if(goodsNoList!=null && goodsNoList.size()>0){
msg.append("商品编码为");
for(String str:goodsNoList){
msg.append(str).append(",");
}
msg.deleteCharAt(msg.length()-1); //去掉末尾的,
msg.append("被重复添加<br />");
}
//处理goods表查不到导入的商品
if(goodsNotExistsList!=null && goodsNotExistsList.size()>0){
msg.append("商品编码为");
for(String str:goodsNotExistsList){
msg.append(str).append(",");
}
msg.deleteCharAt(msg.length()-1); //去掉末尾的,
msg.append("在Goods表不存在,请重新核对信息再导入.<br />");
}
rslt.put("msg", msg.toString());
} else {
rslt.put("code", -1);
rslt.put("msg", msg.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return rslt;
}
}
package com.founder.ec.goods.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jxl.Cell;
import jxl.Sheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.founder.ec.common.dao.CommonDao;
import com.founder.ec.common.utils.StringUtil;
import com.founder.ec.goods.model.EcGoodsCode;
import com.founder.ec.goods.model.EcGoodsPrice;
import com.founder.ec.goods.model.Goods;
import com.founder.ec.goods.service.ImportExcelService;
@Service
public class ImportExcelServiceImpl implements ImportExcelService {
private List<EcGoodsPrice> ecGoodsPriceList;
private Map<String, Goods> goodsMap;
@Autowired
private CommonDao commonDao;
@Override
public HashMap<String, Object> importOrderItemTc(Sheet sheet,
EcGoodsPrice item) {
// TODO Auto-generated method stub
HashMap<String, Object> rslt = new HashMap<String, Object>();
ecGoodsPriceList = new ArrayList<EcGoodsPrice>();
goodsMap = new HashMap<String, Goods>();
EcGoodsCode code=null;
int countColumn = sheet.getColumns();
int countRow = sheet.getRows();
if (countColumn < 6) {
rslt.put("code", -2);// Excel表格应该大于4列
} else if (countRow <= 1) {
rslt.put("code", -2);// Excel表格应该大于1行
} else {
StringBuffer msg = new StringBuffer();
boolean isErr = false;
EcGoodsPrice goodsPrice = null;
Cell cell = null;
for (int i = 1; i < countRow; i++) {
for (int j = 0; j < countColumn; j++) {
cell = sheet.getCell(j, i);
String content = null == cell.getContents() ? "" : cell
.getContents().trim();
switch (j) {
case 0:// 商品编码
try {
Goods g = null;
goodsPrice = new EcGoodsPrice();
if (null != goodsMap.get(content)) {
g = goodsMap.get(content);
} else {
g = new Goods();
g.setGoodsNo(content);
g = (Goods) commonDao.queryForObject(
"Goods.getByGoodsNo", content);
}
if (null != g) {
goodsMap.put(content, g);
goodsPrice.setGoodsNo(g.getGoodsNo());
isErr = false;
} else {
msg.append("第" + (i + 1) + "行,第" + (j + 1) + "列,商品编码" + content + "不存在<br>");
break;
}
} catch (Exception e) {
// isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1)
+ "列,未能找到该编码的商品。").append("<br>");
break;
}
break;
case 1:// 市场分类
try {
if (goodsPrice != null) {
if (content!=null&&!"".equals(content)) {
code=new EcGoodsCode();
code.setIsDelete("N");
code.setType("market");
code.setName(content);
code=(EcGoodsCode) commonDao.queryForObject("EcGoodsCode.getSimilarEcGoodsCode",code);
if (code!=null) {
goodsPrice.setAutoType(code.getId());
isErr=false;
}else {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,市场分类"+content+"不存在。")
.append("<br>");
break;
}
}
isErr = false;
}
isErr = false;
} catch (Exception e) {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,市场分类有误。")
.append("<br>");
break;
}
break;
case 2:// 主要推广方式
try {
if (goodsPrice != null) {
if (content!=null&&!"".equals(content)) {
code=new EcGoodsCode();
code.setIsDelete("N");
code.setType("way");
code.setName(content);
code=(EcGoodsCode) commonDao.queryForObject("EcGoodsCode.getSimilarEcGoodsCode",code);
if (code!=null) {
goodsPrice.setMainSpreada(code.getId());
isErr=false;
}else {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,主要推广方式"+content+"不存在。")
.append("<br>");
break;
}
}
}
isErr = false;
} catch (Exception e) {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,主要推广方式有误。")
.append("<br>");
break;
}
break;
case 3:// 竞争对手
try {
if (goodsPrice != null) {
if (content!=null&&!"".equals(content)) {
code=new EcGoodsCode();
code.setIsDelete("N");
code.setType("comp");
code.setName(content);
code=(EcGoodsCode) commonDao.queryForObject("EcGoodsCode.getSimilarEcGoodsCode",code);
if (code!=null) {
goodsPrice.setTargetWeb(code.getId());
isErr=false;
}else {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,竞争对手"+content+"不存在。")
.append("<br>");
break;
}
}
}
} catch (Exception e) {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,竞争对手有误。")
.append("<br>");
break;
}
break;
case 4:// 厂家指导价
try {
if (goodsPrice != null) {
goodsPrice.setGuidePrice(new BigDecimal(content));
isErr = false;
}
} catch (Exception e) {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,厂家指导价有误。")
.append("<br>");
break;
}
break;
case 5:// 价格
try {
if (goodsPrice != null) {
goodsPrice.setTargetWebPrice(new BigDecimal(content));
isErr = false;
}
} catch (Exception e) {
isErr = true;
msg.append(
"第" + (i + 1) + "行,第" + (j + 1) + "列,价格有误。")
.append("<br>");
break;
}
break;
default:
break;
}
if (isErr) {
goodsPrice = null;
break;
}
}
if (goodsPrice!=null&&goodsPrice.getGoodsNo()!=null) {
goodsPrice.setAddUserId(item.getAddUserId());
ecGoodsPriceList.add(goodsPrice);
}
}
if (StringUtil.isEmpty(msg.toString())) {
rslt.put("code", 0);
} else {
rslt.put("code", -1);
rslt.put("msg", msg.toString());
}
}
try {
if (item.getOperate()!=null&&!"".equals(item.getOperate())) {
if ("save".equals(item.getOperate())) {
//批量插入至ORDER_ITEM_TC
commonDao.batchInsert("EcGoodsPrice.save", ecGoodsPriceList);
}else {
//批量插入至ORDER_ITEM_TC
commonDao.batchInsert("EcGoodsPrice.update", ecGoodsPriceList);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rslt;
}
}
$(function() {
$(document).keydown(function() {// 禁止使用F5刷新
var keynum;
var e = arguments[0];
if (window.event) {// IE
keynum = e.keyCode;
} else if (e.which) {// Netscape/Firefox/Opera
keynum = e.which;
}
if (keynum == 116) {
e.cancelBubble = true;
return false;
}
});
$(document).bind("contextmenu", function(e) {// 屏蔽右键
return false;
});
// var now = new Date();
// $('#saleTime').datebox(
// 'setValue',
// now.getFullYear() + "-" + (now.getMonth() + 1) + "-"
// + now.getDate());
initSWFUpload({
upload_url : appPath + "/page/importExcel/orderItemTc",
post_params : {
"userId" : $("#userId").val(),
"saleTime" : $("#saleTime").datebox("getValue")
},
button_placeholder_id : "orderImportBtn",
upload_start_handler : uploadStartFn,
upload_success_handler : importOk,
file_types : "*.xls",
debug : false,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
}
});
});
function uploadStartFn(file) {
$("#swfText").val(file.name);
var saleTime = $("#saleTime").datebox("getValue");
if(saleTime==null||saleTime==''){
$.messager.alert("系统提示","请选择销售日期!");
return false;
}
var flag = false;
doAjax({
url : appPath + "/jsp/common/session_user_id.jsp",
cache : false,
async : false,
success : function(userIdDom) {
$("#rslt").html("");
$("#uploadUserIdDiv").html(userIdDom);
swfUploadObj.removePostParam("uploadUserId");
swfUploadObj
.addPostParam("uploadUserId", $("#sessionUserId").val());
swfUploadObj.addPostParam("addUserId", $("#sessionUserId").val());
swfUploadObj.addPostParam("userId", $("#sessionUserId").val());
swfUploadObj.addPostParam("saleTime", saleTime);
flag = true;
}
});
return flag;
}
function importOk(file, serverData) {
var serverDataObj = eval("(" + serverData + ")");
if (typeof (serverDataObj.code) != "undefined") {
var progress = new FileProgress(file,
swfUploadObj.customSettings.progressTarget);
progress.setComplete();
progress.setStatus("完成.");
progress.toggleCancel(false);
switch (serverDataObj.code) {
case 0:
$("#rslt").html("");
$("#rslt").html("导入成功");
break;
case -1:
if (typeof (serverDataObj.msg) != "undefined") {
if (serverDataObj.msg.indexOf('不存在') != -1) {
$("#rslt").html("导入成功!但以下数据有误:<br/>" + serverDataObj.msg);
} else {
$("#rslt").html("以下数据有误:<br/>" + serverDataObj.msg);
}
}
break;
case -2:
$("#rslt").html("提供的Excel格式或者数据有误");
break;
case -3:
$("#rslt").html("内部错误,请联系管理员");
break;
default:
break;
}
}
}
Excel 导入遍历的更多相关文章
- C# Excel导入、导出【源码下载】
本篇主要介绍C#的Excel导入.导出. 目录 1. 介绍:描述第三方类库NPOI以及Excel结构 2. Excel导入:介绍C#如何调用NPOI进行Excel导入,包含:流程图.NOPI以及C#代 ...
- 利用反射实现通用的excel导入导出
如果一个项目中存在多种信息的导入导出,为了简化代码,就需要用反射实现通用的excel导入导出 实例代码如下: 1.创建一个 Book类,并编写set和get方法 package com.bean; p ...
- Excel 导入到Datatable 中,再使用常规方法写入数据库
首先呢?要看你的电脑的office版本,我的是office 2013 .为了使用oledb程序,需要安装一个引擎.名字为AccessDatabaseEngine.exe.这里不过多介绍了哦.它的数据库 ...
- Excel导入导出(篇二)
<body> <h3>一.Excel导入</h3> <h5>.模板下载:<a href="UpFiles/TemplateFiles/学 ...
- C# Excel导入、导出
本篇主要介绍C#的Excel导入.导出. 目录 1. 介绍:描述第三方类库NPOI以及Excel结构 2. Excel导入:介绍C#如何调用NPOI进行Excel导入,包含:流程图.NOPI以及C#代 ...
- Octopus——excel导入导出工具
Octopus Octopus是一个简易的Excel导入导出工具.目前主要就两个功能: 导入:将excel中一行数据转换为指定的java对象,并通过指定的正则表达式检查合法性. 导出:按照给定的xml ...
- JeeSite中Excel导入导出
在各种管理系统中,数据的导入导出是经常用到的功能,通常导入导出以Excel.CSV格式居多.如果是学习的过程中,最好是自己实现数据导入与导出的功能,然而在项目中,还是调用现成的功能比较好.近期一直使用 ...
- Java 使用 Jxl 实现 Excel 导入导出
开发过程中经常需要用到数据的导入导出功能,之前用的是POI,这次使用JXL,JXL相对于POI来说要轻量简洁许多,在数据量不大的情况下还是非常实用的.这里做一下使用JXL的学习记录.首先需要导入相应的 ...
- Spring Boot学习笔记----POI(Excel导入导出)
业务:动态生成模板导出Excel,用户修改完再导入Excel. Spring boot + bootstrap + poi 1.添加Dependence <dependency> < ...
随机推荐
- String、StringBuffer与StringBuilder 复习回顾总结
1.三者在执行速度方面的比较:StringBuilder > StringBuffer > String 2.String <(StringBuffer,StringBuild ...
- Java数据通讯中使用Googgle Protobuf 序列化与反序列化
概念 1.什么是protocol buffer ProtocolBuffer是用于结构化数据串行化的灵活.高效.自动的方法,有如XML,不过它更小.更快.也更简单.你可以定义自己的数据结构,然后使用代 ...
- 转载:案例用Excel对会员客户交易数据进行RFM分析
案例:用Excel对会员客户交易数据进行RFM分析 背景: 一个会员服务的企业,有近1年约1200个会员客户的收银数据.由于公司想针对不同 ...
- SpringMVC小结
一放下就生疏,所以要温故,所以要笔记. Tip,多数情况下,SpringMVC建议单例执行,Struts2建议多例执行. 原因就在于Struts2使用属性驱动或模型驱动,而SpringMVC则使用方法 ...
- CSS3小清新下拉菜单 简易大方
之前有分享过几款CSS3菜单和jQuery菜单,像这款HTML5/CSS3自定义下拉框 3D卡片折叠动画3D效果非常华丽,这次要分享的这款相对比较简单,很适合用在用户的操作面板上.先来看看效果图: 怎 ...
- AOP-配合slf4j打印日志
基本思想 凡在目标实例上或在目标实例方法(非静态方法)上标注自定义注解@AutoLog,其方法执行时将触发AOP操作: @AutoLog只有一个参数,用来控制是否打印该方法的参数和返回结果的json字 ...
- Thinkphp5笔记七:设置错误页面②
更加完美的去设置错误页面. 一.准备一个错误页面 error.html,位置:thinkphp\template\index\default\error.html ,准备把前段所有的错误提示都指向这里 ...
- 备份一篇SVN的文章, 从搭建到主备库
来源: http://h2ofly.blog.51cto.com/6834926/1539141 [svn简介] svn用于版本管理数据,它采用了分支管理系统.在它出现之前存在C ...
- 续:纠正:ubuntu 【6.04 LTS】可以安装安装 ! for《Oracle-10.2.0.1,打补丁10.2.0.5:在 debian 版本4【不含4】以上,及 ubuntu 7.04【不含7.04】以上都可以安装!》
经过长时间的试错.探索,终于查明无法顺利安装oracle10g的原因,并且找到顺利安装的方式. 要点: 无法安装的根本原因有2: 1:libc6-dev的版本为2.23-0ubuntu10,其中的cr ...
- Lua 中 number 转换各种进制,以及string串转number
原文地址:http://blog.csdn.net/david_dai_1108/article/details/71699449 --region : NumConvert.lua --Date : ...