|
@@ -1,15 +1,15 @@
|
|
|
package com.caimei.modules.brand.web;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
import com.caimei.modules.brand.entity.BrandAndProductType;
|
|
|
-import com.caimei.modules.coupon.entity.CmCoupon;
|
|
|
-import com.caimei.modules.coupon.entity.ReadExcel;
|
|
|
-import com.caimei.modules.miniprogram.utils.UploadPicUtils;
|
|
|
+import com.caimei.modules.brand.entity.CmBrand;
|
|
|
+import com.caimei.modules.brand.service.CmBrandService;
|
|
|
import com.caimei.modules.product.dao.ProductDao;
|
|
|
import com.caimei.modules.product.entity.Product;
|
|
|
import com.caimei.modules.sys.utils.SMSUtils;
|
|
|
+import com.thinkgem.jeesite.common.config.Global;
|
|
|
+import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
+import com.thinkgem.jeesite.common.utils.StringUtils;
|
|
|
+import com.thinkgem.jeesite.common.web.BaseController;
|
|
|
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
@@ -30,15 +30,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
-import com.thinkgem.jeesite.common.config.Global;
|
|
|
-import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
-import com.thinkgem.jeesite.common.web.BaseController;
|
|
|
-import com.thinkgem.jeesite.common.utils.StringUtils;
|
|
|
-import com.caimei.modules.brand.entity.CmBrand;
|
|
|
-import com.caimei.modules.brand.service.CmBrandService;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -46,6 +39,7 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 采美品牌Controller
|
|
|
+ *
|
|
|
* @author Lijun
|
|
|
* @version 2019-04-19
|
|
|
*/
|
|
@@ -53,460 +47,459 @@ import java.util.Map;
|
|
|
@RequestMapping(value = "${adminPath}/brand/cmBrand")
|
|
|
public class CmBrandController extends BaseController {
|
|
|
|
|
|
- //总行数
|
|
|
- private int totalRows = 0;
|
|
|
- //总条数
|
|
|
- private int totalCells = 0;
|
|
|
- //错误信息接收器
|
|
|
- private String errorMsg;
|
|
|
-
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CmBrandService cmBrandService;
|
|
|
- @Autowired
|
|
|
- private ProductDao productDao;
|
|
|
-
|
|
|
- @ModelAttribute
|
|
|
- public CmBrand get(@RequestParam(required=false) String id) {
|
|
|
- CmBrand entity = null;
|
|
|
- if (StringUtils.isNotBlank(id)){
|
|
|
- entity = cmBrandService.get(id);
|
|
|
- }
|
|
|
- if (entity == null){
|
|
|
- entity = new CmBrand();
|
|
|
- }
|
|
|
- return entity;
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("brand:cmBrand:view")
|
|
|
- @RequestMapping(value = {"list", ""})
|
|
|
- public String list(CmBrand cmBrand, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
- Page<CmBrand> page = cmBrandService.findPage(new Page<CmBrand>(request, response), cmBrand);
|
|
|
- model.addAttribute("page", page);
|
|
|
- return "modules/brand/cmBrandList";
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("brand:cmBrand:view")
|
|
|
- @RequestMapping(value = "form")
|
|
|
- public String form(CmBrand cmBrand, Model model) {
|
|
|
- model.addAttribute("cmBrand", cmBrand);
|
|
|
- String auditNote = cmBrand.getAuditNote();
|
|
|
- if(StringUtils.isNotEmpty(auditNote)){
|
|
|
- if(StringUtils.equals("填写错误",auditNote)){
|
|
|
- cmBrand.setAuditStatus("1");
|
|
|
- }else{
|
|
|
- cmBrand.setAuditStatus("2");
|
|
|
- }
|
|
|
- }else{
|
|
|
- cmBrand.setAuditStatus("0");
|
|
|
- }
|
|
|
- return "modules/brand/cmBrandForm";
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("brand:cmBrand:edit")
|
|
|
- @RequestMapping(value = "save")
|
|
|
- public String save(CmBrand cmBrand, Model model, RedirectAttributes redirectAttributes,HttpServletRequest request) {
|
|
|
- if (!beanValidator(model, cmBrand)){
|
|
|
- return form(cmBrand, model);
|
|
|
- }
|
|
|
- //判断输入的名字是否已存在
|
|
|
- CmBrand cmBrandByName = cmBrandService.findBradByName(cmBrand);
|
|
|
+ //总行数
|
|
|
+ private int totalRows = 0;
|
|
|
+ //总条数
|
|
|
+ private int totalCells = 0;
|
|
|
+ //错误信息接收器
|
|
|
+ private String errorMsg;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CmBrandService cmBrandService;
|
|
|
+ @Autowired
|
|
|
+ private ProductDao productDao;
|
|
|
+
|
|
|
+ @ModelAttribute
|
|
|
+ public CmBrand get(@RequestParam(required = false) String id) {
|
|
|
+ CmBrand entity = null;
|
|
|
+ if (StringUtils.isNotBlank(id)) {
|
|
|
+ entity = cmBrandService.get(id);
|
|
|
+ }
|
|
|
+ if (entity == null) {
|
|
|
+ entity = new CmBrand();
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("brand:cmBrand:view")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(CmBrand cmBrand, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
+ Page<CmBrand> page = cmBrandService.findPage(new Page<CmBrand>(request, response), cmBrand);
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ return "modules/brand/cmBrandList";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("brand:cmBrand:view")
|
|
|
+ @RequestMapping(value = "form")
|
|
|
+ public String form(CmBrand cmBrand, Model model) {
|
|
|
+ model.addAttribute("cmBrand", cmBrand);
|
|
|
+ String auditNote = cmBrand.getAuditNote();
|
|
|
+ if (StringUtils.isNotEmpty(auditNote)) {
|
|
|
+ if (StringUtils.equals("填写错误", auditNote)) {
|
|
|
+ cmBrand.setAuditStatus("1");
|
|
|
+ } else {
|
|
|
+ cmBrand.setAuditStatus("2");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ cmBrand.setAuditStatus("0");
|
|
|
+ }
|
|
|
+ return "modules/brand/cmBrandForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("brand:cmBrand:edit")
|
|
|
+ @RequestMapping(value = "save")
|
|
|
+ public String save(CmBrand cmBrand, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
|
|
|
+ if (!beanValidator(model, cmBrand)) {
|
|
|
+ return form(cmBrand, model);
|
|
|
+ }
|
|
|
+ //判断输入的名字是否已存在
|
|
|
+ CmBrand cmBrandByName = cmBrandService.findBradByName(cmBrand);
|
|
|
// if (StringUtils.isNotBlank(cmBrand.getLogo())) {
|
|
|
// String img = UploadPicUtils.saveImageToServer(cmBrand.getLogo(), request);
|
|
|
// cmBrand.setLogo(img);
|
|
|
// }
|
|
|
- if(null != cmBrandByName){
|
|
|
- addMessage(redirectAttributes, "该品牌已存在");
|
|
|
- }else{
|
|
|
- //判断是新增加还是修改
|
|
|
- if(StringUtils.isEmpty(cmBrand.getId())){//新增
|
|
|
- cmBrand.setCreateDate(new Date());
|
|
|
- cmBrand.setStatus("1");//采美添加默认通过--品牌状态 0:待审核,1:审核通过,2:审核失败
|
|
|
- cmBrand.setSource("0");//添加来源 0:后台添加 ,1:供应商添加
|
|
|
- cmBrand.setSort("0");
|
|
|
- cmBrand.setUserID(UserUtils.getUser()+"");
|
|
|
- }else{//修改
|
|
|
- String status = cmBrand.getStatus();
|
|
|
- CmBrand oldBrand = cmBrandService.get(cmBrand.getId());//获取修改前的品牌信息
|
|
|
- String oldStatus = oldBrand.getStatus();//老的状态
|
|
|
- if(!StringUtils.equals(status,oldStatus)){//重新修改状态才发送短信提示(防止重复编辑重复发送短信)
|
|
|
- if(StringUtils.equals("1",status)){
|
|
|
- String mobile = cmBrand.getShopMobile();
|
|
|
- if (StringUtils.isNotEmpty(mobile)) {
|
|
|
- SMSUtils.sendSms(mobile, "您提交的["+cmBrand.getName()+"]品牌申请,已审核成功");
|
|
|
- }
|
|
|
- }
|
|
|
- if(StringUtils.equals("2",status)){
|
|
|
- String auditNote = cmBrand.getAuditNote();
|
|
|
- if(StringUtils.isEmpty(auditNote)){
|
|
|
- addMessage(model, "请输入失败原因!!");
|
|
|
- return form(cmBrand, model);
|
|
|
- }
|
|
|
- String mobile = cmBrand.getShopMobile();
|
|
|
- if (StringUtils.isNotEmpty(mobile)) {
|
|
|
- SMSUtils.sendSms(mobile, "抱歉,您提交的["+cmBrand.getName()+"]品牌申请,由于"+cmBrand.getAuditNote()+"审核失败,请重新修改提交!");
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(StringUtils.equals("2",status)){
|
|
|
- String auditNote = cmBrand.getAuditNote();
|
|
|
- if(StringUtils.isEmpty(auditNote)){
|
|
|
- addMessage(model, "请输入失败原因!!");
|
|
|
- return form(cmBrand, model);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- cmBrand.setUpdateDate(new Date());
|
|
|
- cmBrandService.save(cmBrand);
|
|
|
- addMessage(redirectAttributes, "保存品牌成功");
|
|
|
- }
|
|
|
- return "redirect:"+Global.getAdminPath()+"/brand/cmBrand/";
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("brand:cmBrand:delete")
|
|
|
- @RequestMapping(value = "delete")
|
|
|
- public String delete(CmBrand cmBrand, RedirectAttributes redirectAttributes) {
|
|
|
- Date date = new Date();
|
|
|
- cmBrand.setUpdateDate(date);
|
|
|
- cmBrand.setDelFlag(date.getTime()+"");
|
|
|
- //删除品牌表格内容
|
|
|
- cmBrandService.delete(cmBrand);
|
|
|
- //清理对应品牌商品信息(标记品牌为null)
|
|
|
- productDao.updateProductByBrandId(Integer.parseInt(cmBrand.getId()));
|
|
|
- addMessage(redirectAttributes, "删除品牌成功");
|
|
|
- return "redirect:"+Global.getAdminPath()+"/brand/cmBrand/?repage";
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("brand:cmBrand:view")
|
|
|
- @RequestMapping(value = {"uploadList"})
|
|
|
- public String uploadList() {
|
|
|
- return "modules/brand/brandUpload";
|
|
|
- }
|
|
|
-
|
|
|
- @ResponseBody
|
|
|
- @RequestMapping(value = "import")
|
|
|
- public Map<String,Object> cibeShopImport(@RequestParam(value="file",required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, Model model){
|
|
|
- Map<String,Object> map = new HashedMap();
|
|
|
- try{
|
|
|
- try {
|
|
|
- //xls 2003版本
|
|
|
- Workbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
- // 得到第一个shell
|
|
|
- Sheet sheet = wb.getSheetAt(0);
|
|
|
- // 得到Excel的行数
|
|
|
- this.totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
- // 得到Excel的列数(前提是有行数)
|
|
|
- if (totalRows > 1 && sheet.getRow(0) != null) {
|
|
|
- this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
- }
|
|
|
- List<BrandAndProductType> brandAndProductType = new ArrayList<>();
|
|
|
- // 循环Excel行数
|
|
|
- for (int r = 1; r < totalRows; r++) {
|
|
|
- Row row = sheet.getRow(r);
|
|
|
- if (row == null){
|
|
|
- continue;
|
|
|
- }
|
|
|
- BrandAndProductType brandAndProduct = new BrandAndProductType();
|
|
|
- // 循环Excel的列
|
|
|
- for (int c = 0; c < this.totalCells; c++) {
|
|
|
- Cell cell = row.getCell(c);
|
|
|
- if (null != cell) {
|
|
|
- String value = getFieldValue(cell);
|
|
|
- switch (c){
|
|
|
- case 0:
|
|
|
- brandAndProduct.setBrandName(value); //品牌名字
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 添加到list
|
|
|
- brandAndProductType.add(brandAndProduct);
|
|
|
- }
|
|
|
-
|
|
|
- //将转化对象插入品牌库
|
|
|
- if(CollectionUtils.isNotEmpty(brandAndProductType)){
|
|
|
- for(BrandAndProductType b:brandAndProductType){
|
|
|
- String brandName = b.getBrandName();
|
|
|
- CmBrand cmBrand = new CmBrand();
|
|
|
- cmBrand.setName(brandName);
|
|
|
- cmBrand.setSource("0");
|
|
|
- cmBrand.setUserID("1");
|
|
|
- cmBrand.setStatus("1");
|
|
|
- cmBrand.setSort("0");
|
|
|
- cmBrand.setDelFlag("0");
|
|
|
- cmBrand.setCreateDate(new Date());
|
|
|
- cmBrand.setUpdateDate(new Date());
|
|
|
- cmBrandService.save(cmBrand);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- map.put("success",true);
|
|
|
- map.put("msg", "上传成功");
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- logger.error(e.getMessage());
|
|
|
- map.put("success",false);
|
|
|
- map.put("msg", "上传失败");
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- @ResponseBody
|
|
|
- @RequestMapping(value = "import1")
|
|
|
- public Map<String,Object> import1(@RequestParam(value="file",required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, Model model){
|
|
|
- Map<String,Object> map = new HashedMap();
|
|
|
- try{
|
|
|
- try {
|
|
|
- Workbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
- // 得到第一个shell
|
|
|
- Sheet sheet = wb.getSheetAt(0);
|
|
|
- // 得到Excel的行数
|
|
|
- this.totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
- // 得到Excel的列数(前提是有行数)
|
|
|
- if (totalRows > 1 && sheet.getRow(0) != null) {
|
|
|
- this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
- }
|
|
|
- List<BrandAndProductType> brandAndProductType = new ArrayList<>();
|
|
|
- // 循环Excel行数
|
|
|
- for (int r = 1; r < totalRows; r++) {
|
|
|
- Row row = sheet.getRow(r);
|
|
|
- if (row == null){
|
|
|
- continue;
|
|
|
- }
|
|
|
- BrandAndProductType brandAndProduct = new BrandAndProductType();
|
|
|
- // 循环Excel的列
|
|
|
- for (int c = 0; c < this.totalCells; c++) {
|
|
|
- Cell cell = row.getCell(c);
|
|
|
- if (null != cell) {
|
|
|
- String value = getFieldValue(cell);
|
|
|
- switch (c){
|
|
|
- case 0:
|
|
|
- brandAndProduct.setProductId((int)Double.parseDouble(value));
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- brandAndProduct.setBrandName(value);
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 添加到list
|
|
|
- brandAndProductType.add(brandAndProduct);
|
|
|
- }
|
|
|
-
|
|
|
- //将转化对象更新到商品表
|
|
|
- if(CollectionUtils.isNotEmpty(brandAndProductType)){
|
|
|
- for(BrandAndProductType b:brandAndProductType){
|
|
|
- //通过名字查询品牌
|
|
|
- String brandName = b.getBrandName();
|
|
|
- CmBrand cmBrand = new CmBrand();
|
|
|
- cmBrand.setName(brandName);
|
|
|
- CmBrand bradByName = cmBrandService.findBradByName(cmBrand);
|
|
|
- if(null != bradByName){
|
|
|
- String id = bradByName.getId();
|
|
|
- Integer productId = b.getProductId();
|
|
|
- Product product = new Product();
|
|
|
- product.setBrandID(Integer.parseInt(id));
|
|
|
- product.setProductID(productId);
|
|
|
- productDao.updateBrnadId(product);
|
|
|
- }else{
|
|
|
- logger.info("---------------------商品不存在该品牌productId"+b.getProductId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- logger.info(">>>>>>>>>>>>>>>>>>>>>>>>上次异常");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- map.put("success",true);
|
|
|
- map.put("msg", "上传成功");
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- logger.error(e.getMessage());
|
|
|
- map.put("success",false);
|
|
|
- map.put("msg", "上传失败");
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @ResponseBody
|
|
|
- @RequestMapping(value = "import2")
|
|
|
- public Map<String,Object> import2(@RequestParam(value="file",required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, Model model){
|
|
|
- Map<String,Object> map = new HashedMap();
|
|
|
- try{
|
|
|
- try {
|
|
|
- Workbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
- // 得到第一个shell
|
|
|
- Sheet sheet = wb.getSheetAt(0);
|
|
|
- // 得到Excel的行数
|
|
|
- this.totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
- // 得到Excel的列数(前提是有行数)
|
|
|
- if (totalRows > 1 && sheet.getRow(0) != null) {
|
|
|
- this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
- }
|
|
|
- List<BrandAndProductType> brandAndProductType = new ArrayList<>();
|
|
|
- // 循环Excel行数
|
|
|
- for (int r = 1; r < totalRows; r++) {
|
|
|
- Row row = sheet.getRow(r);
|
|
|
- if (row == null){
|
|
|
- continue;
|
|
|
- }
|
|
|
- BrandAndProductType brandAndProduct = new BrandAndProductType();
|
|
|
- // 循环Excel的列
|
|
|
- for (int c = 0; c < this.totalCells; c++) {
|
|
|
- Cell cell = row.getCell(c);
|
|
|
- if (null != cell) {
|
|
|
- String value = getFieldValue(cell);
|
|
|
- switch (c){
|
|
|
- case 0:
|
|
|
- brandAndProduct.setProductId((int)Double.parseDouble(value)); //商品ID
|
|
|
- logger.info("__________________________product"+value);
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- break;
|
|
|
- case 4:
|
|
|
+ if (null != cmBrandByName) {
|
|
|
+ addMessage(redirectAttributes, "该品牌已存在");
|
|
|
+ } else {
|
|
|
+ //判断是新增加还是修改
|
|
|
+ if (StringUtils.isEmpty(cmBrand.getId())) {//新增
|
|
|
+ cmBrand.setCreateDate(new Date());
|
|
|
+ cmBrand.setStatus("1");//采美添加默认通过--品牌状态 0:待审核,1:审核通过,2:审核失败
|
|
|
+ cmBrand.setSource("0");//添加来源 0:后台添加 ,1:供应商添加
|
|
|
+ cmBrand.setSort("0");
|
|
|
+ cmBrand.setUserID(UserUtils.getUser() + "");
|
|
|
+ } else {//修改
|
|
|
+ String status = cmBrand.getStatus();
|
|
|
+ CmBrand oldBrand = cmBrandService.get(cmBrand.getId());//获取修改前的品牌信息
|
|
|
+ String oldStatus = oldBrand.getStatus();//老的状态
|
|
|
+ if (!StringUtils.equals(status, oldStatus)) {//重新修改状态才发送短信提示(防止重复编辑重复发送短信)
|
|
|
+ if (StringUtils.equals("1", status)) {
|
|
|
+ String mobile = cmBrand.getShopMobile();
|
|
|
+ if (StringUtils.isNotEmpty(mobile)) {
|
|
|
+ SMSUtils.sendSms(mobile, "您提交的[" + cmBrand.getName() + "]品牌申请,已审核成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("2", status)) {
|
|
|
+ String auditNote = cmBrand.getAuditNote();
|
|
|
+ if (StringUtils.isEmpty(auditNote)) {
|
|
|
+ addMessage(model, "请输入失败原因!!");
|
|
|
+ return form(cmBrand, model);
|
|
|
+ }
|
|
|
+ String mobile = cmBrand.getShopMobile();
|
|
|
+ if (StringUtils.isNotEmpty(mobile)) {
|
|
|
+ SMSUtils.sendSms(mobile, "抱歉,您提交的[" + cmBrand.getName() + "]品牌申请,由于" + cmBrand.getAuditNote() + "审核失败,请重新修改提交!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (StringUtils.equals("2", status)) {
|
|
|
+ String auditNote = cmBrand.getAuditNote();
|
|
|
+ if (StringUtils.isEmpty(auditNote)) {
|
|
|
+ addMessage(model, "请输入失败原因!!");
|
|
|
+ return form(cmBrand, model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ cmBrand.setUpdateDate(new Date());
|
|
|
+ cmBrandService.save(cmBrand);
|
|
|
+ addMessage(redirectAttributes, "保存品牌成功");
|
|
|
+ }
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/brand/cmBrand/";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("brand:cmBrand:delete")
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
+ public String delete(CmBrand cmBrand, RedirectAttributes redirectAttributes) {
|
|
|
+ Date date = new Date();
|
|
|
+ cmBrand.setUpdateDate(date);
|
|
|
+ cmBrand.setDelFlag(date.getTime() + "");
|
|
|
+ //删除品牌表格内容
|
|
|
+ cmBrandService.delete(cmBrand);
|
|
|
+ //清理对应品牌商品信息(标记品牌为null)
|
|
|
+ productDao.updateProductByBrandId(Integer.parseInt(cmBrand.getId()));
|
|
|
+ addMessage(redirectAttributes, "删除品牌成功");
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/brand/cmBrand/?repage";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("brand:cmBrand:view")
|
|
|
+ @RequestMapping(value = {"uploadList"})
|
|
|
+ public String uploadList() {
|
|
|
+ return "modules/brand/brandUpload";
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "import")
|
|
|
+ public Map<String, Object> cibeShopImport(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ try {
|
|
|
+ try {
|
|
|
+ //xls 2003版本
|
|
|
+ Workbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
+ // 得到第一个shell
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ // 得到Excel的行数
|
|
|
+ this.totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
+ // 得到Excel的列数(前提是有行数)
|
|
|
+ if (totalRows > 1 && sheet.getRow(0) != null) {
|
|
|
+ this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ }
|
|
|
+ List<BrandAndProductType> brandAndProductType = new ArrayList<>();
|
|
|
+ // 循环Excel行数
|
|
|
+ for (int r = 1; r < totalRows; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BrandAndProductType brandAndProduct = new BrandAndProductType();
|
|
|
+ // 循环Excel的列
|
|
|
+ for (int c = 0; c < this.totalCells; c++) {
|
|
|
+ Cell cell = row.getCell(c);
|
|
|
+ if (null != cell) {
|
|
|
+ String value = getFieldValue(cell);
|
|
|
+ switch (c) {
|
|
|
+ case 0:
|
|
|
+ brandAndProduct.setBrandName(value); //品牌名字
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加到list
|
|
|
+ brandAndProductType.add(brandAndProduct);
|
|
|
+ }
|
|
|
+
|
|
|
+ //将转化对象插入品牌库
|
|
|
+ if (CollectionUtils.isNotEmpty(brandAndProductType)) {
|
|
|
+ for (BrandAndProductType b : brandAndProductType) {
|
|
|
+ String brandName = b.getBrandName();
|
|
|
+ CmBrand cmBrand = new CmBrand();
|
|
|
+ cmBrand.setName(brandName);
|
|
|
+ cmBrand.setSource("0");
|
|
|
+ cmBrand.setUserID("1");
|
|
|
+ cmBrand.setStatus("1");
|
|
|
+ cmBrand.setSort("0");
|
|
|
+ cmBrand.setDelFlag("0");
|
|
|
+ cmBrand.setCreateDate(new Date());
|
|
|
+ cmBrand.setUpdateDate(new Date());
|
|
|
+ cmBrandService.save(cmBrand);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "上传成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("msg", "上传失败");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "import1")
|
|
|
+ public Map<String, Object> import1(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ try {
|
|
|
+ try {
|
|
|
+ Workbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
+ // 得到第一个shell
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ // 得到Excel的行数
|
|
|
+ this.totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
+ // 得到Excel的列数(前提是有行数)
|
|
|
+ if (totalRows > 1 && sheet.getRow(0) != null) {
|
|
|
+ this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ }
|
|
|
+ List<BrandAndProductType> brandAndProductType = new ArrayList<>();
|
|
|
+ // 循环Excel行数
|
|
|
+ for (int r = 1; r < totalRows; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BrandAndProductType brandAndProduct = new BrandAndProductType();
|
|
|
+ // 循环Excel的列
|
|
|
+ for (int c = 0; c < this.totalCells; c++) {
|
|
|
+ Cell cell = row.getCell(c);
|
|
|
+ if (null != cell) {
|
|
|
+ String value = getFieldValue(cell);
|
|
|
+ switch (c) {
|
|
|
+ case 0:
|
|
|
+ brandAndProduct.setProductId((int) Double.parseDouble(value));
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ brandAndProduct.setBrandName(value);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加到list
|
|
|
+ brandAndProductType.add(brandAndProduct);
|
|
|
+ }
|
|
|
+
|
|
|
+ //将转化对象更新到商品表
|
|
|
+ if (CollectionUtils.isNotEmpty(brandAndProductType)) {
|
|
|
+ for (BrandAndProductType b : brandAndProductType) {
|
|
|
+ //通过名字查询品牌
|
|
|
+ String brandName = b.getBrandName();
|
|
|
+ CmBrand cmBrand = new CmBrand();
|
|
|
+ cmBrand.setName(brandName);
|
|
|
+ CmBrand bradByName = cmBrandService.findBradByName(cmBrand);
|
|
|
+ if (null != bradByName) {
|
|
|
+ String id = bradByName.getId();
|
|
|
+ Integer productId = b.getProductId();
|
|
|
+ Product product = new Product();
|
|
|
+ product.setBrandID(Integer.parseInt(id));
|
|
|
+ product.setProductID(productId);
|
|
|
+ productDao.updateBrnadId(product);
|
|
|
+ } else {
|
|
|
+ logger.info("---------------------商品不存在该品牌productId" + b.getProductId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info(">>>>>>>>>>>>>>>>>>>>>>>>上次异常");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "上传成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("msg", "上传失败");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "import2")
|
|
|
+ public Map<String, Object> import2(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ try {
|
|
|
+ try {
|
|
|
+ Workbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
+ // 得到第一个shell
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ // 得到Excel的行数
|
|
|
+ this.totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
+ // 得到Excel的列数(前提是有行数)
|
|
|
+ if (totalRows > 1 && sheet.getRow(0) != null) {
|
|
|
+ this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ }
|
|
|
+ List<BrandAndProductType> brandAndProductType = new ArrayList<>();
|
|
|
+ // 循环Excel行数
|
|
|
+ for (int r = 1; r < totalRows; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BrandAndProductType brandAndProduct = new BrandAndProductType();
|
|
|
+ // 循环Excel的列
|
|
|
+ for (int c = 0; c < this.totalCells; c++) {
|
|
|
+ Cell cell = row.getCell(c);
|
|
|
+ if (null != cell) {
|
|
|
+ String value = getFieldValue(cell);
|
|
|
+ switch (c) {
|
|
|
+ case 0:
|
|
|
+ brandAndProduct.setProductId((int) Double.parseDouble(value)); //商品ID
|
|
|
+ logger.info("__________________________product" + value);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
// 会所常用品(HSCY)-美容工具(MRGJ)-小工具(XGJ)
|
|
|
|
|
|
- //去掉value中的括号以及括号里内容
|
|
|
- String[] split = value.split("-");
|
|
|
- int length = split.length;
|
|
|
- if(length == 3){
|
|
|
- String s = split[0];
|
|
|
- String s1 = split[1];
|
|
|
- String s2 = split[2];
|
|
|
- int i = s.indexOf("(");
|
|
|
- String substring = s.substring(0, i);
|
|
|
-
|
|
|
- int i1 = s1.indexOf("(");
|
|
|
- String substring1 = s1.substring(0, i1);
|
|
|
-
|
|
|
- int i2 = s2.indexOf("(");
|
|
|
- String substring2 = s2.substring(0, i2);
|
|
|
-
|
|
|
- brandAndProduct.setBigTypeName(substring);//大分类
|
|
|
- brandAndProduct.setSmallTypeName(substring1);//二级分类
|
|
|
- brandAndProduct.setTinyTypeName(substring2);//小分类名字
|
|
|
- }
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 添加到list
|
|
|
- brandAndProductType.add(brandAndProduct);
|
|
|
- }
|
|
|
-
|
|
|
- //将转化对象插入品牌库
|
|
|
- if(CollectionUtils.isNotEmpty(brandAndProductType)){
|
|
|
- for(BrandAndProductType b:brandAndProductType){
|
|
|
- String bigTypeName = b.getBigTypeName();
|
|
|
- String smallTypeName = b.getSmallTypeName();
|
|
|
- String tinyTypeName = b.getTinyTypeName();
|
|
|
-
|
|
|
- List<BrandAndProductType> productByTypeName = productDao.getProductByTypeName(bigTypeName, smallTypeName, tinyTypeName);
|
|
|
- if(CollectionUtils.isNotEmpty(productByTypeName) && productByTypeName.size() == 1){
|
|
|
- BrandAndProductType brandAndProductType1 = productByTypeName.get(0);
|
|
|
- Integer tinyTypeID = brandAndProductType1.getTinyTypeID();
|
|
|
- Product product = new Product();
|
|
|
- product.setProductID(b.getProductId());
|
|
|
- product.setTinyTypeID(tinyTypeID);
|
|
|
- productDao.updateTinyType(product);
|
|
|
- }
|
|
|
- else{
|
|
|
- logger.info("----------------------商品分类异常ProductId"+b.getProductId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logger.info(">>>>>>>>>>>>>>>>>>>>>>>>上次异常");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- map.put("success",true);
|
|
|
- map.put("msg", "上传成功");
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- logger.error(e.getMessage());
|
|
|
- map.put("success",false);
|
|
|
- map.put("msg", "上传失败");
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public String getFieldValue(Cell cell){
|
|
|
- String value = null;
|
|
|
- if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
|
|
|
- value = String.valueOf(cell.getNumericCellValue());
|
|
|
- }else {
|
|
|
- value = cell.getStringCellValue();
|
|
|
- }
|
|
|
- return value;
|
|
|
- }
|
|
|
-
|
|
|
- public int getTotalRows() {
|
|
|
- return totalRows;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalRows(int totalRows) {
|
|
|
- this.totalRows = totalRows;
|
|
|
- }
|
|
|
-
|
|
|
- public int getTotalCells() {
|
|
|
- return totalCells;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalCells(int totalCells) {
|
|
|
- this.totalCells = totalCells;
|
|
|
- }
|
|
|
-
|
|
|
- public String getErrorMsg() {
|
|
|
- return errorMsg;
|
|
|
- }
|
|
|
-
|
|
|
- public void setErrorMsg(String errorMsg) {
|
|
|
- this.errorMsg = errorMsg;
|
|
|
- }
|
|
|
+ //去掉value中的括号以及括号里内容
|
|
|
+ String[] split = value.split("-");
|
|
|
+ int length = split.length;
|
|
|
+ if (length == 3) {
|
|
|
+ String s = split[0];
|
|
|
+ String s1 = split[1];
|
|
|
+ String s2 = split[2];
|
|
|
+ int i = s.indexOf("(");
|
|
|
+ String substring = s.substring(0, i);
|
|
|
+
|
|
|
+ int i1 = s1.indexOf("(");
|
|
|
+ String substring1 = s1.substring(0, i1);
|
|
|
+
|
|
|
+ int i2 = s2.indexOf("(");
|
|
|
+ String substring2 = s2.substring(0, i2);
|
|
|
+
|
|
|
+ brandAndProduct.setBigTypeName(substring);//大分类
|
|
|
+ brandAndProduct.setSmallTypeName(substring1);//二级分类
|
|
|
+ brandAndProduct.setTinyTypeName(substring2);//小分类名字
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加到list
|
|
|
+ brandAndProductType.add(brandAndProduct);
|
|
|
+ }
|
|
|
+
|
|
|
+ //将转化对象插入品牌库
|
|
|
+ if (CollectionUtils.isNotEmpty(brandAndProductType)) {
|
|
|
+ for (BrandAndProductType b : brandAndProductType) {
|
|
|
+ String bigTypeName = b.getBigTypeName();
|
|
|
+ String smallTypeName = b.getSmallTypeName();
|
|
|
+ String tinyTypeName = b.getTinyTypeName();
|
|
|
+
|
|
|
+ List<BrandAndProductType> productByTypeName = productDao.getProductByTypeName(bigTypeName, smallTypeName, tinyTypeName);
|
|
|
+ if (CollectionUtils.isNotEmpty(productByTypeName) && productByTypeName.size() == 1) {
|
|
|
+ BrandAndProductType brandAndProductType1 = productByTypeName.get(0);
|
|
|
+ Integer tinyTypeID = brandAndProductType1.getTinyTypeID();
|
|
|
+ Product product = new Product();
|
|
|
+ product.setProductID(b.getProductId());
|
|
|
+ product.setTinyTypeID(tinyTypeID);
|
|
|
+ productDao.updateTinyType(product);
|
|
|
+ } else {
|
|
|
+ logger.info("----------------------商品分类异常ProductId" + b.getProductId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info(">>>>>>>>>>>>>>>>>>>>>>>>上次异常");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "上传成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("msg", "上传失败");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getFieldValue(Cell cell) {
|
|
|
+ String value = null;
|
|
|
+ if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
|
|
|
+ value = String.valueOf(cell.getNumericCellValue());
|
|
|
+ } else {
|
|
|
+ value = cell.getStringCellValue();
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getTotalRows() {
|
|
|
+ return totalRows;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTotalRows(int totalRows) {
|
|
|
+ this.totalRows = totalRows;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getTotalCells() {
|
|
|
+ return totalCells;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTotalCells(int totalCells) {
|
|
|
+ this.totalCells = totalCells;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getErrorMsg() {
|
|
|
+ return errorMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setErrorMsg(String errorMsg) {
|
|
|
+ this.errorMsg = errorMsg;
|
|
|
+ }
|
|
|
|
|
|
}
|