241 lines
9.7 KiB
Plaintext
241 lines
9.7 KiB
Plaintext
|
|
package com.nationalelectric.greenH5;
|
|||
|
|
|
|||
|
|
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.DTO.GreenMealTicketApplyDTO;
|
|||
|
|
import com.nationalelectric.greenH5.DTO.UserDTO;
|
|||
|
|
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
|||
|
|
import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc;
|
|||
|
|
import com.sgcc.uap.service.validator.ServiceValidatorBaseException;
|
|||
|
|
import com.sgcc.uap.persistence.IHibernateDao;
|
|||
|
|
|
|||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|||
|
|
import java.util.*;
|
|||
|
|
|
|||
|
|
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
|||
|
|
import javax.annotation.Resource;
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* <b>概述</b>:<br>
|
|||
|
|
* <p>
|
|||
|
|
* <b>功能</b>:<br>
|
|||
|
|
*
|
|||
|
|
* @author BOWEI
|
|||
|
|
*/
|
|||
|
|
@Controller
|
|||
|
|
@RequestMapping("/greenFoodsMenu")
|
|||
|
|
public class GreenFoodsMenuController extends GreenBaseController {
|
|||
|
|
|
|||
|
|
@Resource
|
|||
|
|
private IHibernateDao hibernateDao;
|
|||
|
|
@Resource
|
|||
|
|
private IGreenOperateLogBizc greenOperateLogBizc;
|
|||
|
|
@Autowired
|
|||
|
|
private BaseServiceImpl baseService;
|
|||
|
|
|
|||
|
|
/** 外卖点餐列表 */
|
|||
|
|
@RequestMapping(value = "/getAttrTypes", method = RequestMethod.POST)
|
|||
|
|
@ResponseBody
|
|||
|
|
public RestResult getAttrTypes(Map<String, Object> rmap) {
|
|||
|
|
String userId = rmap.get("userId").toString();
|
|||
|
|
GreenUserInfo info = getUserInfo(userId);
|
|||
|
|
if (info == null) {
|
|||
|
|
return new RestResult(Constant.FAILED, "非法用户");
|
|||
|
|
}
|
|||
|
|
try {
|
|||
|
|
|
|||
|
|
String sql = "select attr_name as \"attr_name\" from green_market_attribute where attr_type=0 and attr_range=1 and is_deleted='N' order by sort";
|
|||
|
|
List<Map<String, String>> list = hibernateDao.queryForListWithSql(sql);
|
|||
|
|
|
|||
|
|
return new RestResult(Constant.SUCCESS, "成功", list);
|
|||
|
|
} catch (ServiceValidatorBaseException e) {
|
|||
|
|
throw e;
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
return new RestResult(Constant.FAILED, "返回异常");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 外卖点餐列表 */
|
|||
|
|
@RequestMapping(value = "/list", method = RequestMethod.POST)
|
|||
|
|
@ResponseBody
|
|||
|
|
public RestResult list(Map<String, Object> map) {
|
|||
|
|
String userId = map.get("userId").toString();
|
|||
|
|
String attrType = map.get("attrType")==null?"":map.get("attrType").toString();
|
|||
|
|
GreenUserInfo info = getUserInfo(userId);
|
|||
|
|
if (info == null) {
|
|||
|
|
return new RestResult(Constant.FAILED, "非法用户");
|
|||
|
|
}
|
|||
|
|
try {
|
|||
|
|
|
|||
|
|
List<Map<String, String>> menuList1 = new ArrayList<Map<String,String>>();
|
|||
|
|
|
|||
|
|
String sql = "SELECT a.id as \"id\",a.location_id as \"location_id\",a.kinds_id as \"kinds_id\",a.menu_id as \"menu_id\","
|
|||
|
|
+ "a.no_buy_num as \"no_buy_num\",a.sell_number as \"sell_number\",a.quota as \"quota\",a.upload_date as \"upload_date\","
|
|||
|
|
+ "a.status as \"status\",a.creator as \"creator\",a.modifier as \"modifier\",to_char(a.gmt_created,'YYYY-MM-DD HH24:MI:SS') as \"gmt_created\",to_char(a.gmt_modified,'YYYY-MM-DD HH24:MI:SS') as \"gmt_modified\",a.is_deleted as \"is_deleted\","
|
|||
|
|
+ "b.kinds as \"kinds\",b.food_name as \"food_name\",b.picture as \"picture\",b.price as \"price\",b.unit as \"company\" "
|
|||
|
|
+ "FROM GREEN_FOODS_VARIETY a left join GREEN_FOODS_KINDS b on a.kinds_id = b.id where a.is_deleted = 'N' "
|
|||
|
|
+ " and b.kinds =? "
|
|||
|
|
+ "and a.upload_date = to_char(sysdate, 'yyyy-mm-dd')";
|
|||
|
|
menuList1 = hibernateDao.queryForListWithSql(sql,new Object[]{attrType});
|
|||
|
|
|
|||
|
|
for (Map<String, String> map1 : menuList1) {
|
|||
|
|
String pictureString = map1.get("picture");
|
|||
|
|
map1.put("picture", baseService.getImageBase64(pictureString));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// greenOperateLogBizc.addLog(Constant.TAKE_OUT_FOOD,
|
|||
|
|
// Constant.QUERY, Constant.OPERATE_SUCCESS, "查询外卖预定列表",
|
|||
|
|
// Constant.LOG_OPERATE, userDTO.getUserId());
|
|||
|
|
// return map;
|
|||
|
|
return new RestResult(Constant.SUCCESS, "成功", menuList1);
|
|||
|
|
} catch (ServiceValidatorBaseException e) {
|
|||
|
|
throw e;
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
// greenOperateLogBizc.addLog(Constant.TAKE_OUT_FOOD,
|
|||
|
|
// Constant.QUERY, Constant.OPERATE_FAIL, "查询外卖预定列表",
|
|||
|
|
// Constant.LOG_ERROR, userDTO.getUserId());
|
|||
|
|
return new RestResult(Constant.FAILED, "返回异常");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 主页菜单列表 */
|
|||
|
|
@RequestMapping(value = "/homeFood", method = RequestMethod.POST)
|
|||
|
|
@ResponseBody
|
|||
|
|
public RestResult homeFood(@RequestBody Object requestBody) {
|
|||
|
|
UserDTO userDTO = new ObjectMapper().convertValue(requestBody, new TypeReference<UserDTO>() {
|
|||
|
|
});
|
|||
|
|
String userId = userDTO.getUserId();
|
|||
|
|
GreenUserInfo info = getUserInfo(userId);
|
|||
|
|
if (info == null) {
|
|||
|
|
return new RestResult(Constant.FAILED, "非法用户");
|
|||
|
|
}
|
|||
|
|
try {
|
|||
|
|
List<Map<String, String>> menuList = null;
|
|||
|
|
|
|||
|
|
GreenUserInfo userInfo = getUserInfo(userDTO.getUserId());
|
|||
|
|
String ownerLocation = userInfo.getOwnerLocation();
|
|||
|
|
// 数据处理,当没有的时候,默认一个
|
|||
|
|
if (ownerLocation == null || ownerLocation.equals("")) {
|
|||
|
|
ownerLocation = "1";
|
|||
|
|
String ss = "update green_user_info set owner_location = '1' where id = ?";
|
|||
|
|
hibernateDao.update(ss, new Object[] { userId });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 首页菜单推荐,今日没有菜单,显示最近一日菜单
|
|||
|
|
// menuList = hibernateDao.queryForListWithSql(
|
|||
|
|
// "SELECT a.location_id,b.kinds,b.food_name,b.price,b.picture FROM
|
|||
|
|
// GREEN_FOODS_VARIETY a left join GREEN_FOODS_KINDS b on a.kinds_id
|
|||
|
|
// = b.id where a.is_deleted = 'N' "
|
|||
|
|
// + " and a.location_id = ? and a.upload_date = (SELECT upload_date
|
|||
|
|
// FROM GREEN_FOODS_VARIETY WHERE upload_date <= DATE_FORMAT(now(),
|
|||
|
|
// '%Y-%m-%d') AND location_id = ? AND is_deleted = 'N' ORDER BY
|
|||
|
|
// upload_date DESC LIMIT 1 ) ",
|
|||
|
|
// new Object[] { ownerLocation ,ownerLocation });
|
|||
|
|
|
|||
|
|
menuList = hibernateDao.queryForListWithSql(
|
|||
|
|
"SELECT a.location_id,b.kinds,b.food_name,b.price,b.unit,b.picture FROM GREEN_FOODS_VARIETY a left join GREEN_FOODS_KINDS b on a.kinds_id = b.id where a.is_deleted = 'N' "
|
|||
|
|
+ " and a.location_id = ? and a.upload_date = DATE_FORMAT(now(), '%Y-%m-%d')",
|
|||
|
|
new Object[] { ownerLocation });
|
|||
|
|
|
|||
|
|
for (Map<String, String> map : menuList) {
|
|||
|
|
String pictureString = map.get("picture");
|
|||
|
|
map.put("picture", baseService.getImageBase64(pictureString));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|||
|
|
ArrayList<String> list = new ArrayList<String>();
|
|||
|
|
map.put("cookedFoodList", list);
|
|||
|
|
map.put("fruitList", list);
|
|||
|
|
map.put("mainFoodList", list);
|
|||
|
|
map.put("vegetablesList", list);
|
|||
|
|
map.put("seasoningList", list);
|
|||
|
|
|
|||
|
|
List<Object> HQ_cookedFoodList = new ArrayList<Object>();
|
|||
|
|
List<Object> HQ_fruitList = new ArrayList<Object>();
|
|||
|
|
List<Object> HQ_mainFoodList = new ArrayList<Object>();
|
|||
|
|
List<Object> HQ_vegetablesList = new ArrayList<Object>();
|
|||
|
|
List<Object> HQ_seasoningList = new ArrayList<Object>();
|
|||
|
|
|
|||
|
|
List<Object> YZ_cookedFoodList = new ArrayList<Object>();
|
|||
|
|
List<Object> YZ_fruitList = new ArrayList<Object>();
|
|||
|
|
List<Object> YZ_mainFoodList = new ArrayList<Object>();
|
|||
|
|
List<Object> YZ_vegetablesList = new ArrayList<Object>();
|
|||
|
|
List<Object> YZ_seasoningList = new ArrayList<Object>();
|
|||
|
|
if (menuList != null) {
|
|||
|
|
for (int i = 0; i < menuList.size(); i++) {
|
|||
|
|
String kinds = menuList.get(i).get("kinds");
|
|||
|
|
String locationId = String.valueOf(menuList.get(i).get("location_id"));
|
|||
|
|
// 总部食堂菜品
|
|||
|
|
if (Constant.MENU_COOKED_FOOD.equals(kinds) && "1".equals(locationId)) {
|
|||
|
|
HQ_cookedFoodList.add(menuList.get(i));
|
|||
|
|
map.put("cookedFoodList", HQ_cookedFoodList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_FRUIT.equals(kinds) && "1".equals(locationId)) {
|
|||
|
|
HQ_fruitList.add(menuList.get(i));
|
|||
|
|
map.put("fruitList", HQ_fruitList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_MAIN_FOOD.equals(kinds) && "1".equals(locationId)) {
|
|||
|
|
HQ_mainFoodList.add(menuList.get(i));
|
|||
|
|
map.put("mainFoodList", HQ_mainFoodList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_VEGETABLES.equals(kinds) && "1".equals(locationId)) {
|
|||
|
|
HQ_vegetablesList.add(menuList.get(i));
|
|||
|
|
map.put("vegetablesList", HQ_vegetablesList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_SEASONING.equals(kinds) && "1".equals(locationId)) {
|
|||
|
|
HQ_seasoningList.add(menuList.get(i));
|
|||
|
|
map.put("seasoningList", HQ_seasoningList);
|
|||
|
|
}
|
|||
|
|
// 银座食堂菜品
|
|||
|
|
if (Constant.MENU_COOKED_FOOD.equals(kinds) && "2".equals(locationId)) {
|
|||
|
|
YZ_cookedFoodList.add(menuList.get(i));
|
|||
|
|
map.put("cookedFoodList", YZ_cookedFoodList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_FRUIT.equals(kinds) && "2".equals(locationId)) {
|
|||
|
|
YZ_fruitList.add(menuList.get(i));
|
|||
|
|
map.put("fruitList", YZ_fruitList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_MAIN_FOOD.equals(kinds) && "2".equals(locationId)) {
|
|||
|
|
YZ_mainFoodList.add(menuList.get(i));
|
|||
|
|
map.put("mainFoodList", YZ_mainFoodList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_VEGETABLES.equals(kinds) && "2".equals(locationId)) {
|
|||
|
|
YZ_vegetablesList.add(menuList.get(i));
|
|||
|
|
map.put("vegetablesList", YZ_vegetablesList);
|
|||
|
|
}
|
|||
|
|
if (Constant.MENU_SEASONING.equals(kinds) && "2".equals(locationId)) {
|
|||
|
|
YZ_seasoningList.add(menuList.get(i));
|
|||
|
|
map.put("seasoningList", YZ_seasoningList);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// greenOperateLogBizc.addLog(Constant.HOME, Constant.QUERY,
|
|||
|
|
// Constant.OPERATE_SUCCESS, "查询首页菜品推荐", Constant.LOG_OPERATE,
|
|||
|
|
// userDTO.getUserId());
|
|||
|
|
|
|||
|
|
return new RestResult(Constant.SUCCESS, "成功", map);
|
|||
|
|
} catch (ServiceValidatorBaseException e) {
|
|||
|
|
throw e;
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
// greenOperateLogBizc.addLog(Constant.HOME, Constant.QUERY,
|
|||
|
|
// Constant.OPERATE_FAIL, "查询首页菜品推荐", Constant.LOG_ERROR,
|
|||
|
|
// userDTO.getUserId());
|
|||
|
|
return new RestResult(Constant.FAILED, "返回异常");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|