package com.stylefeng.guns.modular.system.controller.general; 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.shiro.ShiroKit; import com.stylefeng.guns.core.util.DateUtil; import com.stylefeng.guns.core.util.SinataUtil; import com.stylefeng.guns.modular.system.model.TRegion; import com.stylefeng.guns.modular.system.service.ITRegionService; 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.RequestParam; import com.stylefeng.guns.modular.system.model.TAdvertisement; import com.stylefeng.guns.modular.system.service.ITAdvertisementService; import java.util.Date; import java.util.List; import java.util.Map; /** * 广告设置控制器 * * @author fengshuonan * @Date 2020-06-02 09:36:03 */ @Controller @RequestMapping("/tAdvertisement") public class TAdvertisementController extends BaseController { private String PREFIX = "/system/tAdvertisement/"; @Autowired private ITAdvertisementService tAdvertisementService; @Autowired private ITRegionService tRegionService; /** * 跳转到广告设置首页 */ @RequestMapping("") public String index() { return PREFIX + "tAdvertisement.html"; } /** * 跳转到添加广告设置 */ @RequestMapping("/tAdvertisement_add") public String tAdvertisementAdd(Model model) { List list = tRegionService.selectList(new EntityWrapper().eq("parent_id", 0)); model.addAttribute("list",list); return PREFIX + "tAdvertisement_add.html"; } /** * 跳转到修改广告设置 */ @RequestMapping("/tAdvertisement_update/{tAdvertisementId}") public String tAdvertisementUpdate(@PathVariable Integer tAdvertisementId, Model model) { TAdvertisement tAdvertisement = tAdvertisementService.selectById(tAdvertisementId); model.addAttribute("item",tAdvertisement); LogObjectHolder.me().set(tAdvertisement); List list = tRegionService.selectList(new EntityWrapper().eq("parent_id", 0)); model.addAttribute("list",list); return PREFIX + "tAdvertisement_edit.html"; } /** * 获取广告设置列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String insertTime, String name, Integer type) { String beginTime = null; String endTime = null; if (SinataUtil.isNotEmpty(insertTime)){ String[] timeArray = insertTime.split(" - "); beginTime = timeArray[0]; endTime = timeArray[1]; } Page> page = new PageFactory>().defaultPage(); page.setRecords(tAdvertisementService.getAdvertisementList(page,beginTime,endTime,type,name)); return super.packForBT(page); } /** * 新增广告设置 */ @RequestMapping(value = "/add") @ResponseBody public Object add(TAdvertisement tAdvertisement) { tAdvertisement.setInsertTime(new Date()); tAdvertisement.setInsertUser(ShiroKit.getUser().getId()); tAdvertisementService.insert(tAdvertisement); return SUCCESS_TIP; } /** * 删除广告设置 */ @RequestMapping(value = "/delete") @ResponseBody public Object delete(@RequestParam Integer tAdvertisementId) { tAdvertisementService.deleteById(tAdvertisementId); return SUCCESS_TIP; } /** * 操作广告设置 */ @RequestMapping(value = "/opt") @ResponseBody public Object opt(@RequestParam Integer tAdvertisementId,@RequestParam Integer optType) { TAdvertisement tAdvertisement = tAdvertisementService.selectById(tAdvertisementId); if (SinataUtil.isNotEmpty(tAdvertisement)){ if (1 == optType.intValue()){ //上线 tAdvertisement.setState(1); }else if (2 == optType.intValue()){ //下线 tAdvertisement.setState(2); } tAdvertisement.setUpdateTime(new Date()); tAdvertisement.setUpdateUser(ShiroKit.getUser().getId()); tAdvertisementService.updateById(tAdvertisement); } return SUCCESS_TIP; } /** * 修改广告设置 */ @RequestMapping(value = "/update") @ResponseBody public Object update(TAdvertisement tAdvertisement) { tAdvertisement.setUpdateTime(new Date()); tAdvertisement.setUpdateUser(ShiroKit.getUser().getId()); tAdvertisementService.updateById(tAdvertisement); return SUCCESS_TIP; } }