package com.stylefeng.guns.modular.system.controller.general;
|
|
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.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.SinataUtil;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.DateUtil;
|
import com.stylefeng.guns.modular.system.util.RedisUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 控制器
|
*
|
* @author fengshuonan
|
* @Date 2020-06-17 20:51:18
|
*/
|
@Controller
|
@RequestMapping("/activity")
|
public class TActivityController extends BaseController {
|
|
private String PREFIX = "/system/activity/";
|
|
@Autowired
|
private ITActivityService activityService;
|
@Autowired
|
private ITActivityAreaService activityAreaService;
|
@Autowired
|
private ITActivityCouponService activityCouponService;
|
@Autowired
|
private ITRegionService tRegionService;
|
@Autowired
|
private ITBranchOfficeAreaService branchOfficeAreaService;
|
@Autowired
|
private ITBranchOfficeService branchOfficeService;
|
@Autowired
|
private ITCouponService couponService;
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private ITUserToCouponService userToCouponService;
|
/**
|
* 跳转到首页
|
*/
|
@RequestMapping("")
|
public String index(Model model) {
|
// 查询当前帐号的省市区
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
if(roleType == 1){
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("branchOfficeAreaList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
model.addAttribute("branchOfficeAreaList",branchOfficeAreaList);
|
model.addAttribute("roleType",roleType);
|
return PREFIX + "activity.html";
|
}else {
|
TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
|
.eq("branchOfficeId",tBranchOffice.getId()));
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("branchOfficeAreaList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
model.addAttribute("roleType",roleType);
|
model.addAttribute("branchOfficeAreaList",branchOfficeAreaList);
|
return PREFIX + "activity_branchOffice.html";
|
}
|
}
|
|
/**
|
* 跳转到添加
|
*/
|
@RequestMapping("/activity_add")
|
public String activityAdd(Model model) {
|
// 查询当前帐号的省市区
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
if(roleType == 1){
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}else {
|
TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
|
.eq("branchOfficeId",tBranchOffice.getId()));
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}
|
return PREFIX + "activity_add.html";
|
}
|
/**
|
* 跳转到添加
|
*/
|
@RequestMapping("/openAuditDetail/{id}")
|
public String openAuditDetail(@PathVariable Integer id,Model model) {
|
// 查询当前帐号的省市区
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
if(roleType == 1){
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}else {
|
TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
|
.eq("branchOfficeId",tBranchOffice.getId()));
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}
|
model.addAttribute("item",activityService.selectById(id));
|
List<TActivityArea> branchOfficeAreaList = activityAreaService.selectList(new EntityWrapper<TActivityArea>().eq("activityId", id));
|
model.addAttribute("scopeList",branchOfficeAreaList);
|
// 查询优惠券信息
|
List<TActivityCoupon> activityCoupons = activityCouponService.selectList(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
|
List<Integer> couponIds = activityCoupons.stream().map(TActivityCoupon::getCouponId).distinct().collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(couponIds)){
|
List<TCoupon> coupons = couponService.selectList(new EntityWrapper<TCoupon>().in("id", couponIds));
|
for (TCoupon coupon : coupons) {
|
TActivityCoupon tActivityCoupon = activityCoupons.stream().filter(e -> e.getCouponId().equals(coupon.getId())).findFirst().orElse(null);
|
if(Objects.nonNull(tActivityCoupon) && Objects.nonNull(tActivityCoupon.getCreateTime())){
|
coupon.setCreateTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tActivityCoupon.getCreateTime()));
|
}
|
switch (coupon.getCouponType()) {
|
case 1:
|
coupon.setCouponTypeStr("现金券");
|
break;
|
case 2:
|
coupon.setCouponTypeStr("新人券");
|
break;
|
case 3:
|
coupon.setCouponTypeStr("分享券");
|
break;
|
case 4:
|
coupon.setCouponTypeStr("消费优惠券");
|
break;
|
default:
|
coupon.setCouponTypeStr("充值优惠券");
|
break;
|
}
|
switch (coupon.getCouponServiceType()) {
|
case 1:
|
coupon.setCouponServiceTypeStr("通用型");
|
break;
|
default:
|
coupon.setCouponServiceTypeStr("通用型");
|
break;
|
}
|
}
|
model.addAttribute("couponList",coupons);
|
} else {
|
model.addAttribute("couponList",new ArrayList<>());
|
}
|
return PREFIX + "audit_detail.html";
|
}
|
/**
|
* 跳转到添加
|
*/
|
@RequestMapping("/openDetail/{id}")
|
public String openDetail(@PathVariable Integer id,Model model) {
|
// 查询当前帐号的省市区
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
if(roleType == 1){
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}else {
|
TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
|
.eq("branchOfficeId",tBranchOffice.getId()));
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}
|
TActivity tActivity = activityService.selectById(id);
|
|
model.addAttribute("item",tActivity);
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String temp = "";
|
switch (tActivity.getStatus()){
|
case 1:
|
temp = "待审核";
|
break;
|
case 2:
|
temp = "已审核";
|
break;
|
case 3:
|
temp = "已驳回";
|
break;
|
}
|
model.addAttribute("statusString",temp);
|
model.addAttribute("auditTimeString",simpleDateFormat.format(tActivity.getAuditTime()));
|
List<TActivityArea> branchOfficeAreaList = activityAreaService.selectList(new EntityWrapper<TActivityArea>().eq("activityId", id));
|
|
StringBuilder sb = new StringBuilder();
|
for (TActivityArea activityArea : branchOfficeAreaList) {
|
sb.append(activityArea.getProvinceName()+"-"+activityArea.getCityName()+"-"+activityArea.getAreaName()+"、");
|
}
|
model.addAttribute("activityArea",sb.toString());
|
|
model.addAttribute("scopeList",branchOfficeAreaList);
|
// 查询优惠券信息
|
List<TActivityCoupon> activityCoupons = activityCouponService.selectList(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
|
List<Integer> couponIds = activityCoupons.stream().map(TActivityCoupon::getCouponId).distinct().collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(couponIds)){
|
List<TCoupon> coupons = couponService.selectList(new EntityWrapper<TCoupon>().in("id", couponIds));
|
for (TCoupon coupon : coupons) {
|
TActivityCoupon tActivityCoupon = activityCoupons.stream().filter(e -> e.getCouponId().equals(coupon.getId())).findFirst().orElse(null);
|
if(Objects.nonNull(tActivityCoupon) && Objects.nonNull(tActivityCoupon.getCreateTime())){
|
coupon.setCreateTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tActivityCoupon.getCreateTime()));
|
}
|
switch (coupon.getCouponType()) {
|
case 1:
|
coupon.setCouponTypeStr("现金券");
|
break;
|
case 2:
|
coupon.setCouponTypeStr("新人券");
|
break;
|
case 3:
|
coupon.setCouponTypeStr("分享券");
|
break;
|
case 4:
|
coupon.setCouponTypeStr("消费优惠券");
|
break;
|
default:
|
coupon.setCouponTypeStr("充值优惠券");
|
break;
|
}
|
switch (coupon.getCouponServiceType()) {
|
case 1:
|
coupon.setCouponServiceTypeStr("通用型");
|
break;
|
default:
|
coupon.setCouponServiceTypeStr("通用型");
|
break;
|
}
|
}
|
model.addAttribute("couponList",coupons);
|
|
// 查询参与人数,总金额
|
List<TUserToCoupon> userToCoupons = userToCouponService.selectList(new EntityWrapper<TUserToCoupon>().in("couponId", couponIds));
|
int sum = userToCoupons.stream().mapToInt(TUserToCoupon::getCouponTotal).sum();
|
model.addAttribute("joinCount",sum);
|
if(CollectionUtils.isEmpty(userToCoupons)){
|
model.addAttribute("couponMoney",0);
|
}
|
for (TUserToCoupon userToCoupon : userToCoupons) {
|
TCoupon tCoupon = coupons.stream().filter(e -> e.getId().equals(userToCoupon.getCouponId())).findFirst().orElse(null);
|
if(Objects.nonNull(tCoupon)){
|
model.addAttribute("couponMoney",new BigDecimal(userToCoupon.getCouponTotal()).multiply(tCoupon.getCouponPreferentialAmount()));
|
}else {
|
model.addAttribute("couponMoney",0);
|
}
|
}
|
|
} else {
|
model.addAttribute("couponList",new ArrayList<>());
|
model.addAttribute("joinCount",0);
|
model.addAttribute("couponMoney",0);
|
}
|
|
// 查询优惠券点击量,参与人数,领取量
|
String value = redisUtil.getValue("activity_view_count:" + id);
|
if(StringUtils.hasLength(value)){
|
model.addAttribute("readCount",Integer.parseInt(value));
|
}else {
|
model.addAttribute("readCount",0);
|
}
|
|
|
|
|
return PREFIX + "activity_detail.html";
|
}
|
/**
|
* 跳转到选择优惠券页面
|
*/
|
@RequestMapping("/changeCoupon")
|
public String changeCoupon(Model model) {
|
return PREFIX + "tCouponActivity.html";
|
}
|
|
/**
|
* 跳转到修改
|
*/
|
@RequestMapping("/activity_update/{id}")
|
public String activityUpdate(@PathVariable("id") Integer id, Model model) {
|
// 查询当前帐号的省市区
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
if(roleType == 1){
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}else {
|
TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
|
List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
|
.eq("branchOfficeId",tBranchOffice.getId()));
|
if(CollectionUtils.isEmpty(branchOfficeAreaList)){
|
model.addAttribute("provinceList",new ArrayList<>());
|
}
|
branchOfficeAreaList.forEach(item->{
|
item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
|
});
|
model.addAttribute("provinceList",branchOfficeAreaList);
|
}
|
TActivity tActivity = activityService.selectById(id);
|
|
model.addAttribute("item",tActivity);
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String temp = "";
|
switch (tActivity.getStatus()){
|
case 1:
|
temp = "待审核";
|
break;
|
case 2:
|
temp = "已审核";
|
break;
|
case 3:
|
temp = "已驳回";
|
break;
|
}
|
model.addAttribute("statusString",temp);
|
model.addAttribute("auditTimeString",simpleDateFormat.format(tActivity.getAuditTime()));
|
List<TActivityArea> branchOfficeAreaList = activityAreaService.selectList(new EntityWrapper<TActivityArea>().eq("activityId", id));
|
|
StringBuilder sb = new StringBuilder();
|
for (TActivityArea activityArea : branchOfficeAreaList) {
|
sb.append(activityArea.getProvinceName()+"-"+activityArea.getCityName()+"-"+activityArea.getAreaName()+"、");
|
}
|
model.addAttribute("activityArea",sb.toString());
|
|
model.addAttribute("scopeList",branchOfficeAreaList);
|
// 查询优惠券信息
|
List<TActivityCoupon> activityCoupons = activityCouponService.selectList(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
|
List<Integer> couponIds = activityCoupons.stream().map(TActivityCoupon::getCouponId).distinct().collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(couponIds)){
|
List<TCoupon> coupons = couponService.selectList(new EntityWrapper<TCoupon>().in("id", couponIds));
|
for (TCoupon coupon : coupons) {
|
TActivityCoupon tActivityCoupon = activityCoupons.stream().filter(e -> e.getCouponId().equals(coupon.getId())).findFirst().orElse(null);
|
if(Objects.nonNull(tActivityCoupon) && Objects.nonNull(tActivityCoupon.getCreateTime())){
|
coupon.setCreateTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tActivityCoupon.getCreateTime()));
|
}
|
switch (coupon.getCouponType()) {
|
case 1:
|
coupon.setCouponTypeStr("现金券");
|
break;
|
case 2:
|
coupon.setCouponTypeStr("新人券");
|
break;
|
case 3:
|
coupon.setCouponTypeStr("分享券");
|
break;
|
case 4:
|
coupon.setCouponTypeStr("消费优惠券");
|
break;
|
default:
|
coupon.setCouponTypeStr("充值优惠券");
|
break;
|
}
|
switch (coupon.getCouponServiceType()) {
|
case 1:
|
coupon.setCouponServiceTypeStr("通用型");
|
break;
|
default:
|
coupon.setCouponServiceTypeStr("通用型");
|
break;
|
}
|
}
|
model.addAttribute("couponList",coupons);
|
} else {
|
model.addAttribute("couponList",new ArrayList<>());
|
}
|
return PREFIX + "activity_edit.html";
|
}
|
|
/**
|
* 获取列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String createTime,String branchOfficeName,String activityName,
|
String activityAreaCode,Integer status) {
|
ShiroUser user = ShiroKit.getUser();
|
String beginTime = null;
|
String endTime = null;
|
if (SinataUtil.isNotEmpty(createTime)){
|
String[] timeArray = createTime.split(" - ");
|
beginTime = timeArray[0];
|
endTime = timeArray[1];
|
}
|
|
String provinceCode = null;
|
String cityCode = null;
|
String areaCode = null;
|
if(StringUtils.hasLength(activityAreaCode)){
|
String[] split = activityAreaCode.split("-");
|
provinceCode = split[0];
|
cityCode = split[1];
|
areaCode = split[2];
|
}
|
Page<TActivity> page = new PageFactory<TActivity>().defaultPage();
|
List<TActivity> list = activityService.getList(page, beginTime, endTime, branchOfficeName, user.getRoleType(), user.getObjectId(), activityName, provinceCode, cityCode, areaCode, status);
|
for (TActivity tActivity : list) {
|
tActivity.setRoleType(user.getRoleType());
|
}
|
|
page.setRecords(list);
|
return super.packForBT(page);
|
}
|
|
@RequestMapping(value = "/audit")
|
@ResponseBody
|
public Object audit(Integer id,Integer status, String auditRemark) {
|
TActivity activity = activityService.selectById(id);
|
activity.setStatus(status);
|
activity.setAuditRemark(auditRemark);
|
activity.setAuditPeople(ShiroKit.getUser().getName());
|
activity.setAuditTime(new Date());
|
activityService.updateById(activity);
|
return SUCCESS_TIP;
|
}
|
@RequestMapping(value = "/change")
|
@ResponseBody
|
public Object change(@RequestParam Integer code) {
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
List<TBranchOfficeArea> list = new ArrayList<>();
|
if (SinataUtil.isNotEmpty(code)){
|
EntityWrapper<TBranchOfficeArea> wrapper = new EntityWrapper<>();
|
wrapper.eq("provinceCode", code);
|
if(roleType == 2){
|
wrapper.eq("branchOfficeId", objectId);
|
}
|
list = branchOfficeAreaService.selectList(wrapper);
|
}
|
list = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getCityCode))),ArrayList::new));
|
return list;
|
}
|
@RequestMapping(value = "/change1")
|
@ResponseBody
|
public Object change1(@RequestParam Integer code) {
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
List<TBranchOfficeArea> list = new ArrayList<>();
|
if (SinataUtil.isNotEmpty(code)){
|
EntityWrapper<TBranchOfficeArea> wrapper = new EntityWrapper<>();
|
wrapper.eq("cityCode", code);
|
if(roleType == 2){
|
wrapper.eq("branchOfficeId", objectId);
|
}
|
list = branchOfficeAreaService.selectList(wrapper);
|
}
|
list = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getAreaCode))),ArrayList::new));
|
return list;
|
}
|
|
/**
|
* 新增
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TActivity activity,String subArr, String subArr1) {
|
Integer objectId = ShiroKit.getUser().getObjectId();
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
activity.setCompanyId(objectId);
|
activity.setCompanyType(roleType);
|
activity.setCreateTime(new Date());
|
activity.setCreateBy(ShiroKit.getUser().getName());
|
activityService.insert(activity);
|
addActivity(subArr1,activity.getId());
|
addScope(subArr,activity.getId());
|
return SUCCESS_TIP;
|
}
|
|
// 添加优惠券
|
public void addActivity(String subArr,Integer id){
|
JSONArray jsonArray = JSON.parseArray(subArr);
|
activityCouponService.delete(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
|
int size = jsonArray.size();
|
List<TActivityCoupon> activityCoupons = new ArrayList<>();
|
for (int i = 0; i < size; i++){
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
if(Objects.isNull(jsonObject) || jsonObject.size() == 0){
|
continue;
|
}
|
TActivityCoupon activityCoupon = new TActivityCoupon();
|
activityCoupon.setActivityId(id);
|
activityCoupon.setCouponId(jsonObject.getInteger("couponId"));
|
activityCoupon.setCreateTime(new Date());
|
activityCoupons.add(activityCoupon);
|
}
|
activityCouponService.insertBatch(activityCoupons);
|
}
|
|
//添加经营区域
|
public void addScope(String subArr,Integer id){
|
JSONArray jsonArray = JSON.parseArray(subArr);
|
List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>());
|
activityAreaService.delete(new EntityWrapper<TActivityArea>().eq("activityId", id));
|
int size = jsonArray.size();
|
for (int i = 0; i < size; i++){
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
if(Objects.isNull(jsonObject) || jsonObject.size() == 0){
|
continue;
|
}
|
TActivityArea activityArea = activityAreaService.selectOne(new EntityWrapper<TActivityArea>().eq("id", jsonObject.getInteger("recordId")).eq("activityId", id));
|
String provinceCode = jsonObject.getString("provinceCode");
|
String cityCode = jsonObject.getString("cityCode");
|
String areaCode = jsonObject.getString("areaCode");
|
TRegion province = tRegions.stream().filter(e -> e.getCode().equals(provinceCode)).findFirst().get();
|
TRegion city = tRegions.stream().filter(e -> e.getCode().equals(cityCode)).findFirst().get();
|
TRegion area = tRegions.stream().filter(e -> e.getCode().equals(areaCode)).findFirst().get();
|
if (SinataUtil.isEmpty(activityArea)){
|
activityArea = new TActivityArea();
|
activityArea.setProvinceCode(provinceCode);
|
activityArea.setCityCode(cityCode);
|
activityArea.setAreaCode(areaCode);
|
activityArea.setProvinceName(province.getName());
|
activityArea.setCityName(city.getName());
|
activityArea.setAreaName(area.getName());
|
activityArea.setCreateTime(new Date());
|
activityArea.setActivityId(id);
|
activityAreaService.insert(activityArea);
|
}else{
|
activityArea.setProvinceCode(provinceCode);
|
activityArea.setCityCode(cityCode);
|
activityArea.setAreaCode(areaCode);
|
activityArea.setProvinceName(province.getName());
|
activityArea.setCityName(city.getName());
|
activityArea.setAreaName(area.getName());
|
activityArea.setCreateTime(new Date());
|
activityAreaService.updateById(activityArea);
|
}
|
}
|
}
|
|
/**
|
* 删除
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer activityId) {
|
TActivity activity = activityService.selectById(activityId);
|
activity.setIsDelete(1);
|
activityService.updateById(activity);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TActivity activity,String subArr, String subArr1,Integer id) {
|
// Integer objectId = ShiroKit.getUser().getObjectId();
|
// Integer roleType = ShiroKit.getUser().getRoleType();
|
// activity.setCompanyId(objectId);
|
// activity.setCompanyType(roleType);
|
activity.setStatus(1);
|
activityService.updateById(activity);
|
addActivity(subArr1,id);
|
addScope(subArr,id);
|
return SUCCESS_TIP;
|
}
|
@RequestMapping(value = "/updateStatus")
|
@ResponseBody
|
public Object updateStatus(TActivity activity, String subArr,String subArr1) {
|
activityService.updateById(activity);
|
addActivity(subArr1,activity.getId());
|
addScope(subArr,activity.getId());
|
return SUCCESS_TIP;
|
}
|
|
@RequestMapping("/activity_detail/{activityId}")
|
public String activityDetail(@PathVariable Integer activityId, Model model) {
|
TActivity activity = activityService.selectById(activityId);
|
model.addAttribute("item",activity);
|
|
LogObjectHolder.me().set(activity);
|
return PREFIX + "activity_detail.html";
|
}
|
|
/**
|
* 跳转到立即处理页面
|
*/
|
@RequestMapping("/activity_immediately/{id}")
|
public String activityImmediately(@PathVariable Integer id, Model model) {
|
model.addAttribute("id",id);
|
return PREFIX + "activity_immediately.html";
|
}
|
/**
|
* 立即处理操作
|
*/
|
@RequestMapping(value = "/immediately")
|
@ResponseBody
|
public Object immediately(@RequestParam Integer id,@RequestParam Integer state,@RequestParam String remark) {
|
TActivity activity = activityService.selectById(id);
|
if (SinataUtil.isNotEmpty(activity)){
|
activity.setStatus(state);
|
activityService.updateById(activity);
|
}
|
return SUCCESS_TIP;
|
}
|
}
|