admin
2018-12-05 21f49216736c547d99ec1dd46a24c6f43f852fc5
fanli/src/main/java/com/yeshi/fanli/controller/admin/LostOrderAdminController.java
@@ -2,20 +2,25 @@
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.entity.bus.user.LostOrder;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.service.inter.order.LostOrderService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.GsonUtil;
import org.yeshi.utils.JsonUtil;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("admin/new/api/v1/lostOrder")
@@ -66,4 +71,147 @@
      out.print(JsonUtil.loadTrueResult(""));
   }
   /**
    * 新版后台 列表查询
    * @param callback
    * @param pageIndex
    * @param key
    * @param out
    */
   @RequestMapping("query")
   public void query(String callback, Integer pageIndex, Integer pageSize, String key, Integer state,
         Integer handleType, PrintWriter out) {
      if (pageIndex == null || pageIndex < 0){
         pageIndex = 1;
      }
      if (pageSize == null || pageSize < 1) {
         pageSize = Constant.PAGE_SIZE;
      }
      try {
         List<LostOrder> list = lostOrderService.listQuery((pageIndex - 1) * pageSize, pageSize, key, state, handleType);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无更多数据"));
            return;
         }
         for (LostOrder lostOrder: list) {
            Order order = lostOrder.getOrder();
            if (order == null) {
               lostOrder.setOrder(new Order());
            }
            UserInfo userInfo = lostOrder.getUserInfo();
            if (userInfo == null) {
               lostOrder.setUserInfo(new UserInfo());
            } else {
               Map<String, Object> countData = lostOrderService.countByUid(userInfo.getId());
               lostOrder.setTotal(Integer.parseInt(countData.get("total")+""));
               lostOrder.setTotalPass(Integer.parseInt(countData.get("totalPass")+""));
               lostOrder.setTotalReject(Integer.parseInt(countData.get("totalReject")+""));
            }
         }
         long count = lostOrderService.countQuery(key, state, handleType);
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
         GsonBuilder gsonBuilder = new GsonBuilder();
         gsonBuilder.serializeNulls();
         Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create();
         JSONObject data = new JSONObject();
         data.put("pe", pe);
         data.put("result_list", gson.toJson(list));
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   /**
    *  新版后台   通过
    * @param callback
    * @param id
    * @param out
    */
   @RequestMapping("passOrder")
   public void passOrder(String callback, Long id, PrintWriter out) {
      if (id == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
         return;
      }
      try {
         LostOrder lostOrder = lostOrderService.getOne(id);
         if (lostOrder == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("不存在该查询订单"));
            return;
         }
         if (lostOrder.getState() != 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该订单已处理"));
            return;
         }
         lostOrderService.pass(lostOrder);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
         e.printStackTrace();
      }
   }
   /**
    *  新版后台 拒绝
    * @param callback
    * @param id
    * @param reason
    * @param out
    */
   @RequestMapping("rejectOrder")
   public void rejectOrder(String callback, Long id, String reason, PrintWriter out) {
      if (id == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
         return;
      }
      try {
         LostOrder lostOrder = lostOrderService.getOne(id);
         if (lostOrder == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("不存在该查询订单"));
            return;
         }
         if (lostOrder.getState() != 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该订单已处理"));
            return;
         }
         lostOrder.setRemake(reason);
         lostOrderService.reject(lostOrder);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
         e.printStackTrace();
      }
   }
}