/*
 *    Copyright (c) 2018-2025, hnqz All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: hnqz
 */
package com.qunzhixinxi.hnqz.admin.service.impl;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qunzhixinxi.hnqz.admin.api.entity.SysDictItem;
import com.qunzhixinxi.hnqz.admin.entity.WmDaHospital;
import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
import com.qunzhixinxi.hnqz.admin.entity.WmScorePackageStatus;
import com.qunzhixinxi.hnqz.admin.entity.WmTask;
import com.qunzhixinxi.hnqz.admin.entity.WmTaskContent;
import com.qunzhixinxi.hnqz.admin.mapper.WmDaHospitalMapper;
import com.qunzhixinxi.hnqz.admin.mapper.WmTaskContentMapper;
import com.qunzhixinxi.hnqz.admin.service.SysDictItemService;
import com.qunzhixinxi.hnqz.admin.service.SysUserService;
import com.qunzhixinxi.hnqz.admin.service.WmDaHospitalService;
import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
import com.qunzhixinxi.hnqz.admin.service.WmScorePackageStatusService;
import com.qunzhixinxi.hnqz.admin.service.WmTaskService;
import com.qunzhixinxi.hnqz.common.core.util.R;
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 档案-医院
 *
 * @author gaoyanng
 * @date 2020-06-25 23:35:42
 */
@Service
@AllArgsConstructor
public class WmDaHospitalServiceImpl extends ServiceImpl<WmDaHospitalMapper, WmDaHospital> implements WmDaHospitalService {

	private final WmTaskContentMapper wmTaskContentMapper;

	private final WmDaHospitalMapper wmDaHospitalMapper;

	private final WmTaskService wmTaskService;

	private final SysDictItemService sysDictItemService;
	private final SysUserService sysUserService;
	private final WmScorePackageService wmScorePackageService;
	private final WmScorePackageStatusService packageStatusService;


	@Override
	public boolean saveOrUpdateHospitalByTask(WmTask wmTask) {
		WmTaskContent wmTaskContent = wmTaskContentMapper.selectById(wmTask);
		WmDaHospital wmDaHospital = new WmDaHospital();
		wmDaHospital.setYymc(wmTaskContent.getTemp3());
		List<WmDaHospital> list = this.list(Wrappers.query(wmDaHospital));
		WmDaHospital newWmDaHospital = new WmDaHospital();
		if (list.size() > 0) {
			newWmDaHospital = list.get(0);
		}

		//服务药企
		newWmDaHospital.setYymc(wmTaskContent.getTemp3());
		newWmDaHospital.setProvince(wmTaskContent.getTemp4().split(",")[0]);
		newWmDaHospital.setCity(wmTaskContent.getTemp4().split(",")[1]);
		newWmDaHospital.setArea(wmTaskContent.getTemp4().split(",")[2]);
		newWmDaHospital.setYygm(wmTaskContent.getTemp5());//
		newWmDaHospital.setYyxz(wmTaskContent.getTemp6());
		newWmDaHospital.setLxzj(wmTaskContent.getTemp7());
		newWmDaHospital.setWebsite(wmTaskContent.getTemp8());
		newWmDaHospital.setYzxm(wmTaskContent.getTemp10());
		newWmDaHospital.setYzlxfs(wmTaskContent.getTemp11());
		newWmDaHospital.setFyzxm(wmTaskContent.getTemp12());
		newWmDaHospital.setFyzlxfs(wmTaskContent.getTemp13());
		newWmDaHospital.setYwcczxm(wmTaskContent.getTemp14());
		newWmDaHospital.setYwcczlxfs(wmTaskContent.getTemp15());
		newWmDaHospital.setJwcczxm(wmTaskContent.getTemp18());
		newWmDaHospital.setJwcczlxfs(wmTaskContent.getTemp19());
		newWmDaHospital.setYjkzrxm(wmTaskContent.getTemp20());
		newWmDaHospital.setYjkzrlsfs(wmTaskContent.getTemp21());
		newWmDaHospital.setYbczs(wmTaskContent.getTemp22());
		newWmDaHospital.setZlghsy(wmTaskContent.getTemp23());
		newWmDaHospital.setPspzsfry(wmTaskContent.getTemp24());
		newWmDaHospital.setPspzpssy(wmTaskContent.getTemp25());
		return this.saveOrUpdate(newWmDaHospital);
	}

