CmsController.java 27.7 KB
Newer Older
yuquan.zhu committed
1 2
package cn.timer.api.controller.qyxx;

翁国栋 committed
3
import java.util.*;
yuquan.zhu committed
4

5 6 7
import cn.timer.api.bean.qyxx.*;
import cn.timer.api.dto.qyxx.CmsContentReadDto;
import com.github.yulichang.query.MPJQueryWrapper;
翁国栋 committed
8
import com.google.common.collect.Maps;
9
import lombok.extern.slf4j.Slf4j;
yuquan.zhu committed
10 11
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
12 13
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
yuquan.zhu committed
14 15 16 17 18 19 20 21 22
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

邓实川 committed
23
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
yuquan.zhu committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.dao.qyxx.CmsContentMapper;
import cn.timer.api.dao.qyxx.CmsIsReadMapper;
import cn.timer.api.dto.qyxx.CmsContentDto;
import cn.timer.api.dto.qyxx.QyxxIsReadDto;
import cn.timer.api.dto.qyxx.QyxxQueryDto;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

45 46
import javax.annotation.Resource;

yuquan.zhu committed
47 48 49 50
@RestController
@Api(tags = "5.0企业讯息")
@Transactional
@RequestMapping(value = "/qyxx", produces = { "application/json" })
51
@Slf4j
yuquan.zhu committed
52 53 54 55 56 57 58 59
public class CmsController {

	@Autowired
	private CmsContentMapper cmsContentMapper;

	@Autowired
	private CmsIsReadMapper cmsIsReadMapper;

60 61
//	@Autowired
//	private CmsAnnouncementMapper cmsAnnouncementMapper;
yuquan.zhu committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

	/**
	 * 查询所有讯息
	 */
	@GetMapping(value = "/hqqyxx")
	@ApiOperation(value = "获取企业讯息", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<CmsContent>> getQyxx(@CurrentUser UserBean userBean) {
		if (userBean.getOrgCode() != null) {

			Integer orgCode = userBean.getOrgCode();

			QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
			queryWrapper.eq("organization_id", orgCode);

			List<CmsContent> qynr = CmsContent.builder().build().selectList(queryWrapper);

			return ResultUtil.data(qynr, "查询成功!");
		}
		return ResultUtil.error("请登录!");
	}

	/**
	 * 查询最新讯息,获取标题和发布时间
	 */
	@GetMapping(value = "/zxqyxx")
	@ApiOperation(value = "获取最新讯息的标题、发布时间", httpMethod = "GET", notes = "接口发布说明")
翁国栋 committed
88 89
	public Result<Object> groupbyTime(@CurrentUser UserBean userBean) {
		Map map = Maps.newHashMap();
yuquan.zhu committed
90
		Integer orgCode = userBean.getOrgCode();
91 92 93 94 95 96 97 98 99 100
		MPJQueryWrapper<CmsContent> queryWrapper = new MPJQueryWrapper<>();
		queryWrapper.select("t.id", "t.title", "t.author", "t.releasetime", "t.fmtpath")
				.leftJoin("cms_content_read ccr on t.id = ccr.cms_content_id");
		queryWrapper.eq("t.releasestate", 0)
				.and(!StringUtils.isEmpty(userBean.getEmpNum()), wq -> wq.eq("t.open_status", 1)
						.or(true,q -> q.eq("t.open_status", 0).eq("ccr.user_id",userBean.getEmpNum()))
						.or(true,q -> q.eq("t.open_status", 0).eq("t.userid",userBean.getEmpNum())))
				.eq("t.organization_id", orgCode)
				.groupBy("t.id")
				.orderByDesc("t.releasetime").last("limit 6");
yuquan.zhu committed
101
		List<CmsContent> qynr = CmsContent.builder().build().selectList(queryWrapper);
翁国栋 committed
102 103 104 105 106 107 108 109 110
		/*应需求一定要展示前四张图片*/
		QueryWrapper<CmsContent> qw = new QueryWrapper<>();
		qw.select("fmtpath").eq("releasestate", 0).isNotNull("fmtpath").ne("fmtpath","")
				.eq("organization_id", orgCode).orderByDesc("releasetime").last("limit 4");
		List<CmsContent> picList = CmsContent.builder().build().selectList(qw);
		map.put("list",qynr);
		map.put("picList",picList);

		return ResultUtil.data(map, "查询分类成功!");
yuquan.zhu committed
111 112 113 114
	}

	/**
	 * 分类,获取标题和发布时间
翁国栋 committed
115
	 *
yuquan.zhu committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
	 */
//	@GetMapping(value = "/flhqqyxx")
//	@ApiOperation(value = "获取首页分类讯息标题、发布时间", httpMethod = "GET", notes = "接口发布说明")
//	public Result<List<List<CmsContent>>> groupbyTpye(@CurrentUser UserBean userBean) {
//		Integer orgCode = userBean.getOrgCode();
//		List<List<CmsContent>> cmsContentList = new ArrayList<List<CmsContent>>();
//		List<CmsContent> qynrAll = new ArrayList<CmsContent>();
//		QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
//		queryWrapper.select("modularid").eq("organization_id", orgCode).orderByAsc("modularid").groupBy("modularid");
//		List<CmsContent> qynrs = CmsContent.builder().build().selectList(queryWrapper);
//		if (qynrs == null || qynrs.size() == 0) {
//			return ResultUtil.success("查询成功!");
//		}
//		for (CmsContent cmsContent : qynrs) {
//			QueryWrapper<CmsContent> query222 = new QueryWrapper<>();
//			query222.select("id", "modularid", "title", "author", "releasetime").eq("releasestate", 0)
//					.eq("organization_id", orgCode).orderByDesc("releasetime").last("limit 5")
//					.eq("modularid", cmsContent.getModularid());
//			List<CmsContent> cmsContents = CmsContent.builder().build().selectList(query222);
//			if (cmsContents != null && cmsContents.size() > 0) {
//				for (int i = 0; i < cmsContents.size(); i++) {
//					qynrAll.add(cmsContents.get(i));
//				}
//				cmsContentList.add(qynrAll);
//				qynrAll = new ArrayList<CmsContent>();
//			}
//		}
//		return ResultUtil.data(cmsContentList, "查询成功!");
//	}

	/**
	 * 分类内容获取
翁国栋 committed
148
	 *
yuquan.zhu committed
149 150 151 152
	 */
	@GetMapping(value = "/getType")
	@ApiOperation(value = "分类内容获取", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getType(@CurrentUser UserBean userBean) {
153
		// 分类模块信息
154 155
		List<CmsContentModular> list = CmsContentModular.builder().build()
				.selectList(new QueryWrapper<CmsContentModular>().eq("is_open", 0) // 是否开启
156 157
//				.eq("organization_id", userBean.getOrgCode())
				);
yuquan.zhu committed
158 159 160 161
		List<List<CmsContent>> o = new ArrayList<List<CmsContent>>();
		for (CmsContentModular cmsContentModular : list) {
			// 分类模块id
			Integer id = cmsContentModular.getId();
162 163 164 165 166 167 168 169 170 171
			MPJQueryWrapper<CmsContent> queryWrapper = new MPJQueryWrapper<>();
			queryWrapper.select("t.id", "t.modularid", "t.title", "t.author", "t.releasetime")
					.leftJoin("cms_content_read ccr on t.id = ccr.cms_content_id");
			queryWrapper.eq("t.releasestate", 0)
					.and(!StringUtils.isEmpty(userBean.getEmpNum()), wq -> wq.eq("t.open_status", 1)
							.or(true,q -> q.eq("t.open_status", 0).eq("ccr.user_id",userBean.getEmpNum()))
							.or(true,q -> q.eq("t.open_status", 0).eq("t.userid",userBean.getEmpNum())))
					.eq("t.organization_id", userBean.getOrgCode()).eq("t.modularid", id)
					.groupBy("t.id")
					.orderByDesc("t.releasetime")
yuquan.zhu committed
172 173 174 175 176 177 178 179 180
					.last("limit 5");
			List<CmsContent> qynrs = CmsContent.builder().build().selectList(queryWrapper);
			o.add(qynrs);
		}
		return ResultUtil.data(o, "查询成功!");
	}

	/**
	 * 获取分类
翁国栋 committed
181
	 *
yuquan.zhu committed
182 183 184 185
	 */
	@GetMapping(value = "/xxfl")
	@ApiOperation(value = "获取分类", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getxxfl(@CurrentUser UserBean userBean) {
186
		return ResultUtil.data(CmsContentModular.builder().build().selectList(new QueryWrapper<CmsContentModular>()
187
//				.eq("organization_id", userBean.getOrgCode())
188 189
				.eq("is_open", 0)
		.orderByAsc("sort")), "查询分类成功!");
yuquan.zhu committed
190 191 192 193 194 195 196 197 198
	}

	/**
	 * 新增/修改企业OA讯息
	 */
	@PostMapping(value = "/updateqyxx")
	@ApiOperation(value = "添加/修改企业OA讯息", httpMethod = "POST", notes = "接口发布说明")
	public Result<CmsContent> updateqyxx(@CurrentUser UserBean userBean, @RequestBody CmsContentDto cmsContentDto) {

邓实川 committed
199 200 201
		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();

ilal committed
202
//		String str = StringUtils.join(cmsContentDto.getFilepath(), ","); // 数组转字符串(逗号分隔)(推荐)
yuquan.zhu committed
203 204 205

		CmsContent qynr = new CmsContent();
		BeanUtil.copyProperties(cmsContentDto, qynr);
ilal committed
206
//		qynr.setFilepath(str);
邓实川 committed
207 208
//		Integer i = 10000;
//		qynr.setXxbh("XX" + i++);
yuquan.zhu committed
209 210

		Boolean a = qynr.getId() == null;
211 212 213
		if(a){
			qynr.setUserid(empNum);
		}
yuquan.zhu committed
214
		if (a && qynr.getPublisher() == null)
邓实川 committed
215 216
			qynr.setPublisher(empNum);
		qynr.setOrganizationId(orgCode);
yuquan.zhu committed
217 218 219 220
		Long now = new Date().getTime();
		// 录入时间
		qynr.setAddeddate(now);

221
		// 发布方式:1,审核通过后立即发布,2定时发布,3手动发布,4立即发布
yuquan.zhu committed
222 223 224 225 226 227
		Integer fbfs = qynr.getReleasetype();
		// 定时
		if (fbfs != null && fbfs == 2) {
			qynr.setReleasetime(qynr.getReleasetime());
		}

邓实川 committed
228 229
		qynr.setPublisherName(YgglMainEmp.builder().build().selectOne(new LambdaQueryWrapper<YgglMainEmp>()
				.eq(YgglMainEmp::getOrgCode, orgCode).eq(YgglMainEmp::getEmpNum, empNum)).getName());
yuquan.zhu committed
230 231
		qynr.setReleasetype(fbfs);
		qynr.setStatus(0);
232 233 234 235 236
		if(fbfs != null && fbfs == 4){
			qynr.setReleasestate(0);
			qynr.setStatus(1);
			qynr.setReleasetime(now.toString());
		}
yuquan.zhu committed
237
		qynr.insertOrUpdate();
238 239 240 241 242 243 244 245 246 247 248 249
		// 新增 文件传阅 人员数据
		if(a){
			if(!CollectionUtils.isEmpty(cmsContentDto.getCmsContentReads())){
				for (CmsContentRead entity :cmsContentDto.getCmsContentReads() ) {
					entity.setCmsContentId(qynr.getId());
					entity.setOrgCode(orgCode);
					entity.setReadStatus(0);
					entity.setDeleteFlag(0);
					entity.insert();
				}
			}
		}
yuquan.zhu committed
250

251 252 253 254
		if (a){
			String msg = fbfs==4?"提交成功":"提交成功、等待管理员审核";
			return ResultUtil.data(qynr, msg);
		} else {
yuquan.zhu committed
255
			return ResultUtil.data(qynr, "修改成功");
256
		}
yuquan.zhu committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
	}

	/**
	 * 删除企业OA讯息
	 */
	@DeleteMapping(value = "/deleteqyxx")
	@ApiOperation(value = "删除企业OA讯息", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<CmsContent> deleteqyxx(@CurrentUser UserBean userBean, @RequestBody List<CmsContent> ids) {
		if (ids != null) {
			cmsContentMapper.deleteBatchIds(ids);
			return ResultUtil.success("删除成功");
		}
		return ResultUtil.error("没这个id");

	}

	/**
	 * 审核企业OA讯息
	 */
	@PostMapping(value = "/shqyxx")
	@ApiOperation(value = "审核企业OA讯息", httpMethod = "POST", notes = "接口发布说明")
	public Result<CmsContent> shqyxx(@CurrentUser UserBean userBean, @RequestBody CmsContent qynr) {
		Long now = new Date().getTime();
邓实川 committed
280 281
		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();
yuquan.zhu committed
282

邓实川 committed
283 284
		YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda()
				.eq(YgglMainEmp::getOrgCode, orgCode).eq(YgglMainEmp::getEmpNum, empNum));
yuquan.zhu committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
		if (ygglMainEmp != null) {
			qynr.setAuditor(ygglMainEmp.getName());// 审核人
		}
		qynr.setAudittime(now.toString());// 审核时间
		qynr.setAuditopinion(qynr.getAuditopinion());// 审核意见

		// 如果通过审核
		if (qynr.getStatus() == 1) {
			if (qynr.getReleasetype() != null && qynr.getReleasetype() == 1) { // 发布方式为审核通过立即发布,设置发布时间为now
				qynr.setReleasetime(now.toString());
				// 已发布
				qynr.setReleasestate(0);
			} else if (qynr.getReleasetype() == 2) { // 定时发布

				QueryWrapper<CmsContent> q = new QueryWrapper<CmsContent>();
				q.select("id", "releasetime").eq("id", qynr.getId());
				CmsContent c = CmsContent.builder().build().selectOne(q);

				// 发布时间
				Long fbsj = Long.parseLong(c.getReleasetime());
				Date date = DateUtil.date(fbsj);
				// 设置为定时发布中
				qynr.setReleasestate(3);
				qynr.updateById();
				// 设置开始定时发布
				Long deley = fbsj - now;
				if (deley >= 0) {
					Timer timer = new Timer();
					timer.schedule(new TimerTask() {
						@Override
						public void run() {
							qynr.setReleasestate(0);
							qynr.updateById();
							timer.cancel();
						}
					}, date);
				} else {
					qynr.setReleasestate(0);
				}

			} else if (qynr.getReleasetype() == 3) { // 手动发布
				// 未发布
				qynr.setReleasestate(1);
			}

		}
		qynr.updateById();
		return ResultUtil.data(qynr, "审核完成");
	}

	/**
	 * 企业OA讯息查询
	 */
	@PostMapping(value = "/qyxxquery")
	@ApiOperation(value = "搜索OA讯息记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> qyxxquery(@CurrentUser UserBean userBean, @RequestBody QyxxQueryDto qyxxQueryDto) {
ilal committed
341 342 343 344 345 346 347 348 349 350
		String s = qyxxQueryDto.getStartTime();
		String e = qyxxQueryDto.getEndTime();
		Integer t = qyxxQueryDto.getModularid();
		Integer r = qyxxQueryDto.getReleasestate();
		String q = qyxxQueryDto.getQuery();

		Page<CmsContent> page = new Page<CmsContent>(
				qyxxQueryDto.getCurrentPage() == null ? 1 : qyxxQueryDto.getCurrentPage(),
				qyxxQueryDto.getTotalPage() == null ? 10 : qyxxQueryDto.getTotalPage());

351
		MPJQueryWrapper<CmsContent> queryWrapper = new MPJQueryWrapper<>();
352
		queryWrapper.selectAll(CmsContent.class)
353 354 355 356 357
				.leftJoin("cms_content_read ccr on t.id = ccr.cms_content_id");
		queryWrapper.and(!StringUtils.isEmpty(userBean.getEmpNum()), wq -> wq.eq("t.open_status", 1).or(true,sq -> sq.eq("t.open_status", 0).eq("ccr.user_id",userBean.getEmpNum())));
		queryWrapper.eq("t.organization_id", userBean.getOrgCode()).eq("t.status", 1).eq("t.releasestate", 0)
				.eq(t != null && t > -1, "t.modularid", t).eq(r != null && r > -1, "t.releasestate", r)
				.between(!StrUtil.hasBlank(s) && !StrUtil.hasBlank(e), "t.releasetime",
ilal committed
358 359
						!StrUtil.hasBlank(s) ? s : "1000-01-01 00:00:00",
						!StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
360 361 362
				.and(!StrUtil.hasBlank(q), wq -> wq.like("t.userid", q).or().like("t.author", q).or().like("title", q))
				.groupBy("t.id")
				.orderByDesc("t.addeddate");
ilal committed
363 364 365 366 367 368 369 370
		IPage<CmsContent> cmsContentPage = CmsContent.builder().build().selectPage(page, queryWrapper);
		List<CmsContent> cmsContents = cmsContentPage.getRecords();
		cmsContentPage.getCurrent();
		cmsContentPage.getPages();
		cmsContentPage.getTotal();
		cmsContentPage.getSize();
		return ResultUtil.data(cmsContentPage, cmsContents, "企业OA讯息搜索成功");
	}
翁国栋 committed
371

ilal committed
372 373 374 375 376 377
	/**
	 * 企业OA讯息查询
	 */
	@PostMapping(value = "/oaalllist")
	@ApiOperation(value = "搜索OA讯息记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> oaAllList(@CurrentUser UserBean userBean, @RequestBody QyxxQueryDto qyxxQueryDto) {
yuquan.zhu committed
378 379 380 381 382 383 384 385 386 387 388
		String s = qyxxQueryDto.getStartTime();
		String e = qyxxQueryDto.getEndTime();
		Integer t = qyxxQueryDto.getModularid();
		Integer r = qyxxQueryDto.getReleasestate();
		String q = qyxxQueryDto.getQuery();

		Page<CmsContent> page = new Page<CmsContent>(
				qyxxQueryDto.getCurrentPage() == null ? 1 : qyxxQueryDto.getCurrentPage(),
				qyxxQueryDto.getTotalPage() == null ? 10 : qyxxQueryDto.getTotalPage());

		QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
ilal committed
389
		queryWrapper.eq("organization_id", userBean.getOrgCode())
390 391
				.eq(t != null && t > -1, "modularid", t).eq(r != null && r > -1, "releasestate", r)
				.between(!StrUtil.hasBlank(s) && !StrUtil.hasBlank(e), "releasetime",
yuquan.zhu committed
392 393
						!StrUtil.hasBlank(s) ? s : "1000-01-01 00:00:00",
						!StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
394 395
				.and(!StrUtil.hasBlank(q), wq -> wq.like("userid", q).or().like("author", q).or().like("title", q))
				.orderByDesc("addeddate");
yuquan.zhu committed
396 397 398 399 400 401 402 403 404 405 406
		IPage<CmsContent> cmsContentPage = CmsContent.builder().build().selectPage(page, queryWrapper);
		List<CmsContent> cmsContents = cmsContentPage.getRecords();
		cmsContentPage.getCurrent();
		cmsContentPage.getPages();
		cmsContentPage.getTotal();
		cmsContentPage.getSize();
		return ResultUtil.data(cmsContentPage, cmsContents, "企业OA讯息搜索成功");
	}

	/**
	 * 根据id查讯息
翁国栋 committed
407
	 *
yuquan.zhu committed
408 409 410 411 412 413 414 415 416
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/returnpath")
	@ApiOperation(value = "根据id查讯息", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> returnPath(@CurrentUser UserBean userBean, @RequestParam Integer id) {
		QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", id);
		CmsContent cmsContent = CmsContent.builder().build().selectOne(queryWrapper);
ilal committed
417 418 419 420
//		String[] f = null;
//		if (cmsContent != null && cmsContent.getFilepath() != null) {
//			f = cmsContent.getFilepath().split(",");
//		}
yuquan.zhu committed
421 422
		CmsContentDto cmsContentDto = new CmsContentDto();
		BeanUtil.copyProperties(cmsContent, cmsContentDto);
ilal committed
423
//		cmsContentDto.setFilepath(f);
yuquan.zhu committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
		return ResultUtil.data(cmsContentDto);
	}

	/**
	 * OA审核讯息查询搜索
	 */
	@PostMapping(value = "/shxxquery")
	@ApiOperation(value = "搜索OA讯息审核记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> shxxquery(@CurrentUser UserBean userBean, @RequestBody QyxxQueryDto qyxxQueryDto) {
		String s = qyxxQueryDto.getStartTime();
		String e = qyxxQueryDto.getEndTime();
		Integer t = qyxxQueryDto.getModularid();
		String q = qyxxQueryDto.getQuery();
		// 分页
		Page<CmsContent> page = new Page<CmsContent>(
				qyxxQueryDto.getCurrentPage() == null ? 1 : qyxxQueryDto.getCurrentPage(),
				qyxxQueryDto.getTotalPage() == null ? 10 : qyxxQueryDto.getTotalPage());
		// 查询条件
		QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
443
		queryWrapper.eq("organization_id", userBean.getOrgCode())
邓实川 committed
444
				.select("id", "publisher_name", "auditopinion", "modularid", "status", "title", "releasetime",
445
						"addeddate", "author", "summary", "releasetype", "fmtpath","filepath","open_status")
yuquan.zhu committed
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
				.ne("status", 1).eq(t != null && t > -1, "modularid", t)
				.between(!StrUtil.hasBlank(s) && !StrUtil.hasBlank(e), "releasetime",
						!StrUtil.hasBlank(s) ? s : "1000-01-01 00:00:00",
						!StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
				.and(!StrUtil.hasBlank(q), wq -> wq.like("userid", q).or().like("author", q).or().like("title", q))
				.orderByDesc("addeddate");
		IPage<CmsContent> CmsContentPage = CmsContent.builder().build().selectPage(page, queryWrapper);
		List<CmsContent> CmsContents = CmsContentPage.getRecords();
		CmsContentPage.getCurrent();
		CmsContentPage.getPages();
		CmsContentPage.getTotal();
		CmsContentPage.getSize();
		return ResultUtil.data(CmsContentPage, CmsContents, "企业OA讯息审核情况搜索成功");
	}

	/**
	 * 讯息发布
翁国栋 committed
463
	 *
yuquan.zhu committed
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
	 * @param id
	 */
	@GetMapping(value = "/qyxxsdfb/{id}")
	@ApiOperation(value = "OA讯息手动发布", httpMethod = "GET", notes = "接口发布说明")
	public Result<Void> qyxxsdfb(@CurrentUser UserBean userBean, @PathVariable Integer id) {
		// 根据id将状态设为发布
		CmsContent q = new CmsContent();
		UpdateWrapper<CmsContent> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("id", id);
		Long now = new Date().getTime();// 时间毫秒数
		q = CmsContent.builder().organizationId(userBean.getOrgCode()).id(id).releasestate(0)
				.releasetime(now.toString()).build();
		cmsContentMapper.update(q, updateWrapper);
		return ResultUtil.success("发布成功");
	}

	/**
	 * 讯息收回
翁国栋 committed
482
	 *
yuquan.zhu committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
	 * @param id
	 */
	@GetMapping(value = "/qyxxtb/{id}")
	@ApiOperation(value = "OA讯息发布收回", httpMethod = "GET", notes = "接口发布说明")
	public Result<Void> takeBack(@CurrentUser UserBean userBean, @PathVariable Integer id) {
		// 根据id将状态设为收回
		CmsContent q = new CmsContent();
		UpdateWrapper<CmsContent> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("id", id);
		Date now = new Date();
		q = CmsContent.builder().organizationId(userBean.getOrgCode()).id(id).releasestate(2)
				.takeBack(userBean.getEmpNum()).takeBackTime(now.toString()).build();
		cmsContentMapper.update(q, updateWrapper);
		return ResultUtil.success("收回成功");
	}

	/**
	 * 添加已读
翁国栋 committed
501
	 *
yuquan.zhu committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
	 * @param userBean
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/isread")
	@ApiOperation(value = "添加已读人", httpMethod = "GET", notes = "接口发布说明")
	public Result<Void> isRead(@CurrentUser UserBean userBean, Integer mid) {
		Integer empNum = userBean.getEmpNum();

		QueryWrapper<CmsIsRead> q = new QueryWrapper<CmsIsRead>();
		q.eq("mid", mid).eq("uid", empNum);

		CmsIsRead cmsIsRead = CmsIsRead.builder().build().selectOne(q);
		if (!q.equals(null)) {
			cmsIsRead.setMid(mid);
			cmsIsRead.setUid(empNum);
			cmsIsRead.setReadTime(new Date());
			cmsIsRead.insert();
			return ResultUtil.success("添加成功");
		}
		return ResultUtil.success("已存在");
	}

	/**
	 * 查询已读人
翁国栋 committed
527
	 *
yuquan.zhu committed
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
	 * @param userBean
	 * @param mid
	 * @return
	 */
	@PostMapping(value = "/qisread")
	@ApiOperation(value = "查询讯息已读人", httpMethod = "POST", notes = "接口发布说明")
	public Result<QyxxIsReadDto> queryIsRead(@CurrentUser UserBean userBean, @RequestBody Integer mid) {
		QyxxIsReadDto q = cmsIsReadMapper.queryIsReadEmp(userBean.getOrgCode(), mid);
		return ResultUtil.data(q, "查询成功");
	}

	/******************* 以下轮播信息 ************************/

	/**
	 * 新增/修改轮播信息
	 */
	@PostMapping(value = "/addCarousel")
	@ApiOperation(value = "新增轮播信息", httpMethod = "POST", notes = "接口发布说明")
	public Result<CmsAnnouncement> addCarousel(@CurrentUser UserBean userBean,
			@RequestBody CmsAnnouncement cmsAnnouncement) {
		cmsAnnouncement.setFbrid(userBean.getEmpNum());
		cmsAnnouncement.setFbtime(new Date());
		cmsAnnouncement.setOrgCode(userBean.getOrgCode());
		cmsAnnouncement.insertOrUpdate();
		return ResultUtil.data(cmsAnnouncement, "新增/修改成功");
	}

	/**
	 * 删除轮播信息
	 */
	@DeleteMapping(value = "/delCarousel/{id}")
	@ApiOperation(value = "删除轮播信息", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Object> delCarousel(@CurrentUser UserBean userBean, @PathVariable Integer id) {
		Integer orgCode = userBean.getOrgCode();
		return ResultUtil.data(CmsAnnouncement.builder().build()
				.delete(new QueryWrapper<CmsAnnouncement>().eq("org_code", orgCode).eq("id", id)), "删除成功");
	}

	/**
	 * 查询轮播信息列表
	 */
	@PostMapping(value = "/queryCarousel")
	@ApiOperation(value = "查询轮播信息", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> delCarousel(@CurrentUser UserBean userBean, @RequestBody QyxxQueryDto qyxxQueryDto) {
		String s = qyxxQueryDto.getStartTime();
		String e = qyxxQueryDto.getEndTime();
		String q = qyxxQueryDto.getQuery();
		Page<CmsAnnouncement> page = new Page<CmsAnnouncement>(
				qyxxQueryDto.getCurrentPage() == null ? 1 : qyxxQueryDto.getCurrentPage(),
				qyxxQueryDto.getTotalPage() == null ? 10 : qyxxQueryDto.getTotalPage());
		QueryWrapper<CmsAnnouncement> queryWrapper = new QueryWrapper<>();
579
		queryWrapper.eq("org_code", userBean.getOrgCode());
yuquan.zhu committed
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
		queryWrapper.between(!StrUtil.hasBlank(s) && !StrUtil.hasBlank(e), "fbtime",
				!StrUtil.hasBlank(s) ? s : "1000-01-01 00:00:00", !StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
				.and(!StrUtil.hasBlank(q), wq -> wq.like("title", q).or().like("fbnr", q)).orderByDesc("fbtime");

		IPage<CmsAnnouncement> cmsAnnouncementPage = CmsAnnouncement.builder().build().selectPage(page, queryWrapper);
		List<CmsAnnouncement> cmsAnnouncements = cmsAnnouncementPage.getRecords();
		cmsAnnouncementPage.getCurrent();
		cmsAnnouncementPage.getPages();
		cmsAnnouncementPage.getTotal();
		cmsAnnouncementPage.getSize();
		return ResultUtil.data(cmsAnnouncementPage, cmsAnnouncements, "查询成功");
	}

	/**
	 * 查询默认轮播信息
	 */
	@GetMapping(value = "/defaultCarousel")
597
	@ApiOperation(value = "查询轮播信息(默认)", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
598 599
	public Result<Object> defaultCarousel(@CurrentUser UserBean userBean) {
		return ResultUtil.data(
600 601
				CmsAnnouncement.builder().build().selectOne(
						new QueryWrapper<CmsAnnouncement>().eq("is_default", 1).eq("org_code", userBean.getOrgCode())),
yuquan.zhu committed
602 603 604 605 606 607 608 609 610 611
				"查询成功");
	}

	/**
	 * 设置默认
	 */
	@GetMapping(value = "/default/{id}")
	@ApiOperation(value = "设置默认轮播信息", httpMethod = "GET", notes = "接口发布说明")
	public Result<Void> setDefault(@CurrentUser UserBean userBean, @PathVariable("id") Integer id) {
		// 将所有设为非默认
邓实川 committed
612 613
		boolean cmsAnnouncement = CmsAnnouncement.builder().isDefault(0).build().update(
				new LambdaQueryWrapper<CmsAnnouncement>().eq(CmsAnnouncement::getOrgCode, userBean.getOrgCode()));
yuquan.zhu committed
614
		// 根据id设为默认
邓实川 committed
615 616 617 618 619 620 621
		if (cmsAnnouncement) {
			if (CmsAnnouncement.builder().id(id).isDefault(1).build().updateById())
				return ResultUtil.success("设置成功");
			else
				return ResultUtil.success("设置失败");
		}
		return ResultUtil.success("设置失败");
yuquan.zhu committed
622 623
	}

624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
	/**
	 * 查询传阅列表
	 * @return
	 */
	@PostMapping(value = "/getCmsContentReads")
	@ApiOperation(value = "查询传阅列表", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> getCmsContentReads(@CurrentUser UserBean userBean, @RequestBody CmsContentReadDto cmsContentReadDto) {
		Page<CmsContentRead> page = new Page<CmsContentRead>(cmsContentReadDto.getCurrentPage(), cmsContentReadDto.getTotalPage());
		//查询传阅列表
		IPage<CmsContentRead> cmsContentReads = CmsContentRead.builder().build()
				.selectPage(page, new QueryWrapper<CmsContentRead>()
				.lambda().eq(CmsContentRead::getCmsContentId, cmsContentReadDto.getCmsContentId()).orderByDesc(CmsContentRead::getReviewTime));

		return ResultUtil.data(cmsContentReads);
	}

	/**
	 * 标记已阅
	 */
	@GetMapping(value = "/haveRead/{id}")
	@ApiOperation(value = "标记已阅", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> haveRead(@CurrentUser UserBean userBean, @PathVariable("id") Integer id) {
		//用户id查询传阅消息
		CmsContentRead cmsContentRead = CmsContentRead.builder().build()
				.selectOne(new QueryWrapper<CmsContentRead>().lambda()
						.eq(CmsContentRead::getUserId, userBean.getEmpNum())
						.eq(CmsContentRead::getOrgCode, userBean.getOrgCode())
						.eq(CmsContentRead::getCmsContentId,id));

		if(cmsContentRead == null){
			cmsContentRead = new CmsContentRead();
			cmsContentRead.setUserId(userBean.getEmpNum());
			cmsContentRead.setUserName(userBean.getUserInfo().getName());
			cmsContentRead.setOrgCode(userBean.getOrgCode());
			cmsContentRead.setCmsContentId(id);
		}else {
			//已阅 直接返回
			if(cmsContentRead.getReadStatus() == 1){
				return ResultUtil.data(1);
			}
		}

		try {
			cmsContentRead.setReadStatus(1);
			cmsContentRead.setReviewTime(new Date());
			cmsContentRead.insertOrUpdate();
		}catch (Exception e){
			log.error("=============已阅操作失败, " + e);
			return ResultUtil.error(e);
		}
		return ResultUtil.success();
	}

	/**
	 * 根据讯息id查传阅列表
	 * @return
	 */
	@PostMapping(value = "/comment")
	@ApiOperation(value = "评论意见反馈", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> comment(@CurrentUser UserBean userBean, @RequestBody CmsContentReadDto cmsContentReadDto) {
		//用户id查询传阅消息
		CmsContentRead cmsContentRead = CmsContentRead.builder().build()
				.selectOne(new QueryWrapper<CmsContentRead>().lambda()
						.eq(CmsContentRead::getUserId, userBean.getEmpNum())
						.eq(CmsContentRead::getOrgCode, userBean.getOrgCode())
						.eq(CmsContentRead::getCmsContentId,cmsContentReadDto.getCmsContentId()));
		try {
			cmsContentRead.setReviewContent(cmsContentReadDto.getReviewContent());
			cmsContentRead.insertOrUpdate();
		}catch (Exception e){
			log.error("=============评论失败, " + e);
			return ResultUtil.error(e);
		}
		return ResultUtil.success();
	}

	/**
	 * 添加传阅人员
	 * @return
	 */
	@PostMapping(value = "/addReadPersonnel")
	@ApiOperation(value = "添加传阅人员", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> addReadPersonnel(@CurrentUser UserBean userBean, @RequestBody List<CmsContentRead> cmsContentReads) {
		for (CmsContentRead ccr:cmsContentReads
			 ) {
			ccr.insert();
		}
		return ResultUtil.success();
	}


yuquan.zhu committed
715
}