anderx пре 7 година
родитељ
комит
622dcdbc6b

+ 43 - 0
src/main/java/com/goafanti/common/mapper/JtVoucherDetailMapper.xml

@@ -300,4 +300,47 @@
       status = #{status,jdbcType=INTEGER}
     where id = #{id,jdbcType=VARCHAR}
   </update>
+  <select id="selectVoucherDetailList" resultType="com.goafanti.voucher.bo.JtVoucherDetailListBo">
+  	select b.id,a.name,a.money,b.receive_time as receiveTime, a.duration_day as durationDay,
+		a.source,b.status,b.use_time as useTime,c.mobile as userMobile
+		from jt_voucher a 
+		left join jt_voucher_detail b on a.id=b.voucher_id
+		left join user c on b.use_uid=c.id
+		where 1=1
+	<if test="name != null">
+		and  a.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
+	</if>  
+	<if test="status != null">
+		and  b.status  = #{status,jdbcType=INTEGER}
+	</if>
+	<if test="userMobile != null">
+		and  c.mobile = #{userMobile,jdbcType=VARCHAR}
+	</if>
+	<if test="source != null">
+		and  a.source = #{source,jdbcType=INTEGER}
+	</if>
+	order by name
+  	<if test="page_sql!=null">
+		${page_sql}
+	</if>
+  </select>
+  
+  <select id="selectVoucherDetailCount" resultType="java.lang.Integer">
+  	 select	count(*) from jt_voucher a 
+	left join jt_voucher_detail b on a.id=b.voucher_id
+	left join user c on b.use_uid=c.id
+	where 1=1
+	<if test="name != null">
+		and  a.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
+	</if>  
+	<if test="status != null">
+		and  b.status  = #{status,jdbcType=INTEGER}
+	</if>
+	<if test="userMobile != null">
+		and  c.mobile = #{userMobile,jdbcType=VARCHAR}
+	</if>
+	<if test="source != null">
+		and  a.source = #{source,jdbcType=INTEGER}
+	</if>
+  </select>
 </mapper>

+ 1 - 1
src/main/java/com/goafanti/common/mapper/JtVoucherMapper.xml

@@ -365,7 +365,7 @@
 		and  activeState = #{activeState,jdbcType=INTEGER}
 	</if>
 	<if test="source != null">
-		and  source = #{name,jdbcType=INTEGER}
+		and  source = #{source,jdbcType=INTEGER}
 	</if>
 	order by name
   	<if test="page_sql!=null">

+ 7 - 0
src/main/java/com/goafanti/common/utils/DateUtils.java

@@ -455,5 +455,12 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
 		setMidnight(c);
 		return c.getTime();
 	}
+	public static Date getDateAdd(Date date,int a){
+		Calendar ca = Calendar.getInstance();
+		ca.setTime(date);
+		ca.add(Calendar.DATE, a);
+		return ca.getTime();
+		
+	}
 
 }

+ 48 - 30
src/main/java/com/goafanti/voucher/bo/JtVoucherDetailListBo.java

@@ -1,15 +1,50 @@
 package com.goafanti.voucher.bo;
 
