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.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.bean.ShopArticleType; import com.matrix.system.shopXcx.dao.ShopArticleTypeDao; 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.*; import org.springframework.web.servlet.ModelAndView; /** * @description 文章分类 * @author jiangyouyao * @date 2019-06-10 14:41 */ @Controller @RequestMapping(value = "admin/shopArticleType") public class ShopArticleTypeAction { @Autowired private ShopArticleTypeDao shopArticleTypeDao; @Autowired private ServiceUtil serviceUtil; //记录编辑前的值Before_Edit_Value public static final String BEV="ShopArticleType_BEV"; /** * 列表显示 */ @RequestMapping(value = "/showList") public @ResponseBody AjaxResult showList(ShopArticleType shopArticleType, PaginationVO pageVo) { QueryUtil.setQueryLimitCom(shopArticleType); List dataList = shopArticleTypeDao.selectInPage(shopArticleType, pageVo); AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, shopArticleTypeDao.selectTotalRecord(shopArticleType)); return result; } /** * 新增 */ @RemoveRequestToken @RequestMapping(value = "/addShopArticleType") public @ResponseBody AjaxResult addShopArticleType(ShopArticleType shopArticleType) { SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); shopArticleType.setCreateBy(user.getSuName()); shopArticleType.setUpdateBy(user.getSuName()); shopArticleType.setCompanyId(user.getCompanyId()); //检查文章类别名称是否重复 boolean b = serviceUtil.addCheckRepeat("shop_article_type", "artype_name", shopArticleType.getArtypeName()); if(b){ return new AjaxResult(AjaxResult.STATUS_FAIL,"文章类别名称已经存在"); } //检查文章类型编号是否重复 boolean c = serviceUtil.addCheckRepeat("shop_article_type", "artype_code", shopArticleType.getArtypeCode()); if(c){ return new AjaxResult(AjaxResult.STATUS_FAIL,"文章类型编号已经存在"); } int i=shopArticleTypeDao.insert(shopArticleType); if(i > 0){ return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "文章分类"); }else { throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); } } /** * 修改 */ @RemoveRequestToken @RequestMapping(value = "/modifyShopArticleType") public @ResponseBody AjaxResult modifyShopArticleType(ShopArticleType newShopArticleType) { SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); newShopArticleType.setUpdateBy(user.getSuName()); ShopArticleType shopArticleType = shopArticleTypeDao.selectById(newShopArticleType.getArtypeId()); boolean b; if(newShopArticleType.getArtypeCode().equals(shopArticleType.getArtypeCode())){ b = serviceUtil.updateCheckRepeat("shop_article_type", "artype_code", shopArticleType.getArtypeCode(),"artype_code",newShopArticleType.getArtypeCode()); }else{ b = serviceUtil.addCheckRepeat("shop_article_type","artype_code",newShopArticleType.getArtypeCode()); } if(b){ return new AjaxResult(AjaxResult.STATUS_FAIL,"文章类型编号不能重复"); } boolean c; if(newShopArticleType.getArtypeName().equals(shopArticleType.getArtypeName())){ b = serviceUtil.updateCheckRepeat("shop_article_type", "artype_name", shopArticleType.getArtypeName(),"artype_name",newShopArticleType.getArtypeName()); }else{ b = serviceUtil.addCheckRepeat("shop_article_type","artype_name",newShopArticleType.getArtypeName()); } if(b){ return new AjaxResult(AjaxResult.STATUS_FAIL,"文章类别名称不能重复"); } Map modifyMap = new HashMap<>(); try { if(modifyMap.size() == 0 && null == newShopArticleType.getArtypeParentid()){ modifyMap.put("artypeParentid", newShopArticleType.getArtypeParentid()); modifyMap.put("artypeId", newShopArticleType.getArtypeId()); shopArticleTypeDao.updateByMap(modifyMap); } } catch (Exception e) { throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopArticleType); } int i = shopArticleTypeDao.updateByModel(newShopArticleType); 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) { ShopArticleType shopArticleType = new ShopArticleType(); ModelAndView modelAndView = new ModelAndView("admin/shop/shopArticleType-form"); if (id != null) { shopArticleType = shopArticleTypeDao.selectById(id); WebUtil.setSessionAttribute(BEV, shopArticleType); } modelAndView.addObject("obj",shopArticleType); return modelAndView; } /** * 删除 */ @RequestMapping(value = "/del") public @ResponseBody AjaxResult del(String keys) { List ids = StringUtils.strToCollToString(keys, ","); int i = shopArticleTypeDao.deleteByIds(ids); if (i > 0) { return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); } else { throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); } } /** * 显示所有文章类别 * * @author jiangyouyao * @date Dec 10, 2019 * @return */ @RequestMapping(value = "/all") public @ResponseBody AjaxResult all(ShopArticleType shopArticleType) { QueryUtil.setQueryLimitCom(shopArticleType); return new AjaxResult(AjaxResult.STATUS_SUCCESS, shopArticleTypeDao.selectByModel(shopArticleType)); } /** * * 修改查询,在session保存旧值 * @author:jiangyouyao * @param shopArticleType * @param * @return 返回类型 AjaxResult * @date 2019年06月10日 */ @RequestMapping(value = "/findById") public @ResponseBody AjaxResult findById(ShopArticleType shopArticleType) { shopArticleType =shopArticleTypeDao.selectById(shopArticleType.getArtypeId()) ; WebUtil.setSessionAttribute(BEV, shopArticleType); return new AjaxResult(AjaxResult.STATUS_SUCCESS, Collections.singletonList(shopArticleType)); } }