Browse Source

上传图片

anderx 3 years ago
parent
commit
a013a31baf

+ 46 - 0
src/main/java/com/goafanti/admin/controller/AdminApiController.java

@@ -15,7 +15,10 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 
+import com.goafanti.ambSystem.service.AmbPaymentService;
+import com.goafanti.order.enums.OrderImgEnums;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.validation.BindingResult;
@@ -183,6 +186,8 @@ public class AdminApiController extends CertifyApiController {
 	private CopyrightInfoService			copyrightInfoService;
 	@Resource
 	private OrgCognizanceProportionService	orgCognizanceProportionService;
+	@Autowired
+	private AmbPaymentService ambPaymentService;
 
 
 
@@ -3070,4 +3075,45 @@ public class AdminApiController extends CertifyApiController {
 		return res;
 	}
 
+
+	/** 图片上传 **/
+	@RequestMapping(value = "/uploadImg", method = RequestMethod.POST)
+	public synchronized Result uploadImg(HttpServletRequest req, String id, String sign){
+		Result res = new Result();
+		if (StringUtils.isBlank(id)){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号","编号"));
+			return  res;
+		}
+		if (sign.equals(OrderImgEnums.AMBPAYMENT.getCode())){
+
+			String imageUrl=uploadFile(res, "/amb_payment/", req,id, sign);
+			Long idL=Long.valueOf(id);
+			ambPaymentService.pushUploadImg(imageUrl,idL);
+			res.setData(imageUrl);
+		}else {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"sign","sign"));
+			return  res;
+		}
+
+		return res;
+	}
+
+	@RequestMapping(value = "/deleteImg", method = RequestMethod.POST)
+	public Result deleteOrderImg(String fileName,String id,String sign){
+		Result res = new Result();
+		if (StringUtils.isBlank(id)){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号","编号"));
+			return  res;
+		}
+		if (sign.equals(OrderImgEnums.AMBPAYMENT.getCode())){
+			deleteFile(res,fileName);
+			Long idL=Long.valueOf(id);
+			res.setData(ambPaymentService.deleteImg(fileName,idL));
+		}else {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"sign","sign"));
+			return  res;
+		}
+
+		return res;
+	}
 }

+ 27 - 0
src/main/java/com/goafanti/ambSystem/bo/InputAmbPayment.java

@@ -16,6 +16,33 @@ public class InputAmbPayment extends AmbPaymentApplication {
     @Param(name="付款金额")
     @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
     private BigDecimal totalAmount;
+    @Param(name="发起阿米巴")
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    private Long initiateAmbId;
+
+    @Param(name="接受阿米巴")
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    private Long acceptAmbId;
+
+    @Override
+    public Long getInitiateAmbId() {
+        return initiateAmbId;
+    }
+
+    @Override
+    public void setInitiateAmbId(Long initiateAmbId) {
+        this.initiateAmbId = initiateAmbId;
+    }
+
+    @Override
+    public Long getAcceptAmbId() {
+        return acceptAmbId;
+    }
+
+    @Override
+    public void setAcceptAmbId(Long acceptAmbId) {
+        this.acceptAmbId = acceptAmbId;
+    }
 
     @Override
     public Integer getType() {

+ 18 - 16
src/main/java/com/goafanti/ambSystem/controller/AmbPaymentApiController.java

@@ -8,6 +8,8 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.utils.ParamUtils;
+import com.goafanti.order.enums.OrderImgEnums;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
@@ -15,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+
 
 @RestController
 @RequestMapping(value = "/api/admin/amb/payment")
@@ -28,22 +32,18 @@ public class AmbPaymentApiController extends CertifyApiController {
 	 * @param bindingResult
 	 * @return
 	 */
-//	@RequestMapping(value="/add",method = RequestMethod.POST)
-//	public Result addAmb(@Validated InputAmbPayment in, BindingResult bindingResult){
-//		Result res =new Result();
-//		if (bindingResult.hasErrors()) {
-//			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
-//					ParamUtils.getParamName(in,bindingResult.getFieldError().getField())));
-//			return res;
-//		}
-//		int i=ambPaymentService.checkAmbPayment(in);
-//		if (i==-1){
-//			res.getError().add(buildError(String.format("[%s]已存在,请确认后再新增",in.getName())));
-//			return res;
-//		}
-//		res.data(ambService.addAmb(in));
-//		return res;
-//	}
+	@RequestMapping(value="/add",method = RequestMethod.POST)
+	public Result add(@Validated InputAmbPayment in, BindingResult bindingResult){
+		Result res =new Result();
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					ParamUtils.getParamName(in,bindingResult.getFieldError().getField())));
+			return res;
+		}
+
+		res.data(ambPaymentService.add(in));
+		return res;
+	}
 //
 //	@RequestMapping(value="/update",method = RequestMethod.POST)
 //	public Result updateAmb( InputAmb in){
