| @@ -5,31 +5,38 @@ import java.text.ParseException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Date; | |||
| import com.simple.domain.po.MallUserInfo; | |||
| import com.simple.shiro.UserSession; | |||
| import org.apache.shiro.SecurityUtils; | |||
| import org.springframework.web.bind.WebDataBinder; | |||
| import org.springframework.web.bind.annotation.InitBinder; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| @RestController | |||
| public class BaseController { | |||
| @InitBinder | |||
| public void InitBinder(WebDataBinder dataBinder) { | |||
| dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { | |||
| public void setAsText(String value) { | |||
| try { | |||
| setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value)); | |||
| } catch(ParseException e) { | |||
| try { | |||
| setValue(new SimpleDateFormat("yyyy-MM-dd ").parse(value)); | |||
| } catch (ParseException e1) { | |||
| setValue(null); | |||
| } | |||
| } | |||
| } | |||
| public String getAsText() { | |||
| return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) getValue()); | |||
| } | |||
| }); | |||
| } | |||
| @InitBinder | |||
| public void InitBinder(WebDataBinder dataBinder) { | |||
| dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { | |||
| public void setAsText(String value) { | |||
| try { | |||
| setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value)); | |||
| } catch(ParseException e) { | |||
| try { | |||
| setValue(new SimpleDateFormat("yyyy-MM-dd ").parse(value)); | |||
| } catch (ParseException e1) { | |||
| setValue(null); | |||
| } | |||
| } | |||
| } | |||
| public String getAsText() { | |||
| return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) getValue()); | |||
| } | |||
| }); | |||
| } | |||
| public MallUserInfo getUser(){ | |||
| MallUserInfo user = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||
| return user; | |||
| } | |||
| } | |||
| @@ -1,8 +1,9 @@ | |||
| package com.simple.controller; | |||
| import com.simple.domain.dto.WxCouponChannelDto; | |||
| import com.simple.domain.po.MallUserInfo; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.util.Assert; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| @@ -15,6 +16,9 @@ import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @RestController | |||
| @RequestMapping("wxCouponChannel") | |||
| public class WxCouponChannelController extends BaseController | |||
| @@ -22,6 +26,7 @@ public class WxCouponChannelController extends BaseController | |||
| @Autowired | |||
| private WxCouponChannelService wxCouponChannelService; | |||
| private Logger logger = Logger.getLogger(WxCouponChannelController.class); | |||
| @ApiOperation("分页列表接口") | |||
| @@ -66,12 +71,16 @@ public class WxCouponChannelController extends BaseController | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxCouponChannelService.getById(id)); | |||
| } | |||
| /*@ApiOperation("根据") | |||
| @GetMapping("/add") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxCouponChannelService.getById(id)); | |||
| }*/ | |||
| @ApiOperation("批量新增") | |||
| @PostMapping("/addbatch") | |||
| public ResultData findById(@RequestBody WxCouponChannelDto wxCouponChannelDto) { | |||
| String[] ids = wxCouponChannelDto.getCouponIds().split(","); | |||
| List<WxCouponChannel> list = new ArrayList<>(); | |||
| MallUserInfo user = getUser(); | |||
| wxCouponChannelService.addBatch(ids,wxCouponChannelDto.getChannelId(),user.getTenantId()); | |||
| return new ResultData(); | |||
| } | |||
| @@ -60,8 +60,8 @@ public class WxCouponController extends BaseController | |||
| String[] arys = wxCoupon.getBusiness().split(","); | |||
| wxCoupon.setBusiness(JSON.toJSONString(arys)); | |||
| } | |||
| wxCouponService.saveOrUpdate(wxCoupon); | |||
| return new ResultData(); | |||
| Long id = wxCouponService.saveOrUpdate(wxCoupon); | |||
| return new ResultData(id); | |||
| } | |||
| @ApiOperation("根据id更新接口") | |||
| @@ -74,8 +74,8 @@ public class WxCouponController extends BaseController | |||
| String[] arys = wxCoupon.getBusiness().split(","); | |||
| wxCoupon.setBusiness(JSON.toJSONString(arys)); | |||
| } | |||
| wxCouponService.saveOrUpdate(wxCoupon); | |||
| return new ResultData(); | |||
| Long id = wxCouponService.saveOrUpdate(wxCoupon); | |||
| return new ResultData(id); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @@ -0,0 +1,37 @@ | |||
| package com.simple.domain.dto; | |||
| import java.io.Serializable; | |||
| public class WxCouponChannelDto implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| private Long couponId; | |||
| private String couponIds; | |||
| private Integer channelId; | |||
| public Integer getChannelId() { | |||
| return channelId; | |||
| } | |||
| public void setChannelId(Integer channelId) { | |||
| this.channelId = channelId; | |||
| } | |||
| public Long getCouponId() { | |||
| return couponId; | |||
| } | |||
| public void setCouponId(Long couponId) { | |||
| this.couponId = couponId; | |||
| } | |||
| public String getCouponIds() { | |||
| return couponIds; | |||
| } | |||
| public void setCouponIds(String couponIds) { | |||
| this.couponIds = couponIds; | |||
| } | |||
| } | |||
| @@ -1,12 +1,12 @@ | |||
| package com.simple.domain.po; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.*; | |||
| import java.util.*; | |||
| import java.math.*; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import javax.persistence.Id; | |||
| import java.io.Serializable; | |||
| @Table(name = "wx_coupon_channel") | |||
| public class WxCouponChannel implements Serializable { | |||
| @@ -19,6 +19,7 @@ public class WxCouponChannel implements Serializable { | |||
| protected List<String> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| public Long getId() { | |||
| return id; | |||
| @@ -124,7 +125,6 @@ public class WxCouponChannel implements Serializable { | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| @@ -154,7 +154,7 @@ public class WxCouponChannel implements Serializable { | |||
| } | |||
| } | |||
| public void setSortColumns(WxCouponChannel.Field... fields) | |||
| public void setSortColumns(Field... fields) | |||
| { | |||
| if (fields == null || fields.length == 0) { | |||
| return; | |||
| @@ -169,9 +169,9 @@ public class WxCouponChannel implements Serializable { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| @@ -37,6 +37,8 @@ public interface WxCouponChannelService { | |||
| * @param id | |||
| */ | |||
| void deleteById(Long id); | |||
| void addBatch(String[] ids,Integer channelId,String tanantId); | |||
| @@ -29,7 +29,7 @@ public interface WxCouponService { | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxCoupon record); | |||
| Long saveOrUpdate(WxCoupon record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| @@ -3,9 +3,11 @@ package com.simple.service.impl; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.domain.po.WxCoupon; | |||
| import com.simple.domain.po.WxCouponChannel; | |||
| import com.simple.mapper.WxCouponChannelMapper; | |||
| import com.simple.service.WxCouponChannelService; | |||
| import com.simple.service.WxCouponService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.simple.common.IdWorker; | |||
| @@ -15,6 +17,8 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| WxCouponService wxCouponService; | |||
| @Override | |||
| @@ -43,12 +47,32 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { | |||
| public void deleteById(Long id) { | |||
| wxCouponChannelMapper.deleteByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void addBatch(String[] ids,Integer channelId,String tanantId) { | |||
| for (String couponidstr:ids) { | |||
| Long couponid = Long.parseLong(couponidstr); | |||
| addCuponChannel(couponid,channelId,tanantId); | |||
| } | |||
| } | |||
| private void addCuponChannel(Long couponid,Integer channelId,String tanantId){ | |||
| WxCoupon wxCouponUP = new WxCoupon(); | |||
| wxCouponUP.setId(couponid); | |||
| wxCouponUP.setStatus(1); | |||
| wxCouponService.saveOrUpdate(wxCouponUP); | |||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | |||
| wxCouponChannel.setCouponId(couponid); | |||
| wxCouponChannel.setCouponStatus(1); | |||
| wxCouponChannel.setTargetAd(channelId); | |||
| wxCouponChannel.setTenantId(tanantId); | |||
| saveOrUpdate(wxCouponChannel); | |||
| } | |||
| } | |||
| @@ -28,7 +28,7 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxCoupon record) { | |||
| public Long saveOrUpdate(WxCoupon record) { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| @@ -37,6 +37,7 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } else { | |||
| wxCouponMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| return record.getId(); | |||
| } | |||
| @Override | |||