From 7ea5eece501c98a91555a5358931367e78e9d23b Mon Sep 17 00:00:00 2001 From: baizonghao <1719256278@qq.com> Date: 星期四, 25 五月 2023 15:40:09 +0800 Subject: [PATCH] 11 --- src/main/java/com/example/jz/controller/PublicityController.java | 136 ++++++++++++++++++++++++++++++++++++++------- 1 files changed, 114 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/example/jz/controller/PublicityController.java b/src/main/java/com/example/jz/controller/PublicityController.java index 288c017..6256a0e 100644 --- a/src/main/java/com/example/jz/controller/PublicityController.java +++ b/src/main/java/com/example/jz/controller/PublicityController.java @@ -1,18 +1,31 @@ package com.example.jz.controller; - import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.api.ApiController; -import com.baomidou.mybatisplus.extension.api.R; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.example.jz.dao.UserDao; +import com.example.jz.modle.PageParam; +import com.example.jz.modle.R; import com.example.jz.modle.entity.Publicity; +import com.example.jz.modle.entity.User; +import com.example.jz.modle.vo.PublicityVo; import com.example.jz.service.PublicityService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import lombok.SneakyThrows; +import org.springframework.beans.BeanUtils; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.Serializable; -import java.util.List; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; /** * 鍏叡瀹d紶琛�(Publicity)琛ㄦ帶鍒跺眰 @@ -22,23 +35,63 @@ */ @RestController @RequestMapping("publicity") -public class PublicityController extends ApiController { +@Api(tags = "鍏叡瀹d紶鎺ュ彛") +public class PublicityController { /** * 鏈嶅姟瀵硅薄 */ @Resource private PublicityService publicityService; + @Resource + UserDao userDao; /** * 鍒嗛〉鏌ヨ鎵�鏈夋暟鎹� * - * @param page 鍒嗛〉瀵硅薄 + * @param page 鍒嗛〉瀵硅薄 * @param publicity 鏌ヨ瀹炰綋 * @return 鎵�鏈夋暟鎹� */ @GetMapping - public R selectAll(Page<Publicity> page, Publicity publicity) { - return success(this.publicityService.page(page, new QueryWrapper<>(publicity))); + @ApiOperation("鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�") + public R<IPage<PublicityVo>> selectAll(PageParam<Publicity> page, Publicity publicity) { + ArrayList<PublicityVo> publicityVos = new ArrayList<>(); + PageParam<Publicity> publicityPageParam ; + if (publicity.getStatus()!=null ){ + publicityPageParam = publicityService.page(page, + new QueryWrapper<Publicity>().like(StringUtils.isNotBlank(publicity.getPublicityTitle()), + "publicity_title", + publicity.getPublicityTitle()).eq("status",publicity.getStatus()).orderByDesc("ctime")); + }else { + publicityPageParam = publicityService.page(page, + new QueryWrapper<Publicity>().like(StringUtils.isNotBlank(publicity.getPublicityTitle()), + "publicity_title", + publicity.getPublicityTitle()).orderByDesc("ctime")); + } + publicityPageParam.getRecords().forEach(item->{ + PublicityVo publicityVo = new PublicityVo(); + BeanUtils.copyProperties(item,publicityVo); + publicityVo.setUserName(userDao.selectOne(new QueryWrapper<User>().eq("id",item.getCreator())).getRealName()); + publicityVos.add(publicityVo); + }); + PageParam<PublicityVo> publicityVoPageParam = new PageParam<>(); + BeanUtils.copyProperties(publicityPageParam,publicityVoPageParam); + publicityVoPageParam.setRecords(publicityVos); + return R.ok(publicityVoPageParam); + } + + @GetMapping("changTime") + @ApiOperation("淇敼鏃堕棿") + public R changeTime(@RequestParam Integer id, @RequestParam String time){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Publicity publicity = publicityService.getById(id); + try { + publicity.setReleaseTime(sdf.parse(time)); + } catch (ParseException e) { + throw new RuntimeException(e); + } + boolean b = publicityService.updateById(publicity); + return b ? R.ok("淇敼鎴愬姛") : R.failed("淇敼澶辫触"); } /** @@ -48,8 +101,9 @@ * @return 鍗曟潯鏁版嵁 */ @GetMapping("{id}") - public R selectOne(@PathVariable Serializable id) { - return success(this.publicityService.getById(id)); + @ApiOperation("閫氳繃涓婚敭鏌ヨ鍗曟潯鏁版嵁") + public R<Publicity> selectOne(@PathVariable Serializable id) { + return R.ok(publicityService.getById(id)); } /** @@ -59,8 +113,12 @@ * @return 鏂板缁撴灉 */ @PostMapping - public R insert(@RequestBody Publicity publicity) { - return success(this.publicityService.save(publicity)); + @ApiOperation("娣诲姞鍏叡瀹d紶") + public R<Boolean> insert(@RequestBody Publicity publicity) { + publicity.setStatus(0); + publicity.setCtime(new Date()); + publicity.setCreator(userDao.selectOne(new QueryWrapper<User>().eq("login_username", SecurityContextHolder.getContext().getAuthentication().getPrincipal())).getId()); + return R.ok(publicityService.save(publicity)); } /** @@ -70,19 +128,53 @@ * @return 淇敼缁撴灉 */ @PutMapping - public R update(@RequestBody Publicity publicity) { - return success(this.publicityService.updateById(publicity)); + @ApiOperation("淇敼鍏叡瀹d紶鍐呭") + public R<Boolean> update(@RequestBody Publicity publicity) { + return R.ok(publicityService.updateById(publicity)); } /** - * 鍒犻櫎鏁版嵁 + * 涓嬫灦鍏叡瀹d紶 * - * @param idList 涓婚敭缁撳悎 - * @return 鍒犻櫎缁撴灉 + * @param id 涓婚敭缁撳悎 + * @return 鎵ц缁撴灉 */ - @DeleteMapping - public R delete(@RequestParam("idList") List<Long> idList) { - return success(this.publicityService.removeByIds(idList)); + @GetMapping("offline/{id}") + @ApiOperation("涓嬫灦鍏叡瀹d紶") + public R<Boolean> offline(@PathVariable Serializable id) { + return R.ok(publicityService.undercarriage(id)); + } + + /** + * 涓婃灦鍏叡瀹d紶 + * + * @param id 涓婚敭缁撳悎 + * @return 鎵ц缁撴灉 + */ + @GetMapping("release/{id}") + @ApiOperation("涓婃灦鍏叡瀹d紶") + public R<Boolean> release(@PathVariable Serializable id) { + return R.ok(publicityService.grounding(id)); + } + + /** + * 鍒犻櫎鍏叡瀹d紶 + * + * @param id 涓婚敭缁撳悎 + * @return 鎵ц缁撴灉 + */ + @DeleteMapping("{id}") + @ApiOperation("鍒犻櫎鍏叡瀹d紶") + public R<Boolean> delete(@PathVariable Serializable id) { + return R.ok(publicityService.removeById(id)); + } + + @ApiOperation(httpMethod = "POST", value = "妗堜欢鍙�-妗堜欢褰曞叆-妗堜欢瀵煎叆") + @PostMapping("/upload") + @ApiResponse(message = "鎵ц鎴愬姛", code = 200) + @SneakyThrows + public R upload(@RequestParam(value = "multipartFile") MultipartFile multipartFile) { + publicityService.loadFile(multipartFile); + return R.ok(); } } - -- Gitblit v1.8.0