package com.mandi.fendan.controller; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.mandi.fendan.persist.FdMxWlgs; import com.mandi.springmvc.logs.OpLogs; import com.mandi.system.persist.ModuleEnum; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.mandi.common.JSONobj; import com.mandi.common.Jacksonmethod; import com.mandi.common.RequestParam; import com.mandi.common.SessionMethod; import com.mandi.dao.common.ObjectResult; import com.mandi.dao.common.PageRequest; import com.mandi.dao.common.PageResult; import com.mandi.dao.common.Sort; import com.mandi.fendan.service.IErpService; import com.mandi.fendan.service.Ifd_bsheetService; import com.mandi.fendan.service.Ifd_vehicleService; import com.mandi.system.persist.Login; @Controller("fd_businesscon") @RequestMapping(value="/business",method={RequestMethod.POST}) public class Fd_businessCon { Logger log = Logger.getLogger(Fd_businessCon.class); @Resource private IErpService erpser; @Resource private Ifd_bsheetService bsser; @Resource private Ifd_vehicleService fdvser; /** * 获取已分配的销售提单 * @param r * @param re * @return */ @RequestMapping(value="/getList.htm",method={RequestMethod.POST}) @ResponseBody public String getXSTDList(HttpServletRequest r,HttpServletResponse re){ //tdbh--提单编号,khmc--客户,shdd--收货地点,zdbm--制单部门,zdr--制单人 String type=RequestParam.getSqlString(r, "type"); String keyword=RequestParam.getSqlString(r, "keyword"); String companyNo=RequestParam.getSqlString(r, "companyNo"); String sort=RequestParam.getString(r, "sort"); int wcSign=RequestParam.getInt(r, "wcSign"); // [{name, value: asc/desc}] tdbh--提单编,khmc--客户名称,shdd--收货地点,wfds--未分单数,wfdl--未分单量, // shsj--审核时间,zdbm--制单部门,zdr--制单人,ywrq--业务日期,tdlx--提单类型 int page=RequestParam.getInt(r, "page"); int pagesize=RequestParam.getInt(r, "pagesize"); int pages=RequestParam.getInt(r, "pages"); Date sdate=RequestParam.getDate(r, "sdate"); Date edate=RequestParam.getDate(r, "edate"); String cqV=RequestParam.getSqlString(r, "cqV");//厂区 Login lg=SessionMethod.getlogin(r.getSession()); PageRequest pr=new PageRequest(page, pagesize, null); if(pages>0) pr.setNeedPages(true); else pr.setNeedPages(false); List sortc=new ArrayList(); String sortStr=""; if(!StringUtils.isEmpty(sort)){ Sort st=new Sort(); JsonParser jp=new JsonParser(); JsonElement je=jp.parse(sort); if(je!=null&&je.isJsonArray()){ JsonArray ja=je.getAsJsonArray(); // Map sortmp=SortMap.getXSTDsortMap(); for (JsonElement je1 : ja) { JsonObject jo=je1.getAsJsonObject(); if(jo!=null){ String name=JSONobj.getstring(jo, "name"); String value=JSONobj.getstring(jo, "value"); if(StringUtils.isEmpty(sortStr)){ sortStr+=(" "+name+" "+value); }else{ sortStr+=(","+name+" "+value); } } } } if(!StringUtils.isEmpty(st.toString())){ pr.setSort(st); } } if(!StringUtils.isEmpty(sortStr)){ sortStr+=" "; } String str=""; if(wcSign==2){//已关闭销售提单 PageResult> prrc=erpser.getCloseXSTDlist(lg,type,keyword, companyNo, sdate, edate,wcSign, pr,sortc); str=Jacksonmethod.tojson(prrc, false); }else{ PageResult> prr=erpser.getXSTDList(lg,type,keyword, companyNo, sdate, edate,wcSign,null, pr,sortStr,cqV); str=Jacksonmethod.tojson(prr, false); } SessionMethod.writeresp(re, str); return null; } /*** * 改变明细的物流公司 * @return */ @OpLogs(module = ModuleEnum.业务模块, name = "更改提单的物流公司") @RequestMapping(value="/changeWlgs.htm",method= RequestMethod.POST,consumes = "application/json") @ResponseBody public String changeCompany(HttpServletRequest request, HttpServletResponse response){ // json 解析 PageResult> prr = new PageResult>(); // 开始解析JSON,接收的类型为List;主要为了解决这个框架使用@RequestBody时415问题 StringBuilder sb = new StringBuilder(); try(BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(),"utf-8"))) { String line = null; while ((line = br.readLine()) != null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } ObjectMapper objectMapper =new ObjectMapper(); List fdMxWlgsList = null; try { JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, FdMxWlgs.class); fdMxWlgsList = objectMapper.readValue(sb.toString(), javaType); } catch (IOException e) { prr.setCode(1); prr.setErrmsg(e.getMessage()); SessionMethod.writeresp(response, Jacksonmethod.tojson(prr, false)); return null; } // 解析JSON结束 log.info("更改提单的物流公司:" + sb.toString()); try { erpser.changeMxWlgs(fdMxWlgsList); prr.setCode(0); } catch (Exception e) { log.error(e.getMessage(),e); prr.setCode(1); prr.setErrmsg(e.getMessage()); } SessionMethod.writeresp(response, Jacksonmethod.tojson(prr, false)); return null; } /*** * 提单列表 * @param r * @param re * @return */ @RequestMapping(value="/billofLadingList.htm",method={RequestMethod.POST}) @ResponseBody public String billofLadingList(HttpServletRequest r,HttpServletResponse re){ //tdbh--提单编号,khmc--客户,shdd--收货地点,zdbm--制单部门,zdr--制单人 String type=RequestParam.getSqlString(r, "type"); String keyword=RequestParam.getSqlString(r, "keyword"); // String companyNo=RequestParam.getSqlString(r, "companyNo"); String companyNo = ""; // 不要限定公司 String sort=RequestParam.getString(r, "sort"); int wcSign=RequestParam.getInt(r, "wcSign"); // [{name, value: asc/desc}] tdbh--提单编,khmc--客户名称,shdd--收货地点,wfds--未分单数,wfdl--未分单量, // shsj--审核时间,zdbm--制单部门,zdr--制单人,ywrq--业务日期,tdlx--提单类型 int page=RequestParam.getInt(r, "page"); int pagesize=RequestParam.getInt(r, "pagesize"); int pages=RequestParam.getInt(r, "pages"); Date sdate=RequestParam.getDate(r, "sdate"); Date edate=RequestParam.getDate(r, "edate"); String cqV=RequestParam.getSqlString(r, "cqV");//厂区 Login lg=SessionMethod.getlogin(r.getSession()); PageRequest pr=new PageRequest(page, pagesize, null); if(pages>0) pr.setNeedPages(true); else pr.setNeedPages(false); List sortc=new ArrayList(); String sortStr=""; if(!StringUtils.isEmpty(sort)){ Sort st=new Sort(); JsonParser jp=new JsonParser(); JsonElement je=jp.parse(sort); if(je!=null&&je.isJsonArray()){ JsonArray ja=je.getAsJsonArray(); // Map sortmp=SortMap.getXSTDsortMap(); for (JsonElement je1 : ja) { JsonObject jo=je1.getAsJsonObject(); if(jo!=null){ String name=JSONobj.getstring(jo, "name"); String value=JSONobj.getstring(jo, "value"); if(StringUtils.isEmpty(sortStr)){ sortStr+=(" "+name+" "+value); }else{ sortStr+=(","+name+" "+value); } } } } if(!StringUtils.isEmpty(st.toString())){ pr.setSort(st); } } if(!StringUtils.isEmpty(sortStr)){ sortStr+=" "; } String str=""; PageResult> prr=erpser.getXSTDList(lg,type,keyword, companyNo, sdate, edate,wcSign,"fdAdmin" ,pr,sortStr,cqV); str=Jacksonmethod.tojson(prr, false); SessionMethod.writeresp(re, str); return null; } /** *获取全部公司可用车 * @param r * @param re * @return */ @RequestMapping(value="/getVehicleList.htm",method={RequestMethod.POST}) @ResponseBody public String getVehicleList(HttpServletRequest r,HttpServletResponse re){ String companyNo=RequestParam.getSqlString(r, "companyNo"); String vehicleId=RequestParam.getSqlString(r, "vehicleId"); Login lg=SessionMethod.getlogin(r.getSession()); PageResult> prr=fdvser.getalllist(lg,companyNo,vehicleId); String str=Jacksonmethod.tojson(prr, false); SessionMethod.writeresp(re, str); return null; } /** *验证临时车车牌号 * @param r * @param re * @return */ @RequestMapping(value="/validVehicle.htm",method={RequestMethod.POST}) @ResponseBody public String validVehicle(HttpServletRequest r,HttpServletResponse re){ String vehicleId=RequestParam.getSqlString(r, "vehicleId"); Login lg=SessionMethod.getlogin(r.getSession()); ObjectResult orr=fdvser.validVehicle(lg, vehicleId); String str=Jacksonmethod.tojson(orr, false); SessionMethod.writeresp(re, str); return null; } /** *获取单个销售提单信息 * @param r * @param re * @return */ @RequestMapping(value="/getItem.htm",method={RequestMethod.POST}) @ResponseBody public String getItem(HttpServletRequest r,HttpServletResponse re){ String XSTD=RequestParam.getSqlString(r, "keyword"); Login lg=SessionMethod.getlogin(r.getSession()); Map mp=erpser.getXSTD(lg, XSTD); String str=Jacksonmethod.tojson(mp, false); SessionMethod.writeresp(re, str); return null; } /** *获取提单列表进入的单个销售提单信息 * @param r * @param re * @return */ @RequestMapping(value="/getBillofLadingItem.htm",method={RequestMethod.POST}) @ResponseBody public String getBillofLadingItem(HttpServletRequest r,HttpServletResponse re) { String XSTD=RequestParam.getSqlString(r, "keyword"); Login lg=SessionMethod.getlogin(r.getSession()); Map mp = erpser.getBillofLadingXSTD(lg, XSTD); String str=Jacksonmethod.tojson(mp, false); SessionMethod.writeresp(re, str); return null; } /** * 按单配车:拼单 * @param r * @param re * @return */ @RequestMapping(value="/doBindByList.htm",method={RequestMethod.POST}) @ResponseBody @OpLogs(name="整单配车",module = ModuleEnum.业务模块) public String doBindByList(HttpServletRequest r,HttpServletResponse re){ String list=RequestParam.getString(r, "list"); String vehicle=RequestParam.getString(r, "vehicle"); Login lg=SessionMethod.getlogin(r.getSession()); ObjectResult orr=new ObjectResult(); try { orr = erpser.doBindByList(lg, list, vehicle); } catch (Exception e) { e.printStackTrace(); orr.setCode(1); orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"配车程序出错!":e.getMessage()); } String str=Jacksonmethod.tojson(orr, false); SessionMethod.writeresp(re, str); return null; } /** * 按车配单取消 * @param r * @param re * @return */ @OpLogs(name="整单取消配车",module = ModuleEnum.业务模块) @RequestMapping(value="/doUnbindByList.htm",method={RequestMethod.POST}) @ResponseBody public String doUnbindByList(HttpServletRequest r,HttpServletResponse re){ String tdbhlist=RequestParam.getString(r, "list");//[TD-0040130, TD-0040132,...] Login lg=SessionMethod.getlogin(r.getSession()); ObjectResult orr=new ObjectResult(); try { orr = erpser.dounBindByList(lg, tdbhlist); } catch (Exception e) { e.printStackTrace(); orr.setCode(1); orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"配车取消程序出错!":e.getMessage()); } String str=Jacksonmethod.tojson(orr, false); SessionMethod.writeresp(re, str); return null; } /** * 取消分单 * @param r * @param re * @return */ @RequestMapping(value="/doUnbind.htm",method={RequestMethod.POST}) @ResponseBody @OpLogs(name="明细取消配车", module = ModuleEnum.业务模块) public String doUnbind(HttpServletRequest r,HttpServletResponse re){ String list=RequestParam.getString(r, "list");//[{"tdls":,"tdfl":}] String tdbh=RequestParam.getSqlString(r, "tdbh");//提单编号 // String cph=RequestParam.getSqlString(r, "vehicle");//车牌号 Login lg=SessionMethod.getlogin(r.getSession()); ObjectResult orr=new ObjectResult(); try { orr = erpser.doUnbind(lg, list,tdbh); } catch (Exception e) { e.printStackTrace(); orr.setCode(1); orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"取消分单操作失败!":e.getMessage()); } String str=Jacksonmethod.tojson(orr, false); SessionMethod.writeresp(re, str); return null; } /** * 分单 * @param r * @param re * @return */ @RequestMapping(value="/doBind.htm",method={RequestMethod.POST}) @ResponseBody @OpLogs(name="分单配车",module = ModuleEnum.业务模块) public String doBind(HttpServletRequest r,HttpServletResponse re){ String list=RequestParam.getString(r, "list");//[{"tdls":,"tdfl":}] String vehicle=RequestParam.getString(r, "vehicle");//[{"tdls":,"tdfl":}] String xstdNo=RequestParam.getSqlString(r, "tdbh");//[{"tdls":,"tdfl":}] Login lg=SessionMethod.getlogin(r.getSession()); ObjectResult> orr=new ObjectResult>(); try { orr=bsser.saveFd_Bsheet(vehicle, xstdNo, list, lg); } catch (Exception e) { e.printStackTrace(); orr.setCode(1); orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"业务单保存出错!":e.getMessage()); } String str=""; if(orr.getCode()!=0){ str=Jacksonmethod.tojson(orr, false); }else{ str=Jacksonmethod.tojson(orr, false); } SessionMethod.writeresp(re, str); return null; } /** * 关闭分单 * @param r * @param re * @return */ @RequestMapping(value="/closexstd.htm",method={RequestMethod.POST}) @ResponseBody @OpLogs(name="关闭分单",module = ModuleEnum.业务模块) public String closeXstd(HttpServletRequest r,HttpServletResponse re){ String vehicleId=RequestParam.getSqlString(r, "vehicleId")==null?"":RequestParam.getSqlString(r, "vehicleId").trim(); String driver=RequestParam.getSqlString(r, "driver")==null?"":RequestParam.getSqlString(r, "driver").trim(); String phone=RequestParam.getSqlString(r, "phone")==null?"":RequestParam.getSqlString(r, "phone").trim(); String xstdNo=RequestParam.getSqlString(r, "tdNo")==null?"":RequestParam.getSqlString(r, "tdNo").trim();//提单编号 Login lg=SessionMethod.getlogin(r.getSession()); ObjectResult orr=new ObjectResult(); try { orr = erpser.closeXstd(vehicleId,driver,phone,xstdNo, lg); } catch (Exception e) { e.printStackTrace(); orr.setCode(1); orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"关闭分单程序出错!":e.getMessage()); } String str=Jacksonmethod.tojson(orr, false); SessionMethod.writeresp(re, str); return null; } /** * 打开分单 * @param r * @param re * @return */ @RequestMapping(value="/openxstd.htm",method={RequestMethod.POST}) @ResponseBody @OpLogs(name="打开分单",module = ModuleEnum.业务模块) public String openXSTD(HttpServletRequest r,HttpServletResponse re){ String xstdNo=RequestParam.getSqlString(r, "tdNo");//提单编号 Login lg=SessionMethod.getlogin(r.getSession()); ObjectResult orr=new ObjectResult(); try { orr = erpser.openXstd(xstdNo, lg); } catch (Exception e) { e.printStackTrace(); orr.setCode(1); orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"恢复分单程序出错!":e.getMessage()); } String str=Jacksonmethod.tojson(orr, false); SessionMethod.writeresp(re, str); return null; } }