|
@@ -0,0 +1,82 @@
|
|
|
|
|
+package com.jzg.organization.controller;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.jzg.commons.core.page.HttpResult;
|
|
|
|
|
+import com.jzg.commons.entity.dto.PosterAdd;
|
|
|
|
|
+import com.jzg.commons.entity.dto.PosterEnd;
|
|
|
|
|
+import com.jzg.commons.entity.dto.PosterParam;
|
|
|
|
|
+import com.jzg.commons.entity.po.SysPoster;
|
|
|
|
|
+import com.jzg.commons.entity.po.SysPosterOrg;
|
|
|
|
|
+import com.jzg.organization.mapper.PosterOrgMapper;
|
|
|
|
|
+import com.jzg.organization.service.PosterService;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@Validated
|
|
|
|
|
+@Tag(name="广告位管理")
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/poster")
|
|
|
|
|
+public class PosterController {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PosterService posterService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PosterOrgMapper posterOrgMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Schema(description = "查询广告位分页")
|
|
|
|
|
+ @PostMapping("/queryPage")
|
|
|
|
|
+ public HttpResult queryPage(@RequestBody PosterParam posterParam) {
|
|
|
|
|
+ return posterService.queryPage(posterParam);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/save")
|
|
|
|
|
+ public HttpResult save(@RequestBody PosterAdd posterAdd) {
|
|
|
|
|
+ SysPoster sysPoster = BeanUtil.copyProperties(posterAdd, SysPoster.class);
|
|
|
|
|
+ boolean save = posterService.save(sysPoster);
|
|
|
|
|
+ if (save && !CollectionUtils.isEmpty(posterAdd.getLevelOrgIds())){
|
|
|
|
|
+ saveOrUpdate(posterAdd.getLevelOrgIds(), sysPoster.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ return save ? HttpResult.ok("保存成功") : HttpResult.error("保存失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/updateById")
|
|
|
|
|
+ public HttpResult updateById(@RequestBody PosterEnd posterEnd) {
|
|
|
|
|
+ boolean updated = posterService.updateById(BeanUtil.copyProperties(posterEnd, SysPoster.class));
|
|
|
|
|
+ if (updated && !CollectionUtils.isEmpty(posterEnd.getLevelOrgIds())){
|
|
|
|
|
+ saveOrUpdate(posterEnd.getLevelOrgIds(), posterEnd.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ return updated ? HttpResult.ok("修改成功") : HttpResult.error("修改失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void saveOrUpdate(List<String> orgIds,Long id) {
|
|
|
|
|
+ List<SysPosterOrg> list = new ArrayList<>();
|
|
|
|
|
+ orgIds.forEach(orgId -> {
|
|
|
|
|
+ SysPosterOrg posterOrg = new SysPosterOrg();
|
|
|
|
|
+ posterOrg.setPosterId(id);
|
|
|
|
|
+ posterOrg.setOrgId(Long.valueOf(orgId));
|
|
|
|
|
+ list.add(posterOrg);
|
|
|
|
|
+ });
|
|
|
|
|
+ LambdaQueryWrapper<SysPosterOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ lambdaQueryWrapper.eq(SysPosterOrg::getPosterId, id);
|
|
|
|
|
+ posterOrgMapper.delete(lambdaQueryWrapper);
|
|
|
|
|
+ posterOrgMapper.insertOrUpdate(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/delete/{id}")
|
|
|
|
|
+ public HttpResult delete(@PathVariable String id) {
|
|
|
|
|
+ return posterService.removeById(id) ? HttpResult.ok("删除成功") : HttpResult.error("删除失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|