package com.sinata.modular.system.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.google.common.collect.Lists; import com.sinata.common.enums.EnumAppSetKey; import com.sinata.core.base.controller.BaseController; import com.sinata.core.log.LogObjectHolder; import com.sinata.core.util.ToolUtil; import com.sinata.modular.system.model.TAppSet; import com.sinata.modular.system.service.ITAppSetService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; 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.util.HashMap; import java.util.List; import java.util.Map; /** * APP设置控制器 */ @Controller @RequestMapping("/tAppSet") public class TAppSetController extends BaseController { private String PREFIX = "/system/tAppSet/"; @Autowired private ITAppSetService tAppSetService; /** * 跳转到APP设置首页 */ @RequestMapping("html") public String html(Model model) { List ids = Lists.newArrayList( EnumAppSetKey.REGISTER_AGREEMENT_H5.index, EnumAppSetKey.USER_AGREEMENT_H5.index, EnumAppSetKey.TEAM_US_H5.index, EnumAppSetKey.DAILY_TASK_H5.index, EnumAppSetKey.ABOUT_US_H5.index, EnumAppSetKey.SERVICE_TEL_NUMBER.index, EnumAppSetKey.MEMBER_GRADE_H5.index, EnumAppSetKey.RICE_GRAINS_H5.index, EnumAppSetKey.CONTRIBUTION_SCORE_H5.index, EnumAppSetKey.EXCHANGE_AGREEMENT_H5.index, EnumAppSetKey.SERVICE_H5.index, EnumAppSetKey.MERCHANT_H5.index, EnumAppSetKey.HELP_H5.index, EnumAppSetKey.USER_INFO_HANDLE_RULE_H5.index, EnumAppSetKey.JOIN_COMPANY_AGREEMENT_H5.index ); List appSetList = tAppSetService.selectList(null); List> contents = Lists.newArrayList(); for (TAppSet obj : appSetList) { if ( !ids.contains( obj.getId())) { continue; } contents.add( new HashMap(){{ put( "key", obj.getId().toString()); put( "content", obj.getValueStr()); }}); } model.addAttribute( "keys", ids); model.addAttribute( "contents", contents); return PREFIX + "html.html"; } @RequestMapping("/updateHtml") @ResponseBody public Object updateHtml(Integer id, String content) { // H5页面代码包装(判断加上自适应代码) if (ToolUtil.isNotEmpty(content)) { content = ToolUtil.h5Warpper(content); } TAppSet appSet = tAppSetService.selectById(id); if (appSet != null) { appSet.setValueStr(content); tAppSetService.updateById(appSet); } else { appSet = new TAppSet(); appSet.setValueStr(content); tAppSetService.insert(appSet); } return SUCCESS_TIP; } /** * 跳转到APP设置首页 */ @RequestMapping("") public String index() { return PREFIX + "tAppSet.html"; } /** * 跳转到添加APP设置 */ @RequestMapping("/tAppSet_add") public String tAppSetAdd() { return PREFIX + "tAppSet_add.html"; } /** * 跳转到修改APP设置 */ @RequestMapping("/tAppSet_update/{tAppSetId}") public String tAppSetUpdate(@PathVariable Integer tAppSetId, Model model) { TAppSet tAppSet = tAppSetService.selectById(tAppSetId); model.addAttribute("item",tAppSet); LogObjectHolder.me().set(tAppSet); return PREFIX + "tAppSet_edit.html"; } /** * 获取APP设置列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String condition) { Wrapper wrapper = new EntityWrapper(); return tAppSetService.selectList(wrapper); } /** * 新增APP设置 */ @RequestMapping(value = "/add") @ResponseBody public Object add(TAppSet tAppSet) { tAppSetService.insert(tAppSet); return SUCCESS_TIP; } /** * 删除APP设置 */ @RequestMapping(value = "/delete") @ResponseBody public Object delete(@RequestParam Integer tAppSetId) { tAppSetService.deleteById(tAppSetId); // tAppSetService.updateById(new TAppSet(tAppSetId, 1)); return SUCCESS_TIP; } /** * 修改APP设置 */ @RequestMapping(value = "/update") @ResponseBody public Object update(TAppSet tAppSet) { tAppSetService.updateById(tAppSet); return SUCCESS_TIP; } /** * 修改APP设置状态 */ @RequestMapping(value = "/updateState") @ResponseBody public Object updateState(@RequestParam Integer tAppSetId) { // TAppSet obj = tAppSetService.selectById(tAppSetId); // if (obj != null) { // if(obj.getState() == 0) { // obj.setState(1); // } else { // obj.setState(0); // } // tAppSetService.updateById(obj); // } return SUCCESS_TIP; } /** * APP设置详情 */ @RequestMapping(value = "/detail/{tAppSetId}") @ResponseBody public Object detail(@PathVariable("tAppSetId") Integer tAppSetId) { return tAppSetService.selectById(tAppSetId); } }