package com.matrix.system.shopXcx.action;
|
|
import com.matrix.core.anotations.RemoveRequestToken;
|
import com.matrix.core.anotations.SaveRequestToken;
|
import com.matrix.core.constance.MatrixConstance;
|
import com.matrix.core.constance.SystemErrorCode;
|
import com.matrix.core.constance.SystemMessageCode;
|
import com.matrix.core.exception.GlobleException;
|
import com.matrix.core.pojo.AjaxResult;
|
import com.matrix.core.pojo.PaginationVO;
|
import com.matrix.core.tools.ModelUtils;
|
import com.matrix.core.tools.StringUtils;
|
import com.matrix.core.tools.WebUtil;
|
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.ShopPage;
|
import com.matrix.system.shopXcx.dao.ShopPageDao;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @description 小程序页面
|
* @author yourName
|
* @date 2020-04-03 14:56
|
*/
|
@Controller
|
@RequestMapping(value = "admin/shopPage")
|
public class ShopPageAction {
|
@Autowired
|
private ServiceUtil serviceUtil;
|
@Autowired
|
private ShopPageDao shopPageDao;
|
|
//记录编辑前的值Before_Edit_Value
|
public static final String BEV="ShopPage_BEV";
|
|
|
/**
|
* 列表显示
|
*/
|
@RequestMapping(value = "/showList")
|
public @ResponseBody AjaxResult showList(ShopPage shopPage, PaginationVO pageVo) {
|
if (pageVo == null) {
|
pageVo = new PaginationVO();
|
}
|
QueryUtil.setQueryLimitCom(shopPage);
|
List<ShopPage> dataList = shopPageDao.selectInPage(shopPage, pageVo);
|
AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList,
|
shopPageDao.selectTotalRecord(shopPage));
|
return result;
|
}
|
|
/**
|
* 列表显示不分页
|
*/
|
@RequestMapping(value = "/showAllList")
|
public @ResponseBody AjaxResult showAllList(ShopPage shopPage) {
|
QueryUtil.setQueryLimitCom(shopPage);
|
List<ShopPage> dataList = shopPageDao.selectInPage(shopPage, null);
|
AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList,
|
shopPageDao.selectTotalRecord(shopPage));
|
return result;
|
}
|
|
|
/**
|
* 新增
|
*/
|
@RemoveRequestToken
|
@RequestMapping(value = "/addShopPage")
|
public @ResponseBody AjaxResult addShopPage(ShopPage shopPage) {
|
SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
|
if (serviceUtil.addCheckRepeatTowColumn("shop_page", "code", shopPage.getCode(),"company_id", user.getCompanyId())) {
|
throw new GlobleException("code重复");
|
}
|
|
shopPage.setCreateBy(user.getSuName());
|
shopPage.setUpdateBy(user.getSuName());
|
shopPage.setCompanyId(user.getCompanyId());
|
int i=shopPageDao.insert(shopPage);
|
if(i > 0){
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "小程序页面");
|
}else {
|
throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
|
}
|
}
|
|
|
|
|
|
/**
|
* 修改
|
*/
|
@RemoveRequestToken
|
@RequestMapping(value = "/modifyShopPage")
|
public @ResponseBody AjaxResult modifyShopPage(ShopPage newShopPage) {
|
ShopPage oldShopPage = WebUtil.getSessionAttribute(BEV);
|
SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
|
// 校验去重
|
if (serviceUtil.updateCheckRepeatTowColumn("shop_page",
|
"company_id", user.getCompanyId(),
|
"code", newShopPage.getCode(),
|
"id",newShopPage.getId())) {
|
throw new GlobleException("编号" + newShopPage.getCode() + "重复");
|
}
|
|
|
int i = 0;
|
Map<String, Object> modifyMap = null;
|
try {
|
if (!ModelUtils.isModified(oldShopPage, newShopPage)) {
|
i = MatrixConstance.DML_SUCCESSS;
|
}
|
modifyMap = ModelUtils.comparePojo2Map(oldShopPage, newShopPage);
|
} catch (Exception e) {
|
throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopPage);
|
}
|
if (modifyMap.size() > 0) {
|
modifyMap.put("id", oldShopPage.getId());
|
shopPageDao.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(Long id) {
|
ShopPage shopPage = new ShopPage();
|
ModelAndView modelAndView = new ModelAndView("admin/shop/shopPage-form");
|
if (id != null) {
|
shopPage = shopPageDao.selectById(id);
|
WebUtil.setSessionAttribute(BEV, shopPage);
|
}
|
modelAndView.addObject("obj",shopPage);
|
return modelAndView;
|
}
|
|
|
/**
|
* 删除
|
*/
|
@RequestMapping(value = "/del")
|
public @ResponseBody AjaxResult del(String keys) {
|
List<String> ids = StringUtils.strToCollToString(keys, ",");
|
int i = shopPageDao.deleteByIds(ids);
|
if (i > 0) {
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i);
|
} else {
|
throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL);
|
}
|
}
|
|
}
|