+import java.util.Date;
+
 public class JtVoucherDetailListBo {
 		private String id;
 		private String name;
-		private String source;
 		private String money;
-		private String durationDay;
-		private String activeState;
-		private String grantingUid;
-		private String limitUse;
-		private String limitProjectId;
+		private String source;
+		private Date receiveTime;
+		private String starTime;
+		private String endTime;
+		private String status;
+		private String useTime;
+		private String userMobile;
+		private Integer durationDay;
+		
+		public Date getReceiveTime() {
+			return receiveTime;
+		}
+		public void setReceiveTime(Date receiveTime) {
+			this.receiveTime = receiveTime;
+		}
+		public String getEndTime() {
+			return endTime;
+		}
+		public void setEndTime(String endTime) {
+			this.endTime = endTime;
+		}
+		public String getStatus() {
+			return status;
+		}
+		public void setStatus(String status) {
+			this.status = status;
+		}
+		public String getUseTime() {
+			return useTime;
+		}
+		public void setUseTime(String useTime) {
+			this.useTime = useTime;
+		}
+		public String getUserMobile() {
+			return userMobile;
+		}
+		public void setUserMobile(String userMobile) {
+			this.userMobile = userMobile;
+		}
 		public String getId() {
 			return id;
 		}
@@ -34,35 +69,18 @@ public class JtVoucherDetailListBo {
 		public void setMoney(String money) {
 			this.money = money;
 		}
-		public String getDurationDay() {
+		public Integer getDurationDay() {
 			return durationDay;
 		}
-		public void setDurationDay(String durationDay) {
+		public void setDurationDay(Integer durationDay) {
 			this.durationDay = durationDay;
 		}
-		public String getActiveState() {
-			return activeState;
-		}
-		public void setActiveState(String activeState) {
-			this.activeState = activeState;
-		}
-		public String getGrantingUid() {
-			return grantingUid;
-		}
-		public void setGrantingUid(String grantingUid) {
-			this.grantingUid = grantingUid;
-		}
-		public String getLimitUse() {
-			return limitUse;
-		}
-		public void setLimitUse(String limitUse) {
-			this.limitUse = limitUse;
-		}
-		public String getLimitProjectId() {
-			return limitProjectId;
+		public String getStarTime() {
+			return starTime;
 		}
-		public void setLimitProjectId(String limitProjectId) {
-			this.limitProjectId = limitProjectId;
+		public void setStarTime(String starTime) {
+			this.starTime = starTime;
 		}
+	
 		
 }

+ 2 - 8
src/main/java/com/goafanti/voucher/controller/AdminVoucherController.java

@@ -18,8 +18,7 @@ import com.goafanti.voucher.service.VoucherService;
 public class AdminVoucherController extends CertifyApiController {
 	 @Resource
 	 private VoucherService		voucherService;
-	 @Resource
-	private VoucherDetailService voucherDetailService;
+	
 
 	 
 	 
@@ -65,12 +64,7 @@ public class AdminVoucherController extends CertifyApiController {
 		 return result;
 	 }
 	 
-	 @RequestMapping(value = "/selectDetailList" ,method=RequestMethod.GET)
-	 public Result selectVoucherDetailList(String name,Integer status,String userMobile,Integer source,Integer pageNo,Integer pageSize){
-		 Result result=new Result();
-		 result.data(voucherDetailService.selectVoucherDetailList(name, status, userMobile,source, pageNo, pageSize));
-		 return result;
-	 }
+	
 	 
 
 

+ 86 - 0
src/main/java/com/goafanti/voucher/controller/AdminVoucherDetailController.java

@@ -0,0 +1,86 @@
+package com.goafanti.voucher.controller;
+
+import javax.annotation.Resource;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.ErrorConstants;
+import com.goafanti.common.controller.CertifyApiController;
+import com.goafanti.common.model.JtVoucher;
+import com.goafanti.common.model.JtVoucherDetail;
+import com.goafanti.common.utils.StringUtils;
+import com.goafanti.voucher.service.VoucherDetailService;
+import com.goafanti.voucher.service.VoucherService;
+
+@RestController
+@RequestMapping(value = "/open/api/admin/voucherDetail")
+public class AdminVoucherDetailController extends CertifyApiController {
+	
+	 @Resource
+	private VoucherDetailService voucherDetailService;
+
+	 
+	 
+	 @RequestMapping(value = "/save" ,method=RequestMethod.POST)
+	 public Result saveVoucher(JtVoucherDetail voucher ){
+		 Result result=new Result();
+		 chack(voucher, result);
+		 if (!result.getError().isEmpty()) {
+			 return result;	
+		}
+		 result.data(voucherDetailService.saveVoucherDetail(voucher));
+		 return result;
+	 }
+	 @RequestMapping(value = "/update" ,method=RequestMethod.POST)
+	 public Result updateVoucher(JtVoucherDetail voucher ){
+		 Result result=new Result();
+		 chack(voucher, result);
+		 if (!result.getError().isEmpty()) {
+			 return result;	
+		}
+		result.data(voucherDetailService.updateVoucherDetail(voucher));
+		 return result;
+	 }
+	 @RequestMapping(value = "/delect" ,method=RequestMethod.POST)
+	 public Result delectVoucher(String  id ){
+		 Result result=new Result();
+		 result.data(voucherDetailService.delectVoucherDetail(id));
+		 return result;
+	 }
+	 @RequestMapping(value = "/select" ,method=RequestMethod.GET)
+	 public Result selectVoucher(String  id ){
+		 Result result=new Result();
+		 result.data(voucherDetailService.selectVoucherDetail(id));
+		 return result;
+	 }
+	
+	 
+	 @RequestMapping(value = "/selectList" ,method=RequestMethod.GET)
+	 public Result selectVoucherDetailList(String name,Integer status,String userMobile,Integer source,Integer pageNo,Integer pageSize){
+		 Result result=new Result();
+		 result.data(voucherDetailService.selectVoucherDetailList(name, status, userMobile,source, pageNo, pageSize));
+		 return result;
+	 }
+	 
+
+
+
+	private Result chack(JtVoucherDetail voucher, Result result) {
+		
+		if(StringUtils.isBlank(voucher.getVoucherId())) {
+	    		result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"抵用券规则","抵用券规则"));return result;
+	    	}
+		 if(voucher.getUseUid()==null) {
+	    		result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"用户","用户"));return result;
+	    	}
+	    
+	    if(voucher.getStatus()==null) {
+	    		result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"状态","状态"));return result;
+	    	}
+	    
+    
+	    return result;
+	}
+}

