package cn.com.lzt.schedule.controller; import cn.com.lzt.common.util.StringUtil; import cn.com.lzt.schedule.service.impl.ScheduleSuperivseRecordServiceImpl; import cn.com.lzt.schedule.service.impl.ScheduleSuperivseServiceImpl; import cn.com.lzt.sysmsg.service.SysMsgServiceI; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.daju.common.util.DataPage; import com.daju.mix.dao.entity.TBScheduleSuperivse; import com.daju.mix.dao.entity.TBScheduleSuperivseRecord; import com.daju.mix.dao.service.impl.TSBaseUserServiceImpl; import com.xcgl.utils.OrderNumTools; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.jeecgframework.core.common.exception.BusinessException; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.ResourceUtil; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.web.system.pojo.base.TSUser; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * @author :sahib.kio.m * @date :Created in 2021/8/10 下午3:11 */ @Controller @RequestMapping("/scheduleSuperivseController") public class ScheduleSuperivseController { @Resource private ScheduleSuperivseServiceImpl superivseService; @Resource private TSBaseUserServiceImpl baseUserService; @Resource private ScheduleSuperivseRecordServiceImpl superivseRecordService; @Autowired private SystemService systemService; @Autowired private SysMsgServiceI sysMsgService; @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/schedule/superivseList"); } @RequestMapping(params = "datagrid") public void datagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { Map param = new HashMap<>(); for (String key : request.getParameterMap().keySet()) { param.put(key, request.getParameter(key)); } DataPage result = superivseService.superivseList(request,param); TagUtil.datagrid(response, dataGrid, result); } @RequestMapping(params = "goCheck") public ModelAndView goCheck(HttpServletRequest request) { String id = request.getParameter("id"); TBScheduleSuperivse common = superivseService.getById(id); common = scheduleImageUrl(common); request.setAttribute("userName", baseUserService.getById(common.getUserId()).getRealname()); request.setAttribute("common", common); request.setAttribute("responsibleUserName", common.getResponsibleUserId()); request.setAttribute("leaderUserName", common.getLeaderUserId()); List list = superivseRecordService.list(new QueryWrapper() {{ eq("supervise_id", id); orderByDesc("deal_date"); }}); request.setAttribute("list", list); if (CollectionUtils.isEmpty(list)) { request.setAttribute("noRecord", "无整改记录"); } return new ModelAndView("cn/com/lzt/schedule/superivseList-update"); } @RequestMapping(params = "goAdd") public ModelAndView goAdd(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/schedule/superivseList-add"); } public TBScheduleSuperivse scheduleImageUrl(TBScheduleSuperivse common) { if (common != null) { // add-刘梦祥-2022年1月13日19:02:31(新增视频和图片路径解析) if (common.getImgUrl() != null && StringUtils.isNotEmpty(common.getImgUrl())) { if (common.getImgUrl().contains("http") && common.getImgUrl().length() > 10) { try { List imgUrlList = JSONObject.parseArray(common.getImgUrl(), String.class); common.setImgUrlList(imgUrlList); } catch (Exception e) { e.printStackTrace(); } } else { List imgUrlList = new ArrayList<>(); if (!"[null]".equals(common.getImgUrl()) && !"[]".equals(common.getImgUrl())) { imgUrlList.add("http://47.100.210.233/" + common.getImgUrl()); common.setImgUrlList(imgUrlList); } } } if (common.getVideos() != null && StringUtils.isNotEmpty(common.getVideos())) { if (common.getVideos().contains("http")) { try { List videosList = JSONObject.parseArray(common.getVideos(), String.class); common.setVideosList(videosList); } catch (Exception e) { e.printStackTrace(); } } else { List videosList = new ArrayList<>(); if (!"[null]".equals(common.getVideos()) && !"[]".equals(common.getVideos())) { videosList.add("http://47.100.210.233/" + common.getVideos()); common.setVideosList(videosList); } } } if (StringUtils.isNotEmpty(common.getResponsibleUserId())) { String getUserRealNameSql = "select realname from t_s_base_user where id = ?"; Map userData = systemService.findOneForJdbc(getUserRealNameSql, common.getResponsibleUserId()); if (userData != null && userData.containsKey("realname")) { common.setResponsibleUserId(String.valueOf(userData.get("realname"))); } } if (StringUtils.isNotEmpty(common.getLeaderUserId())) { String getUserRealNameSql = "select realname from t_s_base_user where id = ?"; Map userData = systemService.findOneForJdbc(getUserRealNameSql, common.getLeaderUserId()); if (userData != null && userData.containsKey("realname")) { common.setLeaderUserId(String.valueOf(userData.get("realname"))); } } } return common; } @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(HttpServletRequest request) { String id = request.getParameter("id"); TBScheduleSuperivse common = superivseService.getById(id); common = scheduleImageUrl(common); request.setAttribute("userName", baseUserService.getById(common.getUserId()).getRealname()); request.setAttribute("common", common); request.setAttribute("responsibleUserName", common.getResponsibleUserId()); request.setAttribute("leaderUserName", common.getLeaderUserId()); return new ModelAndView("cn/com/lzt/schedule/superivseList-update"); } @RequestMapping(params = "statusUpdate") public ModelAndView statusUpdate(HttpServletRequest request) { String id = request.getParameter("id"); TBScheduleSuperivse common = superivseService.getById(id); common = scheduleImageUrl(common); request.setAttribute("common", common); return new ModelAndView("cn/com/lzt/schedule/superivseList-statusUpdate"); } @RequestMapping(params = "doNoDeal") @ResponseBody public AjaxJson doNoDeal(TBScheduleSuperivse common, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "修改成功"; j.setSuccess(true); try { common = superivseService.getById(common.getId()); if("3".equals(common.getStatus())){ common.setDealStatus("3"); common.setStatus("4"); }else{ common.setDealStatus("3"); } superivseService.updateById(common); } catch (Exception e) { e.printStackTrace(); message = "修改失败"; j.setSuccess(false); throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 督查管理确认按钮 * 如果状态状态为3:只有经办人能看到或操作确认、退回按钮。状态修改为5(整改完))。 * @author 刘梦祥 * @Date 2022年11月28日16:43:33 * @param common 督查管理记录实体类 * @param request HttpServletRequest * @return AjaxJson */ @RequestMapping(params = "doConfirm") @ResponseBody public AjaxJson doConfirm(TBScheduleSuperivse common, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "修改成功"; j.setSuccess(true); try { common = superivseService.getById(common.getId()); TSUser user = ResourceUtil.getSessionUser(); if("3".equals(common.getStatus()) && common.getUserId() != null){ common.setStatus("5"); superivseService.updateById(common); sysMsgService.saveSysMsg(Globals.MSG_TITLE_2,Globals.MSG_CONTENT_3,user.getId(),common.getResponsibleUserId()); sysMsgService.saveSysMsgToDepart(Globals.MSG_TITLE_2,Globals.MSG_CONTENT_3,user.getId(),common.getResponsibleUserId()); }else{ j.setSuccess(false); message = "修改失败,请刷新后重试!"; } } catch (Exception e) { e.printStackTrace(); message = "修改失败"; j.setSuccess(false); throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 督查管理退回按钮 * 如果状态状态为3:只有经办人能看到或操作确认、退回按钮。状态修改为1(初始状态:整改中) * @author 刘梦祥 * @Date 2022年11月28日16:43:33 * @param common 督查管理记录实体类 * @param request HttpServletRequest * @return AjaxJson */ @RequestMapping(params = "doBack") @ResponseBody public AjaxJson doBack(TBScheduleSuperivse common, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "修改成功"; j.setSuccess(true); try { common = superivseService.getById(common.getId()); TSUser user = ResourceUtil.getSessionUser(); if("3".equals(common.getStatus()) && common.getUserId() != null){ common.setStatus("1"); superivseService.updateById(common); sysMsgService.saveSysMsg(Globals.MSG_TITLE_2,Globals.MSG_CONTENT_4,user.getId(),common.getResponsibleUserId()); sysMsgService.saveSysMsgToDepart(Globals.MSG_TITLE_2,Globals.MSG_CONTENT_4,user.getId(),common.getResponsibleUserId()); }else{ j.setSuccess(false); message = "修改失败,请刷新后重试!"; } } catch (Exception e) { e.printStackTrace(); message = "修改失败"; j.setSuccess(false); throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "doUpdate") @ResponseBody public AjaxJson doUpdate(TBScheduleSuperivse common, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "修改成功"; j.setSuccess(true); try { common.setUpdateDate(getNowDateTime()); //整改时间 if (common.getResultUrl() != null) { common.setDealDate(getNowDateTime()); TBScheduleSuperivseRecord record = new TBScheduleSuperivseRecord(); record.setDealDate(getNowDateTime()); record.setImgUrl(common.getResultUrl()); record.setSuperviseId(common.getId()); superivseRecordService.save(record); } //确认时间 if (common.getStatus() == "2") { common.setConfirmDate(getNowDateTime()); } Map param = new HashMap<>(); for (String key : request.getParameterMap().keySet()) { param.put(key, request.getParameter(key)); } String pageTag = param.get("pageTag"); if(StringUtils.isNotEmpty(pageTag) && "rectification".equals(pageTag)){ common.setDealStatus("2"); } superivseService.updateById(common); } catch (Exception e) { e.printStackTrace(); message = "修改失败"; j.setSuccess(false); throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "doAdd") @ResponseBody public AjaxJson doAdd(TBScheduleSuperivse common, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "添加成功"; j.setSuccess(true); try { // update-刘梦祥-2022年11月28日16:30:21(经确认新增的督查表单默认状态为待确认即数据字典中的2) common.setStatus("2"); common.setCreateDate(getNowDateTime()); common.setUpdateDate(getNowDateTime()); common.setCode(OrderNumTools.generateNextBillCode("DC" + getNowDate(), 10, "t_b_schedule_superivse", "code", 4)); superivseService.save(common); // add-刘梦祥-2022年11月28日16:12:35(经确认当用户添加督查管理表单时,需要提示用户) sysMsgService.saveSysMsg(Globals.MSG_TITLE_2,Globals.MSG_CONTENT_2,common.getUserId(),common.getResponsibleUserId()); sysMsgService.saveSysMsgToDepart(Globals.MSG_TITLE_2,Globals.MSG_CONTENT_2,common.getUserId(),common.getResponsibleUserId()); } catch (Exception e) { e.printStackTrace(); message = "添加失败"; j.setSuccess(false); throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } private static SimpleDateFormat sdfDate = new SimpleDateFormat("yyyyMMdd"); private static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static String getNowDate() { Date now = new Date(); String time = sdfDate.format(now); return time; } public static String getNowDateTime() { Date now = new Date(); String time = sdfTime.format(now); return time; } @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(TBScheduleSuperivse common, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "档案删除成功"; try { superivseService.removeById(common); } catch (Exception e) { e.printStackTrace(); message = "档案删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "getName") @ResponseBody public List getName(HttpServletRequest request) { String name = request.getParameter("name"); String sql = "select ID,realname from t_s_base_user where 1=1"; if (!StringUtil.isEmpty(name)) { sql += " and realname like '%" + name + "%'"; } List list = systemService.findListbySql(sql); List> values = list.stream().map(e -> { Map map = new HashMap(); map.put("code", e[0].toString()); map.put("name", e[1].toString()); return map; }).collect(Collectors.toList()); return values; } }