1+ package com .bookshop .controller ;
2+ import java .text .SimpleDateFormat ;
3+ import java .util .ArrayList ;
4+ import java .util .HashMap ;
5+ import java .util .List ;
6+ import java .util .Map ;
7+ import org .apache .commons .lang3 .StringUtils ;
8+ import org .springframework .beans .factory .annotation .Autowired ;
9+ import org .springframework .stereotype .Controller ;
10+ import org .springframework .web .bind .annotation .RequestBody ;
11+ import org .springframework .web .bind .annotation .RequestMapping ;
12+ import org .springframework .web .bind .annotation .RequestMethod ;
13+ import org .springframework .web .bind .annotation .RequestParam ;
14+ import org .springframework .web .bind .annotation .ResponseBody ;
15+
16+ import com .bookshop .modle .OrderDetail ;
17+ import com .bookshop .modle .OrderDetailExample ;
18+ import com .bookshop .service .OrderDetailService ;import com .bookshop .util .StringUtil ;
19+ import com .github .pagehelper .PageInfo ;
20+
21+ @ Controller @ RequestMapping ("/orderDetail" )
22+ public class OrderDetailController {
23+
24+ @ Autowired OrderDetailService orderDetailSV ;
25+
26+ @ ResponseBody @ RequestMapping (value ="/orderDetailQry" ,method =RequestMethod .GET )
27+ public Map orderDetailQry (
28+ @ RequestParam (name ="oDId" ,required =false )String oDId ,
29+ @ RequestParam (name ="oId" ,required =false )String oId ,
30+ @ RequestParam (name ="bId" ,required =false )String bId ,
31+ @ RequestParam (name ="bName" ,required =false )String bName ,
32+ @ RequestParam (name ="bNums" ,required =false )String bNums ,
33+ @ RequestParam (name ="bPrice" ,required =false )String bPrice ,
34+ @ RequestParam (name ="bDiscountprice" ,required =false )String bDiscountprice ,
35+ @ RequestParam (name ="bSumprice" ,required =false )String bSumprice ,
36+ @ RequestParam (name ="bSumdiscountprice" ,required =false )String bSumdiscountprice ,
37+ @ RequestParam (name ="page" ,required =false )String page ,@ RequestParam (name ="limit" ,required =false )String limit ){
38+ Map <String , Object > resultMap =new HashMap <>();
39+ List <Map > mapList = new ArrayList <>();
40+ int pageNum = page == null ? 1 : Integer .parseInt (page );
41+ int pageSize = limit == null ? 10 : Integer .parseInt (limit );
42+ Map <String , String > orderDetailExmMap = new HashMap <>();
43+
44+ orderDetailExmMap .put ("oDId" , oDId );
45+ orderDetailExmMap .put ("oId" , oId );
46+ orderDetailExmMap .put ("bId" , bId );
47+ orderDetailExmMap .put ("bName" , bName );
48+ orderDetailExmMap .put ("bNums" , bNums );
49+ orderDetailExmMap .put ("bPrice" , bPrice );
50+ orderDetailExmMap .put ("bDiscountprice" , bDiscountprice );
51+ orderDetailExmMap .put ("bSumprice" , bSumprice );
52+ orderDetailExmMap .put ("bSumdiscountprice" , bSumdiscountprice );
53+ OrderDetailExample example = orderDetailSV .createOrderDetailExm (orderDetailExmMap );
54+ List <OrderDetail > orderDetailList = orderDetailSV .selectByExample (example ,pageNum ,pageSize );
55+ int total = orderDetailSV .countByExample (example );
56+ for (OrderDetail orderDetail : orderDetailList ) {
57+ Map <String ,Object > tMap = new HashMap <>();
58+ tMap .put ("oDId" , orderDetail .getoDId ());
59+ tMap .put ("oId" , orderDetail .getoId ());
60+ tMap .put ("bId" , orderDetail .getbId ());
61+ tMap .put ("bName" , orderDetail .getbName ());
62+ if (orderDetail .getbNums ()!=null ){
63+ tMap .put ("bNums" , orderDetail .getbNums ().toString ());
64+ }
65+ if (orderDetail .getbPrice ()!=null ){
66+ tMap .put ("bPrice" , orderDetail .getbPrice ().toString ());
67+ }
68+ if (orderDetail .getbDiscountprice ()!=null ){
69+ tMap .put ("bDiscountprice" , orderDetail .getbDiscountprice ().toString ());
70+ }
71+ if (orderDetail .getbSumprice ()!=null ){
72+ tMap .put ("bSumprice" , orderDetail .getbSumprice ().toString ());
73+ }
74+ if (orderDetail .getbSumdiscountprice ()!=null ){
75+ tMap .put ("bSumdiscountprice" , orderDetail .getbSumdiscountprice ().toString ());
76+ }
77+ mapList .add (tMap );
78+ }
79+
80+ resultMap .put ("oderDetailList" , orderDetailList );
81+ PageInfo <OrderDetail > pageInfo =new PageInfo <>(orderDetailList );
82+ resultMap .put ("pageInfo" , pageInfo );
83+
84+ return resultMap ;
85+ }
86+ @ RequestMapping (value ="/addOrderDetail" ,method =RequestMethod .POST ) @ ResponseBody
87+ public String addOrderDetail (@ RequestBody Map <String , String >req ){
88+ String id = req .get ("oDId" );
89+ try {
90+ //判断非空字段是否为空 以及设置创建时间
91+ if (StringUtils .isEmpty (id )){
92+ id = StringUtil .seqGenerate ().toString ();
93+ req .put ("oDId" , id .toString ());
94+ } //订单id-必须 if(StringUtil.isEmpty(req.get("oId"))) { return "oIdNull"; }
95+ OrderDetail orderDetail = orderDetailSV .createOrderDetail (req );
96+
97+ if (orderDetailSV .insertSelective (orderDetail ) == 1 ) {
98+ return "success" ;
99+ }else {
100+ return "error" ;
101+ }
102+ } catch (Exception e ) {
103+ return "error" ;
104+ }
105+ }
106+ @ RequestMapping (value ="/updateOrderDetail" ,method =RequestMethod .POST ) @ ResponseBody
107+ public String updateOrderDetail (@ RequestBody Map <String , String >req ){
108+ String id = req .get ("oDId" );
109+ try { //缺少主鍵
110+ if (StringUtils .isEmpty (id )){
111+ return "oDIdNull" ;
112+ }
113+
114+ OrderDetail orderDetail = orderDetailSV .createOrderDetail (req );
115+ if (orderDetailSV .updateByPrimaryKeySelective (orderDetail ) == 1 ) {
116+ return "success" ;
117+ }else {
118+ return "error" ;
119+ }
120+ } catch (Exception e ) {
121+ return "error" ;
122+ }
123+ }
124+ @ RequestMapping (value ="/deleteOrderDetail" ,method =RequestMethod .POST ) @ ResponseBody
125+ public String deleteOrderDetail (@ RequestBody Map <String , Object >req ){
126+ List <String > idList = (List <String >) req .get ("ids" );
127+ String strSuc = "" ;
128+ String strFail = "" ;
129+ String strNotExist = "" ; try {
130+ if (idList .size () != 0 && idList != null ) {
131+ for (int i = 0 ; i < idList .size (); i ++) {
132+ String id = idList .get (i );
133+ if (orderDetailSV .selectByPrimaryKey (id ) != null ) {
134+ if (orderDetailSV .deleteByPrimaryKey (id ) == 1 ) {
135+ strSuc += (id + " " );
136+ } else {
137+ strFail += (id + " " );
138+ }
139+ } else {
140+ strNotExist += (id + " " ); }
141+ }
142+ if (strNotExist .equals ("" ) && strFail .equals ("" )) {
143+ return strSuc + "delete success" ;
144+ } else {
145+ return strFail + strNotExist + "delete error" ;
146+ }
147+ } else {
148+ return "idsNull" ;
149+ }
150+ } catch (Exception e ) {
151+ return "error" ;
152+ }
153+ }
154+ }
0 commit comments