liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.basic.x01.securityCheck.controller;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.basic.x01.base.BaseController;
import com.basic.x01.securityCheck.SecurityCheckUtil;
import com.basic.x01.securityCheck.mapper.SecurityCheckMapper;
import com.basic.x01.securityCheck.model.TbSecurityCheckItem;
import com.basic.x01.securityCheck.model.TbSecurityType;
import com.basic.x01.system.model.TSysUser;
 
/**
 * 非学校组织的安全检查模块
 * 
 * @company 北京贝思科技术有限公司
 * @author liuyajun, 8384503@qq.com
 * @date 2016年2月16日
 * @time 下午12:17:02
 */
@Controller
@Transactional(rollbackFor=Throwable.class)
public class SecurityCheckOrg extends BaseController {
 
    public final static String ACTION_ID = "securityCheckItem";
    public final static String EDIT_TYPE = "securityCheckEditType";
    public final static String CREATE_ITEM = "securityCheckCreateItem";
    public final static String EDIT_ITEM = "securityCheckEditItem";
    public final static String DELETE_ITEM = "securityCheckDeleteItem";
 
    @Resource
    SecurityCheckMapper checkMapper;
    
    @RequestMapping(value={CREATE_ITEM, EDIT_ITEM, DELETE_ITEM})
    public String securityCheckCreateItem(
            TbSecurityCheckItem item,
            @Param("itemId") String itemId
            ) throws Throwable {
        TSysUser user = this.getLoingedUser();
        
        if(CREATE_ITEM.equals(this.getCurrentActionId())
                && item!=null && !this.isEmpty(item.getTypeId())){
            item.setOrgId(user.getOrgId());
            
            if(checkMapper.checkSameTbSecurityCheckItem(item)>0){
                throw this.exception("该分类下存在相同检查项目");
            }
 
            //新建
            item.setCreateUserId(user.getUserId());
            checkMapper.insertTbSecurityCheckItem(item);
 
            return this.ajax("ok");
        }
        if(EDIT_ITEM.equals(this.getCurrentActionId())
                && item!=null && !this.isEmpty(item.getTypeId())
                && !this.isEmpty(item.getItemId())){
            item.setOrgId(user.getOrgId());
        
            if(checkMapper.checkSameTbSecurityCheckItem(item)>0){
                throw this.exception("该分类下存在相同检查项目");
            }
            //修改
            checkMapper.updateTbSecurityCheckItem(item);
            
            return this.ajax("ok");
        }
        
        if(DELETE_ITEM.equals(this.getCurrentActionId()) 
                && ! this.isEmpty(itemId)){
            //TODO: 没有检查是否使用过
            checkMapper.deleteUnusedTbSecurityCheckItem(user.getOrgId(), itemId);
            return this.ajax("ok");
        }
        
        List<TbSecurityType> typeList = checkMapper.getSecurityType4Edit(user.getOrgId());
 
        this.setAttribute("typeList", typeList);
        this.setAttribute("hasType", typeList.size()>0?"y":"n");
 
        if(EDIT_ITEM.equals(this.getCurrentActionId()) && ! this.isEmpty(itemId)){
            item = checkMapper.getTbSecurityCheckItem(itemId);
            this.setAttribute("checkItem", item);
        }
        
        this.setAttribute("checkWayInputHtml", SecurityCheckUtil.getCheckWayHtml4Edit(item.getCheckWay()));
        
        return "security-check/org-check-item-edit";
    }
    
    @RequestMapping(value="securityCheckEditTypeUpdate")
    public String securityCheckEditTypeUpdate(
            @RequestBody List<TbSecurityType> list) throws Throwable {
        TSysUser user = this.getLoingedUser();
        
        if(list==null || list.size()==0){
            return this.ajax(null);
        }
        
        for(TbSecurityType type : list){
            int sameType = checkMapper.checkSameTbSeucrityType(type);
            if(sameType>0){
                throw this.exception("存在相同的分类名称");
            }
            checkMapper.updateTbSecurityType(type);
        }
        
        checkMapper.deleteUnusedTbSecurityType(list, user.getOrgId());
        
        return this.ajax("ok");
    }
    
    @RequestMapping(value=EDIT_TYPE)
    public String securityCheckEditType(@Param("typeName") String typeName) throws Throwable {
 
        TSysUser user = this.getLoingedUser();
        if(! this.isEmpty(typeName)){
            TbSecurityType type = new TbSecurityType();
            type.setOrgId(user.getOrgId());
            type.setTypeName(typeName.trim());
            //新增
            int sameType = checkMapper.checkSameTbSeucrityType(type);
            if(sameType>0){
                throw this.exception("存在相同的分类名称");
            }
            
            type.setCreateUserId(user.getUserId());
            checkMapper.insertTbSecurityType(type);
            return this.ajax("ok");
        }
        
        List<TbSecurityType> typeList = checkMapper.getSecurityType4Edit(user.getOrgId());
 
        this.setAttribute("typeList", typeList);
        this.setAttribute("hasType", typeList.size()>0?"y":"n");
 
        return "security-check/org-edit-type";
    }
    
    @RequestMapping(value=ACTION_ID)
    public String securityCheckItem(
            @Param("searchTypeId") String searchTypeId,
            @Param("searchItemName") String searchItemName
            ) throws Throwable {
        TSysUser user = this.getLoingedUser();
        
        List<TbSecurityType> typeList = checkMapper.getSecurityType(user.getOrgId());
        
        this.getRequest().setAttribute("typeList", typeList);
        this.getRequest().setAttribute("hasType", typeList.size()>0?"y":"n");
        
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("orgId", user.getOrgId());
        
        if(! this.isEmpty(searchTypeId)){
            this.setAttribute("searchTypeId", searchTypeId);
            param.put("typeId", searchTypeId);
        }
        
        if(! this.isEmpty(searchItemName)){
            this.setAttribute("searchItemName", searchItemName);
            param.put("itemContent", searchItemName);
        }
        
        List<TbSecurityCheckItem> itemList = checkMapper.getSecurityCheckItemList(
                this.wrapPageSearchParam(param));
        
        this.setAttribute("itemList", itemList);
        this.setAttribute("hasItem", itemList.size()>0?"y":"n");
        
        this.setAttribute(EDIT_ITEM, this.checkAccess(EDIT_ITEM)?"y":"n");
        this.setAttribute(DELETE_ITEM, this.checkAccess(DELETE_ITEM)?"y":"n");
        
        return "security-check/org-check-item";
    }
}