package com.shlanbao.tzsc.pms.board.board.controller; import com.shlanbao.tzsc.base.controller.BaseController; import com.shlanbao.tzsc.base.model.Json; import com.shlanbao.tzsc.pms.board.board.service.BoardServiceI; import com.shlanbao.tzsc.pms.qm.self.beans.QmOutWandBean; import com.shlanbao.tzsc.pms.sch.workorder.beans.WorkOrderBean; import net.sf.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Controller @RequestMapping("/pms/board") public class BoardController extends BaseController { @Autowired BoardServiceI boardServiceI; @ResponseBody @RequestMapping("/workorder") public Json workOrder(int type) { Json json = new Json(); try { Map rollPackWorkOrder = boardServiceI.getRollPackWorkOrder(type); json.setSuccess(true); json.setObj(rollPackWorkOrder); json.setMsg("success"); } catch (Exception e) { e.printStackTrace(); json.setSuccess(false); } return json; } @ResponseBody @RequestMapping("/monthqty") public Json YrarMonthQty() { Json json = new Json(); try { Map yearMonthQty = boardServiceI.getYearMonthQty(); json.setSuccess(true); json.setObj(yearMonthQty); json.setMsg("success"); } catch (Exception e) { e.printStackTrace(); json.setSuccess(false); } return json; } @ResponseBody @RequestMapping("/weekqty") public Json getSevenDayQty() { Json json = new Json(); try { Map weekqty = boardServiceI.getSevenDayQty(); json.setSuccess(true); json.setObj(weekqty); json.setMsg("success"); } catch (Exception e) { e.printStackTrace(); json.setSuccess(false); } return json; } @ResponseBody @RequestMapping("/weekeffe") public Json getWeekEffe() { Json json = new Json(); try { Map weekeffe = boardServiceI.getEquEffe(); json.setSuccess(true); json.setObj(weekeffe); json.setMsg("success"); } catch (Exception e) { e.printStackTrace(); json.setSuccess(false); } return json; } @ResponseBody @RequestMapping("/equmax") public Json getEquMax(){ Json json = new Json(); try { Map equMax = boardServiceI.getEquMax(); json.setSuccess(true); json.setObj(equMax); json.setMsg("success"); } catch (Exception e) { e.printStackTrace(); } return json; } @ResponseBody @RequestMapping("/lastMonthWg") public Json queryLastMonthWgqx() { List data = boardServiceI.queryLastMonthWgqx(); Json json = new Json(); try { Map hmap = data.stream().filter(item -> item.getType().contains("盒")).collect(Collectors.groupingBy(QmOutWandBean::getName, Collectors.summingInt(QmOutWandBean::getValue))); Map ymap = data.stream().filter(item -> item.getType().contains("烟")).collect(Collectors.groupingBy(QmOutWandBean::getName, Collectors.summingInt(QmOutWandBean::getValue))); List> data1 = new ArrayList<>(); List> data2 = new ArrayList<>(); List> hList = new ArrayList<>(); hmap.forEach((key,value)->{ Map item = new HashMap<>(); item.put("name",key); item.put("value",value); hList.add(item); }); hList.sort((o1,o2)-> ((Integer) o2.get("value")).compareTo((Integer) o1.get("value")) ); if(hList.size() > 20){ List> subList1 = hList.subList(0, 20); List> subList2 = hList.subList(20,hList.size()); int other = subList2.stream().mapToInt(map -> (int) map.get("value")).sum(); Map oMap = new HashMap<>(); data1.addAll(subList1); oMap.put("name","其它"); oMap.put("value",other); data1.add(oMap); }else { data1.addAll(hList); } List> yList = new ArrayList<>(); ymap.forEach((key,value)->{ Map item = new HashMap<>(); item.put("name",key); item.put("value",value); yList.add(item); }); yList.sort((o1,o2)-> ((Integer) o2.get("value")).compareTo((Integer) o1.get("value")) ); if(yList.size() > 20){ List> subList1 = yList.subList(0, 20); List> subList2 = yList.subList(20,yList.size()); int other = subList2.stream().mapToInt(map -> (int) map.get("value")).sum(); Map oMap = new HashMap<>(); data2.addAll(subList1); oMap.put("name","其它"); oMap.put("value",other); data2.add(oMap); }else { data2.addAll(yList); } Map map = new HashMap<>(); map.put("data1",data1); map.put("data2",data2); if (!data.isEmpty()) { json.setObj(map); json.setSuccess(true); json.setMsg("操作成功!"); } else { json.setMsg("获取数据失败!请重试!"); } } catch (Exception e) { e.printStackTrace(); } return json; } @ResponseBody @RequestMapping("/lastMonthTc") public Json queryTc() { List> data = boardServiceI.queryLastMonthTc(); List> tcList = new ArrayList<>(); Map map = new HashMap<>(); Json json = new Json(); try { Map sumByCategory = data.stream() .collect(Collectors.groupingBy( m -> (String) m.get("name"), Collectors.summingInt(m -> Integer.parseInt(m.get("value").toString())) )); sumByCategory.forEach((key,value)->{ Map item = new HashMap<>(); item.put("name",key); item.put("value",value); tcList.add(item); }); tcList.sort((o1,o2)-> ((Integer) o2.get("value")).compareTo((Integer) o1.get("value")) ); map.put("data",tcList); if (!data.isEmpty()) { json.setObj(map); json.setSuccess(true); json.setMsg("操作成功!"); } else { json.setMsg("获取数据失败!请重试!"); } } catch (Exception e) { e.printStackTrace(); } return json; } }