From 172c5525cbdba1c3b32b47cb60bd35bed707101c Mon Sep 17 00:00:00 2001 From: kongdeqiang <123456> Date: 星期一, 27 三月 2023 17:18:48 +0800 Subject: [PATCH] 增加功能 --- xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/wx/IndexController.java | 166 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 140 insertions(+), 26 deletions(-) diff --git a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/wx/IndexController.java b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/wx/IndexController.java index 46284f5..82bb1a3 100644 --- a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/wx/IndexController.java +++ b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/wx/IndexController.java @@ -10,6 +10,7 @@ import cn.exrick.xboot.your.util.HttpUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -29,7 +30,7 @@ */ @Slf4j @RestController -@Api(tags = "璁㈠崟鎺ュ彛") +@Api(tags = "灏忕▼搴忔帴鍙�") @RequestMapping("/xboot/wx") @Transactional public class IndexController { @@ -55,9 +56,13 @@ @Autowired private ICustomerReceiveService iCustomerReceiveService; + @Autowired + private IOrderLogService iOrderLogService; + //2.寰俊鐧婚檰 - @RequestMapping("/login") + @RequestMapping(value = "/login", method = RequestMethod.POST) + @ApiOperation(value = "寰俊鐧婚檰") public Object doLogin(String code){ JSONObject SessionKeyOpenId = getSessionKeyOrOpenId( code ); @@ -65,7 +70,7 @@ String openid = SessionKeyOpenId.getStr("openid"); if(StrUtil.isEmpty(openid)){ - return ResultUtil.error(SessionKeyOpenId.toString()); + return ResultUtil.error("error寰俊:"+SessionKeyOpenId.toString()); } QueryWrapper<Customer> wrapper = new QueryWrapper<>(); @@ -74,6 +79,8 @@ if(one==null){ return ResultUtil.error(openid);//棣栨鐧婚檰闇�缁戝畾闆跺敭璁稿彲璇� }else { + one.setLoginNum(one.getLoginNum()+1); + iCustomerService.saveOrUpdate(one); return ResultUtil.data(one,"鐧诲綍鎴愬姛"); } } @@ -81,7 +88,7 @@ public static JSONObject getSessionKeyOrOpenId(String code){ //寰俊绔櫥褰昪ode String wxCode = code; - String requestUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=wx0f10f6d253f3ee6b&secret=4d4cbc8da31a96559114ad693de70631&grant_type=authorization_code&js_code="+code; + String requestUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=wx77c0d2c54010b7e4&secret=2282710e890670e916c189347d70a7c5&grant_type=authorization_code&js_code="+code; JSONObject jsonObject = JSONUtil.parseObj( HttpUtil.get(requestUrl)); return jsonObject; } @@ -89,13 +96,31 @@ //3.寰俊缁戝畾闆跺敭璁稿彲璇� //licence:闆跺敭璁稿彲璇佸彿 //openId锛氬井淇d - @RequestMapping("/bindWx") - public Object bindWx(String licence,String openId){ + @RequestMapping(value = "/bindWx", method = RequestMethod.POST) + @ApiOperation(value = "寰俊缁戝畾闆跺敭璁稿彲璇�") + public Object bindWx(String licence,String openId,String linker,String phone){ + QueryWrapper<Customer> wrapper2 = new QueryWrapper<>(); + wrapper2.eq("open_id",openId); + Customer c = iCustomerService.getOne(wrapper2); + if(c==null){ + + }else { + System.out.println(c.getOpenId()); + c.setOpenId(""); + iCustomerService.saveOrUpdate(c); + } + QueryWrapper<Customer> wrapper = new QueryWrapper<>(); wrapper.eq("licence",licence); + if(StrUtil.isNotEmpty(linker)){ + wrapper.eq("linker",linker); + } + if(StrUtil.isNotEmpty(phone)){ + wrapper.eq("phone",phone); + } Customer one = iCustomerService.getOne(wrapper); if(one==null){ - return ResultUtil.error("闆跺敭璁稿彲璇佹棤鏁�");//棣栨鐧婚檰闇�缁戝畾闆跺敭璁稿彲璇� + return ResultUtil.error("璇锋鏌ヨ緭鍏ヤ俊鎭槸鍚︽纭�");//棣栨鐧婚檰闇�缁戝畾闆跺敭璁稿彲璇� }else { one.setOpenId(openId); iCustomerService.saveOrUpdate(one); @@ -104,7 +129,8 @@ } //4.鑾峰彇浠婃棩閰嶉�佽鍗� - @RequestMapping("/getTodayOrder") + @RequestMapping(value = "/getTodayOrder", method = RequestMethod.POST) + @ApiOperation(value = "鑾峰彇浠婃棩閰嶉�佽鍗�") public Object getTodayOrder(String customerId){ OrderTask orderTask = getOrder(customerId); if(orderTask==null){ @@ -127,43 +153,95 @@ } //5.鑾峰彇杞﹁締浣嶇疆 - @RequestMapping("/getCarInfo") + @RequestMapping(value = "/getCarInfo",method = RequestMethod.POST) + @ApiOperation(value = "鑾峰彇杞﹁締浣嶇疆") public Object getCarInfo(String customerId){ QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<OrderTask>(); String format = DateUtil.format(new Date(), "yyyy-MM-dd"); wrapper2.eq("customer_id",customerId); wrapper2.eq("send_date",format); OrderTask orderTask = iOrderTaskService.getOne(wrapper2); + if(orderTask==null){ + return ResultUtil.error("浠婃棩鏃犺鍗�"); + } String carId = orderTask.getCarId(); Car car = iCarService.getById(carId); - String[] carids = new String[1]; - carids[0]= car.getCode(); - String latestGps = haiKangPost.findLatestGps(carids); - JSONObject jsonObject = JSONUtil.parseObj(latestGps); - String data = jsonObject.getStr("data"); - JSONObject jsonObject2 = JSONUtil.parseObj(data); - Integer lng = jsonObject2.getInt("longitude"); - Integer lat = jsonObject2.getInt("latitude"); - - DecimalFormat df = new DecimalFormat("#.000000"); Map<String,Object> map = new HashMap<>(); - map.put("lng",df.format(lng/360000.0)); - map.put("lat",df.format(lat/360000.0)); - map.put("content","杩樻湁3鍗曪紝棰勮10锛�22閫佽揪"); + map.put("lng",118.167491); + map.put("lat",39.651253); + map.put("content","鏆傛棤杞﹁締鏁版嵁"); + if(StrUtil.isEmpty(car.getCode())){ + return ResultUtil.data(map); + } + try { + String[] carids = new String[1]; + carids[0]= car.getCode(); + String latestGps = haiKangPost.findLatestGps(carids); + JSONObject jsonObject = JSONUtil.parseObj(latestGps); + String data = jsonObject.getStr("data"); + JSONArray objects = JSONUtil.parseArray(data); + JSONObject jsonObject2 = objects.getJSONObject(0); + Integer lng = jsonObject2.getInt("longitude"); + Integer lat = jsonObject2.getInt("latitude"); + + DecimalFormat df = new DecimalFormat("#.000000"); + map.put("lng",df.format(lng/360000.0)); + map.put("lat",df.format(lat/360000.0)); + }catch (Exception e){ + + } + QueryWrapper<OrderTask> wrapper = new QueryWrapper<OrderTask>(); + wrapper.eq("area_id",orderTask.getAreaId()); + wrapper.eq("send_date",format); + wrapper.eq("status",0); + wrapper.orderByAsc("seq"); + List<OrderTask> list = iOrderTaskService.list(wrapper); + + if(list.size()>0){ + if(list.get(0).getSeq()<orderTask.getSeq()){ + int i = orderTask.getSeq() - list.get(0).getSeq(); + map.put("content","杩樻湁"+i+"鍗曪紝棰勮"+(i*5)+"鍒嗛挓鍚庨�佽揪"); + } + if(list.get(0).getSeq()==orderTask.getSeq()){ + int i = orderTask.getSeq() - list.get(0).getSeq(); + map.put("content","棰勮5鍒嗛挓鍐呴�佽揪"); + } + } return ResultUtil.data(map); } //6.鍔犳补鍔╁姏 - @RequestMapping("/likes") + @RequestMapping(value = "/likes", method = RequestMethod.POST) + @ApiOperation(value = "鍔犳补鍔╁姏") public Object likes(String customerId){ OrderTask order = getOrder(customerId); + if(order==null){ + return ResultUtil.error("浠婃棩鏃犺鍗�"); + } order.setLikes(1); iOrderTaskService.saveOrUpdate(order); + + saveLog(); return ResultUtil.success("鍔╁姏鎴愬姛"); } + private void saveLog(){ + QueryWrapper<OrderLog> wp = new QueryWrapper<>(); + wp.eq("type",1); + OrderLog one = iOrderLogService.getOne(wp); + if(one!=null){ + one.setNum(one.getNum()+1); + }else{ + one = new OrderLog(); + one.setNum(1); + one.setType(1); + } + iOrderLogService.saveOrUpdate(one); + } + //7.鑾峰彇璁㈠崟鍒楄〃 - @RequestMapping("/getOrderList") + @RequestMapping(value = "/getOrderList", method = RequestMethod.POST) + @ApiOperation(value = "鑾峰彇璁㈠崟鍒楄〃") public Object getOrderList(String customerId, String startTime, String endTime, PageVo page){ page.setSort("sendDate"); page.setOrder("desc"); @@ -180,7 +258,8 @@ } //8.鑾峰彇璁㈠崟璇︽儏鍒楄〃 - @RequestMapping("/getOrderDetail") + @RequestMapping(value = "/getOrderDetail", method = RequestMethod.POST) + @ApiOperation(value = "鑾峰彇璁㈠崟璇︽儏鍒楄〃") public Object getOrderDetail(String orderId){ QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>(); wrapper.eq("order_id",orderId); @@ -189,7 +268,8 @@ } //9.璇勪环 - @RequestMapping("/remark") + @RequestMapping(value = "/remark", method = RequestMethod.POST) + @ApiOperation(value = "璇勪环") public Object remark(int level,String orderId){ OrderTask byId = iOrderTaskService.getById(orderId); byId.setLevel(level); @@ -200,6 +280,7 @@ //10.鑾峰彇鎰忚寤鸿鍒楄〃 @RequestMapping(value = "/getSuggestByPage", method = RequestMethod.GET) + @ApiOperation(value = "鑾峰彇鎰忚寤鸿鍒楄〃") public Result<IPage<Suggest>> getByPage(String customerId,PageVo page) { QueryWrapper<Suggest> wrapper = new QueryWrapper<>(); wrapper.eq("customer_id",customerId); @@ -209,6 +290,7 @@ //12.鏂板鎰忚寤鸿 @RequestMapping(value = "/insertSuggest", method = RequestMethod.POST) + @ApiOperation(value = "鏂板鎰忚寤鸿") public Result<Suggest> insertSuggest(String customerId,String content) { Suggest suggest = new Suggest(); suggest.setContent(content); @@ -221,6 +303,7 @@ //13.鏂板绛炬敹浜� @RequestMapping(value = "/insertReceive", method = RequestMethod.POST) + @ApiOperation(value = "鏂板绛炬敹浜�") public Result<CustomerReceive> insertReceive(String customerId,String name,String phone) { CustomerReceive customerReceive = new CustomerReceive(); customerReceive.setCustomerId(customerId); @@ -232,4 +315,35 @@ } return new ResultUtil<CustomerReceive>().setErrorMsg("鎿嶄綔澶辫触"); } + + //14.鑾峰彇绛炬敹浜哄垪琛� + @RequestMapping(value = "/getCustomerReceive", method = RequestMethod.GET) + @ApiOperation(value = "鑾峰彇绛炬敹浜�") + public Result<List<CustomerReceive>> getCustomerReceive(String customerId) { + PageVo page = new PageVo(); + page.setPageSize(30); + page.setPageNumber(1); + page.setOrder("desc"); + page.setSort("createTime"); + QueryWrapper<CustomerReceive> wrapper = new QueryWrapper<>(); + wrapper.eq("customer_id",customerId); + IPage<CustomerReceive> data = iCustomerReceiveService.page2(PageUtil.initMpPage(page),wrapper); + return new ResultUtil<List<CustomerReceive>>().setData(data.getRecords()); + } + + //15.鑾峰彇绛炬敹浜� + @RequestMapping(value = "/getCustomerReceiveById", method = RequestMethod.GET) + @ApiOperation(value = "鑾峰彇绛炬敹浜�") + public Result<CustomerReceive> getCustomerReceiveById(String customerReceiveId) { + CustomerReceive byId = iCustomerReceiveService.getById(customerReceiveId); + return new ResultUtil<CustomerReceive>().setData(byId); + } + + //16.鍒犻櫎鎺ヨ揣浜� + @RequestMapping(value = "/deleteReceive", method = RequestMethod.POST) + @ApiOperation(value = "鍒犻櫎鎺ヨ揣浜�") + public Object deleteReceive(String id) { + iCustomerReceiveService.removeById(id); + return ResultUtil.success("鍒犻櫎鎴愬姛"); + } } -- Gitblit v1.9.1