Commit 654ba2a0 authored by youjj's avatar youjj

公司股权购买申请参数方式修改,股权信息添加图片

parent fd98a01e
......@@ -3,7 +3,9 @@ package com.xinxincaravan.caravan.vehicle.biz;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.xinxincaravan.caravan.vehicle.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.constant.BranchCompanyStockApplyState;
import com.xinxincaravan.caravan.vehicle.constant.RedisKey;
import com.xinxincaravan.caravan.vehicle.constant.ResCode.ResCode;
import com.xinxincaravan.caravan.vehicle.entity.BranchCompanyStockApplyInfo;
import com.xinxincaravan.caravan.vehicle.entity.BranchCompanyStockInfo;
......@@ -14,17 +16,36 @@ import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyStockApplyInfoVo;
import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyStockApplyVo;
import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyStockInfoVo;
import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyStockSearchVo;
import org.apache.commons.io.FileUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
public class BranchCompanyStockService {
public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
public static final DateTimeFormatter YEARMONTH_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM");
@Value("${branchCompanyStockPic.baseUploadPath:/data/branchCompanyStock/upload/}")
private String baseUploadPath;
@Autowired
private RedisTemplate customRedisTemplate;
@Autowired
BranchCompanyStockInfoMapper branchCompanyStockInfoMapper;
......@@ -169,4 +190,27 @@ public class BranchCompanyStockService {
public void deleteApply(Integer id) {
branchCompanyStockApplyInfoMapper.deleteByPrimaryKey(id);
}
/**
* 写入上传文件,返回相对路径
* @param file
* @return
*/
public RestResponse<String> uploadCompanyPic(MultipartFile file) throws Exception{
//创建本日存放目录
DateTime now = DateTime.now();
String dirPathToday = File.separator + now.toString(DEFAULT_DATE_TIME_FORMATTER);
String redisNoKey = RedisKey.UPLOAD_FILE_NO_PREFIX + now.toString(DEFAULT_DATE_TIME_FORMATTER);
Long no = customRedisTemplate.opsForValue().increment(redisNoKey);
if(no.equals(1l)){
customRedisTemplate.expire(redisNoKey,1, TimeUnit.DAYS);
}
String fileName = file.getOriginalFilename();
String realFileRelPath = dirPathToday + File.separator + no + fileName.substring(fileName.lastIndexOf("."));
//文件存放路径
String filePath = baseUploadPath + realFileRelPath;
//将文件写入指定位置
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
return RestResponse.suc(realFileRelPath);
}
}
......@@ -38,4 +38,6 @@ public class BranchCompanyStockInfo {
private Integer addrCity;
private Integer state;
private Integer companyPic;
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyStockInfoVo;
import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyStockSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@RestController
@IgnoreClientToken
......@@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("branchCompany/stock")
public class BranchCompanyStockController {
private static Integer MAX_DRIVING_LICENSE_SIZE = 10*1024*1024;//10M
@Autowired
BranchCompanyStockService branchCompanyStockService;
......@@ -95,13 +98,26 @@ public class BranchCompanyStockController {
return RestResponse.suc();
}
@RequestMapping(value ="/upload/companyPic",method = RequestMethod.POST)
public RestResponse uploadCompanyPic(@RequestParam("file") MultipartFile file)
throws Exception{
String contentType = file.getContentType(); //图片文件类型
if(!contentType.equals("image/jpeg") && !contentType.equals("image/gif")){
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
if(file.getSize() > MAX_DRIVING_LICENSE_SIZE){
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
return branchCompanyStockService.uploadCompanyPic(file);
}
/**
* 申请购买
* @param applyVo
* @return
*/
@PostMapping("apply")
public RestResponse apply(BranchCompanyStockApplyVo applyVo) {
public RestResponse apply(@RequestBody BranchCompanyStockApplyVo applyVo) {
if (applyVo.getCompanyId() == null || applyVo.getName() == null || applyVo.getTel() == null || applyVo.getCount() == null) {
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
......
......@@ -16,7 +16,6 @@ public class BranchCompanyStockInfoVo {
BigDecimal price;
Integer addrProvince;
Integer addrCity;
// String addrStrProvince;
// String addrStrCity;
Integer state;
String companyPic;
}
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