+ 1 - 1
src/main/java/com/goafanti/voucher/service/VoucherDetailService.java

@@ -12,7 +12,7 @@ public interface VoucherDetailService {
 	
 	int delectVoucherDetail(String id);
 	
-	JtVoucher selectVoucherDetail(String id);
+	JtVoucherDetail selectVoucherDetail(String id);
 	
 	Pagination<JtVoucherDetailListBo> selectVoucherDetailList(String name,Integer limitUse,String userMobile,Integer source,Integer pageNo,Integer pageSize);
 	

+ 32 - 12
src/main/java/com/goafanti/voucher/service/impl/VoucherDetailServiceImpl.java

@@ -2,17 +2,24 @@ package com.goafanti.voucher.service.impl;
 
 
 
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.JtVoucherDetailMapper;
 
-import com.goafanti.common.model.JtVoucher;
 import com.goafanti.common.model.JtVoucherDetail;
+import com.goafanti.common.utils.DateUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.voucher.bo.JtVoucherDetailListBo;
-import com.goafanti.voucher.bo.JtVoucherListBo;
 import com.goafanti.voucher.service.VoucherDetailService;
 @Service
 public class VoucherDetailServiceImpl extends BaseMybatisDao<JtVoucherDetailMapper> implements VoucherDetailService {
@@ -27,28 +34,41 @@ public class VoucherDetailServiceImpl extends BaseMybatisDao<JtVoucherDetailMapp
 
 	@Override
 	public int updateVoucherDetail(JtVoucherDetail voucher) {
-		// TODO Auto-generated method stub
-		return 0;
+		return jtVoucherDetailMapper.updateByPrimaryKeySelective(voucher);
 	}
 
 	@Override
 	public int delectVoucherDetail(String id) {
-		// TODO Auto-generated method stub
-		return 0;
+		return jtVoucherDetailMapper.deleteByPrimaryKey(id);
 	}
 
 	@Override
-	public JtVoucher selectVoucherDetail(String id) {
-		// TODO Auto-generated method stub
-		return null;
+	public JtVoucherDetail selectVoucherDetail(String id) {
+		return jtVoucherDetailMapper.selectByPrimaryKey(id);
 	}
 
 	
+	@SuppressWarnings("unchecked")
 	@Override
-	public Pagination<JtVoucherDetailListBo> selectVoucherDetailList(String name, Integer limitUse, String userMobile,
+	public Pagination<JtVoucherDetailListBo> selectVoucherDetailList(String name, Integer status, String userMobile,
 			Integer source, Integer pageNo, Integer pageSize) {
-		// TODO Auto-generated method stub
-		return null;
+		Map<String,Object> params = new HashMap<>();
+		if (pageNo==null||pageNo<1) pageNo=1;
+		if (pageSize==null||pageSize<1) pageSize=10;
+		if (StringUtils.isNotBlank(name)) params.put("name", name);
+		if (null != status) params.put("status", status);
+		if (null != userMobile) params.put("userMobile", userMobile);
+		if (null != source) params.put("source", source);
+		Pagination<JtVoucherDetailListBo> pagination=	(Pagination<JtVoucherDetailListBo>) findPage("selectVoucherDetailList", "selectVoucherDetailCount",params,
+						pageNo, pageSize);
+		List<JtVoucherDetailListBo> list=(List<JtVoucherDetailListBo>) pagination.getList();
+		for (JtVoucherDetailListBo b : list) {
+			if (b!=null&&b.getDurationDay()!=null&&b.getReceiveTime()!=null&&b.getDurationDay()!=null) {
+				b.setStarTime(DateFormatUtils.format(b.getReceiveTime(), AFTConstants.YYYYMMDDHHMMSS));
+				b.setEndTime(DateFormatUtils.format(DateUtils.getDateAdd(b.getReceiveTime(),b.getDurationDay()), AFTConstants.YYYYMMDDHHMMSS));
+			}
+		}
+				return pagination;
 	}
 
 	

+ 1 - 1
src/main/java/com/goafanti/voucher/service/impl/VoucherServiceImpl.java

@@ -53,7 +53,7 @@ public class VoucherServiceImpl extends BaseMybatisDao<JtVoucherMapper> implemen
 		if (StringUtils.isNotBlank(name)) params.put("name", name);
 		if (null != limitUse) params.put("limitUse", limitUse);
 		if (null != activeState) params.put("activeState", activeState);
-		if (null != source) params.put("category", source);
+		if (null != source) params.put("source", source);
 		return (Pagination<JtVoucherListBo>) findPage("selectVoucherList", "selectVoucherCount",params,
 				pageNo, pageSize);
 	}