|
@@ -0,0 +1,257 @@
|
|
|
+package com.jpsoft.prices.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.prices.modules.base.entity.CompanyDestination;
|
|
|
+import com.jpsoft.prices.modules.base.entity.Destination;
|
|
|
+import com.jpsoft.prices.modules.base.service.CompanyDestinationService;
|
|
|
+import com.jpsoft.prices.modules.base.service.DestinationService;
|
|
|
+import com.jpsoft.prices.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.prices.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.prices.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.prices.modules.base.entity.Company;
|
|
|
+import com.jpsoft.prices.modules.base.service.CompanyService;
|
|
|
+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.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/company")
|
|
|
+@Api(description = "company")
|
|
|
+public class CompanyController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyService companyService;
|
|
|
+ @Autowired
|
|
|
+ private DestinationService destinationService;
|
|
|
+ @Autowired
|
|
|
+ private CompanyDestinationService companyDestinationService;
|
|
|
+
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
+ @GetMapping("create")
|
|
|
+ public MessageResult<Company> create(){
|
|
|
+ MessageResult<Company> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Company company = new Company();
|
|
|
+
|
|
|
+ msgResult.setData(company);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
+ @PostMapping("add")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public MessageResult<Company> add(@RequestBody Company company,@RequestAttribute String subject){
|
|
|
+ MessageResult<Company> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ company.setId(UUID.randomUUID().toString());
|
|
|
+ company.setDelFlag(false);
|
|
|
+ company.setCreateBy(subject);
|
|
|
+ company.setCreateTime(new Date());
|
|
|
+ companyService.insert(company);
|
|
|
+
|
|
|
+ for(List list : company.getDestinationIds()){
|
|
|
+ CompanyDestination companyDestination = new CompanyDestination();
|
|
|
+ companyDestination.setId(UUID.randomUUID().toString());
|
|
|
+ companyDestination.setCompanyId(company.getId());
|
|
|
+ companyDestination.setDestinationId(StringUtils.join(list,","));
|
|
|
+ companyDestinationService.insert(companyDestination);
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="获取信息")
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ public MessageResult<Company> edit(@PathVariable("id") String id){
|
|
|
+ MessageResult<Company> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Company company = companyService.get(id);
|
|
|
+ List<List<String>> list = new ArrayList<>();
|
|
|
+ List<CompanyDestination> companyDestinationList = companyDestinationService.findByCompany(id);
|
|
|
+ for(CompanyDestination companyDestination : companyDestinationList){
|
|
|
+ List<String> strList = Arrays.asList(companyDestination.getDestinationId().split(","));
|
|
|
+ list.add(strList);
|
|
|
+ }
|
|
|
+ company.setDestinationIds(list);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(company);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="更新用户")
|
|
|
+ @PostMapping("update")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public MessageResult<Company> update(@RequestBody Company company,@RequestAttribute String subject){
|
|
|
+ MessageResult<Company> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ company.setUpdateBy(subject);
|
|
|
+ company.setUpdateTime(new Date());
|
|
|
+ companyService.update(company);
|
|
|
+
|
|
|
+ List<CompanyDestination> companyDestinationList = companyDestinationService.findByCompany(company.getId());
|
|
|
+ for(CompanyDestination companyDestination : companyDestinationList){
|
|
|
+ companyDestinationService.delete(companyDestination.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ for(List list : company.getDestinationIds()){
|
|
|
+ CompanyDestination companyDestination = new CompanyDestination();
|
|
|
+ companyDestination.setId(UUID.randomUUID().toString());
|
|
|
+ companyDestination.setCompanyId(company.getId());
|
|
|
+ companyDestination.setDestinationId(StringUtils.join(list,","));
|
|
|
+ companyDestinationService.insert(companyDestination);
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="删除")
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Company company = companyService.get(id);
|
|
|
+ company.setDelFlag(true);
|
|
|
+ company.setUpdateBy(subject);
|
|
|
+ company.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = companyService.update(company);
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ Company company = companyService.get(id);
|
|
|
+ company.setDelFlag(true);
|
|
|
+ company.setUpdateBy(subject);
|
|
|
+ company.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ affectCount += companyService.update(company);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 name, String destinationId,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ searchParams.put("name","%" + name + "%");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(destinationId) && !"null".equals(destinationId)) {
|
|
|
+ searchParams.put("destinationId","%" + destinationId + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("id_","asc"));
|
|
|
+
|
|
|
+ Page<Company> page = companyService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+ for(Company company : page.getResult()){
|
|
|
+ List<String> nameList = new ArrayList<>();
|
|
|
+ List<CompanyDestination> companyDestinationList = companyDestinationService.findByCompany(company.getId());
|
|
|
+ for(CompanyDestination companyDestination : companyDestinationList){
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
+ String[] strIds = companyDestination.getDestinationId().split(",");
|
|
|
+ for(String strId : strIds) {
|
|
|
+ Destination destination = destinationService.get(strId);
|
|
|
+ names.add(destination.getName());
|
|
|
+ }
|
|
|
+ nameList.add(StringUtils.join(names," > "));
|
|
|
+ }
|
|
|
+ company.setDestinationNames(StringUtils.join(nameList,"<br/>"));
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+}
|