/** * Copyright 2018 人人开源 https://www.renren.io *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AddGroup; import com.epmet.commons.tools.validator.group.DefaultGroup; import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.dto.UserAdviceDTO; import com.epmet.dto.form.AdviceListFormDTO; import com.epmet.dto.form.MyAdviceListFormDTO; import com.epmet.dto.form.ReplyAdviceFormDTO; import com.epmet.dto.form.SubmitAdviceFormDTO; import com.epmet.dto.result.AdviceDetailResultDTO; import com.epmet.dto.result.AdviceListResultDTO; import com.epmet.dto.result.MyAdviceListResultDTO; import com.epmet.excel.UserAdviceExcel; import com.epmet.service.UserAdviceService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; /** * user_advice * * @author qu qu@elink-cn.com * @since v1.0.0 2020-11-06 */ @RestController @RequestMapping("useradvice") public class UserAdviceController { @Autowired private UserAdviceService userAdviceService; @Autowired private LoginUserUtil loginUserUtil; @GetMapping("page") public Result> page(@RequestParam Map params) { PageData page = userAdviceService.page(params); return new Result>().ok(page); } @GetMapping("{id}") public Result get(@PathVariable("id") String id) { UserAdviceDTO data = userAdviceService.get(id); return new Result().ok(data); } @PostMapping public Result save(@RequestBody UserAdviceDTO dto) { //效验数据 ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); userAdviceService.save(dto); return new Result(); } @PutMapping public Result update(@RequestBody UserAdviceDTO dto) { //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); userAdviceService.update(dto); return new Result(); } @DeleteMapping public Result delete(@RequestBody String[] ids) { //效验数据 AssertUtils.isArrayEmpty(ids, "id"); userAdviceService.delete(ids); return new Result(); } @GetMapping("export") public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { List list = userAdviceService.list(params); ExcelUtils.exportExcelToTarget(response, null, list, UserAdviceExcel.class); } /** * @Description 运营-回复建议 * @param dto * @return com.epmet.commons.tools.utils.Result * @Author liushaowen * @Date 2020/11/10 9:34 */ @PostMapping("replyadvice") public Result replyAdvice(@RequestBody ReplyAdviceFormDTO dto) { ValidatorUtils.validateEntity(dto); userAdviceService.replyAdvice(dto, loginUserUtil.getLoginUserId()); return new Result(); } /** * @Description 运营端-建议详情 * @param map * @return com.epmet.commons.tools.utils.Result * @Author liushaowen * @Date 2020/11/10 9:33 */ @PostMapping("advicedetail") public Result adviceDetail(@RequestBody Map map) { String adviceId = map.get("adviceId"); if (StringUtils.isBlank(adviceId)) { throw new RenException("adviceId不能为空"); } return new Result().ok(userAdviceService.adviceDetail(adviceId)); } /** * @Description 运营端-建议列表 * @param dto * @return com.epmet.commons.tools.utils.Result> * @Author liushaowen * @Date 2020/11/10 9:32 */ @PostMapping("advicelist") public Result> adviceList(@LoginUser TokenDto tokenDto, @RequestBody AdviceListFormDTO dto) { if (AppClientConstant.APP_GOV.equals(tokenDto.getApp())) { //工作端调用,校验参数 ValidatorUtils.validateEntity(dto, AdviceListFormDTO.WorkPcGroup.class); } //校验时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())){ try { Date start = sdf.parse(dto.getStartTime()); Date end = sdf.parse(dto.getEndTime()); if (start.after(end)){ throw new RenException("开始时间不能大于结束时间"); } }catch (ParseException e){ throw new RenException("日期转换失败"); } } PageData page = userAdviceService.adviceList(dto); return new Result>().ok(page); } /** * @Description 居民端-我的建议列表 * @param dto * @return com.epmet.commons.tools.utils.Result> * @Author liushaowen * @Date 2020/11/9 17:35 */ @PostMapping("myadvicelist") public Result> myAdviceList(@RequestBody MyAdviceListFormDTO dto) { return new Result>().ok(userAdviceService.myAdviceList(dto.getPageSize(),dto.getPageNo(),loginUserUtil.getLoginUserId())); } @PostMapping("submitadvice") public Result submitAdvice(@RequestBody SubmitAdviceFormDTO dto){ ValidatorUtils.validateEntity(dto); if (StringUtils.isBlank(dto.getPhone())) { dto.setPhone("*"); } userAdviceService.submitAdvice(dto,loginUserUtil.getLoginUserId()); return new Result(); } }