action

package com.ivchat.park.coupons.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ivchat.common.action.BaseAction;
import com.ivchat.common.enums.Constant;
import com.ivchat.common.util.AjaxJsonUtil;
import com.ivchat.common.util.dg.FlexGridExtUtil;
import com.ivchat.common.util.ui.AjaxFormResponseUtil;
import com.ivchat.common.vo.DataGridPage;
import com.ivchat.common.vo.PageBean;
import com.ivchat.common.vo.ValidateBean;
import com.ivchat.park.common.model.ACLUser;
import com.ivchat.park.coupons.model.TicketCoupons;
import com.ivchat.park.coupons.model.TicketCouponsIssue;
import com.ivchat.park.coupons.model.TicketCouponsRedundancy;
import com.ivchat.park.coupons.model.TicketMerchant;
import com.ivchat.park.coupons.model.TicketMerchantCoupons;
import com.ivchat.park.coupons.querybean.ParkCouponsManageQueryBean;
import com.ivchat.park.coupons.service.ParkCouponsIssueService;
import com.ivchat.park.coupons.service.ParkCouponsManageService;
import com.ivchat.park.coupons.service.ParkMerchantManageService;
import com.ivchat.park.coupons.service.TicketCouponsRedundancyService;
import com.ivchat.park.coupons.service.TicketMerchantCouponsService;

@Controller("parkCouponsManageAction")
@Scope("prototype")
@ParentPackage("park")
@Namespace("/coupons")
public class ParkCouponsManageAction extends BaseAction{
/**
* id
*/
private static final long serialVersionUID = 1L;

private TicketMerchant ticketMerchant;
private ParkMerchantManageService ticketMerchantService;
private TicketMerchantCouponsService tMerchantCouponsService;
@Resource
private TicketMerchantCouponsService ticketMerchantCouponsService;
private ParkCouponsIssueService parkCouponsIssueService;
private Constant constant;
private String id;
private TicketCoupons ticketCoupons;
private TicketCouponsRedundancy ticketCouponsRedundancy;
private ParkCouponsManageService parkCouponsManageService;
private TicketCouponsRedundancyService ticketCouponsRedundancyService;
private PageBean pageBean;
private boolean relation;
private String s_invalidTime;
/**
* 唯一性校验值/校验ID/校验规则
*/
private String validateValue;
private String customAjaxRule;
private String validateId;

public String execute(){
return SUCCESS;
}

/**
*跳转到添加停车券页面
* @return
*/
public String add(){
return "input";
}

/**
* 前端校验停车券类型的唯一性
* @return
*/
public String uniqueIdentityCard() {
ACLUser user = (ACLUser) getRequest().getSession().getAttribute("user");
if(user==null){
return null;
}
boolean flag = true;
String result = "可以使用";
ParkCouponsManageQueryBean pkcpType = new ParkCouponsManageQueryBean();
pkcpType.setCouponsType(validateValue);
Integer tickInteger = parkCouponsManageService.searchByQueryBean(pkcpType, user);
if(tickInteger > 0) {
flag = false;
result = "停车券类型已存在";
}
ValidateBean vb = new ValidateBean(flag, customAjaxRule, validateId);
AjaxJsonUtil.write(JSONObject.fromObject(vb).toString(), getResponse());
log.info("停车券类型[" + validateValue + "]验证成功,验证结果:" + result);
return null;
}
/**
* 添加停车券类型
* @return
*/

public String save(){
try {

ACLUser user = (ACLUser) getRequest().getSession().getAttribute("user");
if(user==null){
return null;
}
String couponsType = null;
couponsType = ticketCoupons.setCouponsType(ticketCoupons.getCouponsType());
int couponscount = parkCouponsManageService.findCouponsType(couponsType,user);
//判断券名是否存在,存在则不能添加
if(couponscount>0){
AjaxFormResponseUtil.failure(getText("该券名已经存在请重新输入"), getResponse());
}
//判断是否关联,如果关联则将数据添加到商家与券的关联表
if(relation){
TicketMerchantCoupons MerchantCoupons = null;
List<TicketMerchant> list = new ArrayList<TicketMerchant>();
list = ticketMerchantService.findAll(user.getXiaoqu_code());
//如果不存在商家就只保存停车券
if(list.size()==0){
ticketCoupons.setSmallCommunityCode(user.getXiaoqu_code());
ticketCoupons.setCommunityCode(user.getCommunity_code());
ticketCoupons.setState(TicketCoupons.STATE);
ticketCoupons.setTime(new Date());
parkCouponsManageService.save(ticketCoupons);
ticketCouponsRedundancyService.save(ticketCoupons);
AjaxFormResponseUtil.success(getText("添加成功"), getResponse());
return null;
}else{
for(TicketMerchant ticketM:list){
MerchantCoupons = new TicketMerchantCoupons();
MerchantCoupons.setMerchantId(ticketM.getId());
MerchantCoupons.setMerchantName(ticketM.getMerchantName());
MerchantCoupons.setMallbuilderId(ticketM.getMallbuilderId());
MerchantCoupons.setMallbuilderName(ticketM.getMallbuilderName());
MerchantCoupons.setCommunityCode(ticketM.getCommunityCode());
MerchantCoupons.setSmallCommunityCode(ticketM.getSmallCommunityCode());
MerchantCoupons.setUserid(ticketM.getUserid());
MerchantCoupons.setUser(ticketM.getUser());
MerchantCoupons.setTime(new Date());
MerchantCoupons.setCouponsType(ticketCoupons.getCouponsType());
MerchantCoupons.setDeductionFee(ticketCoupons.getDeductionFee());
MerchantCoupons.setMerchantValidityTime(ticketCoupons.getMerchantValidityTime());
MerchantCoupons.setTime(ticketCoupons.getTime());
MerchantCoupons.setUnit(ticketCoupons.getUnit());
MerchantCoupons.setCouponsId(ticketCoupons.getId());
MerchantCoupons.setUserValidityTime(ticketCoupons.getUserValidityTime());
MerchantCoupons.setIsdelete(TicketMerchantCoupons.ISDELETE_LOGIC);
tMerchantCouponsService.save(MerchantCoupons);
}//选择关联商家,同时也要添加券的信息
ticketCoupons.setSmallCommunityCode(user.getXiaoqu_code());
ticketCoupons.setCommunityCode(user.getCommunity_code());
ticketCoupons.setState(TicketCoupons.STATE);
ticketCoupons.setTime(new Date());
parkCouponsManageService.save(ticketCoupons);
ticketCouponsRedundancyService.save(ticketCoupons);
AjaxFormResponseUtil.success(getText("添加成功"), getResponse());
return null;
}
}else{
ticketCoupons.setSmallCommunityCode(user.getXiaoqu_code());
ticketCoupons.setCommunityCode(user.getCommunity_code());
ticketCoupons.setState(TicketCoupons.STATE);
ticketCoupons.setTime(new Date());
parkCouponsManageService.save(ticketCoupons);
ticketCouponsRedundancyService.save(ticketCoupons);
AjaxFormResponseUtil.success(getText("添加成功"), getResponse());

}
} catch (Exception e) {
AjaxFormResponseUtil.failure(getText("添加失败"), getResponse());
}

return null;
}
/**
* 删除:删除停车券的同时,逻辑删除商家和券的关联关系使isdelete更改为0。
* @return
*/
public void delete(){
List<TicketCouponsIssue> list = new ArrayList<TicketCouponsIssue>();
List<TicketCouponsIssue> listEntity = new ArrayList<TicketCouponsIssue>();
try {
if(id!= null){
TicketCoupons ticketCoupons = parkCouponsManageService.get(id);
List<TicketCouponsIssue> unused = parkCouponsIssueService.getUnused(ticketCoupons.getCouponsType());
for(int i=0;i<unused.size();i++){
if(unused.get(i).getUnused()==TicketCouponsIssue.UNUSED){
listEntity.add(unused.get(i));
list.remove(unused.get(i));
}else{
list.add(unused.get(i));
}
}
if(list.size()==0){
parkCouponsManageService.deleteCoupons(ticketCoupons);
//ticketMerchantCouponsService.updateEntity(unused,TicketCouponsIssue.UNUSED);//删除停车券的同时,逻辑删除商家和券的关联关系使isdelete更改为0。
ticketMerchantCouponsService.delete(unused);
parkCouponsIssueService.delete(listEntity);
AjaxFormResponseUtil.success("删除信息成功!", getResponse());
}else{
AjaxFormResponseUtil.failure("优惠券购买的未使用数量为0时才能删除", getResponse());
}
}else {
AjaxFormResponseUtil.failure("请选择要删除的停车券!", getResponse());
}

} catch (Exception e) {
AjaxFormResponseUtil.failure("删除信息失败!", getResponse());
}
}
/**
* 冻结停车券
* @return
* @return
*/
public String frost(){
try {
if(id!= null){
TicketCoupons ticketCoupon = parkCouponsManageService.get(id);
if(ticketCoupon!=null){
parkCouponsManageService.updateFrost(id,TicketCoupons.STATE);
AjaxFormResponseUtil.success("冻结成功!", getResponse());
}else {
AjaxFormResponseUtil.failure("没有该信息请重新选择", getResponse());
}
}else AjaxFormResponseUtil.failure("没有该信息请重新选择!", getResponse());
} catch (Exception e) {
AjaxFormResponseUtil.failure("冻结失败!", getResponse());
}
return null;
}
/**
* 解冻停车券
* @return
* @return
*/
public String freedom(){
String state = null;
try {
if(id!= null){
TicketCoupons ticketCoupon = parkCouponsManageService.get(id);
state = ticketCoupon.getState();
if(state.equals(TicketCoupons.STATE1)){
parkCouponsManageService.updateFreedom(id,TicketCoupons.STATE);
}
AjaxFormResponseUtil.success("解冻成功!", getResponse());
}else{
AjaxFormResponseUtil.failure("没有选中,请重新选择!", getResponse());
}
} catch (Exception e) {
AjaxFormResponseUtil.failure("解冻失败!请重试", getResponse());
}
return null;
}
/**
* 停车券失效
* @return
* @return
*/
public String addlose(){
try {
ticketCoupons = parkCouponsManageService.get(id);

} catch (Exception e) {
e.printStackTrace();
}

return "addlose";
}
/**
* 添加停车券失效时间
* @return
* @return
*/
public String losesave(){
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ticketCoupons =parkCouponsManageService.get(ticketCoupons.getId());
ticketCoupons.setInvalidTime(formatter.parse(s_invalidTime));
parkCouponsManageService.updateLose(ticketCoupons);
AjaxFormResponseUtil.success("添加成功", getResponse());
} catch (Exception e) {
AjaxFormResponseUtil.failure("添加失败", getResponse());
}

return null;
}
/**
* 停车券类型返回页面展示的数据
* @return
*/

public String list(){
ACLUser user = (ACLUser) getRequest().getSession().getAttribute("user");
if(user==null){
return null;
}
DataGridPage data = new DataGridPage();
if(pageBean==null){
pageBean = new PageBean();
}
//思路:先获取到运营商和社区编码和小区的编码,2判断是运营商的可查所有数据,小区的只能看本小区的数据,社区还能看本社区的数据
ParkCouponsManageQueryBean parkCouponsQueryBean = new ParkCouponsManageQueryBean();
if(String.valueOf(Constant.USER_TYPE_SQYY).equals(user.getUsertype())){
data = parkCouponsManageService.getAllByDGP(pageBean,parkCouponsQueryBean);
}else if(String.valueOf(Constant.USER_TYPE_XQ).equals(user.getUsertype())
||String.valueOf(Constant.USER_TYPE_WGJT).equals(user.getUsertype())){
String communityCode = user.getCommunity_code();
String smallCommunityCode = user.getXiaoqu_code();
parkCouponsQueryBean.setCommunityCode(communityCode);
parkCouponsQueryBean.setSmallCommunityCode(smallCommunityCode);
data = parkCouponsManageService.getAllByDGP(pageBean,parkCouponsQueryBean);
}
FlexGridExtUtil.JsonDataToWeb(data, getResponse(),"yyyy-MM-dd");
return null;
}

public boolean isRelation() {
return relation;
}

public void setRelation(boolean relation) {
this.relation = relation;
}

public TicketCoupons getTicketCoupons() {
return ticketCoupons;
}

public void setTicketCoupons(TicketCoupons ticketCoupons) {
this.ticketCoupons = ticketCoupons;
}

public ParkCouponsManageService getParkCouponsManageService() {
return parkCouponsManageService;
}

public void setParkCouponsManageService(
ParkCouponsManageService parkCouponsManageService) {
this.parkCouponsManageService = parkCouponsManageService;
}

public PageBean getPageBean() {
return pageBean;
}

public void setPageBean(PageBean pageBean) {
this.pageBean = pageBean;
}

public static String getState() {
return TicketCoupons.STATE;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getS_invalidTime() {
return s_invalidTime;
}

public void setS_invalidTime(String sInvalidTime) {
s_invalidTime = sInvalidTime;
}
public String getCustomAjaxRule() {
return customAjaxRule;
}
public void setCustomAjaxRule(String customAjaxRule) {
this.customAjaxRule = customAjaxRule;
}
public String getValidateId() {
return validateId;
}
public void setValidateId(String validateId) {
this.validateId = validateId;
}

public Constant getConstant() {
return constant;
}

public void setConstant(Constant constant) {
this.constant = constant;
}
public String getValidateValue() {
return validateValue;
}

public void setValidateValue(String validateValue) {
this.validateValue = validateValue;
}
public ParkMerchantManageService getTicketMerchantService() {
return ticketMerchantService;
}

public void setTicketMerchantService(ParkMerchantManageService ticketMerchantService) {
this.ticketMerchantService = ticketMerchantService;
}

public TicketMerchant getTicketMerchant() {
return ticketMerchant;
}

public void setTicketMerchant(TicketMerchant ticketMerchant) {
this.ticketMerchant = ticketMerchant;
}

public TicketMerchantCouponsService getTicketMerchantCouponsService() {
return ticketMerchantCouponsService;
}

public void setTicketMerchantCouponsService(
TicketMerchantCouponsService ticketMerchantCouponsService) {
this.ticketMerchantCouponsService = ticketMerchantCouponsService;
}

public ParkCouponsIssueService getParkCouponsIssueService() {
return parkCouponsIssueService;
}

public void setParkCouponsIssueService(
ParkCouponsIssueService parkCouponsIssueService) {
this.parkCouponsIssueService = parkCouponsIssueService;
}

public TicketMerchantCouponsService gettMerchantCouponsService() {
return tMerchantCouponsService;
}

public void settMerchantCouponsService(
TicketMerchantCouponsService tMerchantCouponsService) {
this.tMerchantCouponsService = tMerchantCouponsService;
}

public TicketCouponsRedundancyService getTicketCouponsRedundancyService() {
return ticketCouponsRedundancyService;
}

public void setTicketCouponsRedundancyService(
TicketCouponsRedundancyService ticketCouponsRedundancyService) {
this.ticketCouponsRedundancyService = ticketCouponsRedundancyService;
}

public TicketCouponsRedundancy getTicketCouponsRedundancy() {
return ticketCouponsRedundancy;
}

public void setTicketCouponsRedundancy(
TicketCouponsRedundancy ticketCouponsRedundancy) {
this.ticketCouponsRedundancy = ticketCouponsRedundancy;
}

}

时间: 2024-11-24 08:11:38

action的相关文章

【机器学习实战】Machine Learning in Action 代码 视频 项目案例

MachineLearning 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远 Machine Learning in Action (机器学习实战) | ApacheCN(apache中文网) 视频每周更新:如果你觉得有价值,请帮忙点 Star[后续组织学习活动:sklearn + tensorflow] ApacheCN - 学习机器学习群[629470233] 第一部分 分类 1.) 机器学习基础 2.) k-近邻算法 3.) 决策树 4.) 基于概率论的分类方法:朴素

wex5 教程 自定义action与名称去重

有一个订单,需要取出不同的客户名称,且只显示一次名称.效果如下图: 一 思路:自定义action,用sql语句的group by分组,将名称返回前端,用list显示出来. 二 制作步骤: 1 新建service service作为后端服务分发接口,一个工程可以有多个service,一个service可以有多个action. 2  新建action action基本参数: 名称:自定义 实现:(指向 java方法) 格式为 Name.getName   其中Name为java类,首写字母必须为大写

day8——ajax传参到action(Struts2)

第一种:url+?+参数 jsp中: $(function(){ $("[name='delemp']").click(function(){ $this = $(this); $delid = $this.attr("delid"); if(confirm("确认删除该条数据吗?")){ $.ajax({ type:"get", url:"deleteemployeebyid?delid="+$delid

Struts2系列笔记(3)---Action类的3种书写方式

Action类的3种书写方式 本文主要写有关写Action类的3种书写方式: (1)第一种 Action可以是POJO (简单模型对象)  不需要继承任何父类 也不需要实现任何接口 (2)实现Action接口 (3)继承ActionSupport(推荐) 那我们先来书写第一种: (1)第一种 Action可以是POJO (简单模型对象)  不需要继承任何父类 也不需要实现任何接口 1 //这里其实就是一个普通的类,类里面的方法可以任意写,如果写execute()方法那就代表默认执行它 2 pub

Func与Action

Func与Action C#委托的介绍(delegate.Action.Func.predicate) Func和Action委托的区别和简单使用

SharePoint 2010/SharePoint 2013 Custom Action: 基于Site Collection 滚动文字的通知.

应用场景: 有时候我们的站点需要在每个页面实现滚动文字的通知,怎么在不修改Master Page的情况下实现这个功能?我们可以使用Javascript 和 Custom Action 来实现. 创建一个Custom Action.主要使用到 Location = 'ScriptLink' 属性, 该属性可以动态的加载JavaScript 文件链接和代码块到模板页.代码如下: <Elements xmlns="http://schemas.microsoft.com/sharepoint/&

译-BMC Remedy Action Request System权限控制概述

原文链接:Access control overview 说明: BMC Remedy Action Request System是BMC ITSM产品平台,简称AR 或者Remedy,可实现基于ITIL标准的整个IT管理流程的实施定制.该平台可实现多种权限级别的管理,包括人员.组.角色,以及表.字段.行级别等.本文可以用作其他对权限要求比较精细的系统参考. 为了便于理解,部分名词翻译如下: Server:服务器Form (or table):表单Field (or column):字段Acti

Machine Learning In Action 第二章学习笔记: kNN算法

本文主要记录<Machine Learning In Action>中第二章的内容.书中以两个具体实例来介绍kNN(k nearest neighbors),分别是: 约会对象预测 手写数字识别 通过“约会对象”功能,基本能够了解到kNN算法的工作原理.“手写数字识别”与“约会对象预测”使用完全一样的算法代码,仅仅是数据集有变化. 约会对象预测 1 约会对象预测功能需求 主人公“张三”喜欢结交新朋友.“系统A”上面注册了很多类似于“张三”的用户,大家都想结交心朋友.“张三”最开始通过自己筛选的

untiy3d action管理机制的编写

使用unity3d对于一些可视化强迫者来说,是一个不错的选择,但unity3d没有cocos2d的action管理机制,比如cocos2dx的CCMoveTo,CCScale等action,所以笔者通过封装action管理来实现类似cocos2dx的actionmanager. 首先需要写一个ActionManager来创建.更新.移除所有action.编写代码实现如下: using UnityEngine;using System.Collections;using System; publi