first commit
This commit is contained in:
@ -0,0 +1,101 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.xhtmlrenderer.extend.FSImage;
|
||||
import org.xhtmlrenderer.extend.ReplacedElement;
|
||||
import org.xhtmlrenderer.extend.ReplacedElementFactory;
|
||||
import org.xhtmlrenderer.extend.UserAgentCallback;
|
||||
import org.xhtmlrenderer.layout.LayoutContext;
|
||||
import org.xhtmlrenderer.pdf.ITextFSImage;
|
||||
import org.xhtmlrenderer.pdf.ITextImageElement;
|
||||
import org.xhtmlrenderer.render.BlockBox;
|
||||
import org.xhtmlrenderer.simple.extend.FormSubmissionListener;
|
||||
|
||||
|
||||
import com.lowagie.text.BadElementException;
|
||||
import com.lowagie.text.Image;
|
||||
import com.lowagie.text.pdf.codec.Base64;
|
||||
/**
|
||||
* 图片base64支持,把图片转换为itext自己的图片对象
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public class Base64ImgReplacedElementFactory implements ReplacedElementFactory {
|
||||
|
||||
|
||||
/**
|
||||
* 实现createReplacedElement 替换html中的Img标签
|
||||
*
|
||||
* @param c 上下文
|
||||
* @param box 盒子
|
||||
* @param uac 回调
|
||||
* @param cssWidth css宽
|
||||
* @param cssHeight css高
|
||||
* @return ReplacedElement
|
||||
*/
|
||||
public ReplacedElement createReplacedElement(LayoutContext c, BlockBox box, UserAgentCallback uac,
|
||||
int cssWidth, int cssHeight) {
|
||||
Element e = box.getElement();
|
||||
if (e == null) {
|
||||
return null;
|
||||
}
|
||||
String nodeName = e.getNodeName();
|
||||
// 找到img标签
|
||||
if (nodeName.equals("img")) {
|
||||
String attribute = e.getAttribute("src");
|
||||
FSImage fsImage;
|
||||
try {
|
||||
// 生成itext图像
|
||||
fsImage = buildImage(attribute, uac);
|
||||
} catch (BadElementException e1) {
|
||||
fsImage = null;
|
||||
} catch (IOException e1) {
|
||||
fsImage = null;
|
||||
}
|
||||
if (fsImage != null) {
|
||||
// 对图像进行缩放
|
||||
if (cssWidth != -1 || cssHeight != -1) {
|
||||
fsImage.scale(cssWidth, cssHeight);
|
||||
}
|
||||
return new ITextImageElement(fsImage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编解码base64并生成itext图像
|
||||
*/
|
||||
protected FSImage buildImage(String srcAttr, UserAgentCallback uac) throws IOException,
|
||||
BadElementException {
|
||||
FSImage fiImg=null;
|
||||
if (srcAttr.toLowerCase().startsWith("data:image/")) {
|
||||
String base64Code= srcAttr.substring(srcAttr.indexOf("base64,") + "base64,".length(),
|
||||
srcAttr.length());
|
||||
// 解码
|
||||
byte[] decodedBytes = Base64.decode(base64Code);
|
||||
|
||||
|
||||
fiImg= new ITextFSImage(Image.getInstance(decodedBytes));
|
||||
} else {
|
||||
fiImg= uac.getImageResource(srcAttr).getImage();
|
||||
}
|
||||
return fiImg;
|
||||
}
|
||||
|
||||
|
||||
public void reset() {}
|
||||
|
||||
@Override
|
||||
public void remove(Element arg0) {}
|
||||
|
||||
@Override
|
||||
public void setFormSubmissionListener(FormSubmissionListener arg0) {}
|
||||
|
||||
}
|
||||
154
src/com/sipai/controller/base/BasicComponentsController.java
Normal file
154
src/com/sipai/controller/base/BasicComponentsController.java
Normal file
@ -0,0 +1,154 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sipai.entity.base.BasicComponents;
|
||||
import com.sipai.entity.scada.MPoint4APP;
|
||||
import com.sipai.entity.user.Company;
|
||||
import com.sipai.entity.user.Unit;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.service.base.BasicComponentsService;
|
||||
import com.sipai.service.user.UnitService;
|
||||
import com.sipai.tools.CommString;
|
||||
import com.sipai.tools.CommUtil;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/base/basicComponents")
|
||||
public class BasicComponentsController {
|
||||
@Resource
|
||||
private BasicComponentsService basicComponentsService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@RequestMapping("/showlist.do")
|
||||
public String showlist(HttpServletRequest request,Model model) {
|
||||
return "/base/basicComponentsManage";
|
||||
}
|
||||
@RequestMapping("/getlist.do")
|
||||
public ModelAndView getlist(HttpServletRequest request,Model model,
|
||||
@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "rows") Integer rows,
|
||||
@RequestParam(value = "sort", required=false) String sort,
|
||||
@RequestParam(value = "order", required=false) String order) {
|
||||
User cu=(User)request.getSession().getAttribute("cu");
|
||||
String orderstr=" order by morder asc";
|
||||
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("type")!=null && !request.getParameter("type").toString().isEmpty()) {
|
||||
wherestr+= " and type ='"+request.getParameter("type").toString()+"' ";
|
||||
}
|
||||
PageHelper.startPage(page, rows);
|
||||
List<BasicComponents> list = this.basicComponentsService.selectListByWhere(wherestr+orderstr);
|
||||
|
||||
PageInfo<BasicComponents> pi = new PageInfo<BasicComponents>(list);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
|
||||
String result="{\"total\":"+pi.getTotal()+",\"rows\":"+json+"}";
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/add.do")
|
||||
public String doadd(HttpServletRequest request,Model model){
|
||||
String basicComponentsTypeId= request.getParameter("id");
|
||||
request.setAttribute("basicComponentsTypeId", basicComponentsTypeId);
|
||||
return "base/basicComponentsAdd";
|
||||
}
|
||||
|
||||
@RequestMapping("/edit.do")
|
||||
public String doedit(HttpServletRequest request,Model model){
|
||||
String groupId = request.getParameter("id");
|
||||
BasicComponents basicComponents = this.basicComponentsService.selectById(groupId);
|
||||
model.addAttribute("basicComponents", basicComponents);
|
||||
if(basicComponents.getPid()!=null && basicComponents.getPid().equals("")){
|
||||
BasicComponents parent = this.basicComponentsService.selectById(basicComponents.getPid());
|
||||
if(parent != null){
|
||||
model.addAttribute("pname",parent.getName());
|
||||
}else{
|
||||
model.addAttribute("pname","");
|
||||
}
|
||||
}else{
|
||||
model.addAttribute("pname","");
|
||||
}
|
||||
return "base/basicComponentsEdit";
|
||||
}
|
||||
|
||||
@RequestMapping("/save.do")
|
||||
public String dosave(HttpServletRequest request,Model model,
|
||||
@ModelAttribute BasicComponents basicComponents){
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
String id = CommUtil.getUUID();
|
||||
basicComponents.setId(id);
|
||||
basicComponents.setInsuser(cu.getId());
|
||||
basicComponents.setInsdt(CommUtil.nowDate());
|
||||
|
||||
int result =this.basicComponentsService.save(basicComponents);
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+id+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
@RequestMapping("/update.do")
|
||||
public String doupdate(HttpServletRequest request,Model model,
|
||||
@ModelAttribute BasicComponents basicComponents){
|
||||
int result = this.basicComponentsService.update(basicComponents);
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+basicComponents.getId()+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/delete.do")
|
||||
public String dodel(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="id") String id){
|
||||
int result = this.basicComponentsService.deleteById(id);
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/deletes.do")
|
||||
public String dodels(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="ids") String ids){
|
||||
ids=ids.replace(",","','");
|
||||
int result = this.basicComponentsService.deleteByWhere("where id in ('"+ids+"')");
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
/**
|
||||
* 获取树状结构
|
||||
*/
|
||||
@RequestMapping("/getBasicComponentsForTree.do")
|
||||
public String getBasicComponentsForTree(HttpServletRequest request,Model model){
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
//获取非用户节点树(公司 水厂 部门)
|
||||
List<BasicComponents> list = this.basicComponentsService.selectListByWhere("order by morder");
|
||||
String json = basicComponentsService.getTreeList(null, list);
|
||||
model.addAttribute("result", json);
|
||||
return "result";
|
||||
}
|
||||
/**
|
||||
* 获取已配置内容
|
||||
*/
|
||||
@RequestMapping("/getBasicComponentsForCode.do")
|
||||
public String getBasicComponentsForCode(HttpServletRequest request,Model model){
|
||||
String code = request.getParameter("code");
|
||||
com.alibaba.fastjson.JSONArray jsonArray = this.basicComponentsService.selectListByWhereAll("where active='1' and code like '%"+code+"%' ");
|
||||
if(jsonArray!=null && jsonArray.size()>0){
|
||||
model.addAttribute("result", jsonArray);
|
||||
}else{
|
||||
model.addAttribute("result", null);
|
||||
}
|
||||
return "result";
|
||||
}
|
||||
}
|
||||
127
src/com/sipai/controller/base/BasicConfigureController.java
Normal file
127
src/com/sipai/controller/base/BasicConfigureController.java
Normal file
@ -0,0 +1,127 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sipai.entity.base.BasicConfigure;
|
||||
import com.sipai.entity.scada.MPoint4APP;
|
||||
import com.sipai.entity.user.Company;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.service.base.BasicConfigureService;
|
||||
import com.sipai.service.user.UnitService;
|
||||
import com.sipai.tools.CommString;
|
||||
import com.sipai.tools.CommUtil;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/base/basicConfigure")
|
||||
public class BasicConfigureController {
|
||||
@Resource
|
||||
private BasicConfigureService basicConfigureService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@RequestMapping("/showlist.do")
|
||||
public String showlist(HttpServletRequest request,Model model) {
|
||||
return "/base/basicConfigureManage";
|
||||
}
|
||||
@RequestMapping("/getlist.do")
|
||||
public ModelAndView getlist(HttpServletRequest request,Model model,
|
||||
@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "rows") Integer rows,
|
||||
@RequestParam(value = "sort", required=false) String sort,
|
||||
@RequestParam(value = "order", required=false) String order) {
|
||||
User cu=(User)request.getSession().getAttribute("cu");
|
||||
// if(cu==null){
|
||||
// cu=loginService.Login(request.getParameter("username"), request.getParameter("pwd"));
|
||||
// }
|
||||
String orderstr=" order by morder asc";
|
||||
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("pid")!=null && !request.getParameter("pid").toString().isEmpty()) {
|
||||
wherestr+= " and pid ='"+request.getParameter("pid").toString()+"' ";
|
||||
}
|
||||
if (request.getParameter("type")!=null && !request.getParameter("type").toString().isEmpty()) {
|
||||
wherestr+= " and type ='"+request.getParameter("type").toString()+"' ";
|
||||
}
|
||||
PageHelper.startPage(page, rows);
|
||||
List<BasicConfigure> list = this.basicConfigureService.selectListByWhere(wherestr+orderstr);
|
||||
|
||||
PageInfo<BasicConfigure> pi = new PageInfo<BasicConfigure>(list);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
|
||||
String result="{\"total\":"+pi.getTotal()+",\"rows\":"+json+"}";
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/add.do")
|
||||
public String doadd(HttpServletRequest request,Model model){
|
||||
String companyId= request.getParameter("bizId");
|
||||
String basicConfigureTypeId= request.getParameter("id");
|
||||
Company company = this.unitService.getCompById(companyId);
|
||||
request.setAttribute("company", company);
|
||||
request.setAttribute("basicConfigureTypeId", basicConfigureTypeId);
|
||||
//request.setAttribute("list",list);
|
||||
return "base/basicConfigureAdd";
|
||||
}
|
||||
|
||||
@RequestMapping("/edit.do")
|
||||
public String doedit(HttpServletRequest request,Model model){
|
||||
String groupId = request.getParameter("id");
|
||||
BasicConfigure basicConfigure = this.basicConfigureService.selectById(groupId);
|
||||
model.addAttribute("basicConfigure", basicConfigure);
|
||||
return "base/basicConfigureEdit";
|
||||
}
|
||||
|
||||
@RequestMapping("/save.do")
|
||||
public String dosave(HttpServletRequest request,Model model,
|
||||
@ModelAttribute BasicConfigure basicConfigure){
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
String id = CommUtil.getUUID();
|
||||
basicConfigure.setId(id);
|
||||
basicConfigure.setInsuser(cu.getId());
|
||||
basicConfigure.setInsdt(CommUtil.nowDate());
|
||||
|
||||
int result =this.basicConfigureService.save(basicConfigure);
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+id+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
@RequestMapping("/update.do")
|
||||
public String doupdate(HttpServletRequest request,Model model,
|
||||
@ModelAttribute BasicConfigure basicConfigure){
|
||||
int result = this.basicConfigureService.update(basicConfigure);
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+basicConfigure.getId()+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/delete.do")
|
||||
public String dodel(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="id") String id){
|
||||
int result = this.basicConfigureService.deleteById(id);
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/deletes.do")
|
||||
public String dodels(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="ids") String ids){
|
||||
ids=ids.replace(",","','");
|
||||
int result = this.basicConfigureService.deleteByWhere("where id in ('"+ids+"')");
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
}
|
||||
215
src/com/sipai/controller/base/BasicHomePageController.java
Normal file
215
src/com/sipai/controller/base/BasicHomePageController.java
Normal file
@ -0,0 +1,215 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.sipai.entity.base.Result;
|
||||
import com.sipai.entity.user.Unit;
|
||||
import com.sipai.service.company.CompanyService;
|
||||
import com.sipai.tools.CommString;
|
||||
import net.sf.json.JSONArray;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sipai.entity.base.BasicHomePage;
|
||||
import com.sipai.entity.user.Company;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.service.base.BasicHomePageService;
|
||||
import com.sipai.service.user.UnitService;
|
||||
import com.sipai.tools.CommUtil;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/base/basicHomePage")
|
||||
public class BasicHomePageController {
|
||||
@Resource
|
||||
private BasicHomePageService basicHomePageService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
|
||||
@RequestMapping("/showlist.do")
|
||||
public String showlist(HttpServletRequest request, Model model) {
|
||||
return "/base/basicHomePageManage";
|
||||
}
|
||||
|
||||
@RequestMapping("/getlist.do")
|
||||
public ModelAndView getlist(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "rows") Integer rows,
|
||||
@RequestParam(value = "sort", required = false) String sort,
|
||||
@RequestParam(value = "order", required = false) String order) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
// if(cu==null){
|
||||
// cu=loginService.Login(request.getParameter("username"), request.getParameter("pwd"));
|
||||
// }
|
||||
String orderstr = " order by morder asc";
|
||||
|
||||
String wherestr = " where 1=1 ";
|
||||
if (request.getParameter("pid") != null && !request.getParameter("pid").toString().isEmpty()) {
|
||||
wherestr += " and pid ='" + request.getParameter("pid").toString() + "' ";
|
||||
}
|
||||
if (request.getParameter("type") != null && !request.getParameter("type").toString().isEmpty()) {
|
||||
wherestr += " and type ='" + request.getParameter("type").toString() + "' ";
|
||||
}
|
||||
PageHelper.startPage(page, rows);
|
||||
List<BasicHomePage> list = this.basicHomePageService.selectListByWhere(wherestr + orderstr);
|
||||
|
||||
PageInfo<BasicHomePage> pi = new PageInfo<BasicHomePage>(list);
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
|
||||
String result = "{\"total\":" + pi.getTotal() + ",\"rows\":" + json + "}";
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
@RequestMapping("/getJsonByUserId.do")
|
||||
public ModelAndView getJsonByUserId(HttpServletRequest request, Model model) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
String userId = cu.getId();
|
||||
String unitId = request.getParameter("unitId");
|
||||
// System.out.println("unitId==="+unitId);
|
||||
//分四步 1个人当前厂是否配置 2个人全局是否配置 3系统当前厂是否配置 4系统全局是否配置
|
||||
List<BasicHomePage> list = this.basicHomePageService.selectListByWhere(" where userid='" + userId + "' and unitId='" + unitId + "' and type='" + BasicHomePage.Type_Personal + "' and active='" + CommString.Active_True + "' ");
|
||||
if (list.size() == 0) {
|
||||
list = this.basicHomePageService.selectListByWhere(" where userid='" + userId + "' and unitId='all' and type='" + BasicHomePage.Type_Personal + "' and active='" + CommString.Active_True + "' ");
|
||||
if (list.size() == 0) {
|
||||
list = this.basicHomePageService.selectListByWhere(" where unitId='" + unitId + "' and type='" + BasicHomePage.Type_Sys + "' and active='" + CommString.Active_True + "' ");
|
||||
if (list.size() == 0) {
|
||||
list = this.basicHomePageService.selectListByWhere(" where unitId='all' and type='" + BasicHomePage.Type_Sys + "' and active='" + CommString.Active_True + "' ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jsonObject.put("data", list);
|
||||
jsonObject.put("userId", userId);
|
||||
|
||||
model.addAttribute("result", jsonObject);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
@RequestMapping("/add.do")
|
||||
public String doadd(HttpServletRequest request, Model model) {
|
||||
|
||||
return "base/basicHomePageAdd";
|
||||
}
|
||||
|
||||
@RequestMapping("/roleManage.do")
|
||||
public String roleManage(HttpServletRequest request, Model model) {
|
||||
|
||||
return "base/basicHomePageRoleManage";
|
||||
}
|
||||
|
||||
@RequestMapping("/roleEdit.do")
|
||||
public String roleEdit(HttpServletRequest request, Model model) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
String unitId = request.getParameter("unitId");
|
||||
List<BasicHomePage> list = this.basicHomePageService.selectListByWhere(" where unitId='" + unitId + "' and userid='emp01' ");
|
||||
|
||||
if (list != null && list.size() > 0) {
|
||||
model.addAttribute("basicHomePage", list.get(0));
|
||||
return "base/basicHomePageRoleEdit";
|
||||
} else {
|
||||
return "base/basicHomePageAdd";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/edit.do")
|
||||
public String doedit(HttpServletRequest request, Model model) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
String unitId = request.getParameter("unitId");
|
||||
List<BasicHomePage> list = this.basicHomePageService.selectListByWhere(" where unitId='" + unitId + "' and userid='" + cu.getId() + "' ");
|
||||
|
||||
model.addAttribute("userId", cu.getId());
|
||||
if (list != null && list.size() > 0) {
|
||||
model.addAttribute("basicHomePage", list.get(0));
|
||||
return "base/basicHomePageEdit";
|
||||
} else {
|
||||
return "base/basicHomePageAdd";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/save.do")
|
||||
public String dosave(HttpServletRequest request, Model model,
|
||||
@ModelAttribute BasicHomePage basicHomePage) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
String id = CommUtil.getUUID();
|
||||
basicHomePage.setId(id);
|
||||
basicHomePage.setUserid(cu.getId());
|
||||
if (cu.getId().equals("emp01")) {
|
||||
basicHomePage.setType(BasicHomePage.Type_Sys);
|
||||
} else {
|
||||
basicHomePage.setType(BasicHomePage.Type_Personal);
|
||||
}
|
||||
|
||||
int result = this.basicHomePageService.save(basicHomePage);
|
||||
String resstr = "{\"res\":\"" + result + "\",\"id\":\"" + id + "\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/update.do")
|
||||
public String doupdate(HttpServletRequest request, Model model,
|
||||
@ModelAttribute BasicHomePage basicHomePage) {
|
||||
int result = this.basicHomePageService.update(basicHomePage);
|
||||
String resstr = "{\"res\":\"" + result + "\",\"id\":\"" + basicHomePage.getId() + "\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/delete.do")
|
||||
public String dodel(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "id") String id) {
|
||||
int res = this.basicHomePageService.deleteById(id);
|
||||
if (res == 1) {
|
||||
Result result = Result.success(res);
|
||||
model.addAttribute("result", CommUtil.toJson(result));
|
||||
} else {
|
||||
Result result = Result.failed("保存失败");
|
||||
model.addAttribute("result", CommUtil.toJson(result));
|
||||
}
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/deletes.do")
|
||||
public String dodels(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "ids") String ids) {
|
||||
ids = ids.replace(",", "','");
|
||||
int result = this.basicHomePageService.deleteByWhere("where id in ('" + ids + "')");
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树状结构
|
||||
*/
|
||||
@RequestMapping("/getBasicHomePageForTree.do")
|
||||
public String getBasicHomePageForTree(HttpServletRequest request, Model model) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
String unitId = request.getParameter("unitId");
|
||||
//获取非用户节点树(公司 水厂 部门)
|
||||
List<Unit> list = this.unitService.getParentCompanyChildrenBizByUnitid(unitId);
|
||||
String json = basicHomePageService.getTreeList(null, list);
|
||||
model.addAttribute("result", json);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/showNoRole.do")
|
||||
public String showNoRole(HttpServletRequest request, Model model) {
|
||||
|
||||
return "base/basicHomePageNoRole";
|
||||
}
|
||||
}
|
||||
220
src/com/sipai/controller/base/CSVFileUtil.java
Normal file
220
src/com/sipai/controller/base/CSVFileUtil.java
Normal file
@ -0,0 +1,220 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CSVFileUtil {
|
||||
// CSV文件编码
|
||||
public static final String ENCODE = "GBK";
|
||||
|
||||
private FileInputStream fis = null;
|
||||
private InputStreamReader isw = null;
|
||||
private BufferedReader br = null;
|
||||
|
||||
|
||||
public CSVFileUtil(String filename) throws Exception {
|
||||
fis = new FileInputStream(filename);
|
||||
isw = new InputStreamReader(fis, ENCODE);
|
||||
br = new BufferedReader(isw);
|
||||
}
|
||||
|
||||
// ==========以下是公开方法=============================
|
||||
/**
|
||||
* 从CSV文件流中读取一个CSV行。
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public String readLine() throws Exception {
|
||||
|
||||
StringBuffer readLine = new StringBuffer();
|
||||
boolean bReadNext = true;
|
||||
|
||||
while (bReadNext) {
|
||||
//
|
||||
if (readLine.length() > 0) {
|
||||
readLine.append("\r\n");
|
||||
}
|
||||
// 一行
|
||||
String strReadLine = br.readLine();
|
||||
|
||||
// readLine is Null
|
||||
if (strReadLine == null) {
|
||||
return null;
|
||||
}
|
||||
readLine.append(strReadLine);
|
||||
|
||||
// 如果双引号是奇数的时候继续读取。考虑有换行的是情况。
|
||||
if (countChar(readLine.toString(), '"', 0) % 2 == 1) {
|
||||
bReadNext = true;
|
||||
} else {
|
||||
bReadNext = false;
|
||||
}
|
||||
}
|
||||
return readLine.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*把CSV文件的一行转换成字符串数组。指定数组长度,不够长度的部分设置为null。
|
||||
*/
|
||||
public static String[] fromCSVLine(String source, int size) {
|
||||
ArrayList tmpArray = fromCSVLinetoArray(source);
|
||||
if (size < tmpArray.size()) {
|
||||
size = tmpArray.size();
|
||||
}
|
||||
String[] rtnArray = new String[size];
|
||||
tmpArray.toArray(rtnArray);
|
||||
return rtnArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把CSV文件的一行转换成字符串数组。不指定数组长度。
|
||||
*/
|
||||
public static ArrayList fromCSVLinetoArray(String source) {
|
||||
if (source == null || source.length() == 0) {
|
||||
return new ArrayList();
|
||||
}
|
||||
int currentPosition = 0;
|
||||
int maxPosition = source.length();
|
||||
int nextComma = 0;
|
||||
ArrayList rtnArray = new ArrayList();
|
||||
while (currentPosition < maxPosition) {
|
||||
nextComma = nextComma(source, currentPosition);
|
||||
rtnArray.add(nextToken(source, currentPosition, nextComma));
|
||||
currentPosition = nextComma + 1;
|
||||
if (currentPosition == maxPosition) {
|
||||
rtnArray.add("");
|
||||
}
|
||||
}
|
||||
return rtnArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把字符串类型的数组转换成一个CSV行。(输出CSV文件的时候用)
|
||||
*/
|
||||
public static String toCSVLine(String[] strArray) {
|
||||
if (strArray == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuffer cvsLine = new StringBuffer();
|
||||
for (int idx = 0; idx < strArray.length; idx++) {
|
||||
String item = addQuote(strArray[idx]);
|
||||
cvsLine.append(item);
|
||||
if (strArray.length - 1 != idx) {
|
||||
cvsLine.append(',');
|
||||
}
|
||||
}
|
||||
return cvsLine.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串类型的List转换成一个CSV行。(输出CSV文件的时候用)
|
||||
*/
|
||||
public static String toCSVLine(ArrayList strArrList) {
|
||||
if (strArrList == null) {
|
||||
return "";
|
||||
}
|
||||
String[] strArray = new String[strArrList.size()];
|
||||
for (int idx = 0; idx < strArrList.size(); idx++) {
|
||||
strArray[idx] = (String) strArrList.get(idx);
|
||||
}
|
||||
return toCSVLine(strArray);
|
||||
}
|
||||
|
||||
// ==========以下是内部使用的方法=============================
|
||||
/**
|
||||
*计算指定文字的个数。
|
||||
*
|
||||
* @param str 文字列
|
||||
* @param c 文字
|
||||
* @param start 开始位置
|
||||
* @return 个数
|
||||
*/
|
||||
private int countChar(String str, char c, int start) {
|
||||
int i = 0;
|
||||
int index = str.indexOf(c, start);
|
||||
return index == -1 ? i : countChar(str, c, index + 1) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询下一个逗号的位置。
|
||||
*
|
||||
* @param source 文字列
|
||||
* @param st 检索开始位置
|
||||
* @return 下一个逗号的位置。
|
||||
*/
|
||||
private static int nextComma(String source, int st) {
|
||||
int maxPosition = source.length();
|
||||
boolean inquote = false;
|
||||
while (st < maxPosition) {
|
||||
char ch = source.charAt(st);
|
||||
if (!inquote && ch == ',') {
|
||||
break;
|
||||
} else if ('"' == ch) {
|
||||
inquote = !inquote;
|
||||
}
|
||||
st++;
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得下一个字符串
|
||||
*/
|
||||
private static String nextToken(String source, int st, int nextComma) {
|
||||
StringBuffer strb = new StringBuffer();
|
||||
int next = st;
|
||||
while (next < nextComma) {
|
||||
char ch = source.charAt(next++);
|
||||
if (ch == '"') {
|
||||
if ((st + 1 < next && next < nextComma) && (source.charAt(next) == '"')) {
|
||||
strb.append(ch);
|
||||
next++;
|
||||
}
|
||||
} else {
|
||||
strb.append(ch);
|
||||
}
|
||||
}
|
||||
return strb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 在字符串的外侧加双引号。如果该字符串的内部有双引号的话,把"转换成""。
|
||||
*
|
||||
* @param item 字符串
|
||||
* @return 处理过的字符串
|
||||
*/
|
||||
private static String addQuote(String item) {
|
||||
if (item == null || item.length() == 0) {
|
||||
return "\"\"";
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append('"');
|
||||
for (int idx = 0; idx < item.length(); idx++) {
|
||||
char ch = item.charAt(idx);
|
||||
if ('"' == ch) {
|
||||
sb.append("\"\"");
|
||||
} else {
|
||||
sb.append(ch);
|
||||
}
|
||||
}
|
||||
sb.append('"');
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
* 关闭流
|
||||
*/
|
||||
public void close() {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
984
src/com/sipai/controller/base/FileUploadHelper.java
Normal file
984
src/com/sipai/controller/base/FileUploadHelper.java
Normal file
@ -0,0 +1,984 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.sipai.entity.enums.FileNameSpaceEnum;
|
||||
import com.sipai.entity.report.RptCreate;
|
||||
import com.sipai.entity.report.RptInfoSet;
|
||||
import com.sipai.service.report.RptCreateService;
|
||||
import com.sipai.service.report.RptInfoSetService;
|
||||
import com.sipai.tools.MinioProp;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.errors.*;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.axis.encoding.Base64;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sipai.entity.achievement.AcceptanceModelMPoint;
|
||||
import com.sipai.entity.base.CommonFile;
|
||||
import com.sipai.entity.base.Result;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.service.base.CommonFileService;
|
||||
import com.sipai.tools.CommUtil;
|
||||
import com.sipai.tools.FileUtil;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/base")
|
||||
public class FileUploadHelper {
|
||||
|
||||
private String BaseFolderName = "UploadFile";
|
||||
@Resource
|
||||
CommonFileService commonFileService;
|
||||
@Autowired
|
||||
private MinioProp minioProp;
|
||||
@Resource
|
||||
private RptInfoSetService rptInfoSetService;
|
||||
@Resource
|
||||
private RptCreateService rptCreateService;
|
||||
|
||||
/**
|
||||
* 显示上传页面
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @param masterid
|
||||
* @param mappernamespace
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "fileupload.do", method = RequestMethod.GET)
|
||||
public String fileupload(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterid") String masterid,
|
||||
@RequestParam(value = "mappernamespace") String mappernamespace) {
|
||||
model.addAttribute("mappernamespace", mappernamespace);
|
||||
model.addAttribute("masterid", masterid);
|
||||
return "base/fileupload";
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @param masterid
|
||||
* @param mappernamespace
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "uploadfile.do")
|
||||
public ModelAndView uploadFile(@RequestParam MultipartFile[] file, HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterid") String masterid,
|
||||
@RequestParam(value = "mappernamespace") String mappernamespace) throws IOException {
|
||||
String realPath = request.getSession().getServletContext().getRealPath("/");
|
||||
String pjName = request.getContextPath().substring(1, request.getContextPath().length());
|
||||
realPath = realPath.replace(pjName, BaseFolderName);
|
||||
|
||||
User user = (User) request.getSession().getAttribute("cu");
|
||||
String result = this.commonFileService.uploadFile(realPath, mappernamespace, masterid, user, file);
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @param id
|
||||
* @param mappernamespace
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "downloadFile.do")
|
||||
public ModelAndView downloadFile(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "key") String id, @RequestParam(value = "tbName") String tbName) throws IOException {
|
||||
List<CommonFile> commfiles = this.commonFileService.selectListByTableAWhere(tbName, "where id='" + id + "'");
|
||||
if (commfiles != null && commfiles.size() > 0) {
|
||||
FileUtil.downloadFile(response, commfiles.get(0).getFilename(), commfiles.get(0).getAbspath());
|
||||
} else {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件 用于记录和文件唯一对应的情况
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @param id
|
||||
* @param mappernamespace
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "downloadFileFromMasterid.do")
|
||||
public ModelAndView downloadFileFromMasterid(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "key") String id, @RequestParam(value = "tbName") String tbName) throws IOException {
|
||||
List<CommonFile> commfiles = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + id + "'");
|
||||
if (commfiles != null && commfiles.size() > 0) {
|
||||
FileUtil.downloadFile(response, commfiles.get(0).getFilename(), commfiles.get(0).getAbspath());
|
||||
} else {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @param id
|
||||
* @param mappernamespace
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "deletefile.do")
|
||||
public ModelAndView deletefile(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "id") String id,
|
||||
@RequestParam(value = "mappernamespace") String mappernamespace) throws IOException {
|
||||
CommonFile commfile = this.commonFileService.selectById(id, mappernamespace);
|
||||
int res = this.commonFileService.deleteById(id, mappernamespace);
|
||||
if (res > 0) {
|
||||
FileUtil.deleteFile(commfile.getAbspath());
|
||||
model.addAttribute("result", "删除成功");
|
||||
}
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主ID下的文件列表
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @param masterid
|
||||
* @param mappernamespace
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "getFileList.do")
|
||||
public ModelAndView getFileList(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterid") String masterid,
|
||||
@RequestParam(value = "mappernamespace") String mappernamespace) throws IOException {
|
||||
List<CommonFile> list = this.commonFileService.selectByMasterId(masterid, mappernamespace);
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
model.addAttribute("result", json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
@RequestMapping("/doimportExcel.do")
|
||||
public String doimportExcel(HttpServletRequest request, Model model) {
|
||||
return "/base/importExcel";
|
||||
}
|
||||
|
||||
@RequestMapping("/doPrint.do")
|
||||
public String doPrint(HttpServletRequest request, Model model) {
|
||||
return "/base/print";
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示上传页面-bootstrap-fileinput
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "fileinput.do")
|
||||
public String fileinput(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
return "base/fileinput";
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示上传页面-minio (文件)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "fileinputMinio.do")
|
||||
public String fileinputMinio(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
return "base/fileinputMinio";
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示上传页面-minio (图片)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "fileinputMinioPic.do")
|
||||
public String fileinputMinioPic(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
return "base/fileinputMinioPic";
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示上传页面-minio (模板上传页面)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "fileinputMinio_Report.do")
|
||||
public String fileinputMinio_Report(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
return "base/fileinputMinio_Report";
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示上传页面-minio (报表生成上传页面)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "fileinputMinio_Report_Creat.do")
|
||||
public String fileinputMinio_Report_Creat(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
return "base/fileinputMinio_Report_Creat";
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件通用接口
|
||||
*
|
||||
* @param request 请求体
|
||||
* @param dstFileName html上传组件中(input中name属性),上传文件体名称,通过此名称获取所有上传的文件map
|
||||
* @param reportGroupId (特殊)上传报告所述报告组id
|
||||
*/
|
||||
@RequestMapping(value = "inputFile.do")
|
||||
public ModelAndView inputFile(HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
Map<String, Object> ret = new HashMap<String, Object>();
|
||||
String masterId = request.getParameter("masterId");
|
||||
String tbName = request.getParameter("tbName");
|
||||
String nameSpace = request.getParameter("nameSpace");
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
//判断保存文件的路径是否存在
|
||||
String contextPath = request.getContextPath().replace("/", "");
|
||||
String filepathSever = request.getSession().getServletContext().getRealPath("");
|
||||
String filepath = filepathSever.replaceAll(contextPath, BaseFolderName + "/" + nameSpace + "/");
|
||||
File fileUploadPath = new File(filepath);
|
||||
if (!fileUploadPath.exists()) {
|
||||
//解决上传文件目录无法自动创建
|
||||
fileUploadPath.mkdirs();
|
||||
}
|
||||
|
||||
if (ServletFileUpload.isMultipartContent(request)) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
List<MultipartFile> fileList = multipartRequest.getFiles("filelist"); //控件id
|
||||
//for循环只执行一次
|
||||
for (MultipartFile item : fileList) {
|
||||
String fileName = ""; //当前上传文件全名称
|
||||
String fileType = ""; //当前上传文件类型
|
||||
String saveFileName = ""; //保存到服务器目录的文件名称
|
||||
String reportAddr = ""; //保存到服务器目录的文件全路径
|
||||
try {
|
||||
fileName = item.getOriginalFilename();
|
||||
fileType = item.getContentType();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||
saveFileName = dateFormat.format(new Date()) + fileName;
|
||||
reportAddr = fileUploadPath + "/" + saveFileName;
|
||||
reportAddr = reportAddr.replace("/", File.separator).replace("\\", File.separator);
|
||||
|
||||
File savedFile = new File(fileUploadPath, saveFileName);
|
||||
item.transferTo(savedFile);
|
||||
|
||||
//上传文件成功,保存文件信息到表reportDetail
|
||||
CommonFile commonFile = new CommonFile();
|
||||
commonFile.setId(CommUtil.getUUID());
|
||||
commonFile.setMasterid(masterId);
|
||||
commonFile.setFilename(fileName);
|
||||
commonFile.setType(fileType);
|
||||
commonFile.setAbspath(reportAddr);
|
||||
commonFile.setInsdt(CommUtil.nowDate());
|
||||
commonFile.setInsuser(cu.getId());
|
||||
commonFile.setSize((int) item.getSize());
|
||||
int res = commonFileService.insertByTable(tbName, commonFile);
|
||||
|
||||
if (res == 1) {
|
||||
ret.put("suc", true);
|
||||
ret.put("msg", commonFile.getId());
|
||||
} else {
|
||||
ret.put("suc", false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret.put("suc", false);
|
||||
ret.put("msg", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
String result = JSONObject.fromObject(ret).toString();
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "inputFilemore.do")
|
||||
public ModelAndView inputFilemore(HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
Map<String, Object> ret = new HashMap<String, Object>();
|
||||
String masterId = request.getParameter("masterId");
|
||||
String tbName = request.getParameter("tbName");
|
||||
String nameSpace = request.getParameter("nameSpace");
|
||||
String typeId = request.getParameter("typeId");
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
//判断保存文件的路径是否存在
|
||||
String contextPath = request.getContextPath().replace("/", "");
|
||||
String filepathSever = request.getSession().getServletContext().getRealPath("");
|
||||
String filepath = filepathSever.replaceAll(contextPath, BaseFolderName + "/" + nameSpace + "/");
|
||||
File fileUploadPath = new File(filepath);
|
||||
if (!fileUploadPath.exists()) {
|
||||
//解决上传文件目录无法自动创建
|
||||
fileUploadPath.mkdirs();
|
||||
}
|
||||
|
||||
if (ServletFileUpload.isMultipartContent(request)) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
List<MultipartFile> fileList = multipartRequest.getFiles("filelist"); //控件id
|
||||
//for循环只执行一次
|
||||
for (MultipartFile item : fileList) {
|
||||
String fileName = ""; //当前上传文件全名称
|
||||
String fileType = ""; //当前上传文件类型
|
||||
String saveFileName = ""; //保存到服务器目录的文件名称
|
||||
String reportAddr = ""; //保存到服务器目录的文件全路径
|
||||
try {
|
||||
fileName = item.getOriginalFilename();
|
||||
fileType = item.getContentType();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||
saveFileName = dateFormat.format(new Date()) + fileName;
|
||||
reportAddr = fileUploadPath + "/" + saveFileName;
|
||||
reportAddr = reportAddr.replace("/", File.separator).replace("\\", File.separator);
|
||||
|
||||
File savedFile = new File(fileUploadPath, saveFileName);
|
||||
item.transferTo(savedFile);
|
||||
|
||||
//上传文件成功,保存文件信息到表reportDetail
|
||||
CommonFile commonFile = new CommonFile();
|
||||
commonFile.setId(CommUtil.getUUID() + "-" + typeId);
|
||||
commonFile.setMasterid(masterId);
|
||||
commonFile.setFilename(fileName);
|
||||
commonFile.setType(fileType);
|
||||
commonFile.setAbspath(reportAddr);
|
||||
commonFile.setInsdt(CommUtil.nowDate());
|
||||
commonFile.setInsuser(cu.getId());
|
||||
commonFile.setSize((int) item.getSize());
|
||||
int res = commonFileService.insertByTable(tbName, commonFile);
|
||||
|
||||
if (res == 1) {
|
||||
ret.put("suc", true);
|
||||
ret.put("msg", commonFile.getId());
|
||||
} else {
|
||||
ret.put("suc", false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret.put("suc", false);
|
||||
ret.put("msg", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
String result = JSONObject.fromObject(ret).toString();
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件json
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "getInputFileList.do")
|
||||
public ModelAndView getInputFileList(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException {
|
||||
String masterId = request.getParameter("masterId");
|
||||
//masterId="56aa5f35dac644deb7b3938a79cf3fde";
|
||||
String tbName = request.getParameter("tbName");
|
||||
//String nameSpace = request.getParameter("nameSpace");
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + masterId + "'");
|
||||
/* String contextPath=request.getContextPath().replace("/", "");
|
||||
String filepathSever=request.getSession().getServletContext().getRealPath("");
|
||||
contextPath=request.getSession().getServletContext().getContextPath();*/
|
||||
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
model.addAttribute("result", json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件json - minio中
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "getInputFileList_minio.do")
|
||||
public ModelAndView getInputFileList_minio(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException, InvalidPortException, InvalidEndpointException, InvalidBucketNameException, InsufficientDataException, XmlPullParserException, ErrorResponseException, NoSuchAlgorithmException, NoResponseException, InvalidExpiresRangeException, InvalidKeyException, InvalidResponseException, InternalException {
|
||||
String masterId = request.getParameter("masterId");
|
||||
String tbName = request.getParameter("tbName");
|
||||
String bucketName = request.getParameter("bucketName");
|
||||
String type = request.getParameter("type");//文件类型,传需要的类型,不传则查所有 (image是图片、video是视频)
|
||||
|
||||
String wherestr = "where masterid='" + masterId + "'";
|
||||
if (type != null && !type.trim().equals("")) {
|
||||
wherestr += " and type like '%" + type + "%'";
|
||||
}
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, wherestr);
|
||||
for (CommonFile commonFile : list) {
|
||||
String path = commonFile.getAbspath();
|
||||
MinioClient minioClient2 = new MinioClient(minioProp.getEndPoint(), minioProp.getAccessKey(), minioProp.getSecretKey());
|
||||
|
||||
//直接读取图片地址 存在外网无法使用 后面都换成下面的流文件
|
||||
String obj = minioClient2.presignedGetObject(bucketName, path, 3600 * 24 * 7);
|
||||
commonFile.setAbspath(obj);
|
||||
|
||||
//解析成流文件 后面都用这个
|
||||
byte[] buffer = commonFileService.getInputStreamBytes(bucketName, path);
|
||||
String base = Base64.encode(buffer);
|
||||
commonFile.setStreamFile(base);
|
||||
}
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
model.addAttribute("result", json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件json - minio中 (List格式)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "getInputFileList_minio2.do")
|
||||
public ModelAndView getInputFileList_minio2(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException, InvalidPortException, InvalidEndpointException, InvalidBucketNameException, InsufficientDataException, XmlPullParserException, ErrorResponseException, NoSuchAlgorithmException, NoResponseException, InvalidExpiresRangeException, InvalidKeyException, InvalidResponseException, InternalException {
|
||||
String masterId = request.getParameter("masterId");
|
||||
String tbName = request.getParameter("tbName");
|
||||
String bucketName = request.getParameter("bucketName");
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + masterId + "'");
|
||||
for (CommonFile commonFile : list) {
|
||||
MinioClient minioClient2 = new MinioClient(minioProp.getEndPoint(), minioProp.getAccessKey(), minioProp.getSecretKey());
|
||||
String obj = minioClient2.presignedGetObject(bucketName, commonFile.getAbspath(), 3600 * 24 * 7);
|
||||
commonFile.setAbspath(obj);
|
||||
}
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
String result = "{\"total\":" + 1 + ",\"rows\":" + json + "}";
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件json - minio中 (为前台分页)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "getInputFileList_minio3.do")
|
||||
public ModelAndView getInputFileList_minio3(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException, InvalidPortException, InvalidEndpointException, InvalidBucketNameException, InsufficientDataException, XmlPullParserException, ErrorResponseException, NoSuchAlgorithmException, NoResponseException, InvalidExpiresRangeException, InvalidKeyException, InvalidResponseException, InternalException {
|
||||
String masterId = request.getParameter("masterId");
|
||||
String tbName = request.getParameter("tbName");
|
||||
String bucketName = request.getParameter("bucketName");
|
||||
|
||||
String sdt = request.getParameter("sdt");
|
||||
String edt = request.getParameter("edt");
|
||||
|
||||
String whereString = " where masterid='" + masterId + "' ";
|
||||
|
||||
if (sdt != null && sdt.length() > 0 && edt != null && edt.length() > 0) {
|
||||
whereString += " and insdt between '" + sdt + "' and '" + edt + "' ";
|
||||
}
|
||||
if (request.getParameter("pointId") != null && request.getParameter("pointId").length() > 0) {
|
||||
whereString += " and pointId='" + request.getParameter("pointId") + "' ";
|
||||
}
|
||||
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, whereString + " order by insdt desc");
|
||||
// for (CommonFile commonFile : list) {
|
||||
// MinioClient minioClient2 = new MinioClient(minioProp.getEndPoint(), minioProp.getAccessKey(), minioProp.getSecretKey());
|
||||
// String obj = minioClient2.presignedGetObject(bucketName, commonFile.getAbspath(), 3600 * 24 * 7);
|
||||
// commonFile.setAbspath(obj);
|
||||
// }
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
model.addAttribute("result", json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "getInputFileList2.do")
|
||||
public String getInputFileList2(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException, InvalidBucketNameException, InsufficientDataException, XmlPullParserException, ErrorResponseException, NoSuchAlgorithmException, NoResponseException, InvalidKeyException, InvalidResponseException, InternalException, InvalidPortException, InvalidEndpointException, InvalidExpiresRangeException {
|
||||
String bucketName = "maintenance";
|
||||
String objectName = "2021-09-07-10-06-5811111111.png";
|
||||
MinioClient minioClient2 = new MinioClient("http://127.0.0.1:9000", "sipai", "ZAQwsx@2008");
|
||||
String obj = minioClient2.presignedGetObject(bucketName, objectName, 3600 * 24 * 7);
|
||||
// System.out.println(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "getInputFileTableList.do")
|
||||
public String getInputFileTableList(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "rows") Integer rows,
|
||||
@RequestParam(value = "sort", required = false) String sort,
|
||||
@RequestParam(value = "order", required = false) String order) {
|
||||
PageHelper.startPage(page, rows);
|
||||
String masterId = request.getParameter("masterId");
|
||||
String tbName = request.getParameter("tbName");
|
||||
//String nameSpace = request.getParameter("nameSpace");
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + masterId + "' order by insdt desc");
|
||||
PageInfo<CommonFile> pi = new PageInfo<CommonFile>(list);
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
String result = "{\"total\":" + pi.getTotal() + ",\"rows\":" + json + "}";
|
||||
model.addAttribute("result", result);
|
||||
return ("result");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "deleteInputFile.do")
|
||||
public String deleteInputFile(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "key") String id, @RequestParam(value = "tbName") String tbName) throws IOException {
|
||||
int code = 0;
|
||||
Map<String, Object> ret = new HashMap<String, Object>();
|
||||
List<CommonFile> commfiles = this.commonFileService.selectListByTableAWhere(tbName, "where id='" + id + "'");
|
||||
|
||||
if (commfiles != null && commfiles.size() > 0) {
|
||||
File file = new File(commfiles.get(0).getAbspath());
|
||||
if (file.exists()) {
|
||||
file.delete();//删除文件
|
||||
}
|
||||
code = this.commonFileService.deleteByTableAWhere(tbName, "where id='" + id + "'");
|
||||
Result result = new Result();
|
||||
if (code == Result.SUCCESS) {
|
||||
result = Result.success(code);
|
||||
} else {
|
||||
result = Result.failed("删除失败");
|
||||
}
|
||||
model.addAttribute("result", CommUtil.toJson(result));
|
||||
}
|
||||
return "result";
|
||||
}
|
||||
|
||||
//用于记录和文件唯一对应的情况
|
||||
@RequestMapping(value = "deleteInputFileFromMasterid.do")
|
||||
public String deleteInputFileFromMasterid(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "key") String id, @RequestParam(value = "tbName") String tbName) throws IOException {
|
||||
int code = 0;
|
||||
Map<String, Object> ret = new HashMap<String, Object>();
|
||||
List<CommonFile> commfiles = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + id + "'");
|
||||
|
||||
if (commfiles != null && commfiles.size() > 0) {
|
||||
File file = new File(commfiles.get(0).getAbspath());
|
||||
if (file.exists()) {
|
||||
file.delete();//删除文件
|
||||
}
|
||||
code = this.commonFileService.deleteByTableAWhere(tbName, "where masterid='" + id + "'");
|
||||
Result result = new Result();
|
||||
if (code == Result.SUCCESS) {
|
||||
result = Result.success(code);
|
||||
} else {
|
||||
result = Result.failed("删除失败");
|
||||
}
|
||||
model.addAttribute("result", CommUtil.toJson(result));
|
||||
}
|
||||
return "result";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存PDF临时文档,返回文档地址
|
||||
*/
|
||||
@RequestMapping("/getPDFUrl.do")
|
||||
public ModelAndView getPDFUrl(HttpServletRequest request, Model model) {
|
||||
|
||||
String htmlStr = request.getParameter("htmlStr");
|
||||
String realPath = request.getSession().getServletContext().getRealPath("/");
|
||||
String pjName = request.getContextPath().substring(1, request.getContextPath().length());
|
||||
realPath = realPath.replace(pjName, BaseFolderName);
|
||||
realPath += "TempFiles\\";
|
||||
File dir = new File(realPath);
|
||||
if (!dir.exists()) {
|
||||
try {
|
||||
dir.mkdir();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
dir = null;
|
||||
String fileName = CommUtil.getUUID() + ".pdf";
|
||||
realPath += fileName;
|
||||
PDFFileUtil.html2Pdf(realPath, htmlStr);
|
||||
String result = "{\"res\":\"" + realPath.substring(realPath.indexOf(BaseFolderName), realPath.length()).replace("\\", "/") + "\"}";
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程审核上传资料页面
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "fileInputForProcess.do")
|
||||
public String fileInputForProcess(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
return "base/fileInputForProcess";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "fileInputForProcessmore.do")
|
||||
public String fileInputForProcessmore(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace, @RequestParam(value = "typeId") String typeId) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
model.addAttribute("typeId", typeId);
|
||||
return "base/fileInputForProcessMore";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "fileInputForProcessmore1.do")
|
||||
public String fileInputForProcessmore1(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace, @RequestParam(value = "typeId") String typeId) {
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
model.addAttribute("typeId", typeId);
|
||||
return "base/fileInputForProcessMore1";
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据id获取单个文件
|
||||
*/
|
||||
@RequestMapping(value = "getInputFile4Id.do")
|
||||
public ModelAndView getInputFile4Id(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException {
|
||||
String id = request.getParameter("id");
|
||||
String tbName = request.getParameter("tbName");
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, "where id='" + id + "'");
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
model.addAttribute("result", json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* minio 文件上传 (通用)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "updateFile.do")
|
||||
public ModelAndView updateFile(HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
Map<String, Object> ret = new HashMap<String, Object>();
|
||||
String masterId = request.getParameter("masterId");
|
||||
String nameSpace = request.getParameter("nameSpace");
|
||||
String tbName = request.getParameter("tbName");
|
||||
if (nameSpace != null && !nameSpace.isEmpty()) {
|
||||
if (tbName == null || tbName.isEmpty()) {
|
||||
tbName = FileNameSpaceEnum.getTbName(nameSpace);
|
||||
}
|
||||
}
|
||||
if (ServletFileUpload.isMultipartContent(request)) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
List<MultipartFile> fileList = multipartRequest.getFiles("filelist"); //控件id
|
||||
//for循环只执行一次
|
||||
for (MultipartFile item : fileList) {
|
||||
try {
|
||||
int res = commonFileService.updateFile(masterId, nameSpace, tbName, item);
|
||||
|
||||
if (res == 1) {
|
||||
ret.put("suc", true);
|
||||
} else {
|
||||
ret.put("suc", false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret.put("suc", false);
|
||||
ret.put("msg", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
String result = JSONObject.fromObject(ret).toString();
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 以下方法为 minio 文件相关方法 (报表上传定制功能,其他模板最好不要使用)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "updateFile_creat.do")
|
||||
public ModelAndView updateFile_creat(HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
Map<String, Object> ret = new HashMap<String, Object>();
|
||||
String masterId = request.getParameter("masterId");
|
||||
String nameSpace = request.getParameter("nameSpace");
|
||||
// YYJ 20201229
|
||||
String tbName = request.getParameter("tbName");
|
||||
if (nameSpace != null && !nameSpace.isEmpty()) {
|
||||
if (tbName == null || tbName.isEmpty()) {
|
||||
tbName = FileNameSpaceEnum.getTbName(nameSpace);
|
||||
}
|
||||
}
|
||||
|
||||
if (ServletFileUpload.isMultipartContent(request)) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
List<MultipartFile> fileList = multipartRequest.getFiles("filelist"); //控件id
|
||||
//for循环只执行一次
|
||||
for (MultipartFile item : fileList) {
|
||||
try {
|
||||
String uuid = CommUtil.getUUID();
|
||||
int res = commonFileService.updateFile_creat(masterId, nameSpace, tbName, item, uuid);
|
||||
if (res == 1) {
|
||||
|
||||
RptInfoSet rptInfoSet = rptInfoSetService.selectById(masterId);
|
||||
if (rptInfoSet != null) {
|
||||
String rptname = item.getOriginalFilename();
|
||||
|
||||
RptCreate rptCreate = new RptCreate();
|
||||
rptCreate.setId(uuid);
|
||||
rptCreate.setInsdt(CommUtil.nowDate());
|
||||
rptCreate.setInsuser(cu.getId());
|
||||
rptCreate.setUpsdt(CommUtil.nowDate());
|
||||
rptCreate.setUpsuser(cu.getId());
|
||||
|
||||
rptname = rptname.replace(".xls", "");
|
||||
rptname = rptname.replace(".xlsx", "");
|
||||
|
||||
rptCreate.setRptname(rptname);
|
||||
rptCreate.setRptdt(CommUtil.nowDate());
|
||||
rptCreate.setUnitId(rptInfoSet.getUnitId());
|
||||
rptCreate.setRptsetId(masterId);
|
||||
rptCreateService.save2(rptCreate);
|
||||
}
|
||||
|
||||
ret.put("suc", true);
|
||||
} else {
|
||||
ret.put("suc", false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret.put("suc", false);
|
||||
ret.put("msg", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
String result = JSONObject.fromObject(ret).toString();
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "getInputFileListById.do")
|
||||
public ModelAndView getInputFileListById(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException {
|
||||
String id = request.getParameter("id");
|
||||
String masterId = request.getParameter("masterId");
|
||||
//masterId="56aa5f35dac644deb7b3938a79cf3fde";
|
||||
String tbName = request.getParameter("tbName");
|
||||
//String nameSpace = request.getParameter("nameSpace");
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, "where id='" + id + "'");
|
||||
/* String contextPath=request.getContextPath().replace("/", "");
|
||||
String filepathSever=request.getSession().getServletContext().getRealPath("");
|
||||
contextPath=request.getSession().getServletContext().getContextPath();*/
|
||||
if (list != null && list.size() > 0) {
|
||||
String typeString = list.get(0).getType();
|
||||
if (typeString.contains("word") || typeString.contains("sheet") ||
|
||||
typeString.contains("excel") || typeString.contains("presentation") ||
|
||||
typeString.contains("powerpoint")) {
|
||||
List<CommonFile> masterlist = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + id + "'");
|
||||
if (masterlist != null && masterlist.size() > 0) {
|
||||
if (masterlist.get(0).getSize() > 0) {
|
||||
list = masterlist;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + masterId + "'");
|
||||
if (list != null && list.size() > 0) {
|
||||
String typeString = list.get(0).getType();
|
||||
if (typeString.contains("word") || typeString.contains("sheet") ||
|
||||
typeString.contains("excel") || typeString.contains("presentation") ||
|
||||
typeString.contains("powerpoint")) {
|
||||
List<CommonFile> masterlist = this.commonFileService.selectListByTableAWhere(tbName, "where masterid='" + id + "'");
|
||||
if (masterlist != null && masterlist.size() > 0) {
|
||||
if (masterlist.get(0).getSize() > 0) {
|
||||
list = masterlist;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
model.addAttribute("result", json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "showFileOnlinePic.do")
|
||||
public String showFileOnlinePic(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model, @RequestParam(value = "id") String id, @RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "tbName") String tbName, @RequestParam(value = "nameSpace") String nameSpace) {
|
||||
model.addAttribute("id", id);
|
||||
model.addAttribute("tbName", tbName);
|
||||
model.addAttribute("masterId", masterId);
|
||||
model.addAttribute("nameSpace", nameSpace);
|
||||
model.addAttribute("sdt", request.getParameter("sdt"));
|
||||
model.addAttribute("edt", request.getParameter("edt"));
|
||||
return "base/fileOnlinePic";
|
||||
}
|
||||
|
||||
/**
|
||||
* 为获取图片相关,用于前台切换
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "getPicSwitchJson.do")
|
||||
public ModelAndView getPicSwitchJson(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
String masterId = request.getParameter("masterId");
|
||||
String tbName = request.getParameter("tbName");
|
||||
String id = request.getParameter("id");
|
||||
|
||||
String sdt = request.getParameter("sdt");
|
||||
String edt = request.getParameter("edt");
|
||||
|
||||
String whereString = " where masterid='" + masterId + "' ";
|
||||
|
||||
if (sdt != null && sdt.length() > 0 && edt != null && edt.length() > 0) {
|
||||
whereString += " and insdt between '" + sdt + "' and '" + edt + "' ";
|
||||
}
|
||||
|
||||
int nowFilePosition = -1;
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, whereString + " order by insdt desc ");
|
||||
if (list != null && list.size() > 0) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
CommonFile commonFile = list.get(i);
|
||||
if (commonFile.getId().equals(id)) {
|
||||
nowFilePosition = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
JSONArray json = JSONArray.fromObject(list);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("firstNum", nowFilePosition);
|
||||
jsonObject.put("list", json);
|
||||
model.addAttribute("result", jsonObject);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
/**
|
||||
* 为获取图片相关,用于前台切换
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "getNowPicFromSwitch.do")
|
||||
public ModelAndView getNowPicFromSwitch(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException, InvalidPortException, InvalidEndpointException, InvalidBucketNameException, InsufficientDataException, XmlPullParserException, ErrorResponseException, NoSuchAlgorithmException, NoResponseException, InvalidExpiresRangeException, InvalidKeyException, InvalidResponseException, InternalException {
|
||||
String tbName = request.getParameter("tbName");
|
||||
String bucketName = request.getParameter("bucketName");
|
||||
String id = request.getParameter("id");
|
||||
|
||||
List<CommonFile> list = this.commonFileService.selectListByTableAWhere(tbName, " where id='" + id + "' ");
|
||||
if (list != null && list.size() > 0) {
|
||||
CommonFile commonFile = list.get(0);
|
||||
String path = commonFile.getAbspath();
|
||||
MinioClient minioClient2 = new MinioClient(minioProp.getEndPoint(), minioProp.getAccessKey(), minioProp.getSecretKey());
|
||||
|
||||
//直接读取图片地址 存在外网无法使用 后面都换成下面的流文件
|
||||
String obj = minioClient2.presignedGetObject(bucketName, path, 3600 * 24 * 7);
|
||||
commonFile.setAbspath(obj);
|
||||
|
||||
//解析成流文件 后面都用这个
|
||||
byte[] buffer = commonFileService.getInputStreamBytes(bucketName, path);
|
||||
String base = Base64.encode(buffer);
|
||||
commonFile.setStreamFile(base);
|
||||
|
||||
JSONArray json = JSONArray.fromObject(commonFile);
|
||||
// System.out.println(json);
|
||||
model.addAttribute("result", json);
|
||||
}
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
}
|
||||
22
src/com/sipai/controller/base/FreemarkerConfiguration.java
Normal file
22
src/com/sipai/controller/base/FreemarkerConfiguration.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
|
||||
public class FreemarkerConfiguration {
|
||||
private static Configuration config = null;
|
||||
|
||||
/**
|
||||
* Static initialization.
|
||||
*
|
||||
* Initialize the configuration of Freemarker.
|
||||
*/
|
||||
static{
|
||||
config = new Configuration();
|
||||
config.setClassForTemplateLoading(FreemarkerConfiguration.class, "template");
|
||||
}
|
||||
|
||||
public static Configuration getConfiguation(){
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
41
src/com/sipai/controller/base/HtmlGenerator.java
Normal file
41
src/com/sipai/controller/base/HtmlGenerator.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
|
||||
public class HtmlGenerator {
|
||||
/**
|
||||
* Generate html string.
|
||||
*
|
||||
* @param template the name of freemarker teamlate.
|
||||
* @param variables the data of teamlate.
|
||||
* @return htmlStr
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String generate(String templateFile, Map<String,Object> variables) throws Exception{
|
||||
File file = new File(templateFile);
|
||||
if(!file.exists())
|
||||
throw new Exception("模板文件不存在:"+templateFile);
|
||||
|
||||
String templateDir = file.getParentFile().getPath();
|
||||
String templateName =file.getName();
|
||||
Configuration config = FreemarkerConfiguration.getConfiguation();
|
||||
//用于解决前端报空指针问题-->
|
||||
config.setClassicCompatible(true);
|
||||
config.setDirectoryForTemplateLoading(new File(templateDir));
|
||||
Template tp = config.getTemplate(templateName);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
BufferedWriter writer = new BufferedWriter(stringWriter);
|
||||
tp.setEncoding("UTF-8");
|
||||
tp.process(variables, writer);
|
||||
String htmlStr = stringWriter.toString();
|
||||
writer.flush();
|
||||
writer.close();
|
||||
return htmlStr;
|
||||
}
|
||||
}
|
||||
680
src/com/sipai/controller/base/LoginServlet.java
Normal file
680
src/com/sipai/controller/base/LoginServlet.java
Normal file
@ -0,0 +1,680 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sipai.entity.base.BasicComponents;
|
||||
import com.sipai.entity.base.BasicConfigure;
|
||||
import com.sipai.entity.base.Result;
|
||||
import com.sipai.entity.user.*;
|
||||
import com.sipai.security.MyUserDetailServiceImpl;
|
||||
import com.sipai.service.base.BasicComponentsService;
|
||||
import com.sipai.service.base.LoginService;
|
||||
import com.sipai.service.user.*;
|
||||
import com.sipai.tools.CommString;
|
||||
import com.sipai.tools.CommUtil;
|
||||
import com.sipai.tools.JwtUtil;
|
||||
import com.sipai.tools.SessionManager;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||
import org.springframework.security.core.context.SecurityContextImpl;
|
||||
import org.springframework.security.web.WebAttributes;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
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 javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "Login")
|
||||
@Api(value = "Login", tags = "登录")
|
||||
public class LoginServlet {
|
||||
|
||||
@Resource
|
||||
private LoginService loginService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
|
||||
@Resource
|
||||
private UserDetailService userDetailService;
|
||||
|
||||
@Resource
|
||||
private MyUserDetailServiceImpl myUserDetailServiceImpl;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@Resource
|
||||
private ExtSystemService extSystemService;
|
||||
@Resource
|
||||
private BasicComponentsService basicComponentsService;
|
||||
|
||||
@RequestMapping(value = "login.do", method = RequestMethod.GET)
|
||||
public ModelAndView login(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
String password = null;
|
||||
if(session.getAttribute("password")!=null){
|
||||
password = session.getAttribute("password").toString();
|
||||
}
|
||||
if (SessionManager.isOnline(session)) {
|
||||
/*User cu= (User)request.getSession().getAttribute("cu");
|
||||
List<Menu> list = this.menuService.getFullPower(cu.getId());
|
||||
if(list!=null &&list.size()>0){
|
||||
for(int i=list.size()-1;i>=0;i--){
|
||||
Menu menu=list.get(i);
|
||||
if((menu.getType() !=null && menu.getType().equals("func"))
|
||||
|| (menu.getActive() !=null && menu.getActive().equals("禁用"))){
|
||||
list.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
model.addAttribute("list",list);*/
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
if (cu != null) {
|
||||
JSONObject basicPW = basicPassword(password,cu.getId());
|
||||
String code =basicPW.get("code").toString();
|
||||
if("1".equals(code)){
|
||||
//需要跳转
|
||||
//修改密码配置信息
|
||||
JSONArray jsonArray = basicComponentsService.selectListByWhereAll("where active='1' and code like '%password%' order by morder ");
|
||||
if (jsonArray != null && jsonArray.size() > 0) {
|
||||
model.addAttribute("jsonArray", jsonArray);
|
||||
}
|
||||
if(basicPW.get("titleStr")!=null && !basicPW.get("titleStr").toString().isEmpty()){
|
||||
model.addAttribute("titleStr", basicPW.get("titleStr").toString());
|
||||
}
|
||||
return new ModelAndView("forcePasswordChange");
|
||||
}
|
||||
if (cu.getName().equals("admin")) {
|
||||
model.addAttribute("mqttId", cu.getName() + "_web_" + CommUtil.getUUID());
|
||||
} else {
|
||||
model.addAttribute("mqttId", cu.getName() + "_web");
|
||||
}
|
||||
|
||||
Unit unit = this.unitService.getUserBelongingCompany(cu.getId());
|
||||
if (unit != null) {
|
||||
model.addAttribute("top_user_companyId", unit.getId());
|
||||
model.addAttribute("top_user_companyType", unit.getType());
|
||||
}
|
||||
model.addAttribute("top_userId", cu.getId());
|
||||
|
||||
}
|
||||
return new ModelAndView("frameset");
|
||||
}
|
||||
try {
|
||||
//默认使用login-title、login-bottomlogo作为登录页所需代码
|
||||
JSONArray jsonArray = basicComponentsService.selectListByWhereAll("where active='1' and code like '%login%' order by morder ");
|
||||
if (jsonArray != null && jsonArray.size() > 0) {
|
||||
model.addAttribute("jsonArray", jsonArray);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ModelAndView("login");
|
||||
}
|
||||
@ApiOperation(value = "判断密码情况", notes = "判断密码情况", httpMethod = "GET")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "loginCheck.do", method = RequestMethod.GET)
|
||||
public ModelAndView loginCheck(HttpServletRequest request,HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
String password = null;
|
||||
if(session.getAttribute("password")!=null){
|
||||
password = session.getAttribute("password").toString();
|
||||
}
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
JSONObject basicPW = basicPassword(password,cu.getId());
|
||||
String code =basicPW.get("code").toString();
|
||||
int passwordMaxNum =18;
|
||||
int passwordMinNum =10;
|
||||
List<BasicComponents> passwordMax_list = basicComponentsService.selectListByWhere("where active='1' and code like '%password-max%' order by morder");
|
||||
if (passwordMax_list != null && passwordMax_list.size() > 0) {
|
||||
BasicComponents passwordMax = passwordMax_list.get(0);
|
||||
passwordMaxNum = Integer.parseInt(passwordMax.getBasicConfigure().getType());
|
||||
}
|
||||
List<BasicComponents> passwordMin_list = basicComponentsService.selectListByWhere("where active='1' and code like '%password-min%' order by morder");
|
||||
if (passwordMin_list != null && passwordMin_list.size() > 0) {
|
||||
BasicComponents passwordMin = passwordMin_list.get(0);
|
||||
passwordMinNum = Integer.parseInt(passwordMin.getBasicConfigure().getType());
|
||||
}
|
||||
String result = "{\"code\":" + code + ",\"passwordMax\":\"" + passwordMaxNum + "\",\"passwordMin\":\"" + passwordMinNum + "\"}";
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
protected JSONObject basicPassword(String password,String userId) {
|
||||
JSONObject res = new JSONObject();
|
||||
String default_password = CommUtil.generatePassword(UserCommStr.default_password);
|
||||
//验证当前账号密码是否为默认密码,强制修改
|
||||
if (default_password.equals(password)) {
|
||||
res.put("code", 1);
|
||||
return res;
|
||||
//return new ModelAndView("forcePasswordChange");
|
||||
}
|
||||
//验证是否判断密码为强密码
|
||||
List<BasicComponents> passwordType_list = basicComponentsService.selectListByWhere("where active='1' and code like '%password-type%' order by morder");
|
||||
if (passwordType_list != null && passwordType_list.size() > 0) {
|
||||
BasicComponents passwordTypes = passwordType_list.get(0);
|
||||
String passwordType = passwordTypes.getBasicConfigure().getType();
|
||||
int passwordMaxNum =18;
|
||||
int passwordMinNum =10;
|
||||
List<BasicComponents> passwordMax_list = basicComponentsService.selectListByWhere("where active='1' and code like '%password-max%' order by morder");
|
||||
if (passwordMax_list != null && passwordMax_list.size() > 0) {
|
||||
BasicComponents passwordMax = passwordMax_list.get(0);
|
||||
passwordMaxNum = Integer.parseInt(passwordMax.getBasicConfigure().getType());
|
||||
}
|
||||
List<BasicComponents> passwordMin_list = basicComponentsService.selectListByWhere("where active='1' and code like '%password-min%' order by morder");
|
||||
if (passwordMin_list != null && passwordMin_list.size() > 0) {
|
||||
BasicComponents passwordMin = passwordMin_list.get(0);
|
||||
passwordMinNum = Integer.parseInt(passwordMin.getBasicConfigure().getType());
|
||||
}
|
||||
//首先判断是否配置了需要强密码
|
||||
if("strong".equals(passwordType)){
|
||||
//再判断是否为强密码
|
||||
if(!CommUtil.isStrongPwd(password,passwordMinNum,passwordMaxNum)){
|
||||
//不是则修改密码
|
||||
res.put("code", 1);
|
||||
return res;
|
||||
//return new ModelAndView("forcePasswordChange");
|
||||
}
|
||||
}
|
||||
}
|
||||
//验证是否判断密码超时
|
||||
List<BasicComponents> basicComponents_list = basicComponentsService.selectListByWhere("where active='1' and code like '%password-overtime%' order by morder");
|
||||
if (basicComponents_list != null && basicComponents_list.size() > 0) {
|
||||
BasicComponents basicComponents = basicComponents_list.get(0);
|
||||
if (basicComponents != null && basicComponents.getBasicConfigure() != null) {
|
||||
BasicConfigure basicConfigure = basicComponents.getBasicConfigure();
|
||||
if (basicConfigure != null) {
|
||||
String initial_time = "";
|
||||
int days = 30;
|
||||
//type设置强制修改密码天数
|
||||
if (basicConfigure.getType() != null && !basicConfigure.getType().isEmpty()) {
|
||||
//验证是否为数字
|
||||
if (CommUtil.isNumeric(basicConfigure.getType())) {
|
||||
days = Integer.parseInt(basicConfigure.getType());
|
||||
}
|
||||
}
|
||||
UserDetail userDetail = userDetailService.selectByUserId(userId);
|
||||
if (userDetail != null) {
|
||||
if (userDetail.getLastlogintime() != null
|
||||
&& !userDetail.getLastlogintime().isEmpty()) {
|
||||
//用户附属表中Lastlogintime为初始判断时间
|
||||
initial_time = userDetail.getLastlogintime();
|
||||
} else {
|
||||
if (userDetail.getInsdt() != null
|
||||
&& !userDetail.getInsdt().isEmpty()) {
|
||||
//用户附属表中Insdt为初始判断时间
|
||||
initial_time = userDetail.getInsdt();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//insdt设置初始时间
|
||||
if (basicConfigure.getInsdt() != null && !basicConfigure.getInsdt().isEmpty()) {
|
||||
initial_time = basicConfigure.getInsdt();
|
||||
}
|
||||
}
|
||||
if (initial_time != null && !initial_time.isEmpty()) {
|
||||
String nowDate = CommUtil.nowDate();
|
||||
int difference = CommUtil.getDays(nowDate, initial_time);
|
||||
//当前时间与设置时间的差值大于强制修改密码天数,则跳转强制修改
|
||||
if (difference > days) {
|
||||
res.put("titleStr", "当前账号已超过" + days + "天未修改密码,为了安全起见,请修改密码。");
|
||||
res.put("code", 1);
|
||||
return res;
|
||||
//return new ModelAndView("forcePasswordChange");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res.put("code", 0);
|
||||
return res;
|
||||
}
|
||||
@RequestMapping(value = "main.do", method = RequestMethod.GET)
|
||||
public ModelAndView main(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
|
||||
String rptdt = CommUtil.nowDate().substring(0, 7);
|
||||
request.setAttribute("datestr", rptdt.substring(0, 4) + "");
|
||||
|
||||
return new ModelAndView("main");
|
||||
}
|
||||
|
||||
//上实
|
||||
// @RequestMapping(value = "main.do", method = RequestMethod.GET)
|
||||
// public ModelAndView main(HttpServletRequest request,
|
||||
// HttpServletResponse response,Model model) {
|
||||
// HttpSession session = request.getSession(false);
|
||||
// return new ModelAndView("/work/overviewProduceGroup");
|
||||
// }
|
||||
@RequestMapping(value = "main3.do", method = RequestMethod.GET)
|
||||
public ModelAndView main3(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return new ModelAndView("main3");
|
||||
}
|
||||
|
||||
/**
|
||||
* 重庆白羊摊首页
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "mainCQBYT.do", method = RequestMethod.GET)
|
||||
public ModelAndView mainCQBYT(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return new ModelAndView("main_CQBYT");
|
||||
}
|
||||
|
||||
/**
|
||||
* 金山首页 金山排海层级
|
||||
* sj 2021-09-17
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "main_JS_Company.do", method = RequestMethod.GET)
|
||||
public ModelAndView main_JS_Company(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return new ModelAndView("main_JS_Company");
|
||||
}
|
||||
|
||||
/**
|
||||
* 金山首页 分厂层级
|
||||
* sj 2021-09-17
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "main_JS_Factory.do", method = RequestMethod.GET)
|
||||
public ModelAndView main_JS_Factory(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return new ModelAndView("main_JS_Factory");
|
||||
}
|
||||
|
||||
/**
|
||||
* 淄博首页
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "mainZB.do", method = RequestMethod.GET)
|
||||
public ModelAndView mainZB(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return new ModelAndView("main_zibo");
|
||||
}
|
||||
|
||||
/**
|
||||
* 虹桥安全首页
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "mainHQAQ.do", method = RequestMethod.GET)
|
||||
public ModelAndView mainHQAQ(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return new ModelAndView("main_HQAQ");
|
||||
}
|
||||
/**
|
||||
* 注册页面
|
||||
*/
|
||||
@RequestMapping(value = "register.do", method = RequestMethod.GET)
|
||||
public ModelAndView register(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
String unitId = request.getParameter("unitId");
|
||||
Unit unit = unitService.getUnitById(unitId);
|
||||
request.setAttribute("unit", unit);
|
||||
return new ModelAndView("register");
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示所有厂区汇总信息
|
||||
*/
|
||||
@RequestMapping(value = "showStatisticalInfo.do")
|
||||
public ModelAndView showStatisticalInfo(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
ExtSystem extSystem = this.extSystemService.getActiveDataManage(null);
|
||||
String url = "";
|
||||
if (extSystem != null) {
|
||||
url = extSystem.getUrl();
|
||||
}
|
||||
url += "/proapp.do?method=getStatisticalInfo";
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String resp = com.sipai.tools.HttpUtil.sendPost(url, map);
|
||||
request.setAttribute("url", extSystem.getUrl());
|
||||
//JSONObject jsonObject = JSONObject.fromObject(resp);
|
||||
try {
|
||||
/*JSONObject re1=jsonObject.getJSONObject("re1");
|
||||
String result="{\"total\":"+re1.get("total")+",\"rows\":"+re1.getJSONArray("rows")+"}";*/
|
||||
// System.out.println(result);
|
||||
model.addAttribute("resp", resp);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ModelAndView("statisticalInfo");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "doPass.do", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
|
||||
public @ResponseBody
|
||||
JSONObject doPass(HttpServletRequest request, Model model) {
|
||||
SecurityContextImpl securityContextImpl = (SecurityContextImpl) request
|
||||
.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
|
||||
String result = "";
|
||||
String unitId = "";
|
||||
if (securityContextImpl != null) {
|
||||
//设置cu其他信息
|
||||
String userName = securityContextImpl.getAuthentication().getName();
|
||||
User cu = userService.getUserById(userName);
|
||||
cu.setCurrentip(request.getRemoteAddr());
|
||||
cu.setLastlogintime(CommUtil.nowDate());
|
||||
UserDetail userDetail = this.userDetailService.selectByUserId(cu.getId());
|
||||
cu.setUserDetail(userDetail);
|
||||
if (cu.getThemeclass() == null || cu.getThemeclass().isEmpty()) {
|
||||
cu.setThemeclass(CommString.Default_Theme);
|
||||
}
|
||||
Company company = unitService.getCompanyByUserId(cu.getId());
|
||||
if (company != null) {
|
||||
cu.set_pname(company.getSname());
|
||||
unitId = company.getId();
|
||||
} else {
|
||||
//cu.set_pname("平台");
|
||||
List<Company> companies = unitService.getCompaniesByWhere("where pid='-1' and type='C'");
|
||||
if (companies != null) {
|
||||
cu.set_pname(companies.get(0).getSname());
|
||||
unitId = companies.get(0).getId();
|
||||
}
|
||||
}
|
||||
//设置session
|
||||
HttpSession newSession = request.getSession(true);
|
||||
newSession.setAttribute("cu", cu);
|
||||
newSession.setAttribute("unitId", unitId);
|
||||
String token = JwtUtil.sign(cu.getName(), cu.getId());
|
||||
result ="{\"status\":" + true +",\"res\":"+ JSONObject.toJSONString(cu) +
|
||||
",\"Access_Token\":\""+ token +"\"}";
|
||||
}
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "doFail.do")
|
||||
public @ResponseBody
|
||||
JSONObject doFail(HttpServletRequest request, Model model) {
|
||||
AuthenticationServiceException respp = (AuthenticationServiceException) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
||||
String messange = respp.getMessage();
|
||||
String result = "{\"status\":" + false + ",\"res\":\"" + messange + "\"}";
|
||||
return JSONObject.parseObject(result);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "logout.do", method = RequestMethod.POST)
|
||||
public ModelAndView logout(HttpServletRequest request,
|
||||
HttpServletResponse response) throws UnsupportedEncodingException {
|
||||
HttpSession session = request.getSession(false);
|
||||
if (null != session) {
|
||||
session.invalidate();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "validate.do")
|
||||
public ModelAndView validate(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@RequestParam(value = "j_username", required = false) String j_username,
|
||||
@RequestParam(value = "j_password", required = false) String j_password) {
|
||||
User cu = new User();
|
||||
if (j_username != null && j_password != null) {
|
||||
cu = loginService.Login(j_username, j_password);
|
||||
} else {
|
||||
cu = null;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
if (null != cu) {
|
||||
|
||||
//设置cu其他信息
|
||||
cu.setCurrentip(request.getRemoteAddr());
|
||||
cu.setLastlogintime(CommUtil.nowDate());
|
||||
|
||||
HttpSession currentSession = request.getSession(false);
|
||||
if (null != currentSession) {
|
||||
currentSession.invalidate();
|
||||
}
|
||||
//设置session
|
||||
HttpSession newSession = request.getSession(true);
|
||||
newSession.setAttribute("cu", cu);
|
||||
if (CommUtil.checkFrontEnd(request)) {
|
||||
// JSONObject cuId = JSONObject.fromObject(cu.getId());
|
||||
map.put("result", "{\"res\":" + true + ",\"cuId\":\"" + cu.getId() + "\"}");
|
||||
return new ModelAndView("result", map);
|
||||
}
|
||||
map.put("result", true);
|
||||
|
||||
} else {
|
||||
map.put("result", false);
|
||||
}
|
||||
|
||||
return new ModelAndView("result", map);
|
||||
}
|
||||
|
||||
private boolean checkPassword(String psw) {
|
||||
boolean result = false;
|
||||
String regex = "^[a-zA-Z0-9]+$";
|
||||
if (null != psw) {
|
||||
result = psw.matches(regex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*@RequestMapping(value = "resetPwd.do", method = RequestMethod.POST)
|
||||
public ModelAndView resetPwd(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model,
|
||||
@RequestParam(value = "loadNewPassword") String loadNewPassword) {
|
||||
User cu = (User)request.getSession().getAttribute("cu");
|
||||
String loadOldPassword=cu.getPassword();
|
||||
|
||||
String result = "";
|
||||
if (checkPassword(loadOldPassword) && checkPassword(loadNewPassword)) {
|
||||
if (loadOldPassword.equals(loadNewPassword)) {
|
||||
result= "请不要与原密码相同";
|
||||
} else {
|
||||
if (userService.resetpassword(cu,loadNewPassword)==1) {
|
||||
result = "成功";
|
||||
} else {
|
||||
result = "用户不存在或原密码错误,请重新输入";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result= "请输入正确信息,密码只可以是字母或者数字";
|
||||
}
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}*/
|
||||
|
||||
@RequestMapping("/mainPageImg.do")
|
||||
public String mainPageImg(HttpServletRequest request, Model model) {
|
||||
return "/fwk/mainPageImg";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/doLogin4Name.do")
|
||||
public JSONObject doLogin4Name(HttpServletRequest request, Model model) {
|
||||
String userName = request.getParameter("userName");
|
||||
String result = "";
|
||||
String unitId = "";
|
||||
JSONObject jsonObject = null;
|
||||
//设置cu其他信息
|
||||
User cu = userService.getUserByLoginName(userName);
|
||||
if (cu != null) {
|
||||
cu.setCurrentip(request.getRemoteAddr());
|
||||
cu.setLastlogintime(CommUtil.nowDate());
|
||||
UserDetail userDetail = this.userDetailService.selectByUserId(cu.getId());
|
||||
cu.setUserDetail(userDetail);
|
||||
if (cu.getThemeclass() == null || cu.getThemeclass().isEmpty()) {
|
||||
cu.setThemeclass(CommString.Default_Theme);
|
||||
}
|
||||
Company company = unitService.getCompanyByUserId(cu.getId());
|
||||
if (company != null) {
|
||||
cu.set_pname(company.getSname());
|
||||
unitId = company.getId();
|
||||
} else {
|
||||
//cu.set_pname("平台");
|
||||
List<Company> companies = unitService.getCompaniesByWhere("where pid='-1' and type='C'");
|
||||
if (companies != null) {
|
||||
cu.set_pname(companies.get(0).getSname());
|
||||
unitId = companies.get(0).getId();
|
||||
}
|
||||
}
|
||||
//设置session
|
||||
HttpSession newSession = request.getSession(true);
|
||||
newSession.setAttribute("cu", cu);
|
||||
newSession.setAttribute("unitId", unitId);
|
||||
|
||||
// result ="{\"status\":" + true +",\"res\":"+ JSONObject.toJSONString(cu) +"}";
|
||||
result = "{\"status\":" + true + "}";
|
||||
jsonObject = JSONObject.parseObject(result);
|
||||
} else {
|
||||
result = "{\"status\":" + false + "}";
|
||||
jsonObject = JSONObject.parseObject(result);
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/doLogin4NameIn.do")
|
||||
public ModelAndView doLogin4NameIn(HttpServletRequest request, Model model) {
|
||||
String userName = request.getParameter("userName");
|
||||
String result = "";
|
||||
String unitId = "";
|
||||
JSONObject jsonObject = null;
|
||||
//设置cu其他信息
|
||||
// User cu = userService.getUserByLoginName(userName);
|
||||
User cu = new User();
|
||||
cu = loginService.NameLogin(userName);
|
||||
if (cu != null) {
|
||||
cu.setCurrentip(request.getRemoteAddr());
|
||||
cu.setLastlogintime(CommUtil.nowDate());
|
||||
UserDetail userDetail = this.userDetailService.selectByUserId(cu.getId());
|
||||
cu.setUserDetail(userDetail);
|
||||
if (cu.getThemeclass() == null || cu.getThemeclass().isEmpty()) {
|
||||
cu.setThemeclass(CommString.Default_Theme);
|
||||
}
|
||||
Company company = unitService.getCompanyByUserId(cu.getId());
|
||||
if (company != null) {
|
||||
cu.set_pname(company.getSname());
|
||||
unitId = company.getId();
|
||||
} else {
|
||||
//cu.set_pname("平台");
|
||||
List<Company> companies = unitService.getCompaniesByWhere("where pid='-1' and type='C'");
|
||||
if (companies != null) {
|
||||
cu.set_pname(companies.get(0).getSname());
|
||||
unitId = companies.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
//设置session
|
||||
HttpSession newSession = request.getSession(true);
|
||||
newSession.setAttribute("cu", cu);
|
||||
newSession.setAttribute("unitId", unitId);
|
||||
|
||||
if (cu.getName().equals("admin")) {
|
||||
model.addAttribute("mqttId", cu.getName() + "_web_" + CommUtil.getUUID());
|
||||
} else {
|
||||
model.addAttribute("mqttId", cu.getName() + "_web");
|
||||
}
|
||||
|
||||
Unit unit = this.unitService.getUserBelongingCompany(cu.getId());
|
||||
if (unit != null) {
|
||||
model.addAttribute("top_user_companyId", unit.getId());
|
||||
model.addAttribute("top_user_companyType", unit.getType());
|
||||
}
|
||||
model.addAttribute("top_userId", cu.getId());
|
||||
|
||||
return new ModelAndView("frameset");
|
||||
} else {
|
||||
result = "{\"status\":" + false + "}";
|
||||
jsonObject = JSONObject.parseObject(result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final String USERNAME = "j_username";
|
||||
public static final String PASSWORD = "j_password";
|
||||
@RequestMapping(value = "getToken.do", method = RequestMethod.POST)
|
||||
public void getToken(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) throws IOException {
|
||||
|
||||
String username = obtainUsername(request);
|
||||
String password = obtainPassword(request);
|
||||
//验证用户账号与密码是否对应
|
||||
username = username.trim();
|
||||
User user =loginService.NameLogin(username);
|
||||
Result result = null;
|
||||
if(user == null || !user.getPassword().equals(password)) {
|
||||
result = Result.failed("用户名或者密码错误!");
|
||||
}else{
|
||||
String token = JwtUtil.sign(user.getName(), user.getId());
|
||||
String res ="{\"Access_Token\":\""+ token +"\"}";
|
||||
result = Result.success(res,"获取成功!");
|
||||
}
|
||||
|
||||
String jsonStr = JSON.toJSONString(result);
|
||||
response.setCharacterEncoding("UTF-8");// 设置将字符以"UTF-8"编码输出到
|
||||
response.getWriter().println(jsonStr);
|
||||
response.getWriter().flush();
|
||||
}
|
||||
protected String obtainUsername(HttpServletRequest request) {
|
||||
Object obj = request.getParameter(USERNAME);
|
||||
return null == obj ? "" : obj.toString();
|
||||
}
|
||||
protected String obtainPassword(HttpServletRequest request) {
|
||||
Object obj = request.getParameter(PASSWORD);
|
||||
return null == obj ? "" : obj.toString();
|
||||
}
|
||||
/**
|
||||
* 通用建设中界面
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "building.do", method = RequestMethod.GET)
|
||||
public ModelAndView building(HttpServletRequest request,
|
||||
HttpServletResponse response, Model model) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return new ModelAndView("building");
|
||||
}
|
||||
}
|
||||
50
src/com/sipai/controller/base/MainConfigController.java
Normal file
50
src/com/sipai/controller/base/MainConfigController.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import com.sipai.entity.base.MainConfig;
|
||||
import com.sipai.service.base.MainConfigService;
|
||||
import com.sipai.tools.CommString;
|
||||
import net.sf.json.JSONArray;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/base/mainConfig")
|
||||
public class MainConfigController {
|
||||
@Resource
|
||||
private MainConfigService mainConfigService;
|
||||
|
||||
/**
|
||||
* 获取首页配置的点位信息
|
||||
*
|
||||
* @param request
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getJson.do")
|
||||
public ModelAndView getJson(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "unitId") String unitId) {
|
||||
String result = "";
|
||||
try {
|
||||
String orderstr = " order by morder asc";
|
||||
String wherestr = " where 1=1";
|
||||
if (unitId != null && !unitId.equals("")) {
|
||||
wherestr += " and unit_id = '" + unitId + "' ";
|
||||
}
|
||||
List<MainConfig> list = mainConfigService.selectListByWhere(wherestr + orderstr);
|
||||
|
||||
JSONArray json1 = JSONArray.fromObject(list);
|
||||
result = "{\"status\":\"" + CommString.Status_Pass + "\",\"mpcode\":" + json1 + "}";
|
||||
} catch (Exception e) {
|
||||
result = "{\"status\":\"" + CommString.Status_Fail + "\"}";
|
||||
}
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
}
|
||||
206
src/com/sipai/controller/base/MainPageController.java
Normal file
206
src/com/sipai/controller/base/MainPageController.java
Normal file
@ -0,0 +1,206 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sipai.entity.base.MainPage;
|
||||
import com.sipai.entity.base.MainPageType;
|
||||
import com.sipai.entity.scada.MPoint4APP;
|
||||
import com.sipai.entity.user.Company;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.service.base.MainPageService;
|
||||
import com.sipai.service.base.MainPageTypeService;
|
||||
import com.sipai.service.user.UnitService;
|
||||
import com.sipai.tools.CommString;
|
||||
import com.sipai.tools.CommUtil;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/base/mainPage")
|
||||
public class MainPageController {
|
||||
@Resource
|
||||
private MainPageService mainPageService;
|
||||
@Resource
|
||||
private MainPageTypeService mainPageTypeService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@RequestMapping("/showlist.do")
|
||||
public String showlist(HttpServletRequest request,Model model) {
|
||||
return "/base/mainPageManage";
|
||||
}
|
||||
@RequestMapping("/getlist.do")
|
||||
public ModelAndView getlist(HttpServletRequest request,Model model,
|
||||
@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "rows") Integer rows,
|
||||
@RequestParam(value = "sort", required=false) String sort,
|
||||
@RequestParam(value = "order", required=false) String order) {
|
||||
User cu=(User)request.getSession().getAttribute("cu");
|
||||
// if(cu==null){
|
||||
// cu=loginService.Login(request.getParameter("username"), request.getParameter("pwd"));
|
||||
// }
|
||||
String orderstr=" order by morder asc";
|
||||
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("bizId")!=null && !request.getParameter("bizId").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizId").toString()+"' ";
|
||||
}
|
||||
if (request.getParameter("type")!=null && !request.getParameter("type").toString().isEmpty()) {
|
||||
wherestr+= " and type ='"+request.getParameter("type").toString()+"' ";
|
||||
}
|
||||
PageHelper.startPage(page, rows);
|
||||
List<MainPage> list = this.mainPageService.selectListByWhere(wherestr+orderstr);
|
||||
|
||||
PageInfo<MainPage> pi = new PageInfo<MainPage>(list);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
|
||||
String result="{\"total\":"+pi.getTotal()+",\"rows\":"+json+"}";
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/getAllList.do")
|
||||
public ModelAndView getAllList(HttpServletRequest request,Model model) {
|
||||
String orderstr=" order by type , show_way ,morder asc";
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("bizId")!=null && !request.getParameter("bizId").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizId").toString()+"' ";
|
||||
}
|
||||
if (request.getParameter("type")!=null && !request.getParameter("type").toString().isEmpty()) {
|
||||
wherestr+= " and type ='"+request.getParameter("type").toString()+"' ";
|
||||
}
|
||||
if (request.getParameter("showWay")!=null && !request.getParameter("showWay").toString().isEmpty()) {
|
||||
wherestr+= " and show_way in ('"+request.getParameter("showWay").toString().replace(",", "','")+"') ";
|
||||
}
|
||||
List<MainPage> list = this.mainPageService.selectListByWhere(wherestr+orderstr);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/add.do")
|
||||
public String doadd(HttpServletRequest request,Model model){
|
||||
/*
|
||||
String orderstr=" order by morder asc";
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("bizId")!=null && !request.getParameter("bizId").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizId").toString()+"' ";
|
||||
}
|
||||
List<MainPageType> list = this.mainPageTypeService.selectListByWhere(wherestr+orderstr);
|
||||
*/
|
||||
String companyId= request.getParameter("bizId");
|
||||
String mainPageTypeId= request.getParameter("id");
|
||||
Company company = this.unitService.getCompById(companyId);
|
||||
request.setAttribute("company", company);
|
||||
request.setAttribute("mainPageTypeId", mainPageTypeId);
|
||||
//request.setAttribute("list",list);
|
||||
return "base/mainPageAdd";
|
||||
}
|
||||
|
||||
@RequestMapping("/edit.do")
|
||||
public String doedit(HttpServletRequest request,Model model){
|
||||
String groupId = request.getParameter("id");
|
||||
MainPage mainPage = this.mainPageService.selectById(groupId);
|
||||
Company company = this.unitService.getCompById(mainPage.getBizId());
|
||||
request.setAttribute("company", company);
|
||||
model.addAttribute("mainPage", mainPage);
|
||||
return "base/mainPageEdit";
|
||||
}
|
||||
|
||||
@RequestMapping("/save.do")
|
||||
public String dosave(HttpServletRequest request,Model model,
|
||||
@ModelAttribute MainPage mainPage){
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
String id = CommUtil.getUUID();
|
||||
mainPage.setId(id);
|
||||
mainPage.setInsuser(cu.getId());
|
||||
mainPage.setInsdt(CommUtil.nowDate());
|
||||
|
||||
int result =this.mainPageService.save(mainPage);
|
||||
/*if(result>0){
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("leaderid"), "leader");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("memberid"), "member");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("chiefid"), "chief");
|
||||
}*/
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+id+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
@RequestMapping("/update.do")
|
||||
public String doupdate(HttpServletRequest request,Model model,
|
||||
@ModelAttribute MainPage mainPage){
|
||||
int result = this.mainPageService.update(mainPage);
|
||||
/*if(result>0){
|
||||
groupMemberService.deleteByGroupId(group.getId());
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("leaderid"), "leader");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("memberid"), "member");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("chiefid"), "chief");
|
||||
}*/
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+mainPage.getId()+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/delete.do")
|
||||
public String dodel(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="id") String id){
|
||||
int result = this.mainPageService.deleteById(id);
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/deletes.do")
|
||||
public String dodels(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="ids") String ids){
|
||||
ids=ids.replace(",","','");
|
||||
int result = this.mainPageService.deleteByWhere("where id in ('"+ids+"')");
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
/***
|
||||
* APP接口。获取主页分类配置信息
|
||||
* @param request
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getList4APPBySort.do")
|
||||
public ModelAndView getList4APPBySort(HttpServletRequest request,Model model) {
|
||||
// if(cu==null){
|
||||
// cu=loginService.Login(request.getParameter("username"), request.getParameter("pwd"));
|
||||
// }
|
||||
String result = "";
|
||||
try{
|
||||
String orderstr=" order by type , show_way ,morder asc";
|
||||
|
||||
String wherestr=" where 1=1";
|
||||
if (request.getParameter("bizid")!=null && !request.getParameter("bizid").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizid").toString()+"' ";
|
||||
}
|
||||
List<MPoint4APP> list1 = this.mainPageService.selectListByWhere4App(wherestr+orderstr);
|
||||
|
||||
JSONArray json1=JSONArray.fromObject(list1);
|
||||
result="{\"status\":\""+CommString.Status_Pass+"\",\"content1\":"+json1+"}";
|
||||
}catch(Exception e){
|
||||
result="{\"status\":\""+CommString.Status_Fail+"\"}";
|
||||
//System.out.println(e);
|
||||
}
|
||||
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
}
|
||||
194
src/com/sipai/controller/base/MainPageTypeController.java
Normal file
194
src/com/sipai/controller/base/MainPageTypeController.java
Normal file
@ -0,0 +1,194 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sipai.entity.base.MainPage;
|
||||
import com.sipai.entity.base.MainPageType;
|
||||
import com.sipai.entity.user.Company;
|
||||
import com.sipai.entity.user.Unit;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.entity.work.Group;
|
||||
import com.sipai.entity.work.GroupMember;
|
||||
import com.sipai.entity.work.UserWorkStation;
|
||||
import com.sipai.service.base.LoginService;
|
||||
import com.sipai.service.base.MainPageService;
|
||||
import com.sipai.service.base.MainPageTypeService;
|
||||
import com.sipai.service.user.UnitService;
|
||||
import com.sipai.service.work.GroupMemberService;
|
||||
import com.sipai.service.work.GroupService;
|
||||
import com.sipai.tools.CommString;
|
||||
import com.sipai.tools.CommUtil;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/base/mainPageType")
|
||||
public class MainPageTypeController {
|
||||
@Resource
|
||||
private MainPageTypeService mainPageTypeService;
|
||||
@Resource
|
||||
private MainPageService mainPageService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@RequestMapping("/showlist.do")
|
||||
public String showlist(HttpServletRequest request,Model model) {
|
||||
return "/base/mainPageTypeList";
|
||||
}
|
||||
@RequestMapping("/getlist.do")
|
||||
public ModelAndView getlist(HttpServletRequest request,Model model,
|
||||
@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "rows") Integer rows,
|
||||
@RequestParam(value = "sort", required=false) String sort,
|
||||
@RequestParam(value = "order", required=false) String order) {
|
||||
User cu=(User)request.getSession().getAttribute("cu");
|
||||
// if(cu==null){
|
||||
// cu=loginService.Login(request.getParameter("username"), request.getParameter("pwd"));
|
||||
// }
|
||||
String orderstr=" order by morder asc";
|
||||
|
||||
String wherestr=" where 1=1 ";
|
||||
/*
|
||||
if (request.getParameter("mainPageTypeId")!=null && !request.getParameter("mainPageTypeId").toString().isEmpty()) {
|
||||
wherestr+= " and id ='"+request.getParameter("mainPageTypeId").toString()+"' ";
|
||||
}
|
||||
*/
|
||||
if (request.getParameter("bizId")!=null && !request.getParameter("bizId").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizId").toString()+"' ";
|
||||
}
|
||||
PageHelper.startPage(page, rows);
|
||||
List<MainPageType> list = this.mainPageTypeService.selectListByWhere(wherestr+orderstr);
|
||||
|
||||
PageInfo<MainPageType> pi = new PageInfo<MainPageType>(list);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
|
||||
String result="{\"total\":"+pi.getTotal()+",\"rows\":"+json+"}";
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/getAllList.do")
|
||||
public ModelAndView getAllList(HttpServletRequest request,Model model) {
|
||||
String orderstr=" order by morder asc";
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("bizId")!=null && !request.getParameter("bizId").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizId").toString()+"' ";
|
||||
}
|
||||
if (request.getParameter("type")!=null && !request.getParameter("type").toString().isEmpty()) {
|
||||
wherestr+= " and type ='"+request.getParameter("type").toString()+"' ";
|
||||
}
|
||||
List<MainPageType> list = this.mainPageTypeService.selectListByWhere(wherestr+orderstr);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/add.do")
|
||||
public String doadd(HttpServletRequest request,Model model){
|
||||
String companyId= request.getParameter("bizId");
|
||||
Company company = this.unitService.getCompById(companyId);
|
||||
request.setAttribute("company", company);
|
||||
return "base/mainPageTypeAdd";
|
||||
}
|
||||
|
||||
@RequestMapping("/edit.do")
|
||||
public String doedit(HttpServletRequest request,Model model){
|
||||
String groupId = request.getParameter("id");
|
||||
MainPageType mainPageType = this.mainPageTypeService.selectById(groupId);
|
||||
Company company = this.unitService.getCompById(mainPageType.getBizId());
|
||||
request.setAttribute("company", company);
|
||||
model.addAttribute("mainPageType", mainPageType);
|
||||
return "base/mainPageTypeEdit";
|
||||
}
|
||||
|
||||
@RequestMapping("/save.do")
|
||||
public String dosave(HttpServletRequest request,Model model,
|
||||
@ModelAttribute MainPageType mainPageType){
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
String id = CommUtil.getUUID();
|
||||
mainPageType.setId(id);
|
||||
mainPageType.setInsuser(cu.getId());
|
||||
mainPageType.setInsdt(CommUtil.nowDate());
|
||||
|
||||
int result =this.mainPageTypeService.save(mainPageType);
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+id+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/update.do")
|
||||
public String doupdate(HttpServletRequest request,Model model,
|
||||
@ModelAttribute MainPageType mainPageType){
|
||||
int result = this.mainPageTypeService.update(mainPageType);
|
||||
/*if(result>0){
|
||||
groupMemberService.deleteByGroupId(group.getId());
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("leaderid"), "leader");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("memberid"), "member");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("chiefid"), "chief");
|
||||
}*/
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+mainPageType.getId()+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/delete.do")
|
||||
public String dodel(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="mainPageTypeId") String mainPageTypeId){
|
||||
int result = this.mainPageTypeService.deleteById(mainPageTypeId);
|
||||
String whereStr="where type ="+"'"+mainPageTypeId+"'";
|
||||
int resultNum=mainPageService.deleteByWhere(whereStr);
|
||||
model.addAttribute("result", result);
|
||||
model.addAttribute("resultNum", resultNum);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/deletes.do")
|
||||
public String dodels(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="ids") String ids){
|
||||
ids=ids.replace(",","','");
|
||||
int result = this.mainPageTypeService.deleteByWhere("where id in ('"+ids+"')");
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/getType4Select.do")
|
||||
public String getPatrolArea4Select(HttpServletRequest request,Model model){
|
||||
String orderstr=" order by morder asc";
|
||||
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("mainPageTypeId")!=null && !request.getParameter("mainPageTypeId").toString().isEmpty()) {
|
||||
wherestr+= " and id ='"+request.getParameter("mainPageTypeId").toString()+"' ";
|
||||
}
|
||||
if (request.getParameter("bizId")!=null && !request.getParameter("bizId").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizId").toString()+"' ";
|
||||
}
|
||||
|
||||
List<MainPageType> list = this.mainPageTypeService.selectListByWhere(wherestr+orderstr);
|
||||
JSONArray json = new JSONArray();
|
||||
if(list!=null && list.size()>0){
|
||||
for(int i=0;i<list.size();i++){
|
||||
JSONObject jsonObject =new JSONObject();
|
||||
jsonObject.put("id", list.get(i).getId());
|
||||
jsonObject.put("text", list.get(i).getTitle());
|
||||
json.add(jsonObject);
|
||||
}
|
||||
}
|
||||
model.addAttribute("result", json.toString());
|
||||
return "result";
|
||||
}
|
||||
|
||||
}
|
||||
170
src/com/sipai/controller/base/MainPageTypeUserController.java
Normal file
170
src/com/sipai/controller/base/MainPageTypeUserController.java
Normal file
@ -0,0 +1,170 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sipai.entity.base.MainPage;
|
||||
import com.sipai.entity.base.MainPageType;
|
||||
import com.sipai.entity.base.MainPageTypeUser;
|
||||
import com.sipai.entity.user.Company;
|
||||
import com.sipai.entity.user.Unit;
|
||||
import com.sipai.entity.user.User;
|
||||
import com.sipai.entity.work.Group;
|
||||
import com.sipai.entity.work.GroupMember;
|
||||
import com.sipai.entity.work.UserWorkStation;
|
||||
import com.sipai.service.base.LoginService;
|
||||
import com.sipai.service.base.MainPageService;
|
||||
import com.sipai.service.base.MainPageTypeService;
|
||||
import com.sipai.service.base.MainPageTypeUserService;
|
||||
import com.sipai.service.user.UnitService;
|
||||
import com.sipai.service.work.GroupMemberService;
|
||||
import com.sipai.service.work.GroupService;
|
||||
import com.sipai.tools.CommString;
|
||||
import com.sipai.tools.CommUtil;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/base/mainPageTypeUser")
|
||||
public class MainPageTypeUserController {
|
||||
@Resource
|
||||
private MainPageTypeUserService mainPageTypeUserService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@RequestMapping("/showlist.do")
|
||||
public String showlist(HttpServletRequest request,Model model) {
|
||||
return "/base/mainPageTypeUserList";
|
||||
}
|
||||
@RequestMapping("/getlist.do")
|
||||
public ModelAndView getlist(HttpServletRequest request,Model model,
|
||||
@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "rows") Integer rows,
|
||||
@RequestParam(value = "sort", required=false) String sort,
|
||||
@RequestParam(value = "order", required=false) String order) {
|
||||
User cu=(User)request.getSession().getAttribute("cu");
|
||||
// if(cu==null){
|
||||
// cu=loginService.Login(request.getParameter("username"), request.getParameter("pwd"));
|
||||
// }
|
||||
String orderstr=" order by morder asc";
|
||||
|
||||
String wherestr=" where 1=1 ";
|
||||
if (request.getParameter("bizId")!=null && !request.getParameter("bizId").toString().isEmpty()) {
|
||||
wherestr+= " and biz_id ='"+request.getParameter("bizId").toString()+"' ";
|
||||
}
|
||||
PageHelper.startPage(page, rows);
|
||||
List<MainPageTypeUser> list = this.mainPageTypeUserService.selectListByWhere(wherestr+orderstr);
|
||||
|
||||
PageInfo<MainPageTypeUser> pi = new PageInfo<MainPageTypeUser>(list);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
|
||||
String result="{\"total\":"+pi.getTotal()+",\"rows\":"+json+"}";
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/getAllList.do")
|
||||
public ModelAndView getAllList(HttpServletRequest request,Model model) {
|
||||
String orderstr=" order by morder asc";
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
String wherestr=" where 1=1 and insuser ='"+cu.getId()+"'";
|
||||
List<MainPageTypeUser> list = this.mainPageTypeUserService.selectListByWhere(wherestr+orderstr);
|
||||
JSONArray json=JSONArray.fromObject(list);
|
||||
// System.out.println(result);
|
||||
model.addAttribute("result",json);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
@RequestMapping("/add.do")
|
||||
public String doadd(HttpServletRequest request,Model model){
|
||||
String companyId= request.getParameter("bizId");
|
||||
Company company = this.unitService.getCompById(companyId);
|
||||
request.setAttribute("company", company);
|
||||
return "base/mainPageTypeUserAdd";
|
||||
}
|
||||
|
||||
@RequestMapping("/edit.do")
|
||||
public String doedit(HttpServletRequest request,Model model){
|
||||
String groupId = request.getParameter("id");
|
||||
MainPageTypeUser mainPageTypeUser = this.mainPageTypeUserService.selectById(groupId);
|
||||
model.addAttribute("mainPageTypeUser", mainPageTypeUser);
|
||||
return "base/mainPageTypeUserEdit";
|
||||
}
|
||||
|
||||
@RequestMapping("/save.do")
|
||||
public String dosave(HttpServletRequest request,Model model,
|
||||
@ModelAttribute MainPageTypeUser mainPageTypeUser){
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
String id = CommUtil.getUUID();
|
||||
mainPageTypeUser.setId(id);
|
||||
mainPageTypeUser.setInsuser(cu.getId());
|
||||
mainPageTypeUser.setInsdt(CommUtil.nowDate());
|
||||
|
||||
int result =this.mainPageTypeUserService.save(mainPageTypeUser);
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+id+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
@RequestMapping("/update.do")
|
||||
public String doupdate(HttpServletRequest request,Model model,
|
||||
@ModelAttribute MainPageTypeUser mainPageTypeUser){
|
||||
int result = this.mainPageTypeUserService.update(mainPageTypeUser);
|
||||
/*if(result>0){
|
||||
groupMemberService.deleteByGroupId(group.getId());
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("leaderid"), "leader");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("memberid"), "member");
|
||||
groupMemberService.saveMembers(group.getId(), request.getParameter("chiefid"), "chief");
|
||||
}*/
|
||||
String resstr="{\"res\":\""+result+"\",\"id\":\""+mainPageTypeUser.getId()+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
@RequestMapping("/saveAndUpdate.do")
|
||||
public String dosaveAndUpdate(HttpServletRequest request,Model model){
|
||||
String mainPageTypeIds=request.getParameter("mainPageTypeIds");
|
||||
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
|
||||
int result =this.mainPageTypeUserService.saveAndUpdate(cu.getId(),mainPageTypeIds);
|
||||
String resstr="{\"res\":\""+result+"\"}";
|
||||
model.addAttribute("result", resstr);
|
||||
return "result";
|
||||
}
|
||||
@RequestMapping("/delete.do")
|
||||
public String dodel(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="id") String id){
|
||||
int result = this.mainPageTypeUserService.deleteById(id);
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/deletes.do")
|
||||
public String dodels(HttpServletRequest request,Model model,
|
||||
@RequestParam(value="ids") String ids){
|
||||
ids=ids.replace(",","','");
|
||||
int result = this.mainPageTypeUserService.deleteByWhere("where id in ('"+ids+"')");
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
@RequestMapping("/clearRecord.do")
|
||||
public String clearRecord(HttpServletRequest request,Model model){
|
||||
User cu= (User)request.getSession().getAttribute("cu");
|
||||
int result = this.mainPageTypeUserService.deleteByWhere("where insuser = '"+cu.getId()+"'");
|
||||
model.addAttribute("result", result);
|
||||
return "result";
|
||||
}
|
||||
|
||||
}
|
||||
118
src/com/sipai/controller/base/MinioController.java
Normal file
118
src/com/sipai/controller/base/MinioController.java
Normal file
@ -0,0 +1,118 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sipai.entity.enums.FileNameSpaceEnum;
|
||||
import com.sipai.service.base.CommonFileService;
|
||||
import com.sipai.tools.MinioUtils;
|
||||
import io.swagger.annotations.*;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用于传文件到minio 通用
|
||||
* sj 2022-09-08
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/minio")
|
||||
@Api(value = "/minio", tags = "文件管理")
|
||||
public class MinioController {
|
||||
@Autowired
|
||||
private MinioUtils minioUtils;
|
||||
@Autowired
|
||||
CommonFileService commonFileService;
|
||||
|
||||
@GetMapping("init")
|
||||
public String init() {
|
||||
return "file";
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传 (单个视频)
|
||||
*/
|
||||
@ApiOperation(value = "文件上传 (单个视频)", notes = "文件上传 (单个视频)", httpMethod = "POST")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求参数没填好")})
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "MultipartFile源文件", dataType = "MultipartFile", paramType = "query", required = true),
|
||||
@ApiImplicitParam(name = "masterId", value = "表单id", dataType = "String", paramType = "query", required = true),
|
||||
@ApiImplicitParam(name = "nameSpace", value = "桶名称", dataType = "String", paramType = "query", required = true),
|
||||
@ApiImplicitParam(name = "tbName", value = "数据库表", dataType = "String", paramType = "query", required = true)
|
||||
})
|
||||
@RequestMapping(value = "/uploadVideo.do", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String upload(HttpServletRequest request,
|
||||
@RequestParam(name = "file", required = false) MultipartFile file,
|
||||
@RequestParam(value = "masterId") String masterId,
|
||||
@RequestParam(value = "nameSpace") String nameSpace,
|
||||
@RequestParam(value = "tbName") String tbName) {
|
||||
System.out.println("uploadVideo");
|
||||
JSONObject res = null;
|
||||
try {
|
||||
res = minioUtils.uploadFile(file, masterId, nameSpace, tbName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
res.put("code", 0);
|
||||
res.put("msg", "上传失败");
|
||||
}
|
||||
return res.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* minio 文件上传 (通用)
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "updateFile.do")
|
||||
public ModelAndView updateFile(HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
System.out.println("updateFile");
|
||||
Map<String, Object> ret = new HashMap<String, Object>();
|
||||
String masterId = request.getParameter("masterId");
|
||||
String nameSpace = request.getParameter("nameSpace");
|
||||
String tbName = request.getParameter("tbName");
|
||||
if (nameSpace != null && !nameSpace.isEmpty()) {
|
||||
if (tbName == null || tbName.isEmpty()) {
|
||||
tbName = FileNameSpaceEnum.getTbName(nameSpace);
|
||||
}
|
||||
}
|
||||
|
||||
if (ServletFileUpload.isMultipartContent(request)) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
List<MultipartFile> fileList = multipartRequest.getFiles("filelist"); //控件id
|
||||
//for循环只执行一次
|
||||
for (MultipartFile item : fileList) {
|
||||
try {
|
||||
int res = commonFileService.updateFile(masterId, nameSpace, tbName, item);
|
||||
|
||||
if (res == 1) {
|
||||
ret.put("suc", true);
|
||||
} else {
|
||||
ret.put("suc", false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret.put("suc", false);
|
||||
ret.put("msg", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
String result = net.sf.json.JSONObject.fromObject(ret).toString();
|
||||
model.addAttribute("result", result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
}
|
||||
396
src/com/sipai/controller/base/PDFFileUtil.java
Normal file
396
src/com/sipai/controller/base/PDFFileUtil.java
Normal file
@ -0,0 +1,396 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.itextpdf.text.BaseColor;
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Element;
|
||||
import com.itextpdf.text.Font;
|
||||
import com.itextpdf.text.FontProvider;
|
||||
import com.itextpdf.text.PageSize;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
import com.itextpdf.text.Phrase;
|
||||
import com.itextpdf.text.Rectangle;
|
||||
import com.itextpdf.text.pdf.BaseFont;
|
||||
import com.itextpdf.text.pdf.PdfPCell;
|
||||
import com.itextpdf.text.pdf.PdfPTable;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
import com.itextpdf.tool.xml.XMLWorkerHelper;
|
||||
import com.sipai.tools.CommUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.xhtmlrenderer.pdf.ITextFontResolver;
|
||||
import org.xhtmlrenderer.pdf.ITextRenderer;
|
||||
|
||||
|
||||
public class PDFFileUtil {
|
||||
Document document = null;// 建立一个Document对象
|
||||
/* private static Font headFont ;
|
||||
private static Font keyFont ;
|
||||
private static Font nbspFont;
|
||||
private static Font textfont_H ;
|
||||
private static Font textfont_B ;
|
||||
private static Font textfont_13;
|
||||
private static Font textfont_12;
|
||||
private static Font textfont_11;
|
||||
private static Font textfont_10;
|
||||
private static Font textfont_9;
|
||||
private static Font textfont_8;
|
||||
private static Font textfont_7;
|
||||
private static Font textfont_6;
|
||||
int maxWidth = 520;*/
|
||||
|
||||
|
||||
public void createPDF(String outputPath, String xmlStr) {
|
||||
try {
|
||||
Document document = new Document();
|
||||
document.setPageSize(PageSize.A4);// 设置页面大小
|
||||
PdfWriter mPdfWriter = PdfWriter. getInstance(document, new FileOutputStream(outputPath));
|
||||
document.open();
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(xmlStr.getBytes());
|
||||
XMLWorkerHelper.getInstance().parseXHtml(mPdfWriter, document, bin, Charset.forName("UTF-8"), new ChinaFontProvide());
|
||||
/*BaseFont baseFont = BaseFont.createFont("C:/Windows/Fonts/SIMYOU.TTF",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
|
||||
|
||||
Font font = new Font(baseFont);
|
||||
document.add(new Paragraph("解决中文问题了!",font)); */
|
||||
document.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*Document document = new Document();
|
||||
try {
|
||||
|
||||
// 建立一个Document对象
|
||||
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
||||
Font keyfont = new Font(bfChinese, 11, Font.BOLD);// 设置字体大小
|
||||
Font textfont = new Font(bfChinese, 9, Font.NORMAL);// 设置字体大小
|
||||
document.setPageSize(PageSize.A4);// 设置页面大小
|
||||
PdfWriter.getInstance(document, new FileOutputStream(outputPath));
|
||||
document.open();
|
||||
PdfPTable table = createTable(new float[]{1f, 4f, 2f, 2f, 2.5f, 2.5f, 2f});
|
||||
table.addCell(createCell("编号", keyfont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell("文件名", keyfont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell("广告类型", keyfont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell("频道包", keyfont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell("开始日期", keyfont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell("结束日期", keyfont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell("缩略图", keyfont, Element.ALIGN_CENTER));
|
||||
//设置单元格
|
||||
document.add(table);
|
||||
document.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}*/
|
||||
}
|
||||
public synchronized static boolean html2Pdf(String outputPath, String xmlStr) {
|
||||
|
||||
OutputStream os = null;
|
||||
try {
|
||||
//xmlStr = HtmlGenerator.generate("D:/Workspaces/SSMBootstrap/resources/freemaker/template/maintenanceViewTemplate.ftl", new HashMap<String, Object>());
|
||||
os = new FileOutputStream(outputPath);
|
||||
|
||||
ITextRenderer renderer = new ITextRenderer();
|
||||
// DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
// org.w3c.dom.Document doc = builder.parse(new ByteArrayInputStream(xmlStr.getBytes("utf-8")));
|
||||
// renderer.setDocument(doc,null);
|
||||
renderer.setDocumentFromString(xmlStr);
|
||||
// 解决中文支持问题
|
||||
ITextFontResolver fontResolver = renderer.getFontResolver();
|
||||
try {
|
||||
fontResolver.addFont("C:/Windows/fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 解决图片的相对路径问题
|
||||
/*String basePath="D:/Tomcat 7.0/webapps/UploadFile";
|
||||
renderer.getSharedContext().setBaseURL("file:/" + basePath + "/MaintenanceBill");
|
||||
renderer.getSharedContext().setReplacedElementFactory(new Base64ImgReplacedElementFactory());
|
||||
renderer.getSharedContext().getTextRenderer().setSmoothingThreshold(0);*/
|
||||
renderer.layout();
|
||||
try {
|
||||
renderer.createPDF(os);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
/*ByteArrayOutputStream baos=new ByteArrayOutputStream();
|
||||
baos=(ByteArrayOutputStream) os;
|
||||
Hibernate.createBlob();
|
||||
ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());*/
|
||||
if (os!=null) {
|
||||
os.flush();
|
||||
os.close();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 提供中文
|
||||
*
|
||||
*/
|
||||
public class ChinaFontProvide implements FontProvider{
|
||||
|
||||
|
||||
@Override
|
||||
public Font getFont(String arg0, String arg1, boolean arg2, float arg3,
|
||||
int arg4, BaseColor arg5) {
|
||||
BaseFont bfChinese =null;
|
||||
try {
|
||||
// bfChinese=BaseFont.createFont("STSong-Light", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||
bfChinese=BaseFont.createFont("C:/Windows/Fonts/SIMYOU.TTF,1",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Font FontChinese = new Font(bfChinese);
|
||||
return FontChinese;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRegistered(String arg0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/exportMaintenanceDetailPDF.do")
|
||||
public ModelAndView exportMaintenanceDetailPDF(HttpServletRequest request,Model model){
|
||||
|
||||
String htmlStr = request.getParameter("htmlStr");
|
||||
PDFFileUtil pdfFileUtil= new PDFFileUtil();
|
||||
String realPath = request.getSession().getServletContext().getRealPath("/");
|
||||
String pjName = request.getContextPath().substring(1, request.getContextPath().length());
|
||||
realPath = realPath.replace(pjName,"UploadFile");
|
||||
String fileName =CommUtil.getUUID()+".pdf";
|
||||
realPath+="MaintenanceBill\\"+fileName;
|
||||
pdfFileUtil.html2Pdf(realPath, htmlStr);
|
||||
|
||||
String result="{\"res\":\""+realPath.substring(realPath.indexOf("UploadFile"),realPath.length()).replace("\\", "/")+"\"}";
|
||||
model.addAttribute("result",result);
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
/* static{
|
||||
BaseFont bfChinese_H;
|
||||
try {
|
||||
*//**
|
||||
* 新建一个字体,iText的方法 STSongStd-Light 是字体,在iTextAsian.jar 中以property为后缀
|
||||
* UniGB-UCS2-H 是编码,在iTextAsian.jar 中以cmap为后缀 H 代表文字版式是 横版, 相应的 V 代表竖版
|
||||
*//*
|
||||
bfChinese_H = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
|
||||
|
||||
|
||||
headFont = new Font(bfChinese_H, 14, Font.NORMAL);
|
||||
keyFont = new Font(bfChinese_H, 26, Font.BOLD);
|
||||
nbspFont = new Font(bfChinese_H, 13, Font.NORMAL);
|
||||
textfont_H = new Font(bfChinese_H, 10, Font.NORMAL);
|
||||
textfont_B = new Font(bfChinese_H, 12, Font.NORMAL);
|
||||
textfont_13 = new Font(bfChinese_H, 13, Font.NORMAL);
|
||||
textfont_12 = new Font(bfChinese_H, 12, Font.NORMAL);
|
||||
textfont_11 = new Font(bfChinese_H, 11, Font.NORMAL);
|
||||
textfont_10 = new Font(bfChinese_H, 10, Font.NORMAL);
|
||||
textfont_9 = new Font(bfChinese_H, 9, Font.NORMAL);
|
||||
textfont_8 = new Font(bfChinese_H, 8, Font.NORMAL);
|
||||
textfont_7 = new Font(bfChinese_H, 7, Font.NORMAL);
|
||||
textfont_6 = new Font(bfChinese_H, 6, Font.NORMAL);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* 设置页面属性
|
||||
* @param file
|
||||
*/
|
||||
public void setPageProperties(File file) {
|
||||
|
||||
|
||||
//自定义纸张
|
||||
Rectangle rectPageSize = new Rectangle(350, 620);
|
||||
|
||||
|
||||
// 定义A4页面大小
|
||||
//Rectangle rectPageSize = new Rectangle(PageSize.A4);
|
||||
rectPageSize = rectPageSize.rotate();// 加上这句可以实现页面的横置
|
||||
document = new Document(rectPageSize,10, 150, 10, 40);
|
||||
|
||||
|
||||
try {
|
||||
PdfWriter.getInstance(document,new FileOutputStream(file));
|
||||
document.open();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 建表格(以列的数量建)
|
||||
* @param colNumber
|
||||
* @return
|
||||
*/
|
||||
public PdfPTable createTable(int colNumber){
|
||||
PdfPTable table = new PdfPTable(colNumber);
|
||||
try{
|
||||
//table.setTotalWidth(maxWidth);
|
||||
//table.setLockedWidth(true);
|
||||
table.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
table.getDefaultCell().setBorder(1);
|
||||
table.setSpacingBefore(10);
|
||||
table.setWidthPercentage(100);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 建表格(以列的宽度比建)
|
||||
* @param widths
|
||||
* @return
|
||||
*/
|
||||
public PdfPTable createTable(float[] widths){
|
||||
PdfPTable table = new PdfPTable(widths);
|
||||
try{
|
||||
//table.setTotalWidth(maxWidth);
|
||||
//table.setLockedWidth(true);
|
||||
table.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
table.getDefaultCell().setBorder(1);
|
||||
table.setSpacingBefore(10);
|
||||
table.setWidthPercentage(100);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 表格中单元格
|
||||
* @param value
|
||||
* @param font
|
||||
* @param align
|
||||
* @return
|
||||
*/
|
||||
public PdfPCell createCell(String value,Font font,int align){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||
cell.setHorizontalAlignment(align);
|
||||
cell.setPhrase(new Phrase(value,font));
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 表格中单元格
|
||||
* @param value
|
||||
* @param font
|
||||
* @param align
|
||||
* @param colspan
|
||||
* @param rowspan
|
||||
* @return
|
||||
*/
|
||||
public PdfPCell createCell(String value,Font font,int align_v,int align_h,int colspan,int rowspan){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
cell.setVerticalAlignment(align_v);
|
||||
cell.setHorizontalAlignment(align_h);
|
||||
cell.setColspan(colspan);
|
||||
cell.setRowspan(rowspan);
|
||||
cell.setPhrase(new Phrase(value,font));
|
||||
return cell;
|
||||
}
|
||||
/**
|
||||
* 创建无边框表格
|
||||
* @param value
|
||||
* @param font
|
||||
* @param align
|
||||
* @param colspan
|
||||
* @param rowspan
|
||||
* @return
|
||||
*/
|
||||
public PdfPCell createCellNotBorder(String value,Font font,int align_v,int align_h,int colspan,int rowspan){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
cell.setVerticalAlignment(align_v);
|
||||
cell.setHorizontalAlignment(align_h);
|
||||
cell.setColspan(colspan);
|
||||
cell.setRowspan(rowspan);
|
||||
cell.setPhrase(new Phrase(value,font));
|
||||
cell.setBorderWidth(0f);
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 建短语
|
||||
* @param value
|
||||
* @param font
|
||||
* @return
|
||||
*/
|
||||
public Phrase createPhrase(String value,Font font){
|
||||
Phrase phrase = new Phrase();
|
||||
phrase.add(value);
|
||||
phrase.setFont(font);
|
||||
return phrase;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 建段落
|
||||
* @param value
|
||||
* @param font
|
||||
* @param align
|
||||
* @return
|
||||
*/
|
||||
public Paragraph createParagraph(String value,Font font,int align){
|
||||
Paragraph paragraph = new Paragraph();
|
||||
paragraph.add(new Phrase(value,font));
|
||||
paragraph.setAlignment(align);
|
||||
return paragraph;
|
||||
}
|
||||
}
|
||||
448
src/com/sipai/controller/base/PoiUtils.java
Normal file
448
src/com/sipai/controller/base/PoiUtils.java
Normal file
@ -0,0 +1,448 @@
|
||||
package com.sipai.controller.base;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PoiUtils {
|
||||
|
||||
private Map<String, Map<String, Object>> orderMap = new HashMap<String, Map<String, Object>>();
|
||||
|
||||
/*把*/
|
||||
public static void copy(Object obj, Object dest) {
|
||||
// 获取属性
|
||||
BeanInfo sourceBean = null;
|
||||
try {
|
||||
sourceBean = Introspector.getBeanInfo(obj.getClass(), Object.class);
|
||||
} catch (IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PropertyDescriptor[] sourceProperty = sourceBean.getPropertyDescriptors();
|
||||
|
||||
BeanInfo destBean = null;
|
||||
try {
|
||||
destBean = Introspector.getBeanInfo(dest.getClass(), Object.class);
|
||||
} catch (IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PropertyDescriptor[] destProperty = destBean.getPropertyDescriptors();
|
||||
try {
|
||||
for (int i = 0; i < sourceProperty.length; i++) {
|
||||
Object value = sourceProperty[i].getReadMethod().invoke(obj);
|
||||
if (value != null) {
|
||||
|
||||
for (int j = 0; j < destProperty.length; j++) {
|
||||
if (sourceProperty[i].getName().equals(destProperty[j].getName()) && sourceProperty[i].getPropertyType() == destProperty[j].getPropertyType()) {
|
||||
// 调用source的getter方法和dest的setter方法
|
||||
destProperty[j].getWriteMethod().invoke(dest, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
throw new Exception("属性复制失败:" + e.getMessage());
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置一级标题内容及样式
|
||||
*
|
||||
* @param paragraph
|
||||
* @param text
|
||||
*/
|
||||
public void setLevelTitle1(XWPFDocument document, XWPFParagraph paragraph, String text) {
|
||||
/**1.将段落原有文本(原有所有的Run)全部删除*/
|
||||
deleteRun(paragraph);
|
||||
/**3.插入新的Run即将新的文本插入段落*/
|
||||
XWPFRun createRun = paragraph.insertNewRun(0);
|
||||
createRun.setText(text);
|
||||
XWPFRun separtor = paragraph.insertNewRun(1);
|
||||
/**两段之间添加换行*/
|
||||
separtor.setText("\r");
|
||||
createRun.setFontSize(16);
|
||||
createRun.setFontFamily("黑体");
|
||||
paragraph.setIndentationFirstLine(600);
|
||||
paragraph.setSpacingAfter(20);
|
||||
paragraph.setSpacingBefore(20);
|
||||
addCustomHeadingStyle(document, "标题1", 1);
|
||||
paragraph.setStyle("标题1");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置二级标题内容及样式
|
||||
*
|
||||
* @param paragraph
|
||||
* @param text
|
||||
*/
|
||||
public void setLevelTitle2(XWPFDocument document, XWPFParagraph paragraph, String text) {
|
||||
deleteRun(paragraph);
|
||||
/**3.插入新的Run即将新的文本插入段落*/
|
||||
XWPFRun createRun = paragraph.insertNewRun(0);
|
||||
createRun.setText(text);
|
||||
XWPFRun separtor = paragraph.insertNewRun(1);
|
||||
/**两段之间添加换行*/
|
||||
separtor.setText("\r");
|
||||
createRun.setFontSize(16);
|
||||
createRun.setBold(true);
|
||||
createRun.setFontFamily("楷体_GB2312");
|
||||
paragraph.setIndentationFirstLine(600);
|
||||
paragraph.setSpacingAfter(10);
|
||||
paragraph.setSpacingBefore(10);
|
||||
addCustomHeadingStyle(document, "标题2", 2);
|
||||
paragraph.setStyle("标题2");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置正文文本内容及样式
|
||||
*
|
||||
* @param paragraph
|
||||
* @param text
|
||||
*/
|
||||
public void setTextPro(XWPFParagraph paragraph, String text) {
|
||||
deleteRun(paragraph);
|
||||
/**3.插入新的Run即将新的文本插入段落*/
|
||||
XWPFRun createRun = paragraph.insertNewRun(0);
|
||||
createRun.setText(text);
|
||||
XWPFRun separtor = paragraph.insertNewRun(1);
|
||||
/**两段之间添加换行*/
|
||||
separtor.addBreak();
|
||||
createRun.addTab();
|
||||
createRun.setFontFamily("仿宋_GB2312");
|
||||
createRun.setFontSize(16);
|
||||
|
||||
paragraph.setFirstLineIndent(20);
|
||||
paragraph.setAlignment(ParagraphAlignment.BOTH);
|
||||
paragraph.setIndentationFirstLine(600);
|
||||
paragraph.setSpacingAfter(10);
|
||||
paragraph.setSpacingBefore(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向段落添加文本
|
||||
*
|
||||
* @param paragraph
|
||||
* @param text
|
||||
*/
|
||||
public void addTextPro(XWPFParagraph paragraph, String text) {
|
||||
/**3.插入新的Run即将新的文本插入段落*/
|
||||
XWPFRun createRun = paragraph.createRun();
|
||||
createRun.setText(text);
|
||||
XWPFRun separtor = paragraph.createRun();
|
||||
/**两段之间添加换行*/
|
||||
separtor.addBreak();
|
||||
createRun.addTab();
|
||||
createRun.setFontFamily("仿宋_GB2312");
|
||||
createRun.setFontSize(16);
|
||||
paragraph.setFirstLineIndent(20);
|
||||
paragraph.setAlignment(ParagraphAlignment.BOTH);
|
||||
paragraph.setIndentationFirstLine(600);
|
||||
paragraph.setSpacingAfter(10);
|
||||
paragraph.setSpacingBefore(10);
|
||||
|
||||
paragraph.addRun(createRun);
|
||||
paragraph.addRun(separtor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表格标题内容及样式
|
||||
*
|
||||
* @param paragraph
|
||||
* @param text
|
||||
*/
|
||||
public void setTableOrChartTitle(XWPFParagraph paragraph, String text) {
|
||||
/**1.将段落原有文本(原有所有的Run)全部删除*/
|
||||
deleteRun(paragraph);
|
||||
XWPFRun createRun = paragraph.insertNewRun(0);
|
||||
createRun.setText(text);
|
||||
XWPFRun separtor = paragraph.insertNewRun(1);
|
||||
/**两段之间添加换行*/
|
||||
separtor.setText("\r");
|
||||
createRun.setFontFamily("楷体");
|
||||
createRun.setFontSize(16);
|
||||
createRun.setBold(true);
|
||||
paragraph.setSpacingAfter(10);
|
||||
paragraph.setSpacingBefore(10);
|
||||
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
}
|
||||
|
||||
public void deleteRun(XWPFParagraph paragraph) {
|
||||
/*1.将段落原有文本(原有所有的Run)全部删除*/
|
||||
List<XWPFRun> runs = paragraph.getRuns();
|
||||
int runSize = runs.size();
|
||||
/*Paragrap中每删除一个run,其所有的run对象就会动态变化,即不能同时遍历和删除*/
|
||||
int haveRemoved = 0;
|
||||
for (int runIndex = 0; runIndex < runSize; runIndex++) {
|
||||
paragraph.removeRun(runIndex - haveRemoved);
|
||||
haveRemoved++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并行
|
||||
*
|
||||
* @param table
|
||||
* @param col 需要合并的列
|
||||
* @param fromRow 开始行
|
||||
* @param toRow 结束行
|
||||
*/
|
||||
public static void mergeCellVertically(XWPFTable table, int col, int fromRow, int toRow) {
|
||||
for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
|
||||
CTVMerge vmerge = CTVMerge.Factory.newInstance();
|
||||
if (rowIndex == fromRow) {
|
||||
vmerge.setVal(STMerge.RESTART);
|
||||
} else {
|
||||
vmerge.setVal(STMerge.CONTINUE);
|
||||
}
|
||||
XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
|
||||
CTTcPr tcPr = cell.getCTTc().getTcPr();
|
||||
if (tcPr != null) {
|
||||
tcPr.setVMerge(vmerge);
|
||||
} else {
|
||||
tcPr = CTTcPr.Factory.newInstance();
|
||||
tcPr.setVMerge(vmerge);
|
||||
cell.getCTTc().setTcPr(tcPr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表格内容居中
|
||||
*
|
||||
* @param table
|
||||
*/
|
||||
public void setTableCenter(XWPFTable table) {
|
||||
List<XWPFTableRow> rows = table.getRows();
|
||||
for (XWPFTableRow row : rows) {
|
||||
row.setHeight(400);
|
||||
List<XWPFTableCell> cells = row.getTableCells();
|
||||
for (XWPFTableCell cell : cells) {
|
||||
CTTc cttc = cell.getCTTc();
|
||||
CTTcPr ctPr = cttc.addNewTcPr();
|
||||
ctPr.addNewVAlign().setVal(STVerticalJc.CENTER);
|
||||
cttc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.CENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void init(XWPFDocument document) {
|
||||
//获取段落
|
||||
List<XWPFParagraph> paras = document.getParagraphs();
|
||||
|
||||
for (int i = 0; i < paras.size(); i++) {
|
||||
XWPFParagraph para = paras.get(i);
|
||||
// System.out.println(para.getCTP());//得到xml格式
|
||||
// System.out.println(para.getStyleID());//段落级别
|
||||
// System.out.println(para.getParagraphText());//段落内容
|
||||
|
||||
String titleLvl = getTitleLvl(document, para);//获取段落级别
|
||||
if ("a5".equals(titleLvl) || "HTML".equals(titleLvl) || "".equals(titleLvl) || null == titleLvl) {
|
||||
titleLvl = "8";
|
||||
}
|
||||
|
||||
if (null != titleLvl && !"".equals(titleLvl) && !"8".equals(titleLvl)) {
|
||||
String t = titleLvl;
|
||||
String orderCode = getOrderCode(titleLvl);//获取编号
|
||||
String text = para.getParagraphText();
|
||||
text = orderCode + " " + text;
|
||||
List<XWPFRun> runs = para.getRuns();
|
||||
int runSize = runs.size();
|
||||
/**Paragrap中每删除一个run,其所有的run对象就会动态变化,即不能同时遍历和删除*/
|
||||
int haveRemoved = 0;
|
||||
for (int runIndex = 0; runIndex < runSize; runIndex++) {
|
||||
para.removeRun(runIndex - haveRemoved);
|
||||
haveRemoved++;
|
||||
}
|
||||
if ("1".equals(titleLvl)) {
|
||||
setLevelTitle1(document, para, text);
|
||||
}
|
||||
if ("2".equals(titleLvl)) {
|
||||
setLevelTitle2(document, para, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Word中的大纲级别,可以通过getPPr().getOutlineLvl()直接提取,但需要注意,Word中段落级别,通过如下三种方式定义:
|
||||
* 1、直接对段落进行定义;
|
||||
* 2、对段落的样式进行定义;
|
||||
* 3、对段落样式的基础样式进行定义。
|
||||
* 因此,在通过“getPPr().getOutlineLvl()”提取时,需要依次在如上三处读取。
|
||||
*
|
||||
* @param doc
|
||||
* @param para
|
||||
* @return
|
||||
*/
|
||||
public String getTitleLvl(XWPFDocument doc, XWPFParagraph para) {
|
||||
String titleLvl = "";
|
||||
|
||||
//判断该段落是否设置了大纲级别
|
||||
CTP ctp = para.getCTP();
|
||||
if (ctp != null) {
|
||||
CTPPr pPr = ctp.getPPr();
|
||||
if (pPr != null) {
|
||||
if (pPr.getOutlineLvl() != null) {
|
||||
return String.valueOf(pPr.getOutlineLvl().getVal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//判断该段落的样式是否设置了大纲级别
|
||||
if (para.getStyle() != null) {
|
||||
if (doc.getStyles().getStyle(para.getStyle()).getCTStyle().getPPr().getOutlineLvl() != null) {
|
||||
return String.valueOf(doc.getStyles().getStyle(para.getStyle()).getCTStyle().getPPr().getOutlineLvl().getVal());
|
||||
}
|
||||
|
||||
|
||||
//判断该段落的样式的基础样式是否设置了大纲级别
|
||||
if (doc.getStyles().getStyle(doc.getStyles().getStyle(para.getStyle()).getCTStyle().getBasedOn().getVal())
|
||||
.getCTStyle().getPPr().getOutlineLvl() != null) {
|
||||
String styleName = doc.getStyles().getStyle(para.getStyle()).getCTStyle().getBasedOn().getVal();
|
||||
return String.valueOf(doc.getStyles().getStyle(styleName).getCTStyle().getPPr().getOutlineLvl().getVal());
|
||||
}
|
||||
}
|
||||
if (para.getStyleID() != null) {
|
||||
return para.getStyleID();
|
||||
}
|
||||
return titleLvl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加自定义标题样式。这里用的是stackoverflow的源码
|
||||
*
|
||||
* @param docxDocument 目标文档
|
||||
* @param strStyleId 样式名称
|
||||
* @param headingLevel 样式级别
|
||||
*/
|
||||
public static void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) {
|
||||
|
||||
CTStyle ctStyle = CTStyle.Factory.newInstance();
|
||||
ctStyle.setStyleId(strStyleId);
|
||||
|
||||
CTString styleName = CTString.Factory.newInstance();
|
||||
styleName.setVal(strStyleId);
|
||||
ctStyle.setName(styleName);
|
||||
|
||||
CTDecimalNumber indentNumber = CTDecimalNumber.Factory.newInstance();
|
||||
indentNumber.setVal(BigInteger.valueOf(headingLevel));
|
||||
|
||||
// lower number > style is more prominent in the formats bar
|
||||
ctStyle.setUiPriority(indentNumber);
|
||||
|
||||
CTOnOff onoffnull = CTOnOff.Factory.newInstance();
|
||||
ctStyle.setUnhideWhenUsed(onoffnull);
|
||||
|
||||
// style shows up in the formats bar
|
||||
ctStyle.setQFormat(onoffnull);
|
||||
|
||||
// style defines a heading of the given level
|
||||
CTPPr ppr = CTPPr.Factory.newInstance();
|
||||
ppr.setOutlineLvl(indentNumber);
|
||||
ctStyle.setPPr(ppr);
|
||||
|
||||
XWPFStyle style = new XWPFStyle(ctStyle);
|
||||
|
||||
// is a null op if already defined
|
||||
XWPFStyles styles = docxDocument.createStyles();
|
||||
|
||||
style.setType(STStyleType.PARAGRAPH);
|
||||
styles.addStyle(style);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取标题编号
|
||||
*
|
||||
* @param titleLvl
|
||||
* @return
|
||||
*/
|
||||
public String getOrderCode(String titleLvl) {
|
||||
String order = "";
|
||||
|
||||
if ("0".equals(titleLvl) || Integer.parseInt(titleLvl) == 8) {//文档标题||正文
|
||||
return "";
|
||||
} else if (Integer.parseInt(titleLvl) > 0 && Integer.parseInt(titleLvl) < 8) {//段落标题
|
||||
|
||||
//设置最高级别标题
|
||||
Map<String, Object> maxTitleMap = orderMap.get("maxTitleLvlMap");
|
||||
if (null == maxTitleMap) {//没有,表示第一次进来
|
||||
//最高级别标题赋值
|
||||
maxTitleMap = new HashMap<String, Object>();
|
||||
maxTitleMap.put("lvl", titleLvl);
|
||||
orderMap.put("maxTitleLvlMap", maxTitleMap);
|
||||
} else {
|
||||
String maxTitleLvl = maxTitleMap.get("lvl") + "";//最上层标题级别(0,1,2,3)
|
||||
if (Integer.parseInt(titleLvl) < Integer.parseInt(maxTitleLvl)) {//当前标题级别更高
|
||||
maxTitleMap.put("lvl", titleLvl);//设置最高级别标题
|
||||
orderMap.put("maxTitleLvlMap", maxTitleMap);
|
||||
}
|
||||
}
|
||||
|
||||
//查父节点标题
|
||||
int parentTitleLvl = Integer.parseInt(titleLvl) - 1;//父节点标题级别
|
||||
Map<String, Object> cMap = orderMap.get(titleLvl);//当前节点信息
|
||||
Map<String, Object> pMap = orderMap.get(parentTitleLvl + "");//父节点信息
|
||||
|
||||
if (0 == parentTitleLvl) {//父节点为文档标题,表明当前节点为1级标题
|
||||
int count = 0;
|
||||
//最上层标题,没有父节点信息
|
||||
if (null == cMap) {//没有当前节点信息
|
||||
cMap = new HashMap<String, Object>();
|
||||
} else {
|
||||
count = Integer.parseInt(String.valueOf(cMap.get("cCount")));//当前序个数
|
||||
}
|
||||
count++;
|
||||
order = count + "";
|
||||
cMap.put("cOrder", order);//当前序
|
||||
cMap.put("cCount", count);//当前序个数
|
||||
orderMap.put(titleLvl, cMap);
|
||||
|
||||
} else {//父节点为非文档标题
|
||||
int count = 0;
|
||||
//如果没有相邻的父节点信息,当前标题级别自动升级
|
||||
if (null == pMap) {
|
||||
return getOrderCode(String.valueOf(parentTitleLvl));
|
||||
} else {
|
||||
String pOrder = String.valueOf(pMap.get("cOrder"));//父节点序
|
||||
if (null == cMap) {//没有当前节点信息
|
||||
cMap = new HashMap<String, Object>();
|
||||
} else {
|
||||
count = Integer.parseInt(String.valueOf(cMap.get("cCount")));//当前序个数
|
||||
}
|
||||
count++;
|
||||
order = pOrder + "." + count;//当前序编号
|
||||
cMap.put("cOrder", order);//当前序
|
||||
cMap.put("cCount", count);//当前序个数
|
||||
orderMap.put(titleLvl, cMap);
|
||||
}
|
||||
}
|
||||
|
||||
//字节点标题计数清零
|
||||
int childTitleLvl = Integer.parseInt(titleLvl) + 1;//子节点标题级别
|
||||
Map<String, Object> cdMap = orderMap.get(childTitleLvl + "");//
|
||||
if (null != cdMap) {
|
||||
cdMap.put("cCount", 0);//子节点序个数
|
||||
orderMap.get(childTitleLvl + "").put("cCount", 0);
|
||||
}
|
||||
}
|
||||
return order;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user