package com.matrix.system.shopXcx.action; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.constance.SystemMessageCode; import com.matrix.core.pojo.PaginationVO; import com.matrix.core.tools.ModelUtils; import com.matrix.core.tools.StringUtils; import com.matrix.core.constance.SystemErrorCode; import com.matrix.core.anotations.RemoveRequestToken; import com.matrix.system.common.bean.SysUsers; import com.matrix.system.common.tools.ServiceUtil; import com.matrix.system.hive.action.util.QueryUtil; import com.matrix.system.shopXcx.dao.ShopArticleDao; import org.springframework.stereotype.Controller; import com.matrix.core.exception.GlobleException; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.matrix.core.anotations.SaveRequestToken; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.tools.WebUtil; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Map; import com.matrix.system.shopXcx.bean.ShopArticle; import org.springframework.web.servlet.ModelAndView; /** * @description 文章 * @author jiangyouyao * @date 2019-06-10 14:41 */ @Controller @RequestMapping(value = "admin/shopArticle") public class ShopArticleAction { @Autowired private ShopArticleDao shopArticleDao; @Autowired private ServiceUtil serviceUtil; //记录编辑前的值Before_Edit_Value public static final String BEV="ShopArticle_BEV"; /** * 列表显示 */ @RequestMapping(value = "/showList") public @ResponseBody AjaxResult showList(ShopArticle shopArticle, PaginationVO pageVo) { QueryUtil.setQueryLimitCom(shopArticle); List dataList = shopArticleDao.selectInPage(shopArticle, pageVo); AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, shopArticleDao.selectTotalRecord(shopArticle)); return result; } /** * 新增 */ @RemoveRequestToken @RequestMapping(value = "/addShopArticle") public @ResponseBody AjaxResult addShopArticle(ShopArticle shopArticle) { SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); shopArticle.setCreateBy(user.getSuName()); shopArticle.setUpdateBy(user.getSuName()); shopArticle.setCompanyId(user.getCompanyId()); //检查文章类别名称是否重复 boolean b = serviceUtil.addCheckRepeatTowColumn("shop_article", "art_title", shopArticle.getArtTitle(),"artype_id",shopArticle.getArtypeId()); if(b){ return new AjaxResult(AjaxResult.STATUS_FAIL,"同类型下文章标题不能相同"); } int i=shopArticleDao.insert(shopArticle); if(i > 0){ return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "文章"); }else { throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); } } /** * 修改 */ @RemoveRequestToken @RequestMapping(value = "/modifyShopArticle") public @ResponseBody AjaxResult modifyShopArticle(ShopArticle newShopArticle) { ShopArticle oldShopArticle = WebUtil.getSessionAttribute(BEV); int i = 0; Map modifyMap = null; try { if (!ModelUtils.isModified(oldShopArticle, newShopArticle)) { i = MatrixConstance.DML_SUCCESSS; } modifyMap = ModelUtils.comparePojo2Map(oldShopArticle, newShopArticle); if(modifyMap.size() == 0 && null == newShopArticle.getArtypeId() ){ modifyMap.put("artypeId", newShopArticle.getArtypeId()); } } catch (Exception e) { throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopArticle); } if (modifyMap.size() > 0) { //检查同类别下名称是否重复 boolean b = serviceUtil.updateCheckRepeatTowColumn("shop_article", "art_title", newShopArticle.getArtTitle(),"artype_id",newShopArticle.getArtypeId(),"art_id",oldShopArticle.getArtId()); if(b){ return new AjaxResult(AjaxResult.STATUS_FAIL,"同类型下文章标题不能相同"); } } i = shopArticleDao.updateByModel(newShopArticle); /*i = MatrixConstance.DML_SUCCESSS; WebUtil.removeSessionAttribute(BEV);*/ if (i > 0) { return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "文章"); } else { throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL); } } /** * 进入修改界面 */ @SaveRequestToken @RequestMapping(value = "/editForm") public ModelAndView editForm(Integer id) { ShopArticle shopArticle = new ShopArticle(); ModelAndView modelAndView = new ModelAndView("admin/shop/shopArticle-form"); if (id != null) { shopArticle = shopArticleDao.selectById(id); WebUtil.setSessionAttribute(BEV, shopArticle); } modelAndView.addObject("obj",shopArticle); return modelAndView; } /** * 删除 */ @RequestMapping(value = "/del") public @ResponseBody AjaxResult del(String keys) { List ids = StringUtils.strToCollToString(keys, ","); int i = shopArticleDao.deleteByIds(ids); if (i > 0) { return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); } else { throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); } } }