src/main/java/com/xcong/farmer/cms/modules/system/controller/CmsTemplateController.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/xcong/farmer/cms/modules/system/dto/TemplateListDto.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/xcong/farmer/cms/modules/system/entity/CmsTemplateEntity.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/xcong/farmer/cms/modules/system/mapper/CmsTemplateMapper.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/xcong/farmer/cms/modules/system/service/ICmsTemplateService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/xcong/farmer/cms/modules/system/util/LoginUserUtil.java | ●●●●● patch | view | raw | blame | history | |
src/main/resources/mapper/CmsTemplateMapper.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/com/xcong/farmer/cms/modules/system/controller/CmsTemplateController.java
New file @@ -0,0 +1,47 @@ package com.xcong.farmer.cms.modules.system.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.xcong.farmer.cms.common.response.Result; import com.xcong.farmer.cms.modules.system.dto.TemplateListDto; import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity; import com.xcong.farmer.cms.modules.system.service.ICmsTemplateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; /** * @author wzy * @date 2022-07-04 **/ @RestController @RequestMapping(value = "/api/template") @Api(value = "CmsTemplateController", tags = "模板接口类") public class CmsTemplateController { @Autowired private ICmsTemplateService cmsTemplateService; @ApiOperation(value = "上传模板", notes = "上传模板接口") @PostMapping(value = "/uploadTemplate") public Result uploadTemplate(MultipartFile file) { return Result.ok("上传成功"); } @ApiOperation(value = "模板列表", notes = "模板列表接口") @PostMapping(value = "/list") public Result list(@RequestBody @Valid TemplateListDto templateListDto) { return Result.ok(cmsTemplateService.findInPage(templateListDto)); } @ApiOperation(value = "删除模板", notes = "删除模板") @PostMapping(value = "/delete/{id}") public Result delete(@PathVariable("id") Long id) { cmsTemplateService.delete(id); return Result.ok("删除成功"); } } src/main/java/com/xcong/farmer/cms/modules/system/dto/TemplateListDto.java
New file @@ -0,0 +1,24 @@ package com.xcong.farmer.cms.modules.system.dto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotNull; /** * @author wzy * @date 2022-07-04 **/ @Data @ApiModel(value = "TemplateListDto", description = "模板列表接口参数接收类") public class TemplateListDto { @NotNull(message = "参数不能为空") @ApiModelProperty(value = "每页条数", example = "10") private Integer pageSize; @NotNull(message = "参数不能为空") @ApiModelProperty(value = "第几页", example = "1") private Integer pageNum; } src/main/java/com/xcong/farmer/cms/modules/system/entity/CmsTemplateEntity.java
@@ -22,4 +22,6 @@ * 类型 1-文件 2-代码 */ private Integer type; private Long companyId; } src/main/java/com/xcong/farmer/cms/modules/system/mapper/CmsTemplateMapper.java
@@ -1,7 +1,14 @@ package com.xcong.farmer.cms.modules.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity; import org.apache.ibatis.annotations.Param; public interface CmsTemplateMapper extends BaseMapper<CmsTemplateEntity> { IPage<CmsTemplateEntity> selectInPage(IPage<CmsTemplateEntity> page, @Param("record") CmsTemplateEntity cmsTemplateEntity); int delete(@Param("id") Long id, @Param("companyId") Long companyId); } src/main/java/com/xcong/farmer/cms/modules/system/service/ICmsTemplateService.java
New file @@ -0,0 +1,17 @@ package com.xcong.farmer.cms.modules.system.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.xcong.farmer.cms.modules.system.dto.TemplateListDto; import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity; import org.springframework.web.multipart.MultipartFile; public interface ICmsTemplateService extends IService<CmsTemplateEntity> { void updateTemplate(MultipartFile file); IPage<CmsTemplateEntity> findInPage(TemplateListDto templateListDto); void delete(Long id); } src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
New file @@ -0,0 +1,48 @@ package com.xcong.farmer.cms.modules.system.service.Impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.farmer.cms.core.template.TemplateConfiguration; import com.xcong.farmer.cms.modules.system.dto.TemplateListDto; import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity; import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper; import com.xcong.farmer.cms.modules.system.service.ICmsTemplateService; import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; /** * @author wzy * @date 2022-07-04 **/ @Service public class CmsTemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTemplateEntity> implements ICmsTemplateService { @Autowired private TemplateConfiguration cfg; @Override public void updateTemplate(MultipartFile file) { String templatePath = cfg.templatePath; String staticPath = cfg.staticPath; } @Override public IPage<CmsTemplateEntity> findInPage(TemplateListDto templateListDto) { Long companyId = LoginUserUtil.getCompanyId(); IPage<CmsTemplateEntity> page = new Page<>(templateListDto.getPageNum(), templateListDto.getPageSize()); CmsTemplateEntity template = new CmsTemplateEntity(); template.setCompanyId(companyId); return this.baseMapper.selectInPage(page, template); } @Override public void delete(Long id) { Long companyId = LoginUserUtil.getCompanyId(); this.baseMapper.delete(id, companyId); } } src/main/java/com/xcong/farmer/cms/modules/system/util/LoginUserUtil.java
@@ -16,4 +16,8 @@ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); return (UserEntity) request.getSession().getAttribute("user"); } public static Long getCompanyId() { return getLoginUser().getCompanyId() == null ? 0L : getLoginUser().getCompanyId(); } } src/main/resources/mapper/CmsTemplateMapper.xml
@@ -2,4 +2,18 @@ <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper"> <select id="selectInPage" resultType="com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity"> select * from cms_template <where> 1=1 <if test="record.companyId != null and record.companyId != 0"> and company_id=#{record.companyId} </if> </where> </select> <delete id="delete"> delete from cms_template where id=#{id} and company_id=#{companyId} </delete> </mapper>