|
@@ -1,9 +1,103 @@
|
|
|
package com.jpsoft.picc.modules.auth.controller;
|
|
|
|
|
|
+import com.alibaba.druid.util.StringUtils;
|
|
|
+import com.jpsoft.picc.modules.base.entity.Company;
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
+import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.picc.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.picc.modules.pub.dto.CompanyInfoDTO;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.jasig.cas.client.authentication.AttributePrincipal;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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.RestController;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
@Api(description="企业信息管理")
|
|
|
@RestController
|
|
|
+@RequestMapping("/auth/company")
|
|
|
public class CompanyController {
|
|
|
+ @Autowired
|
|
|
+ private CompanyService companyService;
|
|
|
+
|
|
|
+ @GetMapping(value="detail")
|
|
|
+ @ApiOperation(value = "获取企业信息")
|
|
|
+ public MessageResult<CompanyInfoDTO> detail(HttpServletRequest request){
|
|
|
+ MessageResult<CompanyInfoDTO> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyInfoDTO companyInfoDTO = new CompanyInfoDTO();
|
|
|
+
|
|
|
+ //todo
|
|
|
+ AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
+
|
|
|
+ Company company = companyService.findByCreateBy(principal.getName());
|
|
|
+
|
|
|
+ if(company!=null) {
|
|
|
+ PojoUtils.map(company, companyInfoDTO);
|
|
|
+ messageResult.setData(companyInfoDTO);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ messageResult.setData(companyInfoDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value="save")
|
|
|
+ @ApiOperation(value = "保存企业信息")
|
|
|
+ public MessageResult<String> save(CompanyInfoDTO companyInfoDTO,HttpServletRequest request){
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ //todo
|
|
|
+ AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(companyInfoDTO.getId())){
|
|
|
+ Company company = new Company();
|
|
|
+
|
|
|
+ PojoUtils.map(companyInfoDTO, company);
|
|
|
+
|
|
|
+ company.setId(UUID.randomUUID().toString());
|
|
|
+ company.setCreateTime(new Date());
|
|
|
+ company.setCreateBy(principal.getName());
|
|
|
+ company.setDelFlag(false);
|
|
|
+
|
|
|
+ companyService.insert(company);
|
|
|
+
|
|
|
+ messageResult.setData(company.getId());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Company company = companyService.get(companyInfoDTO.getId());
|
|
|
+ PojoUtils.map(companyInfoDTO, company);
|
|
|
+ company.setUpdateTime(new Date());
|
|
|
+ company.setUpdateBy(principal.getName());
|
|
|
+
|
|
|
+ companyService.update(company);
|
|
|
+
|
|
|
+ messageResult.setData(company.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
}
|