| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- package com.template.controller;
- import com.alibaba.fastjson.JSON;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.template.annotation.PassToken;
- import com.template.api.LoginControllerAPI;
- import com.template.api.SystemSettingControllerAPI;
- import com.template.common.utils.*;
- import com.template.config.WxOpenidConfig;
- import com.template.model.pojo.*;
- import com.template.model.request.InsertOrUpdateSystemSettingRequest;
- import com.template.model.request.changePasswordRequest;
- import com.template.model.request.loginRequest;
- import com.template.model.request.mobileLoginRequest;
- import com.template.model.result.CommonResult;
- import com.template.model.result.Wx_user;
- import com.template.model.vo.*;
- import com.template.services.*;
- import io.swagger.annotations.ApiModelProperty;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import java.util.*;
- /**
- * @Author: binguo
- * @Date: 2023/7/5 星期三 9:28
- * @Description: com.template.controller
- * @Version: 1.0
- */
- @RestController
- public class SystemSettingController implements SystemSettingControllerAPI {
- private static Logger logger = LoggerFactory.getLogger(SystemSettingController.class);
- //宿舍缴费设置 welcome_pay_setting
- @Autowired
- private WelcomePaySettingService welcomePaySettingService;
- //宿舍开放比例设置 welcome_open_setting
- @Autowired
- private WelcomeOpenSettingService welcomeOpenSettingService;
- //到站时间段设置 welcome_arrive_setting
- @Autowired
- private WelcomeArriveSettingService welcomeArriveSettingService;
- //基础信息 welcome_setting
- @Autowired
- private WelcomeSettingService welcomeSettingService;
- @Override
- public CommonResult querySettings() {
- List<WelcomePaySetting> wps = welcomePaySettingService.list(null);
- List<WelcomeOpenSetting> wos = welcomeOpenSettingService.list(null);
- List<WelcomeArriveSetting> wass = welcomeArriveSettingService.list(null);
- List<WelcomeSetting> ws = welcomeSettingService.list(null);
- SystemSettingVo result = new SystemSettingVo();
- //选宿舍缴费设置
- List<PaySettingVo> psvs = new ArrayList<>();
- if (wps != null && wps.size() > 0) {
- for (WelcomePaySetting wp : wps) {
- PaySettingVo psv = new PaySettingVo();
- psv.setId(wp.getId());
- psv.setSchool(wp.getSchool());
- psv.setMethod(wp.getMethod());
- psv.setPayAmount(wp.getPayAmount());
- psv.setIsCheck(wp.getIsCheck());
- psvs.add(psv);
- }
- }
- result.setPsvs(psvs);
- //宿舍开放比例设置
- List<OpenSettingVo> osvs = new ArrayList<>();
- if (wos != null && wos.size() > 0) {
- for (WelcomeOpenSetting wo : wos) {
- OpenSettingVo osv = new OpenSettingVo();
- osv.setId(wo.getId());
- osv.setSchool(wo.getSchool());
- osv.setCollege(wo.getCollege());
- osv.setOpenAmount(wo.getOpenAmount());
- osv.setIsCheck(wo.getIsCheck());
- osvs.add(osv);
- }
- }
- result.setOsvs(osvs);
- //到站时间段设置
- List<ArriveSettingVo> asvs = new ArrayList<>();
- if (wass != null && wass.size() > 0) {
- for (WelcomeArriveSetting was : wass) {
- ArriveSettingVo asv = new ArriveSettingVo();
- asv.setId(was.getId());
- asv.setIsCheck(was.getIsCheck());
- asv.setStartTime(was.getStartTime());
- asv.setEndTime(was.getEndTime());
- asvs.add(asv);
- }
- }
- result.setAsvs(asvs);
- if (ws != null && ws.size() > 0) {
- WelcomeSetting wsData = ws.get(0);
- result.setMxhCarNum(wsData.getMxhCarNum());
- result.setHjhCarNum(wsData.getHjhCarNum());
- if (StringUtils.hasText(wsData.getPhone())) {
- List<String> phones = Arrays.asList(wsData.getPhone().split(","));
- result.setPhones(phones);
- } else {
- result.setPhones(new ArrayList<>());
- }
- result.setSafetyNotice(wsData.getSafetyNotice());
- result.setBasicVerification(wsData.getBasicVerification());
- result.setFamilyInfo(wsData.getFamilyInfo());
- result.setArriveSchool(wsData.getArriveSchool());
- result.setChooseDormitory(wsData.getChooseDormitory());
- result.setCarOrder(wsData.getCarOrder());
- }
- return CommonResult.ok(result);
- }
- @Override
- @Transactional(rollbackFor = {Exception.class})
- public CommonResult insertOrUpdateSettings(InsertOrUpdateSystemSettingRequest iussr, BindingResult bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- WelcomeSetting result = new WelcomeSetting();
- List<WelcomeSetting> ws = welcomeSettingService.list(null);
- if (ws != null && ws.size() > 0) {
- result = ws.get(0);
- }
- result.setMxhCarNum(iussr.getMxhCarNum());
- result.setHjhCarNum(iussr.getHjhCarNum());
- String phone = org.apache.commons.lang3.StringUtils.join(iussr.getPhones(), ',');
- result.setPhone(phone);
- result.setSafetyNotice(iussr.getSafetyNotice());
- result.setBasicVerification(iussr.getBasicVerification());
- result.setFamilyInfo(iussr.getFamilyInfo());
- result.setArriveSchool(iussr.getArriveSchool());
- result.setChooseDormitory(iussr.getChooseDormitory());
- result.setCarOrder(iussr.getCarOrder());
- //选宿舍缴费设置WelcomePaySetting
- List<WelcomePaySetting> wpss = new ArrayList<>();
- if (iussr.getPsvs() != null && iussr.getPsvs().size() > 0) {
- for (PaySettingVo psv : iussr.getPsvs()) {
- WelcomePaySetting wps = new WelcomePaySetting();
- wps.setSchool(psv.getSchool());
- wps.setMethod(psv.getMethod());
- wps.setPayAmount(psv.getPayAmount());
- wps.setIsCheck(psv.getIsCheck());
- wpss.add(wps);
- }
- }
- //宿舍开放比例设置 welcome_open_setting
- List<WelcomeOpenSetting> woss = new ArrayList<>();
- if (iussr.getOsvs() != null && iussr.getOsvs().size() > 0) {
- for (OpenSettingVo osv : iussr.getOsvs()) {
- WelcomeOpenSetting wos = new WelcomeOpenSetting();
- wos.setSchool(osv.getSchool());
- wos.setCollege(osv.getCollege());
- wos.setOpenAmount(osv.getOpenAmount());
- wos.setIsCheck(osv.getIsCheck());
- woss.add(wos);
- }
- }
- // //到站时间段设置 welcome_arrive_setting
- // List<WelcomeArriveSetting> wass = new ArrayList<>();
- // if (iussr.getAsvs() != null && iussr.getAsvs().size() > 0) {
- // for (ArriveSettingVo asv : iussr.getAsvs()) {
- // WelcomeArriveSetting was = new WelcomeArriveSetting();
- // was.setIsCheck(asv.getIsCheck());
- // was.setStartTime(asv.getStartTime());
- // was.setEndTime(asv.getEndTime());
- // wass.add(was);
- // }
- // }
- try {
- boolean iuS = welcomeSettingService.saveOrUpdate(result);
- if (!iuS) {
- logger.error("设置失败,result参数:" + JSON.toJSON(result));
- throw new Exception("添加失败!");
- }
- if (wpss != null && wpss.size() > 0) {
- int deleteAll = welcomePaySettingService.deleteAll();
- boolean saveBatch = welcomePaySettingService.saveBatch(wpss);
- if (!saveBatch) {
- logger.error("添加缴费设置信息失败,参数:" + JSON.toJSON(wpss));
- throw new Exception("添加失败!");
- }
- }
- if (woss != null && woss.size() > 0) {
- int deleteAll = welcomeOpenSettingService.deleteAll();
- boolean saveBatch = welcomeOpenSettingService.saveBatch(woss);
- if (!saveBatch) {
- logger.error("添加开放比例设置信息失败,参数:" + JSON.toJSON(woss));
- throw new Exception("添加失败!");
- }
- }
- // if (wass != null && wass.size() > 0) {
- // int deleteAll = welcomeArriveSettingService.deleteAll();
- //
- // boolean saveBatch = welcomeArriveSettingService.saveBatch(wass);
- // if (!saveBatch) {
- // logger.error("添加抵达时间段设置信息失败,参数:" + JSON.toJSON(wass));
- // throw new Exception("添加失败!");
- // }
- // }
- } catch (Exception e) {
- logger.error(e.getMessage());
- throw new Exception("设置失败!");
- }
- return CommonResult.ok("设置成功");
- }
- }
|