|
@@ -0,0 +1,141 @@
|
|
|
|
+package com.caimei.modules.baike.web;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import com.caimei.modules.baike.dao.CmBaikeTypeDao;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
+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.baike.entity.CmBaikeType;
|
|
|
|
+import com.caimei.modules.baike.service.CmBaikeTypeService;
|
|
|
|
+
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import static com.caimei.modules.newhome.web.NewPageQualitySupplierController.isInteger;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 采美百科分类管理Controller
|
|
|
|
+ * @author Aslee
|
|
|
|
+ * @version 2021-11-19
|
|
|
|
+ */
|
|
|
|
+@Controller
|
|
|
|
+@RequestMapping(value = "${adminPath}/baike/cmBaikeType")
|
|
|
|
+public class CmBaikeTypeController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CmBaikeTypeService cmBaikeTypeService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private CmBaikeTypeDao cmBaikeTypeDao;
|
|
|
|
+
|
|
|
|
+ @ModelAttribute
|
|
|
|
+ public CmBaikeType get(@RequestParam(required=false) String id) {
|
|
|
|
+ CmBaikeType entity = null;
|
|
|
|
+ if (StringUtils.isNotBlank(id)){
|
|
|
|
+ entity = cmBaikeTypeService.get(id);
|
|
|
|
+ }
|
|
|
|
+ if (entity == null){
|
|
|
|
+ entity = new CmBaikeType();
|
|
|
|
+ }
|
|
|
|
+ return entity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
|
+ public String list(CmBaikeType cmBaikeType, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
|
+ Page<CmBaikeType> page = cmBaikeTypeService.findPage(new Page<CmBaikeType>(request, response), cmBaikeType);
|
|
|
|
+ model.addAttribute("page", page);
|
|
|
|
+ return "modules/baike/cmBaikeTypeList";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "form")
|
|
|
|
+ public String form(CmBaikeType cmBaikeType, Model model) {
|
|
|
|
+ model.addAttribute("cmBaikeType", cmBaikeType);
|
|
|
|
+ return "modules/baike/cmBaikeTypeForm";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "save")
|
|
|
|
+ public String save(CmBaikeType cmBaikeType, Model model, RedirectAttributes redirectAttributes) {
|
|
|
|
+ if (!beanValidator(model, cmBaikeType)){
|
|
|
|
+ return form(cmBaikeType, model);
|
|
|
|
+ }
|
|
|
|
+ cmBaikeTypeService.save(cmBaikeType);
|
|
|
|
+ addMessage(redirectAttributes, "保存分类成功");
|
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/baike/cmBaikeType/?repage&typeSort=" + cmBaikeType.getTypeSort();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
|
+ public String delete(CmBaikeType cmBaikeType, RedirectAttributes redirectAttributes) {
|
|
|
|
+ cmBaikeTypeService.delete(cmBaikeType);
|
|
|
|
+ addMessage(redirectAttributes, "删除分类成功");
|
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/baike/cmBaikeType/?repage&typeSort=" + cmBaikeType.getTypeSort();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "updateStatus")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public Map<String,Object> updateStatus(Integer status, Integer typeId) {
|
|
|
|
+ HashMap<String, Object> result = new HashMap<>(2);
|
|
|
|
+ cmBaikeTypeDao.updateStatus(status, typeId);
|
|
|
|
+ result.put("success", true);
|
|
|
|
+ result.put("msg", (status == 1 ? "启用" : "停用") + "分类成功");
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量更新排序值
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "batchSaveSort")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public Map<String, Object> batchSaveSort(String sortList) {
|
|
|
|
+ Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
|
+ try {
|
|
|
|
+ String[] newPageLists = sortList.split(",");
|
|
|
|
+ for (String list : newPageLists) {
|
|
|
|
+ String[] split = list.split("-");
|
|
|
|
+ if (split.length == 1 || split.length < 1) {
|
|
|
|
+ String id = split[0];
|
|
|
|
+ String sort = null;
|
|
|
|
+ cmBaikeTypeDao.saveSort(sort, id);
|
|
|
|
+ } else {
|
|
|
|
+ String id = split[0];
|
|
|
|
+ String sort = split[1];
|
|
|
|
+ if (isInteger(sort)) {
|
|
|
|
+ if (StringUtils.equals("0", sort)) {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "排序值只能填写大于等于1的整数");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ cmBaikeTypeDao.saveSort(sort, id);
|
|
|
|
+ } else {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "排序值只能为数字");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("success", true);
|
|
|
|
+ map.put("msg", "更新排序成功");
|
|
|
|
+ return map;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "更新排序失败");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|