CmsController.java 31.7 KB
Newer Older
1 2 3 4 5
package cn.timer.api.controller.qyxx;

import java.util.*;

import cn.timer.api.bean.qyxx.*;
6
import cn.timer.api.bean.qyzx.QyzxEmpEntAsso;
7
import cn.timer.api.dto.qyxx.CmsContentReadDto;
8
import cn.timer.api.utils.redis.RedisUtil;
9 10 11
import com.github.yulichang.query.MPJQueryWrapper;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
12 13
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.data.redis.core.RedisTemplate;
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
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;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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;

import javax.annotation.Resource;

@RestController
@Api(tags = "5.0企业讯息")
@Transactional
55
@RequestMapping(value = "/qyxx", produces = {"application/json"})
56 57 58 59 60 61 62 63 64
@Slf4j
public class CmsController {

	@Autowired
	private CmsContentMapper cmsContentMapper;

	@Autowired
	private CmsIsReadMapper cmsIsReadMapper;

65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
//	@Autowired
//	private CmsAnnouncementMapper cmsAnnouncementMapper;

	/**
	 * 查询所有讯息
	 */
	@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 = "接口发布说明")
	public Result<Object> groupbyTime(@CurrentUser UserBean userBean) {
		Map map = Maps.newHashMap();
		Integer orgCode = userBean.getOrgCode();
		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");
		List<CmsContent> qynr = CmsContent.builder().build().selectList(queryWrapper);
		/*应需求一定要展示前四张图片*/
		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, "查询分类成功!");
	}

	/**
	 * 分类,获取标题和发布时间
	 *
	 */
//	@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, "查询成功!");
//	}

	/**
	 * 分类内容获取
	 */
	@GetMapping(value = "/getType")
	@ApiOperation(value = "分类内容获取", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getType(@CurrentUser UserBean userBean) {
		// 分类模块信息
		List<CmsContentModular> list = CmsContentModular.builder().build()
				.selectList(new QueryWrapper<CmsContentModular>().eq("is_open", 0) // 是否开启
//				.eq("organization_id", userBean.getOrgCode())
				);
		List<List<CmsContent>> o = new ArrayList<List<CmsContent>>();
		for (CmsContentModular cmsContentModular : list) {
			// 分类模块id
			Integer id = cmsContentModular.getId();
			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)
171 172
							.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())))
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
					.eq("t.organization_id", userBean.getOrgCode()).eq("t.modularid", id)
					.groupBy("t.id")
					.orderByDesc("t.releasetime")
					.last("limit 5");
			List<CmsContent> qynrs = CmsContent.builder().build().selectList(queryWrapper);
			o.add(qynrs);
		}
		return ResultUtil.data(o, "查询成功!");
	}

	/**
	 * 获取分类
	 */
	@GetMapping(value = "/xxfl")
	@ApiOperation(value = "获取分类", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getxxfl(@CurrentUser UserBean userBean) {
		return ResultUtil.data(CmsContentModular.builder().build().selectList(new QueryWrapper<CmsContentModular>()
//				.eq("organization_id", userBean.getOrgCode())
				.eq("is_open", 0)
192
				.orderByAsc("sort")), "查询分类成功!");
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
	}

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

		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();

//		String str = StringUtils.join(cmsContentDto.getFilepath(), ","); // 数组转字符串(逗号分隔)(推荐)

		CmsContent qynr = new CmsContent();
		BeanUtil.copyProperties(cmsContentDto, qynr);
//		qynr.setFilepath(str);
//		Integer i = 10000;
//		qynr.setXxbh("XX" + i++);

		Boolean a = qynr.getId() == null;
214
		if (a) {
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
			qynr.setUserid(empNum);
		}
		if (a && qynr.getPublisher() == null)
			qynr.setPublisher(empNum);
		qynr.setOrganizationId(orgCode);
		Long now = new Date().getTime();
		// 录入时间
		qynr.setAddeddate(now);

		// 发布方式:1,审核通过后立即发布,2定时发布,3手动发布,4立即发布
		Integer fbfs = qynr.getReleasetype();
		// 定时
		if (fbfs != null && fbfs == 2) {
			qynr.setReleasetime(qynr.getReleasetime());
		}

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

254 255
		if (a) {
			String msg = fbfs == 4 ? "提交成功" : "提交成功、等待管理员审核";
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
			return ResultUtil.data(qynr, msg);
		} else {
			return ResultUtil.data(qynr, "修改成功");
		}
	}

	/**
	 * 删除企业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();
		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();

		YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda()
				.eq(YgglMainEmp::getOrgCode, orgCode).eq(YgglMainEmp::getEmpNum, empNum));
		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) {
		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());

		MPJQueryWrapper<CmsContent> queryWrapper = new MPJQueryWrapper<>();
		queryWrapper.selectAll(CmsContent.class)
				.leftJoin("cms_content_read ccr on t.id = ccr.cms_content_id");
357
		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())));
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
		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",
						!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("t.userid", q).or().like("t.author", q).or().like("title", q))
				.groupBy("t.id")
				.orderByDesc("t.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讯息搜索成功");
	}

	/**
	 * 企业OA讯息查询
	 */
	@PostMapping(value = "/oaalllist")
	@ApiOperation(value = "搜索OA讯息记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> oaAllList(@CurrentUser UserBean userBean, @RequestBody QyxxQueryDto qyxxQueryDto) {
		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<>();
		queryWrapper.eq("organization_id", userBean.getOrgCode())
				.eq(t != null && t > -1, "modularid", t).eq(r != null && r > -1, "releasestate", r)
				.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讯息搜索成功");
	}