	@Override
	public List<WmDaHospital> listByPoint(WmDaHospital wmDaHospital) {
		return wmDaHospitalMapper.listByPoint(wmDaHospital);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public R approvalHospital(String taskId) {
		List<Map<String, String>> compareList = new ArrayList<>();
		WmDaHospital wmDaHospital = new WmDaHospital();//系统数据
		WmDaHospital newinfo = new WmDaHospital();//对比后数据
		//获取任务信息
		WmTask wmTask = wmTaskService.getById(taskId);
		if (null == wmTask) {
			return R.failed("未查询到调研信息");
		}
		if ("1".equals(wmTask.getPlatAuditStatus())) {
			return R.failed("信息已审核，请重新查询后操作");
		}
		WmTaskContent wmTaskContent = wmTaskContentMapper.selectById(wmTask.getTaskContentId());
		if (null == wmTaskContent) {
			return R.failed("调研信息为空");
		}
		//Temp29对应医院ID
		Boolean exist = false;
		if (StringUtils.isNotEmpty(wmTaskContent.getTemp29())) {
			//有医院id,获取医院信息
			wmDaHospital = this.getById(wmTaskContent.getTemp29());
			if (wmDaHospital != null) {
				exist = true;
			}
		}

		if (!exist && StringUtils.isNotEmpty(wmTaskContent.getTemp3())) {
			//getTemp3 医院名称  防止新增任务后未审核前 医院存在
			WmDaHospital query = new WmDaHospital();
			query.setDelFlag("0");
			query.setEnableFlag("0");
			query.setYymc(wmTaskContent.getTemp3());
			List<WmDaHospital> hospitals = wmDaHospitalMapper.selectList(Wrappers.query(query));
			if (CollectionUtils.isNotEmpty(hospitals)) {
				wmDaHospital = hospitals.get(0);
				exist = true;
			}
		}

		if (exist) {
			//对比系统信息和调研数据
			newinfo.setId(wmDaHospital.getId());
			compareList = compareData(wmDaHospital, wmTaskContent, newinfo);
			if (null != compareList && compareList.size() > 0) {
				wmTask.setCompareResult("2");//信息不一致
			} else {
				wmTask.setCompareResult("3");//信息一致
			}
		} else {
			wmTask.setCompareResult("1");//新增
			//如果是新增，需要匹配原来的字段值
			wmDaHospital.setYymc(wmTaskContent.getTemp3());//名称
			wmDaHospital.setAddress(wmTaskContent.getTemp16());//详细地址
			if (!StringUtil.isEmpty(wmTaskContent.getTemp4())) {//省市区
				String[] citys = wmTaskContent.getTemp4().split("-");
				if (citys.length == 3) {
					wmDaHospital.setProvince(citys[0]);
					wmDaHospital.setCity(citys[1]);
					wmDaHospital.setArea(citys[2]);
				} else {
					String[] citys1 = wmTaskContent.getTemp4().split(",");
					if (citys1.length == 3) {
						wmDaHospital.setProvince(citys1[0]);
						wmDaHospital.setCity(citys1[1]);
						wmDaHospital.setArea(citys1[2]);
					}
				}
			}

			if (null != wmTaskContent.getTemp5()) {
				//小程序端存的value,web存的label，需要匹配
				SysDictItem sysDictItemConn = new SysDictItem();
				sysDictItemConn.setType("hospital_level");
				List<SysDictItem> dictItems = sysDictItemService.list(new QueryWrapper<>(sysDictItemConn));

				Map<String, String> partsMap = dictItems.stream().collect(Collectors.toMap(k -> k.getLabel(), k -> k.getValue()));
				String value = partsMap.get(wmTaskContent.getTemp5());
				wmDaHospital.setYygm(value == null ? wmTaskContent.getTemp5() : value);//医院规模
			}

			if (null != wmTaskContent.getTemp6()) {
				//小程序端存的value,web存的label，需要匹配
				SysDictItem sysDictItemConn = new SysDictItem();
				sysDictItemConn.setType("hospital_xz");
				List<SysDictItem> dictItems = sysDictItemService.list(new QueryWrapper<>(sysDictItemConn));

				Map<String, String> partsMap = dictItems.stream().collect(Collectors.toMap(k -> k.getLabel(), k -> k.getValue()));
				String value = partsMap.get(wmTaskContent.getTemp6());
				wmDaHospital.setYyxz(value == null ? wmTaskContent.getTemp6() : value);//医院性质
			}
			if (null != wmTaskContent.getTemp22()) {
				//小程序端存的value,web存的label，需要匹配
				SysDictItem sysDictItemConn = new SysDictItem();
				sysDictItemConn.setType("hospital_cw");
				List<SysDictItem> dictItems = sysDictItemService.list(new QueryWrapper<>(sysDictItemConn));

				Map<String, String> partsMap = dictItems.stream().collect(Collectors.toMap(k -> k.getLabel(), k -> k.getValue()));
				String value = partsMap.get(wmTaskContent.getTemp22());
				wmDaHospital.setYbczs(value == null ? wmTaskContent.getTemp22() : value);//医院性质
			}
			wmDaHospital.setWebsite(wmTaskContent.getTemp8());//联系总机
			//wmDaHospital.setYygm(wmTaskContent.getTemp5());//医院规模
			//wmDaHospital.setYyxz(wmTaskContent.getTemp6());//医院性质
//			wmDaHospital.setLxzj(wmTaskContent.getTemp7());//联系总机
//			wmDaHospital.setGgyx(wmTaskContent.getTemp8());//公共邮箱
//			wmDaHospital.setYzxm(wmTaskContent.getTemp10());//院长姓名
//			wmDaHospital.setYzlxfs(wmTaskContent.getTemp11());//院长联系方式
//			wmDaHospital.setFyzxm(wmTaskContent.getTemp12());//副院长姓名
//			wmDaHospital.setFyzlxfs(wmTaskContent.getTemp13());//联系方式
//			wmDaHospital.setYwcczxm(wmTaskContent.getTemp14());//医务处处长姓名
//			wmDaHospital.setYwcczlxfs(wmTaskContent.getTemp15());//联系方式
//			wmDaHospital.setYjkzrxm(wmTaskContent.getTemp20());//药剂科主任姓名
//			wmDaHospital.setYjkzrlsfs(wmTaskContent.getTemp21());//联系方式
//			wmDaHospital.setYbczs(wmTaskContent.getTemp22());//院病床总数（张）
//			wmDaHospital.setZlghsy(wmTaskContent.getTemp23());//主流供货商业
			wmDaHospital.setCreateTime(LocalDateTime.now());
			newinfo = wmDaHospital;
		}
		Map<String, Object> result = new HashMap();
		result.put("compareList", compareList);//对比数据
		result.put("info", wmDaHospital);//数据
		result.put("newinfo", newinfo);//数据
		result.put("wmTask", wmTask);
		result.put("wmTaskContent", wmTaskContent);

		return R.ok(result);
	}

	/**
	 * 对比系统数据，和调研数据
	 *
	 * @return
	 */
	public List<Map<String, String>> compareData(WmDaHospital wmDaHospital,
												 WmTaskContent wmTaskContent,
												 WmDaHospital newinfo) {
		List<Map<String, String>> resList = new ArrayList<>();
		String address = wmDaHospital.getProvince() + "-" + wmDaHospital.getCity() + "-" + wmDaHospital.getArea();
		if (StringUtils.isBlank(wmDaHospital.getProvince())) {
			address = null;
		}
		if (StringUtils.isNotBlank(wmTaskContent.getTemp4()) && !wmTaskContent.getTemp4().equals(address)) {
			resList.add(generateMap("所在城市", address, wmTaskContent.getTemp4()));
			String[] citys = wmTaskContent.getTemp4().split("-");
			if (citys.length == 3) {
				newinfo.setProvince(citys[0]);
				newinfo.setCity(citys[1]);
				newinfo.setArea(citys[2]);
			} else {
				String[] citys1 = wmTaskContent.getTemp4().split(",");
				if (citys1.length == 3) {
					newinfo.setProvince(citys1[0]);
					newinfo.setCity(citys1[1]);
					newinfo.setArea(citys1[2]);
				}
			}
		}
		if (StringUtils.isNotBlank(wmTaskContent.getTemp3()) && !wmTaskContent.getTemp3().equals(wmDaHospital.getYymc())) {
			resList.add(generateMap("医院名称", wmDaHospital.getYymc(), wmTaskContent.getTemp3()));
			newinfo.setYymc(wmTaskContent.getTemp3());
		}

		if (StringUtils.isNotBlank(wmTaskContent.getTemp5())) {
			//小程序端存的不一定value或label,web存的label，需要匹配
			Map<String, String> map = compareDictItem("医院规模", wmDaHospital.getYygm(), wmTaskContent.getTemp5(), "hospital_level");
			if (null != map && !map.isEmpty()) {
				resList.add(map);
				newinfo.setYygm(map.get("newData"));
			}
		}
		if (StringUtils.isNotBlank(wmTaskContent.getTemp6())) {
			//小程序端存的value,web存的label，需要匹配
			Map<String, String> map = compareDictItem("医院性质", wmDaHospital.getYyxz(), wmTaskContent.getTemp6(), "hospital_xz");
			if (null != map && !map.isEmpty()) {
				resList.add(map);
				newinfo.setYyxz(map.get("newData"));
			}
		}

		if (StringUtils.isNotBlank(wmTaskContent.getTemp22())) {
			//小程序端存的value,web存的label，需要匹配
			Map<String, String> map = compareDictItem("院病床总数（张）", wmDaHospital.getYbczs(), wmTaskContent.getTemp22(), "hospital_cw");
			if (null != map && !map.isEmpty()) {
				resList.add(map);
				newinfo.setYbczs(map.get("newData"));
			}
		}

		if (StringUtils.isNotBlank(wmTaskContent.getTemp8()) && !wmTaskContent.getTemp8().equals(wmDaHospital.getWebsite())) {
			resList.add(generateMap("医院官网", wmDaHospital.getWebsite(), wmTaskContent.getTemp8()));
			newinfo.setWebsite(wmTaskContent.getTemp8());
		}

//		if (null != wmTaskContent.getTemp22() && !wmTaskContent.getTemp22().equals(wmDaHospital.getYbczs() == null ? wmDaHospital.getYbczs() : wmDaHospital.getYbczs() + "")) {
//			resList.add(generateMap("院病床总数（张）", wmDaHospital.getYbczs() == null ? null : wmDaHospital.getYbczs().toString(), wmTaskContent.getTemp22()));
//			newinfo.setYbczs(Integer.parseInt(wmTaskContent.getTemp22()));
//		}


//		if(null!=wmTaskContent.getTemp6()&&!wmTaskContent.getTemp6().equals(wmDaHospital.getYyxz())){
//			resList.add(generateMap("医院性质",wmDaHospital.getYyxz(),wmTaskContent.getTemp6()));
//			newinfo.setYyxz(wmTaskContent.getTemp6());
//		}
//		if(null!=wmTaskContent.getTemp7()&&!wmTaskContent.getTemp7().equals(wmDaHospital.getLxzj())){
//			resList.add(generateMap("联系总机",wmDaHospital.getLxzj(),wmTaskContent.getTemp7()));
//			newinfo.setLxzj(wmTaskContent.getTemp7());
//		}
//		if(null!=wmTaskContent.getTemp8()&&!wmTaskContent.getTemp8().equals(wmDaHospital.getGgyx())){
//			resList.add(generateMap("公共邮箱",wmDaHospital.getGgyx(),wmTaskContent.getTemp8()));
//			newinfo.setGgyx(wmTaskContent.getTemp8());
//		}
//		if(null!=wmTaskContent.getTemp10()&&!wmTaskContent.getTemp10().equals(wmDaHospital.getYzxm())){
//			resList.add(generateMap("院长姓名",wmDaHospital.getYzxm(),wmTaskContent.getTemp10()));
//			newinfo.setYzxm(wmTaskContent.getTemp10());
//		}
//		if(null!=wmTaskContent.getTemp11()&&!wmTaskContent.getTemp11().equals(wmDaHospital.getYzlxfs())){
//			resList.add(generateMap("院长联系方式",wmDaHospital.getYzlxfs(),wmTaskContent.getTemp11()));
//			newinfo.setYzlxfs(wmTaskContent.getTemp11());
//		}

//		if(null!=wmTaskContent.getTemp12()&&!wmTaskContent.getTemp12().equals(wmDaHospital.getFyzxm())){
//			resList.add(generateMap("副院长姓名",wmDaHospital.getFyzxm(),wmTaskContent.getTemp12()));
//			newinfo.setFyzxm(wmTaskContent.getTemp12());
//		}
//		if(null!=wmTaskContent.getTemp13()&&!wmTaskContent.getTemp13().equals(wmDaHospital.getFyzlxfs())){
//			resList.add(generateMap("副院长联系方式",wmDaHospital.getFyzlxfs(),wmTaskContent.getTemp13()));
//			newinfo.setFyzlxfs(wmTaskContent.getTemp13());
//		}
//		if(null!=wmTaskContent.getTemp14()&&!wmTaskContent.getTemp14().equals(wmDaHospital.getYwcczxm())){
//			resList.add(generateMap("医务处处长姓名",wmDaHospital.getYwcczxm(),wmTaskContent.getTemp14()));
//			newinfo.setYwcczxm(wmTaskContent.getTemp14());
//		}
//		if(null!=wmTaskContent.getTemp15()&&!wmTaskContent.getTemp15().equals(wmDaHospital.getYwcczlxfs())){
//			resList.add(generateMap("医务处处长联系方式",wmDaHospital.getYwcczlxfs(),wmTaskContent.getTemp15()));
//			newinfo.setYwcczlxfs(wmTaskContent.getTemp15());
//		}
//		if(null!=wmTaskContent.getTemp16()&&!wmTaskContent.getTemp16().equals(wmDaHospital.getAddress())){
//			resList.add(generateMap("详细地址",wmDaHospital.getAddress(),wmTaskContent.getTemp16()));
//			newinfo.setAddress(wmTaskContent.getTemp16());
//		}
//		if(null!=wmTaskContent.getTemp20()&&!wmTaskContent.getTemp20().equals(wmDaHospital.getYjkzrxm())){
//			resList.add(generateMap("药剂科主任姓名",wmDaHospital.getYjkzrxm(),wmTaskContent.getTemp20()));
//			newinfo.setYjkzrxm(wmTaskContent.getTemp20());
//		}
//		if(null!=wmTaskContent.getTemp21()&&!wmTaskContent.getTemp21().equals(wmDaHospital.getYjkzrlsfs())){
//			resList.add(generateMap("药剂科主任联系方式",wmDaHospital.getYjkzrlsfs(),wmTaskContent.getTemp21()));
//			newinfo.setYjkzrlsfs(wmTaskContent.getTemp21());
//
//		}

//		if(null!=wmTaskContent.getTemp22()&&!wmTaskContent.getTemp22().equals(wmDaHospital.getYbczs()==null?wmDaHospital.getYbczs():wmDaHospital.getYbczs()+"")){
//			resList.add(generateMap("院病床总数（张）", wmDaHospital.getYbczs()==null?null:wmDaHospital.getYbczs().toString(),wmTaskContent.getTemp22()));
//			newinfo.setYbczs(Integer.parseInt(wmTaskContent.getTemp22()));
//		}
//		if(null!=wmTaskContent.getTemp23()&&!wmTaskContent.getTemp23().equals(wmDaHospital.getZlghsy())){
//			resList.add(generateMap("主流供货商业",wmDaHospital.getZlghsy(),wmTaskContent.getTemp23()));
//			newinfo.setZlghsy(wmTaskContent.getTemp23());
//		}
		return resList;

	}

	/**
	 * 判断两个参数值是否相同
	 *
	 * @param str1 //系统数据
	 * @param str2 //调研数据
	 * @return
	 */

	@Override
	public Map<String, String> compareDictItem(String name,
											   String str1,
											   String str2,
											   String param) {
		if (str2.equals(str1)) {
			return null;
		}
		SysDictItem sysDictItemConn = new SysDictItem();
		sysDictItemConn.setType(param);
		List<SysDictItem> dictItems = sysDictItemService.list(new QueryWrapper<>(sysDictItemConn));
		Map<String, String> partsMap = dictItems.stream().collect(Collectors.toMap(k -> k.getValue(), k -> k.getLabel()));

		String value1 = partsMap.values().contains(str1) ? str1 : partsMap.get(str1);//系统数据
		String value2 = partsMap.values().contains(str2) ? str2 : partsMap.get(str2);//调研数据
		value1 = (value1 == null ? str1 : value1);
		value2 = (value2 == null ? str2 : value2);
		if (StringUtil.isEmpty(value1)) {
			return generateMap(name, value1, value2);
		}
		if (!value1.equals(value2)) {
			return generateMap(name, value1, value2);
		}
		return null;
	}


	public Map<String, String> generateMap(String name, String oldData, String newData) {
		Map map = new HashMap();
		map.put("name", name);
		map.put("oldData", oldData);
		map.put("newData", newData);
		return map;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public R updateByApproval(Map<String, String> map) {
		//先更新任务表
		String taskId = map.get("taskId");
		WmTask wmTask = wmTaskService.getById(taskId);
		if (wmTask == null) {
			return R.failed("未查询到调查信息");
		}
		String approvalInfo = map.get("approvalInfo");
		String approvalOpinion = map.get("approvalOpinion");
		String compareResult = map.get("compareResult");
		//更新时，同一个task_content_id和createtime下的数据，都要更新状态为已审核
//		LambdaUpdateWrapper<WmTask> updateWrapper=new LambdaUpdateWrapper<WmTask>();
//		updateWrapper.set(WmTask::getPlatAuditStatus,"1");
//		updateWrapper.set(WmTask::getApprovalOpinion,approvalOpinion);
//		updateWrapper.set(WmTask::getCompareResult,compareResult);
//		updateWrapper.set(WmTask::getApprovalInfo,approvalInfo);
//		updateWrapper.eq(WmTask::getTaskContentId,wmTask.getTaskContentId());
//		updateWrapper.eq(WmTask::getCreateTime,wmTask.getCreateTime());
		WmTask updateTask = new WmTask();
		updateTask.setId(taskId);
		updateTask.setPlatAuditStatus("1");
		updateTask.setApprovalOpinion(approvalOpinion);
		updateTask.setCompareResult(compareResult);
		updateTask.setApprovalInfo(approvalInfo);

		WmDaHospital wmDaHospital = generateHospital(map);

		if ("1".equals(approvalOpinion)) {//采纳
			//updateWrapper.set(WmTask::getTaskStatus,"3");//审核通过
			// TODO 根据任务积分修改积分包状态

//			updateWrapper.set(WmTask::getRealFlag,"0");//0通过
			updateTask.setRealFlag("0");

			//更新审核信息
			LocalDateTime now = LocalDateTime.now();
			Integer userId = SecurityUtils.getUser().getId();
			if ("1".equals(compareResult)) {//新增
				//新增
				wmDaHospital.setCreateTime(now);
				wmDaHospital.setCreateUser(userId);
				this.save(wmDaHospital);
			} else if ("2".equals(compareResult)) {//信息不一致
				wmDaHospital.setUpdateTime(now);
				wmDaHospital.setUpdateUser(userId);
				this.updateById(wmDaHospital);
			} else if ("3".equals(compareResult)) {//信息一致
				//信息一致的情况下，只改地址
				if (!StringUtil.isEmpty(map.get("address"))) {
					WmDaHospital wmDaHospital1 = new WmDaHospital();
					wmDaHospital1.setId(wmDaHospital.getId());
					wmDaHospital1.setAddress(map.get("address"));
					wmDaHospital1.setLongitude(map.get("longitude"));
					wmDaHospital1.setLatitude(map.get("latitude"));
					wmDaHospital1.setUpdateTime(now);
					wmDaHospital1.setUpdateUser(userId);
					this.updateById(wmDaHospital1);
				}
			}


			//更新任务内容表
			WmTaskContent wmTaskContent = wmTaskContentMapper.selectById(wmTask.getTaskContentId());
			String infoId = map.get("infoId");
			wmTaskContent.setTemp29(infoId);
			wmTaskContentMapper.updateById(wmTaskContent);
		} else {
			//updateWrapper.set(WmTask::getTaskStatus,"2");//审核不通过
//			updateWrapper.set(WmTask::getRealFlag,"1");//1bu通过
			updateTask.setRealFlag("1");
		}
		//提交
		updateTask.setTaskStatus("2");
		LocalDateTime localDateTime = LocalDateTime.now();
		updateTask.setUpdateTime(localDateTime);

		WmScorePackage wmScorePackage = wmScorePackageService.getById(wmTask.getScorePackageId());
// 		if ("1".equals(approvalOpinion)) {
// 			if ("1".equals(wmScorePackage.getPackageType1())) {
// 				Boolean fullFlag = wmTaskService.checkUserTaskSubScore(wmTask.getTaskUserId());
// 				if (fullFlag) {
// //					return R.failed(1, "每日最多提交5万积分");
// 					updateTask.setScore(0);
// 				}
//
// 			}
// 		}
		wmTaskService.updateById(updateTask);
//		wmTaskService.update(updateWrapper);

		//审核之后的操作 //采纳
//		if("1".equals(approvalOpinion)){
//		}else {
		//更新积分包状态

		WmScorePackageStatus query = new WmScorePackageStatus();
		query.setUserId(wmTask.getTaskUserId());
		query.setPackageId(wmTask.getScorePackageId());
		query.setStatus("2");
		WmScorePackageStatus scorePackageStatus = packageStatusService.getOne(Wrappers.query(query));

		/**
		 * 不需要释放 直接返回
		 */
//			if("1".equals(wmScorePackage.getTaskAddFlag()) && "1".equals(scorePackageStatus.getTaskAddFlag())){
//				return R.ok();
//			}

		packageStatusService.updatePackageAndStatus(wmTask, wmScorePackage, scorePackageStatus);
//		}
		return R.ok();
	}


	public WmDaHospital generateHospital(Map<String, String> map) {
		WmDaHospital wmDaHospital = new WmDaHospital();
		wmDaHospital.setId(StringUtil.isBlank(map.get("id")) ? null : map.get("id"));
		wmDaHospital.setYymc(StringUtil.isBlank(map.get("yymc")) ? null : map.get("yymc"));

		wmDaHospital.setProvince(StringUtil.isBlank(map.get("province")) ? null : map.get("province"));
		wmDaHospital.setCity(StringUtil.isBlank(map.get("city")) ? null : map.get("city"));
		wmDaHospital.setArea(StringUtil.isBlank(map.get("area")) ? null : map.get("area"));
		wmDaHospital.setAddress(StringUtil.isBlank(map.get("address")) ? null : map.get("address"));


		wmDaHospital.setYygm(StringUtil.isBlank(map.get("yygm")) ? null : map.get("yygm"));//医院规模
		wmDaHospital.setYyxz(StringUtil.isBlank(map.get("yyxz")) ? null : map.get("yyxz"));//医院性质

		wmDaHospital.setWebsite(StringUtil.isBlank(map.get("website")) ? null : map.get("website"));//医院官网
		wmDaHospital.setYbczs(StringUtil.isBlank(map.get("ybczs")) ? null : map.get("ybczs"));//院病床总数（张）


//		wmDaHospital.setLxzj(StringUtil.isEmpty(map.get("lxzj"))?null:map.get("lxzj"));//联系总机
//		wmDaHospital.setGgyx(StringUtil.isEmpty(map.get("ggyx"))?null:map.get("ggyx"));//公共邮箱
//		wmDaHospital.setYzxm(StringUtil.isEmpty(map.get("yzxm"))?null:map.get("yzxm"));//院长姓名
//		wmDaHospital.setYzlxfs(StringUtil.isEmpty(map.get("yzlxfs"))?null:map.get("yzlxfs"));//院长联系方式
//		wmDaHospital.setFyzxm(StringUtil.isEmpty(map.get("fyzxm"))?null:map.get("fyzxm"));//副院长姓名
//		wmDaHospital.setFyzlxfs(StringUtil.isEmpty(map.get("fyzlxfs"))?null:map.get("fyzlxfs"));//联系方式
//		wmDaHospital.setYwcczxm(StringUtil.isEmpty(map.get("ywcczxm"))?null:map.get("ywcczxm"));//医务处处长姓名
//		wmDaHospital.setYwcczlxfs(StringUtil.isEmpty(map.get("ywcczlxfs"))?null:map.get("ywcczlxfs"));//联系方式
//		wmDaHospital.setYjkzrxm(StringUtil.isEmpty(map.get("yjkzrxm"))?null:map.get("yjkzrxm"));//药剂科主任姓名
//		wmDaHospital.setYjkzrlsfs(StringUtil.isEmpty(map.get("yjkzrlsfs"))?null:map.get("yjkzrlsfs"));//联系方式
//		wmDaHospital.setYbczs(StringUtil.isEmpty(map.get("ybczs"))?null:Integer.parseInt(map.get("ybczs")));//院病床总数（张）
//		wmDaHospital.setZlghsy(StringUtil.isEmpty(map.get("zlghsy"))?null:map.get("zlghsy"));//主流供货商业

		wmDaHospital.setLongitude(StringUtil.isBlank(map.get("longitude")) ? null : map.get("longitude"));//经度
		wmDaHospital.setLatitude(StringUtil.isBlank(map.get("latitude")) ? null : map.get("latitude"));//经度

		return wmDaHospital;
	}

}
