| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.internal.util.codec.Base64; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.mongodb.client.result.UpdateResult; |
| | | import com.stylefeng.guns.config.OSSService; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.dao.HouseResourceMapper; |
| | |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.util.WxAppletTools; |
| | | import com.stylefeng.guns.modular.system.warpper.PointLocation; |
| | | import com.stylefeng.guns.modular.system.warpper.req.AddHouseReq; |
| | | import com.stylefeng.guns.modular.system.warpper.req.HouseQuery; |
| | |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.security.SecureRandom; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | private MongoTemplate mongoTemplate; |
| | | @Autowired |
| | | private IHousingDemandService housingDemandService; |
| | | @Autowired |
| | | private OSSService ossService; |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | @Autowired |
| | | private WxAppletTools wxAppletTools; |
| | | |
| | | |
| | | |
| | |
| | | houseResource.setInsertUserId(null); |
| | | houseResource.setViewsNumber(0); |
| | | houseResource.setStatus(1); |
| | | houseResource.setLeaseTime(req.getTime()); |
| | | houseResource.setLeaseTime(req.getLeaseTime()); |
| | | houseResource.setFirmHouse(req.getFirmHouse()); |
| | | houseResource.setAuthTime(new Date()); |
| | | if (req.getDataType()==1) { |
| | | if (req.getTime().contains("年")) { |
| | | if (req.getLeaseTime().contains("年")) { |
| | | houseResource.setRentalDuration(2); |
| | | } else { |
| | | houseResource.setRentalDuration(1); |
| | | } |
| | | } |
| | | houseResource.setIsManage(1); |
| | | houseResource.setType(2); |
| | | houseResource.setAppUserId(Objects.requireNonNull(ShiroKit.getUser()).id); |
| | | houseResource.setInsertUserId(Objects.requireNonNull(ShiroKit.getUser()).id); |
| | | |
| | | |
| | | |
| | | PointLocation pointLocation = new PointLocation(); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(req.getLongitude()),Double.valueOf(req.getLatitude())); |
| | | pointLocation.setGeoJsonPoint(geoJsonPoint); |
| | | pointLocation.setHouseId(houseResource.getId()); |
| | | mongoTemplate.insert(pointLocation); |
| | | |
| | | houseResource.setCode(pointLocation.getId()); |
| | | this.baseMapper.updateById(houseResource); |
| | | |
| | | InputStream inputStream = null; |
| | | OutputStream outputStream = null; |
| | | String accessToken = wxAppletTools.getAccessToken(); |
| | | try { |
| | | String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("path", "pages/home/home"); |
| | | // param.put("page", "pages/index/index"); // 路径 如果没有默认跳转到首页面微信小程序发布后才可以使用不能添加参数 |
| | | param.put("width", 200); //二维码尺寸 |
| | | param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效 |
| | | param.put("auto_color", true); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效 |
| | | Map<String, Object> line_color = new HashMap<>(); |
| | | line_color.put("r", 0); |
| | | line_color.put("g", 0); |
| | | line_color.put("b", 0); |
| | | param.put("line_color", line_color); |
| | | System.err.println("调用生成微信URL接口传参:" + param); |
| | | MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
| | | HttpEntity requestEntity = new HttpEntity(param, headers); |
| | | ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); |
| | | System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody()); |
| | | byte[] result = entity.getBody(); |
| | | System.err.println(Base64.encodeBase64String(result)); |
| | | inputStream = new ByteArrayInputStream(result); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | // 最后上传生成的文件名 |
| | | String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg"; |
| | | // oss中的文件夹名 |
| | | String objectName = sdf.format(new Date()) + "/" + finalFileName; |
| | | // 上传oss |
| | | ossService.uploadFile2OSS(inputStream, objectName); |
| | | //获取文件的URl地址 |
| | | String imgUrl = ossService.getImgUrl(objectName); |
| | | houseResource.setQrCode(imgUrl); |
| | | this.baseMapper.insert(houseResource); |
| | | System.err.println("看看文件路径" + imgUrl); |
| | | } catch (Exception e) { |
| | | System.err.println("调用小程序生成微信永久小程序码URL接口异常" + e); |
| | | } finally { |
| | | if (inputStream != null) { |
| | | try { |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (outputStream != null) { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | return ResultUtil.success("添加成功"); |
| | | |
| | | } |
| | |
| | | BeanUtils.copyProperties(req,houseResource); |
| | | if (req.getDataType()==1) { |
| | | |
| | | if (req.getTime().contains("年")) { |
| | | if (req.getLeaseTime().contains("年")) { |
| | | houseResource.setRentalDuration(2); |
| | | } else { |
| | | houseResource.setRentalDuration(1); |
| | | } |
| | | } |
| | | houseResource.setUpdateTime(new Date()); |
| | | this.baseMapper.updateById(houseResource); |
| | | |
| | | HouseResource houseResource1 = this.baseMapper.selectById(req.getId()); |
| | | Query query = Query.query(Criteria.where("_id").is(houseResource1.getCode())); |
| | | PointLocation pointLocation = new PointLocation(); |
| | | pointLocation.setId(houseResource1.getCode()); |
| | | pointLocation.setHouseId(houseResource.getId()); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(req.getLongitude()),Double.valueOf(req.getLatitude())); |
| | | pointLocation.setGeoJsonPoint(geoJsonPoint); |
| | | org.bson.Document document = (org.bson.Document)mongoTemplate.getConverter() .convertToMongoType(pointLocation); |
| | | Update update = Update.fromDocument (document); |
| | | UpdateResult updateResult = mongoTemplate.updateFirst(query, update, PointLocation.class); |
| | | |
| | | return ResultUtil.success("编辑成功"); |
| | | |
| | | } |