package cn.exrick.xboot.your.controller.wx; import cn.exrick.xboot.core.common.utils.PageUtil; import cn.exrick.xboot.core.common.utils.ResultUtil; import cn.exrick.xboot.core.common.vo.PageVo; import cn.exrick.xboot.core.common.vo.Result; import cn.exrick.xboot.your.entity.*; import cn.exrick.xboot.your.service.*; import cn.exrick.xboot.your.util.HaiKangPost; 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; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.text.DecimalFormat; import java.util.*; /** * @author whj */ @Slf4j @RestController @Api(tags = "小程序接口") @RequestMapping("/xboot/wx") @Transactional public class IndexController { @Autowired private IOrderTaskService iOrderTaskService; @Autowired private ICustomerService iCustomerService; @Autowired private IOrderDetailService iOrderDetailService; @Autowired private ICarService iCarService; @Autowired private HaiKangPost haiKangPost; @Autowired private ISuggestService iSuggestService; @Autowired private ICustomerReceiveService iCustomerReceiveService; @Autowired private IOrderLogService iOrderLogService; //2.微信登陆 @RequestMapping(value = "/login", method = RequestMethod.POST) @ApiOperation(value = "微信登陆") public Object doLogin(String code){ JSONObject SessionKeyOpenId = getSessionKeyOrOpenId( code ); String openid = SessionKeyOpenId.getStr("openid"); if(StrUtil.isEmpty(openid)){ return ResultUtil.error("error微信:"+SessionKeyOpenId.toString()); } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("open_id",openid); Customer one = iCustomerService.getOne(wrapper); if(one==null){ return ResultUtil.error(openid);//首次登陆需绑定零售许可证 }else { one.setLoginNum(one.getLoginNum()+1); iCustomerService.saveOrUpdate(one); return ResultUtil.data(one,"登录成功"); } } public static JSONObject getSessionKeyOrOpenId(String code){ //微信端登录code String wxCode = 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; } //3.微信绑定零售许可证 //licence:零售许可证号 //openId:微信id @RequestMapping(value = "/bindWx", method = RequestMethod.POST) @ApiOperation(value = "微信绑定零售许可证") public Object bindWx(String licence,String openId,String linker,String phone){ QueryWrapper 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 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("请检查输入信息是否正确");//首次登陆需绑定零售许可证 }else { one.setOpenId(openId); iCustomerService.saveOrUpdate(one); return ResultUtil.data(one,"登录成功"); } } //4.获取今日配送订单 @RequestMapping(value = "/getTodayOrder", method = RequestMethod.POST) @ApiOperation(value = "获取今日配送订单") public Object getTodayOrder(String customerId){ OrderTask orderTask = getOrder(customerId); if(orderTask==null){ return ResultUtil.data(new ArrayList<>()); }else{ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("order_id",orderTask.getId()); List list = iOrderDetailService.list(wrapper); return ResultUtil.data(list); } } public OrderTask getOrder(String customerId){ QueryWrapper wrapper2 = new QueryWrapper(); String format = DateUtil.format(new Date(), "yyyy-MM-dd"); wrapper2.eq("customer_id",customerId); wrapper2.eq("send_date",format); OrderTask orderTask = iOrderTaskService.getOne(wrapper2); return orderTask; } //5.获取车辆位置 @RequestMapping(value = "/getCarInfo",method = RequestMethod.POST) @ApiOperation(value = "获取车辆位置") public Object getCarInfo(String customerId){ QueryWrapper wrapper2 = new QueryWrapper(); 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); Map map = new HashMap<>(); 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 wrapper = new QueryWrapper(); wrapper.eq("area_id",orderTask.getAreaId()); wrapper.eq("send_date",format); wrapper.eq("status",0); wrapper.orderByAsc("seq"); List list = iOrderTaskService.list(wrapper); if(list.size()>0){ if(list.get(0).getSeq() 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(value = "/getOrderList", method = RequestMethod.POST) @ApiOperation(value = "获取订单列表") public Object getOrderList(String customerId, String startTime, String endTime, PageVo page){ page.setSort("sendDate"); page.setOrder("desc"); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("customer_id",customerId); if(StrUtil.isNotEmpty(startTime)){ wrapper.ge("send_date",startTime); } if(StrUtil.isNotEmpty(endTime)){ wrapper.le("send_date",endTime); } IPage page1 = iOrderTaskService.page(PageUtil.initMpPage(page), wrapper); return ResultUtil.data(page1.getRecords()); } //8.获取订单详情列表 @RequestMapping(value = "/getOrderDetail", method = RequestMethod.POST) @ApiOperation(value = "获取订单详情列表") public Object getOrderDetail(String orderId){ QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("order_id",orderId); List list1 = iOrderDetailService.list(wrapper); return ResultUtil.data(list1); } //9.评价 @RequestMapping(value = "/remark", method = RequestMethod.POST) @ApiOperation(value = "评价") public Object remark(int level,String orderId){ OrderTask byId = iOrderTaskService.getById(orderId); byId.setLevel(level); iOrderTaskService.saveOrUpdate(byId); return ResultUtil.success("评价成功"); } //10.获取意见建议列表 @RequestMapping(value = "/getSuggestByPage", method = RequestMethod.GET) @ApiOperation(value = "获取意见建议列表") public Result> getByPage(String customerId,PageVo page) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("customer_id",customerId); IPage data = iSuggestService.page2(PageUtil.initMpPage(page),wrapper); return new ResultUtil>().setData(data); } //12.新增意见建议 @RequestMapping(value = "/insertSuggest", method = RequestMethod.POST) @ApiOperation(value = "新增意见建议") public Result insertSuggest(String customerId,String content) { Suggest suggest = new Suggest(); suggest.setContent(content); suggest.setCustomerId(customerId); if (iSuggestService.saveOrUpdate(suggest)) { return new ResultUtil().setSuccessMsg("操作成功"); } return new ResultUtil().setErrorMsg("操作失败"); } //13.新增签收人 @RequestMapping(value = "/insertReceive", method = RequestMethod.POST) @ApiOperation(value = "新增签收人") public Result insertReceive(String customerId,String name,String phone) { CustomerReceive customerReceive = new CustomerReceive(); customerReceive.setCustomerId(customerId); customerReceive.setPhone(phone); customerReceive.setName(name); customerReceive.setFstatus(0); if (iCustomerReceiveService.saveOrUpdate(customerReceive)) { return new ResultUtil().setSuccessMsg("操作成功"); } return new ResultUtil().setErrorMsg("操作失败"); } //14.获取签收人列表 @RequestMapping(value = "/getCustomerReceive", method = RequestMethod.GET) @ApiOperation(value = "获取签收人") public Result> getCustomerReceive(String customerId) { PageVo page = new PageVo(); page.setPageSize(30); page.setPageNumber(1); page.setOrder("desc"); page.setSort("createTime"); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("customer_id",customerId); IPage data = iCustomerReceiveService.page2(PageUtil.initMpPage(page),wrapper); return new ResultUtil>().setData(data.getRecords()); } //15.获取签收人 @RequestMapping(value = "/getCustomerReceiveById", method = RequestMethod.GET) @ApiOperation(value = "获取签收人") public Result getCustomerReceiveById(String customerReceiveId) { CustomerReceive byId = iCustomerReceiveService.getById(customerReceiveId); return new ResultUtil().setData(byId); } //16.删除接货人 @RequestMapping(value = "/deleteReceive", method = RequestMethod.POST) @ApiOperation(value = "删除接货人") public Object deleteReceive(String id) { iCustomerReceiveService.removeById(id); return ResultUtil.success("删除成功"); } }