supplier V2.0.0版本发布

This commit is contained in:
hupeng committed 2021-06-18 17:27:13 +08:00
1 parent 2b5d2c11ee
commit d95d3b792a
1011 files changed
+29417 -16989

No files matched your search

@@ -0,0 +1,22 @@
package co.yixiang;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* 启动程序
*
* @author ruoyi
*/
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class AdminApplication
{
public static void main(String[] args)
{
// System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(AdminApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ ========== ლ(´ڡ`ლ)゙ \n" +
"\n管理端启动成功 \n官网:https://www.yixiang.co 提供技术支持゙ \n");
}
}
@@ -0,0 +1,18 @@
package co.yixiang;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* web容器中进行部署
*
* @author ruoyi
*/
public class AdminServletInitializer extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(AdminApplication.class);
}
}
@@ -0,0 +1,120 @@
package co.yixiang.web.controller.common;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import co.yixiang.common.config.RuoYiConfig;
import co.yixiang.common.config.ServerConfig;
import co.yixiang.common.constant.Constants;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.common.utils.file.FileUploadUtils;
import co.yixiang.common.utils.file.FileUtils;
/**
* 通用请求处理
*
* @author ruoyi
*/
@Controller
public class CommonController
{
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired
private ServerConfig serverConfig;
/**
* 通用下载请求
*
* @param fileName 文件名称
* @param delete 是否删除
*/
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
try
{
if (!FileUtils.checkAllowDownload(fileName))
{
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = RuoYiConfig.getDownloadPath() + fileName;
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
FileUtils.writeBytes(filePath, response.getOutputStream());
if (delete)
{
FileUtils.deleteFile(filePath);
}
}
catch (Exception e)
{
log.error("下载文件失败", e);
}
}
/**
* 通用上传请求
*/
@PostMapping("/common/upload")
@ResponseBody
public AjaxResult uploadFile(MultipartFile file) throws Exception
{
try
{
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
AjaxResult ajax = AjaxResult.success();
ajax.put("fileName", fileName);
ajax.put("url", url);
return ajax;
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
/**
* 本地资源通用下载
*/
@GetMapping("/common/download/resource")
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
try
{
if (!FileUtils.checkAllowDownload(resource))
{
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
}
// 本地资源路径
String localPath = RuoYiConfig.getProfile();
// 数据库资源地址
String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
// 下载名称
String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, downloadName);
FileUtils.writeBytes(downloadPath, response.getOutputStream());
}
catch (Exception e)
{
log.error("下载文件失败", e);
}
}
}
@@ -0,0 +1,80 @@
package co.yixiang.web.controller.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 模态窗口
*
* @author ruoyi
*/
@Controller
@RequestMapping("/demo/modal")
public class DemoDialogController
{
private String prefix = "demo/modal";
/**
* 模态窗口
*/
@GetMapping("/dialog")
public String dialog()
{
return prefix + "/dialog";
}
/**
* 弹层组件
*/
@GetMapping("/layer")
public String layer()
{
return prefix + "/layer";
}
/**
* 表单
*/
@GetMapping("/form")
public String form()
{
return prefix + "/form";
}
/**
* 表格
*/
@GetMapping("/table")
public String table()
{
return prefix + "/table";
}
/**
* 表格check
*/
@GetMapping("/check")
public String check()
{
return prefix + "/table/check";
}
/**
* 表格radio
*/
@GetMapping("/radio")
public String radio()
{
return prefix + "/table/radio";
}
/**
* 表格回传父窗体
*/
@GetMapping("/parent")
public String parent()
{
return prefix + "/table/parent";
}
}
@@ -0,0 +1,390 @@
package co.yixiang.web.controller.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.CxSelect;
import co.yixiang.common.json.JSONObject;
import co.yixiang.common.json.JSONObject.JSONArray;
import co.yixiang.common.utils.StringUtils;
/**
* 表单相关
*
* @author ruoyi
*/
@Controller
@RequestMapping("/demo/form")
public class DemoFormController
{
private String prefix = "demo/form";
private final static List<UserFormModel> users = new ArrayList<UserFormModel>();
{
users.add(new UserFormModel(1, "1000001", "测试1", "15888888888"));
users.add(new UserFormModel(2, "1000002", "测试2", "15666666666"));
users.add(new UserFormModel(3, "1000003", "测试3", "15666666666"));
users.add(new UserFormModel(4, "1000004", "测试4", "15666666666"));
users.add(new UserFormModel(5, "1000005", "测试5", "15666666666"));
}
/**
* 按钮页
*/
@GetMapping("/button")
public String button()
{
return prefix + "/button";
}
/**
* 下拉框
*/
@GetMapping("/select")
public String select()
{
return prefix + "/select";
}
/**
* 时间轴
*/
@GetMapping("/timeline")
public String timeline()
{
return prefix + "/timeline";
}
/**
* 表单校验
*/
@GetMapping("/validate")
public String validate()
{
return prefix + "/validate";
}
/**
* 功能扩展(包含文件上传)
*/
@GetMapping("/jasny")
public String jasny()
{
return prefix + "/jasny";
}
/**
* 拖动排序
*/
@GetMapping("/sortable")
public String sortable()
{
return prefix + "/sortable";
}
/**
* 单据打印
*/
@GetMapping("/invoice")
public String invoice()
{
return prefix + "/invoice";
}
/**
* 标签 & 提示
*/
@GetMapping("/labels_tips")
public String labels_tips()
{
return prefix + "/labels_tips";
}
/**
* 选项卡 & 面板
*/
@GetMapping("/tabs_panels")
public String tabs_panels()
{
return prefix + "/tabs_panels";
}
/**
* 栅格
*/
@GetMapping("/grid")
public String grid()
{
return prefix + "/grid";
}
/**
* 表单向导
*/
@GetMapping("/wizard")
public String wizard()
{
return prefix + "/wizard";
}
/**
* 文件上传
*/
@GetMapping("/upload")
public String upload()
{
return prefix + "/upload";
}
/**
* 日期和时间页
*/
@GetMapping("/datetime")
public String datetime()
{
return prefix + "/datetime";
}
/**
* 左右互选组件
*/
@GetMapping("/duallistbox")
public String duallistbox()
{
return prefix + "/duallistbox";
}
/**
* 基本表单
*/
@GetMapping("/basic")
public String basic()
{
return prefix + "/basic";
}
/**
* 卡片列表
*/
@GetMapping("/cards")
public String cards()
{
return prefix + "/cards";
}
/**
* summernote 富文本编辑器
*/
@GetMapping("/summernote")
public String summernote()
{
return prefix + "/summernote";
}
/**
* 搜索自动补全
*/
@GetMapping("/autocomplete")
public String autocomplete()
{
return prefix + "/autocomplete";
}
/**
* 多级联动下拉
*/
@GetMapping("/cxselect")
public String cxselect(ModelMap mmap)
{
CxSelect cxSelectTB = new CxSelect();
cxSelectTB.setN("淘宝");
cxSelectTB.setV("taobao");
CxSelect cxSelectTm = new CxSelect();
cxSelectTm.setN("天猫");
cxSelectTm.setV("tm");
CxSelect cxSelectJhs = new CxSelect();
cxSelectJhs.setN("聚划算");
cxSelectJhs.setV("jhs");
List<CxSelect> tmList = new ArrayList<CxSelect>();
tmList.add(cxSelectTm);
tmList.add(cxSelectJhs);
cxSelectTB.setS(tmList);
CxSelect cxSelectJD = new CxSelect();
cxSelectJD.setN("京东");
cxSelectJD.setV("jd");
CxSelect cxSelectCs = new CxSelect();
cxSelectCs.setN("京东超市");
cxSelectCs.setV("jdcs");
CxSelect cxSelectSx = new CxSelect();
cxSelectSx.setN("京东生鲜");
cxSelectSx.setV("jdsx");
List<CxSelect> jdList = new ArrayList<CxSelect>();
jdList.add(cxSelectCs);
jdList.add(cxSelectSx);
cxSelectJD.setS(jdList);
List<CxSelect> cxList = new ArrayList<CxSelect>();
cxList.add(cxSelectTB);
cxList.add(cxSelectJD);
mmap.put("data", JSON.toJSON(cxList));
return prefix + "/cxselect";
}
/**
* 局部刷新
*/
@GetMapping("/localrefresh")
public String localRefresh(ModelMap mmap)
{
JSONArray list = new JSONArray();
JSONObject item = new JSONObject();
item.put("name", "这条任务数据是由ModelMap传递到页面的,点击添加按钮后会将这条数据替换为新数据");
item.put("type", "默认");
item.put("date", "2020.06.10");
list.add(item);
mmap.put("tasks", list);
mmap.put("min", 2);
mmap.put("max", 10);
return prefix + "/localrefresh";
}
/**
* 局部刷新-添加任务
*
* @param fragment 页面中的模板名称
* @param taskName 任务名称
*/
@PostMapping("/localrefresh/task")
public String localRefreshTask(String fragment, String taskName, ModelMap mmap)
{
JSONArray list = new JSONArray();
JSONObject item = new JSONObject();
item.put("name", StringUtils.defaultIfBlank(taskName, "通过电话销售过程中了解各盛市的设备仪器使用、采购情况及相关重要追踪人"));
item.put("type", "新增");
item.put("date", "2018.06.10");
list.add(item);
item = new JSONObject();
item.put("name", "提高自己电话营销技巧,灵活专业地与客户进行电话交流");
item.put("type", "新增");
item.put("date", "2018.06.12");
list.add(item);
mmap.put("tasks", list);
return prefix + "/localrefresh::" + fragment;
}
/**
* 模拟数据
*/
@GetMapping("/cityData")
@ResponseBody
public String cityData()
{
String data = "[{\"n\":\"湖南省\",\"s\":[{\"n\":\"长沙市\",\"s\":[{\"n\":\"芙蓉区\"},{\"n\":\"天心区\"},{\"n\":\"岳麓区\"},{\"n\":\"开福区\"},{\"n\":\"雨花区\"},{\"n\":\"望城区\"},{\"n\":\"长沙县\"},{\"n\":\"宁乡县\"},{\"n\":\"浏阳市\"}]},{\"n\":\"株洲市\",\"s\":[{\"n\":\"荷塘区\"},{\"n\":\"芦淞区\"},{\"n\":\"石峰区\"},{\"n\":\"天元区\"},{\"n\":\"株洲县\"},{\"n\":\"攸县\"},{\"n\":\"茶陵县\"},{\"n\":\"炎陵县\"},{\"n\":\"醴陵市\"}]},{\"n\":\"湘潭市\",\"s\":[{\"n\":\"雨湖区\"},{\"n\":\"岳塘区\"},{\"n\":\"湘潭县\"},{\"n\":\"湘乡市\"},{\"n\":\"韶山市\"}]},{\"n\":\"衡阳市\",\"s\":[{\"n\":\"珠晖区\"},{\"n\":\"雁峰区\"},{\"n\":\"石鼓区\"},{\"n\":\"蒸湘区\"},{\"n\":\"南岳区\"},{\"n\":\"衡阳县\"},{\"n\":\"衡南县\"},{\"n\":\"衡山县\"},{\"n\":\"衡东县\"},{\"n\":\"祁东县\"},{\"n\":\"耒阳市\"},{\"n\":\"常宁市\"}]},{\"n\":\"邵阳市\",\"s\":[{\"n\":\"双清区\"},{\"n\":\"大祥区\"},{\"n\":\"北塔区\"},{\"n\":\"邵东县\"},{\"n\":\"新邵县\"},{\"n\":\"邵阳县\"},{\"n\":\"隆回县\"},{\"n\":\"洞口县\"},{\"n\":\"绥宁县\"},{\"n\":\"新宁县\"},{\"n\":\"城步苗族自治县\"},{\"n\":\"武冈市\"}]},{\"n\":\"岳阳市\",\"s\":[{\"n\":\"岳阳楼区\"},{\"n\":\"云溪区\"},{\"n\":\"君山区\"},{\"n\":\"岳阳县\"},{\"n\":\"华容县\"},{\"n\":\"湘阴县\"},{\"n\":\"平江县\"},{\"n\":\"汨罗市\"},{\"n\":\"临湘市\"}]},{\"n\":\"常德市\",\"s\":[{\"n\":\"武陵区\"},{\"n\":\"鼎城区\"},{\"n\":\"安乡县\"},{\"n\":\"汉寿县\"},{\"n\":\"澧县\"},{\"n\":\"临澧县\"},{\"n\":\"桃源县\"},{\"n\":\"石门县\"},{\"n\":\"津市市\"}]},{\"n\":\"张家界市\",\"s\":[{\"n\":\"永定区\"},{\"n\":\"武陵源区\"},{\"n\":\"慈利县\"},{\"n\":\"桑植县\"}]},{\"n\":\"益阳市\",\"s\":[{\"n\":\"资阳区\"},{\"n\":\"赫山区\"},{\"n\":\"南县\"},{\"n\":\"桃江县\"},{\"n\":\"安化县\"},{\"n\":\"沅江市\"}]},{\"n\":\"郴州市\",\"s\":[{\"n\":\"北湖区\"},{\"n\":\"苏仙区\"},{\"n\":\"桂阳县\"},{\"n\":\"宜章县\"},{\"n\":\"永兴县\"},{\"n\":\"嘉禾县\"},{\"n\":\"临武县\"},{\"n\":\"汝城县\"},{\"n\":\"桂东县\"},{\"n\":\"安仁县\"},{\"n\":\"资兴市\"}]},{\"n\":\"永州市\",\"s\":[{\"n\":\"零陵区\"},{\"n\":\"冷水滩区\"},{\"n\":\"祁阳县\"},{\"n\":\"东安县\"},{\"n\":\"双牌县\"},{\"n\":\"道县\"},{\"n\":\"江永县\"},{\"n\":\"宁远县\"},{\"n\":\"蓝山县\"},{\"n\":\"新田县\"},{\"n\":\"江华瑶族自治县\"}]},{\"n\":\"怀化市\",\"s\":[{\"n\":\"鹤城区\"},{\"n\":\"中方县\"},{\"n\":\"沅陵县\"},{\"n\":\"辰溪县\"},{\"n\":\"溆浦县\"},{\"n\":\"会同县\"},{\"n\":\"麻阳苗族自治县\"},{\"n\":\"新晃侗族自治县\"},{\"n\":\"芷江侗族自治县\"},{\"n\":\"靖州苗族侗族自治县\"},{\"n\":\"通道侗族自治县\"},{\"n\":\"洪江市\"}]},{\"n\":\"娄底市\",\"s\":[{\"n\":\"娄星区\"},{\"n\":\"双峰县\"},{\"n\":\"新化县\"},{\"n\":\"冷水江市\"},{\"n\":\"涟源市\"}]},{\"n\":\"湘西土家族苗族自治州\",\"s\":[{\"n\":\"吉首市\"},{\"n\":\"泸溪县\"},{\"n\":\"凤凰县\"},{\"n\":\"花垣县\"},{\"n\":\"保靖县\"},{\"n\":\"古丈县\"},{\"n\":\"永顺县\"},{\"n\":\"龙山县\"}]}]},{\"n\":\"广东省\",\"s\":[{\"n\":\"广州市\",\"s\":[{\"n\":\"荔湾区\"},{\"n\":\"越秀区\"},{\"n\":\"海珠区\"},{\"n\":\"天河区\"},{\"n\":\"白云区\"},{\"n\":\"黄埔区\"},{\"n\":\"番禺区\"},{\"n\":\"花都区\"},{\"n\":\"南沙区\"},{\"n\":\"萝岗区\"},{\"n\":\"增城市\"},{\"n\":\"从化市\"}]},{\"n\":\"韶关市\",\"s\":[{\"n\":\"武江区\"},{\"n\":\"浈江区\"},{\"n\":\"曲江区\"},{\"n\":\"始兴县\"},{\"n\":\"仁化县\"},{\"n\":\"翁源县\"},{\"n\":\"乳源瑶族自治县\"},{\"n\":\"新丰县\"},{\"n\":\"乐昌市\"},{\"n\":\"南雄市\"}]},{\"n\":\"深圳市\",\"s\":[{\"n\":\"罗湖区\"},{\"n\":\"福田区\"},{\"n\":\"南山区\"},{\"n\":\"宝安区\"},{\"n\":\"龙岗区\"},{\"n\":\"盐田区\"}]},{\"n\":\"珠海市\",\"s\":[{\"n\":\"香洲区\"},{\"n\":\"斗门区\"},{\"n\":\"金湾区\"}]},{\"n\":\"汕头市\",\"s\":[{\"n\":\"龙湖区\"},{\"n\":\"金平区\"},{\"n\":\"濠江区\"},{\"n\":\"潮阳区\"},{\"n\":\"潮南区\"},{\"n\":\"澄海区\"},{\"n\":\"南澳县\"}]},{\"n\":\"佛山市\",\"s\":[{\"n\":\"禅城区\"},{\"n\":\"南海区\"},{\"n\":\"顺德区\"},{\"n\":\"三水区\"},{\"n\":\"高明区\"}]},{\"n\":\"江门市\",\"s\":[{\"n\":\"蓬江区\"},{\"n\":\"江海区\"},{\"n\":\"新会区\"},{\"n\":\"台山市\"},{\"n\":\"开平市\"},{\"n\":\"鹤山市\"},{\"n\":\"恩平市\"}]},{\"n\":\"湛江市\",\"s\":[{\"n\":\"赤坎区\"},{\"n\":\"霞山区\"},{\"n\":\"坡头区\"},{\"n\":\"麻章区\"},{\"n\":\"遂溪县\"},{\"n\":\"徐闻县\"},{\"n\":\"廉江市\"},{\"n\":\"雷州市\"},{\"n\":\"吴川市\"}]},{\"n\":\"茂名市\",\"s\":[{\"n\":\"茂南区\"},{\"n\":\"茂港区\"},{\"n\":\"电白县\"},{\"n\":\"高州市\"},{\"n\":\"化州市\"},{\"n\":\"Line truncated
return data;
}
/**
* 获取用户数据
*/
@GetMapping("/userModel")
@ResponseBody
public AjaxResult userModel()
{
AjaxResult ajax = new AjaxResult();
ajax.put("code", 200);
ajax.put("value", users);
return ajax;
}
/**
* 获取数据集合
*/
@GetMapping("/collection")
@ResponseBody
public AjaxResult collection()
{
String[] array = { "ruoyi 1", "ruoyi 2", "ruoyi 3", "ruoyi 4", "ruoyi 5" };
AjaxResult ajax = new AjaxResult();
ajax.put("value", array);
return ajax;
}
}
class UserFormModel
{
/** 用户ID */
private int userId;
/** 用户编号 */
private String userCode;
/** 用户姓名 */
private String userName;
/** 用户手机 */
private String userPhone;
public UserFormModel()
{
}
public UserFormModel(int userId, String userCode, String userName, String userPhone)
{
this.userId = userId;
this.userCode = userCode;
this.userName = userName;
this.userPhone = userPhone;
}
public int getUserId()
{
return userId;
}
public void setUserId(int userId)
{
this.userId = userId;
}
public String getUserCode()
{
return userCode;
}
public void setUserCode(String userCode)
{
this.userCode = userCode;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getUserPhone()
{
return userPhone;
}
public void setUserPhone(String userPhone)
{
this.userPhone = userPhone;
}
}
@@ -0,0 +1,35 @@
package co.yixiang.web.controller.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 图标相关
*
* @author ruoyi
*/
@Controller
@RequestMapping("/demo/icon")
public class DemoIconController
{
private String prefix = "demo/icon";
/**
* FontAwesome图标
*/
@GetMapping("/fontawesome")
public String fontAwesome()
{
return prefix + "/fontawesome";
}
/**
* Glyphicons图标
*/
@GetMapping("/glyphicons")
public String glyphicons()
{
return prefix + "/glyphicons";
}
}
@@ -0,0 +1,329 @@
package co.yixiang.web.controller.demo.controller;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import co.yixiang.web.controller.demo.domain.CustomerModel;
import co.yixiang.web.controller.demo.domain.UserOperateModel;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.PageDomain;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.core.page.TableSupport;
import co.yixiang.common.core.text.Convert;
import co.yixiang.common.exception.BusinessException;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.web.controller.demo.domain.CustomerModel;
import co.yixiang.web.controller.demo.domain.UserOperateModel;
/**
* 操作控制
*
* @author ruoyi
*/
@Controller
@RequestMapping("/demo/operate")
public class DemoOperateController extends BaseController
{
private String prefix = "demo/operate";
private final static Map<Integer, UserOperateModel> users = new LinkedHashMap<Integer, UserOperateModel>();
{
users.put(1, new UserOperateModel(1, "1000001", "测试1", "0", "15888888888", "ry@qq.com", 150.0, "0"));
users.put(2, new UserOperateModel(2, "1000002", "测试2", "1", "15666666666", "ry@qq.com", 180.0, "1"));
users.put(3, new UserOperateModel(3, "1000003", "测试3", "0", "15666666666", "ry@qq.com", 110.0, "1"));
users.put(4, new UserOperateModel(4, "1000004", "测试4", "1", "15666666666", "ry@qq.com", 220.0, "1"));
users.put(5, new UserOperateModel(5, "1000005", "测试5", "0", "15666666666", "ry@qq.com", 140.0, "1"));
users.put(6, new UserOperateModel(6, "1000006", "测试6", "1", "15666666666", "ry@qq.com", 330.0, "1"));
users.put(7, new UserOperateModel(7, "1000007", "测试7", "0", "15666666666", "ry@qq.com", 160.0, "1"));
users.put(8, new UserOperateModel(8, "1000008", "测试8", "1", "15666666666", "ry@qq.com", 170.0, "1"));
users.put(9, new UserOperateModel(9, "1000009", "测试9", "0", "15666666666", "ry@qq.com", 180.0, "1"));
users.put(10, new UserOperateModel(10, "1000010", "测试10", "0", "15666666666", "ry@qq.com", 210.0, "1"));
users.put(11, new UserOperateModel(11, "1000011", "测试11", "1", "15666666666", "ry@qq.com", 110.0, "1"));
users.put(12, new UserOperateModel(12, "1000012", "测试12", "0", "15666666666", "ry@qq.com", 120.0, "1"));
users.put(13, new UserOperateModel(13, "1000013", "测试13", "1", "15666666666", "ry@qq.com", 380.0, "1"));
users.put(14, new UserOperateModel(14, "1000014", "测试14", "0", "15666666666", "ry@qq.com", 280.0, "1"));
users.put(15, new UserOperateModel(15, "1000015", "测试15", "0", "15666666666", "ry@qq.com", 570.0, "1"));
users.put(16, new UserOperateModel(16, "1000016", "测试16", "1", "15666666666", "ry@qq.com", 260.0, "1"));
users.put(17, new UserOperateModel(17, "1000017", "测试17", "1", "15666666666", "ry@qq.com", 210.0, "1"));
users.put(18, new UserOperateModel(18, "1000018", "测试18", "1", "15666666666", "ry@qq.com", 340.0, "1"));
users.put(19, new UserOperateModel(19, "1000019", "测试19", "1", "15666666666", "ry@qq.com", 160.0, "1"));
users.put(20, new UserOperateModel(20, "1000020", "测试20", "1", "15666666666", "ry@qq.com", 220.0, "1"));
users.put(21, new UserOperateModel(21, "1000021", "测试21", "1", "15666666666", "ry@qq.com", 120.0, "1"));
users.put(22, new UserOperateModel(22, "1000022", "测试22", "1", "15666666666", "ry@qq.com", 130.0, "1"));
users.put(23, new UserOperateModel(23, "1000023", "测试23", "1", "15666666666", "ry@qq.com", 490.0, "1"));
users.put(24, new UserOperateModel(24, "1000024", "测试24", "1", "15666666666", "ry@qq.com", 570.0, "1"));
users.put(25, new UserOperateModel(25, "1000025", "测试25", "1", "15666666666", "ry@qq.com", 250.0, "1"));
users.put(26, new UserOperateModel(26, "1000026", "测试26", "1", "15666666666", "ry@qq.com", 250.0, "1"));
}
/**
* 表格
*/
@GetMapping("/table")
public String table()
{
return prefix + "/table";
}
/**
* 其他
*/
@GetMapping("/other")
public String other()
{
return prefix + "/other";
}
/**
* 查询数据
*/
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(UserOperateModel userModel)
{
TableDataInfo rspData = new TableDataInfo();
List<UserOperateModel> userList = new ArrayList<UserOperateModel>(users.values());
// 查询条件过滤
if (StringUtils.isNotEmpty(userModel.getSearchValue()))
{
userList.clear();
for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet())
{
if (entry.getValue().getUserName().equals(userModel.getSearchValue()))
{
userList.add(entry.getValue());
}
}
}
else if (StringUtils.isNotEmpty(userModel.getUserName()))
{
userList.clear();
for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet())
{
if (entry.getValue().getUserName().equals(userModel.getUserName()))
{
userList.add(entry.getValue());
}
}
}
PageDomain pageDomain = TableSupport.buildPageRequest();
if (null == pageDomain.getPageNum() || null == pageDomain.getPageSize())
{
rspData.setRows(userList);
rspData.setTotal(userList.size());
return rspData;
}
Integer pageNum = (pageDomain.getPageNum() - 1) * 10;
Integer pageSize = pageDomain.getPageNum() * 10;
if (pageSize > userList.size())
{
pageSize = userList.size();
}
rspData.setRows(userList.subList(pageNum, pageSize));
rspData.setTotal(userList.size());
return rspData;
}
/**
* 新增用户
*/
@GetMapping("/add")
public String add(ModelMap mmap)
{
return prefix + "/add";
}
/**
* 新增保存用户
*/
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(UserOperateModel user)
{
Integer userId = users.size() + 1;
user.setUserId(userId);
return AjaxResult.success(users.put(userId, user));
}
/**
* 新增保存主子表信息
*/
@PostMapping("/customer/add")
@ResponseBody
public AjaxResult addSave(CustomerModel customerModel)
{
System.out.println(customerModel.toString());
return AjaxResult.success();
}
/**
* 修改用户
*/
@GetMapping("/edit/{userId}")
public String edit(@PathVariable("userId") Integer userId, ModelMap mmap)
{
mmap.put("user", users.get(userId));
return prefix + "/edit";
}
/**
* 修改保存用户
*/
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(UserOperateModel user)
{
return AjaxResult.success(users.put(user.getUserId(), user));
}
/**
* 导出
*/
@PostMapping("/export")
@ResponseBody
public AjaxResult export(UserOperateModel user)
{
List<UserOperateModel> list = new ArrayList<UserOperateModel>(users.values());
ExcelUtil<UserOperateModel> util = new ExcelUtil<UserOperateModel>(UserOperateModel.class);
return util.exportExcel(list, "用户数据");
}
/**
* 下载模板
*/
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate()
{
ExcelUtil<UserOperateModel> util = new ExcelUtil<UserOperateModel>(UserOperateModel.class);
return util.importTemplateExcel("用户数据");
}
/**
* 导入数据
*/
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
ExcelUtil<UserOperateModel> util = new ExcelUtil<UserOperateModel>(UserOperateModel.class);
List<UserOperateModel> userList = util.importExcel(file.getInputStream());
String message = importUser(userList, updateSupport);
return AjaxResult.success(message);
}
/**
* 删除用户
*/
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
Integer[] userIds = Convert.toIntArray(ids);
for (Integer userId : userIds)
{
users.remove(userId);
}
return AjaxResult.success();
}
/**
* 查看详细
*/
@GetMapping("/detail/{userId}")
public String detail(@PathVariable("userId") Integer userId, ModelMap mmap)
{
mmap.put("user", users.get(userId));
return prefix + "/detail";
}
@PostMapping("/clean")
@ResponseBody
public AjaxResult clean()
{
users.clear();
return success();
}
/**
* 导入用户数据
*
* @param userList 用户数据列表
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
* @return 结果
*/
public String importUser(List<UserOperateModel> userList, Boolean isUpdateSupport)
{
if (StringUtils.isNull(userList) || userList.size() == 0)
{
throw new BusinessException("导入用户数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (UserOperateModel user : userList)
{
try
{
// 验证是否存在这个用户
boolean userFlag = false;
for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet())
{
if (entry.getValue().getUserName().equals(user.getUserName()))
{
userFlag = true;
break;
}
}
if (!userFlag)
{
Integer userId = users.size() + 1;
user.setUserId(userId);
users.put(userId, user);
successNum++;
successMsg.append("<br/>" + successNum + "、用户 " + user.getUserName() + " 导入成功");
}
else if (isUpdateSupport)
{
users.put(user.getUserId(), user);
successNum++;
successMsg.append("<br/>" + successNum + "、用户 " + user.getUserName() + " 更新成功");
}
else
{
failureNum++;
failureMsg.append("<br/>" + failureNum + "、用户 " + user.getUserName() + " 已存在");
}
}
catch (Exception e)
{
failureNum++;
String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0)
{
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new BusinessException(failureMsg.toString());
}
else
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
}
@@ -0,0 +1,53 @@
package co.yixiang.web.controller.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 报表
*
* @author ruoyi
*/
@Controller
@RequestMapping("/demo/report")
public class DemoReportController
{
private String prefix = "demo/report";
/**
* 百度ECharts
*/
@GetMapping("/echarts")
public String echarts()
{
return prefix + "/echarts";
}
/**
* 图表插件
*/
@GetMapping("/peity")
public String peity()
{
return prefix + "/peity";
}
/**
* 线状图插件
*/
@GetMapping("/sparkline")
public String sparkline()
{
return prefix + "/sparkline";
}
/**
* 图表组合
*/
@GetMapping("/metrics")
public String metrics()
{
return prefix + "/metrics";
}
}
@@ -0,0 +1,590 @@
package co.yixiang.web.controller.demo.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.annotation.JsonFormat;
import co.yixiang.common.annotation.Excel;
import co.yixiang.common.annotation.Excel.ColumnType;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.PageDomain;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.core.page.TableSupport;
import co.yixiang.common.core.text.Convert;
import co.yixiang.common.utils.DateUtils;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
/**
* 表格相关
*
* @author ruoyi
*/
@Controller
@RequestMapping("/demo/table")
public class DemoTableController extends BaseController
{
private String prefix = "demo/table";
private final static List<UserTableModel> users = new ArrayList<UserTableModel>();
{
users.add(new UserTableModel(1, "1000001", "测试1", "0", "15888888888", "ry@qq.com", 150.0, "0"));
users.add(new UserTableModel(2, "1000002", "测试2", "1", "15666666666", "ry@qq.com", 180.0, "1"));
users.add(new UserTableModel(3, "1000003", "测试3", "0", "15666666666", "ry@qq.com", 110.0, "1"));
users.add(new UserTableModel(4, "1000004", "测试4", "1", "15666666666", "ry@qq.com", 220.0, "1"));
users.add(new UserTableModel(5, "1000005", "测试5", "0", "15666666666", "ry@qq.com", 140.0, "1"));
users.add(new UserTableModel(6, "1000006", "测试6", "1", "15666666666", "ry@qq.com", 330.0, "1"));
users.add(new UserTableModel(7, "1000007", "测试7", "0", "15666666666", "ry@qq.com", 160.0, "1"));
users.add(new UserTableModel(8, "1000008", "测试8", "1", "15666666666", "ry@qq.com", 170.0, "1"));
users.add(new UserTableModel(9, "1000009", "测试9", "0", "15666666666", "ry@qq.com", 180.0, "1"));
users.add(new UserTableModel(10, "1000010", "测试10", "0", "15666666666", "ry@qq.com", 210.0, "1"));
users.add(new UserTableModel(11, "1000011", "测试11", "1", "15666666666", "ry@qq.com", 110.0, "1"));
users.add(new UserTableModel(12, "1000012", "测试12", "0", "15666666666", "ry@qq.com", 120.0, "1"));
users.add(new UserTableModel(13, "1000013", "测试13", "1", "15666666666", "ry@qq.com", 380.0, "1"));
users.add(new UserTableModel(14, "1000014", "测试14", "0", "15666666666", "ry@qq.com", 280.0, "1"));
users.add(new UserTableModel(15, "1000015", "测试15", "0", "15666666666", "ry@qq.com", 570.0, "1"));
users.add(new UserTableModel(16, "1000016", "测试16", "1", "15666666666", "ry@qq.com", 260.0, "1"));
users.add(new UserTableModel(17, "1000017", "测试17", "1", "15666666666", "ry@qq.com", 210.0, "1"));
users.add(new UserTableModel(18, "1000018", "测试18", "1", "15666666666", "ry@qq.com", 340.0, "1"));
users.add(new UserTableModel(19, "1000019", "测试19", "1", "15666666666", "ry@qq.com", 160.0, "1"));
users.add(new UserTableModel(20, "1000020", "测试20", "1", "15666666666", "ry@qq.com", 220.0, "1"));
users.add(new UserTableModel(21, "1000021", "测试21", "1", "15666666666", "ry@qq.com", 120.0, "1"));
users.add(new UserTableModel(22, "1000022", "测试22", "1", "15666666666", "ry@qq.com", 130.0, "1"));
users.add(new UserTableModel(23, "1000023", "测试23", "1", "15666666666", "ry@qq.com", 490.0, "1"));
users.add(new UserTableModel(24, "1000024", "测试24", "1", "15666666666", "ry@qq.com", 570.0, "1"));
users.add(new UserTableModel(25, "1000025", "测试25", "1", "15666666666", "ry@qq.com", 250.0, "1"));
users.add(new UserTableModel(26, "1000026", "测试26", "1", "15666666666", "ry@qq.com", 250.0, "1"));
}
private final static List<UserTableColumn> columns = new ArrayList<UserTableColumn>();
{
columns.add(new UserTableColumn("用户ID", "userId"));
columns.add(new UserTableColumn("用户编号", "userCode"));
columns.add(new UserTableColumn("用户姓名", "userName"));
columns.add(new UserTableColumn("用户手机", "userPhone"));
columns.add(new UserTableColumn("用户邮箱", "userEmail"));
columns.add(new UserTableColumn("用户状态", "status"));
}
/**
* 搜索相关
*/
@GetMapping("/search")
public String search()
{
return prefix + "/search";
}
/**
* 数据汇总
*/
@GetMapping("/footer")
public String footer()
{
return prefix + "/footer";
}
/**
* 组合表头
*/
@GetMapping("/groupHeader")
public String groupHeader()
{
return prefix + "/groupHeader";
}
/**
* 表格导出
*/
@GetMapping("/export")
public String export()
{
return prefix + "/export";
}
/**
* 表格导出选择列
*/
@GetMapping("/exportSelected")
public String exportSelected()
{
return prefix + "/exportSelected";
}
/**
* 导出数据
*/
@PostMapping("/exportData")
@ResponseBody
public AjaxResult exportSelected(UserTableModel userModel, String userIds)
{
List<UserTableModel> userList = new ArrayList<UserTableModel>(Arrays.asList(new UserTableModel[users.size()]));
Collections.copy(userList, users);
// 条件过滤
if (StringUtils.isNotEmpty(userIds))
{
userList.clear();
for (Long userId : Convert.toLongArray(userIds))
{
for (UserTableModel user : users)
{
if (user.getUserId() == userId)
{
userList.add(user);
}
}
}
}
ExcelUtil<UserTableModel> util = new ExcelUtil<UserTableModel>(UserTableModel.class);
return util.exportExcel(userList, "用户数据");
}
/**
* 翻页记住选择
*/
@GetMapping("/remember")
public String remember()
{
return prefix + "/remember";
}
/**
* 跳转至指定页
*/
@GetMapping("/pageGo")
public String pageGo()
{
return prefix + "/pageGo";
}
/**
* 自定义查询参数
*/
@GetMapping("/params")
public String params()
{
return prefix + "/params";
}
/**
* 多表格
*/
@GetMapping("/multi")
public String multi()
{
return prefix + "/multi";
}
/**
* 点击按钮加载表格
*/
@GetMapping("/button")
public String button()
{
return prefix + "/button";
}
/**
* 直接加载表格数据
*/
@GetMapping("/data")
public String data(ModelMap mmap)
{
mmap.put("users", users);
return prefix + "/data";
}
/**
* 表格冻结列
*/
@GetMapping("/fixedColumns")
public String fixedColumns()
{
return prefix + "/fixedColumns";
}
/**
* 自定义触发事件
*/
@GetMapping("/event")
public String event()
{
return prefix + "/event";
}
/**
* 表格细节视图
*/
@GetMapping("/detail")
public String detail()
{
return prefix + "/detail";
}
/**
* 表格父子视图
*/
@GetMapping("/child")
public String child()
{
return prefix + "/child";
}
/**
* 表格图片预览
*/
@GetMapping("/image")
public String image()
{
return prefix + "/image";
}
/**
* 动态增删改查
*/
@GetMapping("/curd")
public String curd()
{
return prefix + "/curd";
}
/**
* 表格行拖拽操作
*/
@GetMapping("/reorderRows")
public String reorderRows()
{
return prefix + "/reorderRows";
}
/**
* 表格列拖拽操作
*/
@GetMapping("/reorderColumns")
public String reorderColumns()
{
return prefix + "/reorderColumns";
}
/**
* 表格列宽拖动
*/
@GetMapping("/resizable")
public String resizable()
{
return prefix + "/resizable";
}
/**
* 表格行内编辑操作
*/
@GetMapping("/editable")
public String editable()
{
return prefix + "/editable";
}
/**
* 主子表提交
*/
@GetMapping("/subdata")
public String subdata()
{
return prefix + "/subdata";
}
/**
* 表格自动刷新
*/
@GetMapping("/refresh")
public String refresh()
{
return prefix + "/refresh";
}
/**
* 表格打印配置
*/
@GetMapping("/print")
public String print()
{
return prefix + "/print";
}
/**
* 表格标题格式化
*/
@GetMapping("/headerStyle")
public String headerStyle()
{
return prefix + "/headerStyle";
}
/**
* 表格动态列
*/
@GetMapping("/dynamicColumns")
public String dynamicColumns()
{
return prefix + "/dynamicColumns";
}
/**
* 表格其他操作
*/
@GetMapping("/other")
public String other()
{
return prefix + "/other";
}
/**
* 动态获取列
*/
@PostMapping("/ajaxColumns")
@ResponseBody
public AjaxResult ajaxColumns(UserTableColumn userColumn)
{
List<UserTableColumn> columnList = new ArrayList<UserTableColumn>(Arrays.asList(new UserTableColumn[columns.size()]));
Collections.copy(columnList, columns);
if (userColumn != null && "userBalance".equals(userColumn.getField()))
{
columnList.add(new UserTableColumn("用户余额", "userBalance"));
}
return AjaxResult.success(columnList);
}
/**
* 查询数据
*/
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(UserTableModel userModel)
{
TableDataInfo rspData = new TableDataInfo();
List<UserTableModel> userList = new ArrayList<UserTableModel>(Arrays.asList(new UserTableModel[users.size()]));
Collections.copy(userList, users);
// 查询条件过滤
if (StringUtils.isNotEmpty(userModel.getUserName()))
{
userList.clear();
for (UserTableModel user : users)
{
if (user.getUserName().equals(userModel.getUserName()))
{
userList.add(user);
}
}
}
PageDomain pageDomain = TableSupport.buildPageRequest();
if (null == pageDomain.getPageNum() || null == pageDomain.getPageSize())
{
rspData.setRows(userList);
rspData.setTotal(userList.size());
return rspData;
}
Integer pageNum = (pageDomain.getPageNum() - 1) * 10;
Integer pageSize = pageDomain.getPageNum() * 10;
if (pageSize > userList.size())
{
pageSize = userList.size();
}
rspData.setRows(userList.subList(pageNum, pageSize));
rspData.setTotal(userList.size());
return rspData;
}
}
class UserTableColumn
{
/** 表头 */
private String title;
/** 字段 */
private String field;
public UserTableColumn()
{
}
public UserTableColumn(String title, String field)
{
this.title = title;
this.field = field;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public String getField()
{
return field;
}
public void setField(String field)
{
this.field = field;
}
}
class UserTableModel
{
/** 用户ID */
private int userId;
/** 用户编号 */
@Excel(name = "用户编号", cellType = ColumnType.NUMERIC)
private String userCode;
/** 用户姓名 */
@Excel(name = "用户姓名")
private String userName;
/** 用户性别 */
private String userSex;
/** 用户手机 */
@Excel(name = "用户手机")
private String userPhone;
/** 用户邮箱 */
@Excel(name = "用户邮箱")
private String userEmail;
/** 用户余额 */
@Excel(name = "用户余额", cellType = ColumnType.NUMERIC)
private double userBalance;
/** 用户状态(0正常 1停用) */
private String status;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
public UserTableModel()
{
}
public UserTableModel(int userId, String userCode, String userName, String userSex, String userPhone,
String userEmail, double userBalance, String status)
{
this.userId = userId;
this.userCode = userCode;
this.userName = userName;
this.userSex = userSex;
this.userPhone = userPhone;
this.userEmail = userEmail;
this.userBalance = userBalance;
this.status = status;
this.createTime = DateUtils.getNowDate();
}
public int getUserId()
{
return userId;
}
public void setUserId(int userId)
{
this.userId = userId;
}
public String getUserCode()
{
return userCode;
}
public void setUserCode(String userCode)
{
this.userCode = userCode;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getUserSex()
{
return userSex;
}
public void setUserSex(String userSex)
{
this.userSex = userSex;
}
public String getUserPhone()
{
return userPhone;
}
public void setUserPhone(String userPhone)
{
this.userPhone = userPhone;
}
public String getUserEmail()
{
return userEmail;
}
public void setUserEmail(String userEmail)
{
this.userEmail = userEmail;
}
public double getUserBalance()
{
return userBalance;
}
public void setUserBalance(double userBalance)
{
this.userBalance = userBalance;
}
public String getStatus()
{
return status;
}
public void setStatus(String status)
{
this.status = status;
}
public Date getCreateTime()
{
return createTime;
}
public void setCreateTime(Date createTime)
{
this.createTime = createTime;
}
}
@@ -0,0 +1,116 @@
package co.yixiang.web.controller.demo.domain;
import java.util.List;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 客户测试信息
*
* @author ruoyi
*/
public class CustomerModel
{
/**
* 客户姓名
*/
private String name;
/**
* 客户手机
*/
private String phonenumber;
/**
* 客户性别
*/
private String sex;
/**
* 客户生日
*/
private String birthday;
/**
* 客户描述
*/
private String remark;
/**
* 商品信息
*/
private List<GoodsModel> goods;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPhonenumber()
{
return phonenumber;
}
public void setPhonenumber(String phonenumber)
{
this.phonenumber = phonenumber;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getBirthday()
{
return birthday;
}
public void setBirthday(String birthday)
{
this.birthday = birthday;
}
public String getRemark()
{
return remark;
}
public void setRemark(String remark)
{
this.remark = remark;
}
public List<GoodsModel> getGoods()
{
return goods;
}
public void setGoods(List<GoodsModel> goods)
{
this.goods = goods;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("name", getName())
.append("phonenumber", getPhonenumber())
.append("sex", getSex())
.append("birthday", getBirthday())
.append("goods", getGoods())
.append("remark", getRemark())
.toString();
}
}
@@ -0,0 +1,99 @@
package co.yixiang.web.controller.demo.domain;
import java.util.Date;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 商品测试信息
*
* @author ruoyi
*/
public class GoodsModel
{
/**
* 商品名称
*/
private String name;
/**
* 商品重量
*/
private Integer weight;
/**
* 商品价格
*/
private Double price;
/**
* 商品日期
*/
private Date date;
/**
* 商品种类
*/
private String type;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Integer getWeight()
{
return weight;
}
public void setWeight(Integer weight)
{
this.weight = weight;
}
public Double getPrice()
{
return price;
}
public void setPrice(Double price)
{
this.price = price;
}
public Date getDate()
{
return date;
}
public void setDate(Date date)
{
this.date = date;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("name", getName())
.append("weight", getWeight())
.append("price", getPrice())
.append("date", getDate())
.append("type", getType())
.toString();
}
}
@@ -0,0 +1,149 @@
package co.yixiang.web.controller.demo.domain;
import java.util.Date;
import co.yixiang.common.annotation.Excel;
import co.yixiang.common.annotation.Excel.Type;
import co.yixiang.common.core.domain.BaseEntity;
import co.yixiang.common.utils.DateUtils;
public class UserOperateModel extends BaseEntity
{
private static final long serialVersionUID = 1L;
private int userId;
@Excel(name = "用户编号")
private String userCode;
@Excel(name = "用户姓名")
private String userName;
@Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
private String userSex;
@Excel(name = "用户手机")
private String userPhone;
@Excel(name = "用户邮箱")
private String userEmail;
@Excel(name = "用户余额")
private double userBalance;
@Excel(name = "用户状态", readConverterExp = "0=正常,1=停用")
private String status;
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
private Date createTime;
public UserOperateModel()
{
}
public UserOperateModel(int userId, String userCode, String userName, String userSex, String userPhone,
String userEmail, double userBalance, String status)
{
this.userId = userId;
this.userCode = userCode;
this.userName = userName;
this.userSex = userSex;
this.userPhone = userPhone;
this.userEmail = userEmail;
this.userBalance = userBalance;
this.status = status;
this.createTime = DateUtils.getNowDate();
}
public int getUserId()
{
return userId;
}
public void setUserId(int userId)
{
this.userId = userId;
}
public String getUserCode()
{
return userCode;
}
public void setUserCode(String userCode)
{
this.userCode = userCode;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getUserSex()
{
return userSex;
}
public void setUserSex(String userSex)
{
this.userSex = userSex;
}
public String getUserPhone()
{
return userPhone;
}
public void setUserPhone(String userPhone)
{
this.userPhone = userPhone;
}
public String getUserEmail()
{
return userEmail;
}
public void setUserEmail(String userEmail)
{
this.userEmail = userEmail;
}
public double getUserBalance()
{
return userBalance;
}
public void setUserBalance(double userBalance)
{
this.userBalance = userBalance;
}
public String getStatus()
{
return status;
}
public void setStatus(String status)
{
this.status = status;
}
@Override
public Date getCreateTime()
{
return createTime;
}
@Override
public void setCreateTime(Date createTime)
{
this.createTime = createTime;
}
}
@@ -0,0 +1,82 @@
package co.yixiang.web.controller.monitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.framework.web.service.CacheService;
/**
* 缓存监控
*
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/cache")
public class CacheController extends BaseController
{
private String prefix = "monitor/cache";
@Autowired
private CacheService cacheService;
@GetMapping()
public String cache(ModelMap mmap)
{
mmap.put("cacheNames", cacheService.getCacheNames());
return prefix + "/cache";
}
@PostMapping("/getNames")
public String getCacheNames(String fragment, ModelMap mmap)
{
mmap.put("cacheNames", cacheService.getCacheNames());
return prefix + "/cache::" + fragment;
}
@PostMapping("/getKeys")
public String getCacheKeys(String fragment, String cacheName, ModelMap mmap)
{
mmap.put("cacheName", cacheName);
mmap.put("cacheKyes", cacheService.getCacheKeys(cacheName));
return prefix + "/cache::" + fragment;
}
@PostMapping("/getValue")
public String getCacheValue(String fragment, String cacheName, String cacheKey, ModelMap mmap)
{
mmap.put("cacheName", cacheName);
mmap.put("cacheKey", cacheKey);
mmap.put("cacheValue", cacheService.getCacheValue(cacheName, cacheKey));
return prefix + "/cache::" + fragment;
}
@PostMapping("/clearCacheName")
@ResponseBody
public AjaxResult clearCacheName(String cacheName, ModelMap mmap)
{
cacheService.clearCacheName(cacheName);
return AjaxResult.success();
}
@PostMapping("/clearCacheKey")
@ResponseBody
public AjaxResult clearCacheKey(String cacheName, String cacheKey, ModelMap mmap)
{
cacheService.clearCacheKey(cacheName, cacheKey);
return AjaxResult.success();
}
@GetMapping("/clearAll")
@ResponseBody
public AjaxResult clearAll(ModelMap mmap)
{
cacheService.clearAll();
return AjaxResult.success();
}
}
@@ -0,0 +1,26 @@
package co.yixiang.web.controller.monitor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import co.yixiang.common.core.controller.BaseController;
/**
* druid 监控
*
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/data")
public class DruidController extends BaseController
{
private String prefix = "/druid";
@RequiresPermissions("monitor:data:view")
@GetMapping()
public String index()
{
return redirect(prefix + "/index.html");
}
}
@@ -0,0 +1,31 @@
package co.yixiang.web.controller.monitor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.framework.web.domain.Server;
/**
* 服务器监控
*
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/server")
public class ServerController extends BaseController
{
private String prefix = "monitor/server";
@RequiresPermissions("monitor:server:view")
@GetMapping()
public String server(ModelMap mmap) throws Exception
{
Server server = new Server();
server.copyTo();
mmap.put("server", server);
return prefix + "/server";
}
}
@@ -0,0 +1,94 @@
package co.yixiang.web.controller.monitor;
import java.util.List;
import co.yixiang.framework.shiro.service.SysPasswordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.system.domain.SysLogininfor;
import co.yixiang.system.service.ISysLogininforService;
/**
* 系统访问记录
*
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController
{
private String prefix = "monitor/logininfor";
@Autowired
private ISysLogininforService logininforService;
@Autowired
private SysPasswordService passwordService;
@RequiresPermissions("monitor:logininfor:view")
@GetMapping()
public String logininfor()
{
return prefix + "/logininfor";
}
@RequiresPermissions("monitor:logininfor:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysLogininfor logininfor)
{
startPage();
List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
return getDataTable(list);
}
@Log(title = "登录日志", businessType = BusinessType.EXPORT)
@RequiresPermissions("monitor:logininfor:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysLogininfor logininfor)
{
List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
return util.exportExcel(list, "登录日志");
}
@RequiresPermissions("monitor:logininfor:remove")
@Log(title = "登录日志", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(logininforService.deleteLogininforByIds(ids));
}
@RequiresPermissions("monitor:logininfor:remove")
@Log(title = "登录日志", businessType = BusinessType.CLEAN)
@PostMapping("/clean")
@ResponseBody
public AjaxResult clean()
{
logininforService.cleanLogininfor();
return success();
}
@RequiresPermissions("monitor:logininfor:unlock")
@Log(title = "账户解锁", businessType = BusinessType.OTHER)
@PostMapping("/unlock")
@ResponseBody
public AjaxResult unlock(String loginName)
{
passwordService.clearLoginRecordCache(loginName);
return success();
}
}
@@ -0,0 +1,90 @@
package co.yixiang.web.controller.monitor;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.system.domain.SysOperLog;
import co.yixiang.system.service.ISysOperLogService;
/**
* 操作日志记录
*
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController
{
private String prefix = "monitor/operlog";
@Autowired
private ISysOperLogService operLogService;
@RequiresPermissions("monitor:operlog:view")
@GetMapping()
public String operlog()
{
return prefix + "/operlog";
}
@RequiresPermissions("monitor:operlog:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysOperLog operLog)
{
startPage();
List<SysOperLog> list = operLogService.selectOperLogList(operLog);
return getDataTable(list);
}
@Log(title = "操作日志", businessType = BusinessType.EXPORT)
@RequiresPermissions("monitor:operlog:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysOperLog operLog)
{
List<SysOperLog> list = operLogService.selectOperLogList(operLog);
ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
return util.exportExcel(list, "操作日志");
}
@Log(title = "操作日志", businessType = BusinessType.DELETE)
@RequiresPermissions("monitor:operlog:remove")
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(operLogService.deleteOperLogByIds(ids));
}
@RequiresPermissions("monitor:operlog:detail")
@GetMapping("/detail/{operId}")
public String detail(@PathVariable("operId") Long operId, ModelMap mmap)
{
mmap.put("operLog", operLogService.selectOperLogById(operId));
return prefix + "/detail";
}
@Log(title = "操作日志", businessType = BusinessType.CLEAN)
@RequiresPermissions("monitor:operlog:remove")
@PostMapping("/clean")
@ResponseBody
public AjaxResult clean()
{
operLogService.cleanOperLog();
return success();
}
}
@@ -0,0 +1,90 @@
package co.yixiang.web.controller.monitor;
import java.util.List;
import co.yixiang.system.service.ISysUserOnlineService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.core.text.Convert;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.enums.OnlineStatus;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.framework.shiro.session.OnlineSession;
import co.yixiang.framework.shiro.session.OnlineSessionDAO;
import co.yixiang.system.domain.SysUserOnline;
import co.yixiang.system.service.ISysUserOnlineService;
/**
* 在线用户监控
*
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/online")
public class SysUserOnlineController extends BaseController
{
private String prefix = "monitor/online";
@Autowired
private ISysUserOnlineService userOnlineService;
@Autowired
private OnlineSessionDAO onlineSessionDAO;
@RequiresPermissions("monitor:online:view")
@GetMapping()
public String online()
{
return prefix + "/online";
}
@RequiresPermissions("monitor:online:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysUserOnline userOnline)
{
startPage();
List<SysUserOnline> list = userOnlineService.selectUserOnlineList(userOnline);
return getDataTable(list);
}
@RequiresPermissions(value = { "monitor:online:batchForceLogout", "monitor:online:forceLogout" }, logical = Logical.OR)
@Log(title = "在线用户", businessType = BusinessType.FORCE)
@PostMapping("/batchForceLogout")
@ResponseBody
public AjaxResult batchForceLogout(String ids)
{
for (String sessionId : Convert.toStrArray(ids))
{
SysUserOnline online = userOnlineService.selectOnlineById(sessionId);
if (online == null)
{
return error("用户已下线");
}
OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
if (onlineSession == null)
{
return error("用户已下线");
}
if (sessionId.equals(ShiroUtils.getSessionId()))
{
return error("当前登录用户无法强退");
}
onlineSessionDAO.delete(onlineSession);
online.setStatus(OnlineStatus.off_line);
userOnlineService.saveOnline(online);
userOnlineService.removeUserCache(online.getLoginName(), sessionId);
}
return success();
}
}
@@ -0,0 +1,125 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreCoupon;
import co.yixiang.shop.service.IStoreCouponService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
/**
* 优惠券主Controller
*
* @author hupeng
* @date 2019-08-29
*/
@Controller
@RequestMapping("/shop/coupon")
public class StoreCouponController extends BaseController
{
private String prefix = "shop/coupon";
@Autowired
private IStoreCouponService storeCouponService;
@RequiresPermissions("shop:coupon:view")
@GetMapping()
public String coupon()
{
return prefix + "/coupon";
}
/**
* 查询优惠券主列表
*/
@RequiresPermissions("shop:coupon:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreCoupon storeCoupon)
{
startPage();
List<StoreCoupon> list = storeCouponService.selectStoreCouponList(storeCoupon);
return getDataTable(list);
}
/**
* 导出优惠券主列表
*/
@RequiresPermissions("shop:coupon:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreCoupon storeCoupon)
{
List<StoreCoupon> list = storeCouponService.selectStoreCouponList(storeCoupon);
ExcelUtil<StoreCoupon> util = new ExcelUtil<StoreCoupon>(StoreCoupon.class);
return util.exportExcel(list, "coupon");
}
/**
* 新增优惠券主
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存优惠券主
*/
@RequiresPermissions("shop:coupon:add")
@Log(title = "优惠券主", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreCoupon storeCoupon)
{
return toAjax(storeCouponService.insertStoreCoupon(storeCoupon));
}
/**
* 修改优惠券主
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap mmap)
{
StoreCoupon storeCoupon = storeCouponService.selectStoreCouponById(id);
mmap.put("storeCoupon", storeCoupon);
return prefix + "/edit";
}
/**
* 修改保存优惠券主
*/
@RequiresPermissions("shop:coupon:edit")
@Log(title = "优惠券主", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreCoupon storeCoupon)
{
return toAjax(storeCouponService.updateStoreCoupon(storeCoupon));
}
/**
* 删除优惠券主
*/
@RequiresPermissions("shop:coupon:remove")
@Log(title = "优惠券主", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeCouponService.deleteStoreCouponByIds(ids));
}
}
@@ -0,0 +1,125 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreGoodsAttribute;
import co.yixiang.shop.service.IStoreGoodsAttributeService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
/**
* 商品的属性(独立)Controller
*
* @author hupeng
* @date 2019-08-24
*/
@Controller
@RequestMapping("/shop/attribute")
public class StoreGoodsAttributeController extends BaseController
{
private String prefix = "shop/attribute";
@Autowired
private IStoreGoodsAttributeService storeGoodsAttributeService;
@RequiresPermissions("shop:attribute:view")
@GetMapping()
public String attribute()
{
return prefix + "/attribute";
}
/**
* 查询商品的属性(独立)列表
*/
@RequiresPermissions("shop:attribute:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreGoodsAttribute storeGoodsAttribute)
{
startPage();
List<StoreGoodsAttribute> list = storeGoodsAttributeService.selectStoreGoodsAttributeList(storeGoodsAttribute);
return getDataTable(list);
}
/**
* 导出商品的属性(独立)列表
*/
@RequiresPermissions("shop:attribute:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreGoodsAttribute storeGoodsAttribute)
{
List<StoreGoodsAttribute> list = storeGoodsAttributeService.selectStoreGoodsAttributeList(storeGoodsAttribute);
ExcelUtil<StoreGoodsAttribute> util = new ExcelUtil<StoreGoodsAttribute>(StoreGoodsAttribute.class);
return util.exportExcel(list, "attribute");
}
/**
* 新增商品的属性(独立)
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存商品的属性(独立)
*/
@RequiresPermissions("shop:attribute:add")
@Log(title = "商品的属性(独立)", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreGoodsAttribute storeGoodsAttribute)
{
return toAjax(storeGoodsAttributeService.insertStoreGoodsAttribute(storeGoodsAttribute));
}
/**
* 修改商品的属性(独立)
*/
@GetMapping("/edit/{attrId}")
public String edit(@PathVariable("attrId") Long attrId, ModelMap mmap)
{
StoreGoodsAttribute storeGoodsAttribute = storeGoodsAttributeService.selectStoreGoodsAttributeById(attrId);
mmap.put("storeGoodsAttribute", storeGoodsAttribute);
return prefix + "/edit";
}
/**
* 修改保存商品的属性(独立)
*/
@RequiresPermissions("shop:attribute:edit")
@Log(title = "商品的属性(独立)", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreGoodsAttribute storeGoodsAttribute)
{
return toAjax(storeGoodsAttributeService.updateStoreGoodsAttribute(storeGoodsAttribute));
}
/**
* 删除商品的属性(独立)
*/
@RequiresPermissions("shop:attribute:remove")
@Log(title = "商品的属性(独立)", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeGoodsAttributeService.deleteStoreGoodsAttributeByIds(ids));
}
}
@@ -0,0 +1,125 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreGoodsBrand;
import co.yixiang.shop.service.IStoreGoodsBrandService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
/**
* 产品品牌Controller
*
* @author hupeng
* @date 2019-08-23
*/
@Controller
@RequestMapping("/shop/brand")
public class StoreGoodsBrandController extends BaseController
{
private String prefix = "shop/brand";
@Autowired
private IStoreGoodsBrandService storeGoodsBrandService;
@RequiresPermissions("shop:brand:view")
@GetMapping()
public String brand()
{
return prefix + "/brand";
}
/**
* 查询产品品牌列表
*/
@RequiresPermissions("shop:brand:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreGoodsBrand storeGoodsBrand)
{
startPage();
List<StoreGoodsBrand> list = storeGoodsBrandService.selectStoreGoodsBrandList(storeGoodsBrand);
return getDataTable(list);
}
/**
* 导出产品品牌列表
*/
@RequiresPermissions("shop:brand:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreGoodsBrand storeGoodsBrand)
{
List<StoreGoodsBrand> list = storeGoodsBrandService.selectStoreGoodsBrandList(storeGoodsBrand);
ExcelUtil<StoreGoodsBrand> util = new ExcelUtil<StoreGoodsBrand>(StoreGoodsBrand.class);
return util.exportExcel(list, "brand");
}
/**
* 新增产品品牌
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存产品品牌
*/
@RequiresPermissions("shop:brand:add")
@Log(title = "产品品牌", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreGoodsBrand storeGoodsBrand)
{
return toAjax(storeGoodsBrandService.insertStoreGoodsBrand(storeGoodsBrand));
}
/**
* 修改产品品牌
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap)
{
StoreGoodsBrand storeGoodsBrand = storeGoodsBrandService.selectStoreGoodsBrandById(id);
mmap.put("storeGoodsBrand", storeGoodsBrand);
return prefix + "/edit";
}
/**
* 修改保存产品品牌
*/
@RequiresPermissions("shop:brand:edit")
@Log(title = "产品品牌", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreGoodsBrand storeGoodsBrand)
{
return toAjax(storeGoodsBrandService.updateStoreGoodsBrand(storeGoodsBrand));
}
/**
* 删除产品品牌
*/
@RequiresPermissions("shop:brand:remove")
@Log(title = "产品品牌", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeGoodsBrandService.deleteStoreGoodsBrandByIds(ids));
}
}
@@ -0,0 +1,153 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreGoodsCate;
import co.yixiang.shop.service.IStoreGoodsCateService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.common.core.domain.Ztree;
/**
* 商城商品分类Controller
*
* @author hupeng
* @date 2019-08-22
*/
@Controller
@RequestMapping("/shop/cate")
public class StoreGoodsCateController extends BaseController
{
private String prefix = "shop/cate";
@Autowired
private IStoreGoodsCateService storeGoodsCateService;
@RequiresPermissions("shop:cate:view")
@GetMapping()
public String cate()
{
return prefix + "/cate";
}
/**
* 查询商城商品分类树列表
*/
@RequiresPermissions("shop:cate:list")
@PostMapping("/list")
@ResponseBody
public List<StoreGoodsCate> list(StoreGoodsCate storeGoodsCate)
{
List<StoreGoodsCate> list = storeGoodsCateService.selectStoreGoodsCateList(storeGoodsCate);
return list;
}
/**
* 导出商城商品分类列表
*/
@RequiresPermissions("shop:cate:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreGoodsCate storeGoodsCate)
{
List<StoreGoodsCate> list = storeGoodsCateService.selectStoreGoodsCateList(storeGoodsCate);
ExcelUtil<StoreGoodsCate> util = new ExcelUtil<StoreGoodsCate>(StoreGoodsCate.class);
return util.exportExcel(list, "cate");
}
/**
* 新增商城商品分类
*/
@GetMapping(value = { "/add/{id}", "/add/" })
public String add(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
{
if (StringUtils.isNotNull(id))
{
mmap.put("storeGoodsCate", storeGoodsCateService.selectStoreGoodsCateById(id));
}
return prefix + "/add";
}
/**
* 新增保存商城商品分类
*/
@RequiresPermissions("shop:cate:add")
@Log(title = "商城商品分类", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreGoodsCate storeGoodsCate)
{
return toAjax(storeGoodsCateService.insertStoreGoodsCate(storeGoodsCate));
}
/**
* 修改商城商品分类
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap)
{
StoreGoodsCate storeGoodsCate = storeGoodsCateService.selectStoreGoodsCateById(id);
mmap.put("storeGoodsCate", storeGoodsCate);
return prefix + "/edit";
}
/**
* 修改保存商城商品分类
*/
@RequiresPermissions("shop:cate:edit")
@Log(title = "商城商品分类", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreGoodsCate storeGoodsCate)
{
return toAjax(storeGoodsCateService.updateStoreGoodsCate(storeGoodsCate));
}
/**
* 删除
*/
@RequiresPermissions("shop:cate:remove")
@Log(title = "商城商品分类", businessType = BusinessType.DELETE)
@GetMapping("/remove/{id}")
@ResponseBody
public AjaxResult remove(@PathVariable("id") Long id)
{
return toAjax(storeGoodsCateService.deleteStoreGoodsCateById(id));
}
/**
* 选择商城商品分类树
*/
@GetMapping(value = { "/selectCateTree/{id}", "/selectCateTree/" })
public String selectCateTree(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
{
if (StringUtils.isNotNull(id))
{
mmap.put("storeGoodsCate", storeGoodsCateService.selectStoreGoodsCateById(id));
}
return prefix + "/tree";
}
/**
* 加载商城商品分类树列表
*/
@GetMapping("/treeData")
@ResponseBody
public List<Ztree> treeData()
{
List<Ztree> ztrees = storeGoodsCateService.selectStoreGoodsCateTree();
return ztrees;
}
}
@@ -0,0 +1,513 @@
package co.yixiang.web.controller.shop;
import java.text.MessageFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import co.yixiang.shop.domain.*;
import co.yixiang.shop.service.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.shop.domain.*;
import co.yixiang.shop.service.*;
import co.yixiang.shop.vo.SpecVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
import javax.servlet.http.HttpServletRequest;
/**
* 商品主Controller
*
* @author hupeng
* @date 2019-08-25
*/
@Controller
@RequestMapping("/shop/goods")
public class StoreGoodsController extends BaseController
{
private String prefix = "shop/goods";
@Autowired
private IStoreGoodsService storeGoodsService;
@Autowired
private IStoreGoodsTypeService storeGoodsTypeService;
@Autowired
private IStoreSpecService storeSpecService;
@Autowired
private IStoreSpecItemService storeSpecItemService;
@Autowired
private IStoreGoodsAttributeService storeGoodsAttributeService;
@Autowired
protected IStoreGoodsAttrService storeGoodsAttrService;
@Autowired
private IStoreSpecGoodsPriceService storeSpecGoodsPriceService;
@Autowired
private IStoreGoodsCateService storeGoodsCateService;
@RequiresPermissions("shop:goods:view")
@GetMapping()
public String goods()
{
return prefix + "/goods";
}
/**
* 查询商品主列表
*/
@RequiresPermissions("shop:goods:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreGoods storeGoods)
{
startPage();
List<StoreGoods> list = storeGoodsService.selectStoreGoodsList(storeGoods);
return getDataTable(list);
}
/**
* 导出商品主列表
*/
@RequiresPermissions("shop:goods:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreGoods storeGoods)
{
List<StoreGoods> list = storeGoodsService.selectStoreGoodsList(storeGoods);
ExcelUtil<StoreGoods> util = new ExcelUtil<StoreGoods>(StoreGoods.class);
return util.exportExcel(list, "goods");
}
/**
* 新增商品主
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存商品主
*/
@RequiresPermissions("shop:goods:add")
@Log(title = "商品主", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreGoods storeGoods)
{
return toAjax(storeGoodsService.insertStoreGoods(storeGoods));
}
/**
*
* @param goodsId
* @param typeId
* @param mmap
* @return
*/
@GetMapping("/editSpec/{goodsId}/{typeId}")
public String editSpecAttr(@PathVariable("goodsId") Integer goodsId,
@PathVariable("typeId") Integer typeId,
ModelMap mmap){
StoreGoods storeGoods = storeGoodsService.selectStoreGoodsById(goodsId);
//StoreGoodsType goodsType = new StoreGoodsType();
//goodsType.setId(typeId);
List<StoreGoodsType> typeList = storeGoodsTypeService.selectStoreGoodsTypeList(null);
//System.out.println(typeList);
mmap.put("storeGoods", storeGoods);
mmap.put("goodsTypes",typeList);
return prefix + "/spec";
}
/**
*
* @param goodsId
* @param typeId
* @return
*/
@PostMapping("/ajaxSpec")
@ResponseBody
public AjaxResult ajaxSpec(@RequestParam(value = "goods_id",defaultValue = "-1") Integer goodsId,
@RequestParam(value = "type_id",defaultValue = "0") Integer typeId){
//System.out.println("typeId:"+typeId);
if(typeId == 0) return AjaxResult.success("success","");
StoreSpec storeSpec = new StoreSpec();
storeSpec.setTypeId(typeId.longValue());
List<StoreSpec> specs = storeSpecService.selectStoreSpecList(storeSpec);
List<StoreSpecItem> specItems = null;
StoreSpecItem specItem = new StoreSpecItem();
for (StoreSpec spec : specs) {
specItem.setSpecId(spec.getId());
specItems = storeSpecItemService.selectStoreSpecItemList(specItem);
//System.out.println("goodsID:"+goodsId);
if(goodsId > 0){
String itemStr = storeGoodsService.getGoodsItems(goodsId.longValue());
if(StringUtils.isNotEmpty(itemStr)){
String[] strs = itemStr.split("_");
for (StoreSpecItem item : specItems) {
if(Arrays.asList(strs).contains(item.getId().toString())){
item.setSelected(true);
}
}
}
}
spec.setStoreSpecItems(specItems);
}
HashMap<String,Object> map = new HashMap<>();
map.put("data",specs);
//System.out.println(specs);
return AjaxResult.success("success",map);
}
/**
*
* @param goodsId
* @param typeId
* @return
*/
@PostMapping("/ajaxGetAttrInput")
@ResponseBody
public AjaxResult ajaxGetAttrInput(@RequestParam(value = "goods_id",defaultValue = "0") Integer goodsId,
@RequestParam(value = "type_id",defaultValue = "0") Integer typeId){
if(typeId == 0) return AjaxResult.success("success","");
StoreGoodsAttribute attribute = new StoreGoodsAttribute();
attribute.setTypeId(typeId);
List<StoreGoodsAttribute> attributeList = storeGoodsAttributeService
.selectStoreGoodsAttributeList(attribute);
//System.out.println("attributeList:"+attributeList);
String str = "";
StoreGoodsAttr storeGoodsAttr = null;
StoreGoodsAttr goodsAttrOption = new StoreGoodsAttr();
goodsAttrOption.setGoodsId(goodsId);
StringBuilder stringBuilder = new StringBuilder();
for (StoreGoodsAttribute attr : attributeList) {
goodsAttrOption.setAttrId(attr.getAttrId().intValue());
List<StoreGoodsAttr> goodsAttrList = storeGoodsAttrService
.selectStoreGoodsAttrList(goodsAttrOption);
if(goodsAttrList.isEmpty()){
StoreGoodsAttr emptyAttr = new StoreGoodsAttr();
emptyAttr.setGoodsId(0);
emptyAttr.setAttrId(0);
emptyAttr.setGoodsAttrId(0);
emptyAttr.setAttrValue("无");
emptyAttr.setAttrPrice("");
goodsAttrList.add(emptyAttr);
}
for (StoreGoodsAttr goodsAttr : goodsAttrList) {
//str = String.format("<tr class='attr_{}'>",attr.getAttrId());
stringBuilder.append(MessageFormat.format("<tr class=attr_{0}>",attr.getAttrId()));
//System.out.println(attr.getAttrId());
stringBuilder.append(MessageFormat.format("<td>{0}</td> <td>",attr.getAttrName()));
stringBuilder.append(MessageFormat.format("<input class='layui-input' type='text' size='40' value={0} name=attr_{1}[] />",
goodsAttr.getAttrValue(),attr.getAttrId()));
stringBuilder.append("</td></tr>");
}
}
str = stringBuilder.toString();
return AjaxResult.success("success",str);
}
@PostMapping("/ajaxGetSpecInput")
@ResponseBody
public AjaxResult ajaxGetSpecInput(@RequestBody String jsonStr){
SpecVO data=JSON.parseObject(jsonStr,SpecVO.class);
//Map<String,Object> map = (Map<String,Object>)jsonObject;
Map<String,List<Integer>> map2 = new HashMap<>();
//重新组合map有相同键值的组合成list
for (String str : data.getList()) {
Map<String,Object> map = (Map<String,Object>)JSONObject.parseObject(str);
String newKey = map.get("specId").toString();
String newValue = map.get("itemId").toString();
List<Integer> tmpList = new ArrayList<>();
if(map2.containsKey(newKey)){
tmpList = map2.get(newKey);
tmpList.add(Integer.parseInt(newValue));
map2.put(newKey,tmpList);
}else{
tmpList.add(Integer.parseInt(newValue));
map2.put(newKey,tmpList);
}
}
Iterator<Map.Entry<String, List<Integer>>> it = map2.entrySet().iterator();
Map<String, Integer> unsortMap =
new HashMap<String, Integer>();
//迭代map把原来值换成列表大小
while (it.hasNext()){
Map.Entry<String, List<Integer>> entry = it.next();
unsortMap.put(entry.getKey(),entry.getValue().size());
}
//定义一个有序的列表map
Map<String, Integer> sortMap = new LinkedHashMap<>();
//升序排序
Stream<Map.Entry<String, Integer>> st = unsortMap.entrySet().stream();
st.sorted(Comparator.comparing(e -> e.getValue()))
.forEachOrdered(e -> sortMap.put(e.getKey(), e.getValue()));
//根据排序后组合最终的MAP
Map<String, List<Integer>> finalMap = new LinkedHashMap<>();
for(String key : sortMap.keySet()){
finalMap.put(key,map2.get(key));
}
//列表笛卡儿积
ArrayList ls = new ArrayList();
for(List<Integer> value : finalMap.values()){
ls.add(value);
}
if(ls.isEmpty()) return AjaxResult.success("success","");
List Dlist = StringUtils.Dikaerji0(ls);
//todo 组合数据
String str = "<table class='table table-bordered' id='spec_input_tab'><tr>";;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(str);
for(String key : finalMap.keySet()){
StoreSpec storeSpec = storeSpecService
.selectStoreSpecById(Long.valueOf(key));
stringBuilder.append(MessageFormat.format("<td><b>{0}</b></td>",
storeSpec.getName()));
}
stringBuilder.append("<td><b>进货价</b></td><td><b>零售价</b></td><td><b>库存</b></td><td><b>操作</b></td></tr>");
//获取商品规格列表
StoreSpecGoodsPrice storeSpecGoodsPrice = new StoreSpecGoodsPrice();
storeSpecGoodsPrice.setGoodsId(Long.valueOf(data.getGoodsId()));
//开始迭代笛卡儿积
Iterator<ArrayList> iter = Dlist.iterator();
while (iter.hasNext()) {
//System.out.println(iter.next());
List<String> itemName = new ArrayList<>();
stringBuilder.append("<tr>");
List<Integer> iterList = iter.next();
Collections.sort(iterList);
iterList.forEach(item-> {
StoreSpecItem storeSpecItem = storeSpecItemService
.selectStoreSpecItemById(Long.valueOf(item.toString()));
stringBuilder.append(MessageFormat.format("<td>{0}</td>",
storeSpecItem.getItem()));
StoreSpec storeSpec2 = storeSpecService
.selectStoreSpecById(Long.valueOf(storeSpecItem.getSpecId()));
itemName.add(storeSpec2.getName()+":"+storeSpecItem.getItem());
});
String itemKeyStr = org.apache.commons.lang.StringUtils.join(iterList.toArray(), "_");
String itemNameStr = org.apache.commons.lang.StringUtils.join(itemName.toArray(), ",");
//while (iter.next().forEach();)
double keyPrice = 0;
double keyMarketPrice = 0;
int keyStoreCount = 0;
//获取商品规格价格列表
storeSpecGoodsPrice.setKey(itemKeyStr);
List<StoreSpecGoodsPrice> storeSpecGoodsPrices = storeSpecGoodsPriceService
.selectStoreSpecGoodsPriceList(storeSpecGoodsPrice);
//System.out.println(storeSpecGoodsPrices);
if(!storeSpecGoodsPrices.isEmpty()){
StoreSpecGoodsPrice goodsPrice = storeSpecGoodsPrices.get(0);
if(goodsPrice != null){
keyPrice = goodsPrice.getPrice();
keyMarketPrice = goodsPrice.getMarketPrice();
keyStoreCount = goodsPrice.getStoreCount().intValue();
}
}
stringBuilder.append(MessageFormat.format("<td><input name=item[{0}][price] value={1} /></td>",
itemKeyStr,String.valueOf(keyPrice)));
stringBuilder.append(MessageFormat.format("<td><input name=item[{0}][market_price] value={1} /></td>",
itemKeyStr,String.valueOf(keyMarketPrice)));
stringBuilder.append(MessageFormat.format("<td><input name=item[{0}][store_count] value={1} /></td>",
itemKeyStr,String.valueOf(keyStoreCount)));
stringBuilder.append(MessageFormat.format("<td>无<input type='hidden' name=item[{0}][key_name] value={1} /></td>",
itemKeyStr,itemNameStr));
stringBuilder.append("</tr>");
//System.out.println(storeSpecGoodsPrices);
}
stringBuilder.append("</table>");
//str = stringBuilder.toString();
return AjaxResult.success("success",stringBuilder.toString());
//return null;
}
@PostMapping("/saveSpecAttr")
@ResponseBody
public AjaxResult saveSpecAttr(HttpServletRequest request){
//获取所有表单参数
Enumeration<String> paramNames = request.getParameterNames();
Map<String,Map<String,String>> specDataMap = new HashMap<>();
Map<String,String> attrDataMap = new HashMap<>();
Map<String,String> tmpMap = null;
String goodsId = request.getParameter("goodsId");
String goodsType = request.getParameter("type_id");
if(StringUtils.isEmpty(goodsId) || Integer.valueOf(goodsId) == 0){
return AjaxResult.error("参数有误");
}
if(StringUtils.isEmpty(goodsType) || Integer.valueOf(goodsType) == 0){
return AjaxResult.error("请选择模型");
}
//过滤参数
while (paramNames.hasMoreElements()) {
String name = paramNames.nextElement();
String[] values = request.getParameterValues(name);
if(values != null && values.length > 0){
StringBuilder builder = new StringBuilder();
for (int i = 0; i < values.length; i++) {
builder.append(values[i]+" ");
}
//过滤规格组合新的规格数据集合
if(name.contains("item")){
String pattern = "item\\[(\\d+[_\\d+]*)]\\[([a-z]+_?[a-z]+)]";
//String pattern = "item\\[(\\d+_\\d+)]\\[([a-z]+_?[a-z]+)]";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(name);
if (m.find( )) {
String keyOne = m.group(1).trim();
System.out.println("keyOne:"+keyOne);
String keyTwo = m.group(2).trim();
System.out.println("keyTwo:"+keyTwo);
String keyValue = builder.toString().trim();
if(!specDataMap.containsKey(keyOne)){
tmpMap = new HashMap<>();
}
tmpMap.put(keyTwo,keyValue);
specDataMap.put(keyOne,tmpMap);
}
}
//过滤属性组合新的属性集合
if(name.contains("attr_")){
String pattern2= "attr_(\\d+)\\[]";
Pattern r2 = Pattern.compile(pattern2);
Matcher m2 = r2.matcher(name);
//System.out.println(name+" : "+builder.toString());
if (m2.find( )) {
attrDataMap.put(m2.group(1),builder.toString().trim());
}else{
System.out.println("no");
}
}
}
}
if(specDataMap.isEmpty()){
return AjaxResult.error("请选择规格项目");
}
if(attrDataMap.isEmpty()){
return AjaxResult.error("请填写商品属性");
}
storeGoodsService.saveSpecAttr(specDataMap,attrDataMap,goodsId,goodsType);
return AjaxResult.success("操作成功");
}
/**
* 修改商品主
*/
@GetMapping("/edit/{goodsId}")
public String edit(@PathVariable("goodsId") Integer goodsId, ModelMap mmap)
{
StoreGoods storeGoods = storeGoodsService.selectStoreGoodsById(goodsId);
StoreGoodsCate storeGoodsCate = storeGoodsCateService
.selectStoreGoodsCateById(storeGoods.getCateId());
storeGoods.setCateName(storeGoodsCate.getCateTitle());
mmap.put("storeGoods", storeGoods);
return prefix + "/edit";
}
/**
* 修改保存商品主
*/
@RequiresPermissions("shop:goods:edit")
@Log(title = "商品主", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreGoods storeGoods)
{
return toAjax(storeGoodsService.updateStoreGoods(storeGoods));
}
/**
* 删除商品主
*/
@RequiresPermissions("shop:goods:remove")
@Log(title = "商品主", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeGoodsService.deleteStoreGoodsByIds(ids));
}
@PostMapping( "/changeStatus")
@ResponseBody
public AjaxResult changeStatus(StoreGoods storeGoods){
return toAjax(storeGoodsService.updateStoreGoods(storeGoods));
}
}
@@ -0,0 +1,125 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreGoodsType;
import co.yixiang.shop.service.IStoreGoodsTypeService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
/**
* 商品类型(商品模型)Controller
*
* @author hupeng
* @date 2019-08-24
*/
@Controller
@RequestMapping("/shop/type")
public class StoreGoodsTypeController extends BaseController
{
private String prefix = "shop/type";
@Autowired
private IStoreGoodsTypeService storeGoodsTypeService;
@RequiresPermissions("shop:type:view")
@GetMapping()
public String type()
{
return prefix + "/type";
}
/**
* 查询商品类型(商品模型)列表
*/
@RequiresPermissions("shop:type:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreGoodsType storeGoodsType)
{
startPage();
List<StoreGoodsType> list = storeGoodsTypeService.selectStoreGoodsTypeList(storeGoodsType);
return getDataTable(list);
}
/**
* 导出商品类型(商品模型)列表
*/
@RequiresPermissions("shop:type:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreGoodsType storeGoodsType)
{
List<StoreGoodsType> list = storeGoodsTypeService.selectStoreGoodsTypeList(storeGoodsType);
ExcelUtil<StoreGoodsType> util = new ExcelUtil<StoreGoodsType>(StoreGoodsType.class);
return util.exportExcel(list, "type");
}
/**
* 新增商品类型(商品模型)
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存商品类型(商品模型)
*/
@RequiresPermissions("shop:type:add")
@Log(title = "商品类型(商品模型)", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreGoodsType storeGoodsType)
{
return toAjax(storeGoodsTypeService.insertStoreGoodsType(storeGoodsType));
}
/**
* 修改商品类型(商品模型)
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap mmap)
{
StoreGoodsType storeGoodsType = storeGoodsTypeService.selectStoreGoodsTypeById(id);
mmap.put("storeGoodsType", storeGoodsType);
return prefix + "/edit";
}
/**
* 修改保存商品类型(商品模型)
*/
@RequiresPermissions("shop:type:edit")
@Log(title = "商品类型(商品模型)", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreGoodsType storeGoodsType)
{
return toAjax(storeGoodsTypeService.updateStoreGoodsType(storeGoodsType));
}
/**
* 删除商品类型(商品模型)
*/
@RequiresPermissions("shop:type:remove")
@Log(title = "商品类型(商品模型)", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeGoodsTypeService.deleteStoreGoodsTypeByIds(ids));
}
}
@@ -0,0 +1,125 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreMember;
import co.yixiang.shop.service.IStoreMemberService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
/**
* 商城会员信息Controller
*
* @author hupeng
* @date 2019-08-30
*/
@Controller
@RequestMapping("/shop/member")
public class StoreMemberController extends BaseController
{
private String prefix = "shop/member";
@Autowired
private IStoreMemberService storeMemberService;
@RequiresPermissions("shop:member:view")
@GetMapping()
public String member()
{
return prefix + "/member";
}
/**
* 查询商城会员信息列表
*/
@RequiresPermissions("shop:member:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreMember storeMember)
{
startPage();
List<StoreMember> list = storeMemberService.selectStoreMemberList(storeMember);
return getDataTable(list);
}
/**
* 导出商城会员信息列表
*/
@RequiresPermissions("shop:member:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreMember storeMember)
{
List<StoreMember> list = storeMemberService.selectStoreMemberList(storeMember);
ExcelUtil<StoreMember> util = new ExcelUtil<StoreMember>(StoreMember.class);
return util.exportExcel(list, "member");
}
/**
* 新增商城会员信息
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存商城会员信息
*/
@RequiresPermissions("shop:member:add")
@Log(title = "商城会员信息", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreMember storeMember)
{
return toAjax(storeMemberService.insertStoreMember(storeMember));
}
/**
* 修改商城会员信息
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap)
{
StoreMember storeMember = storeMemberService.selectStoreMemberById(id);
mmap.put("storeMember", storeMember);
return prefix + "/edit";
}
/**
* 修改保存商城会员信息
*/
@RequiresPermissions("shop:member:edit")
@Log(title = "商城会员信息", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreMember storeMember)
{
return toAjax(storeMemberService.updateStoreMember(storeMember));
}
/**
* 删除商城会员信息
*/
@RequiresPermissions("shop:member:remove")
@Log(title = "商城会员信息", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeMemberService.deleteStoreMemberByIds(ids));
}
}
@@ -0,0 +1,182 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreOrder;
import co.yixiang.shop.service.IStoreOrderService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
/**
* 订单主Controller
*
* @author hupeng
* @date 2019-08-29
*/
@Controller
@RequestMapping("/shop/order")
public class StoreOrderController extends BaseController
{
private String prefix = "shop/order";
@Autowired
private IStoreOrderService storeOrderService;
@RequiresPermissions("shop:order:view")
@GetMapping()
public String order()
{
return prefix + "/order";
}
/**
* 查询订单主列表
*/
@RequiresPermissions("shop:order:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreOrder storeOrder)
{
startPage();
if(storeOrder.getOrderStatus() != null){
switch (storeOrder.getOrderStatus()){
case -1:
storeOrder.setDeleted(1);
storeOrder.setOrderStatus(0);
storeOrder.setPayStatus(0);
storeOrder.setShippingStatus(0);
break;
case 0:
storeOrder.setDeleted(0);
storeOrder.setOrderStatus(0);
storeOrder.setPayStatus(0);
storeOrder.setShippingStatus(0);
break;
case 1:
storeOrder.setDeleted(0);
storeOrder.setPayStatus(1);
storeOrder.setOrderStatus(0);
storeOrder.setShippingStatus(0);
break;
case 2:
storeOrder.setDeleted(0);
storeOrder.setPayStatus(1);
storeOrder.setOrderStatus(0);
storeOrder.setShippingStatus(1);
break;
case 3:
storeOrder.setDeleted(0);
storeOrder.setPayStatus(1);
storeOrder.setOrderStatus(0);
storeOrder.setShippingStatus(2);
break;
case 4:
storeOrder.setDeleted(0);
storeOrder.setPayStatus(1);
storeOrder.setOrderStatus(0);
storeOrder.setShippingStatus(3);
break;
case 5:
storeOrder.setDeleted(0);
storeOrder.setPayStatus(1);
storeOrder.setOrderStatus(1);
storeOrder.setShippingStatus(0);
break;
case 6:
storeOrder.setDeleted(0);
storeOrder.setPayStatus(1);
storeOrder.setOrderStatus(2);
storeOrder.setShippingStatus(0);
break;
}
}
//System.out.println(storeOrder);
List<StoreOrder> list = storeOrderService.selectStoreOrderList(storeOrder);
return getDataTable(list);
}
/**
* 导出订单主列表
*/
@RequiresPermissions("shop:order:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreOrder storeOrder)
{
List<StoreOrder> list = storeOrderService.selectStoreOrderList(storeOrder);
ExcelUtil<StoreOrder> util = new ExcelUtil<StoreOrder>(StoreOrder.class);
return util.exportExcel(list, "order");
}
/**
* 新增订单主
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存订单主
*/
@RequiresPermissions("shop:order:add")
@Log(title = "订单主", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreOrder storeOrder)
{
return toAjax(storeOrderService.insertStoreOrder(storeOrder));
}
/**
* 修改订单主
*/
@GetMapping("/edit/{orderId}")
public String edit(@PathVariable("orderId") Integer orderId, ModelMap mmap)
{
StoreOrder storeOrder = storeOrderService.selectStoreOrderById(orderId);
mmap.put("storeOrder", storeOrder);
return prefix + "/edit";
}
/**
* 修改保存订单主
*/
@RequiresPermissions("shop:order:edit")
@Log(title = "订单主", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated StoreOrder storeOrder)
{
return toAjax(storeOrderService.updateStoreOrder(storeOrder));
}
/**
* 删除订单主
*/
@RequiresPermissions("shop:order:remove")
@Log(title = "订单主", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeOrderService.deleteStoreOrderByIds(ids));
}
}
@@ -0,0 +1,125 @@
package co.yixiang.web.controller.shop;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreSpec;
import co.yixiang.shop.service.IStoreSpecService;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.common.core.page.TableDataInfo;
/**
* 商品规格(独立)Controller
*
* @author hupeng
* @date 2019-08-25
*/
@Controller
@RequestMapping("/shop/spec")
public class StoreSpecController extends BaseController
{
private String prefix = "shop/spec";
@Autowired
private IStoreSpecService storeSpecService;
@RequiresPermissions("shop:spec:view")
@GetMapping()
public String spec()
{
return prefix + "/spec";
}
/**
* 查询商品规格(独立)列表
*/
@RequiresPermissions("shop:spec:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(StoreSpec storeSpec)
{
startPage();
List<StoreSpec> list = storeSpecService.selectStoreSpecList(storeSpec);
return getDataTable(list);
}
/**
* 导出商品规格(独立)列表
*/
@RequiresPermissions("shop:spec:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(StoreSpec storeSpec)
{
List<StoreSpec> list = storeSpecService.selectStoreSpecList(storeSpec);
ExcelUtil<StoreSpec> util = new ExcelUtil<StoreSpec>(StoreSpec.class);
return util.exportExcel(list, "spec");
}
/**
* 新增商品规格(独立)
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存商品规格(独立)
*/
@RequiresPermissions("shop:spec:add")
@Log(title = "商品规格(独立)", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(StoreSpec storeSpec)
{
return toAjax(storeSpecService.insertStoreSpec(storeSpec));
}
/**
* 修改商品规格(独立)
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap)
{
StoreSpec storeSpec = storeSpecService.selectStoreSpecById(id);
mmap.put("storeSpec", storeSpec);
return prefix + "/edit";
}
/**
* 修改保存商品规格(独立)
*/
@RequiresPermissions("shop:spec:edit")
@Log(title = "商品规格(独立)", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(StoreSpec storeSpec)
{
return toAjax(storeSpecService.updateStoreSpec(storeSpec));
}
/**
* 删除商品规格(独立)
*/
@RequiresPermissions("shop:spec:remove")
@Log(title = "商品规格(独立)", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(storeSpecService.deleteStoreSpecByIds(ids));
}
}
@@ -0,0 +1,92 @@
package co.yixiang.web.controller.system;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.Producer;
import co.yixiang.common.core.controller.BaseController;
/**
* 图片验证码(支持算术形式)
*
* @author ruoyi
*/
@Controller
@RequestMapping("/captcha")
public class SysCaptchaController extends BaseController
{
@Resource(name = "captchaProducer")
private Producer captchaProducer;
@Resource(name = "captchaProducerMath")
private Producer captchaProducerMath;
/**
* 验证码生成
*/
@GetMapping(value = "/captchaImage")
public ModelAndView getKaptchaImage(HttpServletRequest request, HttpServletResponse response)
{
ServletOutputStream out = null;
try
{
HttpSession session = request.getSession();
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
String type = request.getParameter("type");
String capStr = null;
String code = null;
BufferedImage bi = null;
if ("math".equals(type))
{
String capText = captchaProducerMath.createText();
capStr = capText.substring(0, capText.lastIndexOf("@"));
code = capText.substring(capText.lastIndexOf("@") + 1);
bi = captchaProducerMath.createImage(capStr);
}
else if ("char".equals(type))
{
capStr = code = captchaProducer.createText();
bi = captchaProducer.createImage(capStr);
}
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, code);
out = response.getOutputStream();
ImageIO.write(bi, "jpg", out);
out.flush();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
return null;
}
}
@@ -0,0 +1,159 @@
package co.yixiang.web.controller.system;
import java.util.List;
import co.yixiang.system.service.ISysConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.system.domain.SysConfig;
/**
* 参数配置 信息操作处理
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/config")
public class SysConfigController extends BaseController
{
private String prefix = "system/config";
@Autowired
private ISysConfigService configService;
@RequiresPermissions("system:config:view")
@GetMapping()
public String config()
{
return prefix + "/config";
}
/**
* 查询参数配置列表
*/
@RequiresPermissions("system:config:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysConfig config)
{
startPage();
List<SysConfig> list = configService.selectConfigList(config);
return getDataTable(list);
}
@Log(title = "参数管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:config:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysConfig config)
{
List<SysConfig> list = configService.selectConfigList(config);
ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);
return util.exportExcel(list, "参数数据");
}
/**
* 新增参数配置
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存参数配置
*/
@RequiresPermissions("system:config:add")
@Log(title = "参数管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysConfig config)
{
if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setCreateBy(ShiroUtils.getLoginName());
return toAjax(configService.insertConfig(config));
}
/**
* 修改参数配置
*/
@GetMapping("/edit/{configId}")
public String edit(@PathVariable("configId") Long configId, ModelMap mmap)
{
mmap.put("config", configService.selectConfigById(configId));
return prefix + "/edit";
}
/**
* 修改保存参数配置
*/
@RequiresPermissions("system:config:edit")
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysConfig config)
{
if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setUpdateBy(ShiroUtils.getLoginName());
return toAjax(configService.updateConfig(config));
}
/**
* 删除参数配置
*/
@RequiresPermissions("system:config:remove")
@Log(title = "参数管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
configService.deleteConfigByIds(ids);
return success();
}
/**
* 刷新参数缓存
*/
@RequiresPermissions("system:config:remove")
@Log(title = "参数管理", businessType = BusinessType.CLEAN)
@GetMapping("/refreshCache")
@ResponseBody
public AjaxResult refreshCache()
{
configService.resetConfigCache();
return success();
}
/**
* 校验参数键名
*/
@PostMapping("/checkConfigKeyUnique")
@ResponseBody
public String checkConfigKeyUnique(SysConfig config)
{
return configService.checkConfigKeyUnique(config);
}
}
@@ -0,0 +1,209 @@
package co.yixiang.web.controller.system;
import java.util.List;
import co.yixiang.system.service.ISysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.Ztree;
import co.yixiang.common.core.domain.entity.SysDept;
import co.yixiang.common.core.domain.entity.SysRole;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.system.service.ISysDeptService;
/**
* 部门信息
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/dept")
public class SysDeptController extends BaseController
{
private String prefix = "system/dept";
@Autowired
private ISysDeptService deptService;
@RequiresPermissions("system:dept:view")
@GetMapping()
public String dept()
{
return prefix + "/dept";
}
@RequiresPermissions("system:dept:list")
@PostMapping("/list")
@ResponseBody
public List<SysDept> list(SysDept dept)
{
List<SysDept> deptList = deptService.selectDeptList(dept);
return deptList;
}
/**
* 新增部门
*/
@GetMapping("/add/{parentId}")
public String add(@PathVariable("parentId") Long parentId, ModelMap mmap)
{
if (!ShiroUtils.getSysUser().isAdmin())
{
parentId = ShiroUtils.getSysUser().getDeptId();
}
mmap.put("dept", deptService.selectDeptById(parentId));
return prefix + "/add";
}
/**
* 新增保存部门
*/
@Log(title = "部门管理", businessType = BusinessType.INSERT)
@RequiresPermissions("system:dept:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysDept dept)
{
if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
dept.setCreateBy(ShiroUtils.getLoginName());
return toAjax(deptService.insertDept(dept));
}
/**
* 修改
*/
@GetMapping("/edit/{deptId}")
public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap)
{
SysDept dept = deptService.selectDeptById(deptId);
if (StringUtils.isNotNull(dept) && 100L == deptId)
{
dept.setParentName("无");
}
mmap.put("dept", dept);
return prefix + "/edit";
}
/**
* 保存
*/
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:dept:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysDept dept)
{
if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
else if (dept.getParentId().equals(dept.getDeptId()))
{
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
}
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
&& deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
{
return AjaxResult.error("该部门包含未停用的子部门!");
}
dept.setUpdateBy(ShiroUtils.getLoginName());
return toAjax(deptService.updateDept(dept));
}
/**
* 删除
*/
@Log(title = "部门管理", businessType = BusinessType.DELETE)
@RequiresPermissions("system:dept:remove")
@GetMapping("/remove/{deptId}")
@ResponseBody
public AjaxResult remove(@PathVariable("deptId") Long deptId)
{
if (deptService.selectDeptCount(deptId) > 0)
{
return AjaxResult.warn("存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId))
{
return AjaxResult.warn("部门存在用户,不允许删除");
}
return toAjax(deptService.deleteDeptById(deptId));
}
/**
* 校验部门名称
*/
@PostMapping("/checkDeptNameUnique")
@ResponseBody
public String checkDeptNameUnique(SysDept dept)
{
return deptService.checkDeptNameUnique(dept);
}
/**
* 选择部门树
*
* @param deptId 部门ID
* @param excludeId 排除ID
*/
@GetMapping(value = { "/selectDeptTree/{deptId}", "/selectDeptTree/{deptId}/{excludeId}" })
public String selectDeptTree(@PathVariable("deptId") Long deptId,
@PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap)
{
mmap.put("dept", deptService.selectDeptById(deptId));
mmap.put("excludeId", excludeId);
return prefix + "/tree";
}
/**
* 加载部门列表树
*/
@GetMapping("/treeData")
@ResponseBody
public List<Ztree> treeData()
{
List<Ztree> ztrees = deptService.selectDeptTree(new SysDept());
return ztrees;
}
/**
* 加载部门列表树(排除下级)
*/
@GetMapping("/treeData/{excludeId}")
@ResponseBody
public List<Ztree> treeDataExcludeChild(@PathVariable(value = "excludeId", required = false) Long excludeId)
{
SysDept dept = new SysDept();
dept.setDeptId(excludeId);
List<Ztree> ztrees = deptService.selectDeptTreeExcludeChild(dept);
return ztrees;
}
/**
* 加载角色部门(数据权限)列表树
*/
@GetMapping("/roleDeptTreeData")
@ResponseBody
public List<Ztree> deptTreeData(SysRole role)
{
List<Ztree> ztrees = deptService.roleDeptTreeData(role);
return ztrees;
}
}
@@ -0,0 +1,123 @@
package co.yixiang.web.controller.system;
import java.util.List;
import co.yixiang.system.service.ISysDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.entity.SysDictData;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.system.service.ISysDictDataService;
/**
* 数据字典信息
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController
{
private String prefix = "system/dict/data";
@Autowired
private ISysDictDataService dictDataService;
@RequiresPermissions("system:dict:view")
@GetMapping()
public String dictData()
{
return prefix + "/data";
}
@PostMapping("/list")
@RequiresPermissions("system:dict:list")
@ResponseBody
public TableDataInfo list(SysDictData dictData)
{
startPage();
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
return getDataTable(list);
}
@Log(title = "字典数据", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:dict:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysDictData dictData)
{
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
return util.exportExcel(list, "字典数据");
}
/**
* 新增字典类型
*/
@GetMapping("/add/{dictType}")
public String add(@PathVariable("dictType") String dictType, ModelMap mmap)
{
mmap.put("dictType", dictType);
return prefix + "/add";
}
/**
* 新增保存字典类型
*/
@Log(title = "字典数据", businessType = BusinessType.INSERT)
@RequiresPermissions("system:dict:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysDictData dict)
{
dict.setCreateBy(ShiroUtils.getLoginName());
return toAjax(dictDataService.insertDictData(dict));
}
/**
* 修改字典类型
*/
@GetMapping("/edit/{dictCode}")
public String edit(@PathVariable("dictCode") Long dictCode, ModelMap mmap)
{
mmap.put("dict", dictDataService.selectDictDataById(dictCode));
return prefix + "/edit";
}
/**
* 修改保存字典类型
*/
@Log(title = "字典数据", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:dict:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysDictData dict)
{
dict.setUpdateBy(ShiroUtils.getLoginName());
return toAjax(dictDataService.updateDictData(dict));
}
@Log(title = "字典数据", businessType = BusinessType.DELETE)
@RequiresPermissions("system:dict:remove")
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
dictDataService.deleteDictDataByIds(ids);
return success();
}
}
@@ -0,0 +1,190 @@
package co.yixiang.web.controller.system;
import java.util.List;
import co.yixiang.system.service.ISysDictTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.Ztree;
import co.yixiang.common.core.domain.entity.SysDictType;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
/**
* 数据字典信息
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/dict")
public class SysDictTypeController extends BaseController
{
private String prefix = "system/dict/type";
@Autowired
private ISysDictTypeService dictTypeService;
@RequiresPermissions("system:dict:view")
@GetMapping()
public String dictType()
{
return prefix + "/type";
}
@PostMapping("/list")
@RequiresPermissions("system:dict:list")
@ResponseBody
public TableDataInfo list(SysDictType dictType)
{
startPage();
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
return getDataTable(list);
}
@Log(title = "字典类型", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:dict:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysDictType dictType)
{
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
ExcelUtil<SysDictType> util = new ExcelUtil<SysDictType>(SysDictType.class);
return util.exportExcel(list, "字典类型");
}
/**
* 新增字典类型
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存字典类型
*/
@Log(title = "字典类型", businessType = BusinessType.INSERT)
@RequiresPermissions("system:dict:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysDictType dict)
{
if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
{
return error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
dict.setCreateBy(ShiroUtils.getLoginName());
return toAjax(dictTypeService.insertDictType(dict));
}
/**
* 修改字典类型
*/
@GetMapping("/edit/{dictId}")
public String edit(@PathVariable("dictId") Long dictId, ModelMap mmap)
{
mmap.put("dict", dictTypeService.selectDictTypeById(dictId));
return prefix + "/edit";
}
/**
* 修改保存字典类型
*/
@Log(title = "字典类型", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:dict:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysDictType dict)
{
if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
{
return error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
dict.setUpdateBy(ShiroUtils.getLoginName());
return toAjax(dictTypeService.updateDictType(dict));
}
@Log(title = "字典类型", businessType = BusinessType.DELETE)
@RequiresPermissions("system:dict:remove")
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
dictTypeService.deleteDictTypeByIds(ids);
return success();
}
/**
* 刷新字典缓存
*/
@RequiresPermissions("system:dict:remove")
@Log(title = "字典类型", businessType = BusinessType.CLEAN)
@GetMapping("/refreshCache")
@ResponseBody
public AjaxResult refreshCache()
{
dictTypeService.resetDictCache();
return success();
}
/**
* 查询字典详细
*/
@RequiresPermissions("system:dict:list")
@GetMapping("/detail/{dictId}")
public String detail(@PathVariable("dictId") Long dictId, ModelMap mmap)
{
mmap.put("dict", dictTypeService.selectDictTypeById(dictId));
mmap.put("dictList", dictTypeService.selectDictTypeAll());
return "system/dict/data/data";
}
/**
* 校验字典类型
*/
@PostMapping("/checkDictTypeUnique")
@ResponseBody
public String checkDictTypeUnique(SysDictType dictType)
{
return dictTypeService.checkDictTypeUnique(dictType);
}
/**
* 选择字典树
*/
@GetMapping("/selectDictTree/{columnId}/{dictType}")
public String selectDeptTree(@PathVariable("columnId") Long columnId, @PathVariable("dictType") String dictType,
ModelMap mmap)
{
mmap.put("columnId", columnId);
mmap.put("dict", dictTypeService.selectDictTypeByType(dictType));
return prefix + "/tree";
}
/**
* 加载字典列表树
*/
@GetMapping("/treeData")
@ResponseBody
public List<Ztree> treeData()
{
List<Ztree> ztrees = dictTypeService.selectDictTree(new SysDictType());
return ztrees;
}
}
@@ -0,0 +1,157 @@
package co.yixiang.web.controller.system;
import java.util.Date;
import java.util.List;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import co.yixiang.system.service.ISysConfigService;
import co.yixiang.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.config.RuoYiConfig;
import co.yixiang.common.constant.ShiroConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.entity.SysMenu;
import co.yixiang.common.core.domain.entity.SysUser;
import co.yixiang.common.core.text.Convert;
import co.yixiang.common.utils.CookieUtils;
import co.yixiang.common.utils.DateUtils;
import co.yixiang.common.utils.ServletUtils;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.framework.shiro.service.SysPasswordService;
/**
* 首页 业务处理
*
* @author ruoyi
*/
@Controller
public class SysIndexController extends BaseController
{
@Autowired
private ISysMenuService menuService;
@Autowired
private ISysConfigService configService;
@Autowired
private SysPasswordService passwordService;
// 系统首页
@GetMapping("/index")
public String index(ModelMap mmap)
{
// 取身份信息
SysUser user = ShiroUtils.getSysUser();
// 根据用户id取出菜单
List<SysMenu> menus = menuService.selectMenusByUser(user);
mmap.put("menus", menus);
mmap.put("user", user);
mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme"));
mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName"));
mmap.put("ignoreFooter", configService.selectConfigByKey("sys.index.ignoreFooter"));
mmap.put("copyrightYear", RuoYiConfig.getCopyrightYear());
mmap.put("demoEnabled", RuoYiConfig.isDemoEnabled());
mmap.put("isDefaultModifyPwd", initPasswordIsModify(user.getPwdUpdateDate()));
mmap.put("isPasswordExpired", passwordIsExpiration(user.getPwdUpdateDate()));
// 菜单导航显示风格
String menuStyle = configService.selectConfigByKey("sys.index.menuStyle");
// 移动端,默认使左侧导航菜单,否则取默认配置
String indexStyle = ServletUtils.checkAgentIsMobile(ServletUtils.getRequest().getHeader("User-Agent")) ? "index" : menuStyle;
// 优先Cookie配置导航菜单
Cookie[] cookies = ServletUtils.getRequest().getCookies();
for (Cookie cookie : cookies)
{
if (StringUtils.isNotEmpty(cookie.getName()) && "nav-style".equalsIgnoreCase(cookie.getName()))
{
indexStyle = cookie.getValue();
break;
}
}
String webIndex = "topnav".equalsIgnoreCase(indexStyle) ? "index-topnav" : "index";
return webIndex;
}
// 锁定屏幕
@GetMapping("/lockscreen")
public String lockscreen(ModelMap mmap)
{
mmap.put("user", ShiroUtils.getSysUser());
ServletUtils.getSession().setAttribute(ShiroConstants.LOCK_SCREEN, true);
return "lock";
}
// 解锁屏幕
@PostMapping("/unlockscreen")
@ResponseBody
public AjaxResult unlockscreen(String password)
{
SysUser user = ShiroUtils.getSysUser();
if (StringUtils.isNull(user))
{
return AjaxResult.error("服务器超时,请重新登陆");
}
if (passwordService.matches(user, password))
{
ServletUtils.getSession().removeAttribute(ShiroConstants.LOCK_SCREEN);
return AjaxResult.success();
}
return AjaxResult.error("密码不正确,请重新输入。");
}
// 切换主题
@GetMapping("/system/switchSkin")
public String switchSkin()
{
return "skin";
}
// 切换菜单
@GetMapping("/system/menuStyle/{style}")
public void menuStyle(@PathVariable String style, HttpServletResponse response)
{
CookieUtils.setCookie(response, "nav-style", style);
}
// 系统介绍
@GetMapping("/system/main")
public String main(ModelMap mmap)
{
mmap.put("version", RuoYiConfig.getVersion());
return "main2";
}
// 检查初始密码是否提醒修改
public boolean initPasswordIsModify(Date pwdUpdateDate)
{
Integer initPasswordModify = Convert.toInt(configService.selectConfigByKey("sys.account.initPasswordModify"));
return initPasswordModify != null && initPasswordModify == 1 && pwdUpdateDate == null;
}
// 检查密码是否过期
public boolean passwordIsExpiration(Date pwdUpdateDate)
{
Integer passwordValidateDays = Convert.toInt(configService.selectConfigByKey("sys.account.passwordValidateDays"));
if (passwordValidateDays != null && passwordValidateDays > 0)
{
if (StringUtils.isNull(pwdUpdateDate))
{
// 如果从未修改过初始密码,直接提醒过期
return true;
}
Date nowDate = DateUtils.getNowDate();
return DateUtils.differentDaysByMillisecond(nowDate, pwdUpdateDate) > passwordValidateDays;
}
return false;
}
}
@@ -0,0 +1,65 @@
package co.yixiang.web.controller.system;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.ServletUtils;
import co.yixiang.common.utils.StringUtils;
/**
* 登录验证
*
* @author ruoyi
*/
@Controller
public class SysLoginController extends BaseController
{
@GetMapping("/login")
public String login(HttpServletRequest request, HttpServletResponse response)
{
// 如果是Ajax请求,返回Json字符串。
if (ServletUtils.isAjaxRequest(request))
{
return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
}
return "login";
}
@PostMapping("/login")
@ResponseBody
public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe)
{
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
Subject subject = SecurityUtils.getSubject();
try
{
subject.login(token);
return success();
}
catch (AuthenticationException e)
{
String msg = "用户或密码错误";
if (StringUtils.isNotEmpty(e.getMessage()))
{
msg = e.getMessage();
}
return error(msg);
}
}
@GetMapping("/unauth")
public String unauth()
{
return "error/unauth";
}
}
@@ -0,0 +1,198 @@
package co.yixiang.web.controller.system;
import java.util.List;
import co.yixiang.system.service.ISysMenuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.Ztree;
import co.yixiang.common.core.domain.entity.SysMenu;
import co.yixiang.common.core.domain.entity.SysRole;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.framework.shiro.util.AuthorizationUtils;
/**
* 菜单信息
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController
{
private String prefix = "system/menu";
@Autowired
private ISysMenuService menuService;
@RequiresPermissions("system:menu:view")
@GetMapping()
public String menu()
{
return prefix + "/menu";
}
@RequiresPermissions("system:menu:list")
@PostMapping("/list")
@ResponseBody
public List<SysMenu> list(SysMenu menu)
{
Long userId = ShiroUtils.getUserId();
List<SysMenu> menuList = menuService.selectMenuList(menu, userId);
return menuList;
}
/**
* 删除菜单
*/
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
@RequiresPermissions("system:menu:remove")
@GetMapping("/remove/{menuId}")
@ResponseBody
public AjaxResult remove(@PathVariable("menuId") Long menuId)
{
if (menuService.selectCountMenuByParentId(menuId) > 0)
{
return AjaxResult.warn("存在子菜单,不允许删除");
}
if (menuService.selectCountRoleMenuByMenuId(menuId) > 0)
{
return AjaxResult.warn("菜单已分配,不允许删除");
}
AuthorizationUtils.clearAllCachedAuthorizationInfo();
return toAjax(menuService.deleteMenuById(menuId));
}
/**
* 新增
*/
@GetMapping("/add/{parentId}")
public String add(@PathVariable("parentId") Long parentId, ModelMap mmap)
{
SysMenu menu = null;
if (0L != parentId)
{
menu = menuService.selectMenuById(parentId);
}
else
{
menu = new SysMenu();
menu.setMenuId(0L);
menu.setMenuName("主目录");
}
mmap.put("menu", menu);
return prefix + "/add";
}
/**
* 新增保存菜单
*/
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
@RequiresPermissions("system:menu:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysMenu menu)
{
if (UserConstants.MENU_NAME_NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
{
return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
menu.setCreateBy(ShiroUtils.getLoginName());
AuthorizationUtils.clearAllCachedAuthorizationInfo();
return toAjax(menuService.insertMenu(menu));
}
/**
* 修改菜单
*/
@GetMapping("/edit/{menuId}")
public String edit(@PathVariable("menuId") Long menuId, ModelMap mmap)
{
mmap.put("menu", menuService.selectMenuById(menuId));
return prefix + "/edit";
}
/**
* 修改保存菜单
*/
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:menu:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysMenu menu)
{
if (UserConstants.MENU_NAME_NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
{
return error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
menu.setUpdateBy(ShiroUtils.getLoginName());
AuthorizationUtils.clearAllCachedAuthorizationInfo();
return toAjax(menuService.updateMenu(menu));
}
/**
* 选择菜单图标
*/
@GetMapping("/icon")
public String icon()
{
return prefix + "/icon";
}
/**
* 校验菜单名称
*/
@PostMapping("/checkMenuNameUnique")
@ResponseBody
public String checkMenuNameUnique(SysMenu menu)
{
return menuService.checkMenuNameUnique(menu);
}
/**
* 加载角色菜单列表树
*/
@GetMapping("/roleMenuTreeData")
@ResponseBody
public List<Ztree> roleMenuTreeData(SysRole role)
{
Long userId = ShiroUtils.getUserId();
List<Ztree> ztrees = menuService.roleMenuTreeData(role, userId);
return ztrees;
}
/**
* 加载所有菜单列表树
*/
@GetMapping("/menuTreeData")
@ResponseBody
public List<Ztree> menuTreeData()
{
Long userId = ShiroUtils.getUserId();
List<Ztree> ztrees = menuService.menuTreeData(userId);
return ztrees;
}
/**
* 选择菜单树
*/
@GetMapping("/selectMenuTree/{menuId}")
public String selectMenuTree(@PathVariable("menuId") Long menuId, ModelMap mmap)
{
mmap.put("menu", menuService.selectMenuById(menuId));
return prefix + "/tree";
}
}
@@ -0,0 +1,112 @@
package co.yixiang.web.controller.system;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.system.domain.SysNotice;
import co.yixiang.system.service.ISysNoticeService;
/**
* 公告 信息操作处理
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController
{
private String prefix = "system/notice";
@Autowired
private ISysNoticeService noticeService;
@RequiresPermissions("system:notice:view")
@GetMapping()
public String notice()
{
return prefix + "/notice";
}
/**
* 查询公告列表
*/
@RequiresPermissions("system:notice:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysNotice notice)
{
startPage();
List<SysNotice> list = noticeService.selectNoticeList(notice);
return getDataTable(list);
}
/**
* 新增公告
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存公告
*/
@RequiresPermissions("system:notice:add")
@Log(title = "通知公告", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(SysNotice notice)
{
notice.setCreateBy(ShiroUtils.getLoginName());
return toAjax(noticeService.insertNotice(notice));
}
/**
* 修改公告
*/
@GetMapping("/edit/{noticeId}")
public String edit(@PathVariable("noticeId") Long noticeId, ModelMap mmap)
{
mmap.put("notice", noticeService.selectNoticeById(noticeId));
return prefix + "/edit";
}
/**
* 修改保存公告
*/
@RequiresPermissions("system:notice:edit")
@Log(title = "通知公告", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(SysNotice notice)
{
notice.setUpdateBy(ShiroUtils.getLoginName());
return toAjax(noticeService.updateNotice(notice));
}
/**
* 删除公告
*/
@RequiresPermissions("system:notice:remove")
@Log(title = "通知公告", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(noticeService.deleteNoticeByIds(ids));
}
}
@@ -0,0 +1,163 @@
package co.yixiang.web.controller.system;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.system.domain.SysPost;
import co.yixiang.system.service.ISysPostService;
/**
* 岗位信息操作处理
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/post")
public class SysPostController extends BaseController
{
private String prefix = "system/post";
@Autowired
private ISysPostService postService;
@RequiresPermissions("system:post:view")
@GetMapping()
public String operlog()
{
return prefix + "/post";
}
@RequiresPermissions("system:post:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysPost post)
{
startPage();
List<SysPost> list = postService.selectPostList(post);
return getDataTable(list);
}
@Log(title = "岗位管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:post:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysPost post)
{
List<SysPost> list = postService.selectPostList(post);
ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
return util.exportExcel(list, "岗位数据");
}
@RequiresPermissions("system:post:remove")
@Log(title = "岗位管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
try
{
return toAjax(postService.deletePostByIds(ids));
}
catch (Exception e)
{
return error(e.getMessage());
}
}
/**
* 新增岗位
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存岗位
*/
@RequiresPermissions("system:post:add")
@Log(title = "岗位管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysPost post)
{
if (UserConstants.POST_NAME_NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
{
return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
}
else if (UserConstants.POST_CODE_NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
{
return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
}
post.setCreateBy(ShiroUtils.getLoginName());
return toAjax(postService.insertPost(post));
}
/**
* 修改岗位
*/
@GetMapping("/edit/{postId}")
public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
{
mmap.put("post", postService.selectPostById(postId));
return prefix + "/edit";
}
/**
* 修改保存岗位
*/
@RequiresPermissions("system:post:edit")
@Log(title = "岗位管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysPost post)
{
if (UserConstants.POST_NAME_NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
{
return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
}
else if (UserConstants.POST_CODE_NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
{
return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
}
post.setUpdateBy(ShiroUtils.getLoginName());
return toAjax(postService.updatePost(post));
}
/**
* 校验岗位名称
*/
@PostMapping("/checkPostNameUnique")
@ResponseBody
public String checkPostNameUnique(SysPost post)
{
return postService.checkPostNameUnique(post);
}
/**
* 校验岗位编码
*/
@PostMapping("/checkPostCodeUnique")
@ResponseBody
public String checkPostCodeUnique(SysPost post)
{
return postService.checkPostCodeUnique(post);
}
}
@@ -0,0 +1,187 @@
package co.yixiang.web.controller.system;
import co.yixiang.system.service.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.config.RuoYiConfig;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.entity.SysUser;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.DateUtils;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.common.utils.file.FileUploadUtils;
import co.yixiang.framework.shiro.service.SysPasswordService;
/**
* 个人信息 业务处理
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/user/profile")
public class SysProfileController extends BaseController
{
private static final Logger log = LoggerFactory.getLogger(SysProfileController.class);
private String prefix = "system/user/profile";
@Autowired
private ISysUserService userService;
@Autowired
private SysPasswordService passwordService;
/**
* 个人信息
*/
@GetMapping()
public String profile(ModelMap mmap)
{
SysUser user = ShiroUtils.getSysUser();
mmap.put("user", user);
mmap.put("roleGroup", userService.selectUserRoleGroup(user.getUserId()));
mmap.put("postGroup", userService.selectUserPostGroup(user.getUserId()));
return prefix + "/profile";
}
@GetMapping("/checkPassword")
@ResponseBody
public boolean checkPassword(String password)
{
SysUser user = ShiroUtils.getSysUser();
if (passwordService.matches(user, password))
{
return true;
}
return false;
}
@GetMapping("/resetPwd")
public String resetPwd(ModelMap mmap)
{
SysUser user = ShiroUtils.getSysUser();
mmap.put("user", userService.selectUserById(user.getUserId()));
return prefix + "/resetPwd";
}
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
@PostMapping("/resetPwd")
@ResponseBody
public AjaxResult resetPwd(String oldPassword, String newPassword)
{
SysUser user = ShiroUtils.getSysUser();
if (!passwordService.matches(user, oldPassword))
{
return error("修改密码失败,旧密码错误");
}
if (passwordService.matches(user, newPassword))
{
return error("新密码不能与旧密码相同");
}
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
user.setPwdUpdateDate(DateUtils.getNowDate());
if (userService.resetUserPwd(user) > 0)
{
ShiroUtils.setSysUser(userService.selectUserById(user.getUserId()));
return success();
}
return error("修改密码异常,请联系管理员");
}
/**
* 修改用户
*/
@GetMapping("/edit")
public String edit(ModelMap mmap)
{
SysUser user = ShiroUtils.getSysUser();
mmap.put("user", userService.selectUserById(user.getUserId()));
return prefix + "/edit";
}
/**
* 修改头像
*/
@GetMapping("/avatar")
public String avatar(ModelMap mmap)
{
SysUser user = ShiroUtils.getSysUser();
mmap.put("user", userService.selectUserById(user.getUserId()));
return prefix + "/avatar";
}
/**
* 修改用户
*/
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/update")
@ResponseBody
public AjaxResult update(SysUser user)
{
SysUser currentUser = ShiroUtils.getSysUser();
currentUser.setUserName(user.getUserName());
currentUser.setEmail(user.getEmail());
currentUser.setPhonenumber(user.getPhonenumber());
currentUser.setSex(user.getSex());
if (StringUtils.isNotEmpty(user.getPhonenumber())
&& UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(currentUser)))
{
return error("修改用户'" + currentUser.getLoginName() + "'失败,手机号码已存在");
}
else if (StringUtils.isNotEmpty(user.getEmail())
&& UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(currentUser)))
{
return error("修改用户'" + currentUser.getLoginName() + "'失败,邮箱账号已存在");
}
if (userService.updateUserInfo(currentUser) > 0)
{
ShiroUtils.setSysUser(userService.selectUserById(currentUser.getUserId()));
return success();
}
return error();
}
/**
* 保存头像
*/
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/updateAvatar")
@ResponseBody
public AjaxResult updateAvatar(@RequestParam("avatarfile") MultipartFile file)
{
SysUser currentUser = ShiroUtils.getSysUser();
try
{
if (!file.isEmpty())
{
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
currentUser.setAvatar(avatar);
if (userService.updateUserInfo(currentUser) > 0)
{
ShiroUtils.setSysUser(userService.selectUserById(currentUser.getUserId()));
return success();
}
}
return error();
}
catch (Exception e)
{
log.error("修改头像失败!", e);
return error(e.getMessage());
}
}
}
@@ -0,0 +1,47 @@
package co.yixiang.web.controller.system;
import co.yixiang.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.entity.SysUser;
import co.yixiang.framework.shiro.service.SysRegisterService;
import co.yixiang.system.service.ISysConfigService;
/**
* 注册验证
*
* @author ruoyi
*/
@Controller
public class SysRegisterController extends BaseController
{
@Autowired
private SysRegisterService registerService;
@Autowired
private ISysConfigService configService;
@GetMapping("/register")
public String register()
{
return "register";
}
@PostMapping("/register")
@ResponseBody
public AjaxResult ajaxRegister(SysUser user)
{
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
{
return error("当前系统没有开启注册功能!");
}
String msg = registerService.register(user);
return StringUtils.isEmpty(msg) ? success() : error(msg);
}
}
@@ -0,0 +1,299 @@
package co.yixiang.web.controller.system;
import java.util.List;
import co.yixiang.system.service.ISysRoleService;
import co.yixiang.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.entity.SysRole;
import co.yixiang.common.core.domain.entity.SysUser;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.framework.shiro.util.AuthorizationUtils;
import co.yixiang.system.domain.SysUserRole;
/**
* 角色信息
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/role")
public class SysRoleController extends BaseController
{
private String prefix = "system/role";
@Autowired
private ISysRoleService roleService;
@Autowired
private ISysUserService userService;
@RequiresPermissions("system:role:view")
@GetMapping()
public String role()
{
return prefix + "/role";
}
@RequiresPermissions("system:role:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysRole role)
{
startPage();
List<SysRole> list = roleService.selectRoleList(role);
return getDataTable(list);
}
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:role:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysRole role)
{
List<SysRole> list = roleService.selectRoleList(role);
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
return util.exportExcel(list, "角色数据");
}
/**
* 新增角色
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存角色
*/
@RequiresPermissions("system:role:add")
@Log(title = "角色管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysRole role)
{
if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
role.setCreateBy(ShiroUtils.getLoginName());
AuthorizationUtils.clearAllCachedAuthorizationInfo();
return toAjax(roleService.insertRole(role));
}
/**
* 修改角色
*/
@GetMapping("/edit/{roleId}")
public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap)
{
mmap.put("role", roleService.selectRoleById(roleId));
return prefix + "/edit";
}
/**
* 修改保存角色
*/
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysRole role)
{
roleService.checkRoleAllowed(role);
if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
role.setUpdateBy(ShiroUtils.getLoginName());
AuthorizationUtils.clearAllCachedAuthorizationInfo();
return toAjax(roleService.updateRole(role));
}
/**
* 角色分配数据权限
*/
@GetMapping("/authDataScope/{roleId}")
public String authDataScope(@PathVariable("roleId") Long roleId, ModelMap mmap)
{
mmap.put("role", roleService.selectRoleById(roleId));
return prefix + "/dataScope";
}
/**
* 保存角色分配数据权限
*/
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/authDataScope")
@ResponseBody
public AjaxResult authDataScopeSave(SysRole role)
{
roleService.checkRoleAllowed(role);
role.setUpdateBy(ShiroUtils.getLoginName());
if (roleService.authDataScope(role) > 0)
{
ShiroUtils.setSysUser(userService.selectUserById(ShiroUtils.getSysUser().getUserId()));
return success();
}
return error();
}
@RequiresPermissions("system:role:remove")
@Log(title = "角色管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(roleService.deleteRoleByIds(ids));
}
/**
* 校验角色名称
*/
@PostMapping("/checkRoleNameUnique")
@ResponseBody
public String checkRoleNameUnique(SysRole role)
{
return roleService.checkRoleNameUnique(role);
}
/**
* 校验角色权限
*/
@PostMapping("/checkRoleKeyUnique")
@ResponseBody
public String checkRoleKeyUnique(SysRole role)
{
return roleService.checkRoleKeyUnique(role);
}
/**
* 选择菜单树
*/
@GetMapping("/selectMenuTree")
public String selectMenuTree()
{
return prefix + "/tree";
}
/**
* 角色状态修改
*/
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:role:edit")
@PostMapping("/changeStatus")
@ResponseBody
public AjaxResult changeStatus(SysRole role)
{
roleService.checkRoleAllowed(role);
return toAjax(roleService.changeStatus(role));
}
/**
* 分配用户
*/
@RequiresPermissions("system:role:edit")
@GetMapping("/authUser/{roleId}")
public String authUser(@PathVariable("roleId") Long roleId, ModelMap mmap)
{
mmap.put("role", roleService.selectRoleById(roleId));
return prefix + "/authUser";
}
/**
* 查询已分配用户角色列表
*/
@RequiresPermissions("system:role:list")
@PostMapping("/authUser/allocatedList")
@ResponseBody
public TableDataInfo allocatedList(SysUser user)
{
startPage();
List<SysUser> list = userService.selectAllocatedList(user);
return getDataTable(list);
}
/**
* 取消授权
*/
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PostMapping("/authUser/cancel")
@ResponseBody
public AjaxResult cancelAuthUser(SysUserRole userRole)
{
return toAjax(roleService.deleteAuthUser(userRole));
}
/**
* 批量取消授权
*/
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PostMapping("/authUser/cancelAll")
@ResponseBody
public AjaxResult cancelAuthUserAll(Long roleId, String userIds)
{
return toAjax(roleService.deleteAuthUsers(roleId, userIds));
}
/**
* 选择用户
*/
@GetMapping("/authUser/selectUser/{roleId}")
public String selectUser(@PathVariable("roleId") Long roleId, ModelMap mmap)
{
mmap.put("role", roleService.selectRoleById(roleId));
return prefix + "/selectUser";
}
/**
* 查询未分配用户角色列表
*/
@RequiresPermissions("system:role:list")
@PostMapping("/authUser/unallocatedList")
@ResponseBody
public TableDataInfo unallocatedList(SysUser user)
{
startPage();
List<SysUser> list = userService.selectUnallocatedList(user);
return getDataTable(list);
}
/**
* 批量选择用户授权
*/
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PostMapping("/authUser/selectAll")
@ResponseBody
public AjaxResult selectAuthUserAll(Long roleId, String userIds)
{
return toAjax(roleService.insertAuthUsers(roleId, userIds));
}
}
@@ -0,0 +1,289 @@
package co.yixiang.web.controller.system;
import java.util.List;
import java.util.stream.Collectors;
import co.yixiang.system.service.ISysRoleService;
import co.yixiang.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import co.yixiang.common.annotation.Log;
import co.yixiang.common.constant.UserConstants;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.domain.entity.SysRole;
import co.yixiang.common.core.domain.entity.SysUser;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.common.utils.ShiroUtils;
import co.yixiang.common.utils.StringUtils;
import co.yixiang.common.utils.poi.ExcelUtil;
import co.yixiang.framework.shiro.service.SysPasswordService;
import co.yixiang.system.service.ISysPostService;
/**
* 用户信息
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/user")
public class SysUserController extends BaseController
{
private String prefix = "system/user";
@Autowired
private ISysUserService userService;
@Autowired
private ISysRoleService roleService;
@Autowired
private ISysPostService postService;
@Autowired
private SysPasswordService passwordService;
@RequiresPermissions("system:user:view")
@GetMapping()
public String user()
{
return prefix + "/user";
}
@RequiresPermissions("system:user:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysUser user)
{
startPage();
List<SysUser> list = userService.selectUserList(user);
return getDataTable(list);
}
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:user:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysUser user)
{
List<SysUser> list = userService.selectUserList(user);
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
return util.exportExcel(list, "用户数据");
}
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@RequiresPermissions("system:user:import")
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
List<SysUser> userList = util.importExcel(file.getInputStream());
String operName = ShiroUtils.getSysUser().getLoginName();
String message = userService.importUser(userList, updateSupport, operName);
return AjaxResult.success(message);
}
@RequiresPermissions("system:user:view")
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate()
{
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
return util.importTemplateExcel("用户数据");
}
/**
* 新增用户
*/
@GetMapping("/add")
public String add(ModelMap mmap)
{
mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
mmap.put("posts", postService.selectPostAll());
return prefix + "/add";
}
/**
* 新增保存用户
*/
@RequiresPermissions("system:user:add")
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysUser user)
{
if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName())))
{
return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
}
else if (StringUtils.isNotEmpty(user.getPhonenumber())
&& UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
}
else if (StringUtils.isNotEmpty(user.getEmail())
&& UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
user.setCreateBy(ShiroUtils.getLoginName());
return toAjax(userService.insertUser(user));
}
/**
* 修改用户
*/
@GetMapping("/edit/{userId}")
public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
{
List<SysRole> roles = roleService.selectRolesByUserId(userId);
mmap.put("user", userService.selectUserById(userId));
mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
mmap.put("posts", postService.selectPostsByUserId(userId));
return prefix + "/edit";
}
/**
* 修改保存用户
*/
@RequiresPermissions("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysUser user)
{
userService.checkUserAllowed(user);
if (StringUtils.isNotEmpty(user.getPhonenumber())
&& UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在");
}
else if (StringUtils.isNotEmpty(user.getEmail())
&& UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
user.setUpdateBy(ShiroUtils.getLoginName());
return toAjax(userService.updateUser(user));
}
@RequiresPermissions("system:user:resetPwd")
@GetMapping("/resetPwd/{userId}")
public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap)
{
mmap.put("user", userService.selectUserById(userId));
return prefix + "/resetPwd";
}
@RequiresPermissions("system:user:resetPwd")
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
@PostMapping("/resetPwd")
@ResponseBody
public AjaxResult resetPwdSave(SysUser user)
{
userService.checkUserAllowed(user);
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
if (userService.resetUserPwd(user) > 0)
{
if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue())
{
ShiroUtils.setSysUser(userService.selectUserById(user.getUserId()));
}
return success();
}
return error();
}
/**
* 进入授权角色页
*/
@GetMapping("/authRole/{userId}")
public String authRole(@PathVariable("userId") Long userId, ModelMap mmap)
{
SysUser user = userService.selectUserById(userId);
// 获取用户所属的角色列表
List<SysRole> roles = roleService.selectRolesByUserId(userId);
mmap.put("user", user);
mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
return prefix + "/authRole";
}
/**
* 用户授权角色
*/
@RequiresPermissions("system:user:add")
@Log(title = "用户管理", businessType = BusinessType.GRANT)
@PostMapping("/authRole/insertAuthRole")
@ResponseBody
public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
{
userService.insertUserAuth(userId, roleIds);
return success();
}
@RequiresPermissions("system:user:remove")
@Log(title = "用户管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(userService.deleteUserByIds(ids));
}
/**
* 校验用户名
*/
@PostMapping("/checkLoginNameUnique")
@ResponseBody
public String checkLoginNameUnique(SysUser user)
{
return userService.checkLoginNameUnique(user.getLoginName());
}
/**
* 校验手机号码
*/
@PostMapping("/checkPhoneUnique")
@ResponseBody
public String checkPhoneUnique(SysUser user)
{
return userService.checkPhoneUnique(user);
}
/**
* 校验email邮箱
*/
@PostMapping("/checkEmailUnique")
@ResponseBody
public String checkEmailUnique(SysUser user)
{
return userService.checkEmailUnique(user);
}
/**
* 用户状态修改
*/
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:user:edit")
@PostMapping("/changeStatus")
@ResponseBody
public AjaxResult changeStatus(SysUser user)
{
userService.checkUserAllowed(user);
return toAjax(userService.changeStatus(user));
}
}
@@ -0,0 +1,26 @@
package co.yixiang.web.controller.tool;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import co.yixiang.common.core.controller.BaseController;
/**
* build 表单构建
*
* @author ruoyi
*/
@Controller
@RequestMapping("/tool/build")
public class BuildController extends BaseController
{
private String prefix = "tool/build";
@RequiresPermissions("tool:build:view")
@GetMapping()
public String build()
{
return prefix + "/build";
}
}
@@ -0,0 +1,24 @@
package co.yixiang.web.controller.tool;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import co.yixiang.common.core.controller.BaseController;
/**
* swagger 接口
*
* @author ruoyi
*/
@Controller
@RequestMapping("/tool/swagger")
public class SwaggerController extends BaseController
{
@RequiresPermissions("tool:swagger:view")
@GetMapping()
public String index()
{
return redirect("/swagger-ui.html");
}
}
@@ -0,0 +1,181 @@
package co.yixiang.web.controller.tool;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
/**
* swagger 用户测试方法
*
* @author ruoyi
*/
@Api("用户信息管理")
@RestController
@RequestMapping("/test/user")
public class TestController extends BaseController
{
private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
{
users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
}
@ApiOperation("获取用户列表")
@GetMapping("/list")
public AjaxResult userList()
{
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
return AjaxResult.success(userList);
}
@ApiOperation("获取用户详细")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
@GetMapping("/{userId}")
public AjaxResult getUser(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
return AjaxResult.success(users.get(userId));
}
else
{
return error("用户不存在");
}
}
@ApiOperation("新增用户")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer"),
@ApiImplicitParam(name = "username", value = "用户名称", dataType = "String"),
@ApiImplicitParam(name = "password", value = "用户密码", dataType = "String"),
@ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String")
})
@PostMapping("/save")
public AjaxResult save(UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return error("用户ID不能为空");
}
return AjaxResult.success(users.put(user.getUserId(), user));
}
@ApiOperation("更新用户")
@PutMapping("/update")
public AjaxResult update(@RequestBody UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return error("用户ID不能为空");
}
if (users.isEmpty() || !users.containsKey(user.getUserId()))
{
return error("用户不存在");
}
users.remove(user.getUserId());
return AjaxResult.success(users.put(user.getUserId(), user));
}
@ApiOperation("删除用户信息")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
@DeleteMapping("/{userId}")
public AjaxResult delete(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
users.remove(userId);
return success();
}
else
{
return error("用户不存在");
}
}
}
@ApiModel(value = "UserEntity", description = "用户实体")
class UserEntity
{
@ApiModelProperty("用户ID")
private Integer userId;
@ApiModelProperty("用户名称")
private String username;
@ApiModelProperty("用户密码")
private String password;
@ApiModelProperty("用户手机")
private String mobile;
public UserEntity()
{
}
public UserEntity(Integer userId, String username, String password, String mobile)
{
this.userId = userId;
this.username = username;
this.password = password;
this.mobile = mobile;
}
public Integer getUserId()
{
return userId;
}
public void setUserId(Integer userId)
{
this.userId = userId;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getMobile()
{
return mobile;
}
public void setMobile(String mobile)
{
this.mobile = mobile;
}
}
@@ -0,0 +1,69 @@
package co.yixiang.web.core.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import co.yixiang.common.config.RuoYiConfig;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* Swagger2的接口配置
*
* @author ruoyi
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig
{
/** 是否开启swagger */
@Value("${swagger.enabled}")
private boolean enabled;
/**
* 创建API
*/
@Bean
public Docket createRestApi()
{
return new Docket(DocumentationType.SWAGGER_2)
// 是否启用Swagger
.enable(enabled)
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
.apiInfo(apiInfo())
// 设置哪些接口暴露给Swagger展示
.select()
// 扫描所有有注解的api,用这种方式更灵活
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
// 扫描指定包中的swagger注解
//.apis(RequestHandlerSelectors.basePackage("co.yixiang.project.tool.swagger"))
// 扫描所有 .apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
/**
* 添加摘要信息
*/
private ApiInfo apiInfo()
{
// 用ApiInfoBuilder进行定制
return new ApiInfoBuilder()
// 设置标题
.title("标题:若依管理系统_接口文档")
// 描述
.description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
// 作者信息
.contact(new Contact(RuoYiConfig.getName(), null, null))
// 版本
.version("版本号:" + RuoYiConfig.getVersion())
.build();
}
}