(스프링)배송현황 배송관리 등록하기 ajax,

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
function fn_modify_order_state(order_id,select_id){
    var s_delivery_state=document.getElementById(select_id);
    var index = s_delivery_state.selectedIndex;
    var value = s_delivery_state[index].value;
    //console.log("value: "+value );
     
    $.ajax({
        type : "post",
        async : false,
        url : "${contextPath}/admin/order/modifyDeliveryState.do",
        data : {
            order_id:order_id,
            "delivery_state":value
        },
        success : function(data, textStatus) {
            if(data.trim()=='mod_success'){
                alert("주문 정보를 수정했습니다.");
                location.href="${contextPath}/admin/order/adminOrderMain.do";
            }else if(data.trim()=='failed'){
                alert("다시 시도해 주세요.");    
            }
            
        },
        error : function(data, textStatus) {
            alert("에러가 발생했습니다."+data);
        },
        complete : function(data, textStatus) {
            //alert("작업을완료 했습니다");
            
        }
    }); //end ajax    
 
 
 
 
 
 
 
 
 
 
<table class="list_view">
        <tbody align=center >
            <tr style="background:#33ff00" >
                <td class="fixed" >주문번호</td>
                <td class="fixed">주문일자</td>
                <td>주문내역</td>
                <td>배송상태</td>
                <td>배송수정</td>
            </tr>
   <c:choose>
     <c:when test="${empty newOrderList}">            
            <tr>
               <td colspan=5 class="fixed">
                  <strong>주문한 상품이 없습니다.</strong>
               </td>
             </tr>
     </c:when>
     <c:otherwise>
     <c:forEach var="item" items="${newOrderList}" varStatus="i">
        <c:choose>
          <c:when test="${item.order_id != pre_order_id }">  
            <c:choose>
              <c:when test="${item.delivery_state=='delivery_prepared' }">
                <tr  bgcolor="lightgreen">    
              </c:when>
              <c:when test="${item.delivery_state=='finished_delivering' }">
                <tr  bgcolor="lightgray">    
              </c:when>
              <c:otherwise>
                <tr  bgcolor="orange">   
              </c:otherwise>
            </c:choose>   
                 <td width=10%>
                   <a href="javascript:fn_detail_order('${item.order_id}')">
                     <strong>${item.order_id}</strong>
                   </a>
                </td>
                <td width=20%>
                 <strong>${item.pay_order_time }</strong> 
                </td>
                <td width=50% align=left >
                    <strong>주문자:${item.orderer_name}</strong><br>
                  <strong>주문자 번화번호:${item.orderer_hp}</strong><br>
                  <strong>수령자:${item.receiver_name}</strong><br>
                  <strong>수령자 번화번호:${item.receiver_hp1}-${item.receiver_hp2}-${item.receiver_hp3}</strong><br>
                  <strong>주문상품명(수량):${item.goods_title}(${item.order_goods_qty})</strong><br>
                     <c:forEach var="item2" items="${newOrderList}" varStatus="j">
                       <c:if test="${j.index > i.index }" >
                          <c:if  test="${item.order_id ==item2.order_id}" >
                            <strong>주문상품명(수량):${item2.goods_title}(${item2.order_goods_qty})</strong><br>
                      </c:if>   
                       </c:if>
                    </c:forEach> 
                </td>
                <td width=10%>
                 <select name="s_delivery_state${i.index }"  id="s_delivery_state${i.index }">
                 <c:choose>
                   <c:when test="${item.delivery_state=='delivery_prepared' }">
                     <option  value="delivery_prepared" selected>배송준비중</option>
                     <option  value="delivering">배송중</option>
                     <option  value="finished_delivering">배송완료</option>
                     <option  value="cancel_order">주문취소</option>
                     <option  value="returning_goods">반품</option>
                   </c:when>
                    <c:when test="${item.delivery_state=='delivering' }">
                    <option  value="delivery_prepared" >배송준비중</option>
                     <option  value="delivering" selected >배송중</option>
                     <option  value="finished_delivering">배송완료</option>
                     <option  value="cancel_order">주문취소</option>
                     <option  value="returning_goods">반품</option>
                   </c:when>
                   <c:when test="${item.delivery_state=='finished_delivering' }">
                    <option  value="delivery_prepared" >배송준비중</option>
                     <option  value="delivering"  >배송중</option>
                     <option  value="finished_delivering" selected>배송완료</option>
                     <option  value="cancel_order">주문취소</option>
                     <option  value="returning_goods">반품</option>
                   </c:when>
                   <c:when test="${item.delivery_state=='cancel_order' }">
                    <option  value="delivery_prepared" >배송준비중</option>
                     <option  value="delivering"  >배송중</option>
                     <option  value="finished_delivering" >배송완료</option>
                     <option  value="cancel_order" selected>주문취소</option>
                     <option  value="returning_goods">반품</option>
                   </c:when>
                   <c:when test="${item.delivery_state=='returning_goods' }">
                    <option  value="delivery_prepared" >배송준비중</option>
                     <option  value="delivering"  >배송중</option>
                     <option  value="finished_delivering" >배송완료</option>
                     <option  value="cancel_order" >주문취소</option>
                     <option  value="returning_goods" selected>반품</option>
                   </c:when>
                   </c:choose>
                 </select> 
                </td>
                <td width=10%>
                 <input  type="button" value="배송수정"  onClick="fn_modify_order_state('${item.order_id}','s_delivery_state${i.index}')"/>
                </td>
            </tr>
        </c:when>
        </c:choose>    
        <c:set  var="pre_order_id" value="${item.order_id }" />
    </c:forEach>
    </c:otherwise>
  </c:choose>    
         <tr>
             <td colspan=8 class="fixed">
                 <c:forEach   var="page" begin="1" end="10" step="1" >
                 <c:if test="${section >1 && page==1 }">
                  <a href="${contextPath}/admin/order/adminOrderMain.do?chapter=${section-1}&pageNum=${(section-1)*10 +1 }">&nbsp;&nbsp;</a>
                 </c:if>
                  <a href="${contextPath}/admin/order/adminOrderMain.do?chapter=${section}&pageNum=${page}">${(section-1)*10 +page } </a>
                 <c:if test="${page ==10 }">
                  <a href="${contextPath}/admin/order/adminOrderMain.do?chapter=${section+1}&pageNum=${section*10+1}">&nbsp; next</a>
                 </c:if> 
                  </c:forEach> 
           </td>
        </tr>             
        </tbody>
    </table>
  </form>       
 
 
 
 
 
 
 
 
 
 
    @Override
    @RequestMapping(value="/modifyDeliveryState.do" ,method={RequestMethod.POST})
    public ResponseEntity modifyDeliveryState(@RequestParam Map<String, String> deliveryMap, 
                                    HttpServletRequest request, HttpServletResponse response)  throws Exception {
        adminOrderService.modifyDeliveryState(deliveryMap);
        
        String message = null;
        ResponseEntity resEntity = null;
        HttpHeaders responseHeaders = new HttpHeaders();
        message  = "mod_success";
        resEntity =new ResponseEntity(message, responseHeaders, HttpStatus.OK);
        return resEntity;
        
    }
 
 
 
<update id="updateDeliveryState" parameterType="java.util.Map" >
       update t_shopping_order
        <set> 
          <if test=" delivery_state!='' and delivery_state!=null">
            delivery_state=#{delivery_state}
          </if>
        </set>
        where 
        order_id=#{order_id}
    </update>    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@Override
    @RequestMapping(value="/adminOrderMain.do" ,method={RequestMethod.GET, RequestMethod.POST})
    public ModelAndView adminOrderMain(@RequestParam Map<String, String> dateMap,
                                      HttpServletRequest request, HttpServletResponse response)  throws Exception {
        String viewName=(String)request.getAttribute("viewName");
        ModelAndView mav = new ModelAndView(viewName);
 
        String fixedSearchPeriod = dateMap.get("fixedSearchPeriod");
        String section = dateMap.get("section");
        String pageNum = dateMap.get("pageNum");
        String beginDate=null,endDate=null;
        
        String [] tempDate=calcSearchPeriod(fixedSearchPeriod).split(",");
        beginDate=tempDate[0];
        endDate=tempDate[1];
        dateMap.put("beginDate", beginDate);
        dateMap.put("endDate", endDate);
        
        
        HashMap<String,Object> condMap=new HashMap<String,Object>();
        if(section== null) {
            section = "1";
        }
        condMap.put("section",section);
        if(pageNum== null) {
            pageNum = "1";
        }
        condMap.put("pageNum",pageNum);
        condMap.put("beginDate",beginDate);
        condMap.put("endDate", endDate);
        
        
        List<OrderVO> newOrderList=adminOrderService.listNewOrder(condMap);
        mav.addObject("newOrderList",newOrderList);
        
        String beginDate1[]=beginDate.split("-");
        String endDate2[]=endDate.split("-");
        mav.addObject("beginYear",beginDate1[0]);
        mav.addObject("beginMonth",beginDate1[1]);
        mav.addObject("beginDay",beginDate1[2]);
        mav.addObject("endYear",endDate2[0]);
        mav.addObject("endMonth",endDate2[1]);
        mav.addObject("endDay",endDate2[2]);
        
        mav.addObject("section", section);
        mav.addObject("pageNum", pageNum);
        return mav;
        
    }
 
 
<select id="selectNewOrderList" resultMap="orderResult"   parameterType="java.util.HashMap"  >
          select * from (
                select rowNum as recNum,t.*
                   from (
                          select  *  from t_shopping_order 
                          where to_char(pay_order_time,'yyyy-mm-dd')  between #{beginDate} and #{endDate}
                            <if test="search_type=='orderer_id'">
                              AND orderer_id=#{search_word}
                            </if>
                            <if test="search_type=='orderer_name'">
                              AND orderer_name=#{search_word}
                            </if>
                            <if test="search_type=='orderer_hp_num'">
                               AND pay_orderer_hp_num=#{search_word} 
                            </if>
                          order by pay_order_time desc
                        ) t
                )                            
            where                
        recNum between (#{section}-1)*100+ (#{pageNum}-1)*10+1 and (#{section}-1)*100+(#{pageNum})*10                        
    </select>
cs