提交 d28e558e authored 作者: zgy's avatar zgy

完成商品导入导出功能

上级 2dfc748d
package com.platform.controller;
import com.platform.entity.TbCategoryTemplateEntity;
import com.platform.service.TbCategoryTemplateService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* Controller
*
* @author lipengjun
* @date 2020-01-07 12:23:04
*/
@Controller
@RequestMapping("tbcategorytemplate")
public class TbCategoryTemplateController {
@Autowired
private TbCategoryTemplateService tbCategoryTemplateService;
/**
* 查看列表
*/
@RequestMapping("/list")
@RequiresPermissions("tbcategorytemplate:list")
@ResponseBody
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<TbCategoryTemplateEntity> tbCategoryTemplateList = tbCategoryTemplateService.queryList(query);
int total = tbCategoryTemplateService.queryTotal(query);
PageUtils pageUtil = new PageUtils(tbCategoryTemplateList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 查看信息
*/
@RequestMapping("/info/{id}")
@RequiresPermissions("tbcategorytemplate:info")
@ResponseBody
public R info(@PathVariable("id") String id) {
TbCategoryTemplateEntity tbCategoryTemplate = tbCategoryTemplateService.queryObject(id);
return R.ok().put("tbCategoryTemplate", tbCategoryTemplate);
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("tbcategorytemplate:save")
@ResponseBody
public R save(@RequestBody TbCategoryTemplateEntity tbCategoryTemplate) {
tbCategoryTemplateService.save(tbCategoryTemplate);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("tbcategorytemplate:update")
@ResponseBody
public R update(@RequestBody TbCategoryTemplateEntity tbCategoryTemplate) {
tbCategoryTemplateService.update(tbCategoryTemplate);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("tbcategorytemplate:delete")
@ResponseBody
public R delete(@RequestBody String[] ids) {
tbCategoryTemplateService.deleteBatch(ids);
return R.ok();
}
/**
* 查看所有列表
*/
@RequestMapping("/queryAll")
@ResponseBody
public R queryAll(@RequestParam Map<String, Object> params) {
List<TbCategoryTemplateEntity> list = tbCategoryTemplateService.queryList(params);
return R.ok().put("list", list);
}
}
...@@ -7,6 +7,7 @@ import com.platform.service.TbCfGoodstwotypeService; ...@@ -7,6 +7,7 @@ import com.platform.service.TbCfGoodstwotypeService;
import com.platform.service.TbCfStationItemService; import com.platform.service.TbCfStationItemService;
import com.platform.util.ApiBaseAction; import com.platform.util.ApiBaseAction;
import com.platform.utils.*; import com.platform.utils.*;
import com.platform.utils.excel.ExcelImport;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
...@@ -15,6 +16,7 @@ import org.springframework.stereotype.Controller; ...@@ -15,6 +16,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -176,8 +178,30 @@ public class TbCfStationItemController extends ApiBaseAction { ...@@ -176,8 +178,30 @@ public class TbCfStationItemController extends ApiBaseAction {
*/ */
@RequestMapping("/exportExcel") @RequestMapping("/exportExcel")
@ResponseBody @ResponseBody
public R exportExcel() { public R exportExcel() throws IOException {
tbCfStationItemService.exportExcel(); try {
return R.ok(); tbCfStationItemService.exportExcel();
return R.ok();
} catch (Exception e) {
return R.error();
}
}
/**
* 从excel导入
*
* @param multipartFile
* @return
*/
@RequestMapping("/importExcel")
@ResponseBody
public R importExcel(@RequestParam("file") MultipartFile multipartFile) {
try {
tbCfStationItemService.importExcel(multipartFile);
return R.ok();
} catch (Exception e) {
return R.error();
}
} }
} }
package com.platform.dao;
import com.platform.entity.TbCategoryTemplateEntity;
/**
* Dao
*
* @author lipengjun
* @date 2020-01-07 12:23:04
*/
public interface TbCategoryTemplateDao extends BaseDao<TbCategoryTemplateEntity> {
}
...@@ -20,4 +20,5 @@ public interface TbCfCategoryDao extends BaseDao<TbCfCategoryEntity> { ...@@ -20,4 +20,5 @@ public interface TbCfCategoryDao extends BaseDao<TbCfCategoryEntity> {
int changStatusBatch(String[] itemId); int changStatusBatch(String[] itemId);
TbCfCategoryEntity queryByOrderNum(@Param("orderNum") Integer orderNum, @Param("itemId") String itemId); TbCfCategoryEntity queryByOrderNum(@Param("orderNum") Integer orderNum, @Param("itemId") String itemId);
int deleteByItemId(String itemId);
} }
package com.platform.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 实体
* 表名 tb_category_template
*
* @author lipengjun
* @date 2020-01-07 12:23:04
*/
public class TbCategoryTemplateEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 规格Id
*/
private String id;
/**
* 规格名称
*/
private String categoryName;
/**
* 规格描述(规格名称英文)
*/
private String categoryDesc;
/**
* 删除标志
*/
private Integer delFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 设置:规格Id
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:规格Id
*/
public String getId() {
return id;
}
/**
* 设置:规格名称
*/
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
/**
* 获取:规格名称
*/
public String getCategoryName() {
return categoryName;
}
/**
* 设置:规格描述(规格名称英文)
*/
public void setCategoryDesc(String categoryDesc) {
this.categoryDesc = categoryDesc;
}
/**
* 获取:规格描述(规格名称英文)
*/
public String getCategoryDesc() {
return categoryDesc;
}
/**
* 设置:删除标志
*/
public void setDelFlag(Integer delFlag) {
this.delFlag = delFlag;
}
/**
* 获取:删除标志
*/
public Integer getDelFlag() {
return delFlag;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
package com.platform.service;
import com.platform.entity.TbCategoryTemplateEntity;
import java.util.List;
import java.util.Map;
/**
* Service接口
*
* @author lipengjun
* @date 2020-01-07 12:23:04
*/
public interface TbCategoryTemplateService {
/**
* 根据主键查询实体
*
* @param id 主键
* @return 实体
*/
TbCategoryTemplateEntity queryObject(String id);
/**
* 分页查询
*
* @param map 参数
* @return list
*/
List<TbCategoryTemplateEntity> queryList(Map<String, Object> map);
/**
* 分页统计总数
*
* @param map 参数
* @return 总数
*/
int queryTotal(Map<String, Object> map);
/**
* 保存实体
*
* @param tbCategoryTemplate 实体
* @return 保存条数
*/
int save(TbCategoryTemplateEntity tbCategoryTemplate);
/**
* 根据主键更新实体
*
* @param tbCategoryTemplate 实体
* @return 更新条数
*/
int update(TbCategoryTemplateEntity tbCategoryTemplate);
/**
* 根据主键删除
*
* @param id
* @return 删除条数
*/
int delete(String id);
/**
* 根据主键批量删除
*
* @param ids
* @return 删除条数
*/
int deleteBatch(String[] ids);
}
...@@ -5,7 +5,10 @@ import com.platform.entity.ItemInfo; ...@@ -5,7 +5,10 @@ import com.platform.entity.ItemInfo;
import com.platform.entity.TbCfStationItemEntity; import com.platform.entity.TbCfStationItemEntity;
import com.platform.utils.R; import com.platform.utils.R;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -21,7 +24,6 @@ public interface TbCfStationItemService { ...@@ -21,7 +24,6 @@ public interface TbCfStationItemService {
/** /**
* 根据主键查询实体 * 根据主键查询实体
* *
*
* @return 实体 * @return 实体
*/ */
ItemInfo queryItemInfoById(String itemId); ItemInfo queryItemInfoById(String itemId);
...@@ -76,16 +78,20 @@ public interface TbCfStationItemService { ...@@ -76,16 +78,20 @@ public interface TbCfStationItemService {
/** /**
* 修改商品状态 * 修改商品状态
*
* @param status * @param status
* @param itemIds * @param itemIds
* @return * @return
*/ */
void changeItemStatus(Integer status,String[] itemIds); void changeItemStatus(Integer status, String[] itemIds);
/** /**
* 导出到Excel * 导出到Excel
*
* @param * @param
*/ */
void exportExcel(); void exportExcel() throws IOException;
void importExcel(MultipartFile multipartFile);
} }
package com.platform.service.impl;
import com.platform.dao.TbCategoryTemplateDao;
import com.platform.entity.TbCategoryTemplateEntity;
import com.platform.service.TbCategoryTemplateService;
import com.platform.utils.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Service实现类
*
* @author lipengjun
* @date 2020-01-07 12:23:04
*/
@Service("tbCategoryTemplateService")
public class TbCategoryTemplateServiceImpl implements TbCategoryTemplateService {
@Autowired
private TbCategoryTemplateDao tbCategoryTemplateDao;
@Override
public TbCategoryTemplateEntity queryObject(String id) {
return tbCategoryTemplateDao.queryObject(id);
}
@Override
public List<TbCategoryTemplateEntity> queryList(Map<String, Object> map) {
return tbCategoryTemplateDao.queryList(map);
}
@Override
public int queryTotal(Map<String, Object> map) {
return tbCategoryTemplateDao.queryTotal(map);
}
@Override
public int save(TbCategoryTemplateEntity tbCategoryTemplate) {
tbCategoryTemplate.setId(IdUtil.createIdbyUUID());
tbCategoryTemplate.setCreateTime(new Date());
tbCategoryTemplate.setUpdateTime(new Date());
tbCategoryTemplate.setDelFlag(1);
return tbCategoryTemplateDao.save(tbCategoryTemplate);
}
@Override
public int update(TbCategoryTemplateEntity tbCategoryTemplate) {
tbCategoryTemplate.setUpdateTime(new Date());
return tbCategoryTemplateDao.update(tbCategoryTemplate);
}
@Override
public int delete(String id) {
return tbCategoryTemplateDao.delete(id);
}
@Override
public int deleteBatch(String[] ids) {
return tbCategoryTemplateDao.deleteBatch(ids);
}
}
...@@ -4,17 +4,21 @@ import com.platform.dao.*; ...@@ -4,17 +4,21 @@ import com.platform.dao.*;
import com.platform.entity.*; import com.platform.entity.*;
import com.platform.service.TbCfStationItemService; import com.platform.service.TbCfStationItemService;
import com.platform.utils.IdUtil; import com.platform.utils.IdUtil;
import com.platform.utils.UuidUtil;
import com.platform.utils.excel.ExcelExport; import com.platform.utils.excel.ExcelExport;
import com.platform.utils.excel.ExcelImport;
import com.platform.utils.util.StringUtil; import com.platform.utils.util.StringUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -163,7 +167,7 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService { ...@@ -163,7 +167,7 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
} }
@Override @Override
public void update(ItemDescSkus itemSkus, String itemDesc) throws UnsupportedEncodingException { public void update(ItemDescSkus itemSkus, String itemDesc) throws UnsupportedEncodingException {
String itemId = itemSkus.getItemId(); String itemId = itemSkus.getItemId();
Date updateTime = new Date(); Date updateTime = new Date();
//商品sku //商品sku
...@@ -245,23 +249,32 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService { ...@@ -245,23 +249,32 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
tbCfItemDescDao.update(itemDescEntity); tbCfItemDescDao.update(itemDescEntity);
} }
//先删除之前的属性模板 //先删除之前的属性模板
tbCfCategoryDao.deleteByItemId(itemId);
tbCfOptionDao.deleteByItemId(itemId); tbCfOptionDao.deleteByItemId(itemId);
//商品规格 //商品规格
//商品规格
List<TbCfCategoryEntity> tree = itemSkus.getTree(); List<TbCfCategoryEntity> tree = itemSkus.getTree();
for (int i = 0; i < tree.size(); i++) { for (int i = 0; i < tree.size(); i++) {
String cid = IdUtil.createIdbyUUID();
String categoryDesc = tree.get(i).getCategoryDesc(); String categoryDesc = tree.get(i).getCategoryDesc();
TbCfCategoryEntity categoryEntity = tbCfCategoryDao.queryByOrderNum(i + 1, itemId); TbCfCategoryEntity categoryEntity = new TbCfCategoryEntity();
categoryEntity.setUpdateTime(updateTime); categoryEntity.setCategoryId(cid);
categoryEntity.setCreateTime(new Date());
categoryEntity.setUpdateTime(new Date());
categoryEntity.setDelFlag(1);
categoryEntity.setItemId(itemId);
categoryEntity.setCategoryName(tree.get(i).getCategoryName()); categoryEntity.setCategoryName(tree.get(i).getCategoryName());
categoryEntity.setCategoryDesc(categoryDesc); categoryEntity.setCategoryDesc(categoryDesc);
tbCfCategoryDao.update(categoryEntity);
int num = i + 1; int num = i + 1;
categoryEntity.setOrderNum(num);
categoryEntity.setOption("option" + num);
tbCfCategoryDao.save(categoryEntity);
String[] desc = categoryDesc.split(","); String[] desc = categoryDesc.split(",");
for (int j = 0; j < desc.length; j++) { for (int j = 0; j < desc.length; j++) {
//保存新的商品属性模板 //商品属性
TbCfOptionEntity optionEntity = new TbCfOptionEntity(); TbCfOptionEntity optionEntity = new TbCfOptionEntity();
optionEntity.setOptionId(IdUtil.createIdbyUUID()); optionEntity.setOptionId(IdUtil.createIdbyUUID());
optionEntity.setCid(categoryEntity.getCategoryId()); optionEntity.setCid(cid);
optionEntity.setItemId(itemId); optionEntity.setItemId(itemId);
optionEntity.setOptiionSpecies(desc[j]); optionEntity.setOptiionSpecies(desc[j]);
optionEntity.setCreateTime(new Date()); optionEntity.setCreateTime(new Date());
...@@ -301,51 +314,46 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService { ...@@ -301,51 +314,46 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
} }
@Override @Override
public void exportExcel() { public void exportExcel() throws IOException {
// if (itemIds != null) {
// itemList = tbCfStationItemDao.queryByItems(itemIds);
// } else {
List<TbCfStationItemEntityExtends> itemList = tbCfStationItemDao.queryByItems(); List<TbCfStationItemEntityExtends> itemList = tbCfStationItemDao.queryByItems();
// }
ExcelExport excelExport = new ExcelExport(); ExcelExport excelExport = new ExcelExport();
List<Object[]> list = new ArrayList<Object[]>(); List<Object[]> list = new ArrayList<Object[]>();
String status = null;
for (int i = 0; i < itemList.size(); i++) { for (int i = 0; i < itemList.size(); i++) {
List<Object> obj = new ArrayList<Object>(); List<Object> obj = new ArrayList<Object>();
status = itemList.get(i).getEnableFlag().toString();
if ("1".equals(status)) {
status = "在线销售";
} else {
status = "已下架";
}
obj.add(itemList.get(i).getItemId() == null ? null : itemList.get(i).getItemId());
obj.add(itemList.get(i).getItemImg() == null ? null : itemList.get(i).getItemImg());
obj.add(itemList.get(i).getItemCode() == null ? null : itemList.get(i).getItemCode()); obj.add(itemList.get(i).getItemCode() == null ? null : itemList.get(i).getItemCode());
obj.add(itemList.get(i).getItemName() == null ? null : itemList.get(i).getItemName()); obj.add(itemList.get(i).getItemName() == null ? null : itemList.get(i).getItemName());
obj.add(itemList.get(i).getItemBrief() == null ? null : itemList.get(i).getItemBrief());
obj.add(itemList.get(i).getItemTags() == null ? null : itemList.get(i).getItemTags());
obj.add(itemList.get(i).getItemPrice() == null ? null : itemList.get(i).getItemPrice()); obj.add(itemList.get(i).getItemPrice() == null ? null : itemList.get(i).getItemPrice());
obj.add(itemList.get(i).getDiscountPrice() == null ? null : itemList.get(i).getDiscountPrice());
obj.add(itemList.get(i).getItemImg() == null ? null : itemList.get(i).getItemImg());
obj.add(itemList.get(i).getItemCount() == null ? null : itemList.get(i).getItemCount()); obj.add(itemList.get(i).getItemCount() == null ? null : itemList.get(i).getItemCount());
obj.add(itemList.get(i).getItemNum() == null ? null : itemList.get(i).getItemNum());
obj.add(itemList.get(i).getItemCategory() == null ? null : itemList.get(i).getItemCategory()); obj.add(itemList.get(i).getItemCategory() == null ? null : itemList.get(i).getItemCategory());
obj.add(itemList.get(i).getItemCategorytwo() == null ? null : itemList.get(i).getItemCategorytwo()); obj.add(itemList.get(i).getItemCategorytwo() == null ? null : itemList.get(i).getItemCategorytwo());
obj.add(itemList.get(i).getItemDescritionId() == null ? null : itemList.get(i).getItemDescritionId()); obj.add(itemList.get(i).getItemDescritionId() == null ? null : itemList.get(i).getItemDescritionId());
obj.add(itemList.get(i).getEnableFlag() == null ? null : status); obj.add(itemList.get(i).getEnableFlag() == null ? null : itemList.get(i).getEnableFlag());
obj.add(itemList.get(i).getCreateTime() == null ? null : itemList.get(i).getCreateTime()); obj.add(itemList.get(i).getCreateTime() == null ? null : itemList.get(i).getCreateTime());
obj.add(itemList.get(i).getItemDesc() == null ? null : itemList.get(i).getItemDesc()); obj.add(itemList.get(i).getItemDesc() == null ? null : itemList.get(i).getItemDesc());
list.add(obj.toArray()); list.add(obj.toArray());
} }
String[] header = new String[]{"商品编号", "商品名称", "商品标题", "商品标签", "商品价格", "折扣价格",
"商品图片", "库存", "一级分类", "二级分类", "商品品名", "状态", "创建时间", "商品详情"};
String[] header = new String[]{"商品ID", "商品图片", "商品编号", "商品名称", "商品价格", "商品库存",
"点击量", "一级分类", "二级分类", "商品品名", "状态", "创建时间", "商品详情"};
excelExport.addSheetByArray("商品信息", list, header); excelExport.addSheetByArray("商品信息", list, header);
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String time = format.format(date);
File file = new File("D:\\Afrishop\\" + time);
if (!file.exists()) {
file.mkdirs();
}
File excel = new File(file, "product.xlsx");
if (excel.exists()) {
excel.delete();
}
excel.createNewFile();
OutputStream fis; OutputStream fis;
try { try {
fis = new FileOutputStream("D:\\product.xlsx"); fis = new FileOutputStream(excel);
excelExport.getWorkbook().write(fis); excelExport.getWorkbook().write(fis);
...@@ -356,5 +364,46 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService { ...@@ -356,5 +364,46 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
} }
} }
@Override
public void importExcel(MultipartFile multipartFile) {
List<String[]> list = ExcelImport.getExcelData(multipartFile);
list.remove(0);
for (int i = 0; i < list.size(); i++) {
String[] values = list.get(i);
//处理excel数据
handleExcel(values);
}
}
//"商品编号", "商品名称", "商品标题", "商品标签", "商品价格", "折扣价格", "库存","商品图片", "一级分类", "二级分类", "商品品名", "状态", "创建时间", "商品详情"
public void handleExcel(String[] values) {
//商品信息
TbCfStationItemEntity item = new TbCfStationItemEntity();
String itemId = IdUtil.createIdbyUUID();
item.setItemId(itemId);
item.setItemCode(values[0]);
item.setItemName(values[1]);
item.setItemBrief(values[2]);
item.setItemTags(values[3]);
item.setItemPrice(new BigDecimal(values[4]));
item.setDiscountPrice(new BigDecimal(values[5]));
item.setItemImg(values[6]);
item.setItemCount(Long.parseLong(values[7]));
item.setItemCategory(values[8]);
item.setItemCategorytwo(values[9]);
item.setItemDescritionId(values[10]);
item.setEnableFlag(Integer.parseInt(values[11]));
item.setCreateTime(new Date());
item.setItemNum(0L);
tbCfStationItemDao.save(item);
//商品详情
TbCfItemDescEntity desc = new TbCfItemDescEntity();
desc.setItemId(itemId);
desc.setItemDesc(values[13]);
desc.setCreateTime(new Date());
desc.setUpdateTime(new Date());
desc.setDelFlag(1);
tbCfItemDescDao.save(desc);
}
} }
<?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.platform.dao.TbCategoryTemplateDao">
<resultMap type="com.platform.entity.TbCategoryTemplateEntity" id="tbCategoryTemplateMap">
<result property="id" column="id"/>
<result property="categoryName" column="category_name"/>
<result property="categoryDesc" column="category_desc"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="queryObject" resultType="com.platform.entity.TbCategoryTemplateEntity">
select
`id`,
`category_name`,
`category_desc`,
`del_flag`,
`create_time`,
`update_time`
from tb_category_template
where id = #{id}
</select>
<select id="queryList" resultType="com.platform.entity.TbCategoryTemplateEntity">
select
`id`,
`category_name`,
`category_desc`,
`del_flag`,
`create_time`,
`update_time`
from tb_category_template
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
order by id desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from tb_category_template
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert id="save" parameterType="com.platform.entity.TbCategoryTemplateEntity">
insert into tb_category_template(
`id`,
`category_name`,
`category_desc`,
`del_flag`,
`create_time`,
`update_time`)
values(
#{id},
#{categoryName},
#{categoryDesc},
#{delFlag},
#{createTime},
#{updateTime})
</insert>
<update id="update" parameterType="com.platform.entity.TbCategoryTemplateEntity">
update tb_category_template
<set>
<if test="categoryName != null">`category_name` = #{categoryName}, </if>
<if test="categoryDesc != null">`category_desc` = #{categoryDesc}, </if>
<if test="delFlag != null">`del_flag` = #{delFlag}, </if>
<if test="createTime != null">`create_time` = #{createTime}, </if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where id = #{id}
</update>
<delete id="delete">
delete from tb_category_template where id = #{value}
</delete>
<delete id="deleteBatch">
delete from tb_category_template where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
...@@ -128,5 +128,7 @@ ...@@ -128,5 +128,7 @@
#{categoryId} #{categoryId}
</foreach> </foreach>
</delete> </delete>
<delete id="deleteByItemId">
delete from tb_cf_category where item_id =#{itemId}
</delete>
</mapper> </mapper>
\ No newline at end of file
...@@ -54,19 +54,27 @@ ...@@ -54,19 +54,27 @@
</select> </select>
<select id="queryByItems" resultType="com.platform.entity.TbCfStationItemEntityExtends"> <select id="queryByItems" resultType="com.platform.entity.TbCfStationItemEntityExtends">
select select
i.item_id, i.item_id,
`item_img`, `item_code`,
`item_code`, `item_name`,
`item_name`, `item_brief`,
`item_price`, `item_category`,
`item_count`, `item_price`,
`item_num`, `discount_price`,
`item_category`, `item_url`,
`item_categorytwo`, `item_img`,
`item_descrition_id`, `item_tags`,
`enable_flag`, `item_num`,
i.create_time, `item_count`,
item_desc itemDesc `item_sku`,
`item_top`,
`platform_code`,
`platform_name`,
`enable_flag`,
i.create_time,
`item_categorytwo`,
`item_descrition_id`,
item_desc itemDesc
from tb_cf_station_item i left join tb_cf_item_desc d on i.item_id=d.item_id from tb_cf_station_item i left join tb_cf_item_desc d on i.item_id=d.item_id
where where
i.enable_flag!=0 i.enable_flag!=0
......
<!DOCTYPE html>
<html>
<head>
<title></title>
#parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak style="height: calc(100% - 15px);">
<div v-show="showList" style="height: 100%;">
<Row :gutter="16">
<div class="search-group">
<i-col span="4">
<i-input v-model="q.name" @on-enter="query" placeholder="名称"/>
</i-col>
<i-button @click="query">查询</i-button>
<i-button @click="reloadSearch">重置</i-button>
</div>
<div class="buttons-group">
#if($shiro.hasPermission("tbcategorytemplate:save"))
<i-button type="info" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</i-button>
#end
#if($shiro.hasPermission("tbcategorytemplate:update"))
<i-button type="warning" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</i-button>
#end
#if($shiro.hasPermission("tbcategorytemplate:delete"))
<i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>
#end
</div>
</Row>
<table id="jqGrid"></table>
</div>
<Card v-show="!showList">
<p slot="title">{{title}}</p>
<i-form ref="formValidate" :model="tbCategoryTemplate" :rules="ruleValidate" :label-width="80">
<Form-item label="规格名称" prop="categoryName">
<i-input v-model="tbCategoryTemplate.categoryName" placeholder="规格名称"/>
</Form-item>
<Form-item label="规格描述" prop="categoryDesc">
<i-input v-model="tbCategoryTemplate.categoryDesc" placeholder="规格描述(规格名称的英文)"/>
</Form-item>
<Form-item>
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
<i-button type="warning" @click="reload" style="margin-left: 8px"/>返回</i-button>
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
</Form-item>
</i-form>
</Card>
</div>
<script src="${rc.contextPath}/js/sys/tbcategorytemplate.js?_${date.systemTime}"></script>
</body>
</html>
\ No newline at end of file
...@@ -203,7 +203,18 @@ ...@@ -203,7 +203,18 @@
</i-button> </i-button>
#end #end
#if($shiro.hasPermission("tbcfstationitem:import")) #if($shiro.hasPermission("tbcfstationitem:import"))
<i-button type="primary" @click="importExcel()"><i class="fa fa-chevron-up"></i>导入 <i-button type="primary" @click="modal = true"><i class="fa fa-chevron-up"></i>导入
<Modal
v-model="modal"
title="商品导入"
@on-ok="ok"
@on-cancel="cancel">
<template>
<Upload action="../tbcfstationitem/importExcel/">
<i-Button icon="ios-cloud-upload-outline">请选择</i-Button>
</Upload>
</template>
</Modal>
</i-button> </i-button>
#end #end
#if($shiro.hasPermission("tbcfstationitem:export")) #if($shiro.hasPermission("tbcfstationitem:export"))
...@@ -396,19 +407,18 @@ ...@@ -396,19 +407,18 @@
</i-form> </i-form>
</Card> </Card>
</div> <script src="${rc.contextPath}/statics/libs/iview.js"></script>
<script src="${rc.contextPath}/statics/libs/iview.js"></script> <script src="${rc.contextPath}/js/sys/tbcfstationitem.js?_${date.systemTime}"></script>
<script src="${rc.contextPath}/js/sys/tbcfstationitem.js?_${date.systemTime}"></script> <script type="text/javascript">
<script type="text/javascript"> var content = UE.getEditor('itemDesc');
var content = UE.getEditor('itemDesc'); UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl; UE.Editor.prototype.getActionUrl = function (action) {
UE.Editor.prototype.getActionUrl = function (action) { if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') { return '${rc.contextPath}/api/osstest/uploaditemimage';
return '${rc.contextPath}/api/osstest/uploaditemimage'; } else {
} else { return this._bkGetActionUrl.call(this, action);
return this._bkGetActionUrl.call(this, action); }
} };
}; </script>
</script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -139,9 +139,9 @@ function eyeImages(data) { ...@@ -139,9 +139,9 @@ function eyeImages(data) {
* @param name * @param name
*/ */
function handleResetForm(vue, name) { function handleResetForm(vue, name) {
if (vue.$refs[name]!==undefined) { if (vue.$refs[name] !== undefined) {
vue.$refs[name].resetFields(); vue.$refs[name].resetFields();
} }
}; };
...@@ -617,6 +617,11 @@ useFormat = function (cellvalue) { ...@@ -617,6 +617,11 @@ useFormat = function (cellvalue) {
return cellvalue == 0 ? '已使用' : '未使用'; return cellvalue == 0 ? '已使用' : '未使用';
}; };
categoryFormat = function (cellvalue) {
return cellvalue == 1 ? '正常' : '已删除';
};
/** /**
* 订单状态翻译 (0取消,10未付款,20已付款,40已发货,50交易成功,60交易关闭) * 订单状态翻译 (0取消,10未付款,20已付款,40已发货,50交易成功,60交易关闭)
* @param cellvalue * @param cellvalue
...@@ -691,7 +696,7 @@ userTypeFormat = function (cellvalue) { ...@@ -691,7 +696,7 @@ userTypeFormat = function (cellvalue) {
returnStr = "facebook"; returnStr = "facebook";
} else if (cellvalue == '3') { } else if (cellvalue == '3') {
returnStr = "twitter"; returnStr = "twitter";
}else if (cellvalue == '4') { } else if (cellvalue == '4') {
returnStr = "手机"; returnStr = "手机";
} }
} }
......
$(function () {
$("#jqGrid").Grid({
url: '../tbcategorytemplate/list',
colModel: [
{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
{label: '规格名称', name: 'categoryName', index: 'category_name', width: 80},
{label: '规格描述', name: 'categoryDesc', index: 'category_desc', width: 80},
{label: '状态', name: 'delFlag', index: 'del_flag', width: 80, formatter: categoryFormat},
{label: '创建时间', name: 'createTime', index: 'create_time', width: 80}
]
});
});
let vm = new Vue({
el: '#rrapp',
data: {
showList: true,
title: null,
tbCategoryTemplate: {},
ruleValidate: {
name: [
{required: true, message: '名称不能为空', trigger: 'blur'}
]
},
q: {
name: ''
}
},
methods: {
query: function () {
vm.reload();
},
add: function () {
vm.showList = false;
vm.title = "新增";
vm.tbCategoryTemplate = {};
},
update: function (event) {
let id = getSelectedRow("#jqGrid");
if (id == null) {
return;
}
vm.showList = false;
vm.title = "修改";
vm.getInfo(id);
},
saveOrUpdate: function (event) {
let url = vm.tbCategoryTemplate.id == null ? "../tbcategorytemplate/save" : "../tbcategorytemplate/update";
Ajax.request({
url: url,
params: JSON.stringify(vm.tbCategoryTemplate),
type: "POST",
contentType: "application/json",
successCallback: function (r) {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
del: function (event) {
let ids = getSelectedRows("#jqGrid");
if (ids == null){
return;
}
confirm('确定要删除选中的记录?', function () {
Ajax.request({
url: "../tbcategorytemplate/delete",
params: JSON.stringify(ids),
type: "POST",
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
});
},
getInfo: function(id){
Ajax.request({
url: "../tbcategorytemplate/info/"+id,
async: true,
successCallback: function (r) {
vm.tbCategoryTemplate = r.tbCategoryTemplate;
}
});
},
reload: function (event) {
vm.showList = true;
let page = $("#jqGrid").jqGrid('getGridParam', 'page');
$("#jqGrid").jqGrid('setGridParam', {
postData: {'name': vm.q.name},
page: page
}).trigger("reloadGrid");
vm.handleReset('formValidate');
},
reloadSearch: function() {
vm.q = {
name: ''
};
vm.reload();
},
handleSubmit: function (name) {
handleSubmitValidate(this, name, function () {
vm.saveOrUpdate()
});
},
handleReset: function (name) {
handleResetForm(this, name);
}
}
});
\ No newline at end of file
...@@ -26,6 +26,7 @@ $(function () { ...@@ -26,6 +26,7 @@ $(function () {
let vm = new Vue({ let vm = new Vue({
el: '#rrapp', el: '#rrapp',
data: { data: {
modal: false,
showList: true, showList: true,
title: null, title: null,
tbCfStationItem: {}, tbCfStationItem: {},
...@@ -47,9 +48,10 @@ let vm = new Vue({ ...@@ -47,9 +48,10 @@ let vm = new Vue({
alertShow: false,//警告弹窗 alertShow: false,//警告弹窗
serverSkuAttr:[],
attrItem: [{ attrItem: [{
categoryName: 'Size', categoryName: 'Size',
option: ['Color', 'Size', 'Length'], option: [],
categoryDesc: '' categoryDesc: ''
}],//属性设置 }],//属性设置
prevItem: [],//组合数组 prevItem: [],//组合数组
...@@ -189,7 +191,7 @@ let vm = new Vue({ ...@@ -189,7 +191,7 @@ let vm = new Vue({
}); });
}, },
getInfo: function (itemId) { getInfo: function (itemId) {
this.isDisabled = true // this.isDisabled = true
let _this = this let _this = this
Ajax.request({ Ajax.request({
url: "../tbcfstationitem/info/" + itemId, url: "../tbcfstationitem/info/" + itemId,
...@@ -197,12 +199,12 @@ let vm = new Vue({ ...@@ -197,12 +199,12 @@ let vm = new Vue({
successCallback: function (r) { successCallback: function (r) {
r.code === 0 && (() => { r.code === 0 && (() => {
_this.attrItem = [] _this.attrItem = []
let _option = JSON.parse(localStorage.getItem('option')) // let _option = JSON.parse(localStorage.getItem('option'))
//回显属性 //回显属性
r.tbCfStationItem.categoryList.map(item => { r.tbCfStationItem.categoryList.map(item => {
_this.attrItem.push({ _this.attrItem.push({
categoryName: item.categoryName, categoryName: item.categoryName,
option: _option, option: _this.serverSkuAttr,
categoryDesc: item.categoryDesc categoryDesc: item.categoryDesc
}) })
}) })
...@@ -218,6 +220,7 @@ let vm = new Vue({ ...@@ -218,6 +220,7 @@ let vm = new Vue({
}) })
console.log(r) console.log(r)
})() })()
console.log(123321,_this.attrItem)
vm.tbCfStationItem = r.tbCfStationItem.item; vm.tbCfStationItem = r.tbCfStationItem.item;
vm.uploadList[0] = vm.tbCfStationItem.itemImg; vm.uploadList[0] = vm.tbCfStationItem.itemImg;
let itemDesc = vm.tbCfStationItem.itemDesc; let itemDesc = vm.tbCfStationItem.itemDesc;
...@@ -227,10 +230,19 @@ let vm = new Vue({ ...@@ -227,10 +230,19 @@ let vm = new Vue({
vm.tbCfStationItem.enableFlag === 1 && (() => { vm.tbCfStationItem.enableFlag === 1 && (() => {
_this.putaway = true; _this.putaway = true;
})() })()
UE.getEditor('itemDesc').setContent(itemDesc); try{
UE.getEditor('itemDesc').setContent(itemDesc);
}catch (e) {
}
setTimeout(()=>{
UE.getEditor('itemDesc').setContent(itemDesc);
},500)
if (itemDesc == null || itemDesc == '') { if (itemDesc == null || itemDesc == '') {
UE.getEditor('itemDesc').setContent(""); UE.getEditor('itemDesc').setContent("");
} }
} }
}); });
...@@ -389,7 +401,8 @@ let vm = new Vue({ ...@@ -389,7 +401,8 @@ let vm = new Vue({
} else { } else {
this.attrItem.push({ this.attrItem.push({
categoryName: 'Color', categoryName: 'Color',
option: JSON.parse(localStorage.getItem('option')), // option: JSON.parse(localStorage.getItem('option')),
option: this.serverSkuAttr,
categoryDesc: '' categoryDesc: ''
}) })
} }
...@@ -478,6 +491,10 @@ let vm = new Vue({ ...@@ -478,6 +491,10 @@ let vm = new Vue({
}) })
} }
}, },
ok(){
this.reloadSearch();
},
cancel(){},
handleCreateSelect(val) { handleCreateSelect(val) {
let option = JSON.parse(localStorage.getItem('option')) let option = JSON.parse(localStorage.getItem('option'))
option.push(val) option.push(val)
...@@ -504,5 +521,14 @@ let vm = new Vue({ ...@@ -504,5 +521,14 @@ let vm = new Vue({
this.Goodstype = res.list; this.Goodstype = res.list;
console.log('一级分类', this.Goodstype) console.log('一级分类', this.Goodstype)
}) })
//获取默认规格
$.get('../tbcategorytemplate/queryAll',res=>{
let _res = JSON.parse(res)
_res.list.forEach(item=>{
this.attrItem[0].option.push(item.categoryDesc)
this.serverSkuAttr.push(item.categoryDesc)
})
})
} }
}); });
\ No newline at end of file
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
</properties> </properties>
<dependencies> <dependencies>
<!-- excel工具 --> <!-- excel工具 -->
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论