|
@@ -0,0 +1,187 @@
|
|
|
+package org.springblade.meter.controller;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springblade.business.entity.Task;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.manager.entity.ContractInfo;
|
|
|
+import org.springblade.manager.entity.ContractRelationJlyz;
|
|
|
+import org.springblade.manager.feign.ProjectClient;
|
|
|
+import org.springblade.meter.dto.ApiTaskPageDto;
|
|
|
+import org.springblade.meter.entity.MeterApproveOpinion;
|
|
|
+import org.springblade.meter.mapper.MaterialMeterFormTaskMapper;
|
|
|
+import org.springblade.meter.mapper.MeterApproveOpinionMapper;
|
|
|
+import org.springblade.meter.mapper.MiddleMeterApplyTaskMapper;
|
|
|
+import org.springblade.meter.mapper.StartPayMeterFormTaskMapper;
|
|
|
+import org.springblade.meter.vo.ApiTaskPageVo;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.SingleColumnRowMapper;
|
|
|
+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;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/api")
|
|
|
+@Api(value = "第三方对接", tags = "第三方对接接口")
|
|
|
+public class APIController {
|
|
|
+
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+ private final MiddleMeterApplyTaskMapper middleMeterApplyTaskMapper;
|
|
|
+ private final MaterialMeterFormTaskMapper materialMeterFormTaskMapper;
|
|
|
+ private final StartPayMeterFormTaskMapper startPayMeterFormTaskMapper;
|
|
|
+ private final MeterApproveOpinionMapper opinionMapper;
|
|
|
+ private final ProjectClient projectClient;
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 第三方对接 获取任务列表
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/task/apiPage")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "获取任务列表", notes = "ApiTaskPageDto")
|
|
|
+ public R<IPage<ApiTaskPageVo>> apiPage(@RequestBody ApiTaskPageDto dto) {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getProjectId()) || ObjectUtil.isEmpty(dto.getContractId())) {
|
|
|
+ throw new ServiceException("未获取到当前项目或合同段信息");
|
|
|
+ }
|
|
|
+ if(dto.getCurrent()==null){
|
|
|
+ dto.setCurrent(1);
|
|
|
+ }
|
|
|
+ if(dto.getSize()==null){
|
|
|
+ dto.setSize(10);
|
|
|
+ }
|
|
|
+ /*封装入参SQL*/
|
|
|
+ int current = dto.getCurrent();
|
|
|
+ int size = dto.getSize();
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+ StringBuilder sqlString = new StringBuilder("SELECT * FROM u_task WHERE 1=1 AND is_deleted = 0 AND approval_type in (5,6,7,8) "); //approval_type = 5 计量任务
|
|
|
+
|
|
|
+ ContractInfo contractInfo = jdbcTemplate.queryForObject("select contract_type from m_contract_info where id = " + dto.getContractId(), new BeanPropertyRowMapper<>(ContractInfo.class));
|
|
|
+ if (contractInfo != null && Arrays.asList(1, 4).contains(contractInfo.getContractType())) {
|
|
|
+ /*施工、计量合同段(总承包合同段)按照项目id、合同段id正常查询*/
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getProjectId()) && ObjectUtil.isNotEmpty(dto.getContractId())) {
|
|
|
+ sqlString.append(" AND project_id = ? AND contract_id = ?");
|
|
|
+ params.add(dto.getProjectId());
|
|
|
+ params.add(dto.getContractId());
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (contractInfo != null && Arrays.asList(2, 3).contains(contractInfo.getContractType())) {
|
|
|
+ /*监理、业主(指挥部)合同段,默认查询当前项目下所有关联的合同段*/
|
|
|
+ List<ContractRelationJlyz> contractRelationJLYZ = jdbcTemplate.query("select contract_id_sg from m_contract_relation_jlyz where contract_id_jlyz = " + dto.getContractId(), new BeanPropertyRowMapper<>(ContractRelationJlyz.class));
|
|
|
+ Set<Long> ids = contractRelationJLYZ.stream().map(ContractRelationJlyz::getContractIdSg).collect(Collectors.toSet());
|
|
|
+ ids.add(Long.parseLong(dto.getContractId())); //把本身合同段也加入查询
|
|
|
+ sqlString.append(" AND contract_id in(").append(StringUtils.join(ids, ",")).append(")");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getSelectedType())) {
|
|
|
+ sqlString.append(" AND (");
|
|
|
+ if (dto.getSelectedType().equals(1)) { //待办页面
|
|
|
+ sqlString.append(" AND status = 1");
|
|
|
+ } else if (dto.getSelectedType().equals(2)) { //已办页面
|
|
|
+ sqlString.append("EXISTS (SELECT 1 FROM u_task_parallel WHERE u_task.process_instance_id = u_task_parallel.process_instance_id AND u_task_parallel.status in(2,3) AND u_task_parallel.task_user = ?)");
|
|
|
+ /*当前自己的任务必须是已审批、已废除 status = 2,3 ,才视为已办*/
|
|
|
+ params.add(SecureUtil.getUserId());
|
|
|
+ } else if (dto.getSelectedType().equals(3)) { //我发起页面
|
|
|
+ sqlString.append("report_user = ?");
|
|
|
+ params.add(SecureUtil.getUserId());
|
|
|
+ }
|
|
|
+ sqlString.append(")");
|
|
|
+ }
|
|
|
+ /*总数量*/
|
|
|
+ String sqlCount = sqlString.toString().replace("*", "count(1)");
|
|
|
+ Optional<Integer> totalCountOptional = Optional.ofNullable(jdbcTemplate.queryForObject(sqlCount, Integer.class, params.toArray()));
|
|
|
+ int totalCount = totalCountOptional.orElse(0);
|
|
|
+
|
|
|
+ /*分页*/
|
|
|
+ sqlString.append(" ORDER BY create_time DESC LIMIT ? OFFSET ?;");
|
|
|
+
|
|
|
+ params.add(size);
|
|
|
+ params.add((current - 1) * size);
|
|
|
+
|
|
|
+ /*执行SQL获取数据*/
|
|
|
+ String sqlPage = sqlString.toString();
|
|
|
+ List<Task> resultList = jdbcTemplate.query(sqlPage, new BeanPropertyRowMapper<>(Task.class), params.toArray());
|
|
|
+
|
|
|
+ /*解析page分页数据*/
|
|
|
+ IPage<ApiTaskPageVo> page = new Page<>(current, size);
|
|
|
+ List<ApiTaskPageVo> pageList = resultList.stream().map(task -> {
|
|
|
+ ApiTaskPageVo vo = new ApiTaskPageVo();
|
|
|
+ vo.setTaskId(task.getId());
|
|
|
+ vo.setTaskName(task.getTaskName());
|
|
|
+ vo.setTaskStatusName(task.getStatus().equals(1) ? "待审批" : task.getStatus().equals(2) ? "已审批" : "已废除");
|
|
|
+ String sql="";
|
|
|
+ if(task.getMeterTaskType()!=null&&task.getMeterTaskType()==1){
|
|
|
+ sql="Select raw_url From s_interim_pay_certificate where contract_period_id="+task.getFormDataId()+" and is_deleted=0";
|
|
|
+ }else if (task.getMeterTaskType()!=null){
|
|
|
+ sql="Select raw_url From s_material_start_statement where meter_period_id="+task.getFormDataId()+" and is_deleted=0";
|
|
|
+ }
|
|
|
+ if(!sql.equals("")){
|
|
|
+ List<String> query = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
+ if(query.size()>0){
|
|
|
+ vo.setRawUrl(query.get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (task.getMeterTaskType() != null && Arrays.asList(1, 2, 3).contains(task.getMeterTaskType())) {
|
|
|
+ //查看意见信息
|
|
|
+ MeterApproveOpinion opinion = opinionMapper.selectOne(new LambdaQueryWrapper<MeterApproveOpinion>().eq(MeterApproveOpinion::getTaskId, task.getId()));
|
|
|
+ if (opinion == null) {
|
|
|
+ opinion = new MeterApproveOpinion();
|
|
|
+ opinion.setId(SnowFlakeUtil.getId());
|
|
|
+ opinion.setTaskId(task.getId());
|
|
|
+ opinion.setProjectId(Long.valueOf(task.getProjectId()));
|
|
|
+ opinion.setProjectName(projectClient.getById(task.getProjectId()).getProjectName());
|
|
|
+ opinion.setContractId(Long.valueOf(task.getContractId()));
|
|
|
+ opinionMapper.insert(opinion);
|
|
|
+ }
|
|
|
+ vo.setMeterApproveOpinion(opinion);
|
|
|
+ //实时查询上报总金额
|
|
|
+ BigDecimal reportAllMoney = null;
|
|
|
+ if (task.getMeterTaskType() == 1) {
|
|
|
+ //中间计量
|
|
|
+ reportAllMoney = middleMeterApplyTaskMapper.selectAllMoney(Long.valueOf(task.getContractId()),Long.valueOf(task.getFormDataId()));
|
|
|
+ } else if (task.getMeterTaskType() == 2) {
|
|
|
+ //材料计量
|
|
|
+ reportAllMoney = materialMeterFormTaskMapper.selectAllMoney(task.getId());
|
|
|
+ } else if (task.getMeterTaskType() == 3) {
|
|
|
+ //开工计量
|
|
|
+ reportAllMoney = startPayMeterFormTaskMapper.selectAllMoney(task.getId());
|
|
|
+ }
|
|
|
+ if (reportAllMoney == null) {
|
|
|
+ reportAllMoney = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ reportAllMoney = reportAllMoney.setScale(0, RoundingMode.HALF_UP);
|
|
|
+ //报表实际支付金额
|
|
|
+ vo.setReportAllMoney(reportAllMoney);
|
|
|
+ //施工单位送审金额
|
|
|
+ BigDecimal submitApprovalMoney = null;
|
|
|
+ if(task.getMeterTaskType() == 1){
|
|
|
+ submitApprovalMoney=middleMeterApplyTaskMapper.selectSubmitApprovalMoney(Long.valueOf(task.getContractId()),Long.valueOf(task.getFormDataId()));
|
|
|
+ }
|
|
|
+ vo.setSubmitApprovalMoney(submitApprovalMoney);
|
|
|
+ //本期审计审核进度款
|
|
|
+ vo.setProgressMoney(task.getTaskCommonMoney() == null ? BigDecimal.ZERO : task.getTaskCommonMoney());
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ page.setRecords(pageList);
|
|
|
+ page.setTotal(totalCount);
|
|
|
+ return R.data(page);
|
|
|
+ }
|
|
|
+}
|