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.shopXcx.bean.ShopProductImg; import com.matrix.system.shopXcx.dao.ShopProductImgDao; 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 org.springframework.web.servlet.ModelAndView; /** * @description 产品图片表 * @author jyy * @date 2019-06-10 10:58 */ @Controller @RequestMapping(value = "admin/shopProductImg") public class ShopProductImgAction { @Autowired private ShopProductImgDao shopProductImgDao; //记录编辑前的值Before_Edit_Value public static final String BEV="ShopProductImg_BEV"; /** * 列表显示 */ @RequestMapping(value = "/showList") public @ResponseBody AjaxResult showList(ShopProductImg shopProductImg, PaginationVO pageVo) { List dataList = shopProductImgDao.selectInPage(shopProductImg, pageVo); AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, shopProductImgDao.selectTotalRecord(shopProductImg)); return result; } /** * 新增 */ @RemoveRequestToken @RequestMapping(value = "/addShopProductImg") public @ResponseBody AjaxResult addShopProductImg(ShopProductImg shopProductImg) { SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); shopProductImg.setCreateBy(user.getSuName()); shopProductImg.setUpdateBy(user.getSuName()); int i=shopProductImgDao.insert(shopProductImg); if(i > 0){ return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "产品图片表"); }else { throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); } } /** * 修改 */ @RemoveRequestToken @RequestMapping(value = "/modifyShopProductImg") public @ResponseBody AjaxResult modifyShopProductImg(ShopProductImg newShopProductImg) { ShopProductImg oldShopProductImg = WebUtil.getSessionAttribute(BEV); int i = 0; Map modifyMap = null; try { if (!ModelUtils.isModified(oldShopProductImg, newShopProductImg)) { i = MatrixConstance.DML_SUCCESSS; } modifyMap = ModelUtils.comparePojo2Map(oldShopProductImg, newShopProductImg); } catch (Exception e) { throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopProductImg); } if (modifyMap.size() > 0) { modifyMap.put("id", oldShopProductImg.getId()); shopProductImgDao.updateByMap(modifyMap); } 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) { ShopProductImg shopProductImg = new ShopProductImg(); ModelAndView modelAndView = new ModelAndView("admin/shopProductImg-form"); if (id != null) { shopProductImg = shopProductImgDao.selectById(id); WebUtil.setSessionAttribute(BEV, shopProductImg); } modelAndView.addObject("obj",shopProductImg); return modelAndView; } /** * 删除 */ @RequestMapping(value = "/del") public @ResponseBody AjaxResult del(String keys) { List ids = StringUtils.strToCollToString(keys, ","); int i = shopProductImgDao.deleteByIds(ids); if (i > 0) { return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); } else { throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); } } }