hz-zhhq-app-service/greenH5modul/.svn/pristine/54/54816918cfefe98d3a64a5eb6c2...

212 lines
8.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nationalelectric.greenH5;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.nationalelectirc.Constant.Constant;
import com.nationalelectirc.utils.RestResult;
import com.nationalelectric.greenH5.DTO.GreenMealTicketApplyDTO;
import com.nationalelectric.greenH5.DTO.GreenMealTicketDTO;
import com.nationalelectric.greenH5.bizc.IGreenMealTicketBizc;
import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc;
import com.nationalelectric.greenH5.po.GreenUserInfo;
import com.nationalelectric.greenH5.utils.AesEncryptUtil;
import com.nationalelectric.greenH5.utils.DateTime;
import com.nationalelectric.greenH5.utils.DateUtil;
import com.nationalelectric.greenH5.utils.JSONUtil;
import com.nationalelectric.greenH5.utils.MD5Util;
import com.sgcc.uap.persistence.IHibernateDao;
import org.springframework.web.bind.annotation.RequestMapping;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestBody;
/**
* <b>概述</b><br>
* <p>
* <b>功能</b><br>
*
* @author bowei
*/
@Controller
@RequestMapping("/greenMealCard")
public class GreenMealCardController extends GreenBaseController {
/**
* greenmealticket GreenMealTicket逻辑构件
*/
@Resource
private IGreenMealTicketBizc greenmealticketBizc;
@Resource
private IHibernateDao hibernateDao;
@Resource
private IGreenOperateLogBizc greenOperateLogBizc;
@Resource
private GreenDictionaryInfoController greenDictionaryInfoController;
/** 餐券领取列表 */
@RequestMapping(value = "/initData", method = RequestMethod.POST)
@ResponseBody
public RestResult initData(@RequestBody Object requestBody) {
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
String userId = map.get("userId").toString();
String orderId = map.get("orderId").toString();
GreenUserInfo info = getUserInfo(userId);
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
try {
String sql = "select t.user_id,t.canteen_staff_id,t.card_id from t_zhhq_canteen_user_rel t "
+ "where t.is_deleted=0 and t.user_id=?";
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
list = hibernateDao.queryForListWithSql(sql,new Object[] { userId });
if(list.isEmpty()){
return new RestResult(Constant.NO_CK, "你还未绑定餐卡。");
}
if(list.size() == 0){
return new RestResult(Constant.NO_CK, "你还未绑定餐卡。");
}
Map<String, Object> rmap = new HashMap<String, Object>();
// rmap.put("amout",list.get(0).get("amount").toString());
String cardId = list.get(0).get("card_id").toString();
String s = AesEncryptUtil.encrypt(list.get(0).get("canteen_staff_id").toString()+"&"+cardId+"&"+orderId+"&"+DateTime.now().toString());
rmap.put("qCode",s);
rmap.put("staffId", list.get(0).get("canteen_staff_id"));
rmap.put("cardId", list.get(0).get("cardId"));
return new RestResult(Constant.SUCCESS, "成功", rmap);
} catch (Exception e) {
e.printStackTrace();
/*greenOperateLogBizc.addLog(Constant.MEAL_TICKET_B, Constant.QUERY, Constant.OPERATE_FAIL, "查询餐券领取列表",
Constant.LOG_ERROR, greenMealTicketDTO.getUserId());*/
return new RestResult(Constant.FAILED, "返回异常");
}
}
/** 餐券领取列表 */
@RequestMapping(value = "/getMealCard", method = RequestMethod.POST)
@ResponseBody
public RestResult getMealCard(@RequestBody Object requestBody) {
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
String userId = map.get("userId").toString();
String amount = map.get("amount").toString();
GreenUserInfo info = getUserInfo(userId);
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
try {
String codeMsg = "请出示二维码领取外卖";
String sql = "SELECT userId,amount FROM green_meal_card where is_deleted = 'N' AND userId = ? and type = 0";
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
list = hibernateDao.queryForListWithSql(sql,new Object[] { userId });
if(list.isEmpty()){
return new RestResult(Constant.FAILED, "你还未绑定餐卡。");
}
if(list.size() == 0){
return new RestResult(Constant.FAILED, "你还未绑定餐卡。");
}
Map<String, Object> rmap = new HashMap<String, Object>();
rmap.put("amout",list.get(0).get("amount").toString());
if( Float.valueOf(amount) > Float.valueOf(list.get(0).get("amount").toString())){
rmap.put("falg",1);
}else{
rmap.put("falg",0);
}
List<Map<String, Object>> dictionaryInfo2 = greenDictionaryInfoController.getDictionaryInfo("mealsTips");
rmap.put("codeMsg",dictionaryInfo2.get(0).get("data_value"));
String s = AesEncryptUtil.encrypt(list.get(0).get("userId").toString()+"&"+DateTime.now().toString());
rmap.put("qCode",s);
return new RestResult(Constant.SUCCESS, "成功", rmap);
} catch (Exception e) {
e.printStackTrace();
/*greenOperateLogBizc.addLog(Constant.MEAL_TICKET_B, Constant.QUERY, Constant.OPERATE_FAIL, "查询餐券领取列表",
Constant.LOG_ERROR, greenMealTicketDTO.getUserId());*/
return new RestResult(Constant.FAILED, "返回异常");
}
}
/** 获取本月餐券剩余数量 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/eat", method = RequestMethod.POST)
@ResponseBody
public RestResult eat(@RequestBody Object requestBody) {
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
String userId = map.get("userId").toString();
GreenUserInfo info = getUserInfo(userId);
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
SimpleDateFormat Hsdf = new SimpleDateFormat("HH");
int mPass = DateUtil.getMPass(DateTime.now().toString(), "2020-03-23 14:40:45", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
if(mPass > 5){
return new RestResult(Constant.FAILED, "二维码已过期!");
}
int hour2 = new DateTime().getHour();
List<Map<String, Object>> dictionaryInfo2 = greenDictionaryInfoController.getDictionaryInfo("eatSetting");
String lunchPrice = "0",dinnerPrice = "0",dinnerTime;
int lunchStartTime = 11 ,lunchEndTime = 15,dinnerStartTime = 16 ,dinnerEndTime = 20;
int price = 0;
for (int i = 0; i < dictionaryInfo2.size(); i++) {
if(dictionaryInfo2.get(i).get("data_code").toString().equals("lunchPrice")){
lunchPrice = dictionaryInfo2.get(i).get("data_value").toString();
}else if(dictionaryInfo2.get(i).get("data_code").toString().equals("dinnerPrice")){
dinnerPrice = dictionaryInfo2.get(i).get("data_value").toString();
}else if(dictionaryInfo2.get(i).get("data_code").toString().equals("lunchTime")){
String[] split = dictionaryInfo2.get(i).get("data_value").toString().split("-");
lunchStartTime = Integer.valueOf(split[0]);
lunchEndTime = Integer.valueOf(split[1]);
}else if(dictionaryInfo2.get(i).get("data_code").toString().equals("dinnerTime")){
String[] split = dictionaryInfo2.get(i).get("data_value").toString().split("-");
dinnerStartTime = Integer.valueOf(split[0]);
dinnerEndTime = Integer.valueOf(split[1]);
}
}
if(hour2<lunchStartTime){
return new RestResult(Constant.FAILED, "还未到就餐时间!");
}
if(dinnerEndTime < hour2){
return new RestResult(Constant.FAILED, "还未到就餐时间!");
}
if(lunchEndTime < hour2 && hour2 < dinnerStartTime){
return new RestResult(Constant.FAILED, "还未到就餐时间!");
}
int eatFlag = 0;
if(lunchStartTime < hour2 && hour2 < lunchEndTime){
eatFlag = 1;
price = Integer.valueOf(lunchPrice);
}
if(dinnerStartTime < hour2 && hour2 < dinnerEndTime){
eatFlag = 2;
price = Integer.valueOf(dinnerPrice);
}
try {
String sql3 = "UPDATE green_meal_card SET amount = amount - ? WHERE type = '0' AND userId = ? and is_deleted = 'N' ";
hibernateDao.updateWithSql(sql3, new Object[] { price,userId});
return new RestResult(Constant.SUCCESS, "成功", map);
} catch (Exception e) {
e.printStackTrace();
/*greenOperateLogBizc.addLog(Constant.MEAL_TICKET_B, Constant.QUERY, Constant.OPERATE_FAIL, "查询餐券领取列表",
Constant.LOG_ERROR, greenMealTicketDTO.getUserId());*/
return new RestResult(Constant.FAILED, "返回异常");
}
}
}