package com.panzhihua.westcommittee.api;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.panzhihua.common.controller.BaseController;
|
import com.panzhihua.common.exceptions.ServiceException;
|
import com.panzhihua.common.model.vos.LoginUserInfoVO;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.west.SystemUserVo;
|
import com.panzhihua.westcommittee.annotation.DistributedLock;
|
import com.panzhihua.westcommittee.annotation.SysLog;
|
import com.panzhihua.westcommittee.model.dto.*;
|
import com.panzhihua.westcommittee.model.entity.Complaint;
|
import com.panzhihua.westcommittee.model.entity.ComplaintComment;
|
import com.panzhihua.westcommittee.model.entity.Department;
|
import com.panzhihua.westcommittee.model.entity.SystemUser;
|
import com.panzhihua.westcommittee.model.vo.ComplaintVO;
|
import com.panzhihua.westcommittee.model.vo.DispatchVO;
|
import com.panzhihua.westcommittee.service.IComplaintCommentService;
|
import com.panzhihua.westcommittee.service.IComplaintService;
|
import com.panzhihua.westcommittee.service.IDepartmentService;
|
import com.panzhihua.westcommittee.service.ISystemUserService;
|
import com.panzhihua.westcommittee.warpper.MgtComplaintQuery;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.io.IOException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import static cn.hutool.core.util.ObjectUtil.isNull;
|
|
/**
|
* @author mitao
|
* @date 2025/3/14
|
*/
|
@Api(tags = {"西区纪委后台-诉求管理"})
|
@RequestMapping("/complaint")
|
@RestController
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
public class MgtComplaintController extends BaseController {
|
private final IComplaintService complaintService;
|
private final ISystemUserService systemUserService;
|
private final IDepartmentService departmentService;
|
private final IComplaintCommentService complaintCommentService;
|
|
@PostMapping("/save")
|
@ApiOperation(value = "录入诉求")
|
@DistributedLock(lockName = "complaint_serial_number_lock")
|
public R<?> save(@Valid @RequestBody Complaint complaint) {
|
complaintService.saveComplaintAdmin(complaint, getLoginUserInfoWest());
|
return R.ok();
|
}
|
|
@GetMapping("/getAllocationList")
|
@ApiOperation(value = "获取分配派单位列表")
|
public R<List<DispatchVO>> getAllocationList() {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
SystemUser systemUser = systemUserService.getById(loginUserInfoWest.getId());
|
if(systemUser.getSystemRoleId()!=1){
|
return R.fail("非管理员,无权限");
|
}
|
List<DispatchVO> dispatchVOList = new ArrayList<>();
|
Integer oneDepartmentId = systemUser.getOneDepartmentId();
|
Department byId = departmentService.getById(oneDepartmentId);
|
LambdaQueryWrapper<Department> eq = new LambdaQueryWrapper<Department>().eq(Department::getTier, byId.getTier());
|
|
if(byId.getTier()==2){
|
eq.eq(Department::getDistrictsCode, byId.getDistrictsCode());
|
}
|
if(byId.getTier()==3){
|
eq.eq(Department::getStreetId, byId.getStreetId());
|
}
|
if(byId.getTier()==4){
|
eq.eq(Department::getCommunityId, byId.getCommunityId());
|
}
|
|
List<Department> list1 = departmentService.list(eq);
|
for (Department department : list1) {
|
DispatchVO dispatchVO = new DispatchVO();
|
dispatchVO.setId(department.getId().toString());
|
dispatchVO.setName(department.getName());
|
dispatchVOList.add(dispatchVO);
|
}
|
return R.ok(dispatchVOList);
|
}
|
|
|
|
@PostMapping("/assignComplain")
|
@ApiOperation(value = "分配诉求")
|
public R<?> assignComplain(@Valid@RequestBody AssignComplainDto dto) {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
complaintService.assignComplain(loginUserInfoVO,dto.getComplainId(),dto.getDeptId(),dto.getRemark(),dto.getProblemType());
|
return R.ok();
|
}
|
|
|
|
@ApiOperation("诉求列表")
|
@PostMapping("/page")
|
public R<Page<ComplaintVO>> pageList(@RequestBody MgtComplaintQuery query) {
|
SystemUserVo loginUserInfo = getLoginUserInfoWest();
|
return R.ok(complaintService.pageList(query,loginUserInfo));
|
}
|
|
|
|
|
// @ApiOperation("诉求详情")
|
// @GetMapping("/detail/{id}")
|
// public R<ComplaintVO> detail(@ApiParam(name = "id", value = "诉求id", required = true) @PathVariable("id") Long id) {
|
// return R.ok(complaintService.getDetailMgt(id));
|
// }
|
@ApiOperation("导出")
|
@PostMapping("/export")
|
@SysLog(operatorCategory = "诉求导出",operId = 9)
|
public void export(@RequestBody MgtComplaintQuery query) {
|
SystemUserVo loginUserInfo = getLoginUserInfoWest();
|
try {
|
complaintService.export(query,loginUserInfo);
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
|
|
@PostMapping("/update-progress")
|
@ApiOperation("办理进度修改2.0.1")
|
public R<?> updateProgress(@Valid @RequestBody ComplaintProcessUpdateDto dto) {
|
complaintService.updateProgress(dto);
|
return R.ok();
|
}
|
|
@DeleteMapping("del-progress/{id}")
|
@ApiOperation("办理进度删除2.0.1")
|
public R<?> delProgress(@ApiParam(name = "id", value = "办理进度id", required = true) @PathVariable("id") Long id) {
|
complaintService.delProgress(id);
|
return R.ok();
|
}
|
|
|
@ApiOperation("社区问题单、问题处理单、协调通知单 下载")
|
@GetMapping("/download-file/{id}/{type}")
|
@SysLog(operatorCategory = "单导出",operId = 10)
|
public R<?> communityProblem(@ApiParam(name = "id", value = "诉求id", required = true) @PathVariable("id") Long id,
|
@ApiParam(name = "type", value = "类型:1:社区问题单 2:问题处理单 3:协调通知单", required = true) @PathVariable("type") Integer type) {
|
try {
|
String name = complaintService.downloadFile(id, type, getLoginUserInfoWest());
|
return R.ok(name);
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
|
@ApiOperation("诉求详情")
|
@GetMapping("/detail/{id}")
|
public R<ComplaintVO> detail(@PathVariable("id") Long id) {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
return R.ok(complaintService.detail(id,loginUserInfoVO));
|
}
|
|
|
@PostMapping("/save-process")
|
@ApiOperation("办理进度录入")
|
public R<?> saveProcess(@Valid @RequestBody ComplaintProcessDTO dto){
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
complaintService.saveProcess(dto,loginUserInfoVO);
|
return R.ok();
|
}
|
|
@PostMapping("/save-result")
|
@ApiOperation("办理结果录入")
|
public R<?> saveResult(@RequestBody ComplaintCompletionDTO dto){
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
complaintService.saveResult(dto,loginUserInfoVO);
|
return R.ok();
|
}
|
|
|
/**
|
* 问题上报
|
*/
|
@PostMapping("/report")
|
@ApiOperation(value = "问题上报")
|
public R<?> report(@RequestBody ComplaintReportDTO complaintReportDTO) {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
complaintService.saveReport(complaintReportDTO, loginUserInfoVO);
|
return R.ok();
|
}
|
|
|
/**
|
* 延期申请
|
*/
|
@PostMapping("/saveDelay")
|
@ApiOperation(value = "延期申请")
|
public R<?> saveDelay(@Valid @RequestBody ComplaintDelayDTO dto){
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
complaintService.saveDelay(dto, loginUserInfoVO);
|
return R.ok();
|
}
|
|
/**
|
* 延期审核
|
*/
|
@PostMapping("/delayAudit")
|
@ApiOperation(value = "延期审核")
|
public R<?> delayAudit(@RequestBody ComplaintDelayAuditDTO dto) {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
complaintService.delayAudit(dto, loginUserInfoVO);
|
return R.ok();
|
}
|
|
/**
|
* 上报审核
|
*/
|
@PostMapping("/reportAudit")
|
@ApiOperation(value = "问题上报审核并指派")
|
public R<?> reportAudit(@RequestBody ComplaintReporAuditDTO dto) {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
complaintService.reportAudit(dto, loginUserInfoVO);
|
return R.ok();
|
}
|
|
|
@PostMapping("/setProblemType")
|
@ApiOperation(value = "分配问题类型")
|
public R<?> assignComplain(@Valid @RequestBody SetProblemTypeDto dto) {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
// 判断是否管理员
|
complaintService.setProblemType(loginUserInfoVO,dto);
|
return R.ok();
|
}
|
|
|
/**
|
* 评价诉求
|
* @param complaintComment
|
* @return
|
*/
|
@PostMapping("/commentComplaint")
|
@ApiOperation(value = "评价诉求")
|
public R<?> commentComplaint(@RequestBody ComplaintComment complaintComment){
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
int count = complaintCommentService.count(new LambdaQueryWrapper<ComplaintComment>().eq(ComplaintComment::getComplaintId, complaintComment.getComplaintId())
|
.eq(ComplaintComment::getDelFlag, 0));
|
if(0 != count){
|
return R.fail("不能重复评价");
|
}
|
Long userId = loginUserInfoVO.getUserId();
|
complaintComment.setUserId(userId);
|
complaintComment.setCreateTime(new Date());
|
complaintComment.setCreateBy(userId);
|
complaintComment.setUpdateBy(userId);
|
complaintComment.setUpdateTime(new Date());
|
complaintComment.setDelFlag(0);
|
complaintCommentService.save(complaintComment);
|
Complaint complaint = complaintService.getById(complaintComment.getComplaintId());
|
complaint.setStatus(8);
|
complaint.setCommentRate(complaintComment.getRate());
|
complaintService.updateById(complaint);
|
// 不满意 重新生成诉求
|
if(complaintComment.getRate()==0){
|
// 获取当前日期(年月日)
|
String datePrefix = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
|
// 查询当前日期的最大流水号
|
Complaint lastComplaint = complaintService.getOne(new LambdaQueryWrapper<Complaint>()
|
.likeRight(Complaint::getSerialNumber, datePrefix) // 查询以当前日期开头的流水号
|
.orderByDesc(Complaint::getSerialNumber)
|
.last("limit 1"));
|
|
String serialNumber;
|
if (isNull(lastComplaint)) {
|
// 如果当天没有记录,从 0001 开始
|
serialNumber = datePrefix + "0001";
|
} else {
|
// 获取当前日期的最大流水号,并递增
|
String lastSerialNumber = lastComplaint.getSerialNumber();
|
int num = Integer.parseInt(lastSerialNumber.substring(lastSerialNumber.length() - 4)); // 提取后4位数字
|
serialNumber = datePrefix + String.format("%04d", num + 1); // 递增并格式化为4位
|
}
|
Complaint complaint1 = new Complaint();
|
BeanUtils.copyProperties(complaint,complaint1);
|
complaint1.setStatus(0);
|
complaint1.setSerialNumber(serialNumber);
|
complaint1.setAssignStatus(0);
|
complaint1.setCreateTime(new Date());
|
complaint1.setId(null);
|
complaint1.setCompletionTime(null);
|
complaint1.setCompletionUserId(null);
|
complaint1.setCompletionUsername(null);
|
complaint1.setCompletionUserPhone(null);
|
complaint1.setCompletionImages(null);
|
complaint1.setCompletionUserLevel(null);
|
complaint1.setCompletionDescription(null);
|
complaint1.setCompletionVideos(null);
|
complaint1.setCompletionOtherDescription(null);
|
complaint1.setRemark(null);
|
complaint1.setNowLevelTime(new Date());
|
complaint1.setNowLevelSms(0);
|
complaint1.setRedispatch(1);
|
complaintService.save(complaint1);
|
}
|
|
return R.ok();
|
}
|
|
|
/**
|
* 上报撤回
|
*/
|
@PostMapping("/revoke")
|
@ApiOperation(value = "诉求上报撤回")
|
public R<?> reportWithdraw(@RequestBody ComplaintReportWithdrawDTO dto) {
|
SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
|
LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
|
loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
|
loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
|
complaintService.reportWithdraw(dto, loginUserInfoVO);
|
return R.ok();
|
}
|
|
|
}
|