parent
65099d9eae
commit
e31ee1efef
@ -1,187 +0,0 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.CmsCategory; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.CmsCategoryService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@Api(value = "内容分类管理") |
||||
@RequestMapping(value = "/cmsCategory") |
||||
public class CmsCategoryController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsCategoryController.class); |
||||
@Resource |
||||
private CmsCategoryService cmsCategoryService; |
||||
|
||||
@RequestMapping(value = "/addCategory", method = RequestMethod.POST) |
||||
@ApiOperation(value = "增加 分类") |
||||
@ResponseBody |
||||
public ResponseData addCategory(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
|
||||
CmsCategory cmsCategory = jsonObject.getObject("category", CmsCategory.class); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("roles"); |
||||
Object[] roleArray = jsonArray.toArray(); |
||||
|
||||
if (cmsCategory == null || roleArray == null || roleArray.length == 0 |
||||
|| StringUtils.isBlank(cmsCategory.getName()) |
||||
|| StringUtils.isBlank(cmsCategory.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
List<Integer> roleList = new ArrayList<>(); |
||||
for (Object object : roleArray) { |
||||
roleList.add(Integer.valueOf(object.toString())); |
||||
} |
||||
|
||||
if (cmsCategoryService.addCategory(cmsCategory, roleList) > 0) { |
||||
return ResponseMsgUtil.success("添加数据成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> addCategory() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateCategory", method = RequestMethod.POST) |
||||
@ApiOperation(value = "修改 内容分类") |
||||
@ResponseBody |
||||
public ResponseData updateCategory(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
|
||||
CmsCategory cmsCategory = jsonObject.getObject("category", CmsCategory.class); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("roles"); |
||||
Object[] roleArray = jsonArray.toArray(); |
||||
|
||||
if (cmsCategory == null || roleArray == null || roleArray.length == 0 |
||||
|| cmsCategory.getId() == null |
||||
|| StringUtils.isBlank(cmsCategory.getName()) |
||||
|| StringUtils.isBlank(cmsCategory.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
List<Integer> roleList = new ArrayList<>(); |
||||
for (Object object : roleArray) { |
||||
roleList.add(Integer.valueOf(object.toString())); |
||||
} |
||||
|
||||
if (cmsCategoryService.updateCategory(cmsCategory, roleList) > 0) { |
||||
return ResponseMsgUtil.success("修改数据成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> updateCategory() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delCategory", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除 内容分类") |
||||
@ResponseBody |
||||
public ResponseData delCategory(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsCategoryService.delCategory(id) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> updateCategory() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCategoryById", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询 分类详情") |
||||
@ResponseBody |
||||
public ResponseData getCategoryById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsCategoryService.getCategoryById(id)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCategoryTree", method = RequestMethod.GET) |
||||
@ApiOperation(value = "获取分类树") |
||||
@ResponseBody |
||||
public ResponseData getCategoryTree(@RequestParam(value = "roleType", required = false) Integer roleType, |
||||
@RequestParam(value = "parentCode", required = false) String parentCode) { |
||||
try { |
||||
Map<String, Object> paramMap = new HashMap<>(); |
||||
if (roleType != null) { |
||||
paramMap.put("roleType", roleType); |
||||
} |
||||
if (StringUtils.isNotBlank(parentCode)) { |
||||
paramMap.put("parentCode", parentCode); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(cmsCategoryService.getCategoryTree(paramMap)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryTree() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getOwnCategoryTree", method = RequestMethod.GET) |
||||
@ApiOperation(value = "获取拥有的分类树") |
||||
@ResponseBody |
||||
public ResponseData getOwnCategoryTree(@RequestParam(value = "roleType", required = false) Integer roleType) { |
||||
try { |
||||
Map<String, Object> paramMap = new HashMap<>(); |
||||
if (roleType != null) { |
||||
paramMap.put("roleType", roleType); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(cmsCategoryService.getOwnCategoryTree(paramMap)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryTree() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getRolesOfCategory", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id查询 分类角色列表") |
||||
@ResponseBody |
||||
public ResponseData getRolesOfCategory(@RequestParam(value = "id", required = false) Long id) { |
||||
try { |
||||
List<Integer> roleList = new ArrayList<>(); |
||||
if (id != null) { |
||||
roleList = cmsCategoryService.getRolesOfCategory(id); |
||||
} else { |
||||
roleList.add(1); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(roleList); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,220 +0,0 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.CmsCategoryModule; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.CmsCategoryModuleService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@Api(value = "内容管理 模板") |
||||
@RequestMapping(value = "/cmsCategoryModule") |
||||
public class CmsCategoryModuleController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsCategoryModuleController.class); |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private CmsCategoryModuleService cmsCategoryModuleService; |
||||
|
||||
@RequestMapping(value = "/addCategoryModule", method = RequestMethod.POST) |
||||
@ApiOperation(value = "增加 模板") |
||||
@ResponseBody |
||||
public ResponseData addCategoryModule(@RequestBody CmsCategoryModule cmsCategoryModule, |
||||
HttpServletRequest request |
||||
) { |
||||
try { |
||||
if (cmsCategoryModule == null |
||||
|| cmsCategoryModule.getCategoryId() == null |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModuleName()) |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModulePath()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 获取操作者
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
if(sessionObject == null){ |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
cmsCategoryModule.setStatus(1); |
||||
cmsCategoryModule.setCreateTime(new Date()); |
||||
cmsCategoryModule.setOpId(userInfoModel.getSecUser().getId()); |
||||
if (cmsCategoryModuleService.addCategoryModule(cmsCategoryModule) > 0) { |
||||
return ResponseMsgUtil.success("添加成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> addCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateCategoryModule", method = RequestMethod.POST) |
||||
@ApiOperation(value = "修改 模板") |
||||
@ResponseBody |
||||
public ResponseData updateCategoryModule(@RequestBody CmsCategoryModule cmsCategoryModule) { |
||||
try { |
||||
if (cmsCategoryModule == null |
||||
|| cmsCategoryModule.getId() == null |
||||
|| cmsCategoryModule.getCategoryId() == null |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModuleName()) |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModulePath()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsCategoryModule categoryModule = cmsCategoryModuleService.getCategoryModuleById(cmsCategoryModule.getId()); |
||||
if (categoryModule == null || categoryModule.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CATEGORY_MODULE_NOT_FOUND, ""); |
||||
} |
||||
|
||||
cmsCategoryModule.setStatus(categoryModule.getStatus()); |
||||
cmsCategoryModule.setCreateTime(categoryModule.getCreateTime()); |
||||
cmsCategoryModule.setOpId(categoryModule.getOpId()); |
||||
if (cmsCategoryModuleService.updateCategoryModule(cmsCategoryModule) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> updateCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delCategoryModule", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除 模板") |
||||
@ResponseBody |
||||
public ResponseData delCategoryModule(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsCategoryModuleService.delCategoryModule(id) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> delCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCategoryModuleById", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id 查询模板") |
||||
@ResponseBody |
||||
public ResponseData getCategoryModuleById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsCategoryModuleService.getCategoryModuleById(id)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> getCategoryModuleById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getModuleByCategoryId", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据分类id 查询模板列表") |
||||
@ResponseBody |
||||
public ResponseData getModuleByCategoryId(@RequestParam(value = "categoryId", required = true) Long categoryId) { |
||||
try { |
||||
Map<String, Object> paramsMap = new HashMap<>(); |
||||
paramsMap.put("categoryId", categoryId); |
||||
|
||||
return ResponseMsgUtil.success(cmsCategoryModuleService.getListCategoryModule(paramsMap)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> getCategoryModuleById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getListCategoryModule", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询列表 模板") |
||||
@ResponseBody |
||||
public ResponseData getListCategoryModule(@RequestParam(value = "categoryId", required = false) Long categoryId, |
||||
@RequestParam(value = "categoryCode", required = false) String categoryCode, |
||||
@RequestParam(value = "moduleName", required = false) String moduleName, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, Object> paramsMap = new HashMap<>(); |
||||
if (categoryId != null) { |
||||
paramsMap.put("categoryId", categoryId); |
||||
} |
||||
if (StringUtils.isNotBlank(categoryCode)) { |
||||
paramsMap.put("categoryCode", categoryCode); |
||||
} |
||||
if (StringUtils.isNotBlank(moduleName)) { |
||||
paramsMap.put("moduleName", moduleName); |
||||
} |
||||
if (status != null) { |
||||
paramsMap.put("status", status); |
||||
} |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(cmsCategoryModuleService.getListCategoryModule(paramsMap))); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> getListCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateStatusOfModule", method = RequestMethod.POST) |
||||
@ApiOperation(value = "更新 模板状态") |
||||
@ResponseBody |
||||
public ResponseData updateStatusOfContent(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
Long id = jsonObject.getLong("id"); |
||||
Integer status = jsonObject.getInteger("status"); |
||||
|
||||
if (id == null |
||||
|| status == null |
||||
|| (status != 1 && status != 2) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsCategoryModule categoryModule = cmsCategoryModuleService.getCategoryModuleById(id); |
||||
if (categoryModule == null || categoryModule.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CATEGORY_MODULE_NOT_FOUND, ""); |
||||
} |
||||
|
||||
categoryModule.setStatus(status); |
||||
if (cmsCategoryModuleService.updateCategoryModule(categoryModule) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateStatusOfContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,392 +0,0 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.bweb.config.SysConfig; |
||||
import com.hfkj.entity.CmsContent; |
||||
import com.hfkj.entity.CmsPatch; |
||||
import com.hfkj.model.CmsContentModel; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.CmsContentService; |
||||
import com.hfkj.service.CmsPatchService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@Api(value = "内容管理 内容发布") |
||||
@RequestMapping(value = "/cmsContent") |
||||
public class CmsContentController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsContentController.class); |
||||
|
||||
@Resource |
||||
private SysConfig sysConfig; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private CmsContentService cmsContentService; |
||||
@Resource |
||||
private CmsPatchService cmsPatchService; |
||||
|
||||
@RequestMapping(value = "/addContent", method = RequestMethod.POST) |
||||
@ApiOperation(value = "创建内容") |
||||
@ResponseBody |
||||
public ResponseData addContent(@RequestBody JSONObject jsonObject, HttpServletRequest request) { |
||||
try { |
||||
CmsContent cmsContent = jsonObject.getObject("cmsContent", CmsContent.class); |
||||
Long moduleId = jsonObject.getLong("moduleId"); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("patches"); |
||||
List<CmsPatch> patchList = new ArrayList<>(); |
||||
if (jsonArray != null) { |
||||
patchList = JSONObject.parseArray(jsonArray.toJSONString(), CmsPatch.class); |
||||
} |
||||
|
||||
if (cmsContent == null |
||||
|| StringUtils.isBlank(cmsContent.getTitle()) |
||||
|| cmsContent.getCategoryId() == null |
||||
|| cmsContent.getStatus() == null |
||||
|| (cmsContent.getStatus() != 1 && cmsContent.getStatus() != 2) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 获取操作者
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
if(sessionObject == null){ |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (moduleId != null) { |
||||
paramsMap.put("moduleId", moduleId.toString()); |
||||
} |
||||
|
||||
cmsContent.setCreateTime(new Date()); |
||||
cmsContent.setVisitCount(0); |
||||
cmsContent.setUpdateTime(cmsContent.getCreateTime()); |
||||
cmsContent.setCompanyId(userInfoModel.getBsCompany().getId()); |
||||
cmsContent.setOpId(userInfoModel.getSecUser().getId()); |
||||
if (cmsContentService.addContent(cmsContent, patchList, paramsMap,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("添加成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> addContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateContent", method = RequestMethod.POST) |
||||
@ApiOperation(value = "修改内容") |
||||
@ResponseBody |
||||
public ResponseData updateContent(@RequestBody CmsContent cmsContent) { |
||||
try { |
||||
if (cmsContent == null |
||||
|| cmsContent.getId() == null |
||||
|| StringUtils.isBlank(cmsContent.getTitle()) |
||||
|| cmsContent.getCategoryId() == null |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsContent content = cmsContentService.getContentById(cmsContent.getId()); |
||||
if (content == null || content.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CONTENT_NOT_FOUND, ""); |
||||
} else if (content.getStatus() != 1 && content.getStatus() != 3) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); |
||||
} |
||||
|
||||
cmsContent.setCreateTime(content.getCreateTime()); |
||||
cmsContent.setStatus(content.getStatus()); |
||||
cmsContent.setVisitCount(content.getVisitCount()); |
||||
cmsContent.setJumpUrl(content.getJumpUrl()); |
||||
cmsContent.setUpdateTime(new Date()); |
||||
cmsContent.setCompanyId(content.getCompanyId()); |
||||
cmsContent.setOpId(content.getOpId()); |
||||
if (cmsContentService.updateContent(cmsContent, "updateContent", null,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delContent", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除 内容") |
||||
@ResponseBody |
||||
public ResponseData delContent(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsContentService.delContent(id,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> delContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getContentById", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id 查询内容基础信息") |
||||
@ResponseBody |
||||
public ResponseData getContentById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsContentService.getContentDetail(id, null)); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getContentDetail() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getContentDetail", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id 查询内容详情(包括附件列表)") |
||||
@ResponseBody |
||||
public ResponseData getContentDetail(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsContentService.getContentDetail(id, "queryWithPatches")); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getContentDetail() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getListContent", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询内容列表(不包括附件)") |
||||
@ResponseBody |
||||
public ResponseData getListContent(@RequestParam(value = "title", required = false) String title, |
||||
@RequestParam(value = "category", required = false) Long category, |
||||
@RequestParam(value = "categoryCode", required = false) String categoryCode, |
||||
@RequestParam(value = "tag", required = false) String tag, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(value = "companyId", required = false) Long companyId, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (StringUtils.isNotBlank(title)) { |
||||
paramsMap.put("title", title); |
||||
} |
||||
if (category != null) { |
||||
paramsMap.put("category", category.toString()); |
||||
} |
||||
if (categoryCode != null) { |
||||
paramsMap.put("categoryCode", categoryCode); |
||||
} |
||||
if (StringUtils.isNotBlank(tag)) { |
||||
paramsMap.put("tag", tag); |
||||
} |
||||
if (status != null) { |
||||
paramsMap.put("status", status.toString()); |
||||
} |
||||
if (companyId != null) { |
||||
paramsMap.put("companyId", companyId.toString()); |
||||
} |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(cmsContentService.getListContent(paramsMap))); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getListContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateStatusOfContent", method = RequestMethod.POST) |
||||
@ApiOperation(value = "更新 内容发布状态") |
||||
@ResponseBody |
||||
public ResponseData updateStatusOfContent(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
Long id = jsonObject.getLong("id"); |
||||
Integer status = jsonObject.getInteger("status"); |
||||
Long moduleId = jsonObject.getLong("moduleId"); |
||||
|
||||
if (id == null |
||||
|| status == null |
||||
|| (status != 1 && status != 2 && status != 3) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsContent content = cmsContentService.getContentById(id); |
||||
if (content == null || content.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CONTENT_NOT_FOUND, ""); |
||||
} |
||||
|
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (moduleId != null) { |
||||
paramsMap.put("moduleId", moduleId.toString()); |
||||
} |
||||
|
||||
content.setStatus(status); |
||||
if (cmsContentService.updateContent(content, "updateStatusOfContent", paramsMap,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateStatusOfContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateContentQuantity", method = RequestMethod.GET) |
||||
@ApiOperation(value = "内容访问量+1") |
||||
@ResponseBody |
||||
public ResponseData updateContentQuantity(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
CmsContent content = cmsContentService.getContentById(id); |
||||
if (content == null || content.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CONTENT_NOT_FOUND, ""); |
||||
} |
||||
|
||||
if (content.getVisitCount() != null) { |
||||
content.setVisitCount(content.getVisitCount() + 1); |
||||
} else { |
||||
content.setVisitCount(1); |
||||
} |
||||
if (cmsContentService.updateContent(content, "updateContent", null,null) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateContentQuantity() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getListPatches", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询内容附件列表") |
||||
@ResponseBody |
||||
public ResponseData getListPatches(@RequestParam(value = "contentId", required = true) Long contentId, |
||||
@RequestParam(value = "patchType", required = false) Integer patchType, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (contentId != null) { |
||||
paramsMap.put("contentId", contentId.toString()); |
||||
} |
||||
if (patchType != null) { |
||||
paramsMap.put("patchType", patchType.toString()); |
||||
} |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(cmsPatchService.getListPatch(paramsMap))); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getListContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCompleteContentList", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询内容列表(包括附件)") |
||||
@ResponseBody |
||||
public ResponseData getCompleteContentList(@RequestParam(value = "title", required = false) String title, |
||||
@RequestParam(value = "category", required = false) Long category, |
||||
@RequestParam(value = "categoryCode", required = false) String categoryCode, |
||||
@RequestParam(value = "tag", required = false) String tag, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(value = "companyId", required = false) Long companyId, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (StringUtils.isNotBlank(title)) { |
||||
paramsMap.put("title", title); |
||||
} |
||||
if (category != null) { |
||||
paramsMap.put("category", category.toString()); |
||||
} |
||||
if (categoryCode != null) { |
||||
paramsMap.put("categoryCode", categoryCode); |
||||
} |
||||
if (StringUtils.isNotBlank(tag)) { |
||||
paramsMap.put("tag", tag); |
||||
} |
||||
if (status != null) { |
||||
paramsMap.put("status", status.toString()); |
||||
} |
||||
if (companyId != null) { |
||||
paramsMap.put("companyId", companyId.toString()); |
||||
} |
||||
PageHelper.startPage(pageNum, pageSize); |
||||
List<CmsContentModel> result = cmsContentService.getListContent(paramsMap); |
||||
|
||||
// 查询附件列表
|
||||
Map<String, String> params = new HashMap<>(); |
||||
List<CmsPatch> patchList = cmsPatchService.getListPatch(params); |
||||
// 将附件按类型挂到对应的内容
|
||||
for (CmsContentModel item : result) { |
||||
item.setPictures(new ArrayList<>()); |
||||
item.setMusics(new ArrayList<>()); |
||||
item.setVideos(new ArrayList<>()); |
||||
item.setDocuments(new ArrayList<>()); |
||||
item.setOthers(new ArrayList<>()); |
||||
|
||||
patchList.stream().filter(patch -> item.getId().equals(patch.getContentId())) |
||||
.forEach(patch -> { |
||||
switch (patch.getPatchType()){ |
||||
case 1: |
||||
item.getPictures().add(patch); |
||||
break; |
||||
case 2: |
||||
item.getMusics().add(patch); |
||||
break; |
||||
case 3: |
||||
item.getVideos().add(patch); |
||||
break; |
||||
case 4: |
||||
item.getDocuments().add(patch); |
||||
break; |
||||
case 5: |
||||
item.getOthers().add(patch); |
||||
break; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(new PageInfo<>(result)); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getListContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCorporateAdvertising", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询首页轮播图") |
||||
@ResponseBody |
||||
public ResponseData getCorporateAdvertising() { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsContentService.getCorporateAdvertising()); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getCorporateAdvertising() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
@ -1,73 +0,0 @@ |
||||
package com.bweb.controller; |
||||
|
||||
|
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.CmsPatch; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.CmsPatchService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Date; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/cmsPatch") |
||||
@Api(value = "内容管理->附件") |
||||
public class CmsPatchController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsPatchController.class); |
||||
@Resource |
||||
private CmsPatchService cmsPatchService; |
||||
|
||||
@RequestMapping(value = "/addPatch", method = RequestMethod.POST) |
||||
@ApiOperation(value = "添加 附件") |
||||
@ResponseBody |
||||
public ResponseData addPatch(@RequestBody CmsPatch cmsPatch) { |
||||
try { |
||||
if (cmsPatch == null |
||||
|| cmsPatch.getContentId() == null |
||||
|| StringUtils.isBlank(cmsPatch.getPatchName()) |
||||
|| cmsPatch.getPatchType() == null |
||||
|| StringUtils.isBlank(cmsPatch.getPatchPath()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
cmsPatch.setAddTime(new Date()); |
||||
if (cmsPatchService.addPatch(cmsPatch) > 0) { |
||||
return ResponseMsgUtil.success("添加成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsPatchController --> addPatch() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delPatch", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除附件") |
||||
@ResponseBody |
||||
public ResponseData delPatch(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsPatchService.delPatch(id) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsPatchController --> delPatch() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue