首页>代码>s2sh(spring+struts2+hibernate)开发实验室信息管理系统>/Laboratory/src/com/xznu/edu/leave/action/LaboratoryAction.java
package com.xznu.edu.leave.action;

/**
 * 用户新增
 */

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xznu.edu.leave.model.Laboratory;
import com.xznu.edu.leave.model.LaboratoryLog;
import com.xznu.edu.leave.model.Role;
import com.xznu.edu.leave.model.User;
import com.xznu.edu.leave.service.LaboratoryLogService;
import com.xznu.edu.leave.service.LaboratoryService;
import com.xznu.edu.leave.service.RoleService;
import com.xznu.edu.leave.service.UserService;
import com.xznu.edu.leave.utils.JsonUtils;
import com.xznu.edu.leave.utils.Pager;
import com.xznu.edu.leave.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller("laboratoryAction")
@Scope("prototype")
public class LaboratoryAction extends ActionSupport implements ModelDriven<Laboratory> {
    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private LaboratoryService laboratoryService;
    @Autowired
    private LaboratoryLogService laboratoryLogService;
    private User user;
    private Laboratory laboratory;
    private Integer laboratoryId;
    private Map<String, Object> map = new HashMap();


    /**
     * list
     *
     * @return
     */
    public String list(){
        User user1 = UserUtils.getUser();
        if (user1 == null || user1.getId() == null){
            ActionContext.getContext().put("login", 1);
            return SUCCESS;
        }
        Pager<Laboratory> pagers = null;
        Role role = user1.getRole();
        if (role.getEnName().equals("admin")||role.getEnName().equals("js")||role.getEnName().equals("xs")) {
            pagers = laboratoryService.getList(laboratory);
            ActionContext.getContext().put("pagers", pagers);
            ActionContext.getContext().put("user", user1);
            ActionContext.getContext().put("laboratory", laboratory);
        }
        return SUCCESS;
    }

    public String listshenyue(){
        User user1 = UserUtils.getUser();
        if (user1 == null || user1.getId() == null){
            ActionContext.getContext().put("login", 1);
            return SUCCESS;
        }
        Pager<Laboratory> pagers = null;
        Role role = user1.getRole();
        if (role.getEnName().equals("admin")||role.getEnName().equals("js")||role.getEnName().equals("xs")) {
            pagers = laboratoryService.getList(laboratory);
            ActionContext.getContext().put("pagers", pagers);
            ActionContext.getContext().put("user", user1);
            ActionContext.getContext().put("laboratory", laboratory);
        }
        return SUCCESS;
    }

    
    public String listcopy(){
        User user1 = UserUtils.getUser();
        if (user1 == null || user1.getId() == null){
            ActionContext.getContext().put("login", 1);
            return SUCCESS;
        }
        Pager<Laboratory> pagers = null;
        Role role = user1.getRole();
        if (role.getEnName().equals("admin")||role.getEnName().equals("js")||role.getEnName().equals("xs")) {
            pagers = laboratoryService.getList(laboratory);
            ActionContext.getContext().put("pagers", pagers);
            ActionContext.getContext().put("user", user1);
            ActionContext.getContext().put("laboratory", laboratory);
        }
        return SUCCESS;
    }

    /**
     * list2
     *
     * @return
     */
    public String list2(){
        User user1 = UserUtils.getUser();
        if (user1 == null || user1.getId() == null){
            ActionContext.getContext().put("login", 1);
            return SUCCESS;
        }
        Pager<Laboratory> pagers = null;
        Role role = user1.getRole();
        if (role.getEnName().equals("admin")||role.getEnName().equals("js")||role.getEnName().equals("xs")) {
            pagers = laboratoryService.getList(laboratory);
            ActionContext.getContext().put("pagers", pagers);
            ActionContext.getContext().put("user", user1);
            ActionContext.getContext().put("laboratory", laboratory);
        }
        return SUCCESS;
    }
    
    public String list2copy(){
        User user1 = UserUtils.getUser();
        if (user1 == null || user1.getId() == null){
            ActionContext.getContext().put("login", 1);
            return SUCCESS;
        }
        Pager<Laboratory> pagers = null;
        Role role = user1.getRole();
        if (role.getEnName().equals("admin")||role.getEnName().equals("js")||role.getEnName().equals("xs")) {
            pagers = laboratoryService.getList(laboratory);
            ActionContext.getContext().put("pagers", pagers);
            ActionContext.getContext().put("user", user1);
            ActionContext.getContext().put("laboratory", laboratory);
        }
        return SUCCESS;
    }