408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
	@PostMapping(value = "/oaCirculate")
	@ApiOperation(value = "搜索OA文件传阅记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> oaCirculate(@CurrentUser UserBean userBean, @RequestBody QyxxQueryDto qyxxQueryDto) {
		String s = qyxxQueryDto.getStartTime();
		String e = qyxxQueryDto.getEndTime();
		Integer r = qyxxQueryDto.getReleasestate();

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

		QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("organization_id", userBean.getOrgCode())
				.eq("modularid", 7).eq(r != null && r > -1, "releasestate", r)
				.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(wq -> wq.eq("publisher", userBean.getEmpNum()).or().eq("author", userBean.getUserInfo().getName()).or().inSql("id", "select cms_content_id from cms_content_read where user_id =" + userBean.getEmpNum()))

				.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讯息搜索成功");
	}

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
	/**
	 * 根据id查讯息
	 *
	 * @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);
//		String[] f = null;
//		if (cmsContent != null && cmsContent.getFilepath() != null) {
//			f = cmsContent.getFilepath().split(",");
//		}
		CmsContentDto cmsContentDto = new CmsContentDto();
		BeanUtil.copyProperties(cmsContent, cmsContentDto);
//		cmsContentDto.setFilepath(f);
		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<>();
		queryWrapper.eq("organization_id", userBean.getOrgCode())
				.select("id", "publisher_name", "auditopinion", "modularid", "status", "title", "releasetime",
477
						"addeddate", "author", "summary", "releasetype", "fmtpath", "filepath", "open_status")
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 527 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
				.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讯息审核情况搜索成功");
	}

	/**
	 * 讯息发布
	 *
	 * @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("发布成功");
	}

	/**
	 * 讯息收回
	 *
	 * @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("收回成功");
	}

	/**
	 * 添加已读
	 *
	 * @param userBean
	 * @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("已存在");
	}

	/**
	 * 查询已读人
	 *
	 * @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,
578
											   @RequestBody CmsAnnouncement cmsAnnouncement) {
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 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
		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<>();
		queryWrapper.eq("org_code", userBean.getOrgCode());
		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")
	@ApiOperation(value = "查询轮播信息(默认)", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> defaultCarousel(@CurrentUser UserBean userBean) {
		return ResultUtil.data(
				CmsAnnouncement.builder().build().selectOne(
						new QueryWrapper<CmsAnnouncement>().eq("is_default", 1).eq("org_code", userBean.getOrgCode())),
				"查询成功");
	}

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

	/**
	 * 查询传阅列表
657
	 *
658 659 660 661 662 663 664 665 666
	 * @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>()
667
						.lambda().eq(CmsContentRead::getCmsContentId, cmsContentReadDto.getCmsContentId()).orderByDesc(CmsContentRead::getReviewTime));
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682

		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())
683
						.eq(CmsContentRead::getCmsContentId, id));
684

685
		if (cmsContentRead == null) {
686 687 688 689 690
			cmsContentRead = new CmsContentRead();
			cmsContentRead.setUserId(userBean.getEmpNum());
			cmsContentRead.setUserName(userBean.getUserInfo().getName());
			cmsContentRead.setOrgCode(userBean.getOrgCode());
			cmsContentRead.setCmsContentId(id);
691
		} else {
692
			//已阅 直接返回
693
			if (cmsContentRead.getReadStatus() == 1) {
694 695 696 697 698 699 700 701
				return ResultUtil.data(1);
			}
		}

		try {
			cmsContentRead.setReadStatus(1);
			cmsContentRead.setReviewTime(new Date());
			cmsContentRead.insertOrUpdate();
702
		} catch (Exception e) {
703 704 705 706 707 708 709 710
			log.error("=============已阅操作失败, " + e);
			return ResultUtil.error(e);
		}
		return ResultUtil.success();
	}

	/**
	 * 根据讯息id查传阅列表
711
	 *
712 713 714 715 716 717 718 719 720 721
	 * @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())
722
						.eq(CmsContentRead::getCmsContentId, cmsContentReadDto.getCmsContentId()));
723 724 725
		try {
			cmsContentRead.setReviewContent(cmsContentReadDto.getReviewContent());
			cmsContentRead.insertOrUpdate();
726
		} catch (Exception e) {
727 728 729 730 731 732 733
			log.error("=============评论失败, " + e);
			return ResultUtil.error(e);
		}
		return ResultUtil.success();
	}

	/**
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
	 * 根据讯息id查传阅增加文件
	 *
	 * @return
	 */
	@PostMapping(value = "/cmsAddFile")
	@ApiOperation(value = "文件传阅增加文件", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> cmsAddFile(@CurrentUser UserBean userBean, @RequestBody JSONObject request) {

		String cmsContentId = request.getString("cmsContentId");

		//用户id查询传阅消息
		QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", cmsContentId);
		CmsContent cmsContent = CmsContent.builder().build().selectOne(queryWrapper);
		JSONArray addjsonArray = JSONArray.fromObject(request.getString("filepathcms"));
		JSONArray resjsonArray = JSONArray.fromObject(cmsContent.getFilepath());
		resjsonArray.addAll(addjsonArray);
		cmsContent.setFilepath(resjsonArray.toString());
		cmsContentMapper.updateById(cmsContent);
		return ResultUtil.data(resjsonArray.toString());
	}

	/**
757
	 * 添加传阅人员
758
	 *
759 760 761 762 763
	 * @return
	 */
	@PostMapping(value = "/addReadPersonnel")
	@ApiOperation(value = "添加传阅人员", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> addReadPersonnel(@CurrentUser UserBean userBean, @RequestBody List<CmsContentRead> cmsContentReads) {
764 765
		for (CmsContentRead ccr : cmsContentReads
		) {
766 767 768 769 770
			ccr.insert();
		}
		return ResultUtil.success();
	}

771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
	@PostMapping(value = "/getUnreadCmsList")
	@ApiOperation(value = "获取当前用户的未读传阅列表", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> shxxquery(@CurrentUser UserBean userBean) {
		return ResultUtil.data(cmsIsReadMapper.getUnreadList(userBean.getEmpNum()));
	}

	@PostMapping(value = "/adminDeleteFile")
	@ApiOperation(value = "管理员删除附件", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> adminDeleteFile(@CurrentUser UserBean userBean, @RequestBody CmsContentReadDto cmsContentReadDto) {
		QyzxEmpEntAsso ent = QyzxEmpEntAsso.builder().build().selectOne(new QueryWrapper<QyzxEmpEntAsso>().lambda().eq(QyzxEmpEntAsso::getOrgCode, userBean.getOrgCode()).eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum()));
		if (ent.getUserType() == 2) {
			return ResultUtil.error("当前用户没有权限操作");
		}
		CmsContent cmsContent = CmsContent.builder().id(cmsContentReadDto.getId()).build().selectById();
		JSONArray resjsonArray = JSONArray.fromObject(cmsContent.getFilepath());
		/*不转为int会默认使用remove(object)*/
		resjsonArray.remove((int)cmsContentReadDto.getFileIndex());
		cmsContent.setFilepath(resjsonArray.toString());
		cmsContent.updateById();
		return ResultUtil.success("删除附件成功");
	}
792 793

}