883 lines
32 KiB
Plaintext
883 lines
32 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
|
||
import java.io.Serializable;
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.UUID;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import org.apache.commons.lang.SerializationUtils;
|
||
import org.codehaus.jackson.map.ObjectMapper;
|
||
import org.codehaus.jackson.type.TypeReference;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
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.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
||
import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenUserInfoBizc;
|
||
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
import com.nationalelectric.greenH5.utils.DateTime;
|
||
import com.nationalelectric.greenH5.utils.DateUtil;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
||
import okhttp3.Call;
|
||
import okhttp3.FormBody;
|
||
import okhttp3.OkHttpClient;
|
||
import okhttp3.Request;
|
||
import okhttp3.Response;
|
||
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
*
|
||
* @author chenweikang
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/greenCatagory")
|
||
public class GreenCatagoryController extends GreenBaseController {
|
||
|
||
|
||
/**
|
||
* 字典表controller
|
||
*/
|
||
@Resource
|
||
private GreenDictionaryInfoController greenDictionaryInfoController;
|
||
@Resource
|
||
private IGreenOperateLogBizc greenOperateLogBizc;
|
||
/**
|
||
* HibernateDao逻辑构件
|
||
*/
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
|
||
|
||
/**
|
||
* 获取类别列表
|
||
*
|
||
* @param stime
|
||
* @param etime
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "unused" })
|
||
@RequestMapping(value = "/getCatagoryList", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getCatagoryList(@RequestBody Object requestBody) {
|
||
|
||
HashMap<String, Object> rMap = new HashMap<String, Object>();
|
||
try {
|
||
String sql = "select * from t_production_catagory t "
|
||
+ "where t.is_deleted='N' order by t.parent_id,t.seq";
|
||
List<Map<String, Object>> productionCatagoryList = hibernateDao.queryForListWithSql(sql.toString(), new Object[]{ });
|
||
|
||
HashMap<String,Object> tempMap = new HashMap<String,Object>();
|
||
List<HashMap<String, Object>> levelList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> subSelectorList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> lastList = new ArrayList<HashMap<String, Object>>();
|
||
String id = "";
|
||
String name = "";
|
||
String value = "";
|
||
String parentId = "";
|
||
for(int i=0; i<productionCatagoryList.size(); i++){
|
||
id = "";
|
||
name = "";
|
||
value = "";
|
||
parentId = "";
|
||
//如果是产品一级目录
|
||
if((productionCatagoryList.get(i)).get("grade").equals("1")){
|
||
id = productionCatagoryList.get(i).get("uuid").toString();
|
||
name = productionCatagoryList.get(i).get("name").toString();
|
||
tempMap = new HashMap<String,Object>();
|
||
tempMap.put("id", id);
|
||
tempMap.put("name", name);
|
||
levelList.add(tempMap);
|
||
continue;
|
||
}
|
||
//如果是产品二级目录
|
||
else if(productionCatagoryList.get(i).get("grade").equals("2")){
|
||
parentId = productionCatagoryList.get(i).get("parent_id").toString();
|
||
id = productionCatagoryList.get(i).get("uuid").toString();
|
||
name = productionCatagoryList.get(i).get("name").toString();
|
||
|
||
//找出产品一级目录在list中的下标
|
||
HashMap<String,Integer> indexMap = getIndex(levelList,parentId,2);
|
||
int index = indexMap.get("firstIndex");
|
||
subSelectorList = new ArrayList<HashMap<String, Object>>();
|
||
if(levelList.get(index).containsKey("subSelectorList")){
|
||
subSelectorList = (List<HashMap<String, Object>>) levelList.get(index).get("subSelectorList");
|
||
}
|
||
|
||
tempMap = new HashMap<String,Object>();
|
||
tempMap.put("id", id);
|
||
tempMap.put("name", name);
|
||
subSelectorList.add(tempMap);
|
||
|
||
levelList.get(index).put("subSelectorList", subSelectorList);
|
||
continue;
|
||
}
|
||
//如果是产品三级目录
|
||
else if(productionCatagoryList.get(i).get("grade").equals("3")){
|
||
parentId = productionCatagoryList.get(i).get("parent_id").toString();
|
||
id = productionCatagoryList.get(i).get("uuid").toString();
|
||
name = productionCatagoryList.get(i).get("name").toString();
|
||
|
||
HashMap<String,Integer> indexMap = getIndex(levelList,parentId,3);
|
||
int index = indexMap.get("firstIndex");
|
||
int secondIndex = indexMap.get("secondIndex");
|
||
subSelectorList = (List<HashMap<String, Object>>)levelList.get(index).get("subSelectorList");
|
||
lastList = new ArrayList<HashMap<String, Object>>();
|
||
|
||
if(subSelectorList.get(secondIndex).containsKey("levelList")){
|
||
lastList = (List<HashMap<String, Object>>) subSelectorList.get(secondIndex).get("levelList");
|
||
}
|
||
|
||
tempMap = new HashMap<String,Object>();
|
||
tempMap.put("id", id);
|
||
tempMap.put("name", name);
|
||
tempMap.put("value", id);
|
||
lastList.add(tempMap);
|
||
|
||
subSelectorList.get(secondIndex).put("levelList", lastList);
|
||
levelList.get(index).put("subSelectorList", subSelectorList);
|
||
|
||
// (((List<HashMap<String, Object>>)levelList.get(index).get("subSelectorList")).get(secondIndex)).put("levelList", subSelectorList);
|
||
continue;
|
||
}
|
||
}
|
||
|
||
sql = "select tp.* from t_production tp where tp.catagory_id=?";
|
||
ArrayList<HashMap<String, Object>> productionList =new ArrayList<HashMap<String,Object>>();
|
||
ArrayList<HashMap<String, Object>> tempList =new ArrayList<HashMap<String,Object>>();
|
||
List<HashMap<String, Object>> levelProductionList =new ArrayList<HashMap<String,Object>>();
|
||
|
||
//获取每个等级产品list
|
||
//每个等级产品list
|
||
List<HashMap<String, Object>> prods = new ArrayList<HashMap<String, Object>>();
|
||
String catagoryId = "";
|
||
String subCatagoryId = "";//子模块id
|
||
String levelId = "";//具体等级id
|
||
HashMap<String, Object> prod = new HashMap<String,Object>();
|
||
for(int i=0; i< levelList.size(); i++){
|
||
//一级目录内的二级目录list
|
||
subSelectorList = new ArrayList<HashMap<String, Object>>();
|
||
if(levelList.get(i).containsKey("subSelectorList")){
|
||
subSelectorList = (List<HashMap<String, Object>>) levelList.get(i).get("subSelectorList");
|
||
}
|
||
|
||
for(int j=0; j<subSelectorList.size(); j++){
|
||
//二级目录内的三目录list
|
||
lastList = new ArrayList<HashMap<String, Object>>();
|
||
subCatagoryId = subSelectorList.get(j).get("id").toString();
|
||
if(subSelectorList.get(j).containsKey("levelList")){
|
||
lastList = (List<HashMap<String, Object>>) subSelectorList.get(j).get("levelList");
|
||
}
|
||
|
||
sql = "select tp.name,tp.uuid as value from t_production tp where tp.is_deleted='N' and tp.is_in_rack=1 and tp.catagory_id=?";
|
||
productionList = (ArrayList<HashMap<String, Object>>) hibernateDao.queryForListWithSql(sql.toString(), new Object[]{subCatagoryId });
|
||
|
||
|
||
|
||
for(int k=0; k<lastList.size(); k++){
|
||
tempList = new ArrayList<HashMap<String,Object>>();
|
||
for(int uu=0; uu<productionList.size(); uu++){
|
||
tempList.add((HashMap<String,Object>)productionList.get(uu).clone());
|
||
}
|
||
// tempList = (ArrayList<HashMap<String, Object>>) productionList.clone();
|
||
|
||
|
||
sql = "select tp.uuid,tp.name,1 as checked from t_production_relation tpr "
|
||
+"left JOIN t_production tp on tpr.production_id=tp.uuid "
|
||
+"where tp.is_deleted='N' and tp.is_in_rack=1 and tpr.catagory_id=? "
|
||
+"group by tp.seq";
|
||
levelProductionList = hibernateDao.queryForListWithSql(sql.toString(), new Object[]{ lastList.get(k).get("id") });
|
||
|
||
for(int n=0; n<tempList.size(); n++){
|
||
tempList.get(n).put("checked", 0);
|
||
for(int m=0; m<levelProductionList.size(); m++){
|
||
if(tempList.get(n).get("name").equals(levelProductionList.get(m).get("name"))){
|
||
tempList.get(n).put("checked", 1);
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
// ((List<HashMap<String, Object>>)((List<HashMap<String, Object>>)levelList.get(i).get("subSelectorList")).get(j).get("levelList")).get(k).put("prods", tempList);
|
||
lastList.get(k).put("prods", tempList);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
rMap.put("list", levelList);
|
||
return new RestResult(Constant.SUCCESS, "请求成功",rMap);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取类别列表
|
||
*
|
||
* @param stime
|
||
* @param etime
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "unused" })
|
||
@RequestMapping(value = "/getAllProdunctions", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getAllProdunctions(@RequestBody Object requestBody) {
|
||
|
||
HashMap<String, Object> rMap = new HashMap<String, Object>();
|
||
try {
|
||
String sql = "SELECT"
|
||
+" menu1,"
|
||
+" mainId,"
|
||
+" menu2,"
|
||
+" subId,"
|
||
+" menu3,"
|
||
+" levelId,"
|
||
+" production_name,"
|
||
+" prodId,"
|
||
+"CASE"
|
||
|
||
+" WHEN ( ISNULL( t_production_relation.production_id ) = 1 ) THEN"
|
||
+" 0 ELSE 1 "
|
||
+" END"
|
||
+" as isChecked"
|
||
+" FROM"
|
||
+" ("
|
||
+" SELECT"
|
||
+" table1.`name` AS menu1,"
|
||
+" table1.uuid as mainId,"
|
||
+" table1.seq AS seq1,"
|
||
+" table2.`name` AS menu2,"
|
||
+" table2.uuid as subId,"
|
||
+" table2.seq AS seq2,"
|
||
+" table3.`name` AS menu3,"
|
||
+" table3.UUid as levelId,"
|
||
+" table3.seq AS seq3,"
|
||
+" table3.uuid AS catagory_id,"
|
||
+" table4.`name` AS menu4,"
|
||
+" table4.uuid as prodId,"
|
||
+" table4.uuid AS production_id,"
|
||
+" table4.name as production_name,"
|
||
+" table4.seq as seq4"
|
||
+" FROM"
|
||
+" `t_production_catagory` AS table1,"
|
||
+" `t_production_catagory` AS table2,"
|
||
+" `t_production_catagory` AS table3,"
|
||
+" t_production AS table4 "
|
||
+" WHERE"
|
||
+" table1.grade = '1'"
|
||
+" AND table2.parent_id = table1.uuid"
|
||
+" AND table3.parent_id = table2.uuid "
|
||
+" AND table4.catagory_id = table2.uuid "
|
||
+" AND table1.is_deleted='N'"
|
||
+" AND table2.is_deleted='N'"
|
||
+" AND table3.is_deleted='N'"
|
||
+" AND table4.is_deleted='N'"
|
||
+" AND table4.is_in_rack=1"
|
||
+" ) production_all"
|
||
+" LEFT JOIN t_production_relation ON production_all.catagory_id = t_production_relation.catagory_id "
|
||
+" AND production_all.production_id = t_production_relation.production_id "
|
||
+"ORDER BY production_all.seq1,production_all.seq2,production_all.seq3,production_all.seq4";
|
||
List<HashMap<String, Object>> productionCatagoryList = hibernateDao.queryForListWithSql(sql.toString(), new Object[]{ });
|
||
|
||
String mainId = "";
|
||
String menu1 = "";
|
||
String lastMainId = "";
|
||
String subId = "";
|
||
String menu2 = "";
|
||
String lastSubId = "";
|
||
String levelId = "";
|
||
String menu3 = "";
|
||
String lastLevelId = "";
|
||
String lastLevelName = "";
|
||
String proId = "";
|
||
String productionName = "";
|
||
String lastProId = "";
|
||
int isChecked = 0;
|
||
HashMap<String, Object> tempMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个产品的map
|
||
*/
|
||
HashMap<String, Object> prodMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个等级的map
|
||
*/
|
||
HashMap<String, Object> levelMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个子类的map
|
||
*/
|
||
HashMap<String, Object> subMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个主类的map
|
||
*/
|
||
HashMap<String, Object> mainMap = new HashMap<String,Object>();
|
||
|
||
List<HashMap<String, Object>> prodsList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> levelsList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> subsList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> mainsList = new ArrayList<HashMap<String, Object>>();
|
||
for(int i=0; i<productionCatagoryList.size(); i++){
|
||
tempMap = productionCatagoryList.get(i);
|
||
//如果一级目录的id相等,说明是同一大类的,判断是不是同一子类、等级
|
||
if(lastMainId.equals(tempMap.get("mainId"))){
|
||
|
||
//如果是同一子类的,判断是否是同一等级
|
||
if(lastSubId.equals(tempMap.get("subId"))){
|
||
|
||
//如果是同一等级的,放入到此等级下的产品列表
|
||
if(lastLevelId.equals(tempMap.get("levelId"))){
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
subsList = (List<HashMap<String, Object>>)
|
||
mainsList.get(mainsList.size()-1).get("subSelectorList");
|
||
levelsList = (List<HashMap<String, Object>>)
|
||
subsList.get(subsList.size()-1).get("levelList");
|
||
prodsList = (List<HashMap<String, Object>>)
|
||
levelsList.get(levelsList.size()-1).get("prods");
|
||
prodsList = prodsList !=null ? prodsList:new ArrayList<HashMap<String, Object>>();
|
||
prodsList.add(prodMap);
|
||
levelsList.get(levelsList.size()-1).put("prods", prodsList);
|
||
}
|
||
else{
|
||
//不是同一等级的,等级列表一级新加一个等级,新等级下新加一个产品列表,产品列表下新加产品
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
subsList = (List<HashMap<String, Object>>)
|
||
mainsList.get(mainsList.size()-1).get("subSelectorList");
|
||
levelsList = (List<HashMap<String, Object>>)
|
||
subsList.get(subsList.size()-1).get("levelList");
|
||
levelsList = levelsList !=null ? levelsList:new ArrayList<HashMap<String, Object>>();
|
||
|
||
prodsList = new ArrayList<HashMap<String, Object>>();
|
||
prodsList.add(prodMap);
|
||
|
||
levelMap = new HashMap<String,Object>();
|
||
levelMap.put("id", tempMap.get("levelId"));
|
||
levelMap.put("name", tempMap.get("menu3"));
|
||
levelMap.put("prods", prodsList);
|
||
|
||
levelsList.add(levelMap);
|
||
subsList.get(subsList.size()-1).put("levelList", levelsList);
|
||
}
|
||
}
|
||
else{
|
||
//不是同一子类,子类列表新加一个子类,
|
||
//此子类中新加一个等级列表,等级列表中新加一个产品列表,产品列表下新加产品
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
levelsList = new ArrayList<HashMap<String, Object>>();
|
||
prodsList = new ArrayList<HashMap<String, Object>>();
|
||
prodsList.add(prodMap);
|
||
levelMap = new HashMap<String,Object>();
|
||
levelMap.put("id", tempMap.get("levelId"));
|
||
levelMap.put("name", tempMap.get("menu3"));
|
||
levelMap.put("prods", prodsList);
|
||
levelsList.add(levelMap);
|
||
|
||
subMap = new HashMap<String,Object>();
|
||
subMap.put("id", tempMap.get("subId"));
|
||
subMap.put("name", tempMap.get("menu2"));
|
||
subMap.put("levelList", levelsList);
|
||
|
||
subsList = (List<HashMap<String, Object>>)
|
||
mainsList.get(mainsList.size()-1).get("subSelectorList");
|
||
subsList = subsList !=null ? subsList:new ArrayList<HashMap<String, Object>>();
|
||
|
||
|
||
subsList.add(subMap);
|
||
mainsList.get(mainsList.size()-1).put("subSelectorList", subsList);
|
||
}
|
||
}
|
||
else{
|
||
//产品list增加产品
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
prodsList = new ArrayList<HashMap<String,Object>>();
|
||
prodsList.add(prodMap);
|
||
|
||
|
||
//等级list增加一个新的等级
|
||
levelMap = new HashMap<String,Object>();
|
||
levelMap.put("id", tempMap.get("levelId"));
|
||
levelMap.put("name", tempMap.get("menu3"));
|
||
levelMap.put("prods", prodsList);
|
||
levelsList = new ArrayList<HashMap<String,Object>>();
|
||
levelsList.add(levelMap);
|
||
|
||
//子类list增加一个子类
|
||
subsList = new ArrayList<HashMap<String,Object>>();
|
||
subMap = new HashMap<String,Object>();
|
||
subMap.put("id", tempMap.get("subId"));
|
||
subMap.put("name", tempMap.get("menu2"));
|
||
subMap.put("levelList", levelsList);
|
||
subsList.add(subMap);
|
||
|
||
//模块list增加一个子类
|
||
mainMap = new HashMap<String,Object>();
|
||
mainMap.put("id", tempMap.get("mainId"));
|
||
mainMap.put("name", tempMap.get("menu1"));
|
||
mainMap.put("subSelectorList", subsList);
|
||
mainsList.add(mainMap);
|
||
|
||
|
||
|
||
}
|
||
lastMainId = ((HashMap<String,Object>)tempMap.clone()).get("mainId").toString();
|
||
// System.out.println(lastMainId);
|
||
lastSubId = tempMap.get("subId").toString();
|
||
lastLevelId = tempMap.get("levelId").toString();
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
rMap.put("list", mainsList);
|
||
return new RestResult(Constant.SUCCESS, "请求成功",rMap);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取已选中类别列表
|
||
*
|
||
* @param stime
|
||
* @param etime
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "unused" })
|
||
@RequestMapping(value = "/getChoosedProdunctions", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getChoosedProdunctions(@RequestBody Object requestBody) {
|
||
|
||
HashMap<String, Object> rMap = new HashMap<String, Object>();
|
||
try {
|
||
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
|
||
String applyId = map.get("applyId").toString();
|
||
String userPhone = "";
|
||
String userId = "";
|
||
String userName = "";
|
||
String sql = "SELECT"
|
||
+" menu1,"
|
||
+" mainId,"
|
||
+" menu2,"
|
||
+" subId,"
|
||
+" menu3,"
|
||
+" levelId,"
|
||
+" production_name,"
|
||
+" prodId,"
|
||
+" chProd.user_id,"
|
||
+" chProd.user_name,"
|
||
+" chProd.user_phone,"
|
||
+" chProd.apply_status,"
|
||
+" chProd.apply_time,"
|
||
+"CASE"
|
||
+" WHEN ( ISNULL( t_production_relation.production_id ) = 1 ) THEN"
|
||
+" 0 ELSE 1 "
|
||
+" END"
|
||
+" as isChecked"
|
||
+" FROM"
|
||
+" ("
|
||
+" SELECT"
|
||
+" table1.`name` AS menu1,"
|
||
+" table1.uuid as mainId,"
|
||
+" table1.seq AS seq1,"
|
||
+" table2.`name` AS menu2,"
|
||
+" table2.uuid as subId,"
|
||
+" table2.seq AS seq2,"
|
||
+" table3.`name` AS menu3,"
|
||
+" table3.UUid as levelId,"
|
||
+" table3.seq AS seq3,"
|
||
+" table3.uuid AS catagory_id,"
|
||
+" table4.`name` AS menu4,"
|
||
+" table4.uuid as prodId,"
|
||
+" table4.uuid AS production_id,"
|
||
+" table4.name as production_name,"
|
||
+" table4.seq as seq4"
|
||
+" FROM"
|
||
+" `t_production_catagory` AS table1,"
|
||
+" `t_production_catagory` AS table2,"
|
||
+" `t_production_catagory` AS table3,"
|
||
+" t_production AS table4 "
|
||
+" WHERE"
|
||
+" table1.grade = '1'"
|
||
+" AND table2.parent_id = table1.uuid"
|
||
+" AND table3.parent_id = table2.uuid "
|
||
+" AND table4.catagory_id = table2.uuid "
|
||
+" AND table1.is_deleted='N'"
|
||
+" AND table2.is_deleted='N'"
|
||
+" AND table3.is_deleted='N'"
|
||
+" AND table4.is_deleted='N'"
|
||
+" AND table4.is_in_rack=1"
|
||
+" ) production_all"
|
||
+" LEFT JOIN t_production_relation ON production_all.catagory_id = t_production_relation.catagory_id "
|
||
+" AND production_all.production_id = t_production_relation.production_id ,"
|
||
+" (select tpad.level_id,tpad.apply_status as dStatus,tpa.user_id,tpa.user_name,tpa.user_phone,"
|
||
+" tpa.apply_status,tpa.apply_time "
|
||
+" from t_production_apply_detail tpad LEFT JOIN "
|
||
+" t_production_apply tpa on tpad.apply_id=tpa.uuid "
|
||
+" where tpa.uuid=?) as chProd "
|
||
+" WHERE"
|
||
+" production_all.levelId = chProd.level_id "
|
||
+"ORDER BY production_all.seq1,production_all.seq2,production_all.seq3,production_all.seq4";
|
||
List<HashMap<String, Object>> productionCatagoryList = hibernateDao.queryForListWithSql(sql.toString(), new Object[]{ applyId });
|
||
|
||
String mainId = "";
|
||
String menu1 = "";
|
||
String lastMainId = "";
|
||
String subId = "";
|
||
String menu2 = "";
|
||
String lastSubId = "";
|
||
String levelId = "";
|
||
String menu3 = "";
|
||
String lastLevelId = "";
|
||
String lastLevelName = "";
|
||
String proId = "";
|
||
String productionName = "";
|
||
String lastProId = "";
|
||
int isChecked = 0;
|
||
HashMap<String, Object> tempMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个产品的map
|
||
*/
|
||
HashMap<String, Object> prodMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个等级的map
|
||
*/
|
||
HashMap<String, Object> levelMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个子类的map
|
||
*/
|
||
HashMap<String, Object> subMap = new HashMap<String,Object>();
|
||
/**
|
||
* 某个主类的map
|
||
*/
|
||
HashMap<String, Object> mainMap = new HashMap<String,Object>();
|
||
|
||
List<HashMap<String, Object>> prodsList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> levelsList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> subsList = new ArrayList<HashMap<String, Object>>();
|
||
List<HashMap<String, Object>> mainsList = new ArrayList<HashMap<String, Object>>();
|
||
for(int i=0; i<productionCatagoryList.size(); i++){
|
||
tempMap = productionCatagoryList.get(i);
|
||
userName = productionCatagoryList.get(i).get("user_name").toString();
|
||
userPhone = productionCatagoryList.get(i).get("user_phone").toString();
|
||
userId = productionCatagoryList.get(i).get("user_id").toString();
|
||
//如果一级目录的id相等,说明是同一大类的,判断是不是同一子类、等级
|
||
if(lastMainId.equals(tempMap.get("mainId"))){
|
||
|
||
//如果是同一子类的,判断是否是同一等级
|
||
if(lastSubId.equals(tempMap.get("subId"))){
|
||
|
||
//如果是同一等级的,放入到此等级下的产品列表
|
||
if(lastLevelId.equals(tempMap.get("levelId"))){
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
subsList = (List<HashMap<String, Object>>)
|
||
mainsList.get(mainsList.size()-1).get("subSelectorList");
|
||
levelsList = (List<HashMap<String, Object>>)
|
||
subsList.get(subsList.size()-1).get("levelList");
|
||
prodsList = (List<HashMap<String, Object>>)
|
||
levelsList.get(levelsList.size()-1).get("prods");
|
||
prodsList = prodsList !=null ? prodsList:new ArrayList<HashMap<String, Object>>();
|
||
prodsList.add(prodMap);
|
||
levelsList.get(levelsList.size()-1).put("prods", prodsList);
|
||
}
|
||
else{
|
||
//不是同一等级的,等级列表一级新加一个等级,新等级下新加一个产品列表,产品列表下新加产品
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
subsList = (List<HashMap<String, Object>>)
|
||
mainsList.get(mainsList.size()-1).get("subSelectorList");
|
||
levelsList = (List<HashMap<String, Object>>)
|
||
subsList.get(subsList.size()-1).get("levelList");
|
||
levelsList = levelsList !=null ? levelsList:new ArrayList<HashMap<String, Object>>();
|
||
|
||
prodsList = new ArrayList<HashMap<String, Object>>();
|
||
prodsList.add(prodMap);
|
||
|
||
levelMap = new HashMap<String,Object>();
|
||
levelMap.put("id", tempMap.get("levelId"));
|
||
levelMap.put("name", tempMap.get("menu3"));
|
||
levelMap.put("prods", prodsList);
|
||
|
||
levelsList.add(levelMap);
|
||
subsList.get(subsList.size()-1).put("levelList", levelsList);
|
||
}
|
||
}
|
||
else{
|
||
//不是同一子类,子类列表新加一个子类,
|
||
//此子类中新加一个等级列表,等级列表中新加一个产品列表,产品列表下新加产品
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
levelsList = new ArrayList<HashMap<String, Object>>();
|
||
prodsList = new ArrayList<HashMap<String, Object>>();
|
||
prodsList.add(prodMap);
|
||
levelMap = new HashMap<String,Object>();
|
||
levelMap.put("id", tempMap.get("levelId"));
|
||
levelMap.put("name", tempMap.get("menu3"));
|
||
levelMap.put("prods", prodsList);
|
||
levelsList.add(levelMap);
|
||
|
||
subMap = new HashMap<String,Object>();
|
||
subMap.put("id", tempMap.get("subId"));
|
||
subMap.put("name", tempMap.get("menu2"));
|
||
subMap.put("levelList", levelsList);
|
||
|
||
subsList = (List<HashMap<String, Object>>)
|
||
mainsList.get(mainsList.size()-1).get("subSelectorList");
|
||
subsList = subsList !=null ? subsList:new ArrayList<HashMap<String, Object>>();
|
||
|
||
|
||
subsList.add(subMap);
|
||
mainsList.get(mainsList.size()-1).put("subSelectorList", subsList);
|
||
}
|
||
}
|
||
else{
|
||
//产品list增加产品
|
||
prodMap = new HashMap<String,Object>();
|
||
prodMap.put("id", tempMap.get("prodId"));
|
||
prodMap.put("name", tempMap.get("production_name"));
|
||
prodMap.put("value", tempMap.get("prodId"));
|
||
prodMap.put("isChecked", tempMap.get("isChecked"));
|
||
|
||
prodsList = new ArrayList<HashMap<String,Object>>();
|
||
prodsList.add(prodMap);
|
||
|
||
|
||
//等级list增加一个新的等级
|
||
levelMap = new HashMap<String,Object>();
|
||
levelMap.put("id", tempMap.get("levelId"));
|
||
levelMap.put("name", tempMap.get("menu3"));
|
||
levelMap.put("prods", prodsList);
|
||
levelsList = new ArrayList<HashMap<String,Object>>();
|
||
levelsList.add(levelMap);
|
||
|
||
//子类list增加一个子类
|
||
subsList = new ArrayList<HashMap<String,Object>>();
|
||
subMap = new HashMap<String,Object>();
|
||
subMap.put("id", tempMap.get("subId"));
|
||
subMap.put("name", tempMap.get("menu2"));
|
||
subMap.put("levelList", levelsList);
|
||
subsList.add(subMap);
|
||
|
||
//模块list增加一个子类
|
||
mainMap = new HashMap<String,Object>();
|
||
mainMap.put("id", tempMap.get("mainId"));
|
||
mainMap.put("name", tempMap.get("menu1"));
|
||
mainMap.put("subSelectorList", subsList);
|
||
mainsList.add(mainMap);
|
||
|
||
|
||
|
||
}
|
||
lastMainId = ((HashMap<String,Object>)tempMap.clone()).get("mainId").toString();
|
||
// System.out.println(lastMainId);
|
||
lastSubId = tempMap.get("subId").toString();
|
||
lastLevelId = tempMap.get("levelId").toString();
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
rMap.put("list", mainsList);
|
||
rMap.put("userPhone", userPhone);
|
||
rMap.put("userId", userId);
|
||
rMap.put("userName", userName);
|
||
return new RestResult(Constant.SUCCESS, "请求成功",rMap);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取类别列表
|
||
*
|
||
* @param stime
|
||
* @param etime
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "unused" })
|
||
@RequestMapping(value = "/getProductionList", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getProductionList(@RequestBody Object requestBody) {
|
||
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
|
||
String userId = map.get("userId") == null || "".equals(map.get("userId")) ? null : map.get("userId").toString();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if (info == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
String catagoryId = map.get("catagoryId").toString();
|
||
HashMap<String, Object> rMap = new HashMap<String, Object>();
|
||
try {
|
||
String sql = "select tp.uuid,tp.name,1 as checked from t_production_relation tpr "
|
||
+"left JOIN t_production tp on tpr.production_id=tp.uuid "
|
||
+"where tp.is_deleted='N' and tp.is_in_rack=1 and tpr.catagory_id=? "
|
||
+"group by tp.seq";
|
||
List<Map<String, Object>> productionList = hibernateDao.queryForListWithSql(sql.toString(), new Object[]{ catagoryId });
|
||
rMap.put("list", productionList);
|
||
return new RestResult(Constant.SUCCESS, "请求成功",rMap);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 保存我的产品列表
|
||
* @param requestBody
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "unused" })
|
||
@RequestMapping(value = "/saveMyProductionApply", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult saveMyProductionApply(@RequestBody Object requestBody) {
|
||
|
||
HashMap<String, Object> rMap = new HashMap<String,Object>();
|
||
try {
|
||
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
|
||
String userId = map.get("userId") == null || "".equals(map.get("userId")) ? null : map.get("userId").toString();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if (info == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
String applyId = UUID.randomUUID().toString();
|
||
|
||
int applyStatus = 1;
|
||
String userName = map.get("userName").toString();
|
||
//插入到申请表
|
||
String insertSql = "INSERT INTO t_production_apply (uuid,user_id,user_phone,apply_time,apply_status,"
|
||
+ " creator,modifier,gmt_created,gmt_modified,user_name "
|
||
+ ") "
|
||
+ "VALUES(?,?,?,SYSDATE(),?,"
|
||
+ "?,?,SYSDATE(),SYSDATE(),?"
|
||
+ ")";
|
||
hibernateDao.updateWithSql(insertSql,new Object[] { applyId,map.get("userId"),
|
||
map.get("userPhone"),applyStatus,
|
||
map.get("userId"),map.get("userId"),userName});
|
||
|
||
ArrayList list = (ArrayList) map.get("choosedLevelIds");
|
||
//插入到详情表
|
||
String levelId = "";
|
||
for(int i=0;i<list.size();i++){
|
||
levelId = (String) list.get(i);
|
||
// detailId = UUID.randomUUID().toString();
|
||
insertSql = "INSERT INTO t_production_apply_detail (uuid,apply_id,level_id,apply_time,apply_status,"
|
||
+ " creator,modifier,gmt_created,gmt_modified "
|
||
+ ") "
|
||
+ "VALUES(?,?,?,SYSDATE(),?,"
|
||
+ "?,?,SYSDATE(),SYSDATE() "
|
||
+ ")";
|
||
hibernateDao.updateWithSql(insertSql,new Object[] { UUID.randomUUID().toString(),applyId,
|
||
levelId,1,
|
||
map.get("userId"),map.get("userId")});
|
||
}
|
||
|
||
rMap.put("applyId", applyId);
|
||
|
||
return new RestResult(Constant.SUCCESS, "提交成功", rMap);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 获取父节点为parentID的一级、二级父节点id
|
||
* @param levelList
|
||
* @param parentId
|
||
* @param grade
|
||
* @return
|
||
*/
|
||
public static HashMap<String,Integer> getIndex(List<HashMap<String, Object>> levelList,String parentId,int grade){
|
||
HashMap<String,Integer> indexMap = new HashMap<String,Integer>();
|
||
int firstIndex = -1;
|
||
int secondIndex = -1;
|
||
indexMap.put("firstIndex", firstIndex);
|
||
indexMap.put("secondIndex", secondIndex);
|
||
if(grade == 2){
|
||
for(int i=0; i< levelList.size(); i++){
|
||
if(levelList.get(i).get("id").equals(parentId)){
|
||
firstIndex = i;
|
||
indexMap.put("firstIndex", firstIndex);
|
||
return indexMap;
|
||
}
|
||
}
|
||
}
|
||
else if(grade == 3){
|
||
for(int i=0; i< levelList.size(); i++){
|
||
for(int j=0; j<((List<HashMap<String,Object>>)levelList.get(i).get("subSelectorList")).size(); j++){
|
||
if(((List<HashMap<String,Object>>)levelList.get(i).get("subSelectorList")).get(j).get("id").equals(parentId)){
|
||
firstIndex = i;
|
||
secondIndex = j;
|
||
indexMap.put("firstIndex", firstIndex);
|
||
indexMap.put("secondIndex", secondIndex);
|
||
return indexMap;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return indexMap;
|
||
|
||
}
|
||
|
||
|
||
}
|