    /**
     * 预约
     *
     * @return
     */
    public void yy() throws IOException {
        laboratory.setIsYy(1);
        laboratory.setUser(UserUtils.getUser());
        LaboratoryLog laboratoryLog = new LaboratoryLog();
        laboratoryLog.setIsYy(1);
        laboratoryLog.setLaboratory(laboratory);
        laboratoryLog.setTime(new Date());
        laboratoryLog.setUser(UserUtils.getUser());
        laboratoryLogService.save(laboratoryLog);
        laboratory.setLaboratoryLogId(laboratoryLog.getId());
        laboratoryService.updates(laboratory);
        map.put("flag", true);
        map.put("url", "laboratory_list2.do");
        JsonUtils.toJson(map);
    }

    /**
     * 取消预约
     *
     * @return
     */
    public void qx() throws IOException {
        Laboratory laboratory1 = laboratoryService.findById(laboratory.getId());
        LaboratoryLog laboratoryLog = laboratoryLogService.findById(laboratory1.getLaboratoryLogId());
        if (laboratoryLog.getUser().getId() == UserUtils.getUser().getId()){
            laboratory1.setIsYy(0);
            laboratory1.setUser(null);
            laboratoryService.update(laboratory1);
            laboratoryLog.setIsYy(0);
            laboratoryLog.setEndTime(new Date());
            laboratoryLog.setQx(UserUtils.getUser());
            laboratoryLogService.updates(laboratoryLog);
            map.put("flag", true);
            map.put("url", "laboratory_list2.do");
            JsonUtils.toJson(map);
        } else {
            map.put("flag", false);
            map.put("url", "laboratory_list2.do");
            JsonUtils.toJson(map);
        }

    }

    /**
     * 跳转add
     *
     * @return
     */
    public String add(){
        User user1 = UserUtils.getUser();
        ActionContext.getContext().put("bean", user1);
        return SUCCESS;
    }

    /**
     * 查询修改
     *
     * @return
     */
    public String edit() {
        if (laboratoryId != null && !laboratoryId.equals("")){
            Laboratory bean = laboratoryService.findById(laboratoryId);
            ActionContext.getContext().put("bean", bean);
        }
        return SUCCESS;
    }


    /**
     * 审核
     *
     * @return
     */
    public void updateSh() throws IOException {
        user.setIsSh(1);
        userService.updates(user);
        map.put("flag", true);
        map.put("url", "user_list.do");
        JsonUtils.toJson(map);
    }
    
    public void updateShcopy() throws IOException {
        user.setIsSh(1);
        userService.updates(user);
        map.put("flag", true);
        map.put("url", "usercopy_list.do");
        JsonUtils.toJson(map);
    }
    

    /**
     * 更新
     *
     * @return
     */
    public void update() throws IOException {
        laboratoryService.updates(laboratory);
        map.put("flag", true);
        map.put("url", "laboratory_list.do");
        JsonUtils.toJson(map);
    }

    /**
     * 保存
     *
     * @return
     */
    public String save() throws IOException {
        laboratory.setTime(new Date());
        laboratoryService.save(laboratory);
        map.put("flag", true);
        map.put("url", "laboratory_list.do");
        JsonUtils.toJson(map);
        return SUCCESS;
    }

    public void delete() throws IOException {
        laboratory.setIsDelete(1);
        laboratoryService.updates(laboratory);
        map.put("flag", true);
        map.put("url", "laboratory_list.do");
        JsonUtils.toJson(map);
    }

    @Override
    public Laboratory getModel() {
        if (laboratory == null) {
            laboratory = new Laboratory();
        }
        return laboratory;
    }

    public Integer getLaboratoryId() {
        return laboratoryId;
    }

    public void setLaboratoryId(Integer laboratoryId) {
        this.laboratoryId = laboratoryId;
    }

}
最近下载更多
zolscy  LV12 4月5日
acid111  LV1 2月26日
hbj1285984841  LV4 2023年10月19日
hxzyhxzy  LV1 2023年10月3日
LongTory  LV2 2023年5月9日
ming_123_9715  LV23 2023年4月27日
王培龚  LV4 2023年4月11日
kevinkg  LV12 2023年4月3日
wxxgyh  LV2 2023年3月23日
东方之珠_1628  LV6 2022年12月1日
最近浏览更多
zolscy  LV12 4月5日
WBelong  LV7 3月8日
acid111  LV1 2月26日
359469859 1月31日
暂无贡献等级
admin_z  LV22 2023年12月28日
lasttimeapp 2023年11月27日
暂无贡献等级
hbj1285984841  LV4 2023年10月19日
hxzyhxzy  LV1 2023年10月3日
186092  LV4 2023年9月20日
Huangyinghai  LV1 2023年7月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友