package com.landtool.lanbase.modules.api.controller.MapPortal; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.org.entity.OrgUser; import com.landtool.lanbase.modules.org.service.OrgUnitService; import com.landtool.lanbase.modules.org.service.OrgUserService; import com.landtool.lanbase.modules.res.entity.Res_TempPrint; import com.landtool.lanbase.modules.res.entity.Res_Template; import com.landtool.lanbase.modules.res.service.ResTempPrintService; import com.landtool.lanbase.modules.res.service.ResTemplateService; import com.landtool.lanbase.modules.sys.controller.AbstractController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @Controller @RequestMapping("/api/maptempprint/") @Api(value = "", tags = {"专题制图地图出图打印接口"}) public class MapTempPrintController extends AbstractController { @Autowired private ResTempPrintService resTempPrintService; @Autowired private OrgUserService orgUserService; @Autowired private OrgUnitService orgUnitService; @Autowired private ResTemplateService resTemplateService; /** * 新增地图出图打印信息 */ @PostMapping(path = "/addMapTempPrint") @ApiOperation(value = "新增地图出图打印信息", notes = "") @ResponseBody public int addMapTempPrint( @ApiParam(name = "userid", value = "用户ID", required = true) @RequestParam(name = "userid") int userid, @ApiParam(name = "rtid", value = "模板ID") @RequestParam(name = "rtid") Integer rtid, @ApiParam(name = "title", value = "标题", required = true) @RequestParam(name = "title") String title, @ApiParam(name = "mapcontent", value = "地图内容", required = true) @RequestParam(name = "mapcontent") String mapcontent, @ApiParam(name = "chartcontent", value = "制图信息") @RequestParam(name = "chartcontent") String chartcontent, @ApiParam(name = "isshowlegend", value = "是否显示图例", required = true) @RequestParam(name = "isshowlegend") int isshowlegend, @ApiParam(name = "chartstyle", value = "出图格式", required = true) @RequestParam(name = "chartstyle") String chartstyle, @ApiParam(name = "chartscale", value = "出图比例", required = true) @RequestParam(name = "chartscale") String chartscale, @ApiParam(name = "chartextent", value = "出图范围") @RequestParam(name = "chartextent") String chartextent, @ApiParam(name = "isscalelocked", value = "是否锁定比例尺") @RequestParam(name = "isscalelocked") Integer isscalelocked) { Res_TempPrint resTempPrint = new Res_TempPrint(); resTempPrint.setUserid(userid);//用户ID if(rtid != null) { resTempPrint.setRtid(rtid);//模板ID } resTempPrint.setTitle(title);//标题 if(chartcontent != null && !chartcontent.isEmpty()) { resTempPrint.setChartcontent(chartcontent);//制图信息 } resTempPrint.setMapcontent(mapcontent);//地图内容 resTempPrint.setIsshowlegend(isshowlegend);//是否显示图例 resTempPrint.setChartstyle(chartstyle);//出图格式 resTempPrint.setChartscale(chartscale);//出图比例 resTempPrint.setAuditstatus(3); //新增添加未提交状态 if(chartextent != null && !chartextent.isEmpty()) { resTempPrint.setChartextent(chartextent);//出图范围 } if(isscalelocked != null) { resTempPrint.setIsscalelocked(isscalelocked);//是否锁定比例尺 } Timestamp time = new Timestamp(new Date().getTime()); resTempPrint.setChartdate(time); resTempPrintService.insertSelective(resTempPrint);//新增地图出图打印信息 int objectid = resTempPrintService.queryResTempPrintIdentCurrent();//获取新增信息ID return objectid; } /** * 更新地图出图打印信息 */ @PostMapping("updateMapTemPrint") @ApiOperation(value = "更新地图出图打印信息", notes = "") @ResponseBody public int updateMapTemPrint(Res_TempPrint resTempPrint) { resTempPrintService.updateByPrimaryKeySelective(resTempPrint); return resTempPrint.getObjectid(); } /** * 提交地图出图打印信息 */ @PostMapping("sumbitMapTemPrint") @ApiOperation(value = "提交地图出图打印信息", notes = "") @ResponseBody public String sumbitMapTemPrint(int objectid) { Res_TempPrint resTempPrint = resTempPrintService.selectByPrimaryKey(objectid); Map map = new HashMap<>(); if (resTempPrint != null) { resTempPrint.setAuditstatus(2); resTempPrintService.updateByPrimaryKeySelective(resTempPrint); map.put("success", true); map.put("msg", "提交成功!"); } else { map.put("success", false); map.put("msg", "提交失败!提示:出图打印信息不存在!"); } return JSON.toJSONString(map, SerializerFeature.WriteMapNullValue); } /** * 根据ID获取地图出图信息 */ @GetMapping("getMapPrintById") @ResponseBody public String getMapPrintById(int objid) { Res_TempPrint resTempPrint = resTempPrintService.selectByPrimaryKey(objid); OrgUser user = orgUserService.queryObject(resTempPrint.getUserid().longValue()); String name = user.getChinesename(); String unit = orgUserService.getDefaultUnit(user.getUserid()).getUnitname(); //获取审核人中文名 String auditUserName = ""; if(resTempPrint.getAudituserid() != null) { OrgUser auditUser = orgUserService.queryObject(resTempPrint.getAudituserid().longValue()); if(auditUser != null) { auditUserName = auditUser.getChinesename(); } } Res_Template resTemplate = new Res_Template(); if(resTempPrint.getRtid() != null) { resTemplate = resTemplateService.selectResTemplateByRtId(resTempPrint.getRtid()); } String rtname = ""; String templatetype = ""; if (resTemplate != null) { rtname = resTemplate.getRtname(); templatetype = resTemplate.getTemplatetype(); } else if(resTempPrint.getRtid() == 0) { rtname = "MAP_ONLY"; templatetype = "MAP_ONLY"; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List> maps = new LinkedList<>(); Map map = new HashMap<>(); map.put("userid", resTempPrint.getUserid()); map.put("rtid", resTempPrint.getRtid()); map.put("rtname", rtname); map.put("templatetype", templatetype); map.put("title", resTempPrint.getTitle()); map.put("auditstatus", resTempPrint.getAuditstatus()); map.put("audituser", auditUserName); map.put("mapcontent", JSON.parseObject(resTempPrint.getMapcontent())); map.put("chartcontent", JSON.parseArray(resTempPrint.getChartcontent())); map.put("chartextent", resTempPrint.getChartextent()); map.put("isshowlegend", resTempPrint.getIsshowlegend()); map.put("isscalelocked", resTempPrint.getIsscalelocked()); map.put("chartstyle", resTempPrint.getChartstyle()); map.put("chartscale", resTempPrint.getChartscale()); map.put("chartdate", sdf.format(resTempPrint.getChartdate())); map.put("username", name); map.put("userunit", unit); maps.add(map); return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue); } /** * 审核地图出图打印信息 */ @PostMapping(path = "/auditMapTempPrint") @ApiOperation(value = "审核地图出图打印信息", notes = "") @ResponseBody public String auditMapTempPrint( @ApiParam(name = "objectid", value = "出图打印信息ID", required = true) @RequestParam(name = "objectid") int objectid, @ApiParam(name = "audituserid", value = "审核人ID", required = true) @RequestParam(name = "audituserid") int audituserid, @ApiParam(name = "auditopinion", value = "审核意见") String auditopinion, @ApiParam(name = "auditstatus", value = "审核结果", required = true) @RequestParam(name = "auditstatus") int auditstatus) { Res_TempPrint resTempPrint = resTempPrintService.selectByPrimaryKey(objectid); Map map = new HashMap<>(); if (resTempPrint != null) { try { resTempPrint.setAudituserid(audituserid);//审核人 resTempPrint.setAuditopinion(auditopinion);//审核意见 resTempPrint.setAuditstatus(auditstatus);//审核结果 Timestamp time = new Timestamp(new Date().getTime()); resTempPrint.setAuditdate(time);//审核时间 resTempPrintService.updateByPrimaryKeySelective(resTempPrint); map.put("success", true); map.put("msg", "审核成功!"); } catch (Exception e) { map.put("success", false); map.put("msg", e.getMessage()); } } else { map.put("success", false); map.put("msg", "出图打印信息不存在!"); } return JSON.toJSONString(map, SerializerFeature.WriteMapNullValue); } /** * 获取出图审核信息 发布人可看自己出图审核状态,审核人可看自己及其他用户出图资源并可做审核 * @return */ @GetMapping("/getChuTuList") @ResponseBody @ApiOperation(value = "获取出图审核信息", notes = "") public String selectInfoList(HttpServletRequest request, PageBean pageBean) { String callbackFunName = request.getParameter("callback"); String userprintaudit = request.getParameter("userprintaudit");//用户出图审核权限 String userid = request.getParameter("userid");//用户ID if (callbackFunName == null || callbackFunName.isEmpty()) { callbackFunName = "callback"; } pageBean.setLimit(10); PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());//设置当前页数及每页条数 List resTempPrints = null; Res_TempPrint res_tempPrint = new Res_TempPrint(); String admin = "true"; // 查询当前登陆用户是否具备出图审核权限 是:查所有 不是:查自己的 if (userprintaudit == "false") { // 如果具备出图审核权限,不添加用户id,查询所有。如果不是 添加id 查询单个 admin = "false"; //Integer userid = getUserId().intValue();//获取登录用户ID res_tempPrint.setUserid(Integer.parseInt(userid)); } resTempPrints = resTempPrintService.getList(res_tempPrint); int countNums = (int) ((Page) resTempPrints).getTotal();//获取记录总数 PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(resTempPrints); StringBuilder rsb = new StringBuilder(); rsb.append("["); List> maps = new LinkedList<>(); for (int i = 0; i < resTempPrints.size(); i++) { Map remap = new HashMap<>(); remap.put("objectid", resTempPrints.get(i).getObjectid()); remap.put("title", resTempPrints.get(i).getTitle()); remap.put("auditstatus", resTempPrints.get(i).getAuditstatus()); maps.add(remap); } Map newmap = new HashMap<>(); newmap.put("Count", countNums); newmap.put("Page", pageBean.getPage()); newmap.put("isAdmin", admin); newmap.put("ShuJu", maps); return callbackFunName + "(" + JSON.toJSONString(newmap, SerializerFeature.WriteMapNullValue) + ")"; } /** * 删除出图记录 */ @GetMapping("/delTempPrint") @ResponseBody @ApiOperation(value = "获取出图审核信息", notes = "") public String selectInfoList(@ApiParam(name = "objectid", value = "出图打印信息ID", required = true) @RequestParam(name = "objectid") int objectid) { Map map = new HashMap<>(); try { resTempPrintService.deleteByPrimaryKey(objectid); map.put("success", true); map.put("msg", "删除成功!"); } catch (Exception e) { map.put("success", false); map.put("msg", "删除失败!错误提示:" + e.getMessage()); } return JSON.toJSONString(map, SerializerFeature.WriteMapNullValue); } }