package org.springblade.modules.workreport.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.common.utils.arg; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.modules.FTP.FtpUtil; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.service.IDeptService; import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.service.MyAsyncService; import org.springblade.modules.workreport.entity.WorkReport; import org.springblade.modules.workreport.service.WorkReportService; import org.springblade.modules.workreport.vo.WorkReportVo; import org.springframework.web.bind.annotation.*; import java.sql.Wrapper; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * @author zhongrj * @time 2021-07-12 * @desc 工作汇报管理控制层 */ @RestController @AllArgsConstructor @RequestMapping("/workReport") public class WorkReportController { private final WorkReportService workReportService; private final IUserService userService; private final IDeptService deptService; private final MyAsyncService myAsyncService; /** * 自定义分页 * * @param query page,size * @param workReport 工作汇报信息对象 */ @GetMapping("/page") public R> page(WorkReportVo workReport, Query query) { IPage pages = workReportService.selectWorkReportPage(Condition.getPage(query), workReport); List records = pages.getRecords(); for (WorkReportVo record : records) { record.setReplyRealName(getReplyRealName(record)); record.setReplyDeptName(getReplyDeptName(record)); } return R.data(pages); } /** * 自定义分页--接收到的汇报信息page * * @param query page,size * @param workReport 工作汇报信息对象 */ @GetMapping("/pageReply") public R> pageReply(WorkReportVo workReport, Query query) { IPage pages = workReportService.selectWorkReplyPage(Condition.getPage(query), workReport); return R.data(pages); } /** * 新增 * * @param workReport 工作汇报信息对象 */ @PostMapping("/save") @ApiOperation(value = "新增", notes = "传入workReport") public R save(@RequestBody WorkReport workReport) { return R.status(workReportService.save(workReport)); } /** * 修改 * * @param workReport 工作汇报信息对象 */ @PostMapping("/update") public R update(@RequestBody WorkReport workReport) { return R.status(workReportService.updateById(workReport)); } /** * 新增或修改 * * @param workReport 工作汇报信息对象 */ @PostMapping("/submit") public R submit(@RequestBody WorkReport workReport) { boolean status = false; if (null == workReport.getId()) { workReport.setReportTime(new Date()); workReport.setReplyDeptIds(getReplyDeptIds(workReport.getReceivedIds())); //新增 status = workReportService.save(workReport); if (status) { //数据同步 String s1 = "insert into sys_work_report(id,type,content,work_desc,report_time,received_ids,dept_id,reply_dept_ids,category,user_id) " + "values(" + "'" + workReport.getId() + "'" + "," + "'" + workReport.getType() + "'" + "," + "'" + workReport.getContent() + "'" + "," + "'" + workReport.getWorkDesc() + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(workReport.getReportTime()) + "'" + "," + "'" + workReport.getReceivedIds() + "'" + "," + "'" + workReport.getDeptId() + "'" + "," + "'" + workReport.getReplyDeptIds() + "'" + "," + "'" + workReport.getCategory() + "'" + "," + "'" + workReport.getUserId() + "'" + ")"; //FtpUtil.sqlFileUpload(s1); myAsyncService.dataSync(s1); } } else { workReport.setReplyDeptIds(getReplyDeptIds(workReport.getReceivedIds())); if (null == workReport.getReplyTime()) { workReport.setReplyTime(new Date()); } //修改 status = workReportService.updateById(workReport); if (status) { //内网同步 String s1 = "update sys_work_report set type = " + "'" + workReport.getType() + "'" + ",content = " + "'" + workReport.getContent() + "'" + ",work_desc = " + "'" + workReport.getWorkDesc() + "'" + ",received_ids = " + "'" + workReport.getReceivedIds() + "'" + ",reply_content = " + "'" + workReport.getReplyContent() + "'" + ",reply_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(workReport.getReplyTime()) + "'" + ",dept_id = " + "'" + workReport.getDeptId() + "'" + ",reply_dept_ids = " + "'" + workReport.getReplyDeptIds() + "'" + ",category = " + "'" + workReport.getCategory() + "'" + ",user_id = " + "'" + workReport.getUserId() + "'" + " " + "where id = " + "'" + workReport.getId() + "'"; //FtpUtil.sqlFileUpload(s1); myAsyncService.dataSync(s1); } } return R.status(status); } /** * 删除 * * @param ids 工作汇报信息ids 数组 */ @PostMapping("/remove") public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) { //内网删除 List list = Func.toLongList(ids); list.forEach(id -> { //内网同步 String s1 = "delete from sys_work_report where id = " + "'" + id + "'"; //FtpUtil.sqlFileUpload(s1); myAsyncService.dataSync(s1); }); return R.status(workReportService.removeByIds(Func.toLongList(ids))); } /** * 详情 * * @param workReport 工作汇报信息对象 */ @GetMapping("/detail") @ApiOperation(value = "详情", notes = "传入workReport") public R detail(WorkReport workReport) { //查询工作汇报详情 WorkReportVo detail = workReportService.selectWorkReportInfo(workReport); detail.setReplyRealName(getReplyRealName(detail)); detail.setReplyDeptName(getReplyDeptName(detail)); //查询接收人单位(名称)信息 return R.data(detail); } /** * 获取接收人的单位信息 * * @param detail 汇报详情 * @return */ private String getReplyDeptName(WorkReportVo detail) { if (null != detail.getReplyDeptIds() && detail.getReplyDeptIds() != "" && !detail.getReplyDeptIds().isEmpty()) { List replyDeptIds = Arrays.asList(detail.getReplyDeptIds().split(",")); StringBuilder replyDeptNameInfo = new StringBuilder(); if (replyDeptIds.size() > 0) { for (String deptId : replyDeptIds) { //查询接收人单位信息 Dept deptDetail = deptService.getById(Long.parseLong(deptId)); if (null != deptDetail) { replyDeptNameInfo = replyDeptNameInfo.append(deptDetail.getDeptName()).append(","); } } if (replyDeptNameInfo.length() > 0) { //截取 return replyDeptNameInfo.substring(0, replyDeptNameInfo.length() - 1); } } } return null; } /** * 获取接收人的单位id(dept)信息 * * @param * @return */ private String getReplyDeptIds(String detail) { List userIds = Arrays.asList(detail.split(",")); List list = new ArrayList<>(); for (String userId : userIds) { //查询接收人单位信息 User userDetail = userService.getById(userId); if (null != userDetail) { list.add(userDetail.getDeptId()); } } //去重 List collect = list.stream().distinct().collect(Collectors.toList()); //截取 return String.join(",", collect); } /** * 查询接收人姓名信息 * * @param detail 汇报详情 * @return */ private String getReplyRealName(WorkReportVo detail) { List userIds = Arrays.asList(detail.getReceivedIds().split(",")); StringBuilder replyRealNameInfo = new StringBuilder(); for (String userId : userIds) { //查询接收人姓名信息 // User user = new User(); // user.setCardid(idCardNo); // User userDetail = userService.getOne(Condition.getQueryWrapper(user)); User userDetail = userService.getById(userId); if (null != userDetail) { replyRealNameInfo = replyRealNameInfo.append(userDetail.getRealName()).append(","); } } //截取 if (replyRealNameInfo.toString().length() > 0) { return replyRealNameInfo.substring(0, replyRealNameInfo.length() - 1); } return null; } }