#
18516761980
2022-07-25 2c37b04bc0e5e2eae772166f514ff67113668f17
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package com.slcf.controller;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.slcf.pojo.UserBean;
import com.slcf.bean.LocationCondition;
import com.slcf.bean.LocationEntity;
import com.slcf.pojo.LocationBean;
import com.slcf.pojo.SysLogBean;
import com.slcf.service.LocationService;
import com.slcf.service.RoleService;
import com.slcf.service.SysLogService;
import com.slcf.util.AuthorityCode;
 
/**
 * 库位管理控制器层
 * @author admin
 * @date 2018年11月7日
 */
@Controller
@RequestMapping("/basic")
public class LocationController {
 
    @Resource
    LocationService locationService;
    @Autowired
    SysLogService sysLogService;
    @Autowired
    RoleService roleService;
    
    @RequestMapping("/goLocation.action")
    public String goLocationPage(HttpServletRequest request){
        try {
            String rid = request.getSession().getAttribute("ROLEID").toString();
            String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid), 
                    AuthorityCode.LocationCode);
            request.getSession().setAttribute("AUTHCODE",authCode);
            // 插入日志
            UserBean user = (UserBean) request.getSession().getAttribute("USER");
            SysLogBean sysLog = new SysLogBean();
            sysLog.setLogin_no(user.getUser_account());
            sysLog.setMachine_ip(request.getRemoteAddr());
            sysLog.setForm_no("goLocation.action");
            sysLog.setTts_keyname("访问:库位管理");
            sysLog.setModi_user(user.getUser_account());
            sysLogService.insertSysLog(sysLog);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "location";
    }
    
    /**
     * 添加
     * @param LocationEntity
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/addLocation.action")
    public Integer insertLocation(LocationEntity location,HttpServletRequest request){
        int result=0;
        try {
            UserBean user=(UserBean)request.getSession().getAttribute("USER");            
            int srow = location.getS_row();
            int erow = location.getE_row();
            int sbay = location.getS_bay();
            int ebay = location.getE_bay();
            int slev = location.getS_lev();
            int elev = location.getE_lev();
            int whs_type = location.getWhs_type();            
 
            for(int i=srow; i<=erow; i++) {
                for(int j=sbay; j<=ebay; j++) {
                    for(int k=slev; k<=elev; k++) {
                        String loc_no = String.format("%02d", i) + String.format("%03d", j) + String.format("%02d", k);
                        int crn_no = (i+1)/2;
                        LocationBean loc = new LocationBean();
                        loc.setLoc_no(loc_no);
                        loc.setLoc_sts("O");
                        loc.setModi_user(user.getUser_account());
                        loc.setRow1(i);
                        loc.setBay1(j);
                        loc.setLev1(k);
                        loc.setCrn_no(crn_no);
                        loc.setWhs_type(whs_type);
                        loc.setLoc_type(whs_type);   //库位类型
                        locationService.insertLocation(loc);
                        result++;
                    }
                }
            }                                    
//            System.out.println(i+"++++++++++++");    
            if(result>0) {
                // 插入日志
//                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("addLocation.action");
                sysLog.setTts_keyname("初始化库位:排" + srow + "-" + erow + ",列" + sbay + "-" + ebay + ",层" + slev + "-" + elev);
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
            result=0;
        }
        return result;
    }
    
    /**
     * 分页查询所有
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/locationList.action")
    public Map<String,Object> queryLocationListByPages(LocationCondition locationCon){
        Map<String,Object>map=locationService.queryLocationList(locationCon);
        return map;
    }
//    @ResponseBody
//    @RequestMapping("/locationList.action")
//    public Map<String,Object> queryLocationListByPages(
//            @RequestParam(value="pageNumber",defaultValue="1",required=false)int pageNumber,
//            @RequestParam("pageSize")int pageSize){
//        Map<String,Object>map=new HashMap<String, Object>();
//        try {
//            int count=locationService.queryLocationCount();
//            List<LocationBean>dlist=locationService.queryLocationList((pageNumber-1)*pageSize, pageSize);
//            map.put("total", count);
//            map.put("rows", dlist);            
//        }catch(Exception e) {
//            System.out.println(e.getMessage());
//        }
//        return map;
//    }
    
    /**
     * 根据id查询信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryLocationById.action")
    public LocationBean queryLocationById(@RequestParam("did")String id){
        try {
            return locationService.queryLocationById(id);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 验证工作代号是否唯一
     * @param did
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkLocation.action")
    public Map<String,Object> checkLocation(@RequestParam("did")String id){        
        Map<String,Object> map=new HashMap<String, Object>();
//        boolean flag=userService.validUserAccount(account, uid);
        try {
            LocationBean Location = locationService.queryLocationById(id);
            if(Location==null){
                map.put("msg", "代号可用");
            }else{
                map.put("msg", "代号不可用");
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 修改信息
     * @param LocationEntity
     * @return
     */
    @ResponseBody
    @RequestMapping("/upLocation.action")
    public Integer upLocation(LocationBean location,HttpServletRequest request){
        int result = 0;
        try {
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            location.setModi_user(user.getUser_account());
            
            result=locationService.upLocation(location);
            if(result>0) {
                // 插入日志
//                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("upLocation.action");
                sysLog.setTts_keyname("修改库位:" + location.getLoc_no());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/delLocation.action")
    public int delLocation(@RequestParam("did")String id,HttpServletRequest request){
        int result = 0;
        try {
            result=locationService.delLocation(id);
            
            if(result>0) {
                // 插入日志
                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("delLocation.action");
                sysLog.setTts_keyname("删除库位,ID:" + id);
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 查询所有
     * @return
     */
    @ResponseBody
    @RequestMapping("/getLocation.action")
    public List<LocationBean> getLocation(){
        try {
            return locationService.getLocationList();
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }        
    }
    
    /**
     * 重置库位表
     * @return
     */
    @ResponseBody
    @RequestMapping("/resetLocation.action")
    public int resetLocation(HttpServletRequest request){
        int result = 0;
        try {
            result=locationService.resetLocation();
            
            if(result>0) {
                // 插入日志
                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("resetLocation.action");
                sysLog.setTts_keyname("重置库位表");
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    @ResponseBody
    @RequestMapping("/getRow.action")
    public Map<String,Object> getRow(){
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            map.put("rows",locationService.getRowList()); 
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }    
        return map;
    }
}