|
@@ -0,0 +1,304 @@
|
|
|
|
+package com.jpsoft.prices.modules.base.controller;
|
|
|
|
+
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
|
+import com.jpsoft.prices.modules.base.entity.Destination;
|
|
|
|
+import com.jpsoft.prices.modules.base.service.DestinationService;
|
|
|
|
+import com.jpsoft.prices.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.prices.modules.common.dto.Sort;
|
|
|
|
+import com.jpsoft.prices.modules.common.utils.PojoUtils;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/base/destination")
|
|
|
|
+@Api(description = "模版")
|
|
|
|
+public class DestinationController {
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DestinationService destinationService;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
|
+ @GetMapping("create")
|
|
|
|
+ public MessageResult<Destination> create(){
|
|
|
|
+ MessageResult<Destination> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Destination destination = new Destination();
|
|
|
|
+
|
|
|
|
+ msgResult.setData(destination);
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
|
+ @PostMapping("add")
|
|
|
|
+ public MessageResult<Destination> add(@RequestBody Destination destination,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Destination> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ destination.setId(UUID.randomUUID().toString());
|
|
|
|
+ destination.setDelFlag(false);
|
|
|
|
+ destination.setCreateBy(subject);
|
|
|
|
+ destination.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+ Destination destinationParent = destinationService.get(destination.getParentId());
|
|
|
|
+ if(destinationParent != null){
|
|
|
|
+ destination.setCode(destinationParent.getCode() + "," + destination.getId());
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ destination.setCode(destination.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int affectCount = destinationService.insert(destination);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(destination);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据库添加失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="获取信息")
|
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
|
+ public MessageResult<Destination> edit(@PathVariable("id") String id){
|
|
|
|
+ MessageResult<Destination> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Destination destination = destinationService.get(id);
|
|
|
|
+
|
|
|
|
+ if (destination != null) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(destination);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="更新用户")
|
|
|
|
+ @PostMapping("update")
|
|
|
|
+ public MessageResult<Destination> update(@RequestBody Destination destination,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Destination> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ destination.setUpdateBy(subject);
|
|
|
|
+ destination.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ Destination destinationParent = destinationService.get(destination.getParentId());
|
|
|
|
+ if(destinationParent != null){
|
|
|
|
+ destination.setCode(destinationParent.getCode() + "," + destination.getId());
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ destination.setCode(destination.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int affectCount = destinationService.update(destination);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ updateChildCode(destination.getId());
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(destination);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据库更新失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="更新code")
|
|
|
|
+ @PostMapping("updateChildCode")
|
|
|
|
+ public void updateChildCode(String parentId){
|
|
|
|
+ Destination destination = destinationService.get(parentId);
|
|
|
|
+ List<Destination> childList = destinationService.listByParentId(parentId);
|
|
|
|
+ for(Destination child : childList){
|
|
|
|
+ child.setCode(destination.getCode() + "," + child.getId());
|
|
|
|
+ destinationService.update(child);
|
|
|
|
+
|
|
|
|
+ updateChildCode(child.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="删除")
|
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Destination destination = destinationService.get(id);
|
|
|
|
+ destination.setDelFlag(true);
|
|
|
|
+ destination.setUpdateBy(subject);
|
|
|
|
+ destination.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = destinationService.update(destination);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(affectCount);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="批量删除")
|
|
|
|
+ @PostMapping("batchDelete")
|
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ int affectCount = 0;
|
|
|
|
+
|
|
|
|
+ for (String id : idList) {
|
|
|
|
+ Destination destination = destinationService.get(id);
|
|
|
|
+ destination.setDelFlag(true);
|
|
|
|
+ destination.setUpdateBy(subject);
|
|
|
|
+ destination.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ affectCount += destinationService.update(destination);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(affectCount);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="列表")
|
|
|
|
+ @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
|
+ public MessageResult<Map> pageList(
|
|
|
|
+ String parentId, String name,
|
|
|
|
+ @RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
|
|
|
|
+ @RequestParam(name="pageSize",defaultValue = "10") int pageSize,
|
|
|
|
+ @RequestAttribute String subject){
|
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
+ if(StringUtils.isNotEmpty(parentId) && !"null".equals(parentId)){
|
|
|
|
+ searchParams.put("parentId", parentId);
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isNotEmpty(name)){
|
|
|
|
+ searchParams.put("name", "%" + name + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
|
+ sortList.add(new Sort("code_","asc"));
|
|
|
|
+
|
|
|
|
+ Page<Destination> page = destinationService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
+ for(Destination li : page.getResult()){
|
|
|
|
+ li.setParentFullName(getFullName(li.getCode()));
|
|
|
|
+ if(StringUtils.isNotEmpty(li.getParentId())) {
|
|
|
|
+ Destination destination = destinationService.get(li.getParentId());
|
|
|
|
+ li.setParentName(destination.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<Destination> listByParentId(String parentId){
|
|
|
|
+ List<Destination> list = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ list = destinationService.getListByParentId(parentId);
|
|
|
|
+ for (Destination destination : list){
|
|
|
|
+ destination.setChildren(listByParentId(destination.getId()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "查询")
|
|
|
|
+ @RequestMapping(value = "query", method = RequestMethod.POST)
|
|
|
|
+ public MessageResult<List> query(String code) {
|
|
|
|
+ MessageResult<List> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
|
+ sortList.add(new Sort("parent_id", "asc"));
|
|
|
|
+ sortList.add(new Sort("name_", "asc"));
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(code) && !"undefined".equals(code)) {
|
|
|
|
+ searchParams.put("noCode", code + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Page<Destination> page = destinationService.pageSearch(searchParams,1,10000,false,sortList);
|
|
|
|
+ List<Destination> destinationList = page.getResult();
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(destinationList);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getFullName(String code){
|
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
|
+ String[] ids = code.split(",");
|
|
|
|
+ for(String id : ids){
|
|
|
|
+ Destination destination = destinationService.get(id);
|
|
|
|
+ names.add(destination.getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return StringUtils.join(names, " > ");
|
|
|
|
+ }
|
|
|
|
+}
|