src/main/java/com/moral/common/bean/PageBean.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/common/util/WebUtils.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/controller/AccountController.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/AccountService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/AccountServiceImpl.java | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/common/bean/PageBean.java
@@ -32,6 +32,7 @@ * @param navigatePages 页码数量 */ public PageBean(List<T> list) { super(); if (list instanceof Page) { Page<T> page = (Page<T>) list; this.pageIndex = page.getPageNum(); @@ -43,5 +44,8 @@ } } public PageBean() { super(); } } src/main/java/com/moral/common/util/WebUtils.java
@@ -30,7 +30,11 @@ } else { if (!ObjectUtils.isEmpty(values[0]) && !"null".equalsIgnoreCase(values[0])) { params.put(unprefixed, values[0]); if ("sorter".equals(unprefixed)) { params.put(unprefixed, values[0].replace("end", "")); } else { params.put(unprefixed, values[0]); } } } } src/main/java/com/moral/controller/AccountController.java
@@ -2,12 +2,14 @@ import static com.moral.common.util.WebUtils.getParametersStartingWith; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -31,9 +33,21 @@ return new ResultBean<PageBean<Account>>(accounts); } @GetMapping("account") @PostMapping("account") public ResultBean<Integer> saveOrUpdateAccount(@RequestBody Account account) { Integer result = accountService.saveOrUpdateAccount(account); return new ResultBean<Integer>(result); } @PostMapping("account/id") public ResultBean<Integer> deleteAccountByLogic(@RequestBody Account account) { Integer result = accountService.deleteAccountByLogic(account); return new ResultBean<Integer>(result); } @PostMapping("accounts/ids") public ResultBean<Integer> deleteAccountsByLogic(@RequestBody List<Integer> ids) { Integer result = accountService.deleteAccountsByLogic(ids); return new ResultBean<Integer>(result); } } src/main/java/com/moral/service/AccountService.java
@@ -1,5 +1,6 @@ package com.moral.service; import java.util.List; import java.util.Map; import com.moral.common.bean.PageBean; @@ -17,4 +18,8 @@ Integer saveOrUpdateAccount(Account account); Integer deleteAccountByLogic(Account account); Integer deleteAccountsByLogic(List<Integer> ids); } src/main/java/com/moral/service/impl/AccountServiceImpl.java
@@ -23,6 +23,8 @@ import com.moral.common.bean.Constants; import com.moral.common.bean.PageBean; import com.moral.common.exception.BusinessException; import com.moral.common.util.Crypto; import com.moral.common.util.ResourceUtil; import com.moral.entity.Account; import com.moral.mapper.AccountMapper; import com.moral.service.AccountService; @@ -93,11 +95,17 @@ public PageBean<Account> getAccountListByPage(Map<String, Object> parameters) { Example example = new Example(Account.class); Criteria criteria = example.createCriteria(); if (parameters.containsKey("name")) { criteria.andLike("name", "%" + (String) parameters.get("name") + "%"); if (parameters.containsKey("accountName")) { criteria.andLike("accountName", "%" + (String) parameters.get("accountName") + "%"); } if (parameters.containsKey("mobile")) { criteria.andLike("mobile", "%" + (String) parameters.get("mobile") + "%"); } if (parameters.containsKey("isDelete")) { criteria.andEqualTo("isDelete", parameters.get("isDelete")); } if (parameters.containsKey("sorter")) { example.setOrderByClause((String) parameters.get("sorter")); } PageHelper.startPage(Integer.valueOf((String) parameters.get("pageIndex")), Integer.valueOf((String) parameters.get("pageSize"))); List<Account> accounts = accountMapper.selectByExample(example); @@ -110,10 +118,31 @@ if (ObjectUtils.isEmpty(account.getId())) { account.setIsDelete(Constants.IS_DELETE_FALSE); account.setCreateTime(new Date()); account.setPassword(Crypto.md5(ResourceUtil.getValue("password"))); return accountMapper.insertSelective(account); }else { } else { return accountMapper.updateByPrimaryKeySelective(account); } } @Override @Transactional public Integer deleteAccountByLogic(Account account) { account.setIsDelete(Constants.IS_DELETE_TRUE); if (account.getId() > 0) { throw new BusinessException("hahahahahah.................."); } return accountMapper.updateByPrimaryKeySelective(account); } @Override @Transactional public Integer deleteAccountsByLogic(List<Integer> ids) { Account account = new Account(); account.setIsDelete(Constants.IS_DELETE_TRUE); Example example = new Example(Account.class); example.or().andIn("id", ids); return accountMapper.updateByExampleSelective(account, example); } }