Commit 51cd4ecb authored by hanfeng's avatar hanfeng

Merge remote-tracking branch 'origin/dev' into dev

parents ab8c264f 63fc9b3c
......@@ -6,21 +6,28 @@ import com.github.wxiaoqi.security.common.exception.auth.ClientTokenException;
import com.github.wxiaoqi.security.common.exception.auth.UserInvalidException;
import com.github.wxiaoqi.security.common.exception.auth.UserTokenException;
import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.util.HttpRequestUtil;
import com.github.wxiaoqi.security.common.util.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import static org.springframework.http.HttpStatus.NOT_EXTENDED;
......@@ -31,7 +38,8 @@ import static org.springframework.http.HttpStatus.NOT_EXTENDED;
@ResponseBody
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Value("${spring.application.name}")
private String applicationName;
/**
* 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的
*/
......@@ -69,7 +77,15 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
if(0 == ex.getStatus()) {
response.setStatus(500);
}
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + ex.getStackTrace().toString());
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", ex.toString() + ":" +ex.getMessage());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
logger.error(e.getMessage());
}
return new BaseResponse(ex.getStatus(), ex.getMessage());
}
......@@ -82,10 +98,39 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
StringWriter stringWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stringWriter));
logger.error(cause.getMessage(), ex);
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + stringWriter.toString());
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
logger.error(e.getMessage());
}
return new BaseResponse(5000, "Server exception: " + ex.getMessage());
}
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + ex.getStackTrace().toString());
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", initCommonLogPrePart()+ ":" + ex.toString() + ":" + ex.getMessage());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
logger.error(e.getMessage());
}
return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage());
}
public String initCommonLogPrePart() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();//获取request
StringBuilder stringBuilder = new StringBuilder();
//request 获得头部
stringBuilder.append(request.getHeader("app"));
LocalDateTime startTime= LocalDateTime.now();//开始时间
stringBuilder.append("》》" +startTime.toString());
stringBuilder.append("》》" +request.getServletPath());
stringBuilder.append("》》" +applicationName + ":" + request.getServletPath());
return stringBuilder.toString();
}
}
......@@ -4,18 +4,27 @@ package com.github.wxiaoqi.security.common.handler;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.HttpRequestUtil;
import com.github.wxiaoqi.security.common.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
@RestControllerAdvice("com.xxfc.platform")
@Slf4j
public class PlatformExceptionHandler {
@Value("${spring.application.name}")
private String applicationName;
@ExceptionHandler(value = {BaseException.class})
public BaseResponse baseExceptionHandler(Exception e) {
......@@ -35,11 +44,27 @@ public class PlatformExceptionHandler {
StringWriter stringWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stringWriter));
log.error(cause.getMessage(), e);
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + stringWriter.toString());
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) {
log.error(ex.getMessage());
}
return assembleResult(ObjectRestResponse.createFailedResult(5000, "服务器开小差了,请稍后重试!"), "Server exception: " + e.getMessage());
}
log.error("Server exception: ", e);
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + e.getStackTrace().toString());
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", initCommonLogPrePart()+ ":" + e.toString() + ":" + e.getMessage());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) {
log.error(ex.getMessage());
}
return assembleResult(ObjectRestResponse.createFailedResult(5000, "服务器开小差了,请稍后重试!"), "Server exception: " + e.getMessage());
}
......@@ -52,4 +77,18 @@ public class PlatformExceptionHandler {
return assembleResult(error, e.getClass().getSimpleName() + ": " + e.getMessage());
}
public String initCommonLogPrePart() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();//获取request
StringBuilder stringBuilder = new StringBuilder();
//request 获得头部
stringBuilder.append(request.getHeader("app"));
LocalDateTime startTime= LocalDateTime.now();//开始时间
stringBuilder.append("》》" +startTime.toString());
stringBuilder.append("》》" +request.getServletPath());
stringBuilder.append("》》" +applicationName + ":" + request.getServletPath());
return stringBuilder.toString();
}
}
package com.github.wxiaoqi.security.common.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URLDecoder;
@Slf4j
public class HttpRequestUtil {
/**
* post请求
* @param url url地址
* @return
*/
public static String httpPost(String url){
//post请求返回结果
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost method = new HttpPost(url);
String str = "";
try {
HttpResponse result = httpClient.execute(method);
url = URLDecoder.decode(url, "UTF-8");
/**请求发送成功,并得到响应**/
if (result.getStatusLine().getStatusCode() == 200) {
try {
/**读取服务器返回过来的json字符串数据**/
str = EntityUtils.toString(result.getEntity(),"UTF-8");
} catch (Exception e) {
log.error("post请求提交失败:" + url, e);
}
}
} catch (IOException e) {
log.error("post请求提交失败:" + url, e);
}
return str;
}
/**
* 发送get请求
* @param url 路径
* @return
*/
public static String httpGet(String url){
//get请求返回结果
String strResult = null;
try {
DefaultHttpClient client = new DefaultHttpClient();
//发送get请求
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
/**请求发送成功,并得到响应**/
if (response.getStatusLine().getStatusCode() == org.apache.http.HttpStatus.SC_OK) {
/**读取服务器返回过来的json字符串数据**/
strResult = EntityUtils.toString(response.getEntity(),"UTF-8");
} else {
log.error("get请求提交失败:" + url);
}
} catch (IOException e) {
log.error("get请求提交失败:" + url, e);
}
return strResult;
}
}
......@@ -158,4 +158,9 @@ public interface UserFeign {
@RequestParam(value = "cono",required = false) String cono,
@RequestParam(value = "reason",required = false) String reason,
@RequestParam(value = "isSuccess") Boolean isSuccess);
@GetMapping("/app/user/collect/exist")
boolean isCollectionByTypeAndTypeId(@RequestParam("userId") Integer userId,
@RequestParam(value = "type") int type,
@RequestParam("id") Integer typId);
}
......@@ -14,12 +14,14 @@ import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.tour.entity.TourGood;
import com.xxfc.platform.tour.feign.TourFeign;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
import java.util.Objects;
/**
* ${DESCRIPTION}
......@@ -105,17 +107,13 @@ public class AppUserCollectBiz extends BaseBiz<AppUserCollectMapper, AppUserColl
}
public boolean isCollectionByTypeAndTypeId(Integer userId,int type, Integer typeId) {
AppUserCollect appUserCollect = new AppUserCollect();
appUserCollect.setType(type);
appUserCollect.setTypeId(typeId);
appUserCollect.setUserId(userId);
appUserCollect.setIsDel(0);
List<AppUserCollect> collect = mapper.select(appUserCollect);
return CollectionUtils.isNotEmpty(collect);
}
}
......@@ -19,6 +19,7 @@ import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.xxfc.platform.tour.feign.TourFeign;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -108,4 +109,11 @@ public class AppUserCollectController extends CommonBaseController {
return collectBiz.upUserCollect(collectDTO);
}
@GetMapping("/collect/exist")
@ApiOperation("判断是否收藏")
public boolean isCollectionByTypeAndTypeId(@RequestParam("userId") Integer userId,
@RequestParam(value = "type") int type,
@RequestParam("id") Integer typId){
return collectBiz.isCollectionByTypeAndTypeId(userId,type,typId);
}
}
......@@ -19,4 +19,6 @@ public class CampsiteShopFindDTO extends PageParam {
private Integer type;
private String name;
private String keyWord;
}
......@@ -100,4 +100,9 @@ public class CampsiteShopDetailVo {
@ApiModelProperty(value = "海报背景")
private String posterBackground;
/**
* 是否已经被收藏
*/
private Boolean hasCollection;
}
......@@ -19,6 +19,7 @@ import tk.mybatis.spring.annotation.MapperScan;
*/
@SpringBootApplication(scanBasePackages = {
"com.xxfc.platform",
"com.github.wxiaoqi.security.admin.support.aop",
"com.github.wxiaoqi.security.common.handler",
"com.github.wxiaoqi.security.common.log"
})
......
......@@ -2,6 +2,7 @@ package com.xxfc.platform.campsite.biz;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.RandomUtil;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
......@@ -22,6 +23,7 @@ import com.xxfc.platform.campsite.mapper.CampsiteShopMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import java.time.Instant;
......@@ -41,6 +43,8 @@ import java.util.stream.Collectors;
@Slf4j
public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
private final int CAMPSITE_COLLECTION_TYPE=3;
@Autowired
private CampsiteShopTagBiz campsiteShopTagBiz;
......@@ -56,6 +60,9 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
@Resource(name = "customRedisTemplate")
ValueOperations<String, String> campsiteValueOperations;
@Autowired
private UserFeign userFeign ;
/**
* 营地缓存前缀
*/
......@@ -81,7 +88,7 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
public PageDataVO<CampsiteShopPageVo> findCampsiteShopPageByType(CampsiteShopFindDTO campsiteShopFindDTO) {
String campsite_cache_key = String.format("%s%s%s%s%s", campsiteShopFindDTO.getType() == null ? "" : campsiteShopFindDTO.getType() + ":",
/* String campsite_cache_key = String.format("%s%s%s%s%s", campsiteShopFindDTO.getType() == null ? "" : campsiteShopFindDTO.getType() + ":",
campsiteShopFindDTO.getAddrProvince() == null ? "" : campsiteShopFindDTO.getAddrProvince() + ":",
campsiteShopFindDTO.getAddrCity()==null?"":campsiteShopFindDTO.getAddrCity()+":",
campsiteShopFindDTO.getPage()+":",
......@@ -90,9 +97,9 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
if (result != null) {
return JSONObject.parseObject(result, new TypeReference<PageDataVO<CampsiteShopPageVo>>() {
});
}
}*/
PageDataVO<CampsiteShopPageVo> campsiteShopPageDataVO = findCampsiteShopPageByTypeAndName(campsiteShopFindDTO);
campHashOperations.put(CAMPSITE_LIST_CACHE_PREKEY,campsite_cache_key,JSONObject.toJSONString(campsiteShopPageDataVO));
/* campHashOperations.put(CAMPSITE_LIST_CACHE_PREKEY,campsite_cache_key,JSONObject.toJSONString(campsiteShopPageDataVO));*/
return campsiteShopPageDataVO;
}
......@@ -100,8 +107,7 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
public PageDataVO<CampsiteShopPageVo> findCampsiteShopPageByTypeAndName(CampsiteShopFindDTO campsiteShopFindDTO){
PageDataVO<CampsiteShopPageVo> campsiteShopPageDataVO = new PageDataVO<>();
PageDataVO<CampsiteShopPageDTO> pageDataVO = PageDataVO.pageInfo(campsiteShopFindDTO.getPage(), campsiteShopFindDTO.getLimit(),
() -> mapper.findAllCampsiteShopsByTypeOrCodeOrName(campsiteShopFindDTO.getType(),campsiteShopFindDTO.getAddrProvince(),
campsiteShopFindDTO.getAddrCity(),campsiteShopFindDTO.getName()));
() -> mapper.findAllCampsiteShopsByTypeOrCodeOrName(campsiteShopFindDTO));
List<CampsiteShopPageDTO> campsiteShopPageDTOS = pageDataVO.getData();
if (CollectionUtils.isEmpty(campsiteShopPageDTOS)) {
campsiteShopPageDataVO.setPageNum(campsiteShopFindDTO.getPage());
......@@ -131,18 +137,19 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
}
/**
* @param id
* @param longitude 经度
* @param latitude 纬度
* @return
*/
public CampsiteShopDetailVo findCampsiteShopDetailById(Integer id, Double longitude, Double latitude) {
public CampsiteShopDetailVo findCampsiteShopDetailById(Integer userId,Integer id, Double longitude, Double latitude) {
/*
String result = campsiteValueOperations.get(String.format("%s%d", CAMSITE_DETAIL_CACHE_PREKEY, id));
if (Objects.nonNull(result)) {
return JSONObject.parseObject(result, new TypeReference<CampsiteShopDetailVo>() {
});
}
*/
CampsiteShopDetailVo campsiteShopDetailVo = new CampsiteShopDetailVo();
CampsiteShopDetailDTO campsiteShopDetailDTO = mapper.findCampsiteShopDetailById(id);
......@@ -181,7 +188,17 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
campsiteShopDetailVo.setDistance(String.format("%.1f", distance));
}
}
campsiteValueOperations.set(String.format("%s%d", CAMSITE_DETAIL_CACHE_PREKEY, id), JSONObject.toJSONString(campsiteShopDetailVo));
if (Objects.nonNull(userId)){
boolean isCollection = userFeign.isCollectionByTypeAndTypeId(userId,CAMPSITE_COLLECTION_TYPE,id);
campsiteShopDetailVo.setHasCollection(isCollection);
}else {
campsiteShopDetailVo.setHasCollection(false);
}
/* campsiteValueOperations.set(String.format("%s%d", CAMSITE_DETAIL_CACHE_PREKEY, id), JSONObject.toJSONString(campsiteShopDetailVo));*/
return campsiteShopDetailVo;
}
......@@ -258,7 +275,7 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
//保存或更新 * 营地与营地类型信息
List<Integer> campsiteTagDTOS = campsiteShopAdminDTO.getCampsiteTagDTOS();
campsiteShopTagBiz.saveBatch(campsiteTagDTOS, campsiteShop.getId());
redisTemplate.delete(CAMPSITE_LIST_CACHE_PREKEY);
// redisTemplate.delete(CAMPSITE_LIST_CACHE_PREKEY);
return effectRows;
}
......@@ -294,8 +311,8 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
}
campsiteShopAdminVO.setCarouse(campsiteShopAdminVO.getCarouse() == null ? new ArrayList<CampsiteShopCarouselVo>() : campsiteShopAdminVO.getCarouse());
campsiteShopAdminVO.setCampsiteTagListVos(campsiteShopAdminVO.getCampsiteTagListVos() == null ? new ArrayList<CampsiteTagListVo>() : campsiteShopAdminVO.getCampsiteTagListVos());
redisTemplate.delete(String.format("%s%d", CAMSITE_DETAIL_CACHE_PREKEY, id));
redisTemplate.delete(CAMPSITE_LIST_CACHE_PREKEY);
// redisTemplate.delete(String.format("%s%d", CAMSITE_DETAIL_CACHE_PREKEY, id));
// redisTemplate.delete(CAMPSITE_LIST_CACHE_PREKEY);
return campsiteShopAdminVO;
}
......@@ -307,20 +324,20 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
*/
public int updateCampsiteSatus(int id) {
int effectRows = mapper.updateCampsiteStatusById(id, 1);
if (effectRows > 0) {
/* if (effectRows > 0) {
redisTemplate.delete(String.format("%s%d", CAMSITE_DETAIL_CACHE_PREKEY, id));
redisTemplate.delete(CAMPSITE_LIST_CACHE_PREKEY);
}
}*/
return effectRows;
}
public int upperOrLowerShelves(Integer id, Integer status) {
int effectRows = mapper.updateCampsiteSaleStatusById(id, status);
if (effectRows > 0) {
/* if (effectRows > 0) {
redisTemplate.delete(String.format("%s%d", CAMSITE_DETAIL_CACHE_PREKEY, id));
redisTemplate.delete(CAMPSITE_LIST_CACHE_PREKEY);
}
}*/
return effectRows;
}
......
package com.xxfc.platform.campsite.mapper;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.xxfc.platform.campsite.dto.CampsiteShopAdminFindDTO;
import com.xxfc.platform.campsite.dto.CampsiteShopAdminPageDTO;
import com.xxfc.platform.campsite.dto.CampsiteShopDetailDTO;
import com.xxfc.platform.campsite.dto.CampsiteShopPageDTO;
import com.xxfc.platform.campsite.dto.*;
import com.xxfc.platform.campsite.entity.CampsiteShop;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
......@@ -24,12 +21,8 @@ public interface CampsiteShopMapper extends Mapper<CampsiteShop> {
/**
* 根据店铺类型查找店铺列表
*
* @param typeId
*/
List<CampsiteShopPageDTO> findAllCampsiteShopsByTypeOrCodeOrName(@Param("typeId") Integer typeId,
@Param("proviceCode") Integer proviceCode,
@Param("cityCode") Integer cityCode,
@Param("name") String name);
List<CampsiteShopPageDTO> findAllCampsiteShopsByTypeOrCodeOrName(CampsiteShopFindDTO campsiteShopFindDTO);
/**
* 首页营地列表
......
package com.xxfc.platform.campsite.rest;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
......@@ -31,11 +32,13 @@ public class CampsiteShopController extends BaseController<CampsiteShopBiz, Camp
@GetMapping("/app/unauth/shops")
public ObjectRestResponse<PageDataVO<CampsiteShopPageVo>> findCampsiteShopPageByTypeAndName(@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", required = false, defaultValue = "6") Integer pageSize) {
@RequestParam(value = "pageSize", required = false, defaultValue = "6") Integer pageSize,
@RequestParam(value = "keyWord",required = false) String keyWord) {
CampsiteShopFindDTO campsiteShopFindDTO = new CampsiteShopFindDTO();
campsiteShopFindDTO.setType(type);
campsiteShopFindDTO.setPage(pageNo);
campsiteShopFindDTO.setLimit(pageSize);
campsiteShopFindDTO.setKeyWord(keyWord);
PageDataVO<CampsiteShopPageVo> pageDataVO = getBaseBiz().findCampsiteShopPageByType(campsiteShopFindDTO);
return ObjectRestResponse.succ(pageDataVO);
}
......@@ -55,8 +58,9 @@ public class CampsiteShopController extends BaseController<CampsiteShopBiz, Camp
@GetMapping("/app/unauth/shop")
public ObjectRestResponse<CampsiteShopDetailVo> findCampsiteShopDetailById(@RequestParam(value = "id") Integer id,
@RequestParam(value = "longitude", required = false) Double longitude,
@RequestParam(value = "latitude", required = false) Double latitude) {
CampsiteShopDetailVo campsiteShopDetailVo = getBaseBiz().findCampsiteShopDetailById(id, longitude, latitude);
@RequestParam(value = "latitude", required = false) Double latitude,
AppUserDTO appUserDTO) {
CampsiteShopDetailVo campsiteShopDetailVo = getBaseBiz().findCampsiteShopDetailById(appUserDTO.getUserid(),id, longitude, latitude);
return ObjectRestResponse.succ(campsiteShopDetailVo);
}
......
......@@ -66,18 +66,21 @@
cs.sale_state = 1
AND cs.is_del = 0
<if test="typeId!=null">
and cst.tag_id=#{typeId}
<if test="type!=null">
and cst.tag_id=#{type}
</if>
<if test="proviceCode != null">
<if test="addrProvince != null">
and cs.`province`=#{proviceCode}
</if>
<if test="cityCode != null">
<if test="addrCity != null">
and cs.`city`=#{cityCode}
</if>
<if test="name!=null and name!=''">
and cs.`name` like concat('%',#{name},'%')
</if>
<if test="keyWord!=null and keyWord!=''">
and (cs.`name` like concat('%',#{keyWord},'%') or cs.address like concat('%',#{keyWord},'%') or `ct`.name like concat('%',#{keyWord},'%') )
</if>
GROUP BY cs.id
order by cs.hot DESC,cs.crt_time DESC
</select>
......
......@@ -251,7 +251,6 @@ public class OrderVehicleCrosstownBiz extends BaseBiz<OrderVehicaleCrosstownMapp
}
Vehicle vehicle = null;
RestResponse<Vehicle> vehicleRestResponse = vehicleFeign.findById(orderRentVehicleDetail.getVehicleId());
log.info("获取车辆信息返回消息:{}", vehicleRestResponse.getMessage());
if (vehicleRestResponse.getData() != null) {
vehicle = vehicleRestResponse.getData();
} else {
......@@ -289,13 +288,13 @@ public class OrderVehicleCrosstownBiz extends BaseBiz<OrderVehicaleCrosstownMapp
vehicleDepartureVo.setCheckMan(checkUserInfoDto.getUsername());
vehicleDepartureVo.setCheckManTel(checkUserInfoDto.getTelephone());
}
log.info("小程序订单出车: " + vehicleDepartureVo.toString());
try {
RestResponse restResponse = vehicleFeign.departureBySmall(vehicleDepartureVo);
if (restResponse.getStatus() != 200) {
return ObjectRestResponse.createFailedResult(1001, restResponse.getMessage());
}
log.error("返回信息: " + restResponse.toString());
log.info("小程序订单出车成功: " + restResponse.getCode() + restResponse.getMessage());
} catch (Exception e) {
return ObjectRestResponse.createFailedResult(1001, e.getMessage());
}
......@@ -309,12 +308,13 @@ public class OrderVehicleCrosstownBiz extends BaseBiz<OrderVehicaleCrosstownMapp
vehicleArrivalVo.setRecycleManTel(checkUserInfoDto.getTelephone());
}
vehicleArrivalVo.setBookRecordId(orderRentVehicleDetail.getBookRecordId());
log.info("小程序订单还车: " + vehicleArrivalVo.toString());
try {
RestResponse restResponse = vehicleFeign.arrivalBySmall(vehicleArrivalVo);
if (restResponse.getStatus() != 200) {
return ObjectRestResponse.createFailedResult(1001, restResponse.getMessage());
}
log.error("返回信息: " + restResponse.toString());
log.info("小程序订单还车成功: " + restResponse.getCode() + restResponse.getMessage());
} catch (Exception e) {
return ObjectRestResponse.createFailedResult(500, e.getMessage());
}
......
......@@ -187,7 +187,7 @@ public class OrderCalculateBiz {
//返回优惠券
if(StrUtil.isNotBlank(baseOrder.getCouponTickerNos())) {
//没有租车消费金额,所以返回所有优惠券
inProgressVO.setBackCoupons(StrUtil.split(baseOrder.getCouponTickerNos(), ','));
backCouponNos.addAll(StrUtil.split(baseOrder.getCouponTickerNos(), ','));
}
//设置消费金额,添加租车以外的消费金额
......
......@@ -242,6 +242,7 @@
</select>
<select id="getAllOrderList" parameterType="Map" resultType="com.xxfc.platform.order.pojo.bg.BgOrderListVo">
SELECT
DISTINCT(b1.id),
bc1.`name` AS startCompanyName,
bc2. NAME AS endCompanyName,
v1.number_plate AS numberPlate,
......
......@@ -674,12 +674,12 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay>{
orderPayVo.setAmount(3);
orderPayVo.setBody("扣除租车订单费用");
orderPayVo.setSubject("租车订单交易费用");
orderPayBiz.testTradeRefund("216584713656209408", 105000, "退还违约金1050元", "2165847136562094081050");
//orderPayBiz.testTradeRefund("216584713656209408", 105000, "退还违约金1050元", "2165847136562094081050");
//orderPayBiz.fundAuthOrderUnFreeze(orderPayVo, "");
//orderPayBiz.alipayOrderRefund("20191024153859000003","2019102422001421530513773694", 2, "xxxx", "");
//orderPayBiz.tradePay(orderPayVo, "");
//orderPayBiz.fundAuthCancel(orderPayVo, "");
//orderPayBiz.tradePay("20191114182254000019", "2019111410002001530505959461", 1,"扣除违约金", "扣除违约金");
orderPayBiz.fundAuthQuery("20191115092455000004");
orderPayBiz.fundAuthQuery("20191031172653000026");
}
}
......@@ -2,7 +2,7 @@ package com.xxfc.platform.universal.controller;
import com.xxfc.platform.universal.biz.MailServiceBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -13,7 +13,7 @@ public class EmailSendController {
@Autowired
MailServiceBiz mailServiceBiz;
@GetMapping(value = "/app/unauth/send")
@PostMapping(value = "/app/unauth/send")
public void senEmail(String toUser, String subject, String content) {
mailServiceBiz.run(toUser, subject, content);
}
......
package com.xxfc.platform.vehicle.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
/**
* 分公司停靠车辆统计
*/
@Table(name = "branch_company_vehicle_count")
@Data
public class BranchCompanyVehicleCount {
@Id
private Long id;
/**
* 公司名称
*/
@Column(name = "company_name")
private String companyName;
/**
* 当前停靠车辆数量
*/
@Column(name = "vehicle_num")
private Integer vehicleNum;
/**
* 统计日期
*/
@Column(name = "count_date")
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(
pattern = "yyyy-MM-dd"
)
private Date countDate;
}
\ No newline at end of file
......@@ -3,7 +3,8 @@ package com.xxfc.platform.vehicle.pojo;
import lombok.Data;
@Data
public class BranchCompanyVehicleCount {
public class BranchCompanyVehicleCountVo {
private String parkBranchCompanyName;
private Integer count;
private Integer companyId;
}
package com.xxfc.platform.vehicle.pojo.dto;
import com.github.wxiaoqi.security.common.vo.PageParam;
import lombok.Data;
@Data
public class BranchCompanyVehicleCountDTO extends PageParam {
//开始时间 yyyy-MM-dd
private String startTime;
//结束时间
private String endTime;
private String companyName;
//统计类型,日月年, 1、日,2、月,3、年
private Integer type;
//需要除去的天数
private Integer dayNum;
}
package com.xxfc.platform.vehicle.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Calendar;
@Service
@Slf4j
public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCountMapper, BranchCompanyVehicleCount> {
@Autowired
VehicleInformationDownloadBiz vehicleInformationDownloadBiz;
public ObjectRestResponse add(BranchCompanyVehicleCount branchCompanyVehicleCount) {
if (branchCompanyVehicleCount == null) {
return ObjectRestResponse.paramIsEmpty();
}
BranchCompanyVehicleCount oldValue = selectOne(branchCompanyVehicleCount);
if (oldValue == null) {
insertSelectiveRe(branchCompanyVehicleCount);
}
return ObjectRestResponse.succ();
}
public ObjectRestResponse<PageDataVO<BranchCompanyVehicleCount>> findAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
vehicleInformationDownloadBiz.addAll();
Integer pageNo = branchCompanyVehicleCountDTO.getPage() == null ? 1 : branchCompanyVehicleCountDTO.getPage();
Integer pageSize = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit();
Integer type = branchCompanyVehicleCountDTO.getType() == null ? 1 : branchCompanyVehicleCountDTO.getType();
branchCompanyVehicleCountDTO.setPage(pageNo);
branchCompanyVehicleCountDTO.setLimit(pageSize);
branchCompanyVehicleCountDTO.setType(type);
if (type == 1) {
branchCompanyVehicleCountDTO.setDayNum(1);
} else if (type == 2) {
branchCompanyVehicleCountDTO.setDayNum(7);
} else if (type == 3) {
branchCompanyVehicleCountDTO.setDayNum(getCurrentMonthLastDay());
}
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<BranchCompanyVehicleCount> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.getAllByParam(query.getSuper()));
return ObjectRestResponse.succ();
}
public int getCurrentMonthLastDay() {
Calendar a = Calendar.getInstance();
a.set(Calendar.DATE, 1);//把日期设置为当月第一天
a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
int maxDate = a.get(Calendar.DATE);
return maxDate;
}
}
......@@ -9,6 +9,7 @@ import com.xxfc.platform.vehicle.constant.ResCode.ResCode;
import com.xxfc.platform.vehicle.entity.*;
import com.xxfc.platform.vehicle.mapper.*;
import com.xxfc.platform.vehicle.pojo.*;
import com.xxfc.platform.vehicle.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
......@@ -198,14 +199,6 @@ public class VehicleActiveService {
throw new BaseException(ResCode.VEHICLE_DEPARTURE_VEHICLE_UNEXIST.getDesc(),
ResCode.VEHICLE_DEPARTURE_VEHICLE_UNEXIST.getCode());
}
// if (StringUtils.isBlank(arrivalVo.getRecycleMan()) || StringUtils.isBlank(arrivalVo.getRecycleManTel())) {
// throw new BaseException(ResCode.CHECKUSER_AND_PHONE_NOT_NULL.getDesc(),
// ResCode.CHECKUSER_AND_PHONE_NOT_NULL.getCode());
// }
// if (!vehicle.getStatus().equals(VehicleStatus.DEPARTURE.getCode())) {
// throw new BaseException(ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getDesc() + ", 车辆状态是:" + getVehicleStatus(vehicle.getStatus(), vehicle.getId()),
// ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getCode());
// }
Integer MileageRest = vehicle.getMileageLastUpdate();
Integer MileageRest1 = arrivalVo.getMileage();
if (MileageRest1 == null) {
......@@ -217,6 +210,9 @@ public class VehicleActiveService {
if (arrivalVo.getBookRecordId() != null) {
vehicleBookRecord = vehicleBookRecordBiz.selectById(arrivalVo.getBookRecordId());
updateBookRecordStatus(vehicleBookRecord, 2);
} else {
throw new BaseException(ResCode.VEHICLE_BOOK_RECORD_IS_NOT_EXIST.getDesc(),
ResCode.VEHICLE_BOOK_RECORD_IS_NOT_EXIST.getCode());
}
// 写入车辆公里数,还车分公司id
vehicle.setMileageLastUpdate(MileageRest1);
......@@ -239,12 +235,9 @@ public class VehicleActiveService {
}
if (flag) { //如果此条记录后面还有未收车记录,就不修改车辆状态
vehicle.setStatus(VehicleStatus.NORMAL.getCode());
// if (result == 0) {
// throw new BaseException(ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getDesc(),
// ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getCode());
// }
}
vehicleMapper.updateByPrimaryKeySelective(vehicle);
DateTime arrivalDate = new DateTime(vehicleBookRecord.getBookEndDate());
DateTime actualArrivalDate = new DateTime(new Date());
//提前还车处理
......@@ -257,7 +250,8 @@ public class VehicleActiveService {
bookVehicleVo.setUnbookStartDate(actualArrivalDate.toString(DATE_TIME_FORMATTER));
bookVehicleVo.setUnbookEndDate(arrivalDate.toString(DATE_TIME_FORMATTER));
bookVehicleVo.setRemark(bookVehicleVo.getRemark()==null?"": bookVehicleVo.getRemark()+ " 用户提前还车,取消剩余天数, 初始预定结束时间是," + new DateTime(vehicleBookRecord.getBookEndDate()).toString(DATE_TIME_FORMATTER));
vehicleBookRecord.setRemark(bookVehicleVo.getRemark());
vehicleBookRecord.setBookEndDate(new Date());
vehicleBookRecord.setRemark(bookVehicleVo.getRemark());
try {
Boolean hasSuc = vehicleBiz.unbookVehicle(bookVehicleVo);
if (!hasSuc) {
......@@ -285,6 +279,11 @@ public class VehicleActiveService {
if (vehicleBookRecord != null) {
departureLog.setArrivalBranchCompanyId(vehicleBookRecord.getRetCompany());
}
//添加收车成功,后面有当天预定的记录时,取消当天的预定
boolean unBookStatus = unBookArrivalDateTime(vehicleBookRecord);
if (!unBookStatus) {
log.info("还车释放当天bookInfo失败!请手动修改!");
}
vehicleDepartureLogMapper.updateByPrimaryKeySelective(departureLog);
// 车辆活动日志
VehicleActiveLog activeLog = vehicleActiveLogMapper.selectLastByVehicleId(arrivalVo.getVehicleId());
......@@ -295,23 +294,6 @@ public class VehicleActiveService {
activeLog.setEndTime(new Date());
activeLog.setUpdateTime(new Date());
vehicleActiveLogMapper.updateByPrimaryKeySelective(activeLog);
//取消预定时间 bookInfo和bookRecord
// BookVehicleVO bookVehicleVo = new BookVehicleVO();
// BeanUtils.copyProperties(vehicleBookRecord, bookVehicleVo);
// bookVehicleVo.setNotCheckTimeLegal(Boolean.TRUE);
// bookVehicleVo.setBookStartDate(null);
// bookVehicleVo.setBookEndDate(null);
// bookVehicleVo.setUnbookStartDate(new DateTime(vehicleBookRecord.getBookStartDate()).toString(DATE_TIME_FORMATTER));
// bookVehicleVo.setUnbookEndDate(new DateTime(vehicleBookRecord.getBookEndDate()).toString(DATE_TIME_FORMATTER));
// try {
// Boolean hasSuc = vehicleBiz.unbookVehicle(bookVehicleVo);
// if(!hasSuc){
// throw new BaseException(ResCode.VEHICLE_UNBOOK_FAIL.getDesc(), ResCode.VEHICLE_UNBOOK_FAIL.getCode());
// }
// } catch ( Exception e) {
// log.error(e.getMessage(), e);;
// }
} else {
throw new BaseException(ResCode.VEHICLE_BOOKED_RECORD_MILEAGE_CHANGED.getDesc(),
ResCode.VEHICLE_BOOKED_RECORD_MILEAGE_CHANGED.getCode());
......@@ -322,6 +304,46 @@ public class VehicleActiveService {
vehicleDepartureLogMapper.insertSelective(vehicleDepartureLog);
}
/**
* 如果还车时,还车当天还有其他预定记录,则不释放当天的bookInfo, 如果没有其他记录,则释放当天的bookInfo
* @param vehicleBookRecord
* @return
*/
public boolean unBookArrivalDateTime(VehicleBookRecord vehicleBookRecord) {
Map<String, Object> map = new HashMap<>();
Date startDate = null;
if (vehicleBookRecord.getActualEndDate() == null) {
startDate = vehicleBookRecord.getBookEndDate();
} else {
startDate = vehicleBookRecord.getActualEndDate();
}
DateTime bookStartDate = new DateTime(startDate);
DateTime unBookEndDate = DateTime.now().withMillis(DateUtils.getEndOfDay());
map.put("startTime", bookStartDate.toString(DATE_TIME_FORMATTER));
map.put("endTime", unBookEndDate.toString(DATE_TIME_FORMATTER));
map.put("status", 1);
map.put("vehicleId", vehicleBookRecord.getVehicleId());
log.info("查询还车当天是否有其他预定记录:{}", map);
List<VehicleBookRecordVo> vehicleBookRecords = vehicleBookRecordBiz.selectAllBookRecord(map).getData();
if (vehicleBookRecords == null || vehicleBookRecords.size() <= 0) { //没有记录,取消记录
BookVehicleVO bookVehicleVO = new BookVehicleVO();
bookVehicleVO.setVehicleId(vehicleBookRecord.getVehicleId());
DateTime unBookStartDate = DateTime.now().withMillis(DateUtils.getStartOfDay());
bookVehicleVO.setUnbookStartDate(unBookStartDate.toString(DATE_TIME_FORMATTER));
bookVehicleVO.setUnbookEndDate(unBookEndDate.toString(DATE_TIME_FORMATTER));
log.info("释放还车当天bookInfo: {}", bookVehicleVO);
try {
return vehicleBiz.unbookVehicle(bookVehicleVO);
} catch (Exception e) {
log.info("还车释放当天bookInfo失败");
e.printStackTrace();
}
}
log.info("还车当天有其他预定记录,不释放当天bookInfo, {}", vehicleBookRecords);
return true;
}
//添加出车时间过滤 再出车开始时间前一天至结束时间内可以出车,并且预定记录为已审核状态
public void checkDateInvalid(VehicleDepartureVo arrivalVo) {
if (arrivalVo.getBookRecordId() != null) {
......
......@@ -1516,8 +1516,8 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
return vehicles.stream().map(Vehicle::getId).collect(Collectors.toList());
}
public List<BranchCompanyVehicleCount> getAllVehicleInfo() {
return mapper.getAllVehicleInfo();
public List<BranchCompanyVehicleCountVo> getAllVehicleInfo(Map<String, Object> param) {
return mapper.getAllVehicleInfo(param);
}
}
......@@ -491,12 +491,17 @@ public class VehicleBookRecordBiz extends BaseBiz<VehicleBookRecordMapper, Vehic
}
public ObjectRestResponse<List<VehicleBookRecordVo>> selectAllBookRecord(Map<String, Object> param) {
return ObjectRestResponse.succ(mapper.selectAllBookRecord(param));
}
public ObjectRestResponse<List<VehicleBookRecordVo>> selectAllBookRecord(Date startTime, Date endTime, Integer status) {
Map<String, Object> map = new HashMap<>();
map.put("startTime", startTime);
map.put("endTime", endTime);
map.put("status", status);
return ObjectRestResponse.succ(mapper.selectAllBookRecord(map));
return selectAllBookRecord(map);
}
/**
......
......@@ -4,23 +4,25 @@ import com.alibaba.fastjson.JSON;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Lists;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.entity.Vehicle;
import com.xxfc.platform.vehicle.mapper.VehicleMapper;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo;
import com.xxfc.platform.vehicle.pojo.ResultVehicleVo;
import com.xxfc.platform.vehicle.pojo.VehicleExcelVo;
import com.xxfc.platform.vehicle.pojo.VehiclePageQueryVo;
import com.xxfc.platform.vehicle.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
@Slf4j
......@@ -29,7 +31,11 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
@Autowired
private VehicleBiz vehicleBiz;
@Autowired
private BranchCompanyVehicleCountBiz branchCompanyVehicleCountBiz;
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
public List getByPageNotAllData(VehiclePageQueryVo vehiclePageQueryVo, List<Integer> companyList) throws Exception {
......@@ -94,8 +100,41 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
}
public List<BranchCompanyVehicleCount> getAllVehicleInfo() {
return vehicleBiz.getAllVehicleInfo();
public void getAllVehicleInfo() {
Map<String, Object> map = new HashMap<>();
map.put("startTime", DateTime.now().withMillis(DateUtils.getStartOfDay()).toString(DEFAULT_DATE_TIME_FORMATTER));
map.put("endTime", DateTime.now().withMillis(DateUtils.getEndOfDay()).toString(DEFAULT_DATE_TIME_FORMATTER));
add(map);
}
public void addAll() {
DateTime dateTime = DateTime.parse("2019-10-01 00:00:00", DEFAULT_DATE_TIME_FORMATTER);
DateTime dateTime1 = DateTime.parse("2019-10-01 23:59:59", DEFAULT_DATE_TIME_FORMATTER);
for (int i = 0; i < 52; i++) {
Map<String, Object> map = new HashMap<>();
map.put("startTime", dateTime.plusDays(i).toString(DEFAULT_DATE_TIME_FORMATTER));
map.put("endTime", dateTime1.plusDays(i).toString(DEFAULT_DATE_TIME_FORMATTER));
add(map);
}
}
public void add(Map<String, Object> param) {
List<BranchCompanyVehicleCountVo> branchCompanyVehicleCountVos = vehicleBiz.getAllVehicleInfo(param);
branchCompanyVehicleCountVos.forEach(result->{
try {
if (result != null) {
BranchCompanyVehicleCount branchCompanyVehicleCount = new BranchCompanyVehicleCount();
branchCompanyVehicleCount.setCompanyName(result.getParkBranchCompanyName());
branchCompanyVehicleCount.setVehicleNum(result.getCount());
branchCompanyVehicleCount.setCountDate(DateTime.parse(param.get("startTime").toString().split(" ")[0]).toDate());
branchCompanyVehicleCountBiz.add(branchCompanyVehicleCount);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
}
package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
import java.util.Map;
public interface BranchCompanyVehicleCountMapper extends Mapper<BranchCompanyVehicleCount> {
List<BranchCompanyVehicleCount> getAllByParam(Map<String, Object> param);
}
\ No newline at end of file
......@@ -54,5 +54,5 @@ public interface VehicleMapper extends Mapper<Vehicle> {
@Select("select `id` from `vehicle` where `is_del`=0")
List<String> findExistVehicleIds();
List<BranchCompanyVehicleCount> getAllVehicleInfo();
List<BranchCompanyVehicleCountVo> getAllVehicleInfo(Map<String, Object> params);
}
\ No newline at end of file
package com.xxfc.platform.vehicle.rest.admin;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.vehicle.biz.BranchCompanyVehicleCountBiz;
import com.xxfc.platform.vehicle.common.BaseController;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value = "/bg-vehicle/count")
public class BranchCompanyVehicleCountController extends BaseController<BranchCompanyVehicleCountBiz> {
@GetMapping(value = "/getAll")
@ResponseBody
public ObjectRestResponse getAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
return baseBiz.findAll(branchCompanyVehicleCountDTO);
}
}
......@@ -7,11 +7,15 @@ import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.biz.BranchCompanyVehicleCountBiz;
import com.xxfc.platform.vehicle.biz.VehicleBiz;
import com.xxfc.platform.vehicle.biz.VehicleInformationDownloadBiz;
import com.xxfc.platform.vehicle.common.BaseController;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.pojo.VehicleExcelVo;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -30,7 +34,7 @@ import java.util.List;
public class VehicleInformationDownloadController extends BaseController<VehicleInformationDownloadBiz> {
@Autowired
UserFeign userFeign;
private UserFeign userFeign;
@Autowired
private UserAuthConfig userAuthConfig;
......@@ -39,7 +43,10 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
private VehicleBiz vehicleBiz;
@Autowired
HttpServletResponse response;
private BranchCompanyVehicleCountBiz branchCompanyVehicleCountBiz;
@Autowired
private HttpServletResponse response;
@GetMapping("/excel")
public void downloadExcel(@RequestParam(value = "vehiclePageQueryVoJson", required = false) String vehiclePageQueryVoJson) throws Exception {
......@@ -70,11 +77,17 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
}
@GetMapping("/app/unauth/export")
public void exportVehicleInfo() throws Exception {
List<BranchCompanyVehicleCount> rows = baseBiz.getAllVehicleInfo();
public void exportVehicleInfo(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) throws Exception {
PageDataVO<BranchCompanyVehicleCount> pageDataVO = branchCompanyVehicleCountBiz.findAll(branchCompanyVehicleCountDTO).getData();
if (pageDataVO == null || pageDataVO.getData() == null) {
throw new BaseException(ResultCode.getMsg(ResultCode.NOTEXIST_CODE), ResultCode.NOTEXIST_CODE);
}
List<BranchCompanyVehicleCount> rows = pageDataVO.getData();
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.addHeaderAlias("parkBranchCompanyName", "停靠分公司");
writer.addHeaderAlias("count", "车辆数量");
writer.addHeaderAlias("id", "ID");
writer.addHeaderAlias("countDate", "日期");
writer.addHeaderAlias("companyName", "停靠分公司");
writer.addHeaderAlias("vehicleNum", "车辆数量");
// 一次性写出内容,使用默认样式,强制输出标题
writer.write(rows, true);
//response为HttpServletResponse对象
......@@ -89,4 +102,5 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
}
package com.xxfc.platform.vehicle.util;
import org.joda.time.DateTime;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
......@@ -19,4 +21,43 @@ public class DateUtils {
public static Date localDateToDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
/**
* 获取当天的开始时间
* @return
*/
public static long getStartOfDay() {
return getStartOfDay(new Date());
}
/**
* 获取某天的开始时间
* @param date
* @return
*/
public static long getStartOfDay(Date date) {
DateTime dateTime = new DateTime(date);
DateTime startOfDay = dateTime.withTimeAtStartOfDay();
return startOfDay.getMillis();
}
/**
* 获取当天的结束时间
* @return
*/
public static long getEndOfDay() {
return getEndOfDay(new Date());
}
/**
* 获取某天的结束时间
* @param date
* @return
*/
public static long getEndOfDay(Date date) {
DateTime dateTime = new DateTime(date);
DateTime endOfDay = dateTime.millisOfDay().withMaximumValue();
return endOfDay.getMillis();
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper" >
<resultMap id="BaseResultMap" type="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="BIGINT" />
<result column="company_name" property="companyName" jdbcType="VARCHAR" />
<result column="vehicle_num" property="vehicleNum" jdbcType="INTEGER" />
<result column="count_date" property="countDate" jdbcType="TIMESTAMP" />
<result column="company_id" property="companyId" jdbcType="INTEGER" />
</resultMap>
<select id="getAllByParam" parameterType="Map" resultType="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount">
SELECT company_name, CEILING((
CASE
WHEN #{type} = 1 THEN
sum(vehicle_num) / #{dayNum}
WHEN #{type} = 2 THEN
sum(vehicle_num) / #{dayNum}
WHEN #{type} = 3 THEN
sum(vehicle_num) / #{dayNum}
END
))
AS vehicleNum from branch_company_vehicle_count
<where>
<if test="companyName != null and companyName != ''">
and company_name like concat('%', #{companyName}, '%')
</if>
<if test="startTime != null and startTime != ''">
and count_date &gt; #{startTime} and count_date &lt; #{endTime}
</if>
</where>
GROUP BY company_name
</select>
</mapper>
\ No newline at end of file
......@@ -554,8 +554,13 @@
<if test="startTime != null and status == 2">
and v1.book_end_date between #{startTime} and #{endTime}
</if>
<if test="vehicleId != null and vehicleId != ''">
and v1.vehicle_id = #{vehicleId}
</if>
</select>
<!--获取所有已取消的预定记录-->
<select id="selectAllCancelBookRecord" resultMap="searchBookRecord" parameterType="Map">
select v1.* from vehicle_book_record v1
......
......@@ -591,18 +591,16 @@
</select>
<!--导出分公司停靠所有车辆-->
<select id="getAllVehicleInfo" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCount">
SELECT
b1. NAME AS parkBranchCompanyName,
count(v1.id) as count
FROM
branch_company b1
LEFT JOIN vehicle v1 ON v1.park_branch_company_id = b1.id
WHERE
b1.is_del = 0
AND v1.is_del = 0
GROUP BY b1.`name`
order by b1.`name`
<select id="getAllVehicleInfo" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo" parameterType="Map">
select tmp.name as parkBranchCompanyName, COUNT(0) as count from (
select v1.number_plate, b.name from vehicle_book_record v
LEFT JOIN branch_company b on b.id = v.lift_company
LEFT JOIN vehicle v1 on v1.id = v.vehicle_id
where v.`status` != 4 and v.`status` != 6
and v.book_start_date &gt; #{startTime} and v.book_start_date &lt; #{endTime}
ORDER BY v.vehicle_id, v.book_start_date DESC
) tmp
GROUP BY name
</select>
<select id="lockByCode" resultType="com.xxfc.platform.vehicle.entity.Vehicle"
......@@ -992,7 +990,14 @@
, vbre.ret_company as to_lift_company
, vbrs.lift_company as to_return_company
from
(select vehicle_id, max(if(book_end_date &lt; #{startDateExtend}, book_end_date, null)) as max_book_end_date, min(if(book_start_date &gt; #{endDateExtend}, book_start_date, null)) as min_book_start_date from vehicle_book_record where status != 4 and status != 6 group by vehicle_id) sevbr
<!--
查询开始时间 前面的最后一条 预约记录
查询结束时间 后面的第一条 预约记录
添加比较actual_start_date 和 actual_end_date-->
(select vehicle_id
, max(if(IFNULL(actual_end_date, book_end_date) &lt; #{startDateExtend}, IFNULL(actual_end_date,book_end_date), null)) as max_book_end_date
, min(if(IFNULL(actual_start_date, book_start_date) &gt; #{endDateExtend}, IFNULL(actual_start_date, book_start_date), null)) as min_book_start_date
from vehicle_book_record where status != 4 and status != 6 group by vehicle_id) sevbr
left join vehicle_book_record vbre
on sevbr.vehicle_id = vbre.vehicle_id and sevbr.max_book_end_date = vbre.book_end_date and vbre.status != 4 and vbre.status != 6
left join vehicle_book_record vbrs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment