| @@ -0,0 +1,228 @@ | |||||
| package com.iformall.controller.mem; | |||||
| import cn.afterturn.easypoi.excel.ExcelImportUtil; | |||||
| import cn.afterturn.easypoi.excel.entity.ImportParams; | |||||
| import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; | |||||
| import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; | |||||
| import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.domain.po.WxMerchant; | |||||
| import com.iformall.domain.po.WxTags; | |||||
| import com.iformall.domain.vo.CUserBaseInfoT; | |||||
| import com.iformall.domain.vo.WxBillExcelTemplateOther; | |||||
| import com.iformall.mapper.WxMerchantMapper; | |||||
| import com.iformall.service.WxBillAllService; | |||||
| import com.iformall.service.WxCUserBasicInfoService; | |||||
| import com.iformall.service.WxTagsService; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.shiro.session.UnknownSessionException; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.data.redis.core.StringRedisTemplate; | |||||
| import org.springframework.scheduling.annotation.Async; | |||||
| import org.springframework.stereotype.Component; | |||||
| import java.io.File; | |||||
| import java.util.*; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| import java.util.stream.Collectors; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Component | |||||
| public class ImportTemplateTask { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||||
| @Autowired | |||||
| private WxTagsService wxTagsService; | |||||
| @Autowired | |||||
| StringRedisTemplate stringRedisTemplate; | |||||
| @Autowired | |||||
| private WxBillAllService wxBillAllService; | |||||
| @Autowired | |||||
| private WxMerchantMapper wxMerchantMapper; | |||||
| @Async | |||||
| public void importBillData(File file, MallUserInfo user, String importKey, String tenantId) { | |||||
| ImportParams params = new ImportParams(); | |||||
| // 需要验证 | |||||
| params.setImportFields(new String[]{"商户名*", "费用类型*", "费用属性*", "费用所属期-开始时间*", "费用所属期-结束时间*", "收款金额(元)*", "收款日期*", "截止缴款日*", "收款方式"}); | |||||
| IExcelDataHandler<CUserBaseInfoT> handler = new ImportTemplateTask.UserExcelHandler(); | |||||
| handler.setNeedHandlerFields(new String[]{"商户名*", "费用类型*", "费用属性*", "费用所属期-开始时间*", "费用所属期-结束时间*", "收款金额(元)*", "收款日期*", "截止缴款日*"}); | |||||
| params.setNeedVerify(true); | |||||
| ExcelImportResult<WxBillExcelTemplateOther> datalist = null; | |||||
| try { | |||||
| datalist = ExcelImportUtil.importExcelMore(file, WxBillExcelTemplateOther.class, params); | |||||
| } catch (Exception e) { | |||||
| set_redis_value(importKey, "1", "0", "0", "1", true); | |||||
| logger.error(e.getMessage()); | |||||
| // 删除缓存文件 | |||||
| file.delete(); | |||||
| return; | |||||
| } | |||||
| // 删除缓存文件 | |||||
| file.delete(); | |||||
| if (datalist == null) { | |||||
| logger.error("导入模板失败: 模板数据解析失败"); | |||||
| set_redis_value(importKey, "1", "0", "0", "1", true); | |||||
| return; | |||||
| } | |||||
| List<WxBillExcelTemplateOther> successList = datalist.getList(); | |||||
| List<WxBillExcelTemplateOther> failList = datalist.getFailList(); | |||||
| //此处判断商户是否存在 | |||||
| //1 过滤重复商户名 | |||||
| Set<String> merchantSet = successList.parallelStream().map(s -> StringUtils.trim(s.getMerchantName())).collect(Collectors.toSet()); | |||||
| //2 查询商户名是否存在 | |||||
| Map<String, WxMerchant> merchantMap = new HashMap<>(); | |||||
| merchantSet.parallelStream().forEach(merchantName -> { | |||||
| WxMerchant wxMerchantQuery = new WxMerchant(); | |||||
| wxMerchantQuery.setTenantId(tenantId); | |||||
| wxMerchantQuery.setName(merchantName); | |||||
| WxMerchant wxMerchant = wxMerchantMapper.selectOne(wxMerchantQuery); | |||||
| if (wxMerchant != null) { | |||||
| merchantMap.put(merchantName, wxMerchant); | |||||
| } | |||||
| }); | |||||
| //3 计失败条数 | |||||
| List<WxBillExcelTemplateOther> billSuccessList = new ArrayList<>(); | |||||
| successList.parallelStream().forEach(s -> { | |||||
| WxMerchant wxMerchant = merchantMap.get(s.getMerchantName()); | |||||
| Long merchantId = wxMerchant.getId(); | |||||
| if (merchantId != null) { | |||||
| s.setMerchantId(merchantId); | |||||
| Integer type = wxMerchant.getType(); | |||||
| s.setMerchantType(type); | |||||
| billSuccessList.add(s); | |||||
| } | |||||
| }); | |||||
| int billSuccessSize = billSuccessList.size(); | |||||
| int successSize = successList.size(); | |||||
| int failSize = failList.size(); | |||||
| int total = successSize + failSize; | |||||
| int failCount = successSize - billSuccessSize; | |||||
| int all_success = billSuccessSize; | |||||
| int all_fail = failSize + failCount; | |||||
| logger.info("验证通过的数量: " + billSuccessSize); | |||||
| logger.info("验证未通过的数量: " + failSize); | |||||
| //添加到redis里 | |||||
| set_redis_value(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); | |||||
| if (successSize > 0) { | |||||
| try { | |||||
| successList.parallelStream().forEach(bill -> { | |||||
| try { | |||||
| wxBillAllService.importBill(tenantId, importKey, bill, user); | |||||
| } catch (UnknownSessionException ue) { | |||||
| logger.error("session :" + ue.getMessage()); | |||||
| } | |||||
| }); | |||||
| } catch (Exception e) { | |||||
| set_redis_value(importKey, "1", "0", "0", "1", true); | |||||
| e.printStackTrace(); | |||||
| logger.error("导入模板失败:" + e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | |||||
| private class UserExcelHandler extends ExcelDataHandlerDefaultImpl<CUserBaseInfoT> { | |||||
| @Override | |||||
| public Object importHandler(CUserBaseInfoT obj, String name, Object value) { | |||||
| if (value == null) { | |||||
| value = ""; | |||||
| } | |||||
| System.out.println(name + " + " + value.toString()); | |||||
| return super.importHandler(obj, name, value); | |||||
| } | |||||
| } | |||||
| private void set_redis_value(String importKey, String allCount, String allSuccessCount, String processCount, String failCount, boolean fail) { | |||||
| stringRedisTemplate.opsForHash().put(importKey, "allCount", allCount); | |||||
| stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", allSuccessCount); | |||||
| stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount); | |||||
| stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount); | |||||
| if (fail) { | |||||
| stringRedisTemplate.expire(importKey, 10, TimeUnit.SECONDS); | |||||
| } | |||||
| } | |||||
| @Async | |||||
| public void importMemberData(File file, MallUserInfo user, String importKey, String tenantId) { | |||||
| ImportParams params = new ImportParams(); | |||||
| // 需要验证 | |||||
| params.setImportFields(new String[]{"姓名", "性别", "手机号*", "微信昵称", "学历", "生日", "地址", "上次活跃时间", "注册时间", "标签", "成长值", "积分"}); | |||||
| IExcelDataHandler<CUserBaseInfoT> handler = new ImportTemplateTask.UserExcelHandler(); | |||||
| handler.setNeedHandlerFields(new String[]{"手机号*"}); | |||||
| params.setNeedVerify(true); | |||||
| ExcelImportResult<CUserBaseInfoT> datalist = null; | |||||
| try { | |||||
| datalist = ExcelImportUtil.importExcelMore(file, CUserBaseInfoT.class, params); | |||||
| } catch (Exception e) { | |||||
| set_redis_value(importKey, "1", "0", "0", "1", true); | |||||
| logger.error(e.getMessage()); | |||||
| // 删除缓存文件 | |||||
| file.delete(); | |||||
| return; | |||||
| } | |||||
| // 删除缓存文件 | |||||
| file.delete(); | |||||
| if (datalist == null) { | |||||
| logger.error("导入模板失败: 模板数据解析失败"); | |||||
| set_redis_value(importKey, "1", "0", "0", "1", true); | |||||
| return; | |||||
| } | |||||
| List<CUserBaseInfoT> successList = datalist.getList(); | |||||
| List<CUserBaseInfoT> failList = datalist.getFailList(); | |||||
| logger.info("验证通过的数量: " + successList.size()); | |||||
| logger.info("验证未通过的数量: " + failList.size()); | |||||
| int total = successList.size() + failList.size(); | |||||
| int all_success = successList.size(); | |||||
| int all_fail = failList.size(); | |||||
| //添加到redis里 | |||||
| set_redis_value(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); | |||||
| if (successList.size() > 0) { | |||||
| WxTags wxTagsQ = new WxTags(); | |||||
| List<WxTags> tagList = wxTagsService.findList(wxTagsQ); | |||||
| try { | |||||
| successList.parallelStream().forEach(uBase -> { | |||||
| try { | |||||
| wxCUserBasicInfoService.importOneMem(tenantId, importKey, tagList, uBase, user); | |||||
| } catch (UnknownSessionException ue) { | |||||
| logger.error("session :" + ue.getMessage()); | |||||
| } | |||||
| }); | |||||
| } catch (Exception e) { | |||||
| set_redis_value(importKey, "1", "0", "0", "1", true); | |||||
| e.printStackTrace(); | |||||
| logger.error("导入模板失败:" + e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,182 @@ | |||||
| package com.iformall.controller.template; | |||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | |||||
| import com.iformall.controller.mem.ImportTemplateTask; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.enums.EnumImportType; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.utils.Constant; | |||||
| import io.swagger.annotations.Api; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.data.redis.core.StringRedisTemplate; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import java.io.BufferedInputStream; | |||||
| import java.io.File; | |||||
| import java.io.FileOutputStream; | |||||
| import java.io.IOException; | |||||
| import java.util.Map; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("wxImportTemplate") | |||||
| @Api(description = "模板导入") | |||||
| public class WxImportTemplateController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private String fmUploadDir; | |||||
| @Autowired | |||||
| StringRedisTemplate stringRedisTemplate; | |||||
| @Autowired | |||||
| private ImportTemplateTask importTemplateTask; | |||||
| private void set_redis_value(String importKey, String allCount, String allSuccessCount, String processCount, String failCount, boolean fail) { | |||||
| stringRedisTemplate.opsForHash().put(importKey, "allCount", allCount); | |||||
| stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", allSuccessCount); | |||||
| stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount); | |||||
| stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount); | |||||
| if (fail) { | |||||
| stringRedisTemplate.expire(importKey, 10, TimeUnit.SECONDS); | |||||
| } | |||||
| } | |||||
| @PostMapping(value = "/importTemplate", consumes = "multipart/*") | |||||
| @SystemControllerLog(description = "导入数据") | |||||
| public ResultData importTemplate(@RequestParam("file") MultipartFile mFile, @RequestParam("type") Integer type) { | |||||
| logger.debug("[" + getIpAddr() + "] WxImportTemplateController::importTemplate"); | |||||
| if (mFile.isEmpty()) { | |||||
| throw new MallinkException(Result.ERROR, "上传文件不能为空"); | |||||
| } | |||||
| //得到当前用户ID | |||||
| final MallUserInfo user = getUser(); | |||||
| String userId = type + "_" + user.getId(); | |||||
| String importKey = Constant.importMemPrev + userId; | |||||
| final String tenantId = getTenantId(); | |||||
| //查询当前用户得到的值是否为空,为空继续,不为空,返回模板正在导入 | |||||
| Boolean allCount = stringRedisTemplate.opsForHash().hasKey(importKey, "allCount"); | |||||
| if (allCount) { | |||||
| return new ResultData(Result.SUCCESS, "模板正在导入"); | |||||
| } | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + ""); | |||||
| stringRedisTemplate.expire(importKey, 30, TimeUnit.MINUTES); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allSuccessCount", 0 + ""); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "processCount", ""); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", ""); | |||||
| String fpath = fmUploadDir; | |||||
| File targetFile = new File(fpath); | |||||
| if (!targetFile.exists()) { | |||||
| targetFile.mkdirs(); | |||||
| } | |||||
| String fileName = type + ".xlsx"; | |||||
| int dot = mFile.getOriginalFilename().lastIndexOf('.'); | |||||
| fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length()); | |||||
| File lFile = new File(fpath + File.separator + fileName); | |||||
| FileOutputStream fos = null; | |||||
| BufferedInputStream fs = null; | |||||
| try { | |||||
| fos = new FileOutputStream(lFile); | |||||
| fs = (BufferedInputStream) mFile.getInputStream(); | |||||
| byte[] buffer = new byte[1024]; | |||||
| int len = 0; | |||||
| while ((len = fs.read(buffer)) != -1) { | |||||
| fos.write(buffer, 0, len); | |||||
| } | |||||
| fos.close(); | |||||
| fs.close(); | |||||
| } catch (Exception e) { | |||||
| stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1"); | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); | |||||
| } finally { | |||||
| if (fos != null) { | |||||
| try { | |||||
| fos.close(); | |||||
| } catch (IOException e) { | |||||
| stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1"); | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); | |||||
| } | |||||
| } | |||||
| if (fs != null) { | |||||
| try { | |||||
| fs.close(); | |||||
| } catch (IOException e) { | |||||
| stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1"); | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); | |||||
| } | |||||
| } | |||||
| } | |||||
| if (type.equals(EnumImportType.MEMBER.getCode())) { | |||||
| importTemplateTask.importMemberData(lFile, user, importKey, tenantId); | |||||
| } | |||||
| //暂时不区分账单类型,导入时区分 | |||||
| importTemplateTask.importBillData(lFile, user, importKey, tenantId); | |||||
| return new ResultData(Result.SUCCESS, "模板正在导入"); | |||||
| } | |||||
| @GetMapping("/queryTemplateCount") | |||||
| @SystemControllerLog(description = "导入数据查询") | |||||
| public ResultData queryTemplateCount(@RequestParam("type") MultipartFile type) { | |||||
| String importKey = Constant.importMemPrev + type + "_" + getUser().getId(); | |||||
| Map entries = stringRedisTemplate.opsForHash().entries(importKey); | |||||
| logger.info(JSONArray.toJSONString(entries) + ">>>>>>>>>>>>>>>>>>>>>1"); | |||||
| if (entries.size() < 4) { | |||||
| entries.clear(); | |||||
| return new ResultData(Result.SUCCESS, "ok", entries); | |||||
| } | |||||
| String allCount = entries.get("allCount").toString(); | |||||
| String allSuccessCount = entries.get("allSuccessCount").toString(); | |||||
| String processCount = entries.get("processCount").toString(); | |||||
| String failCount = entries.get("failCount").toString(); | |||||
| if (StringUtils.isNotBlank(failCount) && allCount.equals(failCount)) {//stringRedisTemplate.expire(userId,1,TimeUnit.SECONDS); | |||||
| logger.info(JSONArray.toJSONString(entries) + ">>>>>>>>>>>>>>>>>>>>>2"); | |||||
| //完全失败 | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "allCount"); | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "allSuccessCount"); | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "processCount"); | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "failCount"); | |||||
| return new ResultData(ErrorCode.MEM_IMPORT_ERR); | |||||
| } | |||||
| //导入完成 | |||||
| if (StringUtils.isNotBlank(allSuccessCount) && allSuccessCount.equals(processCount)) { | |||||
| ResultData ok = new ResultData(Result.SUCCESS, "ok", entries); | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "allCount"); | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "allSuccessCount"); | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "processCount"); | |||||
| stringRedisTemplate.opsForHash().delete(importKey, "failCount"); | |||||
| return ok; | |||||
| } | |||||
| return new ResultData(Result.SUCCESS, "查询成功", entries); | |||||
| } | |||||
| } | |||||
| @@ -35,4 +35,6 @@ public class WxBillExcelTemplate { | |||||
| @Excel(name = "收款方式", width = 20, orderNum = "9") | @Excel(name = "收款方式", width = 20, orderNum = "9") | ||||
| private String payWay; | private String payWay; | ||||
| private Long merchantId; | |||||
| private Integer merchantType; | |||||
| } | } | ||||
| @@ -0,0 +1,43 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| public enum EnumImportType { | |||||
| MEMBER(1, "会员"), | |||||
| SHOP_RENT(2, "商铺租金"), | |||||
| POINT_RENT(3, "多经点位租金"), | |||||
| SHOP_PROPERTY(4, "商铺物业费"), | |||||
| POINT_PROPERTY(5, "多经点位物业费"), | |||||
| DAILY(6, "日常费用"), | |||||
| OTHER(7, "其他费用"), | |||||
| OTHER_DEPOSIT(8, "其他押金"),; | |||||
| public static EnumImportType getEnum(Integer code) { | |||||
| for (EnumImportType value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumImportType(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -4,6 +4,7 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.domain.vo.WxBillAll; | import com.iformall.domain.vo.WxBillAll; | ||||
| import com.iformall.domain.vo.WxBillExcelTemplate; | import com.iformall.domain.vo.WxBillExcelTemplate; | ||||
| import com.iformall.domain.vo.WxBillExcelTemplateOther; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| @@ -60,4 +61,6 @@ public interface WxBillAllService { | |||||
| void exportTemplate(WxBillExcelTemplate wxBillExcelTemplate, HttpServletRequest request, HttpServletResponse response); | void exportTemplate(WxBillExcelTemplate wxBillExcelTemplate, HttpServletRequest request, HttpServletResponse response); | ||||
| void importBill(String tenantId, String importKey, WxBillExcelTemplateOther bill, MallUserInfo user); | |||||
| } | } | ||||
| @@ -5,7 +5,6 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.domain.po.WxBillAction; | import com.iformall.domain.po.WxBillAction; | ||||
| import com.iformall.enums.EnumBillAction; | |||||
| import com.iformall.mapper.WxBillActionMapper; | import com.iformall.mapper.WxBillActionMapper; | ||||
| import com.iformall.service.WxBillActionService; | import com.iformall.service.WxBillActionService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -13,7 +12,6 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.math.BigDecimal; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| /** | /** | ||||
| @@ -49,10 +47,8 @@ public class WxBillActionServiceImpl implements WxBillActionService { | |||||
| WxBillAction wxBillAction = new WxBillAction(); | WxBillAction wxBillAction = new WxBillAction(); | ||||
| wxBillAction.setId(idWorker.nextId()); | wxBillAction.setId(idWorker.nextId()); | ||||
| wxBillAction.setBillId(action.getBillId()); | wxBillAction.setBillId(action.getBillId()); | ||||
| String oldPrice = new BigDecimal(action.getOldPrice()).divide(new BigDecimal(100)).toPlainString(); | |||||
| String newPrice = new BigDecimal(action.getNewPrice()).divide(new BigDecimal(100)).toPlainString(); | |||||
| wxBillAction.setDetails(oldPrice + "元变更成" + newPrice + "元"); | |||||
| wxBillAction.setAction(EnumBillAction.UPDATE_BILL.getCode()); | |||||
| wxBillAction.setDetails(action.getDetails()); | |||||
| wxBillAction.setAction(action.getAction()); | |||||
| wxBillAction.setUserId(user.getId()); | wxBillAction.setUserId(user.getId()); | ||||
| wxBillAction.setUserName(user.getName()); | wxBillAction.setUserName(user.getName()); | ||||
| wxBillAction.setPhone(user.getPhone()); | wxBillAction.setPhone(user.getPhone()); | ||||
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.po.msg.MailMsg; | import com.iformall.domain.po.msg.MailMsg; | ||||
| @@ -107,6 +108,9 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||||
| @Autowired | @Autowired | ||||
| private WxPayAccountBillMapper wxPayAccountBillMapper; | private WxPayAccountBillMapper wxPayAccountBillMapper; | ||||
| @Autowired | |||||
| WxMerchantShopMapper wxMerchantShopMapper; | |||||
| @Override | @Override | ||||
| public Map<String, Object> listAsPage(WxBillAll record, Integer pageIndex, Integer pageSize) { | public Map<String, Object> listAsPage(WxBillAll record, Integer pageIndex, Integer pageSize) { | ||||
| //更新各账单状态 | //更新各账单状态 | ||||
| @@ -867,8 +871,10 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||||
| public void addBillAction(Long billId, Long oldPrice, Long newPrice, MallUserInfo mallUserInfo) { | public void addBillAction(Long billId, Long oldPrice, Long newPrice, MallUserInfo mallUserInfo) { | ||||
| WxBillAction wxBillAction = new WxBillAction(); | WxBillAction wxBillAction = new WxBillAction(); | ||||
| wxBillAction.setBillId(billId); | wxBillAction.setBillId(billId); | ||||
| wxBillAction.setOldPrice(oldPrice); | |||||
| wxBillAction.setNewPrice(newPrice); | |||||
| String oldPriceStr = new BigDecimal(oldPrice).divide(new BigDecimal(100)).toPlainString(); | |||||
| String newPriceStr = new BigDecimal(newPrice).divide(new BigDecimal(100)).toPlainString(); | |||||
| wxBillAction.setDetails(oldPriceStr + "元变更成" + newPriceStr + "元"); | |||||
| wxBillAction.setAction(EnumBillAction.UPDATE_BILL.getCode()); | |||||
| wxBillActionService.modifyBill(wxBillAction, mallUserInfo); | wxBillActionService.modifyBill(wxBillAction, mallUserInfo); | ||||
| } | } | ||||
| @@ -940,6 +946,226 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||||
| } | } | ||||
| @Override | |||||
| public void importBill(String tenantId, String importKey, WxBillExcelTemplateOther bill, MallUserInfo user) { | |||||
| //租金 | |||||
| Integer billType = bill.getBillType(); | |||||
| if (billType.equals(EnumBillExcelTemplate.SHOP_RENT.getCode()) || billType.equals(EnumBillExcelTemplate.POINT_RENT.getCode())) { | |||||
| WxBillRent rentQuery = new WxBillRent(); | |||||
| rentQuery.setTenantId(tenantId); | |||||
| rentQuery.setMerchantId(bill.getMerchantId()); | |||||
| rentQuery.setStarttime(bill.getStarttime()); | |||||
| rentQuery.setEndtime(bill.getEndtime()); | |||||
| if (billType.equals(EnumBillExcelTemplate.SHOP_RENT.getCode())) { | |||||
| rentQuery.setRentShopType(EnumRentShopType.SHOP.getCode()); | |||||
| } else { | |||||
| rentQuery.setRentShopType(EnumRentShopType.POINT.getCode()); | |||||
| } | |||||
| rentQuery.setIsPreview(EnumIsPreview.NO.getCode()); | |||||
| WxBillRent rent = wxBillRentMapper.selectOne(rentQuery); | |||||
| if (rent != null) { | |||||
| long pay = new BigDecimal(bill.getPayStr()).multiply(new BigDecimal(100)).longValueExact(); | |||||
| if (rent.getOwe() <= pay) { | |||||
| rent.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| } | |||||
| rent.setPay(rent.getPay() + pay); | |||||
| rent.setOwe(rent.getOwe() - pay); | |||||
| rent.setPayDate(bill.getPayDate()); | |||||
| rent.setReceiveDate(bill.getReceiveDate()); | |||||
| wxBillRentMapper.updateByPrimaryKey(rent); | |||||
| addActionImport(rent.getId(), bill.getPayWay(), user); | |||||
| } | |||||
| } else if (billType.equals(EnumBillExcelTemplate.SHOP_PROPERTY.getCode()) || billType.equals(EnumBillExcelTemplate.POINT_PROPERTY.getCode())) { | |||||
| WxBillProperty propertyQuery = new WxBillProperty(); | |||||
| propertyQuery.setTenantId(tenantId); | |||||
| propertyQuery.setMerchantId(bill.getMerchantId()); | |||||
| propertyQuery.setStarttime(bill.getStarttime()); | |||||
| propertyQuery.setEndtime(bill.getEndtime()); | |||||
| if (billType.equals(EnumBillExcelTemplate.SHOP_PROPERTY.getCode())) { | |||||
| propertyQuery.setRentShopType(EnumRentShopType.SHOP.getCode()); | |||||
| } else { | |||||
| propertyQuery.setRentShopType(EnumRentShopType.POINT.getCode()); | |||||
| } | |||||
| propertyQuery.setIsPreview(EnumIsPreview.NO.getCode()); | |||||
| WxBillProperty property = wxBillPropertyMapper.selectOne(propertyQuery); | |||||
| if (property != null) { | |||||
| long pay = new BigDecimal(bill.getPayStr()).multiply(new BigDecimal(100)).longValueExact(); | |||||
| if (property.getOwe() <= pay) { | |||||
| property.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| } | |||||
| property.setPay(property.getPay() + pay); | |||||
| property.setOwe(property.getOwe() - pay); | |||||
| property.setPayDate(bill.getPayDate()); | |||||
| property.setReceiveDate(bill.getReceiveDate()); | |||||
| wxBillPropertyMapper.updateByPrimaryKey(property); | |||||
| addActionImport(property.getId(), bill.getPayWay(), user); | |||||
| } | |||||
| } else if (billType.equals(EnumBillExcelTemplate.DAILY.getCode())) { | |||||
| WxBillDaily dailyQuery = new WxBillDaily(); | |||||
| String billAttrStr = StringUtils.trim(bill.getBillAttr()); | |||||
| if (billAttrStr.equals(EnumBillExcelTemplateDaily.WATER.getMessage())) { | |||||
| dailyQuery.setType(EnumBillDailyType.WATER.getCode()); | |||||
| } | |||||
| if (billAttrStr.equals(EnumBillExcelTemplateDaily.POWER.getMessage())) { | |||||
| dailyQuery.setType(EnumBillDailyType.POWER.getCode()); | |||||
| } | |||||
| if (billAttrStr.equals(EnumBillExcelTemplateDaily.AIR_CONDITIONING.getMessage())) { | |||||
| dailyQuery.setType(EnumBillDailyType.AIR_CONDITIONING.getCode()); | |||||
| } | |||||
| dailyQuery.setTenantId(tenantId); | |||||
| dailyQuery.setMerchantId(bill.getMerchantId()); | |||||
| dailyQuery.setReceiveDate(bill.getReceiveDate()); | |||||
| dailyQuery.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| WxBillDaily daily = wxBillDailyMapper.selectOne(dailyQuery); | |||||
| long pay = new BigDecimal(bill.getPayStr()).multiply(new BigDecimal(100)).longValueExact(); | |||||
| if (daily != null) { | |||||
| if (daily.getOwe() <= pay) { | |||||
| daily.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| } | |||||
| daily.setPay(daily.getPay() + pay); | |||||
| daily.setOwe(daily.getOwe() - pay); | |||||
| daily.setPayDate(bill.getPayDate()); | |||||
| daily.setReceiveDate(bill.getReceiveDate()); | |||||
| wxBillDailyMapper.updateByPrimaryKey(daily); | |||||
| } else { | |||||
| WxMerchantShop wxMerchantShop = new WxMerchantShop(); | |||||
| wxMerchantShop.setTenantId(tenantId); | |||||
| wxMerchantShop.setMerchantId(bill.getMerchantId()); | |||||
| wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| List<WxMerchantShop> select = wxMerchantShopMapper.select(wxMerchantShop); | |||||
| if (!select.isEmpty()) { | |||||
| daily = new WxBillDaily(); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| daily.setId(idWorker.nextId()); | |||||
| daily.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| daily.setReceivePay(pay); | |||||
| daily.setReceiveDate(bill.getReceiveDate()); | |||||
| daily.setPay(pay); | |||||
| daily.setType(dailyQuery.getType()); | |||||
| daily.setTenantId(tenantId); | |||||
| daily.setMerchantId(bill.getMerchantId()); | |||||
| daily.setShopId(select.get(0).getShopId()); | |||||
| daily.setRentShopType(bill.getMerchantType()); | |||||
| daily.setPayDate(bill.getPayDate()); | |||||
| Date date = new Date(); | |||||
| daily.setCreatetime(date); | |||||
| daily.setUpdatetime(date); | |||||
| daily.setExpiredDay(0L); | |||||
| daily.setOwe(0L); | |||||
| daily.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| wxBillDailyMapper.insertSelective(daily); | |||||
| } | |||||
| } | |||||
| addActionImport(daily.getId(), bill.getPayWay(), user); | |||||
| } else if (billType.equals(EnumBillExcelTemplate.OTHER.getCode())) { | |||||
| WxBillOther otherQuery = new WxBillOther(); | |||||
| otherQuery.setTenantId(tenantId); | |||||
| otherQuery.setMerchantId(bill.getMerchantId()); | |||||
| otherQuery.setReceiveDate(bill.getReceiveDate()); | |||||
| otherQuery.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| WxBillOther other = wxBillOtherMapper.selectOne(otherQuery); | |||||
| long pay = new BigDecimal(bill.getPayStr()).multiply(new BigDecimal(100)).longValueExact(); | |||||
| if (other != null) { | |||||
| if (other.getOwe() <= pay) { | |||||
| other.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| } | |||||
| other.setName(bill.getBillAttr()); | |||||
| other.setComments(bill.getBillAttr()); | |||||
| other.setPay(other.getPay() + pay); | |||||
| other.setOwe(other.getOwe() - pay); | |||||
| other.setPayDate(bill.getPayDate()); | |||||
| other.setReceiveDate(bill.getReceiveDate()); | |||||
| wxBillOtherMapper.updateByPrimaryKey(other); | |||||
| } else { | |||||
| WxMerchantShop wxMerchantShop = new WxMerchantShop(); | |||||
| wxMerchantShop.setTenantId(tenantId); | |||||
| wxMerchantShop.setMerchantId(bill.getMerchantId()); | |||||
| wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| List<WxMerchantShop> select = wxMerchantShopMapper.select(wxMerchantShop); | |||||
| if (!select.isEmpty()) { | |||||
| other = new WxBillOther(); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| other.setId(idWorker.nextId()); | |||||
| other.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| other.setReceivePay(pay); | |||||
| other.setReceiveDate(bill.getReceiveDate()); | |||||
| other.setPay(pay); | |||||
| other.setTenantId(tenantId); | |||||
| other.setMerchantId(bill.getMerchantId()); | |||||
| other.setShopId(select.get(0).getShopId()); | |||||
| other.setRentShopType(bill.getMerchantType()); | |||||
| other.setPayDate(bill.getPayDate()); | |||||
| Date date = new Date(); | |||||
| other.setCreatetime(date); | |||||
| other.setUpdatetime(date); | |||||
| other.setExpiredDay(0L); | |||||
| other.setOwe(0L); | |||||
| other.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| wxBillOtherMapper.insertSelective(other); | |||||
| } | |||||
| } | |||||
| addActionImport(other.getId(), bill.getPayWay(), user); | |||||
| } else if (billType.equals(EnumBillExcelTemplate.OTHER_DEPOSIT.getCode())) { | |||||
| WxBillOtherDeposit otherDepositQuery = new WxBillOtherDeposit(); | |||||
| otherDepositQuery.setTenantId(tenantId); | |||||
| otherDepositQuery.setMerchantId(bill.getMerchantId()); | |||||
| otherDepositQuery.setReceiveDate(bill.getReceiveDate()); | |||||
| otherDepositQuery.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| WxBillOtherDeposit otherDeposit = wxBillOtherDepositMapper.selectOne(otherDepositQuery); | |||||
| long pay = new BigDecimal(bill.getPayStr()).multiply(new BigDecimal(100)).longValueExact(); | |||||
| if (otherDeposit != null) { | |||||
| if (otherDeposit.getOwe() <= pay) { | |||||
| otherDeposit.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| } | |||||
| otherDeposit.setPay(otherDeposit.getPay() + pay); | |||||
| otherDeposit.setOwe(otherDeposit.getOwe() - pay); | |||||
| otherDeposit.setPayDate(bill.getPayDate()); | |||||
| otherDeposit.setReceiveDate(bill.getReceiveDate()); | |||||
| wxBillOtherDepositMapper.updateByPrimaryKey(otherDeposit); | |||||
| } else { | |||||
| WxMerchantShop wxMerchantShop = new WxMerchantShop(); | |||||
| wxMerchantShop.setTenantId(tenantId); | |||||
| wxMerchantShop.setMerchantId(bill.getMerchantId()); | |||||
| wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| List<WxMerchantShop> select = wxMerchantShopMapper.select(wxMerchantShop); | |||||
| if (!select.isEmpty()) { | |||||
| otherDepositQuery = new WxBillOtherDeposit(); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| otherDepositQuery.setId(idWorker.nextId()); | |||||
| otherDepositQuery.setStatus(EnumBillRentStatus.PAID.getCode()); | |||||
| otherDepositQuery.setReceivePay(pay); | |||||
| otherDepositQuery.setReceiveDate(bill.getReceiveDate()); | |||||
| otherDepositQuery.setPay(pay); | |||||
| otherDepositQuery.setTenantId(tenantId); | |||||
| otherDepositQuery.setMerchantId(bill.getMerchantId()); | |||||
| otherDepositQuery.setShopId(select.get(0).getShopId()); | |||||
| otherDepositQuery.setRentShopType(bill.getMerchantType()); | |||||
| otherDepositQuery.setPayDate(bill.getPayDate()); | |||||
| Date date = new Date(); | |||||
| otherDepositQuery.setCreatetime(date); | |||||
| otherDepositQuery.setUpdatetime(date); | |||||
| otherDepositQuery.setExpiredDay(0L); | |||||
| otherDepositQuery.setOwe(0L); | |||||
| otherDepositQuery.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| wxBillOtherDepositMapper.insertSelective(otherDepositQuery); | |||||
| } | |||||
| } | |||||
| addActionImport(otherDeposit.getId(), bill.getPayWay(), user); | |||||
| } else { | |||||
| logger.error("账单导入失败"); | |||||
| } | |||||
| } | |||||
| public void addActionImport(Long billId, String payWay, MallUserInfo user) { | |||||
| WxBillAction wxBillAction = new WxBillAction(); | |||||
| wxBillAction.setBillId(billId); | |||||
| String details = StringUtils.isEmpty(payWay) ? "其他缴费" : payWay + "缴费"; | |||||
| wxBillAction.setDetails(details); | |||||
| wxBillAction.setAction(EnumBillAction.IMPORT_PAY.getCode()); | |||||
| wxBillActionService.modifyBill(wxBillAction, user); | |||||
| } | |||||
| public void updateDailyBill(Long businessId, Long newPrice, Date updateDate) { | public void updateDailyBill(Long businessId, Long newPrice, Date updateDate) { | ||||
| WxBillDaily dbBill = wxBillDailyMapper.selectByPrimaryKey(businessId); | WxBillDaily dbBill = wxBillDailyMapper.selectByPrimaryKey(businessId); | ||||
| WxBillDaily wxBillDaily = new WxBillDaily(); | WxBillDaily wxBillDaily = new WxBillDaily(); | ||||