| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.common.constant.factory.PageFactory; |
| | | import com.stylefeng.guns.core.log.LogObjectHolder; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.shiro.ShiroUser; |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.core.util.SinataUtil; |
| | | import com.stylefeng.guns.modular.system.model.SysCouponActivity; |
| | | import com.stylefeng.guns.modular.system.model.SysCouponRecord; |
| | | import com.stylefeng.guns.modular.system.model.TUser; |
| | | import com.stylefeng.guns.modular.system.model.UserCouponRecord; |
| | | import com.stylefeng.guns.modular.system.service.ISysCouponActivityService; |
| | | import com.stylefeng.guns.modular.system.service.ISysCouponRecordService; |
| | | import com.stylefeng.guns.modular.system.service.ITUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import com.stylefeng.guns.core.log.LogObjectHolder; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import com.stylefeng.guns.modular.system.model.SysCouponActivity; |
| | | import com.stylefeng.guns.modular.system.service.ISysCouponActivityService; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | } |
| | | return SUCCESS_TIP; |
| | | } |
| | | class timerTaskTest extends TimerTask { |
| | | private Integer id; |
| | | |
| | | public timerTaskTest(Integer id) { |
| | | this.id = id; |
| | | } |
| | | @Override |
| | | public void run() { |
| | | SysCouponActivity sysCouponActivity = sysCouponActivityService.selectById(id); |
| | | UserCouponRecord userCouponRecord = new UserCouponRecord(); |
| | | userCouponRecord.setMoney(sysCouponActivity.getMoney()); |
| | | userCouponRecord.setFullMoney(sysCouponActivity.getFullMoney()); |
| | | Date nowDay = new Date(); |
| | | userCouponRecord.setInsertTime(nowDay); |
| | | userCouponRecord.setExpirationTime(new Date(nowDay.getTime()+sysCouponActivity.getEffective()*24*3600*1000L)); |
| | | userCouponRecord.setCompanyId(sysCouponActivity.getCompanyId()); |
| | | userCouponRecord.setState(1); |
| | | userCouponRecord.setCouponType(sysCouponActivity.getCouponType()); |
| | | userCouponRecord.setCouponUseType(sysCouponActivity.getCouponUseType()); |
| | | userCouponRecord.setCouponActivityId(sysCouponActivity.getId()); |
| | | userCouponRecord.setActivityType(1); |
| | | //判断发送类型1=全部用户,2=选择用户 |
| | | if(sysCouponActivity.getSendType()==1){ |
| | | Wrapper wrapper = new EntityWrapper<TUser>(); |
| | | if(sysCouponActivity.getCompanyType()!=1){ |
| | | wrapper.eq("companyId",sysCouponActivity.getCompanyId()); |
| | | } |
| | | List<TUser> list = userService.selectList(wrapper); |
| | | for(TUser user:list){ |
| | | userCouponRecord.setUserId(user.getId()); |
| | | for (int i=0;i<sysCouponActivity.getNumber();i++){ |
| | | userCouponRecord.insert(); |
| | | } |
| | | } |
| | | sysCouponActivity.setSendUserNum(list.size()); |
| | | sysCouponActivity.updateById(); |
| | | }else{ |
| | | JSONArray userId = JSON.parseArray(sysCouponActivity.getSendUserId()); |
| | | for(int j=0;j<userId.size();j++){ |
| | | userCouponRecord.setUserId(userId.getJSONObject(j).getInteger("userId")); |
| | | for (int i=0;i<sysCouponActivity.getNumber();i++){ |
| | | userCouponRecord.insert(); |
| | | } |
| | | } |
| | | sysCouponActivity.setSendUserNum(userId.size()); |
| | | sysCouponActivity.updateById(); |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | /** |
| | | * 删除 |
| | | */ |
| | |
| | | public Object detail(@PathVariable("sysCouponActivityId") Integer sysCouponActivityId) { |
| | | return sysCouponActivityService.selectById(sysCouponActivityId); |
| | | } |
| | | |
| | | class timerTaskTest extends TimerTask { |
| | | private Integer id; |
| | | |
| | | public timerTaskTest(Integer id) { |
| | | this.id = id; |
| | | } |
| | | @Override |
| | | public void run() { |
| | | SysCouponActivity sysCouponActivity = sysCouponActivityService.selectById(id); |
| | | UserCouponRecord userCouponRecord = new UserCouponRecord(); |
| | | userCouponRecord.setMoney(sysCouponActivity.getMoney()); |
| | | userCouponRecord.setFullMoney(sysCouponActivity.getFullMoney()); |
| | | Date nowDay = new Date(); |
| | | userCouponRecord.setInsertTime(nowDay); |
| | | userCouponRecord.setExpirationTime(new Date(nowDay.getTime()+sysCouponActivity.getEffective()*24*3600*1000L)); |
| | | userCouponRecord.setCompanyId(sysCouponActivity.getCompanyId()); |
| | | userCouponRecord.setState(1); |
| | | userCouponRecord.setCouponType(sysCouponActivity.getCouponType()); |
| | | userCouponRecord.setCouponUseType(sysCouponActivity.getCouponUseType()); |
| | | userCouponRecord.setCouponActivityId(sysCouponActivity.getId()); |
| | | userCouponRecord.setCouponId(sysCouponActivity.getCouponId()); |
| | | userCouponRecord.setActivityType(1); |
| | | //判断发送类型1=全部用户,2=选择用户 |
| | | if(sysCouponActivity.getSendType()==1){ |
| | | Wrapper wrapper = new EntityWrapper<TUser>(); |
| | | if(sysCouponActivity.getCompanyType()!=1){ |
| | | wrapper.eq("companyId",sysCouponActivity.getCompanyId()); |
| | | } |
| | | List<TUser> list = userService.selectList(wrapper); |
| | | for(TUser user:list){ |
| | | userCouponRecord.setUserId(user.getId()); |
| | | for (int i=0;i<sysCouponActivity.getNumber();i++){ |
| | | userCouponRecord.insert(); |
| | | } |
| | | } |
| | | sysCouponActivity.setSendUserNum(list.size()); |
| | | sysCouponActivity.updateById(); |
| | | }else{ |
| | | JSONArray userId = JSON.parseArray(sysCouponActivity.getSendUserId()); |
| | | for(int j=0;j<userId.size();j++){ |
| | | userCouponRecord.setUserId(userId.getJSONObject(j).getInteger("userId")); |
| | | for (int i=0;i<sysCouponActivity.getNumber();i++){ |
| | | userCouponRecord.insert(); |
| | | } |
| | | } |
| | | sysCouponActivity.setSendUserNum(userId.size()); |
| | | sysCouponActivity.updateById(); |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |