科目信息

This commit is contained in:
hjc 2019-12-11 22:22:35 +08:00
parent ed643abfe5
commit 4e63bbd12b
16 changed files with 607 additions and 3 deletions

View File

@ -0,0 +1,128 @@
package com.cwhelp.admin.business.controller;
import com.cwhelp.admin.business.validator.BssClassItemValid;
import com.cwhelp.common.enums.AccountStandardEnum;
import com.cwhelp.common.enums.StatusEnum;
import com.cwhelp.common.utils.EntityBeanUtil;
import com.cwhelp.common.utils.ResultVoUtil;
import com.cwhelp.common.utils.StatusUtil;
import com.cwhelp.common.vo.ResultVo;
import com.cwhelp.modules.business.domain.BssClassItem;
import com.cwhelp.modules.business.service.BssClassItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author huang.jc
* @date 2019/12/11
*/
@Controller
@RequestMapping("/bss/classItem")
public class BssClassItemController {
@Autowired
private BssClassItemService bssClassItemService;
/**
* 列表页面
*/
@GetMapping("/index")
@RequiresPermissions("bss:classItem:index")
public String index(Model model, BssClassItem classItem) {
// 创建匹配器进行动态查询匹配
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("itemName", match -> match.contains());
// 获取数据列表
Example<BssClassItem> example = Example.of(classItem, matcher);
Page<BssClassItem> list = bssClassItemService.getPageList(example);
List<BssClassItem> items = list.getContent();
items.stream().forEach(bssClassItem -> {
bssClassItem.setItemTypeName(AccountStandardEnum.getNameById(bssClassItem.getItemType()));
});
// 封装数据
model.addAttribute("list", items);
model.addAttribute("page", list);
return "/business/classItem/index";
}
/**
* 跳转到添加页面
*/
@GetMapping("/add")
@RequiresPermissions("bss:classItem:add")
public String toAdd() {
return "/business/classItem/add";
}
/**
* 跳转到编辑页面
*/
@GetMapping("/edit/{id}")
@RequiresPermissions("bss:classItem:edit")
public String toEdit(@PathVariable("id") BssClassItem classItem, Model model) {
model.addAttribute("classItem", classItem);
return "/business/classItem/add";
}
/**
* 保存添加/修改的数据
* @param valid 验证对象
*/
@PostMapping({"/add","/edit"})
@RequiresPermissions({"bss:classItem:add","bss:classItem:edit"})
@ResponseBody
public ResultVo save(@Validated BssClassItemValid valid, BssClassItem classItem) {
// 复制保留无需修改的数据
if (classItem.getId() != null) {
BssClassItem beClassItem = bssClassItemService.getById(classItem.getId());
EntityBeanUtil.copyProperties(beClassItem, classItem);
}
// 保存数据
bssClassItemService.save(classItem);
return ResultVoUtil.SAVE_SUCCESS;
}
/**
* 跳转到详细页面
*/
@GetMapping("/detail/{id}")
@RequiresPermissions("bss:classItem:detail")
public String toDetail(@PathVariable("id") BssClassItem classItem, Model model) {
model.addAttribute("classItem",classItem);
return "/business/classItem/detail";
}
/**
* 设置一条或者多条数据的状态
*/
@RequestMapping("/status/{param}")
@RequiresPermissions("bss:classItem:status")
@ResponseBody
public ResultVo status(
@PathVariable("param") String param,
@RequestParam(value = "ids", required = false) List<Long> ids) {
// 更新状态
StatusEnum statusEnum = StatusUtil.getStatusEnum(param);
if (bssClassItemService.updateStatus(statusEnum, ids)) {
return ResultVoUtil.success(statusEnum.getMessage() + "成功");
} else {
return ResultVoUtil.error(statusEnum.getMessage() + "失败,请重新操作");
}
}
}

View File

@ -1,4 +1,4 @@
package com.cwhelp.admin.business.controller;
package com.cwhelp.admin.business.controller.api;
import com.cwhelp.common.api.baidu.BaiduAipOCR;
import com.cwhelp.common.api.baidu.entity.vatinvoice.*;

View File

@ -0,0 +1,20 @@
package com.cwhelp.admin.business.validator;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author huang.jc
* @date 2019/12/11
*/
@Data
public class BssClassItemValid implements Serializable {
@NotEmpty(message = "科目名称不能为空")
private String itemName;
@NotNull(message = "科目类型不能为空")
private Short itemType;
}

View File

@ -1,4 +1,4 @@
package com.cwhelp.admin.business.controller;
package com.cwhelp.admin.system.controller.api;
import com.cwhelp.common.constant.ApiConst;
import com.cwhelp.common.utils.ResultVoUtil;
@ -22,7 +22,7 @@ import java.util.UUID;
*/
@RestController
@RequestMapping("/api")
public class BssApiLoginController {
public class ApiLoginController {
@Autowired
private ApiUserService apiUserService;

View File

@ -13,6 +13,8 @@ project:
### spring配置
spring:
main:
allow-bean-definition-overriding: true
## 数据库配置
datasource:
driver-class-name: com.mysql.jdbc.Driver

View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
</head>
<body>
<div class="layui-form timo-compile">
<form th:action="@{/bss/classItem/add}">
<input type="hidden" name="id" th:if="${classItem}" th:value="${classItem.id}">
<div class="layui-form-item">
<label class="layui-form-label">科目名称</label>
<div class="layui-input-inline">
<input class="layui-input" type="text" name="itemName" placeholder="请输入科目名称" th:value="${classItem?.itemName}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">科目类型</label>
<div class="layui-input-inline">
<select class="layui-select" name="itemType" mo:dict="ACCOUNTING_STANDARDS" mo-selected="${classItem?.itemType}" mo-empty="" lay-type="itemType"></select>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">备注</label>
<div class="layui-input-block">
<textarea placeholder="请输入内容" class="layui-textarea" name="remark">[[${classItem?.remark}]]</textarea>
</div>
</div>
<div class="layui-form-item timo-finally">
<button class="layui-btn ajax-submit"><i class="fa fa-check-circle"></i> 保存</button>
<button class="layui-btn btn-secondary close-popup"><i class="fa fa-times-circle"></i> 关闭</button>
</div>
</form>
</div>
<script th:replace="/common/template :: script"></script>
</body>
</html>

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
</head>
<body>
<div class="timo-detail-page">
<div class="timo-detail-title">基本信息</div>
<table class="layui-table timo-detail-table">
<colgroup>
<col width="100px"><col>
<col width="100px"><col>
</colgroup>
<tbody>
<tr>
<th>主键ID</th>
<td th:text="${classItem.id}"></td>
<th>科目名称</th>
<td th:text="${classItem.itemName}"></td>
</tr>
<tr>
<th>科目类型</th>
<td th:text="${classItem.itemType}"></td>
<th>创建者</th>
<td th:text="${classItem.createBy?.nickname}"></td>
</tr>
<tr>
<th>创建时间</th>
<td th:text="${#dates.format(classItem.createDate, 'yyyy-MM-dd HH:mm:ss')}" colspan="3"></td>
</tr>
<tr>
<th>备注</th>
<td th:text="${classItem.remark}" colspan="3"></td>
</tr>
</tbody>
</table>
</div>
<script th:replace="/common/template :: script"></script>
</body>
</html>

View File

@ -0,0 +1,84 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
</head>
<body class="timo-layout-page">
<div class="layui-card">
<div class="layui-card-header timo-card-header">
<span><i class="fa fa-bars"></i> 科目信息管理</span>
<i class="layui-icon layui-icon-refresh refresh-btn"></i>
</div>
<div class="layui-card-body">
<div class="layui-row timo-card-screen">
<div class="pull-left layui-form-pane timo-search-box">
<div class="layui-inline">
<label class="layui-form-label">状态</label>
<div class="layui-input-block timo-search-status">
<select class="timo-search-select" name="status" mo:dict="SEARCH_STATUS" mo-selected="${param.status}"></select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">科目名称</label>
<div class="layui-input-block">
<input type="text" name="itemName" th:value="${param.itemName}" placeholder="请输入科目名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<button class="layui-btn timo-search-btn">
<i class="fa fa-search"></i>
</button>
</div>
</div>
<div class="pull-right screen-btn-group">
<button class="layui-btn open-popup" data-title="添加科目信息" th:attr="data-url=@{/bss/classItem/add}" data-size="auto">
<i class="fa fa-plus"></i> 添加</button>
<div class="btn-group">
<button class="layui-btn">操作<span class="caret"></span></button>
<dl class="layui-nav-child layui-anim layui-anim-upbit">
<dd><a class="ajax-status" th:href="@{/bss/classItem/status/ok}">启用</a></dd>
<dd><a class="ajax-status" th:href="@{/bss/classItem/status/freezed}">冻结</a></dd>
<dd><a class="ajax-status" th:href="@{/bss/classItem/status/delete}">删除</a></dd>
</dl>
</div>
</div>
</div>
<div class="timo-table-wrap">
<table class="layui-table timo-table">
<thead>
<tr>
<th class="timo-table-checkbox">
<label class="timo-checkbox"><input type="checkbox">
<i class="layui-icon layui-icon-ok"></i></label>
</th>
<th>主键ID</th>
<th>科目名称</th>
<th>科目类型</th>
<th>数据状态</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="item:${list}">
<td><label class="timo-checkbox"><input type="checkbox" th:value="${item.id}">
<i class="layui-icon layui-icon-ok"></i></label></td>
<td th:text="${item.id}">主键ID</td>
<td th:text="${item.itemName}">科目名称</td>
<td th:text="${item.itemTypeName}">科目类型</td>
<td th:text="${#dicts.dataStatus(item.status)}">数据状态</td>
<td th:text="${#dates.format(item.createDate, 'yyyy-MM-dd HH:mm:ss')}">创建时间</td>
<td>
<a class="open-popup" data-title="编辑科目信息" th:attr="data-url=@{'/bss/classItem/edit/'+${item.id}}" data-size="auto" href="#">编辑</a>
<a class="open-popup" data-title="详细信息" th:attr="data-url=@{'/bss/classItem/detail/'+${item.id}}" data-size="800,600" href="#">详细</a>
<a class="ajax-get" data-msg="您是否确认删除" th:href="@{/bss/classItem/status/delete(ids=${item.id})}">删除</a>
</td>
</tr>
</tbody>
</table>
</div>
<div th:replace="/common/fragment :: page"></div>
</div>
</div>
<script th:replace="/common/template :: script"></script>
</body>
</html>

View File

@ -0,0 +1,34 @@
package com.cwhelp.common.enums;
import lombok.Getter;
/**
* Created by huangjc on 2019/12/11 0011.
* 会计准则
*/
@Getter
public enum AccountStandardEnum {
SMALL_ENTERPRISES(1, "小企业会计准则"),
ENTERPRISES(2, "小企业会计准则"),
NON_PROFIT_ORGANIZATIONS(3, "民间非营利组织会计制度");
AccountStandardEnum(int id, String name){
this.id = id;
this.name = name;
}
private int id;
private String name;
public static String getNameById(int id){
for (AccountStandardEnum accountStandardEnum : AccountStandardEnum.values()) {
if(accountStandardEnum.getId() == id){
return accountStandardEnum.getName();
}
}
return "";
}
}

View File

@ -0,0 +1,53 @@
package com.cwhelp.common.filter;
import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Created by huangjc on 2019/12/10 0010.
*/
@Component
@ServletComponentScan
@WebFilter(filterName = "apiLoginFilter", urlPatterns = {"/api_biz/*"})
public class ApiLoginFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;
String token = request.getHeader("token");
HttpSession session = request.getSession();
if(session.getAttribute(token) == null){
response.setStatus(401);
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject json = new JSONObject();
json.put("code","401");
json.put("msg","请先登录!");
writer.print(json);
return;
}else{
filterChain.doFilter(request, response);
}
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("ApiLoginFilter initing..." + filterConfig.getFilterName());
}
@Override
public void destroy() {
}
}

