package com.gszc.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.gszc.entity.*; import com.gszc.mapper.*; import com.gszc.service.ICustomService; import com.gszc.util.Uuid8Utils; import org.apache.ibatis.session.RowBounds; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.UUID; /** *

* 服务实现类 *

* * @author ky * @since 2020-04-27 */ @Service @Transactional public class CustomServiceImpl extends ServiceImpl implements ICustomService { @Autowired CustomMapper customMapper; @Autowired CustomSupportMapper customSupportMapper; @Autowired MiniUserMapper miniUserMapper; @Autowired ReceiveAddressServiceImpl receiveAddressService; @Autowired PcUserMapper pcUserMapper; @Autowired InvoiceMapper invoiceMapper; @Autowired InvoiceHeaderMapper invoiceHeaderMapper; public void customRegister(Custom custom,List customSupports){ String id = Uuid8Utils.generateShortUUID(); custom.setId(id); custom.setCreateDate( new Date()); custom.setModifyDate( new Date()); custom.setStatusCode("todo"); customMapper.insert(custom); if(customSupports.size()>0){ for(CustomSupport customSupport:customSupports){ String supportid = UUID.randomUUID().toString(); customSupport.setId(supportid); customSupport.setCreateDate( new Date()); customSupport.setModifyDate( new Date()); customSupport.setCustomId(id); customSupportMapper.insert(customSupport); } } } /** * 用户可开票(已认证)公司 * @param userId * @return */ public List invoiceCustomList(String userId){ List customs = customMapper.selectList(new EntityWrapper().eq("mini_user_id", userId).eq("status_code","enable")); return customs; } public List customList(String userId,String type){ Wrapper miniUserId = new EntityWrapper().eq("mini_user_id", userId); if(null==type){ }else if(type.equals("todo")){ miniUserId.eq("status_code","todo"); }else if(type.equals("disable")){ miniUserId.eq("status_code","disable"); }else if(type.equals("enable")){ miniUserId.eq("status_code","enable"); } List customs = customMapper.selectList(miniUserId); return customs; } public JSONObject customDetail(String customId){ JSONObject jsonObject = new JSONObject(); Custom custom = customMapper.selectById(customId); List customSupports = customSupportMapper.selectList(new EntityWrapper().eq("custom_id", customId)); jsonObject.put("custom",custom); jsonObject.put("customSupports",customSupports); return jsonObject; } /** * 待接单 * @param pageNum * @param pageSize * @return */ public JSONObject pcTodoCustomList(Integer pageNum,Integer pageSize){ Integer count = customMapper.selectCount(new EntityWrapper().eq("status_code", "todo")); List customs = customMapper.selectPage(new RowBounds((pageNum-1)*pageSize,pageSize),new EntityWrapper().eq("status_code", "todo")); JSONObject jsonObject = new JSONObject(); jsonObject.put("count",count); jsonObject.put("customs",customs); return jsonObject; } /** * 待认证 * @param pageNum * @param pageSize * @return */ public JSONObject pcDisableCustomList(Integer pageNum,Integer pageSize){ Integer count = customMapper.selectCount(new EntityWrapper().eq("status_code", "disable")); List customs = customMapper.selectPage(new RowBounds((pageNum-1)*pageSize,pageSize),new EntityWrapper().eq("status_code", "disable")); JSONObject jsonObject = new JSONObject(); jsonObject.put("count",count); jsonObject.put("customs",customs); return jsonObject; } /** * 已认证 * @param pageNum * @param pageSize * @return */ public JSONObject pcEnableCustomList(Integer pageNum,Integer pageSize){ Integer count = customMapper.selectCount(new EntityWrapper().eq("status_code", "enable")); List customs = customMapper.selectPage(new RowBounds((pageNum-1)*pageSize,pageSize),new EntityWrapper().eq("status_code", "enable")); JSONObject jsonObject = new JSONObject(); jsonObject.put("count",count); jsonObject.put("customs",customs); return jsonObject; } /** * 接单 * @param customId * @param userId */ public void doCustom(String customId,String userId){ Custom custom = new Custom(); custom.setId(customId); custom.setModifyDate( new Date()); custom.setCopycatId(userId); custom.setStatusCode("disable"); customMapper.updateById(custom); } /** * 修改接单员 * @param customId * @param userId */ public void changeCopycat(String customId,String userId){ Custom custom = new Custom(); custom.setId(customId); custom.setModifyDate( new Date()); custom.setCopycatId(userId); customMapper.updateById(custom); } /** * 跟进备注 * @param customId */ public void customNotice(String customId, String notice, String noticeContent){ Custom custom = new Custom(); custom.setId(customId); custom.setModifyDate( new Date()); custom.setNotice(notice); custom.setNoticeContent(noticeContent); customMapper.updateById(custom); } /** * 认证 * @param customId */ public void enableCustom(String customId, String businessLicense, String socialCreditCode,Long serviceBeginDate,Long serviceEndDate){ Custom custom = new Custom(); custom.setId(customId); custom.setModifyDate( new Date()); custom.setBusinessLicense(businessLicense); custom.setSocialCreditCode(socialCreditCode); custom.setStatusCode("enable"); custom.setServiceBeginDate(new Date(serviceBeginDate)); custom.setServiceEndDate(new Date(serviceEndDate)); customMapper.updateById(custom); } public JSONObject enableCustomDetail(String customId){ JSONObject jsonObject = new JSONObject(); Custom custom = customMapper.selectById(customId); String miniUserId = custom.getMiniUserId(); MiniUser miniUser = miniUserMapper.selectById(miniUserId); List receiveAddressList = receiveAddressService.addressList(miniUserId); String copycatId = custom.getCopycatId(); PcUser pcUser = pcUserMapper.selectById(copycatId); jsonObject.put("custom",custom); jsonObject.put("miniUser",miniUser); jsonObject.put("receiveAddressList",receiveAddressList); jsonObject.put("pcUser",pcUser); //年度 Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.YEAR, -1); Date y = c.getTime(); List yearInvoiceList = invoiceMapper.selectList(new EntityWrapper().eq("custom_id", customId).ge("create_date", y)); //月度 c.setTime(new Date()); c.add(Calendar.MONTH, -1); Date m = c.getTime(); List monthInvoiceList = invoiceMapper.selectList(new EntityWrapper().eq("custom_id", customId).ge("create_date", m)); BigDecimal yearMoney = new BigDecimal("0"); BigDecimal monthMoney = new BigDecimal("0"); for(Invoice invoice:yearInvoiceList){ BigDecimal money = invoice.getMoney(); yearMoney = yearMoney.add(money); } for(Invoice invoice:monthInvoiceList){ BigDecimal money = invoice.getMoney(); monthMoney = monthMoney.add(money); } jsonObject.put("yearMoney",yearMoney); jsonObject.put("monthMoney",monthMoney); jsonObject.put("yearCount",yearInvoiceList.size()); return jsonObject; } public JSONObject enableCustomDetailInvoiceList(String customId,Integer pageNum,Integer pageSize){ Integer count = invoiceMapper.selectCount(new EntityWrapper().eq("custom_id", customId)); List invoiceList = invoiceMapper.selectPage(new RowBounds((pageNum-1)*pageSize,pageSize),new EntityWrapper().eq("custom_id", customId)); JSONObject jsonObject = new JSONObject(); jsonObject.put("count",count); jsonObject.put("invoiceList",invoiceList); return jsonObject; } public void deleteCustom(String customId){ customMapper.deleteById(customId); } }