|
@@ -1,4 +1,339 @@
|
|
|
package com.jpsoft.picc.modules.auth.controller;
|
|
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.picc.modules.auth.dto.AcceptInsuranceDTO;
|
|
|
+import com.jpsoft.picc.modules.auth.dto.InsuranceApplicationDTO;
|
|
|
+import com.jpsoft.picc.modules.auth.dto.InsuranceJobsDTO;
|
|
|
+import com.jpsoft.picc.modules.base.entity.*;
|
|
|
+import com.jpsoft.picc.modules.base.service.InsuranceDefinitionLimitService;
|
|
|
+import com.jpsoft.picc.modules.base.service.InsuranceDefinitionService;
|
|
|
+import com.jpsoft.picc.modules.base.service.InsuranceJobsService;
|
|
|
+import com.jpsoft.picc.modules.base.service.JobsService;
|
|
|
+import com.jpsoft.picc.modules.business.entity.ApplicationPolicy;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsurancePolicy;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsurancePolicyMember;
|
|
|
+import com.jpsoft.picc.modules.business.service.ApplicationPolicyService;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsuranceApplicationService;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsurancePolicyMemberService;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsurancePolicyService;
|
|
|
+import com.jpsoft.picc.modules.common.constant.PolicyStatus;
|
|
|
+import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.picc.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.picc.modules.common.utils.PojoUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jasig.cas.client.authentication.AttributePrincipal;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.joda.time.Interval;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Api(description="投保历史查询")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/auth/applicationPolicy")
|
|
|
public class ApplicationPolicyController {
|
|
|
+ @Autowired
|
|
|
+ private InsuranceApplicationService insuranceApplicationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationPolicyService applicationPolicyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsurancePolicyService insurancePolicyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsuranceJobsService insuranceJobsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsuranceDefinitionService insuranceDefinitionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsuranceDefinitionLimitService insuranceDefinitionLimitService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JobsService jobsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsurancePolicyMemberService insurancePolicyMemberService;
|
|
|
+
|
|
|
+ @PostMapping(value="historyList")
|
|
|
+ @ApiOperation(value = "投保历史查看")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "applicationId",value = "参保单编号", required = true, paramType = "form"),
|
|
|
+ })
|
|
|
+ public MessageResult<Map> historyList(String applicationId,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize){
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ //todo
|
|
|
+ Page<InsurancePolicy> page = applicationPolicyService.findPolicyByApplicationId(applicationId,pageIndex,pageSize);
|
|
|
+
|
|
|
+ Map dataMap = PojoUtils.pageWrapper(page);
|
|
|
+
|
|
|
+ InsuranceApplication insuranceApplication = insuranceApplicationService.get(applicationId);
|
|
|
+
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ for (InsurancePolicy policy : page.getResult()) {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ map.put("applicationId",applicationId);
|
|
|
+ map.put("policyId",policy.getId());
|
|
|
+ map.put("startTime",sdf.format(policy.getStartTime()));
|
|
|
+ map.put("endTime",sdf.format(policy.getEndTime()));
|
|
|
+ map.put("definitionName",insuranceApplication.getDefinitionName());
|
|
|
+
|
|
|
+ if (now.before(policy.getStartTime())){
|
|
|
+ map.put("status","未生效");
|
|
|
+ }
|
|
|
+ else if(now.after(policy.getEndTime())){
|
|
|
+ map.put("status","已过期");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ map.put("status","保障中");
|
|
|
+ }
|
|
|
+
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ dataMap.put("data",mapList);
|
|
|
+
|
|
|
+ messageResult.setData(dataMap);
|
|
|
+ messageResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="获取投保信息")
|
|
|
+ @RequestMapping(value = "insureDetail",method = RequestMethod.GET)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "applicationId",value = "投保编号", required = true, paramType = "query",dataType = "String")
|
|
|
+ })
|
|
|
+ public MessageResult<InsuranceApplicationDTO> insureDetail(String applicationId,
|
|
|
+ HttpServletRequest request){
|
|
|
+ MessageResult<InsuranceApplicationDTO> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ InsuranceApplicationDTO insuranceApplicationDTO = new InsuranceApplicationDTO();
|
|
|
+
|
|
|
+ try {
|
|
|
+ InsuranceApplication insuranceApplication = null;
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(applicationId)) {
|
|
|
+ insuranceApplication = insuranceApplicationService.get(applicationId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (insuranceApplication != null) {
|
|
|
+ PojoUtils.map(insuranceApplication, insuranceApplicationDTO);
|
|
|
+ insuranceApplicationDTO.setApplicationId(insuranceApplication.getId());
|
|
|
+
|
|
|
+ DateTime endTime = new DateTime(insuranceApplication.getEndTime());
|
|
|
+ DateTime startTime = new DateTime(insuranceApplication.getStartTime());
|
|
|
+ Interval interval = new Interval(startTime, endTime);
|
|
|
+
|
|
|
+ insuranceApplicationDTO.setMonthNumber(interval.toPeriod().getMonths());
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setData(insuranceApplicationDTO);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<InsuranceJobs> findByDefinitionId(String definitionId){
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ searchParams.put("definitionId",definitionId);
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("create_time","asc"));
|
|
|
+ Page<InsuranceJobs> insuranceJobsPage = insuranceJobsService.pageSearch(searchParams,1,100,sortList);
|
|
|
+
|
|
|
+ return insuranceJobsPage.getResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="获取承保信息")
|
|
|
+ @RequestMapping(value = "acceptDetail",method = RequestMethod.GET)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "applicationId",value = "投保单ID", required = true,paramType = "query",dataType = "String"),
|
|
|
+ @ApiImplicitParam(name = "policyId",value = "每月投保单ID", required = true,paramType = "query",dataType = "String"),
|
|
|
+ })
|
|
|
+ public MessageResult<AcceptInsuranceDTO> acceptDetail(@RequestParam(value="applicationId",defaultValue="") String applicationId,
|
|
|
+ @RequestParam(value="policyId",defaultValue="") String policyId){
|
|
|
+ MessageResult<AcceptInsuranceDTO> msgResult = new MessageResult<>();
|
|
|
+ AcceptInsuranceDTO acceptInsuranceDTO = new AcceptInsuranceDTO();
|
|
|
+
|
|
|
+ try {
|
|
|
+ //投保单
|
|
|
+ InsuranceApplication insuranceApplication = insuranceApplicationService.get(applicationId);
|
|
|
+
|
|
|
+ //险种
|
|
|
+ InsuranceDefinition insuranceDefinition = insuranceDefinitionService.get(insuranceApplication.getDefinitionId());
|
|
|
+
|
|
|
+ //险种名称
|
|
|
+ acceptInsuranceDTO.setInsuranceDefName(insuranceDefinition.getName());
|
|
|
+
|
|
|
+ //险种关联限额
|
|
|
+ List<InsuranceDefinitionLimit> insuranceDefinitionLimits = insuranceDefinitionLimitService.findByDefinitionId(insuranceApplication.getDefinitionId());
|
|
|
+
|
|
|
+ acceptInsuranceDTO.setInsuranceDefLimitList(insuranceDefinitionLimits);
|
|
|
+
|
|
|
+ //关联岗位
|
|
|
+ List<InsuranceJobs> InsuranceJobsList = findByDefinitionId(insuranceApplication.getDefinitionId());
|
|
|
+
|
|
|
+ DateTime endTime = new DateTime(insuranceApplication.getEndTime());
|
|
|
+ acceptInsuranceDTO.setEndTime(insuranceApplication.getEndTime());
|
|
|
+
|
|
|
+ DateTime startTime = new DateTime(insuranceApplication.getStartTime());
|
|
|
+ acceptInsuranceDTO.setStartTime(insuranceApplication.getStartTime());
|
|
|
+
|
|
|
+ Interval interval = new Interval(startTime, endTime);
|
|
|
+
|
|
|
+ //投保总月份
|
|
|
+ int months = interval.toPeriod().getMonths();
|
|
|
+
|
|
|
+ BigDecimal totalAmount = new BigDecimal(0);
|
|
|
+ int totalNumber = 0;
|
|
|
+
|
|
|
+ List<InsuranceJobsDTO> insuranceJobsList = new ArrayList<>();
|
|
|
+
|
|
|
+ //查询不同岗位,参保费用
|
|
|
+ for(InsuranceJobs insuranceJobs : InsuranceJobsList){
|
|
|
+ Jobs jobs = jobsService.get(insuranceJobs.getJobsId());
|
|
|
+
|
|
|
+ InsuranceJobsDTO insuranceJobsDTO = new InsuranceJobsDTO();
|
|
|
+
|
|
|
+ insuranceJobsDTO.setJobs(jobs);
|
|
|
+
|
|
|
+ long memberCount = insurancePolicyMemberService.countByPolicyIdAndJobsId(policyId,insuranceJobs.getJobsId());
|
|
|
+
|
|
|
+ insuranceJobsDTO.setCharges(insuranceJobs.getCharges());
|
|
|
+ insuranceJobsDTO.setChargesY(insuranceJobs.getCharges().multiply(new BigDecimal(12)));
|
|
|
+ insuranceJobsDTO.setNumber(Long.valueOf(memberCount).intValue());
|
|
|
+
|
|
|
+ insuranceJobsDTO.setMoney(insuranceJobsDTO.getCharges()
|
|
|
+ .multiply(new BigDecimal(months))
|
|
|
+ .multiply(new BigDecimal(insuranceJobsDTO.getNumber())));
|
|
|
+
|
|
|
+ totalAmount = totalAmount.add(insuranceJobsDTO.getMoney());
|
|
|
+ totalNumber += memberCount;
|
|
|
+
|
|
|
+ insuranceJobsList.add(insuranceJobsDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ acceptInsuranceDTO.setInsuranceJobsList(insuranceJobsList);
|
|
|
+ acceptInsuranceDTO.setTotalAmount(totalAmount);
|
|
|
+
|
|
|
+ msgResult.setData(acceptInsuranceDTO);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value="生成下月投保单")
|
|
|
+ @ApiOperation(value = "generateNextMonthPolicy")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "applicationId",value = "投保单编号", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "policyId",value = "本月投保单编号", required = true, paramType = "form"),
|
|
|
+ })
|
|
|
+ public MessageResult<String> generateNextMonthPolicy(
|
|
|
+ String applicationId,String policyId,
|
|
|
+ HttpServletRequest request){
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
+ AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
+
|
|
|
+ try {
|
|
|
+ //添加下月投保单
|
|
|
+ InsurancePolicy srcPolicy = insurancePolicyService.get(policyId);
|
|
|
+ InsurancePolicy destPolicy = new InsurancePolicy();
|
|
|
+
|
|
|
+ PojoUtils.map(srcPolicy,destPolicy);
|
|
|
+
|
|
|
+ DateTime startTime = new DateTime(srcPolicy.getEndTime()).plusDays(1);
|
|
|
+
|
|
|
+ destPolicy.setStartTime(startTime.toDate());
|
|
|
+ destPolicy.setEndTime(startTime.plusMonths(1).toDate());
|
|
|
+
|
|
|
+ destPolicy.setEffectiveDate(startTime.toString("yyyyMM"));
|
|
|
+
|
|
|
+ boolean exist = insurancePolicyService.existByApplicationIdAndEffectiveDate(applicationId,destPolicy.getEffectiveDate());
|
|
|
+
|
|
|
+ if (exist){
|
|
|
+ throw new Exception(destPolicy.getEffectiveDate() + "投保单已存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ destPolicy.setNo(srcPolicy.getNo()+1);
|
|
|
+ destPolicy.setId(UUID.randomUUID().toString());
|
|
|
+ destPolicy.setStatus(PolicyStatus.Draft.getValue() + "");
|
|
|
+ destPolicy.setCreateBy(principal.getName());
|
|
|
+ destPolicy.setCreateTime(new Date());
|
|
|
+ destPolicy.setUpdateBy(principal.getName());
|
|
|
+ destPolicy.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ insurancePolicyService.insert(destPolicy);
|
|
|
+
|
|
|
+ //关联投保单及每月投保单
|
|
|
+ ApplicationPolicy applicationPolicy = new ApplicationPolicy();
|
|
|
+ applicationPolicy.setId(UUID.randomUUID().toString());
|
|
|
+ applicationPolicy.setApplicationId(applicationId);
|
|
|
+ applicationPolicy.setPolicyId(policyId);
|
|
|
+
|
|
|
+ applicationPolicyService.insert(applicationPolicy);
|
|
|
+
|
|
|
+ //关联参保人员
|
|
|
+ List<InsurancePolicyMember> memberList = insurancePolicyMemberService.findByPolicyId(policyId);
|
|
|
+
|
|
|
+ for (InsurancePolicyMember srcMember : memberList) {
|
|
|
+ InsurancePolicyMember destMember = new InsurancePolicyMember();
|
|
|
+
|
|
|
+ destMember.setId(UUID.randomUUID().toString());
|
|
|
+ destMember.setMemberId(srcMember.getMemberId());
|
|
|
+ destMember.setDelFlag(false);
|
|
|
+ destMember.setCreateBy(principal.getName());
|
|
|
+ destMember.setCreateTime(new Date());
|
|
|
+ destMember.setStatus(srcMember.getStatus());
|
|
|
+
|
|
|
+ insurancePolicyMemberService.insert(destMember);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
}
|