View File

@ -55,6 +55,19 @@ public class UserAction extends ActionMap {
}
}
// api用户登录行为方法
public void apiUserLogin(ResetLog resetLog){
ActionLog actionLog = resetLog.getActionLog();
if (resetLog.isSuccess()){
actionLog.setMessage("api后台登录成功");
}else {
String username = (String) resetLog.getParam("username");
ResultVo resultVo = (ResultVo) resetLog.getRetValue();
actionLog.setOperName(username);
actionLog.setMessage(String.format("api后台登录失败[%s]%s", username, resultVo.getMsg()));
}
}
// 保存用户行为方法
public void userSave(ResetLog resetLog){
resetLog.getActionLog().setMessage("用户成功:${username}");

View File

@ -0,0 +1,54 @@
package com.cwhelp.modules.business.domain;
import com.cwhelp.common.enums.StatusEnum;
import com.cwhelp.common.utils.StatusUtil;
import com.cwhelp.modules.system.domain.User;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* @author huang.jc
* @date 2019/12/11
*/
@Data
@Entity
@Table(name="sys_class_item")
@EntityListeners(AuditingEntityListener.class)
@Where(clause = StatusUtil.notDelete)
public class BssClassItem implements Serializable {
// 主键ID
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
// 科目名称
private String itemName;
// 科目类型
private Short itemType;
// 数据状态
private Byte status = StatusEnum.OK.getCode();
// 备注
private String remark;
// 创建者
@CreatedBy
@ManyToOne(fetch=FetchType.LAZY)
@NotFound(action=NotFoundAction.IGNORE)
@JoinColumn(name="create_by")
@JsonIgnore
private User createBy;
// 创建时间
@CreatedDate
private Date createDate;
@Transient
private String itemTypeName;
}

View File

@ -0,0 +1,11 @@
package com.cwhelp.modules.business.repository;
import com.cwhelp.modules.business.domain.BssClassItem;
import com.cwhelp.modules.system.repository.BaseRepository;
/**
* @author huang.jc
* @date 2019/12/11
*/
public interface BssClassItemRepository extends BaseRepository<BssClassItem, Long> {
}

View File

@ -0,0 +1,41 @@
package com.cwhelp.modules.business.service;
import com.cwhelp.common.enums.StatusEnum;
import com.cwhelp.modules.business.domain.BssClassItem;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author huang.jc
* @date 2019/12/11
*/
public interface BssClassItemService {
/**
* 获取分页列表数据
* @param example 查询实例
* @return 返回分页数据
*/
Page<BssClassItem> getPageList(Example<BssClassItem> example);
/**
* 根据ID查询数据
* @param id 主键ID
*/
BssClassItem getById(Long id);
/**
* 保存数据
* @param classItem 实体对象
*/
BssClassItem save(BssClassItem classItem);
/**
* 状态(启用冻结删除)/批量状态处理
*/
@Transactional
Boolean updateStatus(StatusEnum statusEnum, List<Long> idList);
}

View File

@ -0,0 +1,66 @@
package com.cwhelp.modules.business.service.impl;
import com.cwhelp.common.data.PageSort;
import com.cwhelp.common.enums.StatusEnum;
import com.cwhelp.modules.business.domain.BssClassItem;
import com.cwhelp.modules.business.repository.BssClassItemRepository;
import com.cwhelp.modules.business.service.BssClassItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author huang.jc
* @date 2019/12/11
*/
@Service
public class BssClassItemServiceImpl implements BssClassItemService {
@Autowired
private BssClassItemRepository bssClassItemRepository;
/**
* 根据ID查询数据
* @param id 主键ID
*/
@Override
@Transactional
public BssClassItem getById(Long id) {
return bssClassItemRepository.findById(id).orElse(null);
}
/**
* 获取分页列表数据
* @param example 查询实例
* @return 返回分页数据
*/
@Override
public Page<BssClassItem> getPageList(Example<BssClassItem> example) {
// 创建分页对象
PageRequest page = PageSort.pageRequest();
return bssClassItemRepository.findAll(example, page);
}
/**
* 保存数据
* @param classItem 实体对象
*/
@Override
public BssClassItem save(BssClassItem classItem) {
return bssClassItemRepository.save(classItem);
}
/**
* 状态(启用冻结删除)/批量状态处理
*/
@Override
@Transactional
public Boolean updateStatus(StatusEnum statusEnum, List<Long> idList) {
return bssClassItemRepository.updateStatus(statusEnum.getCode(), idList) > 0;
}
}

View File

@ -626,3 +626,27 @@ INSERT INTO `sys_user_role` VALUES ('12', '17');
INSERT INTO `sys_user_role` VALUES ('8', '18');
INSERT INTO `sys_user_role` VALUES ('10', '18');
INSERT INTO `sys_user_role` VALUES ('12', '18');
-- ----------------------------
-- Table structure for sys_class_item
-- ----------------------------
CREATE TABLE `sys_class_item` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`create_date` datetime DEFAULT NULL,
`item_name` varchar(255) DEFAULT NULL,
`item_type` smallint(6) DEFAULT NULL,
`remark` varchar(255) DEFAULT NULL,
`status` tinyint(4) DEFAULT NULL,
`create_by` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKscjv9528cflikft0lwnwcujv0` (`create_by`),
CONSTRAINT `FKscjv9528cflikft0lwnwcujv0` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of sys_class_item
-- ----------------------------
INSERT INTO `sys_user_role` VALUES (1, '2019-12-11 21:12:20','食品支出',1,'',1,1);
INSERT INTO `sys_user_role` VALUES (2, '2019-12-11 21:12:20','食品收入',1,'',1,1);