| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.yeshi.fanli.entity.SystemEnum;
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | |
| | | @RequestMapping("api/v2/navbar")
|
| | | public class HomeNavbarControllerV2 {
|
| | |
|
| | | @Resource
|
| | | private HomeNavbarService homeNavbarService;
|
| | | @Resource
|
| | | private HomeNavbarService homeNavbarService;
|
| | |
|
| | | @Resource
|
| | | private HomeNavbarUserService homeNavbarUserService;
|
| | | |
| | | @Resource
|
| | | private DeviceSexService deviceSexService;
|
| | | |
| | | @Resource
|
| | | private HomeNavbarUserService homeNavbarUserService;
|
| | |
|
| | | @Resource
|
| | | private DeviceSexService deviceSexService;
|
| | |
|
| | |
|
| | | /**
|
| | | * 改变性别
|
| | | * @param acceptData
|
| | | * @param sex
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "changeSex", method = RequestMethod.POST)
|
| | | public void changeSex(AcceptData acceptData, Integer sex, PrintWriter out) {
|
| | | try {
|
| | | // 获取设备定义性别
|
| | | deviceSexService.save(acceptData.getDevice(), sex);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("sex", sex);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("切换失败"));
|
| | | }
|
| | | }
|
| | | /**
|
| | | * 改变性别
|
| | | *
|
| | | * @param acceptData
|
| | | * @param sex
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "changeSex", method = RequestMethod.POST)
|
| | | public void changeSex(AcceptData acceptData, Integer sex, PrintWriter out) {
|
| | | try {
|
| | | // 获取设备定义性别
|
| | | deviceSexService.save(acceptData.getDevice(), sex);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("sex", sex);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("切换失败"));
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 获取导航栏内容
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getHomeItems", method = RequestMethod.POST)
|
| | | public void getHomeItems(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | // 获取设备定义性别
|
| | | int deviceSex = deviceSexService.getDeviceSex(acceptData.getDevice(),acceptData.getSystem());
|
| | | List<HomeNavbar> listNavbar = homeNavbarUserService.listEffectiveNavbar(uid, acceptData.getDevice(), deviceSex,acceptData.getSystem());
|
| | | |
| | | List<HomeNavbar> list = new ArrayList<HomeNavbar>();
|
| | | if (listNavbar != null) {
|
| | | list.addAll(listNavbar);
|
| | | } |
| | | |
| | | if (!VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) {
|
| | | for (int i = 0; i < list.size(); i ++) {
|
| | | NavbarTypeEnum type = list.get(i).getType();
|
| | | if (type == NavbarTypeEnum.commonTemplate) {
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | JSONObject data = new JSONObject();
|
| | | data.put("sex", deviceSex);
|
| | | data.put("count", list.size());
|
| | | data.put("listNavbar", JsonUtil.getApiCommonGson().toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取导航栏编辑内容
|
| | | * |
| | | * @param acceptData
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getUserItems", method = RequestMethod.POST)
|
| | | public void getUserItems(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | try {
|
| | | List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
|
| | | List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
|
| | | /**
|
| | | * 获取导航栏内容
|
| | | *
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getHomeItems", method = RequestMethod.POST)
|
| | | public void getHomeItems(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | // 获取设备定义性别
|
| | | int deviceSex = deviceSexService.getDeviceSex(acceptData.getDevice(), acceptData.getSystem());
|
| | | List<HomeNavbar> listNavbar = homeNavbarUserService.listEffectiveNavbar(uid, acceptData.getDevice(), deviceSex, acceptData.getSystem());
|
| | |
|
| | | // 系统默认导航栏
|
| | | List<HomeNavbar> listNavbar = homeNavbarService.listQueryEffectiveNavbar(acceptData.getSystem());
|
| | | if (listNavbar != null && listNavbar.size() > 0) {
|
| | | listItems.addAll(listNavbar);
|
| | | }
|
| | | List<HomeNavbar> list = new ArrayList<HomeNavbar>();
|
| | | if (listNavbar != null) {
|
| | | list.addAll(listNavbar);
|
| | | }
|
| | |
|
| | | int nonCount = 0;
|
| | | // 查询用户自定义导航
|
| | | List<HomeNavbarUser> listUser = homeNavbarUserService.listUserNavbar(uid, acceptData.getDevice());
|
| | | //非板栗快省删除网页类导航
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (list.get(i).getType() == NavbarTypeEnum.web && acceptData.getSystem() != SystemEnum.blks) {
|
| | | list.remove(i--);
|
| | | }
|
| | | }
|
| | |
|
| | | if (listUser == null || listUser.size() == 0) {
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar homeNavbar = listItems.get(i);
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | if (!VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) {
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | NavbarTypeEnum type = list.get(i).getType();
|
| | | if (type == NavbarTypeEnum.commonTemplate) {
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (homeNavbar.getIsDefault()) {
|
| | | if (homeNavbar.getIsFixed()) {
|
| | | nonCount++;
|
| | | }
|
| | | |
| | | listExist.add(homeNavbar);
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | }
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("sex", deviceSex);
|
| | | data.put("count", list.size());
|
| | | data.put("listNavbar", JsonUtil.getApiCommonGson().toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | } else {
|
| | | // 获取固定不可编辑
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar homeNavbar = listItems.get(i);
|
| | | /**
|
| | | * 获取导航栏编辑内容
|
| | | *
|
| | | * @param acceptData
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getUserItems", method = RequestMethod.POST)
|
| | | public void getUserItems(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | try {
|
| | | List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
|
| | | List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
|
| | |
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | // 系统默认导航栏
|
| | | List<HomeNavbar> listNavbar = homeNavbarService.listQueryEffectiveNavbar(acceptData.getSystem());
|
| | | if (listNavbar != null && listNavbar.size() > 0) {
|
| | | listItems.addAll(listNavbar);
|
| | | }
|
| | |
|
| | | if (homeNavbar.getIsFixed()) {
|
| | | listExist.add(homeNavbar);
|
| | | nonCount++;
|
| | | int nonCount = 0;
|
| | | // 查询用户自定义导航
|
| | | List<HomeNavbarUser> listUser = homeNavbarUserService.listUserNavbar(uid, acceptData.getDevice());
|
| | |
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | if (listUser == null || listUser.size() == 0) {
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar homeNavbar = listItems.get(i);
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | |
|
| | | // 用户编辑的数据
|
| | | for (HomeNavbarUser homeNavbarUser : listUser) {
|
| | | HomeNavbar homeNavbar = homeNavbarUser.getHomeNavbar();
|
| | | if (homeNavbar == null) {
|
| | | continue;
|
| | | }
|
| | | if (homeNavbar.getIsDefault()) {
|
| | | if (homeNavbar.getIsFixed()) {
|
| | | nonCount++;
|
| | | }
|
| | |
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | continue;
|
| | | }
|
| | | listExist.add(homeNavbar);
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | long homeId = homeNavbar.getId();
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar navbar = listItems.get(i);
|
| | | long id = navbar.getId();
|
| | | if (homeId == id) {
|
| | | // 加入用户已选
|
| | | listExist.add(navbar);
|
| | | // 移除用户已选
|
| | | listItems.remove(navbar);
|
| | | i--;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | } else {
|
| | | // 获取固定不可编辑
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar homeNavbar = listItems.get(i);
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("min", 6);
|
| | | data.put("max", 16);
|
| | | data.put("nonCount", nonCount);
|
| | | data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
|
| | | data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (HomeNavbarUserException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置自定义
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param list
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "saveUserItems", method = RequestMethod.POST)
|
| | | public void saveUserItems(AcceptData acceptData, Long uid, String barIds, PrintWriter out) {
|
| | | try {
|
| | | if (StringUtil.isNullOrEmpty(barIds)) {
|
| | | out.print(JsonUtil.loadFalseResult("Id参数不能为空"));
|
| | | return;
|
| | | }
|
| | | if (homeNavbar.getIsFixed()) {
|
| | | listExist.add(homeNavbar);
|
| | | nonCount++;
|
| | |
|
| | | Gson gson = new Gson();
|
| | | List<Long> list = gson.fromJson(barIds, new TypeToken<ArrayList<Long>>() {
|
| | | }.getType());
|
| | | if (list == null || list.size() == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("未检测到数据"));
|
| | | return;
|
| | | }
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | }
|
| | | }
|
| | |
|
| | | homeNavbarUserService.addNavbarUser(uid, acceptData.getDevice(), list);
|
| | | out.print(JsonUtil.loadTrueResult("保存成功"));
|
| | | |
| | | // 设置为通用
|
| | | deviceSexService.save(acceptData.getDevice(), 0);
|
| | | |
| | | } catch (HomeNavbarUserException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | | // 用户编辑的数据
|
| | | for (HomeNavbarUser homeNavbarUser : listUser) {
|
| | | HomeNavbar homeNavbar = homeNavbarUser.getHomeNavbar();
|
| | | if (homeNavbar == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 还原默认
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "restoreDefault", method = RequestMethod.POST)
|
| | | public void restoreDefault(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | try {
|
| | | int nonCount = 0;
|
| | | List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
|
| | | List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
|
| | | |
| | | |
| | | List<HomeNavbar> listNavbar = homeNavbarUserService.restoreSystemDefault(uid, acceptData.getDevice(),acceptData.getSystem());
|
| | | if (listNavbar != null && listNavbar.size() > 0) {
|
| | | listItems.addAll(listNavbar);
|
| | | }
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar homeNavbar = listItems.get(i);
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | |
| | | // 筛选出默认项
|
| | | if (!homeNavbar.getIsDefault()) {
|
| | | break;
|
| | | } else {
|
| | | // 固定个数
|
| | | if (homeNavbar.getIsFixed()) {
|
| | | nonCount++;
|
| | | }
|
| | | // 默认项
|
| | | listExist.add(homeNavbar);
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | }
|
| | | long homeId = homeNavbar.getId();
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar navbar = listItems.get(i);
|
| | | long id = navbar.getId();
|
| | | if (homeId == id) {
|
| | | // 加入用户已选
|
| | | listExist.add(navbar);
|
| | | // 移除用户已选
|
| | | listItems.remove(navbar);
|
| | | i--;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("nonCount", nonCount);
|
| | | data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
|
| | | data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | |
| | | // 设置为通用
|
| | | deviceSexService.save(acceptData.getDevice(), 0);
|
| | | |
| | | } catch (HomeNavbarUserException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("min", 6);
|
| | | data.put("max", 16);
|
| | | data.put("nonCount", nonCount);
|
| | | data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
|
| | | data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (HomeNavbarUserException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置自定义
|
| | | *
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param list
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "saveUserItems", method = RequestMethod.POST)
|
| | | public void saveUserItems(AcceptData acceptData, Long uid, String barIds, PrintWriter out) {
|
| | | try {
|
| | | if (StringUtil.isNullOrEmpty(barIds)) {
|
| | | out.print(JsonUtil.loadFalseResult("Id参数不能为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | Gson gson = new Gson();
|
| | | List<Long> list = gson.fromJson(barIds, new TypeToken<ArrayList<Long>>() {
|
| | | }.getType());
|
| | | if (list == null || list.size() == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("未检测到数据"));
|
| | | return;
|
| | | }
|
| | |
|
| | | homeNavbarUserService.addNavbarUser(uid, acceptData.getDevice(), list);
|
| | | out.print(JsonUtil.loadTrueResult("保存成功"));
|
| | |
|
| | | // 设置为通用
|
| | | deviceSexService.save(acceptData.getDevice(), 0);
|
| | |
|
| | | } catch (HomeNavbarUserException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 还原默认
|
| | | *
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "restoreDefault", method = RequestMethod.POST)
|
| | | public void restoreDefault(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | try {
|
| | | int nonCount = 0;
|
| | | List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
|
| | | List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
|
| | |
|
| | |
|
| | | List<HomeNavbar> listNavbar = homeNavbarUserService.restoreSystemDefault(uid, acceptData.getDevice(), acceptData.getSystem());
|
| | | if (listNavbar != null && listNavbar.size() > 0) {
|
| | | listItems.addAll(listNavbar);
|
| | | }
|
| | |
|
| | | for (int i = 0; i < listItems.size(); i++) {
|
| | | HomeNavbar homeNavbar = listItems.get(i);
|
| | | // 活动剔除
|
| | | if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | |
|
| | | // 筛选出默认项
|
| | | if (!homeNavbar.getIsDefault()) {
|
| | | break;
|
| | | } else {
|
| | | // 固定个数
|
| | | if (homeNavbar.getIsFixed()) {
|
| | | nonCount++;
|
| | | }
|
| | | // 默认项
|
| | | listExist.add(homeNavbar);
|
| | | listItems.remove(homeNavbar);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("nonCount", nonCount);
|
| | | data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
|
| | | data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | |
|
| | | // 设置为通用
|
| | | deviceSexService.save(acceptData.getDevice(), 0);
|
| | |
|
| | | } catch (HomeNavbarUserException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | |
|
| | | }
|