208 lines
8.0 KiB
Plaintext
208 lines
8.0 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.text.SimpleDateFormat;
|
||
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 java.util.concurrent.locks.ReentrantLock;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import org.codehaus.jackson.map.ObjectMapper;
|
||
import org.codehaus.jackson.type.TypeReference;
|
||
import org.springframework.beans.BeanUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||
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.jysoft.weChat.service.WechatService;
|
||
import com.jysoft.weChat.vo.ContentVo;
|
||
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.enums.OrderStatus;
|
||
import com.nationalelectric.greenH5.enums.TakeStatus;
|
||
import com.nationalelectric.greenH5.po.GreenActiveInfo;
|
||
import com.nationalelectric.greenH5.po.GreenActiveSign;
|
||
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 com.sgcc.uap.service.validator.ServiceValidatorBaseException;
|
||
|
||
import net.sf.json.JSONObject;
|
||
import net.sf.json.JSONArray;
|
||
|
||
|
||
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
*
|
||
* @author chenweikang
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/greenActiveInfo")
|
||
public class GreenActiveInfoController extends GreenBaseController {
|
||
|
||
|
||
@Resource
|
||
private IHibernateDao hibernateDao;
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
@Resource
|
||
private WechatService wService;
|
||
/**
|
||
* greenfoodorderdetail GreenFoodOrderDetail逻辑构件
|
||
*/
|
||
@Resource
|
||
private IGreenOperateLogBizc greenOperateLogBizc;
|
||
|
||
private ReentrantLock lock = new ReentrantLock();
|
||
|
||
|
||
/**用户订单列表*/
|
||
@RequestMapping(value="/getActiveInfoList", method = RequestMethod.POST)
|
||
@ResponseBody
|
||
public RestResult getActiveInfoList(@RequestBody Map<String,Object> map){
|
||
|
||
String userId = (String) map.get("userId");
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if(info==null){
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
try {
|
||
Integer signUp = (Integer) map.get("signUp");
|
||
//分页信息
|
||
Integer pageSize = (Integer) map.get("pageSize");
|
||
Integer page = (Integer) map.get("pageNum");
|
||
|
||
page = (page-1) * pageSize;
|
||
int limit = ((page > 0 ? page : 1) -1) * pageSize;
|
||
|
||
String sql = "SELECT ID AS \"id\",title AS \"title\", des_info AS \"des_info\",author AS \"author\", "
|
||
+ " start_time AS \"start_time\",end_time AS \"end_time\",signup_endtime AS \"signup_endtime\", "
|
||
+ " create_time AS \"create_time\" FROM( SELECT rn.*, ROWNUM AS rw FROM ("
|
||
+ " select a.id,a.title,a.des_info,a.author,a.start_time,a.end_time,a.signup_endtime,a.create_time from green_active_info a "
|
||
+ " where ";
|
||
if(signUp==0){
|
||
sql+= " not ";
|
||
}
|
||
sql+= " EXISTS(select 1 from green_active_sign s where s.user_id = ? and s.active_id=a.id) and a.is_del='1' and a.status = '1' order by a.create_time desc "
|
||
+ " ) rn ) WHERE rw > ? and rw <= ? ";
|
||
List<Map<String,Object>> avtiveInfoList = hibernateDao.queryForListWithSql(sql,new Object[]{ userId,limit, pageSize});
|
||
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
|
||
for(Map<String,Object> avtiveInfo:avtiveInfoList){
|
||
//Long id = (Long)avtiveInfo.get("id");
|
||
Long id = Long.parseLong(String.valueOf(avtiveInfo.get("id")));
|
||
String itemSql = "select id as \"id\",active_id as \"active_id\",k_val as \"k_val\",item as \"item\" from green_active_item_info where active_id="+id;
|
||
List<Map<String,Object>> itemList = hibernateDao.queryForListWithSql(itemSql);
|
||
avtiveInfo.put("itemList", itemList);
|
||
list.add(avtiveInfo);
|
||
}
|
||
return new RestResult(Constant.SUCCESS,"成功",list);
|
||
}catch (ServiceValidatorBaseException e) {
|
||
throw e;
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"返回异常");
|
||
}
|
||
}
|
||
|
||
/**用户订单列表*/
|
||
@RequestMapping(value="/getActiveInfo", method = RequestMethod.POST)
|
||
@ResponseBody
|
||
public RestResult getActiveInfo(@RequestBody Map<String,Object> map){
|
||
|
||
// String userId = greenReport.getCreateBy();
|
||
// GreenUserInfo info = getUserInfo(userId);
|
||
// if(info==null){
|
||
// return new RestResult(Constant.FAILED, "非法用户");
|
||
// }
|
||
try {
|
||
String id = (String) map.get("id");
|
||
String userId = (String) map.get("userId");
|
||
|
||
|
||
String sql = "SELECT a. ID AS \"id\",a.title AS \"title\", a.des_info AS \"des_info\",a.author AS \"author\", "
|
||
+ " a.start_time AS \"start_time\",a.end_time AS \"end_time\",a.signup_endtime AS \"signup_endtime\", "
|
||
+ " a.create_time AS \"create_time\", "
|
||
+ "s. STATUS AS \"sign_status\" FROM green_active_info a "
|
||
+ "LEFT JOIN ( SELECT * FROM green_active_sign WHERE user_id = ? ) s ON a.id = s.active_id WHERE a.id = ?";
|
||
List<Map<String,Object>> avtiveInfoList = hibernateDao.queryForListWithSql(sql,new Object[]{userId,id});
|
||
if(avtiveInfoList.size()<=0){
|
||
return new RestResult(Constant.FAILED,"查无该数据");
|
||
}
|
||
Map<String,Object> activeInfo = avtiveInfoList.get(0);
|
||
String itemSql = "select id as \"id\",active_id as \"active_id\",k_val as \"k_val\",item as \"item\" from green_active_item_info where active_id="+id;
|
||
List<Map<String,Object>> itemList = hibernateDao.queryForListWithSql(itemSql);
|
||
activeInfo.put("itemList", itemList);
|
||
return new RestResult(Constant.SUCCESS,"成功",activeInfo);
|
||
}catch (ServiceValidatorBaseException e) {
|
||
throw e;
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"返回异常");
|
||
}
|
||
}
|
||
|
||
/**用户订单列表*/
|
||
@RequestMapping(value="/signUpActive", method = RequestMethod.POST)
|
||
@ResponseBody
|
||
public RestResult signUpActive(@RequestBody GreenActiveSign greenActiveSign){
|
||
|
||
try {
|
||
hibernateDao.saveObject(greenActiveSign);
|
||
return new RestResult(Constant.SUCCESS,"报名成功");
|
||
}catch (ServiceValidatorBaseException e) {
|
||
throw e;
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"报名失败");
|
||
}
|
||
}
|
||
/**用户订单列表*/
|
||
@RequestMapping(value="/signInActive", method = RequestMethod.POST)
|
||
@ResponseBody
|
||
public RestResult signInActive(@RequestBody GreenActiveSign greenActiveSign){
|
||
|
||
try {
|
||
Long activeId = greenActiveSign.getActiveId();
|
||
String userId = greenActiveSign.getUserId();
|
||
Integer status = greenActiveSign.getStatus();
|
||
// String getSql = "select status from green_active_sign where active_id=? and user_id = ?";
|
||
// List<Map<String,Object>> list = hibernateDao.queryForListWithSql(getSql, new Object[]{activeId,userId});
|
||
// Integer status = (Integer) list.get(0).get("status");
|
||
if(status==1){
|
||
String sql = "update green_active_sign set status=1,sign_in_time = ? where active_id=? and user_id = ?";
|
||
hibernateDao.updateWithSql(sql, new Object[]{new Date(),activeId,userId});
|
||
return new RestResult(Constant.SUCCESS,"已签到");
|
||
}else if(status==2){
|
||
String sql = "update green_active_sign set status=2,sign_out_time= ? where active_id=? and user_id = ?";
|
||
hibernateDao.updateWithSql(sql, new Object[]{new Date(),activeId,userId});
|
||
return new RestResult(Constant.SUCCESS,"已签退");
|
||
}
|
||
return new RestResult(Constant.SUCCESS,"已签退");
|
||
}catch (ServiceValidatorBaseException e) {
|
||
throw e;
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"签到失败");
|
||
}
|
||
}
|
||
}
|