@@ -97,4 +97,6 @@ public class AmbPaymentApiController extends CertifyApiController {
 //		return res;
 //	}
 
+
+
 }

+ 6 - 1
src/main/java/com/goafanti/ambSystem/service/AmbPaymentService.java

@@ -3,5 +3,10 @@ package com.goafanti.ambSystem.service;
 import com.goafanti.ambSystem.bo.InputAmbPayment;
 
 public interface AmbPaymentService {
-    int checkAmbPayment(InputAmbPayment in);
+
+    int add(InputAmbPayment in);
+
+    void pushUploadImg(String imageUrl, Long id);
+
+    int deleteImg(String fileName, Long id);
 }

+ 50 - 2
src/main/java/com/goafanti/ambSystem/service/Impl/AmbPaymentServiceImpl.java

@@ -4,10 +4,18 @@ import com.goafanti.ambSystem.bo.InputAmbPayment;
 import com.goafanti.ambSystem.service.AmbPaymentService;
 import com.goafanti.common.dao.AmbPaymentApplicationMapper;
 import com.goafanti.common.dao.AmbSystemMapper;
+import com.goafanti.common.model.AmbPaymentApplication;
 import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.shiro.token.TokenManager;
+import org.apache.commons.lang3.StringUtils;
 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.stream.Collectors;
+
 @Service
 public class AmbPaymentServiceImpl extends BaseMybatisDao<AmbPaymentApplicationMapper> implements AmbPaymentService {
     @Autowired
@@ -15,9 +23,49 @@ public class AmbPaymentServiceImpl extends BaseMybatisDao<AmbPaymentApplicationM
     @Autowired
     private AmbSystemMapper ambSystemMapper;
 
+
+
+    @Override
+    public int add(InputAmbPayment in) {
+        in.setStatus(0);
+        in.setProcessStatus(0);
+        return ambPaymentApplicationMapper.insertSelective(in);
+    }
+
     @Override
-    public int checkAmbPayment(InputAmbPayment in) {
+    public void pushUploadImg(String imageUrl, Long id) {
+        AmbPaymentApplication bo = ambPaymentApplicationMapper.selectByPrimaryKey(id);
+        StringBuffer str=new StringBuffer();
+        if (StringUtils.isNotBlank(bo.getAnnexUrl())){
+            str=str.append(bo.getAnnexUrl()).append(",").append(imageUrl);
+        }else {
+            str=str.append(imageUrl);
+        }
+        AmbPaymentApplication newBo=new AmbPaymentApplication();
+        newBo.setId(bo.getId());
+        newBo.setAnnexUrl(str.substring(0,str.length()-1));
+        ambPaymentApplicationMapper.updateByPrimaryKeySelective(newBo);
+    }
 
-        return 0;
+    @Override
+    public int deleteImg(String fileName, Long id) {
+        AmbPaymentApplication bo = ambPaymentApplicationMapper.selectByPrimaryKey(id);
+        List<String > list=new ArrayList<>();
+        StringBuffer str=new StringBuffer();
+        if (StringUtils.isNotBlank(bo.getAnnexUrl())){
+            String[] ss=bo.getAnnexUrl().split(",");
+            list= Arrays.stream(ss).filter(e ->!e.equals(fileName)).collect(Collectors.toList());
+        }
+        if (list.size()<1){
+            bo.setAnnexUrl("");
+        }else {
+            for (String s : list) {
+                str=str.append(s).append(",");
+            }
+        }
+        AmbPaymentApplication newBo=new AmbPaymentApplication();
+        newBo.setId(bo.getId());
+        newBo.setAnnexUrl(str.substring(0,str.length()-1));
+        return ambPaymentApplicationMapper.updateByPrimaryKeySelective(newBo);
     }
 }

+ 2 - 2
src/main/java/com/goafanti/common/controller/BaseApiController.java

@@ -78,13 +78,13 @@ public class BaseApiController extends BaseController {
 	}
 
 
-	protected String uploadFile(Result res, String path,  HttpServletRequest req,String orderNo, String sign) {
+	protected String uploadFile(Result res, String path,  HttpServletRequest req,String id, String sign) {
 		List<MultipartFile> files = getFiles(req);
 		String fileName = "";
 		if (!files.isEmpty()) {
 			try {
 				MultipartFile mf = files.get(0);
-				fileName = FileUtils.orderFileName(mf,orderNo,path,sign);
+				fileName = FileUtils.orderFileName(mf,id,path,sign);
 				mf.transferTo(toFile(fileName));
 				LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
 			} catch (Exception e) {

+ 35 - 24
src/main/java/com/goafanti/common/mapper/AmbPaymentApplicationMapper.xml

@@ -5,6 +5,8 @@
     <id column="id" jdbcType="BIGINT" property="id" />
     <result column="type" jdbcType="INTEGER" property="type" />
     <result column="total_amount" jdbcType="DECIMAL" property="totalAmount" />
+    <result column="initiate_amb_id" jdbcType="BIGINT" property="initiateAmbId" />
+    <result column="accept_amb_id" jdbcType="BIGINT" property="acceptAmbId" />
     <result column="content" jdbcType="VARCHAR" property="content" />
     <result column="remarks" jdbcType="VARCHAR" property="remarks" />
     <result column="annex_url" jdbcType="VARCHAR" property="annexUrl" />
@@ -14,11 +16,10 @@
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
-    <result column="payment_amb_id" jdbcType="VARCHAR" property="paymentAmbId" />
   </resultMap>
   <sql id="Base_Column_List">
-    id, `type`, total_amount, content, remarks, annex_url, process_status, `status`, 
-    create_by, create_time, update_by, update_time, payment_amb_id
+    id, `type`, total_amount, initiate_amb_id, accept_amb_id, content, remarks, annex_url, 
+    process_status, `status`, create_by, create_time, update_by, update_time
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
     select 
@@ -31,16 +32,16 @@
     where id = #{id,jdbcType=BIGINT}
   </delete>
   <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.AmbPaymentApplication" useGeneratedKeys="true">
-    insert into amb_payment_application (`type`, total_amount, content, 
-      remarks, annex_url, process_status, 
-      `status`, create_by, create_time, 
-      update_by, update_time, payment_amb_id
-      )
-    values (#{type,jdbcType=INTEGER}, #{totalAmount,jdbcType=DECIMAL}, #{content,jdbcType=VARCHAR}, 
-      #{remarks,jdbcType=VARCHAR}, #{annexUrl,jdbcType=VARCHAR}, #{processStatus,jdbcType=INTEGER}, 
-      #{status,jdbcType=INTEGER}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
-      #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{paymentAmbId,jdbcType=VARCHAR}
-      )
+    insert into amb_payment_application (`type`, total_amount, initiate_amb_id, 
+      accept_amb_id, content, remarks, 
+      annex_url, process_status, `status`, 
+      create_by, create_time, update_by, 
+      update_time)
+    values (#{type,jdbcType=INTEGER}, #{totalAmount,jdbcType=DECIMAL}, #{initiateAmbId,jdbcType=BIGINT}, 
+      #{acceptAmbId,jdbcType=BIGINT}, #{content,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, 
+      #{annexUrl,jdbcType=VARCHAR}, #{processStatus,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, 
+      #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, 
+      #{updateTime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.AmbPaymentApplication" useGeneratedKeys="true">
     insert into amb_payment_application
@@ -51,6 +52,12 @@
       <if test="totalAmount != null">
         total_amount,
       </if>
+      <if test="initiateAmbId != null">
+        initiate_amb_id,
+      </if>
+      <if test="acceptAmbId != null">
+        accept_amb_id,
+      </if>
       <if test="content != null">
         content,
       </if>
@@ -78,9 +85,6 @@
       <if test="updateTime != null">
         update_time,
       </if>
-      <if test="paymentAmbId != null">
-        payment_amb_id,
-      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="type != null">
@@ -89,6 +93,12 @@
       <if test="totalAmount != null">
         #{totalAmount,jdbcType=DECIMAL},
       </if>
+      <if test="initiateAmbId != null">
+        #{initiateAmbId,jdbcType=BIGINT},
+      </if>
+      <if test="acceptAmbId != null">
+        #{acceptAmbId,jdbcType=BIGINT},
+      </if>
       <if test="content != null">
         #{content,jdbcType=VARCHAR},
       </if>
@@ -116,9 +126,6 @@
       <if test="updateTime != null">
         #{updateTime,jdbcType=TIMESTAMP},
       </if>
-      <if test="paymentAmbId != null">
-        #{paymentAmbId,jdbcType=VARCHAR},
-      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.AmbPaymentApplication">
@@ -130,6 +137,12 @@
       <if test="totalAmount != null">
         total_amount = #{totalAmount,jdbcType=DECIMAL},
       </if>
+      <if test="initiateAmbId != null">
+        initiate_amb_id = #{initiateAmbId,jdbcType=BIGINT},
+      </if>
+      <if test="acceptAmbId != null">
+        accept_amb_id = #{acceptAmbId,jdbcType=BIGINT},
+      </if>
       <if test="content != null">
         content = #{content,jdbcType=VARCHAR},
       </if>
@@ -157,9 +170,6 @@
       <if test="updateTime != null">
         update_time = #{updateTime,jdbcType=TIMESTAMP},
       </if>
-      <if test="paymentAmbId != null">
-        payment_amb_id = #{paymentAmbId,jdbcType=VARCHAR},
-      </if>
     </set>
     where id = #{id,jdbcType=BIGINT}
   </update>
@@ -167,6 +177,8 @@
     update amb_payment_application
     set `type` = #{type,jdbcType=INTEGER},
       total_amount = #{totalAmount,jdbcType=DECIMAL},
+      initiate_amb_id = #{initiateAmbId,jdbcType=BIGINT},
+      accept_amb_id = #{acceptAmbId,jdbcType=BIGINT},
       content = #{content,jdbcType=VARCHAR},
       remarks = #{remarks,jdbcType=VARCHAR},
       annex_url = #{annexUrl,jdbcType=VARCHAR},
@@ -175,8 +187,7 @@
       create_by = #{createBy,jdbcType=VARCHAR},
       create_time = #{createTime,jdbcType=TIMESTAMP},
       update_by = #{updateBy,jdbcType=VARCHAR},
-      update_time = #{updateTime,jdbcType=TIMESTAMP},
-      payment_amb_id = #{paymentAmbId,jdbcType=VARCHAR}
+      update_time = #{updateTime,jdbcType=TIMESTAMP}
     where id = #{id,jdbcType=BIGINT}
   </update>
 </mapper>

+ 26 - 13
src/main/java/com/goafanti/common/model/AmbPaymentApplication.java

@@ -22,6 +22,16 @@ public class AmbPaymentApplication implements Serializable {
     private BigDecimal totalAmount;
 
     /**
+     * 发起阿米巴
+     */
+    private Long initiateAmbId;
+
+    /**
+     * 接受阿米巴
+     */
+    private Long acceptAmbId;
+
+    /**
      * 内容及说明
      */
     private String content;
@@ -66,11 +76,6 @@ public class AmbPaymentApplication implements Serializable {
      */
     private Date updateTime;
 
-    /**
-     * 付款巴编号
-     */
-    private String paymentAmbId;
-
     private static final long serialVersionUID = 1L;
 
     public Long getId() {
@@ -97,6 +102,22 @@ public class AmbPaymentApplication implements Serializable {
         this.totalAmount = totalAmount;
     }
 
+    public Long getInitiateAmbId() {
+        return initiateAmbId;
+    }
+
+    public void setInitiateAmbId(Long initiateAmbId) {
+        this.initiateAmbId = initiateAmbId;
+    }
+
+    public Long getAcceptAmbId() {
+        return acceptAmbId;
+    }
+
+    public void setAcceptAmbId(Long acceptAmbId) {
+        this.acceptAmbId = acceptAmbId;
+    }
+
     public String getContent() {
         return content;
     }
@@ -168,12 +189,4 @@ public class AmbPaymentApplication implements Serializable {
     public void setUpdateTime(Date updateTime) {
         this.updateTime = updateTime;
     }
-
-    public String getPaymentAmbId() {
-        return paymentAmbId;
-    }
-
-    public void setPaymentAmbId(String paymentAmbId) {
-        this.paymentAmbId = paymentAmbId;
-    }
 }

+ 8 - 2
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -162,9 +162,15 @@ public class FileUtils {
 	 * @param path
 	 * @return
 	 */
-	public static String orderFileName(MultipartFile mf, String orderNo, String path,String sign) {
+	public static String orderFileName(MultipartFile mf, String id, String path,String sign) {
 		String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
-		String fileName =  path + orderNo + "/" + System.nanoTime()+"_"+sign + suffix;
+		String fileName =  path + id + "/" + System.nanoTime()+"_"+sign + suffix;
+		return fileName;
+	}
+
+	public static String orderFileName(MultipartFile mf, String path,String sign) {
+		String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
+		String fileName =  path + sign + "/" + System.nanoTime()+"_"+sign + suffix;
 		return fileName;
 	}
 

+ 4 - 1
src/main/java/com/goafanti/order/enums/OrderImgEnums.java

@@ -9,7 +9,10 @@ public enum OrderImgEnums {
     /** 补充协议*/
     SUPPLEMENT("supplement","补充协议"),
     /** 服务内容*/
-    CONTENT("content","服务内容");
+    CONTENT("content","服务内容"),
+    /** 阿米巴付款*/
+    AMBPAYMENT("amb_payment","阿米巴付款"),
+    NOT("not","未知");
 
     private OrderImgEnums(String code, String desc){
         this.code=code;